support for format 2

This commit is contained in:
josch 2014-03-16 13:30:26 +01:00
parent 4e0732b75a
commit 5b45233b5e
2 changed files with 21 additions and 12 deletions

View file

@ -93,10 +93,13 @@ def extract_def(infile,outdir,shred=True):
pixeldata += length*chr(code) pixeldata += length*chr(code)
totalrowlength+=length totalrowlength+=length
elif fmt == 2: elif fmt == 2:
coff, = struct.unpack("<H", f.read(2)) lineoffs = struct.unpack("<%dH"%h, f.read(2*h))
coff += 32 # unknown
f.seek(coff) _,_ = struct.unpack("<BB", f.read(2))
for i in range(h): for lineoff in lineoffs:
if f.tell() != offs+32+lineoff:
print "unexpected offset: %d, expected %d"%(f.tell(),offs+32+lineoff)
f.seek(offs+32+lineoff)
totalrowlength=0 totalrowlength=0
while totalrowlength<w: while totalrowlength<w:
segment, = struct.unpack("<B", f.read(1)) segment, = struct.unpack("<B", f.read(1))

View file

@ -209,8 +209,8 @@ def makedef(indir, outdir):
# 4*height bytes for lineoffsets # 4*height bytes for lineoffsets
curoffset += 32+4*h+sum(len(d) for d in data) curoffset += 32+4*h+sum(len(d) for d in data)
elif fmt == 2: elif fmt == 2:
# two bytes for the header # 2*height bytes for lineoffsets plus two unknown bytes
curoffset += 32+2+sum(len(d) for d in data) curoffset += 32+2*h+2+sum(len(d) for d in data)
elif fmt == 3: elif fmt == 3:
# width/16 bytes per line as offset header # width/16 bytes per line as offset header
curoffset += 32+(w/16)*h+sum(len(d) for d in data) curoffset += 32+(w/16)*h+sum(len(d) for d in data)
@ -240,13 +240,19 @@ def makedef(indir, outdir):
for i in data: for i in data:
outf.write(i) outf.write(i)
elif fmt == 2: elif fmt == 2:
s = 2+sum(len(d) for d in data) s = 2*h+2+sum(len(d) for d in data)
outf.write(struct.pack("<IIIIIIii",s,fmt,fw,fh,w,h,lm,tm)) outf.write(struct.pack("<IIIIIIii",s,fmt,fw,fh,w,h,lm,tm))
offs = outf.tell()-32+2 lineoffs = []
if offs > ushrtmax: acc = 0
print "exceeding max ushort value: %d"%offs for d in data:
return False offs = acc+2*h+2
outf.write(struct.pack("<H",offs)) if offs > ushrtmax:
print "exceeding max ushort value: %d"%offs
return False
lineoffs.append(offs)
acc += len(d)
outf.write(struct.pack("<%dH"%h, *lineoffs))
outf.write(struct.pack("<BB", 0, 0)) # unknown function
for i in data: for i in data:
outf.write(i) outf.write(i)
elif fmt == 3: elif fmt == 3: