def chunk_DHDR(self, offset, bytes): "DHDR -- delta image follows" # assertions if self.count == 0: raise SyntaxError("misplaced DHDR chunk") s = self.fp.read(bytes) size, mode, rawmode = self.__getmodesize(s) # delta header diff = i8(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 = ("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
def __getmodesize(self, s, full=1): size = i32(s), i32(s[4:]) try: mode, rawmode = _MODES[(i8(s[8]), i8(s[9]))] except: raise SyntaxError("unknown image mode") if full: if i8(s[12]): pass # interlace not yet supported if i8(s[11]): raise SyntaxError("unknown filter category") return size, mode, rawmode
def chunk_AHDR(self, offset, bytes): "AHDR -- animation header" # assertions if self.count != 0: raise SyntaxError("misplaced AHDR chunk") s = self.fp.read(bytes) self.size = i32(s), i32(s[4:]) try: self.mode, self.rawmode = _MODES[(i8(s[8]), i8(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
def chunk_PAST(self, offset, bytes): "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(bytes) 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 ["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 = ("PAST",) self.__store() return s