示例#1
0
    def chunk_DHDR(self, offset, nbytes):
        "DHDR -- delta image follows"

        # assertions
        if self.count == 0:
            raise SyntaxError("misplaced DHDR chunk")

        s = self.fp.read(nbytes)

        size, mode, rawmode = self.__getmodesize(s)

        # delta header
        diff = s[13]
        offs = i32(s[14:18]), i32(s[18:22])

        bbox = offs + (offs[0] + size[0], offs[1] + size[1])

        if Image.DEBUG:
            print("DHDR", diff, bbox)

        # FIXME: decode and apply image
        self.action = (b"DHDR", diff, bbox)

        # setup decoder
        self.im = Image.core.new(mode, size)

        self.decoder = Image.core.zip_decoder(rawmode)
        self.decoder.setimage(self.im, (0, 0) + size)

        self.data = b""

        return s
示例#2
0
    def __getmodesize(self, s, full=1):

        size = i32(s), i32(s[4:])

        try:
            mode, rawmode = _MODES[(s[8], s[9])]
        except:
            raise SyntaxError("unknown image mode")

        if full:
            if s[12]:
                pass  # interlace not yet supported
            if s[11]:
                raise SyntaxError("unknown filter category")

        return size, mode, rawmode
示例#3
0
    def chunk_AHDR(self, offset, nbytes):
        "AHDR -- animation header"

        # assertions
        if self.count != 0:
            raise SyntaxError("misplaced AHDR chunk")

        s = self.fp.read(nbytes)
        self.size = i32(s), i32(s[4:])
        try:
            self.mode, self.rawmode = _MODES[(s[8], s[9])]
        except:
            raise SyntaxError("unknown ARG mode")

        if Image.DEBUG:
            print("AHDR size", self.size)
            print("AHDR mode", self.mode, self.rawmode)

        return s
示例#4
0
    def chunk_PAST(self, offset, nbytes):
        "PAST -- paste one image into another"

        # assertions
        if self.count == 0:
            raise SyntaxError("misplaced PAST chunk")

        if self.repair is not None:
            # we must repair the target image before we
            # start pasting

            # brute force; a better solution would be to
            # update only the dirty rectangles in images[id].
            # note that if images[id] doesn't exist, it must
            # be created

            self.images[self.id] = self.images[self.repair].copy()
            self.repair = None

        s = self.fp.read(nbytes)
        im = self.images[i16(s)]
        x, y = i32(s[2:6]), i32(s[6:10])
        bbox = x, y, im.size[0] + x, im.size[1] + y

        if im.mode in [b"RGBA"]:
            # paste with transparency
            # FIXME: should handle P+transparency as well
            self.images[self.id].paste(im, bbox, im)
        else:
            # paste without transparency
            self.images[self.id].paste(im, bbox)

        self.action = (b"PAST",)
        self.__store()

        return s