 | Expert | | Join Date: Jul 2006 Location: Norway
Posts: 112
# 1
Aug 15 '09
| |
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) -
#ota2tga
-
-
def writetga(width,height,data,filename):
-
f = open(filename,"wb")
-
file = ""
-
file+="%c%c%c" % (0,0,2)
-
file+="%c%c%c%c%c" % (0,0,0,0,0)
-
file+="%c%c%c%c" % (0,0,0,0)
-
file+="%c%c" % ((width & 0x00ff)%0xff,(width & 0xff00)%0xff)
-
file+="%c%c" % ((height & 0x00ff)%0xff,(height & 0xff00)%0xff)
-
file+="%c%c" % (0x18,0x0)
-
for i in range(height):
-
for j in range(width):
-
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])
-
f.write(file)
-
f.close()
-
-
# add the name of your .ota file here.
-
f = open("Grafikkmelding.ota","rb")
-
info = ord(f.read(1))
-
width = ord(f.read(1))
-
height = ord(f.read(1))
-
color = ord(f.read(1))
-
-
pixmap = [[255,255,255]]*(72*28)
-
print width
-
print height
-
x = 0
-
y = 0
-
l = ""
-
for i in range(height):
-
for j in range(width / 8):
-
v = ord(f.read(1))
-
for k in range(8):
-
if( ((v >> 7-k) & 0x01) == 0):
-
l+=" "
-
pixmap[x+y*width] = [255,255,255]
-
else:
-
l+="#"
-
pixmap[x+y*width] = [0,0,0]
-
x+=1
-
if(x > width):
-
x=0
-
y+=1
-
l+="\n"
-
f.close()
-
print l
-
writetga(width,height,pixmap,"output.tga")
-
-kudos
|