コード例 #1
0
    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
コード例 #2
0
ファイル: mappy.py プロジェクト: 071300726/tiled
  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
コード例 #3
0
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
コード例 #4
0
ファイル: mappy.py プロジェクト: tjoen/tiled
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
コード例 #5
0
 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))
コード例 #6
0
ファイル: mappy.py プロジェクト: 071300726/tiled
 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))