def unpackchunks(cls, f): chunks = OrderedDict() with open(f, 'rb') as fh: frm = fmpchunk() frm.unpack(fh) frm.data = fh.read(4) filelen = frm.len - 16 chunks[frm.id] = frm print frm while fh.tell() < filelen: fc = fmpchunk() if not fc.unpack(fh): break print fh.tell(), fc fc.data = fh.read(fc.len) chunks[fc.id] = fc return chunks
def unpackchunks(cls, f): chunks = OrderedDict() with open(f, 'rb') as fh: frm = fmpchunk() frm.unpack(fh) frm.data = fh.read(4) filelen = frm.len - 16 chunks[frm.id] = frm print frm while fh.tell() < filelen: fc = fmpchunk() if not fc.unpack(fh): break print fh.tell(), fc fc.data = fh.read(fc.len) chunks[fc.id] = fc return chunks
def readchunks(f): chunks = {} with open(f, 'rb') as fh: fc = fmpchunk() fc.unpack(fh) filelen = fc.len - 16 print fc, fh.read(4) while fh.tell() < filelen and fc.unpack(fh) != None: print fh.tell(), fc if fc.id == 'MPHD': mp = MPHD() mp.unpack(fh) realsz = struct.calcsize(mp.__fstr) #if fc.len > realsz: # raise Exception('Unread data: '+str(fc.len-realsz)) fh.read(fc.len-realsz) print mp chunks[fc.id] = mp else: chunks[fc.id] = fh.read(fc.len) return chunks
def readchunks(f): chunks = {} with open(f, 'rb') as fh: fc = fmpchunk() fc.unpack(fh) filelen = fc.len - 16 print fc, fh.read(4) while fh.tell() < filelen and fc.unpack(fh) != None: print fh.tell(), fc if fc.id == 'MPHD': mp = MPHD() mp.unpack(fh) realsz = struct.calcsize(mp.__fstr) #if fc.len > realsz: # raise Exception('Unread data: '+str(fc.len-realsz)) fh.read(fc.len - realsz) print mp chunks[fc.id] = mp else: chunks[fc.id] = fh.read(fc.len) return chunks
def pack(self, cmap): """cmap -- QImage.colorTable""" yield fmpchunk(id='CMAP', len=len(list(cmap))).pack() for c in cmap: yield struct.pack('3B', (c.qRed, c.qGreen, c.qBlue))
def pack(self, cmap): """cmap -- QImage.colorTable""" yield fmpchunk(id='CMAP', len=len(list(cmap))).pack() for c in cmap: yield struct.pack('3B', (c.qRed,c.qGreen,c.qBlue))