#!/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 from collections import defaultdict import os def sanitize_filename(fname): # find the first character outside range [32-126] for i,c in enumerate(fname): if ord(c) < 32 or ord(c) > 126: break return fname[:i] def extract_def(infile,outdir): 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