473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,387 developers and data experts.

OTA. to TGA extractor

kudos
127 Expert 100+
Do you remeber the OTA format? The simple graphic format that you could send as a SMS message? Anyway, I found a cool OTA image on my cellphone, and wanted to extract it to a "normal" graphics format, and add it to a t-shirt (it also writes the image out to stdout as a number of '#'s)

Expand|Select|Wrap|Line Numbers
  1. #ota2tga
  2.  
  3. def writetga(width,height,data,filename):
  4.  f = open(filename,"wb")
  5.  file = ""
  6.  file+="%c%c%c" % (0,0,2)
  7.  file+="%c%c%c%c%c" % (0,0,0,0,0)
  8.  file+="%c%c%c%c" % (0,0,0,0)
  9.  file+="%c%c" % ((width & 0x00ff)%0xff,(width & 0xff00)%0xff)
  10.  file+="%c%c" % ((height & 0x00ff)%0xff,(height & 0xff00)%0xff)
  11.  file+="%c%c" % (0x18,0x0)
  12.  for i in range(height):
  13.   for j in range(width):
  14.    file+="%c%c%c" % (data[j+(height-1-i)*(width-1)][0],data[j+(height-1-i)*(width-1)][1],data[j+(height-1-i)*(width-1)][2])
  15.  f.write(file)
  16.  f.close()
  17.  
  18. # add the name of your .ota file here.
  19. f = open("Grafikkmelding.ota","rb")
  20. info = ord(f.read(1))
  21. width = ord(f.read(1))
  22. height = ord(f.read(1))
  23. color = ord(f.read(1))
  24.  
  25. pixmap = [[255,255,255]]*(72*28)
  26. print width
  27. print height
  28. x = 0
  29. y = 0
  30. l = ""
  31. for i in range(height):
  32.  for j in range(width / 8):
  33.   v = ord(f.read(1))
  34.   for k in range(8):
  35.    if( ((v >> 7-k) & 0x01) == 0):
  36.     l+=" "
  37.     pixmap[x+y*width] = [255,255,255]
  38.    else:
  39.     l+="#"
  40.     pixmap[x+y*width] = [0,0,0]
  41.    x+=1
  42.    if(x > width):
  43.     x=0
  44.     y+=1
  45.  l+="\n"   
  46. f.close()
  47. print l
  48. writetga(width,height,pixmap,"output.tga")
  49.  
-kudos
Aug 15 '09 #1
0 3288

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marco | last post by:
Hi, I am searching for a tool that extract information from a HTLM page and format it in xml format For instance for this page:...
4
by: cstudent79 | last post by:
Hello folks,how do u do ? I want to develop an application that can extract text from a powerpoint presentation.But i am in dark about the powerpoint file format.I would be obliged if somebody can...
0
by: bsimaie | last post by:
Hello group Since I want to modify a large program written in C(40K line) for the academic purposes and the program compose of several modules, it is necessary to have software structure in order...
1
by: _BNC | last post by:
I've been looking for a couple weeks for a regex expression that will extract text from html in a form that will look like IE screen output. I'm sure one of you guys hid it somewhere as a joke, but...
0
by: Vijay | last post by:
h any know how the website extractor tool works thanks & regard Vijay
6
by: isbat1 | last post by:
I need to extract some embedded resources back to disk from a .net assembly. What tool do I need, and where do I get it?
23
by: Randy | last post by:
Since these operators can't be member functions, and since friend functions can't be declared virtual, how do I make my inserters and extractors polymorphic? --Randy Yates
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.