Exemplo n.º 1
0
    sig = fobj.read(4)
    if sig != '\x00\x00\x00\x00':
        raise SyntaxError, 'Unknown signature, expecting 0x00000000'
    return read_32(fobj, (start + 4, length - 4), (width, height))

def read_32(fobj, (start, length), size):
    """
    Read a 32bit RGB icon resource.  Seems to be either uncompressed or
    an RLE packbits-like scheme.
    """
    fobj.seek(start)
    sizesq = size[0] * size[1]
    if length == sizesq * 3:
        # uncompressed ("RGBRGBGB")
        indata = fobj.read(length)
        im = Image.frombuffer("RGB", size, indata, "raw", "RGB", 0, 1)
    else:
        # decode image
        im = Image.new("RGB", size, None)
        for band_ix in range(3):
            data = []
            bytesleft = sizesq
            while bytesleft > 0:
                byte = fobj.read(1)
                if not byte:
                    break
                byte = ord(byte)
                if byte & 0x80:
                    blocksize = byte - 125
                    byte = fobj.read(1)
                    for i in range(blocksize):