#!/usr/bin/env python import zlib import struct import os from PIL import Image, ImageDraw from common import crc24_func, get_complement, font def is_pcx(data): size,width,height = struct.unpack(">16 g = (crc&0xff00)>>8 b = crc&0xff w,h = im.size pixels = im.load() for i in range(w): for j in range(h): if pixels[i,j] > 7: if im.mode == 'P': pixels[i,j] = 8+crc%248 else: pixels[i,j] = (r,g,b) im.resize((w*3,h*3)) draw = ImageDraw.Draw(im) tw,th = draw.textsize(os.path.basename(filename),font=font) tpos = ((w*3-tw)/2,(h*3-th)/2) if im.mode == 'P': # we can't really have a complement in palette mode, so just get some color draw.text(tpos,os.path.basename(filename),255,font=font) else: draw.text(tpos,os.path.basename(filename),get_complement(r,g,b),font=font) im = im.resize((w,h),Image.ANTIALIAS) im.save(filename, "PNG") else: return False else: o = open(filename,"w+") o.write(data) o.close() return True if __name__ == '__main__': import sys if len(sys.argv) != 3: print "usage: %s infile.lod ./outdir"%sys.argv[0] print "" print "usually after installing the normal way:" print " %s .vcmi/Data/H3bitmap.lod .vcmi/Mods/vcmi/Data/"%sys.argv[0] print " rm .vcmi/Data/H3bitmap.lod" print " %s .vcmi/Data/H3sprite.lod .vcmi/Mods/vcmi/Data/"%sys.argv[0] print " rm .vcmi/Data/H3sprite.lod" exit(1) ret = unpack_lod(sys.argv[1], sys.argv[2]) exit(0 if ret else 1)