def ric_decode(imgbuf):
    offset = 0
    boxType = None
    boxLen, boxType, payload = iso_media.read_box(imgbuf[offset:])
    if boxType != "FTYP" or payload != "RIC ":
        print >> sys.stderr, "Fishy file type!!!", boxType, payload
        return None
    offset += boxLen
    boxLen, boxType, payload = iso_media.read_box(imgbuf[offset:])
    if boxType != "ILOT":
        print >> sys.stderr, "No offset table???", boxType
        return None
    offset += boxLen
    layers = wrapper.unwrapLayers(imgbuf[offset:])
    outputImg = Decoder().decode(layers)
    output = StringIO()
    outputImg.save(output, "JPEG", quality = 90);
    return output.getvalue()
Beispiel #2
0
def ric_decode(imgbuf):
    offset = 0
    boxType = None
    boxLen, boxType, payload = iso_media.read_box(imgbuf[offset:])
    if boxType != "FTYP" or payload != "RIC ":
        print >> sys.stderr, "Fishy file type!!!", boxType, payload
        return None
    offset += boxLen
    boxLen, boxType, payload = iso_media.read_box(imgbuf[offset:])
    if boxType != "ILOT":
        print >> sys.stderr, "No offset table???", boxType
        return None
    offset += boxLen
    layers = wrapper.unwrapLayers(imgbuf[offset:])
    outputImg = Decoder().decode(layers)
    output = StringIO()
    outputImg.save(output, "JPEG", quality=90)
    return output.getvalue()
def unwrapLayers(buf):
    def readImageBuffer(imgbuf, type):
        offset = 0
        parameters = []
        for i in range(params_num[type]):
            parameters.append((iso_media.read_int16(imgbuf[offset:]),
                               iso_media.read_int16(imgbuf[offset + 2:])))
            offset += 4

        io = StringIO(imgbuf[offset:])
        img = Image.open(io)
        io.close()
        return img, parameters

    bufLen = len(buf)
    offset = 0
    layers = []
    while offset < bufLen:
        boxLen, boxType, payload = iso_media.read_box(buf[offset:])
        offset += boxLen
        layers.append(readImageBuffer(payload, boxType))

    return layers
def unwrapLayers(buf):
    def readImageBuffer(imgbuf, type):
        offset = 0
        parameters = []
        for i in range(params_num[type]):
            parameters.append((iso_media.read_int16(imgbuf[offset:]),
                               iso_media.read_int16(imgbuf[offset+2:])))
            offset += 4



        io = StringIO(imgbuf[offset:])
        img = Image.open(io)
        io.close()
        return img, parameters
    bufLen = len(buf)
    offset = 0
    layers = []
    while offset < bufLen:
        boxLen, boxType, payload = iso_media.read_box(buf[offset:])
        offset += boxLen
        layers.append(readImageBuffer(payload, boxType))

    return layers
 def testRead(self):
     data1 = "\x00\x00\x00\x0bftypbla"
     length, type, payload = iso_media.read_box(data1)
     self.failUnless(length == 11)
     self.failUnless(type == "ftyp")
     self.failUnless(payload == "bla")
 def testRead(self):
     data1 = "\x00\x00\x00\x0bftypbla"
     length, type, payload = iso_media.read_box(data1)
     self.failUnless(length == 11)
     self.failUnless(type == "ftyp")
     self.failUnless(payload == "bla")