Guest User

Nayuta Transparency Fixer v3

a guest
Apr 21st, 2015
356
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import sys
  3.  
  4. def get_data(filename):
  5.     totalbytes = os.path.getsize(filename)
  6.     infile = open(filename, 'rb')
  7.     totalfiledata = infile.read(totalbytes)
  8.     infile.close()
  9.     return totalfiledata
  10.  
  11. def myprogram(filename):
  12.     filedata = get_data(filename + '.orig')
  13.     pos = 0x36
  14.     transparent_color = -1
  15.     transparency_bytes = []
  16.     for x in range(256):
  17.         transparency_byte = filedata[pos + x*4 + 3]
  18.         transparency_bytes.append(transparency_byte)
  19.         if transparency_byte == '\x00':
  20.             if transparent_color != -1:
  21.                 print 'More than one transparent color.'
  22.                 print 'First transparent color was %s.' % hex(transparent_color)
  23.                 print 'Second transparent color was %s.' % hex(x)
  24.                 quit()
  25.             transparent_color = x
  26.     print 'Transparent color is %s: %s.' % \
  27.           (hex(transparent_color), \
  28.            filedata[0x36 + transparent_color*4:\
  29.                     0x36 + (transparent_color + 1)*4].encode('hex'))
  30.     transparent_color = filedata[0x36 + transparent_color*4:\
  31.                                  0x36 + transparent_color*4 + 3]
  32.  
  33.     filedata = get_data(filename + '.bmp')
  34.     pos = 0x36
  35.     colortable = []
  36.     transparent_color_flag = False
  37.     for x in range(256):
  38.         color = filedata[pos + x*4:pos + x*4 + 3]
  39.         if color == transparent_color:
  40.             if transparent_color_flag == True:
  41.                 print 'Multiple transparent colors.'
  42.                 quit()
  43.             transparent_color_flag = True
  44.             colortable.append(color + '\x00')
  45.         else:
  46.             colortable.append(color + '\xff')
  47.  
  48.     if not transparent_color_flag:
  49.         print 'No transparent color.'
  50.         quit()
  51.  
  52.     outfile = open(filename + '.bmp','wb')
  53.     outfile.write(filedata[:0x36] + "".join(colortable) + filedata[0x436:])
  54.     outfile.close()
  55.     print 'Updated %s.' % (filename + '.bmp')
  56. sys.argv.append('title01')
  57. myprogram(sys.argv[1])
RAW Paste Data