OTA. TGA提取

你还记得OTA格式吗?可以作为短信发送的简单图形格式?无论如何,我在我的手机上发现了一张很酷的OTA图片,我想把它提取成一种"正常"的图形格式,并将它添加到一个
T—恤衫
(它还将图像作为多个'#'写出到标准输出中)

选择 | 换行 | 行号
  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.  

-赞誉

标签: python

评论已关闭