Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- def get_data(filename):
- totalbytes = os.path.getsize(filename)
- infile = open(filename, 'rb')
- totalfiledata = infile.read(totalbytes)
- infile.close()
- return totalfiledata
- def myprogram(filename):
- filedata = get_data(filename + '.orig')
- pos = 0x36
- transparent_color = -1
- transparency_bytes = []
- for x in range(256):
- transparency_byte = filedata[pos + x*4 + 3]
- transparency_bytes.append(transparency_byte)
- if transparency_byte == '\x00':
- if transparent_color != -1:
- print 'More than one transparent color.'
- print 'First transparent color was %s.' % hex(transparent_color)
- print 'Second transparent color was %s.' % hex(x)
- quit()
- transparent_color = x
- print 'Transparent color is %s: %s.' % \
- (hex(transparent_color), \
- filedata[0x36 + transparent_color*4:\
- 0x36 + (transparent_color + 1)*4].encode('hex'))
- transparent_color = filedata[0x36 + transparent_color*4:\
- 0x36 + transparent_color*4 + 3]
- filedata = get_data(filename + '.bmp')
- pos = 0x36
- colortable = []
- transparent_color_flag = False
- for x in range(256):
- color = filedata[pos + x*4:pos + x*4 + 3]
- if color == transparent_color:
- if transparent_color_flag == True:
- print 'Multiple transparent colors.'
- quit()
- transparent_color_flag = True
- colortable.append(color + '\x00')
- else:
- colortable.append(color + '\xff')
- if not transparent_color_flag:
- print 'No transparent color.'
- quit()
- outfile = open(filename + '.bmp','wb')
- outfile.write(filedata[:0x36] + "".join(colortable) + filedata[0x436:])
- outfile.close()
- print 'Updated %s.' % (filename + '.bmp')
- sys.argv.append('title01')
- myprogram(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement