All pastes #442304 Raw Edit

Stuff

public python v1 · immutable
·published 2007-04-16 03:58 UTC
rendered paste body
import sys, struct, arraybmpheader1 = [0x00, 0x00, 0x00, 0x00, 0x36, 0x04, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00]bmpheader2 = [0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00]bmpheader3 = [		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,		0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00,		0x80, 0x00, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0x00,		0xC0, 0xDC, 0xC0, 0x00, 0xF0, 0xCA, 0xA6, 0x00, 0x00, 0x20, 0x40, 0x00,		0x00, 0x20, 0x60, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, 0x20, 0xA0, 0x00,		0x00, 0x20, 0xC0, 0x00, 0x00, 0x20, 0xE0, 0x00, 0x00, 0x40, 0x00, 0x00,		0x00, 0x40, 0x20, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x40, 0x60, 0x00,		0x00, 0x40, 0x80, 0x00, 0x00, 0x40, 0xA0, 0x00, 0x00, 0x40, 0xC0, 0x00,		0x00, 0x40, 0xE0, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x60, 0x20, 0x00,		0x00, 0x60, 0x40, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x60, 0x80, 0x00,		0x00, 0x60, 0xA0, 0x00, 0x00, 0x60, 0xC0, 0x00, 0x00, 0x60, 0xE0, 0x00,		0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x20, 0x00, 0x00, 0x80, 0x40, 0x00,		0x00, 0x80, 0x60, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0xA0, 0x00,		0x00, 0x80, 0xC0, 0x00, 0x00, 0x80, 0xE0, 0x00, 0x00, 0xA0, 0x00, 0x00,		0x00, 0xA0, 0x20, 0x00, 0x00, 0xA0, 0x40, 0x00, 0x00, 0xA0, 0x60, 0x00,		0x00, 0xA0, 0x80, 0x00, 0x00, 0xA0, 0xA0, 0x00, 0x00, 0xA0, 0xC0, 0x00,		0x00, 0xA0, 0xE0, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0xC0, 0x20, 0x00,		0x00, 0xC0, 0x40, 0x00, 0x00, 0xC0, 0x60, 0x00, 0x00, 0xC0, 0x80, 0x00,		0x00, 0xC0, 0xA0, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xE0, 0x00,		0x00, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x20, 0x00, 0x00, 0xE0, 0x40, 0x00,		0x00, 0xE0, 0x60, 0x00, 0x00, 0xE0, 0x80, 0x00, 0x00, 0xE0, 0xA0, 0x00,		0x00, 0xE0, 0xC0, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x40, 0x00, 0x00, 0x00,		0x40, 0x00, 0x20, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x60, 0x00,		0x40, 0x00, 0x80, 0x00, 0x40, 0x00, 0xA0, 0x00, 0x40, 0x00, 0xC0, 0x00,		0x40, 0x00, 0xE0, 0x00, 0x40, 0x20, 0x00, 0x00, 0x40, 0x20, 0x20, 0x00,		0x40, 0x20, 0x40, 0x00, 0x40, 0x20, 0x60, 0x00, 0x40, 0x20, 0x80, 0x00,		0x40, 0x20, 0xA0, 0x00, 0x40, 0x20, 0xC0, 0x00, 0x40, 0x20, 0xE0, 0x00,		0x40, 0x40, 0x00, 0x00, 0x40, 0x40, 0x20, 0x00, 0x40, 0x40, 0x40, 0x00,		0x40, 0x40, 0x60, 0x00, 0x40, 0x40, 0x80, 0x00, 0x40, 0x40, 0xA0, 0x00,		0x40, 0x40, 0xC0, 0x00, 0x40, 0x40, 0xE0, 0x00, 0x40, 0x60, 0x00, 0x00,		0x40, 0x60, 0x20, 0x00, 0x40, 0x60, 0x40, 0x00, 0x40, 0x60, 0x60, 0x00,		0x40, 0x60, 0x80, 0x00, 0x40, 0x60, 0xA0, 0x00, 0x40, 0x60, 0xC0, 0x00,		0x40, 0x60, 0xE0, 0x00, 0x40, 0x80, 0x00, 0x00, 0x40, 0x80, 0x20, 0x00,		0x40, 0x80, 0x40, 0x00, 0x40, 0x80, 0x60, 0x00, 0x40, 0x80, 0x80, 0x00,		0x40, 0x80, 0xA0, 0x00, 0x40, 0x80, 0xC0, 0x00, 0x40, 0x80, 0xE0, 0x00,		0x40, 0xA0, 0x00, 0x00, 0x40, 0xA0, 0x20, 0x00, 0x40, 0xA0, 0x40, 0x00,		0x40, 0xA0, 0x60, 0x00, 0x40, 0xA0, 0x80, 0x00, 0x40, 0xA0, 0xA0, 0x00,		0x40, 0xA0, 0xC0, 0x00, 0x40, 0xA0, 0xE0, 0x00, 0x40, 0xC0, 0x00, 0x00,		0x40, 0xC0, 0x20, 0x00, 0x40, 0xC0, 0x40, 0x00, 0x40, 0xC0, 0x60, 0x00,		0x40, 0xC0, 0x80, 0x00, 0x40, 0xC0, 0xA0, 0x00, 0x40, 0xC0, 0xC0, 0x00,		0x40, 0xC0, 0xE0, 0x00, 0x40, 0xE0, 0x00, 0x00, 0x40, 0xE0, 0x20, 0x00,		0x40, 0xE0, 0x40, 0x00, 0x40, 0xE0, 0x60, 0x00, 0x40, 0xE0, 0x80, 0x00,		0x40, 0xE0, 0xA0, 0x00, 0x40, 0xE0, 0xC0, 0x00, 0x40, 0xE0, 0xE0, 0x00,		0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x20, 0x00, 0x80, 0x00, 0x40, 0x00,		0x80, 0x00, 0x60, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0xA0, 0x00,		0x80, 0x00, 0xC0, 0x00, 0x80, 0x00, 0xE0, 0x00, 0x80, 0x20, 0x00, 0x00,		0x80, 0x20, 0x20, 0x00, 0x80, 0x20, 0x40, 0x00, 0x80, 0x20, 0x60, 0x00,		0x80, 0x20, 0x80, 0x00, 0x80, 0x20, 0xA0, 0x00, 0x80, 0x20, 0xC0, 0x00,		0x80, 0x20, 0xE0, 0x00, 0x80, 0x40, 0x00, 0x00, 0x80, 0x40, 0x20, 0x00,		0x80, 0x40, 0x40, 0x00, 0x80, 0x40, 0x60, 0x00, 0x80, 0x40, 0x80, 0x00,		0x80, 0x40, 0xA0, 0x00, 0x80, 0x40, 0xC0, 0x00, 0x80, 0x40, 0xE0, 0x00,		0x80, 0x60, 0x00, 0x00, 0x80, 0x60, 0x20, 0x00, 0x80, 0x60, 0x40, 0x00,		0x80, 0x60, 0x60, 0x00, 0x80, 0x60, 0x80, 0x00, 0x80, 0x60, 0xA0, 0x00,		0x80, 0x60, 0xC0, 0x00, 0x80, 0x60, 0xE0, 0x00, 0x80, 0x80, 0x00, 0x00,		0x80, 0x80, 0x20, 0x00, 0x80, 0x80, 0x40, 0x00, 0x80, 0x80, 0x60, 0x00,		0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0xA0, 0x00, 0x80, 0x80, 0xC0, 0x00,		0x80, 0x80, 0xE0, 0x00, 0x80, 0xA0, 0x00, 0x00, 0x80, 0xA0, 0x20, 0x00,		0x80, 0xA0, 0x40, 0x00, 0x80, 0xA0, 0x60, 0x00, 0x80, 0xA0, 0x80, 0x00,		0x80, 0xA0, 0xA0, 0x00, 0x80, 0xA0, 0xC0, 0x00, 0x80, 0xA0, 0xE0, 0x00,		0x80, 0xC0, 0x00, 0x00, 0x80, 0xC0, 0x20, 0x00, 0x80, 0xC0, 0x40, 0x00,		0x80, 0xC0, 0x60, 0x00, 0x80, 0xC0, 0x80, 0x00, 0x80, 0xC0, 0xA0, 0x00,		0x80, 0xC0, 0xC0, 0x00, 0x80, 0xC0, 0xE0, 0x00, 0x80, 0xE0, 0x00, 0x00,		0x80, 0xE0, 0x20, 0x00, 0x80, 0xE0, 0x40, 0x00, 0x80, 0xE0, 0x60, 0x00,		0x80, 0xE0, 0x80, 0x00, 0x80, 0xE0, 0xA0, 0x00, 0x80, 0xE0, 0xC0, 0x00,		0x80, 0xE0, 0xE0, 0x00, 0xC0, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x20, 0x00,		0xC0, 0x00, 0x40, 0x00, 0xC0, 0x00, 0x60, 0x00, 0xC0, 0x00, 0x80, 0x00,		0xC0, 0x00, 0xA0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xE0, 0x00,		0xC0, 0x20, 0x00, 0x00, 0xC0, 0x20, 0x20, 0x00, 0xC0, 0x20, 0x40, 0x00,		0xC0, 0x20, 0x60, 0x00, 0xC0, 0x20, 0x80, 0x00, 0xC0, 0x20, 0xA0, 0x00,		0xC0, 0x20, 0xC0, 0x00, 0xC0, 0x20, 0xE0, 0x00, 0xC0, 0x40, 0x00, 0x00,		0xC0, 0x40, 0x20, 0x00, 0xC0, 0x40, 0x40, 0x00, 0xC0, 0x40, 0x60, 0x00,		0xC0, 0x40, 0x80, 0x00, 0xC0, 0x40, 0xA0, 0x00, 0xC0, 0x40, 0xC0, 0x00,		0xC0, 0x40, 0xE0, 0x00, 0xC0, 0x60, 0x00, 0x00, 0xC0, 0x60, 0x20, 0x00,		0xC0, 0x60, 0x40, 0x00, 0xC0, 0x60, 0x60, 0x00, 0xC0, 0x60, 0x80, 0x00,		0xC0, 0x60, 0xA0, 0x00, 0xC0, 0x60, 0xC0, 0x00, 0xC0, 0x60, 0xE0, 0x00,		0xC0, 0x80, 0x00, 0x00, 0xC0, 0x80, 0x20, 0x00, 0xC0, 0x80, 0x40, 0x00,		0xC0, 0x80, 0x60, 0x00, 0xC0, 0x80, 0x80, 0x00, 0xC0, 0x80, 0xA0, 0x00,		0xC0, 0x80, 0xC0, 0x00, 0xC0, 0x80, 0xE0, 0x00, 0xC0, 0xA0, 0x00, 0x00,		0xC0, 0xA0, 0x20, 0x00, 0xC0, 0xA0, 0x40, 0x00, 0xC0, 0xA0, 0x60, 0x00,		0xC0, 0xA0, 0x80, 0x00, 0xC0, 0xA0, 0xA0, 0x00, 0xC0, 0xA0, 0xC0, 0x00,		0xC0, 0xA0, 0xE0, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0x20, 0x00,		0xC0, 0xC0, 0x40, 0x00, 0xC0, 0xC0, 0x60, 0x00, 0xC0, 0xC0, 0x80, 0x00,		0xC0, 0xC0, 0xA0, 0x00, 0xF0, 0xFB, 0xFF, 0x00, 0xA4, 0xA0, 0xA0, 0x00,		0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00,		0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00,		0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00]def get_int(s):	return struct.unpack("=I",s)[0]	def get_char(s):	return struct.unpack("=B",s)[0]    def get_short(s):	return struct.unpack("=H",s)[0]def give_long(s):    return struct.pack("=L", s)    def usage():    print sys.argv[0], "FOOBAR.MAP FOOBAR.BMP"      if len(sys.argv) < 3:    usage()    sys.exit()try:    fp_map = open(sys.argv[1], "rb")except IOError:    print "File", sys.argv[1], "does not exist!"    sys.exit()fp_map.seek(0, 2)map_filesize = fp_map.tell()fp_map.seek(0, 0)    fp_map.seek(4, 1) #skip 4 bytes    #read the .map width and heightmap_width = get_short(fp_map.read(2))map_height = get_short(fp_map.read(2))print sys.argv[1], "size has %i width and %i height." % (map_width, map_height)ico_filename = "%s.ICO" % (sys.argv[1][:2])print "Trying to find %s..." % (ico_filename),try:    fp_ico = open(ico_filename, "rb")except IOError:    print "File", ico_filename, "does not exist!"    sys.exit()    print "found!"fp_ico.seek(0, 2)ico_filesize = fp_ico.tell()fp_ico.seek(0, 0)print "%s has %i bytes or 16*16 %i images." % (ico_filename, ico_filesize, ico_filesize / 256)ico_buffer = []out_buffer = []while(fp_ico.tell() < ico_filesize):    ico_buffer.append(fp_ico.read(256))print "ICO images found:", len(ico_buffer)#skip last magic bytefp_map.seek(2, 1)#print fp_map.tell()row = 1while fp_map.tell() < map_filesize:         map_buffer = fp_map.read(map_width) #read width bytes        for i in range(0, map_width, 2):        try:            ico_id = get_short(map_buffer[i:i+2])        except:               print "ERROR! - Offset:", map_width*row+i                        #print row, i, ico_id                if ico_id > (ico_filesize / 256):            ico_id = get_char(map_buffer[i:i+1])          try:            ico_data = ico_buffer[ico_id]        except IndexError:            print "ERROR: Index out of bounds -", ico_id                out_buffer.append(ico_data)            row += 1    print "BUFFER size:", len(out_buffer)    #open the destination bmp filetry:    fp_bmp = open(sys.argv[2], "wb")except IOError:    print "File", sys.argv[2], "could not be opened!"    sys.exit()#last step - write the data to bmp bufferfp_bmp.write("BM")bmp_filesize = 16*16*map_width*map_height+1078fp_bmp.write(give_long(bmp_filesize)) #write total bmp file size#fp_bmp.write(bmpheader1))a = array.array('H')a.fromlist(bmpheader1)a.tofile(fp_bmp)del(a)fp_bmp.write(give_long(16*map_width))fp_bmp.write(give_long(16*map_height))#fp_bmp.write(''.join(bmpheader2))a = array.array('H')a.fromlist(bmpheader2)a.tofile(fp_bmp)del(a)fp_bmp.write(give_long(map_height*map_height))#fp_bmp.write(''.join(bmpheader3))a = array.array('H')a.fromlist(bmpheader3)a.tofile(fp_bmp)del(a)for e in range(map_height):    for f in range(0, 256, 16):        for g in range(map_width):            fp_bmp.write(out_buffer[(e*g)+g][f:f+16])