self.mode = "P" self.palette = ImagePalette.raw("RGB", string.join(palette, "")) self.tile = [("raw", (0, 0)+self.size, self.fp.tell(), ("P", 0, 1))] def load_read(self, bytes): # # load all image data in one chunk xsize, ysize = self.size s = [None] * ysize for i in range(ysize): s[i] = string.ljust(self.fp.readline()[1:xsize+1], xsize) self.fp = None return string.join(s, "") # # Registry Image.register_open("XPM", XpmImageFile, _accept) Image.register_extension("XPM", ".xpm") Image.register_mime("XPM", "image/xpm")
op.write("q %d 0 0 %d 0 0 cm /image Do Q\n" % (int(width * 72.0 / resolution), int(height * 72.0 / resolution))) xref[5] = fp.tell() _obj(fp, 5, Length=len(op.getvalue())) fp.write("stream\n") fp.write(op.getvalue()) fp.write("\nendstream\n") _endobj(fp) # # trailer startxref = fp.tell() fp.write("xref\n0 %d\n0000000000 65535 f \n" % len(xref)) for x in xref[1:]: fp.write("%010d 00000 n \n" % x) fp.write("trailer\n<<\n/Size %d\n/Root 1 0 R\n>>\n" % len(xref)) fp.write("startxref\n%d\n%%%%EOF\n" % startxref) fp.flush() # # -------------------------------------------------------------------- Image.register_save("PDF", _save) Image.register_extension("PDF", ".pdf") Image.register_mime("PDF", "application/pdf")
## # Image plugin for MPEG streams. This plugin can identify a stream, # but it cannot read it. class MpegImageFile(ImageFile.ImageFile): format = "MPEG" format_description = "MPEG" def _open(self): s = BitStream(self.fp) if s.read(32) != 0x1B3: raise SyntaxError, "not an MPEG file" self.mode = "RGB" self.size = s.read(12), s.read(12) # -------------------------------------------------------------------- # Registry stuff Image.register_open("MPEG", MpegImageFile) Image.register_extension("MPEG", ".mpg") Image.register_extension("MPEG", ".mpeg") Image.register_mime("MPEG", "video/mpeg")
(int(width * 72.0 / resolution), int(height * 72.0 / resolution))) xref[5] = fp.tell() _obj(fp, 5, Length=len(op.getvalue())) fp.write("stream\n") fp.write(op.getvalue()) fp.write("\nendstream\n") _endobj(fp) # # trailer startxref = fp.tell() fp.write("xref\n0 %d\n0000000000 65535 f \n" % len(xref)) for x in xref[1:]: fp.write("%010d 00000 n \n" % x) fp.write("trailer\n<<\n/Size %d\n/Root 1 0 R\n>>\n" % len(xref)) fp.write("startxref\n%d\n%%%%EOF\n" % startxref) fp.flush() # # -------------------------------------------------------------------- Image.register_save("PDF", _save) Image.register_extension("PDF", ".pdf") Image.register_mime("PDF", "application/pdf")
extra, ) ImageFile._save(im, fp, [("jpeg", (0, 0) + im.size, 0, rawmode)]) def _save_cjpeg(im, fp, filename): # ALTERNATIVE: handle JPEGs via the IJG command line utilities. import os file = im._dump() os.system("cjpeg %s >%s" % (file, filename)) try: os.unlink(file) except: pass # -------------------------------------------------------------------q- # Registry stuff Image.register_open("JPEG", JpegImageFile, _accept) Image.register_save("JPEG", _save) Image.register_extension("JPEG", ".jfif") Image.register_extension("JPEG", ".jpe") Image.register_extension("JPEG", ".jpg") Image.register_extension("JPEG", ".jpeg") Image.register_mime("JPEG", "image/jpeg")
fp.write(o16b(offset)) fp.write(chr(transparent_index)) fp.write(chr(compression_type)) fp.write(o16b(0)) # reserved by Palm # now write colormap if necessary if colormapsize > 0: fp.write(o16b(256)) for i in range(256): fp.write(chr(i)) if colormapmode == 'RGB': fp.write(chr(colormap[3 * i]) + chr(colormap[3 * i + 1]) + chr(colormap[3 * i + 2])) elif colormapmode == 'RGBA': fp.write(chr(colormap[4 * i]) + chr(colormap[4 * i + 1]) + chr(colormap[4 * i + 2])) # now convert data to raw form ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, rowbytes, 1))]) fp.flush() # # -------------------------------------------------------------------- Image.register_save("Palm", _save) Image.register_extension("Palm", ".palm") Image.register_mime("Palm", "image/palm")
def append(self, chunk): self.data.append(chunk) def append(fp, cid, *data): data = string.join(data, "") hi, lo = Image.core.crc32(data, Image.core.crc32(cid)) crc = o16(hi) + o16(lo) fp.append((cid, data, crc)) fp = collector() try: im.encoderinfo = params _save(im, fp, None, append) finally: del im.encoderinfo return fp.data # -------------------------------------------------------------------- # Registry Image.register_open("PNG", PngImageFile, _accept) Image.register_save("PNG", _save) Image.register_extension("PNG", ".png") Image.register_mime("PNG", "image/png")
print cid, bytes, "(unknown)" s = self.fp.read(bytes) self.arg.crc(cid, s) self.fp.read(4) # ship extra CRC def tell(self): return 0 def verify(self): "Verify ARG file" # back up to first chunk self.fp.seek(8) self.arg.verify(self) self.arg.close() self.fp = None # # -------------------------------------------------------------------- Image.register_open("ARG", ArgImageFile, _accept) Image.register_extension("ARG", ".arg") Image.register_mime("ARG", "video/x-arg")
# data orientation stride = len(bits) * ((im.size[0]*bits[0]+7)/8) ifd[ROWSPERSTRIP] = im.size[1] ifd[STRIPBYTECOUNTS] = stride * im.size[1] ifd[STRIPOFFSETS] = 0 # this is adjusted by IFD writer ifd[COMPRESSION] = 1 # no compression offset = ifd.save(fp) ImageFile._save(im, fp, [ ("raw", (0,0)+im.size, offset, (rawmode, stride, 1)) ]) # -- helper for multi-page save -- if im.encoderinfo.has_key("_debug_multipage"): #just to access o32 and o16 (using correct byte order) im._debug_multipage = ifd # # -------------------------------------------------------------------- # Register Image.register_open("TIFF", TiffImageFile, _accept) Image.register_save("TIFF", _save) Image.register_extension("TIFF", ".tif") Image.register_extension("TIFF", ".tiff") Image.register_mime("TIFF", "image/tiff")
o16(offset[0]) + # offset o16(offset[1]) + o16(im.size[0]) + # size o16(im.size[1]) + chr(0) + # flags chr(8)) # bits ImageFile._save(im, fp, [("gif", (0,0)+im.size, 0, RAWMODE[im.mode])]) fp.write("\0") # end of image data finally: del im.encoderinfo return fp.data # -------------------------------------------------------------------- # Registry Image.register_open(GifImageFile.format, GifImageFile, _accept) Image.register_save(GifImageFile.format, _save) Image.register_extension(GifImageFile.format, ".gif") Image.register_mime(GifImageFile.format, "image/gif") # # Uncomment the following line if you wish to use NETPBM/PBMPLUS # instead of the built-in "uncompressed" GIF encoder # Image.register_save(GifImageFile.format, _save_netpbm)
self.tile = [("xbm", (0, 0) + self.size, m.end(), None)] def _save(im, fp, filename): if im.mode != "1": raise IOError, "cannot write mode %s as XBM" % im.mode fp.write("#define im_width %d\n" % im.size[0]) fp.write("#define im_height %d\n" % im.size[1]) hotspot = im.encoderinfo.get("hotspot") if hotspot: fp.write("#define im_x_hot %d\n" % hotspot[0]) fp.write("#define im_y_hot %d\n" % hotspot[1]) fp.write("static char im_bits[] = {\n") ImageFile._save(im, fp, [("xbm", (0, 0) + im.size, 0, None)]) fp.write("};\n") Image.register_open("XBM", XbmImageFile, _accept) Image.register_save("XBM", _save) Image.register_extension("XBM", ".xbm") Image.register_mime("XBM", "image/xbm")
# now write colormap if necessary if colormapsize > 0: fp.write(o16b(256)) for i in range(256): fp.write(chr(i)) if colormapmode == 'RGB': fp.write( chr(colormap[3 * i]) + chr(colormap[3 * i + 1]) + chr(colormap[3 * i + 2])) elif colormapmode == 'RGBA': fp.write( chr(colormap[4 * i]) + chr(colormap[4 * i + 1]) + chr(colormap[4 * i + 2])) # now convert data to raw form ImageFile._save(im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, rowbytes, 1))]) fp.flush() # # -------------------------------------------------------------------- Image.register_save("Palm", _save) Image.register_extension("Palm", ".palm") Image.register_mime("Palm", "image/palm")
self.tile = [("xbm", (0, 0)+self.size, m.end(), None)] def _save(im, fp, filename): if im.mode != "1": raise IOError, "cannot write mode %s as XBM" % im.mode fp.write("#define im_width %d\n" % im.size[0]) fp.write("#define im_height %d\n" % im.size[1]) hotspot = im.encoderinfo.get("hotspot") if hotspot: fp.write("#define im_x_hot %d\n" % hotspot[0]) fp.write("#define im_y_hot %d\n" % hotspot[1]) fp.write("static char im_bits[] = {\n") ImageFile._save(im, fp, [("xbm", (0,0)+im.size, 0, None)]) fp.write("};\n") Image.register_open("XBM", XbmImageFile, _accept) Image.register_save("XBM", _save) Image.register_extension("XBM", ".xbm") Image.register_mime("XBM", "image/xbm")
subsampling, extra, ) ImageFile._save(im, fp, [("jpeg", (0, 0) + im.size, 0, rawmode)]) def _save_cjpeg(im, fp, filename): # ALTERNATIVE: handle JPEGs via the IJG command line utilities. import os file = im._dump() os.system("cjpeg %s >%s" % (file, filename)) try: os.unlink(file) except: pass # -------------------------------------------------------------------q- # Registry stuff Image.register_open("JPEG", JpegImageFile, _accept) Image.register_save("JPEG", _save) Image.register_extension("JPEG", ".jfif") Image.register_extension("JPEG", ".jpe") Image.register_extension("JPEG", ".jpg") Image.register_extension("JPEG", ".jpeg") Image.register_mime("JPEG", "image/jpeg")
if Image.DEBUG: print cid, bytes, "(unknown)" s = self.fp.read(bytes) self.arg.crc(cid, s) self.fp.read(4) # ship extra CRC def tell(self): return 0 def verify(self): "Verify ARG file" # back up to first chunk self.fp.seek(8) self.arg.verify(self) self.arg.close() self.fp = None # # -------------------------------------------------------------------- Image.register_open("ARG", ArgImageFile, _accept) Image.register_extension("ARG", ".arg") Image.register_mime("ARG", "video/x-arg")
self.mode = "P" self.palette = ImagePalette.raw("RGB", string.join(palette, "")) self.tile = [("raw", (0, 0) + self.size, self.fp.tell(), ("P", 0, 1))] def load_read(self, bytes): # # load all image data in one chunk xsize, ysize = self.size s = [None] * ysize for i in range(ysize): s[i] = string.ljust(self.fp.readline()[1:xsize + 1], xsize) self.fp = None return string.join(s, "") # # Registry Image.register_open("XPM", XpmImageFile, _accept) Image.register_extension("XPM", ".xpm") Image.register_mime("XPM", "image/xpm")