#!/usr/bin/env python # http://aethra-cronicles-remake.googlecode.com/svn-history/r4/trunk/export/sergroj/RSDef.pas # vcmi/client/CAnimation.cpp import struct from PIL import Image, ImageDraw from collections import defaultdict import os from common import crc24_func, font, sanitize_filename def get_color(fname): crc = crc24_func(fname) # values 0-7 must not be used as they might represent transparency # so we are left with 248 values return 8+crc%248 def extract_def(infile,outdir,shred=True): f = open(infile) bn = os.path.basename(infile) bn = os.path.splitext(bn)[0] # t - type # blocks - # of blocks # the second and third entry are width and height which are not used t,_,_,blocks = struct.unpack(" 9: # truncate name name = bn[:9-len(num)]+num else: name = bn+num k+=1 names.append(name) # a list of offsets for n in names: offs, = struct.unpack(" fw or tm > fh: print "margins (%dx%d) are higher than dimensions (%dx%d)"%(lm,tm,fw,fh) return False lineoffs = struct.unpack("<"+"I"*h, f.read(4*h)) for lineoff in lineoffs: f.seek(offs+32+lineoff) totalrowlength=0 while totalrowlength 7: pixels[i,j] = color im.putpalette(palette) im.save(outname) return True if __name__ == '__main__': import sys if len(sys.argv) != 3: print "usage: %s input.def ./outdir"%sys.argv[0] print "to process all files:" print " for f in *.def; do n=`basename $f .def`; mkdir -p defs/$n; %s defextract.py $f defs/$n; done"%sys.argv[0] exit(1) ret = extract_def(sys.argv[1], sys.argv[2]) exit(0 if ret else 1)