Imaging-1.1.3/README0100444000076400007640000002550507444357237013642 0ustar fredrikfredrik The Python Imaging Library $Id: //modules/pil/README#9 $ Release 1.1.3 (Mar 15, 2025) ==================================================================== The Python Imaging Library 1.1.3 ==================================================================== Contents -------- + Introduction + Support Options + News Highlights + Software License + Build instructions for UNIX + Build instructions for Windows -------------------------------------------------------------------- Introduction -------------------------------------------------------------------- The Python Imaging Library (PIL) adds image processing capabilities to your Python environment. This library provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities. This source kit has been built and tested on Windows NT/2000, and a a number of Unix platforms (including Alpha, Solaris and Intel systems). We believe that it should work on most modern platforms (people are using it on Crays, after all ;-) The main distribution site for this software is: http://www.pythonware.com/products/pil/ That site also contains information about free and commercial support options, PIL add-ons, answers to frequently asked questions, and more. The PIL handbook is not included in this distribution; to get the latest version, check: http://www.pythonware.com/library/ For installation and licensing details, see below. -------------------------------------------------------------------- Support Options -------------------------------------------------------------------- + Free Support For support and general questions on the Python Imaging Library, send e-mail to the Image SIG mailing list: image-sig@python.org You can join the Image SIG by sending a mail to: image-sig-request@python.org Put "subscribe" in the message body to automatically subscribe to the list, or "help" to get additional information. Alternatively, you can send your questions to the Python mailing list, python-list@python.org, or post them to the newsgroup comp.lang.python. + Commercial Support Secret Labs (PythonWare) offers support contracts for companies using the Python Imaging Library in commercial applications, or in mission- critical environments. This includes technical support, bug fixes, extensions to the PIL library, sample applications, and more. For the full story, check: http://www.pythonware.com/products/pil/support.htm Or send a mail to: sales@pythonware.com -------------------------------------------------------------------- News Highlights in 1.1.3 (as compared to 1.0): -------------------------------------------------------------------- + Adapted to Python 1.6, 2.0, 2.1 and 2.2. This version also runs under 1.5.2, but probably not under versions older than that. + To reduce module dependencies, the Tkinter support has been moved to a separate binary module. + The JPEG decoder is more tolerant for broken files. As long as all image data can be read, it won't complain. + An ANTIALIAS downsampling filter has been added. + Includes distutils build script (setup.py) for 2.0 and later. + The usual crop of bug fixes and performance tweaks. For detailed information on these and other changes, see the CHANGES documents. -------------------------------------------------------------------- Software License -------------------------------------------------------------------- The Python Imaging Library is Copyright (c) 1997-2002 by Secret Labs AB Copyright (c) 1995-2002 by Fredrik Lundh By obtaining, using, and/or copying this software and/or its associated documentation, you agree that you have read, understood, and will comply with the following terms and conditions: Permission to use, copy, modify, and distribute this software and its associated documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies, and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Secret Labs AB or the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------- Build instructions for UNIX -------------------------------------------------------------------- NOTE: To build the Python Imaging Library, you need an ANSI C com- piler. The "cc" compiler on SunOS 4 is *not* ANSI compliant. On that platform, use "acc" or "gcc" instead. On some platforms, you may have to use compiler options like "-ansi" or "-std" to get full ANSI C support. 1. If you need JPEG and/or PNG support, make sure to get and build the necessary external libraries: - for JPEG support, get the IJG JPEG library, version 6a or 6b. You can find this library here: http://www.ijg.org ftp://ftp.uu.net/graphics/jpeg/ - for PNG and ZIP support, get the ZLIB library (by Gailly/Adler). PIL was tested with version 1.0.4, but is likely to work with versions from 0.95 and onwards. You can find this library here: http://www.info-zip.org/pub/infozip/zlib/ If you have RedHat 4.2 or newer, the libraries provided with the operating system should work just fine. 2. If you didn't build Python from sources, make sure you have Python's build support files on your machine. If you've down- loaded a prebuilt package (e.g. a Linux RPM), you probably need additional developer packages. If this doesn't mean anything to you, you can still carry out steps 3 to 5 as described below. Step 6 will probably fail, though. 3. Unpack the PIL distribution (the file Imaging-1.1.3.tar.gz) in your Python extensions directory (if you have one. If not, feel free to unpack it in any other suitable directory). $ cd Python-2.1/Extensions # example $ gunzip Imaging-1.1.3.tar.gz $ tar xvf Imaging-1.1.3.tar 4. Now build the Imaging core library (libImaging.a): $ cd Imaging-1.1.3/libImaging $ ./configure $ make If you need to specify additional compiler options, the second line should look something like: $ CC="cc -ansi" ./configure 5. When the build has finished, go back to the Imaging directory. $ cd .. 6. If you're using Python 2.0 or later, you can use the setup.py script to finish the build. The following commands should do the trick: $ python setup.py build $ python setup.py install (depending on how Python has been installed on your machine, you might have to log in as a superuser to run the 'install' command.) If the setup.py command finishes without any errors, you're done! If you have an older Python version, or if the setup.py script cannot figure out how your system is configured, you can build PIL in the traditional way, using the Setup.in file. See steps 7 through 10 below for details. 7. If you don't have the IJG JPEG or ZLIB libraries (or you have them, but not in a standard place), copy the "Setup.in" file to "Setup" and edit it according to the instructions in the file. 8. Edit Makefile.pre.in and build a Makefile following the instructions there. In most cases, you can simply give the following command: $ make -f Makefile.pre.in boot If this doesn't generate a Makefile, you probably don't have the necessary build files on your machine. See step 2 above for more information. 9. To build a dynamically loaded module, just type "make": $ make This will create two files; "_imaging.so", and "_imagingtk.so" (the latter isn't created if you commented out the Tcl/Tk inter- face section in Setup.in) Then type (assuming a standard shell): $ PYTHONPATH=.:./PIL ; export PYTHONPATH $ python >>> import _imaging >>> import Image If both imports works, you've successfully added PIL to your Python environment. To to a slightly more extensive test, you can run the MiniTest test suite: $ python MiniTest/test.py There are a few demo scripts in the Scripts directory that you can use to further test the library. 10. Copy the "_imaging.so" module, the "_imagingtk.so" module, and the contents of the "Imaging/PIL" directory to a suitable place along the Python path. If you're using Python 1.5 or later, the preferred way is to create a "PIL" subdirectory under "site-packages", copy the "PIL.pth" file to "site-packages", and the rest of the files to the new subdirectory. Example: $ cp PIL.pth /usr/local/lib/Python1.5/site-packages $ mkdir /usr/local/lib/Python1.5/site-packages/PIL $ cp *.so PIL/* /usr/local/lib/Python1.5/site-packages/PIL You can also place "PIL" subdirectory anywhere along the Python path, and use PIL as a package. Example: $ mkdir /usr/local/lib/Python1.5/PIL $ cp *.so PIL/* /usr/local/lib/Python1.5/PIL -------------------------------------------------------------------- Build instructions for Windows -------------------------------------------------------------------- [FIXME: this section needs to be updated] The current release does not include Windows makefiles. For prebuilt versions, check the product site: http://www.pythonware.com/products/pil/ Building your own copy under Visual Studio should be straightforward; create a new project based on the sample extensions provided with Python (the target should be "_imaging.pyd"), add all C files except "Except.c" and "coretest.c" to that project, check the contents of the "ImConfig.h" file (modify it if necessary), and build the DLL. NOTE: Make sure to build PIL with the same linking options as was used on the Python interpreter (usually /MD). If you mix linking options, anything can happen... (the most common problem is that "save" doesn't work!) (If I'd used Visual Studio myself, I would have provided a project file. But I don't. Contributions are welcome, though...) -------------------------------------------------------------------- NOTE: If you use Tk on Windows, you may wish to install the booster patches which provides dramatic performance improvements for 16- and 24-bit displays. See the description in the Tk subdirectory for details. -------------------------------------------------------------------- Imaging-1.1.3/CHANGES-1130100444000076400007640000011127707444200030014233 0ustar fredrikfredrikThe Python Imaging Library $Id: //modules/pil/CHANGES-113#3 $ ACKNOWLEDGEMENTS: PIL wouldn't be what it is without the help of, among others: David Ascher, Phil Austin, Anthony Baxter, Jan Blom, Duncan Booth, Roger Burnham, Gene Cash, Kevin Cazabon, Fred Clare, Greg Coats, Greg Couch, Bill Crutchfield, Tim Docker, Fred Drake, Robin Friedrich, Markus Gritsch, Mark Hammond, Bernhard Herzog, Rob Hooft, Jack Jansen, Bill Janssen, Edward Jones, Richard Jones, Robert Kern, Bob Klimek, Andrew MacIntyre, Gordon McMillan, Skip Montanaro, Fredrik Nehr, Håkan Karlsson, Robert Kern, Matthias Klose, Magnus Källström, Hamish Lawson, Eric Raymond, Bertil Reinhammar, Toby Sargeant, Barry Scott, Les Schaffer, Joel Shprentz, D. Alan Stewart, Perry Stoll, Paul Svensson, Ivan Tkatchev, Rune Uhlin, Sasha Voynow, and Charles Waldman. *** Changes from release 1.1 to 1.1.3 *** (1.1.3 final released) + Made setup.py look for old versions of zlib. For some back- ground, see: http://www.gzip.org/zlib/advisory-2002-03-11.txt (1.1.3c2 released) + Added setup.py file (tested on Unix and Windows). You still need to build libImaging/imaging.lib in the traditional way, but the setup.py script takes care of the rest. The old Setup.in/Makefile.pre.in build method is still supported. + Fixed segmentation violation in ANTIALIAS filter (an internal buffer wasn't properly allocated). (1.1.3c1 released) + Added ANTIALIAS downsampling filter for high-quality "resize" and "thumbnail" operations. Also added filter option to the "thumbnail" operation; the default value is NEAREST, but this will most likely change in future versions. + Fixed plugin loader to be more robust if the __file__ variable isn't set. + Added seek/tell support (for layers) to the PhotoShop loader. Layer 0 is the main image. + Added new (but experimental) "ImageOps" module, which provides shortcuts for commonly used operations on entire images. + Don't mess up when loading PNG images if the decoder leaves data in the output buffer. This could cause internal errors on some PNG images, with some versions of ZLIB. (Bug report and patch provided by Bernhard Herzog.) + Don't mess up on Unicode filenames. + Don't mess up when drawing on big endian platforms. + Made the TIFF loader a bit more robust; it can now read some more slightly broken TIFF files (based on input from Ted Wright, Bob Klimek, and D. Alan Stewart) + Added OS/2 EMX build files (from Andrew MacIntyre) + Change "ImageFont" to reject image files if they don't have the right mode. Older versions could leak memory for "P" images. (Bug reported by Markus Gritsch). (imToolkit 1.2a3 and 1.2b1 released) + Renamed some internal functions to avoid potential build problem on Mac OS X. + Added DL_EXPORT where relevant (for Cygwin, based on input from Robert Yodlowski) + (re)moved bogus __init__ call in BdfFontFile (bug spotted by Fred Clare) + Added "ImageGrab" support (Windows only) + Added support for XBM hotspots (based on code contributed by Bernhard Herzog). + Added support for Palm pixmaps (from Bill Janssen) + Added write support for more TIFF tags, namely the Artist, Copyright, DateTime, ResolutionUnit, Software, XResolution and YResolution tags (from Greg Couch) + Added TransposedFont wrapper to ImageFont module + Added "optimize" flag to GIF encoder. If optimize is present and non-zero, PIL will work harder to create a small file. + Raise "EOFError" (not IndexError) when reading beyond the end of a TIFF sequence. + Support rewind ("seek(0)") for GIF and TIFF sequences. + Load grayscale GIF images as mode "L" (imToolkit 1.2a2 released) + Added DPI read/write support to the JPEG codec. The decoder sets the info["dpi"] attribute for JPEG files with JFIF dpi settings. The encoder uses the "dpi" option: im = Image.open("file.jpg") dpi = im.info["dpi"] # raises KeyError if DPI not known im.save("out.jpg", dpi=dpi) Note that PIL doesn't always preserve the "info" attribute for normal image operations. (1.1.2c1 and 1.1.2 final released) + Adapted to Python 2.1. Among other things, all uses of the "regex" module has been repleased with "re". + Fixed attribute error when reading large PNG files (this bug was introduced in maintenance code released after the 1.1.1 release) + Ignore non-string objects in sys.path + Fixed Image.transform(EXTENT) for negative xoffsets + Fixed loading of image plugins if PIL is installed as a package. (The plugin loader now always looks in the directory where the Image.py module itself is found, even if that directory isn't on the standard search path) + The Png plugin has been added to the list of preloaded standard formats + Fixed bitmap/text drawing in fill mode. + Fixed "getextrema" to work also for multiband images. + Added transparency support for L and P images to the PNG codec. + Improved support for read-only images. The "load" method now sets the "readonly" attribute for memory-mapped images. Operations that modifies an image in place (such as "paste" and drawing operations) creates an in-memory copy of the image, if necessary. (before this change, any attempt to modify a memory-mapped image resulted in a core dump...) + Added special cases for lists everywhere PIL expects a sequence. This should speed up things like "putdata" and drawing operations. + The Image.offset method is deprecated. Use the ImageChops.offset function instead. + Changed ImageChops operators to copy palette and info dictionary from the first image argument. (1.1.1 released) + Additional fixes for Python 1.6/2.0, including TIFF "save" bug. + Changed "init" to properly load plugins when PIL is used as a package. + Fixed broken "show" method (on Unix) *** Changes from release 1.0 to 1.1 *** + Adapted to Python 1.6 ("append" and other method changes) + Fixed Image.paste when pasting with solid colour and matte layers ("L" or "RGBA" masks) (bug reported by Robert Kern) + To make it easier to distribute prebuilt versions of PIL, the tkinit binding stuff has been moved to a separate extension module, named "_imagingtk". *** Changes from release 0.3b2 to 1.0 final *** + If there's no 16-bit integer (like on a Cray T3E), set INT16 to the smallest integer available. Most of the library works just fine anyway (from Bill Crutchfield) + Tweaks to make drawing work on big-endian platforms. (1.0c2 released) + If PIL is built with the WITH_TKINTER flag, ImageTk can automatically hook into a standard Tkinter build. You no longer need to build your own Tkinter to use the ImageTk module. The old way still works, though. For more information, see Tk/install.txt. + Some tweaks to ImageTk to support multiple Tk interpreters (from Greg Couch). + ImageFont "load_path" now scans directory mentioned in .pth files (from Richard Jones). (1.0c1 released) + The TIFF plugin has been rewritten. The new plugin fully supports all major PIL image modes (including F and I). + The ImageFile module now includes a Parser class, which can be used to incrementally decode an image file (while down- loading it from the net, for example). See the handbook for details. + "show" now converts non-standard modes to "L" or "RGB" (as appropriate), rather than writing weird things to disk for "xv" to choke upon. (bug reported by Les Schaffer). (1.0b2 released) + Major speedups for rotate, transform(EXTENT), and transform(AFFINE) when using nearest neighbour resampling. + Modified ImageDraw to be compatible with the Arrow graphics interface. See the handbook for details. + PIL now automatically loads file codecs when used as a package (from The Dragon De Monsyne). Also included an __init__.py file in the standard distribution. + The GIF encoder has been modified to produce much smaller files. PIL now uses a run-length encoding method to encode GIF files. On a random selection of GIF images grabbed from the web, this version makes the images about twice as large as the original LZW files, where the earlier version made them over 5 times larger. YMMV, of course. + Added PCX write support (works with "1", "P", "L", and "RGB") + Added "bitmap" and "textsize" methods to ImageDraw. + Improved font rendering code. Fixed a bug or two, and moved most of the time critical stuff to C. + Removed "bdf2pil.py". Use "pilfont.py" instead! + Improved 16-bit support (still experimental, though). The following methods now support "I;16" and "I;16B" images: "getpixel", "copy", "convert" (to and from mode "I"), "resize", "rotate", and "transform" with nearest neighbour filters, and "save" using the IM format. The "new" and "open" functions also work as expected. On Windows, 16-bit files are memory mapped. NOTE: ALL other operations are still UNDEFINED on 16-bit images. + The "paste" method now supports constant sources. Just pass a colour value (a number or a tuple, depending on the target image mode) instead of the source image. This was in fact implemented in an inefficient way in earlier versions (the "paste" method generated a temporary source image if you passed it a colour instead of an image). In this version, this is handled on the C level instead. + Added experimental "RGBa" support. An "RGBa" image is an RGBA image where the colour components have have been premultipled with the alpha value. PIL allows you to convert an RGBA image to an RGBa image, and to paste RGBa images on top of RGB images. Since this saves a bunch of multiplications and shifts, it is typically about twice as fast an ordinary RGBA paste. + Eliminated extra conversion step when pasting "RGBA" or "RGBa" images on top of "RGB" images. + Fixed Image.BICUBIC resampling for "RGB" images. + Fixed PCX image file handler to properly read 8-bit PCX files (bug introduced in 1.0b1, reported by Bernhard Herzog) + Fixed PSDraw "image" method to restore the coordinate system. + Fixed "blend" problem when applied to images that was not already loaded (reported by Edward C. Jones) + Fixed -f option to "pilconvert.py" (from Anthony Baxter) (1.0b1 released) + Added Toby J. Sargeant's quantization package. To enable quantization, use the "palette" option to "convert": imOut = im.convert("P", palette=Image.ADAPTIVE) This can be used with "L", "P", and "RGB" images. In this version, dithering cannot be used with adaptive palettes. Note: ADAPTIVE currently maps to median cut quantization with 256 colours. The quantization package also contains a maximum coverage quantizer, which will be supported by future versions of PIL. + Added Eric S. Raymond's "pildriver" image calculator to the distribution. See the docstring for more information. + The "offset" method no longer dumps core if given positive offsets (from Charles Waldman). + Fixed a resource leak that could cause ImageWin to run out of GDI resources (from Roger Burnham). + Added "arc", "chord", and "pieslice" methods to ImageDraw (inspired by code contributed by Richard Jones). + Added experimental 16-bit support, via modes "I;16" (little endian data) and "I;16B" (big endian). Only a few methods properly support such images (see above). + Added XV thumbnail file handler (from Gene Cash). + Fixed BMP image file handler to handle palette images with small palettes (from Rob Hooft). + Fixed Sun raster file handler for palette images (from Charles Waldman). + Improved various internal error messages. + Fixed Path constructor to handle arbitrary sequence objects. This also affects the ImageDraw class (from Richard Jones). + Fixed a bug in JpegDecode that caused PIL to report "decoder error -2" for some progressive JPEG files (reported by Magnus Källström, who also provided samples). + Fixed a bug in JpegImagePlugin that caused PIL to hang when loading JPEG files using 16-bit quantization tables. + The Image "transform" method now supports Image.QUAD transforms. The data argument is an 8-tuple giving the upper left, lower left, lower right, and upper right corner of the source quadri- lateral. Also added Image.MESH transform which takes a list of quadrilaterals. + The Image "resize", "rotate", and "transform" methods now support Image.BILINEAR (2x2) and Image.BICUBIC (4x4) resampling filters. Filters can be used with all transform methods. + The ImageDraw "rectangle" method now includes both the right and the bottom edges when drawing filled rectangles. + The TGA decoder now works properly for runlength encoded images which have more than one byte per pixel. + "getbands" on an YCbCr image now returns ("Y", "Cb", "Cr") + Some file drivers didn't handle the optional "modify" argument to the load method. This resulted in exceptions when you used "paste" (and other methods that modify an image in place) on a newly opened file. *** Changes from release 0.2 (b5) to 0.3 (b2) *** (0.3b2 released) The test suite includes 825 individual tests. + An Image "getbands" method has been added. It returns a tuple containing the individual band names for this image. To figure out how many bands an image has, use "len(im.getbands())". + An Image "putpixel" method has been added. + The Image "point" method can now be used to convert "L" images to any other format, via a lookup table. That table should contain 256 values for each band in the output image. + Some file drivers (including FLI/FLC, GIF, and IM) accidently overwrote the offset method with an internal attribute. All drivers have been updated to use private attributes where possible. + The Image "histogram" method now works for "I" and "F" images. For these modes, PIL divides the range between the min and max values used in the image into 256 bins. You can also pass in your own min and max values via the "extrema" option: h = im.histogram(extrema=(0, 255)) + An Image "getextrema" method has been added. It returns the min and max values used in the image. In this release, this works for single band images only. + Changed the PNG driver to load and save mode "I" images as 16-bit images. When saving, values outside the range 0..65535 are clipped. + Fixed ImageFont.py to work with the new "pilfont" compiler. + Added JPEG "save" and "draft" support for mode "YCbCr" images. Note that if you save an "YCbCr" image as a JPEG file and read it back, it is read as an RGB file. To get around this, you can use the "draft" method: im = Image.open("color.jpg") im.draft("YCbCr", im.size) + Read "RGBA" TGA images. Also fixed the orientation bug; all images should now come out the right way. + Changed mode name (and internal representation) from "YCrCb" to "YCbCr" (!) *** WARNING: MAY BREAK EXISTING CODE *** (0.3b1 released) The test suite includes 750 individual tests. + The "pilfont" package is now included in the standard PIL distribution. The pilfont utility can be used to convert X BDF and PCF raster font files to a format understood by the ImageFont module. + GIF files are now interlaced by default. To write a non-interlaced file, pass interlace=0 to the "save" method. + The default string format has changed for the "fromstring" and "tostring" methods. *** WARNING: MAY BREAK EXISTING CODE *** NOTE: If no extra arguments are given, the first line in the string buffer is the top line of the image, instead of the bottom line. For RGB images, the string now contains 3 bytes per pixel instead of 4. These changes were made to make the methods compatible with the "fromstring" factory function. To get the old behaviour, use the following syntax: data = im.tostring("raw", "RGBX", 0, -1) im.fromstring(data, "raw", "RGBX", 0, -1) + "new" no longer gives a MemoryError if the width or height is zero (this only happened on platforms where malloc(0) or calloc(0) returns NULL). + "new" now adds a default palette object to "P" images. + You can now convert directly between all modes supported by PIL. When converting colour images to "P", PIL defaults to a "web" palette and dithering. When converting greyscale images to "1", PIL uses a thresholding and dithering. + Added a "dither" option to "convert". By default, "convert" uses floyd-steinberg error diffusion for "P" and "1" targets, so this option is only used to *disable* dithering. Allowed values are NONE (no dithering) or FLOYDSTEINBERG (default). imOut = im.convert("P", dither=Image.NONE) + Added a full set of "I" decoders. You can use "fromstring" (and file decoders) to read any standard integer type as an "I" image. + Added some support for "YCbCr" images (creation, conversion from/to "L" and "RGB", IM YCC load/save) + "getpixel" now works properly with fractional coordinates. + ImageDraw "setink" now works with "I", "F", "RGB", "RGBA", "RGBX", "CMYK", and "YCbCr" images. + ImImagePlugin no longer attaches palettes to "RGB" images. + Various minor fixes. (0.3a4 released) + Added experimental IPTC/NAA support. + Eliminated AttributeError exceptions after "crop" (from Skip Montanaro) + Reads some uncompressed formats via memory mapping (this is currently supported on Win32 only) + Fixed some last minute glitches in the last alpha release (Types instead of types in Image.py, version numbers, etc.) + Eliminated some more bogus compiler warnings. + Various fixes to make PIL compile and run smoother on Macs (from Jack Jansen). + Fixed "fromstring" and "tostring" for mode "I" images. (0.3a3 released) The test suite includes 530 individual tests. + Eliminated unexpected side-effect in "paste" with matte. "paste" now works properly also if compiled with "gcc". + Adapted to Python 1.5 (build issues only) + Fixed the ImageDraw "point" method to draw also the last point (!). + Added "I" and "RGBX" support to Image.new. + The plugin path is now properly prepended to the module search path when a plugin module is imported. + Added "draw" method to the ImageWin.Dib class. This is used by Topaz to print images on Windows printers. + "convert" now supports conversions from "P" to "1" and "F". + "paste" can now take a colour instead of an image as the first argument. The colour must match the colour argument given to the new function, and match the mode of the target image. + Fixed "paste" to allow a mask also for mode "F" images. + The BMP driver now saves mode "1" images. When loading images, the mode is set to "L" for 8-bit files with greyscale palettes, and to "P" for other 8-bit files. + The IM driver now reads and saves "1" images (file modes "0 1" or "L 1"). + The JPEG and GIF drivers now saves "1" images. For JPEG, the image is saved as 8-bit greyscale (it will load as mode "L"). For GIF, the image will be loaded as a "P" image. + Fixed a potential buffer overrun in the GIF encoder. (0.3a2 released) The test suite includes 400 individual tests. + Improvements to the test suite revealed a number of minor bugs, which are all fixed. Note that crop/paste, 32-bit ImageDraw, and ImageFont are still weak spots in this release. + Added "putpalette" method to the Image class. You can use this to add or modify the palette for "P" and "L" images. If a palette is added to an "L" image, it is automatically converted to a "P" image. + Fixed ImageDraw to properly handle 32-bit image memories ("RGB", "RGBA", "CMYK", "F") + Fixed "fromstring" and "tostring" not to mess up the mode attribute in default mode. + Changed ImPlatform.h to work on CRAY's (don't have one at home, so I haven't tried it). The previous version assumed that either "short" or "int" were 16-bit wide. PIL still won't compile on platforms where neither "short", "int" nor "long" are 32-bit wide. + Added file= and data= keyword arguments to PhotoImage and BitmapImage. This allows you to use them as drop-in replacements for the corre- sponding Tkinter classes. + Removed bogus references to the crack coder (ImagingCrack). (0.3a1 released) + Make sure image is loaded in "tostring". + Added floating point packer (native 32-bit floats only). *** Changes from release 0.1b1 to 0.2 (b5) *** + Modified "fromstring" and "tostring" methods to use file codecs. Also added "fromstring" factory method to create an image directly from data in a string. + Added support for 32-bit floating point images (mode "F"). You can convert between "L" and "F" images, and apply a subset of the available image processing methods on the "F" image. You can also read virtually any data format into a floating point image memory; see the section on "Decoding Floating Point Data" in the handbook for more information. (0.2b5 released; on windows only) + Fixed the tobitmap() method to work properly for small bitmaps. + Added RMS and standard deviation to the ImageStat.Stat class. Also modified the constructor to take an optional feature mask, and also to accept either an image or a list containing the histogram data. + The BitmapImage code in ImageTk can now use a special bitmap decoder, which has to be patched into Tk. See the "Tk/pilbitmap.txt" file for details. If not installed, bitmaps are transferred to Tk as XBM strings. + The PhotoImage code in ImageTk now uses a Tcl command ("PyImagingPaste") instead of a special image type. This gives somewhat better performance, and also allows PIL to support transparency. *** WARNING: TKAPPINIT MUST BE MODIFIED *** + ImageTk now honours the alpha layer in RGBA images. Only fully transparent pixels are made transparent (that is, the alpha layer is treated as a mask). To treat the alpha laters as a matte, you must paste the image on the background before handing it over to ImageTk. + Added McIdas reader (supports 8-bit images only). + PIL now preloads drivers for BMP, GIF, JPEG, PPM, and TIFF. As long as you only load and save these formats, you don't have to wait for a full scan for drivers. To force scanning, call the Image.init() function. + The "seek" and "tell" methods are now always available, also for single-frame images. + Added optional mask argument to histogram method. The mask may be an "1" or "L" image with the same size as the original image. Only pixels where the mask is non-zero are included in the histogram. + The "paste" method now allows you to specify only the lower left corner (a 2-tuple), instead of the full region (a 4-tuple). + Reverted to old plugin scanning model; now scans all directory names in the path when looking for plugins. + Added PIXAR raster support. Only uncompressed ("dumped") RGB images can currently be read (based on information provided by Greg Coats). + Added FlashPix (FPX) read support. Reads all pixel formats, but only the highest resolution is read, and the viewing transform is currently ignored. + Made PNG encoding somewhat more efficient in "optimize" mode; a bug in 0.2b4 didn't enable all predictor filters when optimized storage were requested. + Added Microsoft Image Composer (MIC) read support. When opened, the first sprite in the file is loaded. You can use the seek method to load additional sprites from the file. + Properly reads "P" and "CMYK" PSD images. + "pilconvert" no longer optimizes by default; use the -o option to make the file as small as possible (at the expense of speed); use the -q option to set the quality when compressing to JPEG. + Fixed "crop" not to drop the palette for "P" images. + Added and verified FLC support. + Paste with "L" or "RGBA" alpha is now several times faster on most platforms. + Changed Image.new() to initialize the image to black, as described in the handbook. To get an uninitialized image, use None as the colour. + Fixed the PDF encoder to produce a valid header; Acrobat no longer complains when you load PDF images created by PIL. + PIL only scans fully-qualified directory names in the path when looking for plugins. *** WARNING: MAY BREAK EXISTING CODE *** + Faster implementation of "save" used when filename is given, or when file object has "fileno" and "flush" methods. + Fixed the "crop" method not to crash if the region extends outside the source image. + Eliminated a massive memory leak in the "save" function. + The GIF decoder doesn't crash if the code size is set to an illegal value. This could happen since another bug didn't handle local palettes properly if they didn't have the same size as the global palette (not very common). + Added predictor support (TIFF 6.0 section 14) to the TIFF decoder. + Fixed palette and padding problems in BMP driver. Now properly writes "1", "L", "P" and "RGB" images. + Fixed getpixel()/getdata() to return correct pixel values. + Added PSD (PhotoShop) read support. Reads both uncompressed and compressed images of most types. + Added GIF write support (writes "uncompressed" GIF files only, due to unresolvable licensing issues). The "gifmaker.py" script can be used to create GIF animations. + Reads 8-bit "L" and "P" TGA images. Also reads 16-bit "RGB" images. + Added FLI read support. This driver has only been tested on a few FLI samples. + Reads 2-bit and 4-bit PCX images. + Added MSP read and write support. Both version 1 and 2 can be read, but only version 1 (uncompressed) files are written. + Fixed a bug in the FLI/FLC identification code that caused the driver to raise an exception when parsing valid FLI/FLC files. + Improved performance when loading file format plugins, and when opening files. + Added GIF animation support, via the "seek" and "tell" methods. You can use "player.py" to play an animated GIF file. + Removed MNG support, since the spec is changing faster than I can change the code. I've added support for the experimental ARG format instead. Contact me for more information on this format. + Added keyword options to the "save" method. The following options are currently supported: format option description -------------------------------------------------------- JPEG optimize minimize output file at the expense of compression speed. JPEG progressive enable progressive output. the option value is ignored. JPEG quality set compression quality (1-100). the default value is 75. JPEG smooth smooth dithered images. value is strengh (1-100). default is off (0). PNG optimize minimize output file at the expense of compression speed. Expect more options in future releases. Also note that file writers silently ignore unknown options. + Plugged memory leaks in the PNG and TIFF decoders. + Added PNG write support. + (internal) RGB unpackers and converters now set the pad byte to 255 (full opacity). + Properly handles the "transparency" property for GIF, PNG and XPM files. + Added a "putalpha" method, allowing you to attach a "1" or "L" image as the alpha layer to an "RGBA" image. + Various improvements to the sample scripts: "pilconvert" Carries out some extra tricks in order to make the resulting file as small as possible. "explode" (NEW) Split an image sequence into individual frames. "gifmaker" (NEW) Convert a sequence file into a GIF animation. Note that the GIF encoder create "uncompressed" GIF files, so animations created by this script are rather large (typically 2-5 times the compressed sizes). "image2py" (NEW) Convert a single image to a python module. See comments in this script for details. "player" If multiple images are given on the command line, they are interpreted as frames in a sequence. The script assumes that they all have the same size. Also note that this script now can play FLI/FLC and GIF animations. This player can also execute embedded Python animation applets (ARG format only). "viewer" Transparent images ("P" with transparency property, and "RGBA") are superimposed on the standard Tk back- ground. + Fixed colour argument to "new". For multilayer images, pass a tuple: (Red, Green, Blue), (Red, Green, Blue, Alpha), or (Cyan, Magenta, Yellow, Black). + Added XPM (X pixmap) read support. (0.2b3 released) + Added MNG (multi-image network graphics) read support. "Ming" is a proposed animation standard, based on the PNG file format. You can use the "player" sample script to display some flavours of this format. The MNG standard is still under development, as is this driver. More information, including sample files, can be found at + Added a "verify" method to images loaded from file. This method scans the file for errors, without actually decoding the image data, and raises a suitable exception if it finds any problems. Currently implemented for PNG and MNG files only. + Added support for interlaced GIF images. + Added PNG read support -- if linked with the ZLIB compression library, PIL reads all kinds of PNG images, except interlaced files. + Improved PNG identification support -- doesn't mess up on unknown chunks, identifies all possible PNG modes, and verifies checksum on PNG header chunks. + Added an experimental reader for placable Windows Meta Files (WMF). This reader is still very incomplete, but it illustrates how PIL's drawing capabilities can be used to render vector and metafile formats. + Added restricted drivers for images from Image Tools (greyscale only) and LabEye/IFUNC (common interchange modes only). + Some minor improvements to the sample scripts provided in the "Scripts" directory. + The test images have been moved to the "Images" directory. (0.2b2 released) (0.2b1 released; Windows only) + Fixed filling of complex polygons. The ImageDraw "line" and "polygon" methods also accept Path objects. + The ImageTk "PhotoImage" object can now be constructed directly from an image. You can also pass the object itself to Tkinter, instead of using the "image" attribute. Finally, using "paste" on a displayed image automatically updates the display. + The ImageTk "BitmapImage" object allows you to create transparent overlays from 1-bit images. You can pass the object itself to Tkinter. The constructor takes the same arguments as the Tkinter BitmapImage class; use the "foreground" option to set the colour of the overlay. + Added a "putdata" method to the Image class. This can be used to load a 1-layer image with data from a sequence object or a string. An optional floating point scale and offset can be used to adjust the data to fit into the 8-bit pixel range. Also see the "getdata" method. + Added the EXTENT method to the Image "transform" method. This can be used to quickly crop, stretch, shrink, or mirror a subregion from another image. + Adapted to Python 1.4. + Added a project makefile for Visual C++ 4.x. This allows you to easily build a dynamically linked version of PIL for Windows 95 and NT. + A Tk "booster" patch for Windows is available. It gives dramatic performance improvements for some displays. Has been tested with Tk 4.2 only, but is likely to work with Tk 4.1 as well. See the Tk subdirectory for details. + You can now save 1-bit images in the XBM format. In addition, the Image class now provides a "tobitmap" method which returns a string containing an XBM representation of the image. Quite handy to use with Tk. + More conversions, including "RGB" to "1" and more. (0.2a1 released) + Where earlier versions accepted lists, this version accepts arbitrary Python sequences (including strings, in some cases). A few resource leaks were plugged in the process. + The Image "paste" method now allows the box to extend outside the target image. The size of the box, the image to be pasted, and the optional mask must still match. + The ImageDraw module now supports filled polygons, outlined and filled ellipses, and text. Font support is rudimentary, though. + The Image "point" method now takes an optional mode argument, allowing you to convert the image while translating it. Currently, this can only be used to convert "L" or "P" images to "1" images (creating thresholded images or "matte" masks). + An Image "getpixel" method has been added. For single band images, it returns the pixel value at a given position as an integer. For n-band images, it returns an n-tuple of integers. + An Image "getdata" method has been added. It returns a sequence object representing the image as a 1-dimensional array. Only len() and [] can be used with this sequence. This method returns a reference to the existing image data, so changes in the image will be immediately reflected in the sequence object. + Fixed alignment problems in the Windows BMP writer. + If converting an "RGB" image to "RGB" or "L", you can give a second argument containing a colour conversion matrix. + An Image "getbbox" method has been added. It returns the bounding box of data in an image, considering the value 0 as background. + An Image "offset" method has been added. It returns a new image where the contents of the image have been offset the given distance in X and/or Y direction. Data wraps between edges. + Saves PDF images. The driver creates a binary PDF 1.1 files, using JPEG compression for "L", "RGB", and "CMYK" images, and hex encoding (same as for PostScript) for other formats. + The "paste" method now accepts "1" masks. Zero means transparent, any other pixel value means opaque. This is faster than using an "L" transparency mask. + Properly writes EPS files (and properly prints images to postscript printers as well). + Reads 4-bit BMP files, as well as 4 and 8-bit Windows ICO and CUR files. Cursor animations are not supported. + Fixed alignment problems in the Sun raster loader. + Added "draft" and "thumbnail" methods. The draft method is used to optimize loading of JPEG and PCD files, the thumbnail method is used to create a thumbnail representation of an image. + Added Windows display support, via the ImageWin class (see the handbook for details). + Added raster conversion for EPS files. This requires GNU or Aladdin Ghostscript, and probably works on UNIX only. + Reads PhotoCD (PCD) images. The base resolution (768x512) can be read from a PhotoCD file. + Eliminated some compiler warnings. Bindings now compile cleanly in C++ mode. Note that the Imaging library itself must be compiled in C mode. + Added "bdf2pil.py", which converts BDF fonts into images with associated metrics. This is definitely work in progress. For info, see description in script for details. + Fixed a bug in the "ImageEnhance.py" module. + Fixed a bug in the netpbm save hack in "GifImagePlugin.py" + Fixed 90 and 270 degree rotation of rectangular images. + Properly reads 8-bit TIFF palette-color images. + Reads plane separated RGB and CMYK TIFF images. + Added driver debug mode. This is enabled by setting Image.DEBUG to a non-zero value. Try the -D option to "pilfile.py" and see what happens. + Don't crash on "atend" constructs in PostScript files. + Only the Image module imports _imaging directly. Other modules should refer to the binding module as "Image.core". *** Changes from release 0.0 to 0.1 (b1) *** + A handbook is available (distributed separately). + The coordinate system is changed so that (0,0) is now located in the upper left corner. This is in compliancy with ISO 12087 and 90% of all other image processing and graphics libraries. + Modes "1" (bilevel) and "P" (palette) have been introduced. Note that bilevel images are stored with one byte per pixel. + The Image "crop" and "paste" methods now accepts None as the box argument, to refer to the full image (self, that is). + The Image "crop" method now works properly. + The Image "point" method is now available. You can use either a lookup table or a function taking one argument. + The Image join function has been renamed to "merge". + An Image "composite" function has been added. It is identical to copy() followed by paste(mask). + An Image "eval" function has been added. It is currently identical to point(function); that is, only a single image can be processed. + A set of channel operations has been added. See the "ImageChops" module, test_chops.py, and the handbook for details. + Added the "pilconvert" utility, which converts image files. Note that the number of output formats are still quite restricted. + Added the "pilfile" utility, which quickly identifies image files (without loading them, in most cases). + Added the "pilprint" utility, which prints image files to Postscript printers. + Added a rudimentary version of the "pilview" utility, which is simple image viewer based on Tk. Only File/Exit and Image/Next works properly. + An interface to Tk has been added. See "Lib/ImageTk.py" and README for details. + An interface to Jack Jansen's Img library has been added (thanks to Jack). This allows you to read images through the Img extensions file format handlers. See the file "Lib/ImgExtImagePlugin.py" for details. + Postscript printing is provided through the PSDraw module. See the handbook for details. Imaging-1.1.3/CONTENTS0100444000076400007640000001167307444357237014143 0ustar fredrikfredrikImaging/README Imaging/CHANGES-113 Imaging/CONTENTS Imaging/BUILDME Imaging/setup.py Imaging/Setup.in Imaging/Makefile.pre.in Imaging/libImaging/Makefile.win Imaging/libImaging/ImConfig.h.win Imaging/libImaging/Imaging.h Imaging/libImaging/ImDib.h Imaging/libImaging/ImPlatform.h Imaging/libImaging/Quant.h Imaging/libImaging/QuantHash.h Imaging/libImaging/QuantHeap.h Imaging/libImaging/QuantDefines.h Imaging/libImaging/QuantTypes.h Imaging/libImaging/Access.c Imaging/libImaging/Antialias.c Imaging/libImaging/Bands.c Imaging/libImaging/Blend.c Imaging/libImaging/Chops.c Imaging/libImaging/Convert.c Imaging/libImaging/ConvertYCbCr.c Imaging/libImaging/Copy.c Imaging/libImaging/Crc32.c Imaging/libImaging/Crop.c Imaging/libImaging/Dib.c Imaging/libImaging/Draw.c Imaging/libImaging/Effects.c Imaging/libImaging/Except.c Imaging/libImaging/File.c Imaging/libImaging/Fill.c Imaging/libImaging/Filter.c Imaging/libImaging/Geometry.c Imaging/libImaging/GetBBox.c Imaging/libImaging/Histo.c Imaging/libImaging/Matrix.c Imaging/libImaging/Negative.c Imaging/libImaging/Offset.c Imaging/libImaging/Pack.c Imaging/libImaging/Palette.c Imaging/libImaging/Paste.c Imaging/libImaging/Point.c Imaging/libImaging/Quant.c Imaging/libImaging/QuantHash.c Imaging/libImaging/QuantHeap.c Imaging/libImaging/Storage.c Imaging/libImaging/Unpack.c Imaging/libImaging/UnpackYCC.c Imaging/libImaging/Bit.h Imaging/libImaging/Gif.h Imaging/libImaging/Jpeg.h Imaging/libImaging/Lzw.h Imaging/libImaging/Raw.h Imaging/libImaging/Zip.h Imaging/libImaging/BitDecode.c Imaging/libImaging/EpsEncode.c Imaging/libImaging/FliDecode.c Imaging/libImaging/GifDecode.c Imaging/libImaging/GifEncode.c Imaging/libImaging/HexDecode.c Imaging/libImaging/JpegDecode.c Imaging/libImaging/JpegEncode.c Imaging/libImaging/LzwDecode.c Imaging/libImaging/MspDecode.c Imaging/libImaging/PackDecode.c Imaging/libImaging/PcdDecode.c Imaging/libImaging/PcxEncode.c Imaging/libImaging/PcxDecode.c Imaging/libImaging/RawDecode.c Imaging/libImaging/RawEncode.c Imaging/libImaging/SunRleDecode.c Imaging/libImaging/TgaRleDecode.c Imaging/libImaging/XbmDecode.c Imaging/libImaging/XbmEncode.c Imaging/libImaging/ZipDecode.c Imaging/libImaging/ZipEncode.c Imaging/libImaging/coretest.c Imaging/libImaging/configure Imaging/libImaging/ImConfig.h.in Imaging/libImaging/Makefile.in Imaging/_imaging.c Imaging/decode.c Imaging/encode.c Imaging/display.c Imaging/map.c Imaging/outline.c Imaging/path.c Imaging/_imagingtk.c Imaging/PIL.pth Imaging/PIL/__init__.py Imaging/PIL/ArgImagePlugin.py Imaging/PIL/BdfFontFile.py Imaging/PIL/BmpImagePlugin.py Imaging/PIL/ContainerIO.py Imaging/PIL/CurImagePlugin.py Imaging/PIL/DcxImagePlugin.py Imaging/PIL/EpsImagePlugin.py Imaging/PIL/FliImagePlugin.py Imaging/PIL/FontFile.py Imaging/PIL/FpxImagePlugin.py Imaging/PIL/GbrImagePlugin.py Imaging/PIL/GdImageFile.py Imaging/PIL/GifImagePlugin.py Imaging/PIL/GimpGradientFile.py Imaging/PIL/GimpPaletteFile.py Imaging/PIL/IcoImagePlugin.py Imaging/PIL/Image.py Imaging/PIL/ImageChops.py Imaging/PIL/ImageDraw.py Imaging/PIL/ImageEnhance.py Imaging/PIL/ImageFile.py Imaging/PIL/ImageFileIO.py Imaging/PIL/ImageFilter.py Imaging/PIL/ImageFont.py Imaging/PIL/ImageOps.py Imaging/PIL/ImagePalette.py Imaging/PIL/ImagePath.py Imaging/PIL/ImageSequence.py Imaging/PIL/ImageStat.py Imaging/PIL/ImageTk.py Imaging/PIL/ImageWin.py Imaging/PIL/ImImagePlugin.py Imaging/PIL/ImtImagePlugin.py Imaging/PIL/IptcImagePlugin.py Imaging/PIL/JpegImagePlugin.py Imaging/PIL/McIdasImagePlugin.py Imaging/PIL/MicImagePlugin.py Imaging/PIL/MpegImagePlugin.py Imaging/PIL/MspImagePlugin.py Imaging/PIL/OleFileIO.py Imaging/PIL/PaletteFile.py Imaging/PIL/PcdImagePlugin.py Imaging/PIL/PcfFontFile.py Imaging/PIL/PcxImagePlugin.py Imaging/PIL/PdfImagePlugin.py Imaging/PIL/PixarImagePlugin.py Imaging/PIL/PngImagePlugin.py Imaging/PIL/PpmImagePlugin.py Imaging/PIL/PsdImagePlugin.py Imaging/PIL/PSDraw.py Imaging/PIL/SgiImagePlugin.py Imaging/PIL/SunImagePlugin.py Imaging/PIL/TarIO.py Imaging/PIL/TgaImagePlugin.py Imaging/PIL/TiffImagePlugin.py Imaging/PIL/TiffTags.py Imaging/PIL/WmfImagePlugin.py Imaging/PIL/XbmImagePlugin.py Imaging/PIL/XpmImagePlugin.py Imaging/PIL/XVThumbImagePlugin.py Imaging/Scripts/pilconvert.py Imaging/Scripts/pildriver.py Imaging/Scripts/pilfile.py Imaging/Scripts/pilfont.py Imaging/Scripts/pilprint.py Imaging/Images/lena.gif Imaging/Images/lena.ppm Imaging/Images/lena.jpg Imaging/Images/courB08.bdf Imaging/Images/courB08.pbm Imaging/Images/courB08.pil Imaging/Sane/README Imaging/Sane/sanedoc.txt Imaging/Sane/_sanemodule.c Imaging/Sane/sane.py Imaging/Sane/demo.py Imaging/Scripts/README Imaging/Scripts/bdf2pil.py Imaging/Scripts/enhancer.py Imaging/Scripts/explode.py Imaging/Scripts/gifmaker.py Imaging/Scripts/image2py.py Imaging/Scripts/painter.py Imaging/Scripts/player.py Imaging/Scripts/viewer.py Imaging/Scripts/thresholder.py Imaging/Tk/tkImaging.c Imaging/Tk/install.txt Imaging/Tk/booster.txt Imaging/Tk/pilbitmap.txt Imaging/MiniTest/test.py Imaging/MiniTest/doctest.py Imaging-1.1.3/BUILDME0100444000076400007640000000026107442710203013736 0ustar fredrikfredrik# quick build (for lazy programmers). for more information on the # build process, see the README file. cd libImaging ./configure make cd .. make -f Makefile.pre.in boot make Imaging-1.1.3/setup.py0100444000076400007640000001231607444200030014442 0ustar fredrikfredrik#!/usr/bin/env python # # Setup script for PIL # $Id: //modules/pil/setup.py#7 $ # # Usage: python setup.py install # # before running this script, build the libImaging directory # and all support libraries (the JPEG library, ZLIB, etc). # from distutils.core import setup, Extension import os, sys, re # -------------------------------------------------------------------- # configuration NAME = "PIL" DESCRIPTION = "Python Imaging Library" AUTHOR = "Secret Labs AB / PythonWare", "info@pythonware.com" HOMEPAGE = "http://www.pythonware.com/products/pil" # on windows, the build script expects to find both library files and # include files in the directories below. tweak as necessary. JPEGDIR = "../../kits/jpeg-6b" ZLIBDIR = "../../kits/zlib-1.1.3" # on windows, the following is used to control how and where to search # for Tcl/Tk files. None enables automatic searching; to override, set # this to a directory name TCLROOT = None from PIL.Image import VERSION PY_VERSION = sys.version[0] + sys.version[2] # -------------------------------------------------------------------- # configure imaging module MODULES = [] INCLUDE_DIRS = ["libImaging"] LIBRARY_DIRS = ["libImaging"] LIBRARIES = ["Imaging"] HAVE_LIBJPEG = 0 HAVE_LIBTIFF = 0 HAVE_LIBZ = 0 # parse ImConfig.h to figure out what external libraries we're using for line in open(os.path.join("libImaging", "ImConfig.h")).readlines(): m = re.match("#define\s+HAVE_LIB([A-Z]+)", line) if m: lib = m.group(1) if lib == "JPEG": HAVE_LIBJPEG = 1 if sys.platform == "win32": LIBRARIES.append("jpeg") INCLUDE_DIRS.append(JPEGDIR) LIBRARY_DIRS.append(JPEGDIR) else: LIBRARIES.append("jpeg") elif lib == "TIFF": HAVE_LIBTIFF = 1 LIBRARIES.append("tiff") elif lib == "Z": HAVE_LIBZ = 1 if sys.platform == "win32": LIBRARIES.append("zlib") INCLUDE_DIRS.append(ZLIBDIR) LIBRARY_DIRS.append(ZLIBDIR) else: LIBRARIES.append("z") if sys.platform == "win32": # standard windows libraries LIBRARIES.extend(["kernel32", "user32", "gdi32"]) MODULES.append( Extension( "_imaging", ["_imaging.c", "decode.c", "encode.c", "map.c", "display.c", "outline.c", "path.c"], include_dirs=INCLUDE_DIRS, library_dirs=LIBRARY_DIRS, libraries=LIBRARIES ) ) # security check if HAVE_LIBZ: # look for old, unsafe version of zlib # note: this only finds zlib.h if ZLIBDIR is properly set zlibfile = os.path.join(ZLIBDIR, "zlib.h") if os.path.isfile(zlibfile): for line in open(zlibfile).readlines(): m = re.match('#define\s+ZLIB_VERSION\s+"([^"]*)"', line) if m: if m.group(1) < "1.1.4": print print "*** Warning: zlib", m.group(1), print "may contain a security vulnerability." print "*** Consider upgrading to zlib 1.1.4 or newer." print "*** See:", print "http://www.gzip.org/zlib/advisory-2002-03-11.txt" print break # -------------------------------------------------------------------- # configure imagingtk module try: import _tkinter TCL_VERSION = _tkinter.TCL_VERSION[:3] except (ImportError, AttributeError): pass else: INCLUDE_DIRS = ["libImaging"] LIBRARY_DIRS = ["libImaging"] LIBRARIES = ["Imaging"] if sys.platform == "win32": # locate tcl/tk on windows if TCLROOT: path = [TCLROOT] else: path = [ os.path.join("/py" + PY_VERSION, "Tcl"), os.path.join(os.environ.get("ProgramFiles", ""), "Tcl"), # FIXME: add more directories here? ] for root in path: TCLROOT = os.path.abspath(root) if os.path.isfile(os.path.join(TCLROOT, "include", "tk.h")): break else: print "*** cannot find Tcl/Tk headers and library files" print " change the TCLROOT variable in the setup.py file" sys.exit(1) # print "using Tcl/Tk libraries at", TCLROOT # print "using Tcl/Tk version", TCL_VERSION version = TCL_VERSION[0] + TCL_VERSION[2] INCLUDE_DIRS.append(os.path.join(TCLROOT, "include")) LIBRARY_DIRS.append(os.path.join(TCLROOT, "lib")) LIBRARIES.extend(["tk" + version, "tcl" + version]) else: # assume the libraries are installed in the default location LIBRARIES.extend(["tk" + TCL_VERSION, "tcl" + TCL_VERSION]) MODULES.append( Extension( "_imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"], include_dirs=INCLUDE_DIRS, library_dirs=LIBRARY_DIRS, libraries=LIBRARIES ) ) # build! setup( name=NAME, version=VERSION, author=AUTHOR[0], author_email=AUTHOR[1], description=DESCRIPTION, url=HOMEPAGE, packages=[""], extra_path = "PIL", package_dir={"": "PIL"}, ext_modules = MODULES, ) Imaging-1.1.3/Setup.in0100444000076400007640000000336607442710204014374 0ustar fredrikfredrik# Setup file for the Imaging module # ================================= # # INSTRUCTIONS: # # 1) Edit the configuration settings as described below. # # 2) Go to the libImaging directory and build the support library. # # 3) Run "make -f Makefile.pre.in boot" # # 4) Run "make" # # This file has the same format as /Modules/Setup.in. # # -------------------------------------------------------------------- # Remove (or comment) the following line if you wish to build a # statically linked python interpreter. *shared* # -------------------------------------------------------------------- # Core library. Edit or remove the library specifications to match # your configuration. As they stand, they assume that you have the # IJG JPEG library 6.0a and zlib 1.0.4 (or newer versions of these # libraries) in a standard location. _imaging _imaging.c decode.c encode.c map.c display.c outline.c path.c \ -IlibImaging libImaging/libImaging.a \ # # *** IJG JPEG library (libjpeg) location -I/usr/local/include -L/usr/local/lib -ljpeg \ # # *** ZLIB (libz) location -I/usr/local/include -L/usr/local/lib -lz # -------------------------------------------------------------------- # Tkinter bindings. Comment away if you don't need ImageTk, or if # you're using a custom _tkinter instead (like in earlier versions of # PIL). Edit the library specifications to match your configuration. _imagingtk _imagingtk.c \ -IlibImaging Tk/tkImaging.c \ -I/usr/local/include -L/usr/local/lib -ltcl8.0 -ltk8.0 \ -L/usr/X11R6/lib -lX11 # -------------------------------------------------------------------- # Sane driver. uncomment to enable this driver (see Sane/README for # more info) # _sane Sane/_sanemodule.c -IlibImaging -L/usr/local/lib/sane/ -lsane-dll Imaging-1.1.3/Makefile.pre.in0100444000076400007640000002313207442710203015566 0ustar fredrikfredrik# Universal Unix Makefile for Python extensions # ============================================= # Short Instructions # ------------------ # 1. Build and install Python (1.5 or newer). # 2. "make -f Makefile.pre.in boot" # 3. "make" # You should now have a shared library. # Long Instructions # ----------------- # Build *and install* the basic Python 1.5 distribution. See the # Python README for instructions. (This version of Makefile.pre.in # only withs with Python 1.5, alpha 3 or newer.) # Create a file Setup.in for your extension. This file follows the # format of the Modules/Setup.in file; see the instructions there. # For a simple module called "spam" on file "spammodule.c", it can # contain a single line: # spam spammodule.c # You can build as many modules as you want in the same directory -- # just have a separate line for each of them in the Setup.in file. # If you want to build your extension as a shared library, insert a # line containing just the string # *shared* # at the top of your Setup.in file. # Note that the build process copies Setup.in to Setup, and then works # with Setup. It doesn't overwrite Setup when Setup.in is changed, so # while you're in the process of debugging your Setup.in file, you may # want to edit Setup instead, and copy it back to Setup.in later. # (All this is done so you can distribute your extension easily and # someone else can select the modules they actually want to build by # commenting out lines in the Setup file, without editing the # original. Editing Setup is also used to specify nonstandard # locations for include or library files.) # Copy this file (Misc/Makefile.pre.in) to the directory containing # your extension. # Run "make -f Makefile.pre.in boot". This creates Makefile # (producing Makefile.pre and sedscript as intermediate files) and # config.c, incorporating the values for sys.prefix, sys.exec_prefix # and sys.version from the installed Python binary. For this to work, # the python binary must be on your path. If this fails, try # make -f Makefile.pre.in Makefile VERSION=1.5 installdir= # where is the prefix used to install Python for installdir # (and possibly similar for exec_installdir=). # Note: "make boot" implies "make clobber" -- it assumes that when you # bootstrap you may have changed platforms so it removes all previous # output files. # If you are building your extension as a shared library (your # Setup.in file starts with *shared*), run "make" or "make sharedmods" # to build the shared library files. If you are building a statically # linked Python binary (the only solution of your platform doesn't # support shared libraries, and sometimes handy if you want to # distribute or install the resulting Python binary), run "make # python". # Note: Each time you edit Makefile.pre.in or Setup, you must run # "make Makefile" before running "make". # Hint: if you want to use VPATH, you can start in an empty # subdirectory and say (e.g.): # make -f ../Makefile.pre.in boot srcdir=.. VPATH=.. # === Bootstrap variables (edited through "make boot") === # The prefix used by "make inclinstall libainstall" of core python installdir= /usr/local # The exec_prefix used by the same exec_installdir=$(installdir) # Source directory and VPATH in case you want to use VPATH. # (You will have to edit these two lines yourself -- there is no # automatic support as the Makefile is not generated by # config.status.) srcdir= . VPATH= . # === Variables that you may want to customize (rarely) === # (Static) build target TARGET= python # Installed python binary (used only by boot target) PYTHON= python # Add more -I and -D options here CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(EXECINCLUDEPY) $(DEFS) # These two variables can be set in Setup to merge extensions. # See example[23]. BASELIB= BASESETUP= # === Variables set by makesetup === MODOBJS= _MODOBJS_ MODLIBS= _MODLIBS_ # === Definitions added by makesetup === # === Variables from configure (through sedscript) === VERSION= @VERSION@ CC= @CC@ LINKCC= @LINKCC@ SGI_ABI= @SGI_ABI@ OPT= @OPT@ LDFLAGS= @LDFLAGS@ DEFS= @DEFS@ LIBS= @LIBS@ LIBM= @LIBM@ LIBC= @LIBC@ RANLIB= @RANLIB@ MACHDEP= @MACHDEP@ SO= @SO@ LDSHARED= @LDSHARED@ CCSHARED= @CCSHARED@ LINKFORSHARED= @LINKFORSHARED@ #@SET_CCC@ # Install prefix for architecture-independent files prefix= /usr/local # Install prefix for architecture-dependent files exec_prefix= $(prefix) # === Fixed definitions === # Shell used by make (some versions default to the login shell, which is bad) SHELL= /bin/sh # Expanded directories BINDIR= $(exec_installdir)/bin LIBDIR= $(exec_prefix)/lib MANDIR= $(installdir)/man INCLUDEDIR= $(installdir)/include SCRIPTDIR= $(prefix)/lib # Detailed destination directories BINLIBDEST= $(LIBDIR)/python$(VERSION) LIBDEST= $(SCRIPTDIR)/python$(VERSION) INCLUDEPY= $(INCLUDEDIR)/python$(VERSION) EXECINCLUDEPY= $(exec_installdir)/include/python$(VERSION) LIBP= $(exec_installdir)/lib/python$(VERSION) DESTSHARED= $(BINLIBDEST)/site-packages LIBPL= $(LIBP)/config PYTHONLIBS= $(LIBPL)/libpython$(VERSION).a MAKESETUP= $(LIBPL)/makesetup MAKEFILE= $(LIBPL)/Makefile CONFIGC= $(LIBPL)/config.c CONFIGCIN= $(LIBPL)/config.c.in SETUP= $(LIBPL)/Setup SYSLIBS= $(LIBM) $(LIBC) ADDOBJS= $(LIBPL)/python.o config.o # Portable install script (configure doesn't always guess right) INSTALL= $(LIBPL)/install-sh -c # Shared libraries must be installed with executable mode on some systems; # rather than figuring out exactly which, we always give them executable mode. # Also, making them read-only seems to be a good idea... INSTALL_SHARED= ${INSTALL} -m 555 # === Fixed rules === # Default target. This builds shared libraries only default: sharedmods # Build everything all: static sharedmods # Build shared libraries from our extension modules sharedmods: $(SHAREDMODS) # Build a static Python binary containing our extension modules static: $(TARGET) $(TARGET): $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB) $(CC) $(LDFLAGS) $(ADDOBJS) lib.a $(PYTHONLIBS) \ $(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) \ -o $(TARGET) install: sharedmods if test ! -d $(DESTSHARED) ; then \ mkdir $(DESTSHARED) ; else true ; fi -for i in X $(SHAREDMODS); do \ if test $$i != X; \ then $(INSTALL_SHARED) $$i $(DESTSHARED)/$$i; \ fi; \ done # Build the library containing our extension modules lib.a: $(MODOBJS) -rm -f lib.a ar cr lib.a $(MODOBJS) -$(RANLIB) lib.a # This runs makesetup *twice* to use the BASESETUP definition from Setup config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP) $(MAKESETUP) \ -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) $(MAKE) -f Makefile do-it-again # Internal target to run makesetup for the second time do-it-again: $(MAKESETUP) \ -m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP) # Make config.o from the config.c created by makesetup config.o: config.c $(CC) $(CFLAGS) -c config.c # Setup is copied from Setup.in *only* if it doesn't yet exist Setup: cp $(srcdir)/Setup.in Setup # Make the intermediate Makefile.pre from Makefile.pre.in Makefile.pre: Makefile.pre.in sedscript sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre # Shortcuts to make the sed arguments on one line P=prefix E=exec_prefix H=Generated automatically from Makefile.pre.in by sedscript. L=LINKFORSHARED # Make the sed script used to create Makefile.pre from Makefile.pre.in sedscript: $(MAKEFILE) sed -n \ -e '1s/.*/1i\\/p' \ -e '2s%.*%# $H%p' \ -e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \ -e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \ -e '/^CCC=/s/^CCC=[ ]*\(.*\)/s%#@SET_CCC[@]%CCC=\1%/p' \ -e '/^LINKCC=/s/^LINKCC=[ ]*\(.*\)/s%@LINKCC[@]%\1%/p' \ -e '/^OPT=/s/^OPT=[ ]*\(.*\)/s%@OPT[@]%\1%/p' \ -e '/^LDFLAGS=/s/^LDFLAGS=[ ]*\(.*\)/s%@LDFLAGS[@]%\1%/p' \ -e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \ -e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \ -e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \ -e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \ -e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \ -e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \ -e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \ -e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \ -e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \ -e '/^$L=/s/^$L=[ ]*\(.*\)/s%@$L[@]%\1%/p' \ -e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \ -e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \ $(MAKEFILE) >sedscript echo "/^#@SET_CCC@/d" >>sedscript echo "/^installdir=/s%=.*%= $(installdir)%" >>sedscript echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%" >>sedscript echo "/^srcdir=/s%=.*%= $(srcdir)%" >>sedscript echo "/^VPATH=/s%=.*%= $(VPATH)%" >>sedscript echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%" >>sedscript echo "/^BASELIB=/s%=.*%= $(BASELIB)%" >>sedscript echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%" >>sedscript # Bootstrap target boot: clobber VERSION=`$(PYTHON) -c "import sys; print sys.version[:3]"`; \ installdir=`$(PYTHON) -c "import sys; print sys.prefix"`; \ exec_installdir=`$(PYTHON) -c "import sys; print sys.exec_prefix"`; \ $(MAKE) -f $(srcdir)/Makefile.pre.in VPATH=$(VPATH) srcdir=$(srcdir) \ VERSION=$$VERSION \ installdir=$$installdir \ exec_installdir=$$exec_installdir \ Makefile # Handy target to remove intermediate files and backups clean: -rm -f *.o *~ # Handy target to remove everything that is easily regenerated clobber: clean -rm -f *.a tags TAGS config.c Makefile.pre $(TARGET) sedscript -rm -f *.so *.sl so_locations # Handy target to remove everything you don't want to distribute distclean: clobber -rm -f Makefile Setup Imaging-1.1.3/libImaging/Makefile.win0100444000076400007640000000333707442710204017240 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: Makefile.win,v 1.1 2025/05/09 23:34:53 fredrik Exp $ # # makefile for VC++ 4.X and 5.0 # # This makefile compiles and tests the Imaging core library. # # To build with the IJG JPEG and ZLIB libraries, you may have # to change the JPEGINCLUDE and ZLIBINCLUDE settings. # # Copyright (c) 1996-2002 by Secret Labs AB # Copyright (c) 1995-1996 by Fredrik Lundh # # See the README file for information on usage and redistribution. # all: imaging.lib JPEGINCLUDE= -I../../../kits/jpeg-6b TIFFINCLUDE= -I../../../kits/tifflib ZLIBINCLUDE= -I../../../kits/zlib-1.1.3 CC= cl.exe CFLAGS= -W3 -Ox -O2 -c -MD -nologo $(JPEGINCLUDE) \ $(TIFFINCLUDE) $(ZLIBINCLUDE) OUTLIB= imaging.lib OBJS= Access.obj\ Antialias.obj\ Bands.obj\ BitDecode.obj\ Blend.obj\ Chops.obj\ Convert.obj\ ConvertYCbCr.obj\ Copy.obj\ Crc32.obj\ Crop.obj\ Dib.obj\ Draw.obj\ Effects.obj\ EpsEncode.obj\ Except.obj\ File.obj\ Fill.obj\ Filter.obj\ FliDecode.obj\ Geometry.obj\ GetBBox.obj\ GifDecode.obj\ GifEncode.obj\ HexDecode.obj\ Histo.obj\ JpegDecode.obj\ JpegEncode.obj\ LzwDecode.obj\ Matrix.obj\ MspDecode.obj\ Negative.obj\ Offset.obj\ Pack.obj\ PackDecode.obj\ Palette.obj\ Paste.obj\ Quant.obj\ QuantHash.obj\ QuantHeap.obj\ PcdDecode.obj\ PcxDecode.obj\ PcxEncode.obj\ Point.obj\ RawDecode.obj\ RawEncode.obj\ Storage.obj\ SunRleDecode.obj\ TgaRleDecode.obj\ Unpack.obj\ UnpackYCC.obj\ XbmDecode.obj\ XbmEncode.obj\ ZipDecode.obj\ ZipEncode.obj $(OUTLIB): $(OBJS) lib -out:$(OUTLIB) $(OBJS) coretest.exe: coretest.c $(OUTLIB) $(CPP) -MD -o coretest.exe coretest.c $(OUTLIB) clean: del *.obj del $(OUTLIB) test: coretest Imaging-1.1.3/libImaging/ImConfig.h.win0100444000076400007640000000442107442710204017437 0ustar fredrikfredrik/* $Id: //modules/pil/libImaging/ImConfig.h#2 $ * * The Python Imaging Library. * * File: * ImConfig.win -- ImConfig.h template for Windows (from ImConfig.h) * * Copyright (c) Fredrik Lundh 1995. */ /* -------------------------------------------------------------------- */ /* Define if you have the IJG jpeg library (-ljpeg). */ #define HAVE_LIBJPEG /* Define if you have the Greg Ward's mpeg library (-lmpeg). */ #undef HAVE_LIBMPEG /* Define if you have the zlib compression library (-lz). */ #define HAVE_LIBZ /* -------------------------------------------------------------------- */ /* Note: this configuration file was designed for Visual C++ 4.0 and * later. It might need some tweaking to work with other compilers, * including 16-bit environments. */ #ifndef WIN32 #define WIN32 #endif /* VC++ 4.0 is a bit annoying when it comes to precision issues (like claiming that "float a = 0.0;" would lead to loss of precision). I don't like to see warnings from my code, but since I still want to keep it readable, I simply switch off a few warnings instead of adding the tons of casts that VC++ seem to require. This code is compiled with numerous other compilers as well, so any real errors are likely to be catched anyway. */ #pragma warning(disable: 4244) /* conversion from 'float' to 'int' */ #pragma warning(disable: 4305) /* conversion from 'const int' to 'char' */ /* Define to empty if the keyword does not work. */ /* #undef const */ /* Define as __inline if that's what the C compiler calls it. */ #define inline __inline #ifndef HAVE_PROTOTYPES /* Define if you have ANSI prototypes. */ #define HAVE_PROTOTYPES 1 #endif #ifndef STDC_HEADERS /* Define if you have the ANSI C header files. */ #define STDC_HEADERS 1 #endif /* Define if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ /* #undef WORDS_BIGENDIAN */ /* The number of bytes in a char. */ #define SIZEOF_CHAR 1 /* The number of bytes in a double. */ #define SIZEOF_DOUBLE 8 /* The number of bytes in a float. */ #define SIZEOF_FLOAT 4 /* The number of bytes in a int. */ #define SIZEOF_INT 4 /* The number of bytes in a long. */ #define SIZEOF_LONG 4 /* The number of bytes in a short. */ #define SIZEOF_SHORT 2 Imaging-1.1.3/libImaging/Imaging.h0100444000076400007640000004060507442710204016527 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Imaging.h#3 $ * * declarations for the imaging core library * * Copyright (c) 1997-2002 by Secret Labs AB * Copyright (c) 1995-2002 by Fredrik Lundh * * See the README file for information on usage and redistribution. */ #include #include #include #include #include "ImPlatform.h" #if defined(__cplusplus) extern "C" { #endif #ifndef M_PI #define M_PI 3.14159265359 #endif /* -------------------------------------------------------------------- */ /* * Image data organization: * * mode bytes byte order * ------------------------------- * 1 1 1 * L 1 L * P 1 P * I 4 I (32-bit integer, native byte order) * F 4 F (32-bit IEEE float, native byte order) * RGB 4 R, G, B, - * RGBA 4 R, G, B, A * CMYK 4 C, M, Y, K * YCbCr 4 Y, Cb, Cr, - * * "P" is an 8-bit palette mode, which should be mapped through the * palette member to get an output image. Check palette->mode to * find the corresponding "real" mode. */ /* Handles */ typedef struct ImagingMemoryInstance* Imaging; typedef struct ImagingAccessInstance* ImagingAccess; typedef struct ImagingHistogramInstance* ImagingHistogram; typedef struct ImagingOutlineInstance* ImagingOutline; typedef struct ImagingPaletteInstance* ImagingPalette; /* pixel types */ #define IMAGING_TYPE_UINT8 0 #define IMAGING_TYPE_INT32 1 #define IMAGING_TYPE_FLOAT32 2 #define IMAGING_TYPE_SPECIAL 3 struct ImagingMemoryInstance { /* Format */ char mode[4+1]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK") */ int type; /* Data type */ int depth; /* Depth (ignored in this version) */ int bands; /* Number of bands (1, 3, or 4) */ int xsize; /* Image dimension. */ int ysize; /* Colour palette (for "P" images only) */ ImagingPalette palette; /* Data pointers */ UINT8 **image8; /* Set for 8-bit image (pixelsize=1). */ INT32 **image32; /* Set for 32-bit image (pixelsize=4). */ /* Internals */ char **image; /* Actual raster data. */ char *block; /* Set if data is allocated in a single block. */ int pixelsize; /* Size of a pixel, in bytes (1, 2 or 4) */ int linesize; /* Size of a line, in bytes (xsize * pixelsize) */ /* Virtual methods */ void (*destroy)(Imaging im); }; #define IMAGING_ACCESS_HEAD\ int (*getline)(ImagingAccess access, char *buffer, int y);\ void (*destroy)(ImagingAccess access) struct ImagingAccessInstance { IMAGING_ACCESS_HEAD; /* Data members */ Imaging im; }; struct ImagingHistogramInstance { /* Format */ char mode[4+1]; /* Band names (of corresponding source image) */ int bands; /* Number of bands (1, 3, or 4) */ /* Data */ long *histogram; /* Histogram (bands*256 longs) */ }; struct ImagingPaletteInstance { /* Format */ char mode[4+1]; /* Band names */ /* Data */ UINT8 palette[1024];/* Palette data (same format as image data) */ INT16* cache; /* Palette cache (used for predefined palettes) */ int keep_cache; /* This palette will be reused; keep cache */ }; /* Objects */ /* ------- */ extern Imaging ImagingNew(const char* mode, int xsize, int ysize); extern Imaging ImagingNew2(const char* mode, Imaging imOut, Imaging imIn); extern void ImagingDelete(Imaging im); extern Imaging ImagingNewBlock(const char* mode, int xsize, int ysize); extern Imaging ImagingNewArray(const char* mode, int xsize, int ysize); extern Imaging ImagingNewMap(const char* filename, int readonly, const char* mode, int xsize, int ysize); extern Imaging ImagingNewPrologue(const char *mode, unsigned xsize, unsigned ysize); extern Imaging ImagingNewEpilogue(Imaging im); extern void ImagingCopyInfo(Imaging destination, Imaging source); extern void ImagingHistogramDelete(ImagingHistogram histogram); extern ImagingAccess ImagingAccessNew(Imaging im); extern void ImagingAccessDelete(ImagingAccess access); extern ImagingPalette ImagingPaletteNew(const char *mode); extern ImagingPalette ImagingPaletteNewBrowser(void); extern ImagingPalette ImagingPaletteDuplicate(ImagingPalette palette); extern void ImagingPaletteDelete(ImagingPalette palette); extern int ImagingPaletteCachePrepare(ImagingPalette palette); extern void ImagingPaletteCacheUpdate(ImagingPalette palette, int r, int g, int b); extern void ImagingPaletteCacheDelete(ImagingPalette palette); #define ImagingPaletteCache(p, r, g, b)\ p->cache[(r>>2) + (g>>2)*64 + (b>>2)*64*64] extern Imaging ImagingQuantize(Imaging im, int colours, int mode, int kmeans); /* Exceptions */ /* ---------- */ extern void* ImagingError_IOError(void); extern void* ImagingError_MemoryError(void); extern void* ImagingError_ModeError(void); /* maps to ValueError by default */ extern void* ImagingError_Mismatch(void); /* maps to ValueError by default */ extern void* ImagingError_ValueError(const char* message); /* Transform callbacks */ /* ------------------- */ /* standard transforms */ #define IMAGING_TRANSFORM_AFFINE 0 #define IMAGING_TRANSFORM_QUAD 3 /* standard filters */ #define IMAGING_TRANSFORM_NEAREST 0 #define IMAGING_TRANSFORM_ANTIALIAS 1 #define IMAGING_TRANSFORM_BILINEAR 2 #define IMAGING_TRANSFORM_BICUBIC 3 typedef int (*ImagingTransformMap)(double* X, double* Y, int x, int y, void* data); typedef int (*ImagingTransformFilter)(void* out, Imaging im, double x, double y, void* data); /* Image Manipulation Methods */ /* -------------------------- */ extern Imaging ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha); extern Imaging ImagingCopy(Imaging im); extern Imaging ImagingConvert( Imaging im, const char* mode, ImagingPalette palette, int dither); extern Imaging ImagingConvertMatrix(Imaging im, const char *mode, float m[]); extern Imaging ImagingCrop(Imaging im, int x0, int y0, int x1, int y1); extern Imaging ImagingFill(Imaging im, const void* ink); extern int ImagingFill2( Imaging into, const void* ink, Imaging mask, int x0, int y0, int x1, int y1); extern Imaging ImagingFilter(Imaging im, const int* kernel); extern Imaging ImagingFilterThin(Imaging im, int maxpass); extern Imaging ImagingFillLinearGradient(const char* mode); extern Imaging ImagingFillRadialGradient(const char* mode); extern Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn); extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn); extern Imaging ImagingGetBand(Imaging im, int band); extern int ImagingGetBBox(Imaging im, int bbox[4]); extern int ImagingGetExtrema(Imaging im, void *extrema); extern int ImagingGetProjection(Imaging im, UINT8* xproj, UINT8* yproj); extern ImagingHistogram ImagingGetHistogram( Imaging im, Imaging mask, void *extrema); extern Imaging ImagingNegative(Imaging im); extern Imaging ImagingOffset(Imaging im, int xoffset, int yoffset); extern int ImagingPaste( Imaging into, Imaging im, Imaging mask, int x0, int y0, int x1, int y1); extern Imaging ImagingPoint( Imaging im, const char* tablemode, const void* table); extern Imaging ImagingPointTransform( Imaging imIn, double scale, double offset); extern Imaging ImagingPutBand(Imaging im, Imaging imIn, int band); extern Imaging ImagingResize(Imaging imOut, Imaging imIn, int filter); extern Imaging ImagingRotate( Imaging imOut, Imaging imIn, double theta, int filter); extern Imaging ImagingRotate90(Imaging imOut, Imaging imIn); extern Imaging ImagingRotate180(Imaging imOut, Imaging imIn); extern Imaging ImagingRotate270(Imaging imOut, Imaging imIn); extern Imaging ImagingStretch(Imaging imOut, Imaging imIn, int filter); extern Imaging ImagingTransformAffine( Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, double a[6], int filter, int fill); extern Imaging ImagingTransformQuad( Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, double a[8], int filter, int fill); extern Imaging ImagingTransform( Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, ImagingTransformMap transform, void* transform_data, ImagingTransformFilter filter, void* filter_data, int fill); extern Imaging ImagingCopy2(Imaging imOut, Imaging imIn); extern Imaging ImagingConvert2(Imaging imOut, Imaging imIn); /* Standard Image Enhancement Filters */ extern Imaging ImagingFilterBlur(Imaging im); extern Imaging ImagingFilterContour(Imaging im); extern Imaging ImagingFilterDetail(Imaging im); extern Imaging ImagingFilterEdgeEnhance(Imaging im); extern Imaging ImagingFilterEdgeEnhanceMore(Imaging im); extern Imaging ImagingFilterEmboss(Imaging im); extern Imaging ImagingFilterFindEdges(Imaging im); extern Imaging ImagingFilterSmooth(Imaging im); extern Imaging ImagingFilterSmoothMore(Imaging im); extern Imaging ImagingFilterSharpen(Imaging im); /* Channel operations */ /* any mode, except "F" */ extern Imaging ImagingChopLighter(Imaging imIn1, Imaging imIn2); extern Imaging ImagingChopDarker(Imaging imIn1, Imaging imIn2); extern Imaging ImagingChopDifference(Imaging imIn1, Imaging imIn2); extern Imaging ImagingChopMultiply(Imaging imIn1, Imaging imIn2); extern Imaging ImagingChopScreen(Imaging imIn1, Imaging imIn2); extern Imaging ImagingChopAdd( Imaging imIn1, Imaging imIn2, float scale, int offset); extern Imaging ImagingChopSubtract( Imaging imIn1, Imaging imIn2, float scale, int offset); extern Imaging ImagingChopAddModulo(Imaging imIn1, Imaging imIn2); extern Imaging ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2); /* "1" images only */ extern Imaging ImagingChopAnd(Imaging imIn1, Imaging imIn2); extern Imaging ImagingChopOr(Imaging imIn1, Imaging imIn2); extern Imaging ImagingChopXor(Imaging imIn1, Imaging imIn2); /* Image measurement */ extern void ImagingCrack(Imaging im, int x0, int y0); /* Graphics */ struct ImagingAffineMatrixInstance { float a[9]; }; typedef struct ImagingAffineMatrixInstance *ImagingAffineMatrix; extern int ImagingDrawArc(Imaging im, int x0, int y0, int x1, int y1, int start, int end, const void* ink); extern int ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap, const void* ink); extern int ImagingDrawChord(Imaging im, int x0, int y0, int x1, int y1, int start, int end, const void* ink, int fill); extern int ImagingDrawEllipse(Imaging im, int x0, int y0, int x1, int y1, const void* ink, int fill); extern int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink); extern int ImagingDrawPieslice(Imaging im, int x0, int y0, int x1, int y1, int start, int end, const void* ink, int fill); extern int ImagingDrawPoint(Imaging im, int x, int y, const void* ink); extern int ImagingDrawPolygon(Imaging im, int points, int *xy, const void* ink, int fill); extern int ImagingDrawRectangle(Imaging im, int x0, int y0, int x1, int y1, const void* ink, int fill); /* Level 2 graphics (WORK IN PROGRESS) */ extern ImagingOutline ImagingOutlineNew(void); extern void ImagingOutlineDelete(ImagingOutline outline); extern int ImagingDrawOutline(Imaging im, ImagingOutline outline, const void* ink, int fill); extern int ImagingOutlineMove(ImagingOutline outline, float x, float y); extern int ImagingOutlineLine(ImagingOutline outline, float x, float y); extern int ImagingOutlineCurve(ImagingOutline outline, float x1, float y1, float x2, float y2, float x3, float y3); extern int ImagingOutlineTransform(ImagingOutline outline, double a[6]); extern int ImagingOutlineClose(ImagingOutline outline); /* Special effects */ extern Imaging ImagingEffectSpread(Imaging imIn, int distance); extern Imaging ImagingEffectNoise(int xsize, int ysize, float sigma); extern Imaging ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality); /* Obsolete */ extern int ImagingToString(Imaging im, int orientation, char *buffer); extern int ImagingFromString(Imaging im, int orientation, char *buffer); /* File I/O */ /* -------- */ /* Built-in drivers */ extern Imaging ImagingOpenPPM(const char* filename); extern int ImagingSavePPM(Imaging im, const char* filename); /* Utility functions */ extern UINT32 ImagingCRC32(UINT32 crc, UINT8* buffer, int bytes); /* Codecs */ typedef struct ImagingCodecStateInstance *ImagingCodecState; typedef int (*ImagingCodec)(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingBitDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingEpsEncode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); #ifdef HAVE_LIBJPEG extern int ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); #endif extern int ImagingLzwDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); #ifdef HAVE_LIBMPEG extern int ImagingMpegDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); #endif extern int ImagingMspDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingPackbitsDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingPcxEncode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingXbmDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); #ifdef HAVE_LIBZ extern int ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); #endif typedef void (*ImagingShuffler)(UINT8* out, const UINT8* in, int pixels); /* Public shufflers */ extern void ImagingPackRGB(UINT8* out, const UINT8* in, int pixels); extern void ImagingPackBGR(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackRGB(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackBGR(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackYCC(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackYCCA(UINT8* out, const UINT8* in, int pixels); extern void ImagingUnpackYCbCr(UINT8* out, const UINT8* in, int pixels); extern void ImagingConvertRGB2YCbCr(UINT8* out, const UINT8* in, int pixels); extern void ImagingConvertYCbCr2RGB(UINT8* out, const UINT8* in, int pixels); extern ImagingShuffler ImagingFindUnpacker(const char* mode, const char* rawmode, int* bits_out); extern ImagingShuffler ImagingFindPacker(const char* mode, const char* rawmode, int* bits_out); struct ImagingCodecStateInstance { int count; int state; int errcode; int x, y; int ystep; int xsize, ysize, xoff, yoff; ImagingShuffler shuffle; int bits, bytes; UINT8 *buffer; void *context; }; /* Errcodes */ #define IMAGING_CODEC_END 1 #define IMAGING_CODEC_OVERRUN -1 #define IMAGING_CODEC_BROKEN -2 #define IMAGING_CODEC_UNKNOWN -3 #define IMAGING_CODEC_CONFIG -8 #define IMAGING_CODEC_MEMORY -9 #if defined(__cplusplus) } #endif Imaging-1.1.3/libImaging/ImDib.h0100444000076400007640000000226507442710204016140 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/ImDib.h#2 $ * * Windows DIB specifics * * Copyright (c) Secret Labs AB 1997-98. * Copyright (c) Fredrik Lundh 1996. * * See the README file for information on usage and redistribution. */ #ifdef WIN32 #include #if defined(__cplusplus) extern "C" { #endif struct ImagingDIBInstance { /* Windows interface */ HDC dc; HBITMAP bitmap; HGDIOBJ old_bitmap; BITMAPINFO *info; UINT8 *bits; HPALETTE palette; /* Used by cut and paste */ char mode[4]; int xsize, ysize; int pixelsize; int linesize; ImagingShuffler pack; ImagingShuffler unpack; }; typedef struct ImagingDIBInstance* ImagingDIB; extern char* ImagingGetModeDIB(int size_out[2]); extern ImagingDIB ImagingNewDIB(const char *mode, int xsize, int ysize); extern void ImagingDeleteDIB(ImagingDIB im); extern void ImagingDrawDIB(ImagingDIB dib, int dc, int dst[4], int src[4]); extern void ImagingExposeDIB(ImagingDIB dib, int dc); extern int ImagingQueryPaletteDIB(ImagingDIB dib, int dc); extern void ImagingPasteDIB(ImagingDIB dib, Imaging im, int xy[4]); #if defined(__cplusplus) } #endif #endif Imaging-1.1.3/libImaging/ImPlatform.h0100444000076400007640000000225307442710204017223 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/ImPlatform.h#2 $ * * platform declarations for the imaging core library * * Copyright (c) Fredrik Lundh 1995-96. */ #include "ImConfig.h" /* Check that we have an ANSI compliant compiler */ #ifndef HAVE_PROTOTYPES #error Sorry, this library requires support for ANSI prototypes. #endif #ifndef STDC_HEADERS #error Sorry, this library requires ANSI header files. #endif #if SIZEOF_SHORT == 2 #define INT16 short #elif SIZEOF_INT == 2 #define INT16 int #else #define INT16 short /* most things works just fine anyway... */ #endif #if SIZEOF_SHORT == 4 #define INT32 short #elif SIZEOF_INT == 4 #define INT32 int #elif SIZEOF_LONG == 4 #define INT32 long #else #error Cannot find required 32-bit integer type #endif #if SIZEOF_LONG == 8 #define INT64 long #endif #if SIZEOF_FLOAT == 4 #define FLOAT32 float #elif SIZEOF_DOUBLE == 4 #define FLOAT32 double /* and pigs can fly... */ #else #error Cannot find required 32-bit floating point type #endif #if SIZEOF_DOUBLE == 8 #define FLOAT64 double #endif #define INT8 signed char #define UINT8 unsigned char #define UINT16 unsigned INT16 #define UINT32 unsigned INT32 Imaging-1.1.3/libImaging/Quant.h0100444000076400007640000000143307442710204016240 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Quant.h#2 $ * * image quantizer * * Written by Toby J Sargeant . * * See the README file for information on usage and redistribution. */ #ifndef __QUANT_H__ #define __QUANT_H__ typedef union { struct { unsigned char r,g,b,a; } c; struct { unsigned char v[4]; } a; unsigned long v; } Pixel; int quantize(Pixel *, unsigned long, unsigned long, Pixel **, unsigned long *, unsigned long **, int); int quantize2(Pixel *, unsigned long, unsigned long, Pixel **, unsigned long *, unsigned long **, int); #endif Imaging-1.1.3/libImaging/QuantHash.h0100444000076400007640000000243107442710204017043 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/QuantHash.h#2 $ * * image quantizer * * Written by Toby J Sargeant . * * See the README file for information on usage and redistribution. */ #ifndef __HASH_H__ #define __HASH_H__ #include "QuantTypes.h" HashTable hashtable_new(HashFunc,HashCmpFunc); void hashtable_free(HashTable); void hashtable_foreach(HashTable,IteratorFunc,void *); void hashtable_foreach_update(HashTable,IteratorUpdateFunc,void *); int hashtable_insert(HashTable,void *,void *); int hashtable_update(HashTable,void *,void *); int hashtable_lookup(const HashTable,const void *,void **); int hashtable_lookup_or_insert(HashTable,void *,void **,void *); int hashtable_insert_or_update_computed(HashTable,void *,ComputeFunc,ComputeFunc); int hashtable_delete(HashTable,const void *); int hashtable_remove(HashTable,const void *,void **,void **); void *hashtable_set_user_data(HashTable,void *); void *hashtable_get_user_data(const HashTable); DestroyFunc hashtable_set_key_destroy_func(HashTable,DestroyFunc); DestroyFunc hashtable_set_value_destroy_func(HashTable,DestroyFunc); unsigned long hashtable_get_count(const HashTable); void hashtable_rehash(HashTable); void hashtable_rehash_compute(HashTable,CollisionFunc); #endif Imaging-1.1.3/libImaging/QuantHeap.h0100444000076400007640000000077607442710204017047 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/QuantHeap.h#3 $ * * image quantizer * * Written by Toby J Sargeant . * * See the README file for information on usage and redistribution. */ #ifndef __HEAP_H__ #define __HEAP_H__ #include "QuantTypes.h" void ImagingQuantHeapFree(Heap); int ImagingQuantHeapRemove(Heap,void **); int ImagingQuantHeapAdd(Heap,void *); int ImagingQuantHeapTop(Heap,void **); Heap *ImagingQuantHeapNew(HeapCmpFunc); #endif Imaging-1.1.3/libImaging/QuantDefines.h0100444000076400007640000000107307442710204017536 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/QuantDefines.h#2 $ * * image quantizer * * Written by Toby J Sargeant . * * See the README file for information on usage and redistribution. */ #ifndef __DEFINES_H__ #define __DEFINES_H__ #if 0 void *newMalloc(size_t,const char *,const char *,int); void newFree(void *,const char *,const char *,int); void print_malloc_stats(); #define malloc(x) newMalloc(x,__FILE__,__FUNCTION__,__LINE__) #define free(x) newFree(x,__FILE__,__FUNCTION__,__LINE__) #endif #endif Imaging-1.1.3/libImaging/QuantTypes.h0100444000076400007640000000161007442710204017262 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/QuantTypes.h#2 $ * * image quantizer * * Written by Toby J Sargeant . * * See the README file for information on usage and redistribution. */ #ifndef __TYPES_H__ #define __TYPES_H__ typedef void *HashTable; typedef void *Heap; typedef unsigned long (*HashFunc)(const HashTable,const void *); typedef int (*HashCmpFunc)(const HashTable,const void *,const void *); typedef void (*IteratorFunc)(const HashTable,const void *,const void *,void *); typedef void (*IteratorUpdateFunc)(const HashTable,const void *,void **,void *); typedef void (*DestroyFunc)(const HashTable,void *); typedef void (*ComputeFunc)(const HashTable,const void *,void **); typedef void (*CollisionFunc)(const HashTable,void **,void **,void *,void *); typedef int (*HeapCmpFunc)(const Heap,const void *,const void *); #endif Imaging-1.1.3/libImaging/Access.c0100444000076400007640000000203407442710204016342 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Access.c#2 $ * * imaging access objects * * an access object can convert image data on the fly * * history: * 98-12-29 fl Created * * Copyright (c) Secret Labs AB 1998. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" static void destroy(ImagingAccess access) { /* nop */ } static int getline(ImagingAccess access, char* buffer, int y) { memcpy(buffer, access->im->image[y], access->im->linesize); return 1; } ImagingAccess ImagingAccessNew(Imaging im) { /* Create a standard access object */ ImagingAccess access; access = calloc(1, sizeof(struct ImagingAccessInstance)); if (!access) return (ImagingAccess) ImagingError_MemoryError(); access->im = im; access->getline = getline; access->destroy = destroy; return access; } void ImagingAccessDelete(ImagingAccess access) { if (!access) return; if (access->destroy) access->destroy(access); free(access); } Imaging-1.1.3/libImaging/Antialias.c0100444000076400007640000002313207442757331017064 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Antialias.c#6 $ * * pilopen antialiasing support * * history: * 2025-03-09 fl Created (for PIL 1.1.3) * 2025-03-10 fl Added support for mode "F" * * Copyright (c) 1997-2002 by Secret Labs AB * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #include /* resampling filters (from antialias.py) */ struct filter { float (*filter)(float x); float support; }; static float sinc(float x) { if (x == 0.0) return 1.0; x = x * M_PI; return sin(x) / x; } static float antialias(float x) { /* lanczos (truncated sinc) */ if (-3.0 <= x && x < 3.0) return sinc(x) * sinc(x/3); return 0.0; } static struct filter ANTIALIAS = { antialias, 3.0 }; static float nearest(float x) { if (-0.5 <= x && x < 0.5) return 1.0; return 0.0; } static struct filter NEAREST = { nearest, 0.5 }; static float bilinear(float x) { if (x < 0.0) x = -x; if (x < 1.0) return 1.0-x; return 0.0; } static struct filter BILINEAR = { bilinear, 1.0 }; static float bicubic(float x) { /* FIXME: double-check this algorithm */ /* FIXME: for best results, "a" should be -0.5 to -1.0, but we'll set it to zero for now, to match the 1.1 magnifying filter */ #define a 0.0 if (x < 0.0) x = -x; if (x < 1.0) return (((a + 2.0) * x) - (a + 3.0)) * x*x + 1; if (x < 2.0) return (((a * x) - 5*a) * x + 8) * x - 4*a; return 0.0; #undef a } static struct filter BICUBIC = { bicubic, 2.0 }; Imaging ImagingStretch(Imaging imOut, Imaging imIn, int filter) { /* FIXME: this is a quick and straightforward translation from a python prototype. might need some further C-ification... */ struct filter *filterp; float support, scale, filterscale; float center, ww, ss, ymin, ymax, xmin, xmax; int xx, yy, x, y, b; float *k; /* check modes */ if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); /* check filter */ switch (filter) { case IMAGING_TRANSFORM_NEAREST: filterp = &NEAREST; break; case IMAGING_TRANSFORM_ANTIALIAS: filterp = &ANTIALIAS; break; case IMAGING_TRANSFORM_BILINEAR: filterp = &BILINEAR; break; case IMAGING_TRANSFORM_BICUBIC: filterp = &BICUBIC; break; default: return (Imaging) ImagingError_ValueError( "unsupported resampling filter" ); } if (imIn->ysize == imOut->ysize) { /* prepare for horizontal stretch */ filterscale = scale = (float) imIn->xsize / imOut->xsize; } else if (imIn->xsize == imOut->xsize) { /* prepare for vertical stretch */ filterscale = scale = (float) imIn->ysize / imOut->ysize; } else return (Imaging) ImagingError_Mismatch(); /* determine support size (length of resampling filter) */ support = filterp->support; if (filterscale < 1.0) { filterscale = 1.0; support = 0.5; } support = support * filterscale; /* coefficient buffer (with rounding safety margin) */ k = malloc(((int) support * 2 + 10) * sizeof(float)); if (!k) return (Imaging) ImagingError_MemoryError(); if (imIn->xsize == imOut->xsize) { /* vertical stretch */ for (yy = 0; yy < imOut->ysize; yy++) { center = yy * scale; ww = 0.0; ss = 1.0 / filterscale; /* calculate filter weights */ ymin = floor(center - support); if (ymin < 0.0) ymin = 0.0; ymax = ceil(center + support); if (ymax > imIn->ysize) ymax = imIn->ysize; for (y = (int) ymin; y < (int) ymax; y++) { float w = filterp->filter((y - center + 0.5) * ss) * ss; k[y - (int) ymin] = w; ww = ww + w; } if (ww == 0.0) ww = 1.0; else ww = 1.0 / ww; if (imIn->image8) { /* 8-bit grayscale */ for (xx = 0; xx < imOut->xsize; xx++) { ss = 0.0; for (y = (int) ymin; y < (int) ymax; y++) ss = ss + imIn->image8[y][xx] * k[y - (int) ymin]; ss = ss * ww; if (ss <= 0.0) imOut->image[yy][xx] = 0; else if (ss >= 255.0) imOut->image[yy][xx] = 255; else imOut->image[yy][xx] = ss; } } else switch(imIn->type) { case IMAGING_TYPE_UINT8: /* n-bit grayscale */ for (xx = 0; xx < imOut->xsize*4; xx++) { /* FIXME: skip over unused pixels */ ss = 0.0; for (y = (int) ymin; y < (int) ymax; y++) ss = ss + (UINT8) imIn->image[y][xx] * k[y-(int) ymin]; ss = ss * ww; if (ss <= 0.0) imOut->image[yy][xx] = 0; else if (ss >= 255.0) imOut->image[yy][xx] = 255; else imOut->image[yy][xx] = ss; } break; case IMAGING_TYPE_INT32: /* 32-bit integer */ for (xx = 0; xx < imOut->xsize; xx++) { ss = 0.0; for (y = (int) ymin; y < (int) ymax; y++) ss = ss + imIn->image32[y][xx] * k[y - (int) ymin]; imOut->image32[yy][xx] = ss * ww; } break; case IMAGING_TYPE_FLOAT32: /* 32-bit float */ for (xx = 0; xx < imOut->xsize; xx++) { ss = 0.0; for (y = (int) ymin; y < (int) ymax; y++) ss = ss + ((FLOAT32*) imIn->image32[y])[xx] * k[y - (int) ymin]; ((FLOAT32*) imOut->image32[yy])[xx] = ss * ww; } break; default: return (Imaging) ImagingError_ModeError(); } } } else { /* horizontal stretch */ for (xx = 0; xx < imOut->xsize; xx++) { center = xx * scale; ww = 0.0; ss = 1.0 / filterscale; xmin = floor(center - support); if (xmin < 0.0) xmin = 0.0; xmax = ceil(center + support); if (xmax > imIn->xsize) xmax = imIn->xsize; for (x = (int) xmin; x < (int) xmax; x++) { float w = filterp->filter((x - center + 0.5) * ss) * ss; k[x - (int) xmin] = w; ww = ww + w; } if (ww == 0.0) ww = 1.0; else ww = 1.0 / ww; if (imIn->image8) { /* 8-bit grayscale */ for (yy = 0; yy < imOut->ysize; yy++) { ss = 0.0; for (x = (int) xmin; x < (int) xmax; x++) ss = ss + imIn->image8[yy][x] * k[x - (int) xmin]; ss = ss * ww; if (ss <= 0.0) imOut->image[yy][xx] = 0; else if (ss >= 255.0) imOut->image[yy][xx] = 255; else imOut->image[yy][xx] = ss; } } else switch(imIn->type) { case IMAGING_TYPE_UINT8: /* n-bit grayscale */ for (yy = 0; yy < imOut->ysize; yy++) { for (b = 0; b < imIn->bands; b++) { ss = 0.0; for (x = (int) xmin; x < (int) xmax; x++) ss = ss + (UINT8) imIn->image[yy][x*4+b] * k[x - (int) xmin]; ss = ss * ww; if (ss <= 0.0) imOut->image[yy][xx*4+b] = 0; else if (ss >= 255.0) imOut->image[yy][xx*4+b] = 255; else imOut->image[yy][xx*4+b] = ss; } } break; case IMAGING_TYPE_INT32: /* 32-bit integer */ for (yy = 0; yy < imOut->ysize; yy++) { ss = 0.0; for (x = (int) xmin; x < (int) xmax; x++) ss = ss + imIn->image32[yy][x] * k[x - (int) xmin]; imOut->image32[yy][xx] = ss * ww; } break; case IMAGING_TYPE_FLOAT32: /* 32-bit float */ for (yy = 0; yy < imOut->ysize; yy++) { ss = 0.0; for (x = (int) xmin; x < (int) xmax; x++) ss = ss + ((FLOAT32*) imIn->image[yy])[x] * k[x - (int) xmin]; ((FLOAT32*) imOut->image[yy])[xx] = ss * ww; } break; default: return (Imaging) ImagingError_ModeError(); } } } free(k); return imOut; } Imaging-1.1.3/libImaging/Bands.c0100444000076400007640000000360207442710204016172 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Bands.c#2 $ * * stuff to extract and paste back individual bands * * history: * 96-03-20 fl: Created * 97-08-27 fl: Fixed putband for single band targets. * * Copyright (c) Fredrik Lundh 1996-97. * Copyright (c) Secret Labs AB 1997. * * See the README file for details on usage and redistribution. */ #include "Imaging.h" Imaging ImagingGetBand(Imaging imIn, int band) { Imaging imOut; int x, y; /* Check arguments */ if (!imIn || imIn->type != IMAGING_TYPE_UINT8) return (Imaging) ImagingError_ModeError(); if (band < 0 || band >= imIn->bands) return (Imaging) ImagingError_ValueError("band index out of range"); /* Shortcuts */ if (imIn->bands == 1) return ImagingCopy(imIn); imOut = ImagingNew("L", imIn->xsize, imIn->ysize); if (!imOut) return NULL; /* Extract band from image */ for (y = 0; y < imIn->ysize; y++) { UINT8* in = (UINT8*) imIn->image[y] + band; UINT8* out = imOut->image8[y]; for (x = 0; x < imIn->xsize; x++) { out[x] = *in; in += 4; } } return imOut; } Imaging ImagingPutBand(Imaging imOut, Imaging imIn, int band) { int x, y; /* Check arguments */ if (!imIn || imIn->bands != 1 || !imOut) return (Imaging) ImagingError_ModeError(); if (band < 0 || band >= imOut->bands) return (Imaging) ImagingError_ValueError("band index out of range"); if (imIn->type != imOut->type || imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); /* Shortcuts */ if (imOut->bands == 1) return ImagingCopy2(imOut, imIn); /* Insert band into image */ for (y = 0; y < imIn->ysize; y++) { UINT8* in = imIn->image8[y]; UINT8* out = (UINT8*) imOut->image[y] + band; for (x = 0; x < imIn->xsize; x++) { *out = in[x]; out += 4; } } return imOut; } Imaging-1.1.3/libImaging/Blend.c0100444000076400007640000000370707442710204016175 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Blend.c#2 $ * * interpolate between two existing images * * history: * 96-03-20 fl Created * 96-05-18 fl Simplified blend expression * 96-10-05 fl Fixed expression bug, special case for interpolation * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for details on usage and redistribution. */ #include "Imaging.h" Imaging ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha) { Imaging imOut; int x, y; /* Check arguments */ if (!imIn1 || !imIn2 || imIn1->type != IMAGING_TYPE_UINT8) return ImagingError_ModeError(); if (imIn1->type != imIn2->type || imIn1->bands != imIn2->bands || imIn1->xsize != imIn2->xsize || imIn1->ysize != imIn2->ysize) return ImagingError_Mismatch(); /* Shortcuts */ if (alpha == 0.0) return ImagingCopy(imIn1); else if (alpha == 1.0) return ImagingCopy(imIn2); imOut = ImagingNew(imIn1->mode, imIn1->xsize, imIn1->ysize); if (!imOut) return NULL; ImagingCopyInfo(imOut, imIn1); if (alpha >= 0 && alpha <= 1.0) { /* Interpolate between bands */ for (y = 0; y < imIn1->ysize; y++) { UINT8* in1 = (UINT8*) imIn1->image[y]; UINT8* in2 = (UINT8*) imIn2->image[y]; UINT8* out = (UINT8*) imOut->image[y]; for (x = 0; x < imIn1->linesize; x++) out[x] = (UINT8) ((int) in1[x] + alpha * ((int) in2[x] - (int) in1[x])); } } else { /* Extrapolation; must make sure to clip resulting values */ for (y = 0; y < imIn1->ysize; y++) { UINT8* in1 = (UINT8*) imIn1->image[y]; UINT8* in2 = (UINT8*) imIn2->image[y]; UINT8* out = (UINT8*) imOut->image[y]; for (x = 0; x < imIn1->linesize; x++) { float temp = ((int) in1[x] + alpha * ((int) in2[x] - (int) in1[x])); if (temp <= 0.0) out[x] = 0; else if (temp >= 255.0) out[x] = 255; else out[x] = (UINT8) temp; } } } return imOut; } Imaging-1.1.3/libImaging/Chops.c0100444000076400007640000000631207442710204016220 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Chops.c#2 $ * * basic channel operations * * history: * 96-03-28 fl: Created * 96-08-13 fl: Added and/or/xor for "1" images * 96-12-14 fl: Added add_modulo, sub_modulo * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for details on usage and redistribution. */ #include "Imaging.h" #define CHOP(operation, mode)\ int x, y;\ Imaging imOut;\ imOut = create(imIn1, imIn2, mode);\ if (!imOut)\ return NULL;\ for (y = 0; y < imOut->ysize; y++) {\ UINT8* out = (UINT8*) imOut->image[y];\ UINT8* in1 = (UINT8*) imIn1->image[y];\ UINT8* in2 = (UINT8*) imIn2->image[y];\ for (x = 0; x < imOut->linesize; x++) {\ int temp = operation;\ if (temp <= 0)\ out[x] = 0;\ else if (temp >= 255)\ out[x] = 255;\ else\ out[x] = temp;\ }\ }\ return imOut; #define CHOP2(operation, mode)\ int x, y;\ Imaging imOut;\ imOut = create(imIn1, imIn2, mode);\ if (!imOut)\ return NULL;\ for (y = 0; y < imOut->ysize; y++) {\ UINT8* out = (UINT8*) imOut->image[y];\ UINT8* in1 = (UINT8*) imIn1->image[y];\ UINT8* in2 = (UINT8*) imIn2->image[y];\ for (x = 0; x < imOut->linesize; x++) {\ out[x] = operation;\ }\ }\ return imOut; static Imaging create(Imaging im1, Imaging im2, char* mode) { int xsize, ysize; if (!im1 || !im2 || im1->type != IMAGING_TYPE_UINT8 || (mode != NULL && (strcmp(im1->mode, "1") || strcmp(im2->mode, "1")))) return (Imaging) ImagingError_ModeError(); if (im1->type != im2->type || im1->bands != im2->bands) return (Imaging) ImagingError_Mismatch(); xsize = (im1->xsize < im2->xsize) ? im1->xsize : im2->xsize; ysize = (im1->ysize < im2->ysize) ? im1->ysize : im2->ysize; return ImagingNew(im1->mode, xsize, ysize); } Imaging ImagingChopLighter(Imaging imIn1, Imaging imIn2) { CHOP((in1[x] > in2[x]) ? in1[x] : in2[x], NULL); } Imaging ImagingChopDarker(Imaging imIn1, Imaging imIn2) { CHOP((in1[x] < in2[x]) ? in1[x] : in2[x], NULL); } Imaging ImagingChopDifference(Imaging imIn1, Imaging imIn2) { CHOP(abs((int) in1[x] - (int) in2[x]), NULL); } Imaging ImagingChopMultiply(Imaging imIn1, Imaging imIn2) { CHOP((int) in1[x] * (int) in2[x] / 255, NULL); } Imaging ImagingChopScreen(Imaging imIn1, Imaging imIn2) { CHOP(255 - ((int) (255 - in1[x]) * (int) (255 - in2[x])) / 255, NULL); } Imaging ImagingChopAdd(Imaging imIn1, Imaging imIn2, float scale, int offset) { CHOP(((int) in1[x] + (int) in2[x]) / scale + offset, NULL); } Imaging ImagingChopSubtract(Imaging imIn1, Imaging imIn2, float scale, int offset) { CHOP(((int) in1[x] - (int) in2[x]) / scale + offset, NULL); } Imaging ImagingChopAnd(Imaging imIn1, Imaging imIn2) { CHOP2(in1[x] && in2[x], "1"); } Imaging ImagingChopOr(Imaging imIn1, Imaging imIn2) { CHOP2(in1[x] | in2[x], "1"); } Imaging ImagingChopXor(Imaging imIn1, Imaging imIn2) { CHOP2((in1[x] != 0) ^ (in2[x] != 0), "1"); } Imaging ImagingChopAddModulo(Imaging imIn1, Imaging imIn2) { CHOP2(in1[x] + in2[x], NULL); } Imaging ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2) { CHOP2(in1[x] - in2[x], NULL); } Imaging-1.1.3/libImaging/Convert.c0100444000076400007640000005262207442710204016571 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Convert.c#3 $ * * convert images * * history: * 95-06-15 fl created * 95-11-28 fl added some "RGBA" and "CMYK" conversions * 96-04-22 fl added "1" conversions (same as "L") * 96-05-05 fl added palette conversions (hack) * 96-07-23 fl fixed "1" conversions to zero/non-zero convention * 96-11-01 fl fixed "P" to "L" and "RGB" to "1" conversions * 96-12-29 fl set alpha byte in RGB converters * 97-05-12 fl added ImagingConvert2 * 97-05-30 fl added floating point support * 97-08-27 fl added "P" to "1" and "P" to "F" conversions * 98-01-11 fl added integer support * 98-07-01 fl added "YCbCr" support * 98-07-02 fl added "RGBX" conversions (sort of) * 98-07-04 fl added floyd-steinberg dithering * 98-07-12 fl changed "YCrCb" to "YCbCr" (!) * 98-12-29 fl added basic "I;16" and "I;16B" conversions * 99-02-03 fl added "RGBa", and "BGR" conversions (experimental) * * Copyright (c) Secret Labs AB 1997-99. * Copyright (c) Fredrik Lundh 1995-97. * * See the README file for details on usage and redistribution. */ #include "Imaging.h" #define CLIP(v) ((v) <= 0 ? 0 : (v) >= 255 ? 255 : (v)) #define CLIP16(v) ((v) <= -32768 ? -32768 : (v) >= 32767 ? 32767 : (v)) /* like (a * b + 127) / 255), but much faster on most platforms */ #define MULDIV255(a, b, tmp)\ (tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8)) /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ #define L(rgb)\ ((INT32) (rgb)[0]*299 + (INT32) (rgb)[1]*587 + (INT32) (rgb)[2]*114) /* ------------------- */ /* 1 (bit) conversions */ /* ------------------- */ static void bit2l(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) *out++ = (*in++ != 0) ? 255 : 0; } static void bit2rgb(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { UINT8 v = (*in++ != 0) ? 255 : 0; *out++ = v; *out++ = v; *out++ = v; *out++ = 255; } } static void bit2cmyk(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { *out++ = 0; *out++ = 0; *out++ = 0; *out++ = (*in++ != 0) ? 0 : 255; } } static void bit2ycbcr(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { *out++ = (*in++ != 0) ? 255 : 0; *out++ = 128; *out++ = 128; *out++ = 255; } } /* ----------------- */ /* RGB/L conversions */ /* ----------------- */ static void l2bit(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) *out++ = (*in++ >= 128) ? 255 : 0; } static void l2rgb(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { UINT8 v = *in++; *out++ = v; *out++ = v; *out++ = v; *out++ = 255; } } static void rgb2bit(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++, in += 4) /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ *out++ = (L(in) >= 128000) ? 255 : 0; } static void rgb2l(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++, in += 4) /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ *out++ = L(in) / 1000; } static void rgb2i(UINT8* out_, const UINT8* in, int xsize) { int x; INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++, in += 4) *out++ = L(in) / 1000; } static void rgb2f(UINT8* out_, const UINT8* in, int xsize) { int x; FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++, in += 4) *out++ = L(in) / 1000.0F; } static void rgb2bgr15(UINT8* out_, const UINT8* in, int xsize) { int x; UINT16* out = (UINT16*) out_; for (x = 0; x < xsize; x++, in += 4) *out++ = ((((UINT16)in[0])<<8)&0x7c00) + ((((UINT16)in[1])<<2)&0x03e0) + ((((UINT16)in[2])>>3)&0x001f); } static void rgb2bgr16(UINT8* out_, const UINT8* in, int xsize) { int x; UINT16* out = (UINT16*) out_; for (x = 0; x < xsize; x++, in += 4) *out++ = ((((UINT16)in[0])<<8)&0xf800) + ((((UINT16)in[1])<<3)&0x07e0) + ((((UINT16)in[2])>>3)&0x001f); } static void rgb2bgr24(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++, in += 4) { *out++ = in[2]; *out++ = in[1]; *out++ = in[0]; } } /* ---------------- */ /* RGBA conversions */ /* ---------------- */ static void rgb2rgba(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { *out++ = *in++; *out++ = *in++; *out++ = *in++; *out++ = 255; in++; } } static void rgba2rgb(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { *out++ = *in++; *out++ = *in++; *out++ = *in++; *out++ = 255; in++; } } static void rgba2rgba(UINT8* out, const UINT8* in, int xsize) { int x; unsigned int alpha, tmp; for (x = 0; x < xsize; x++) { alpha = in[3]; *out++ = MULDIV255(*in++, alpha, tmp); *out++ = MULDIV255(*in++, alpha, tmp); *out++ = MULDIV255(*in++, alpha, tmp); *out++ = *in++; } } /* ---------------- */ /* CMYK conversions */ /* ---------------- */ static void l2cmyk(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { *out++ = 0; *out++ = 0; *out++ = 0; *out++ = ~(*in++); } } static void rgb2cmyk(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { /* Note: no undercolour removal */ *out++ = ~(*in++); *out++ = ~(*in++); *out++ = ~(*in++); *out++ = 0; in++; } } static void cmyk2rgb(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++, in += 4) { *out++ = CLIP(255 - (in[0] + in[3])); *out++ = CLIP(255 - (in[1] + in[3])); *out++ = CLIP(255 - (in[2] + in[3])); *out++ = 255; } } /* ------------- */ /* I conversions */ /* ------------- */ static void bit2i(UINT8* out_, const UINT8* in, int xsize) { int x; INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++) *out++ = (*in++ != 0) ? 255 : 0; } static void l2i(UINT8* out_, const UINT8* in, int xsize) { int x; INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++) *out++ = (INT32) *in++; } static void i2l(UINT8* out, const UINT8* in_, int xsize) { int x; INT32* in = (INT32*) in_; for (x = 0; x < xsize; x++, in++, out++) { if (*in <= 0) *out = 0; else if (*in >= 255) *out = 255; else *out = (UINT8) *in; } } static void i2f(UINT8* out_, const UINT8* in_, int xsize) { int x; INT32* in = (INT32*) in_; FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++) *out++ = (FLOAT32) *in++; } /* ------------- */ /* F conversions */ /* ------------- */ static void bit2f(UINT8* out_, const UINT8* in, int xsize) { int x; FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++) *out++ = (*in++ != 0) ? 255.0 : 0.0; } static void l2f(UINT8* out_, const UINT8* in, int xsize) { int x; FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++) *out++ = (FLOAT32) *in++; } static void f2l(UINT8* out, const UINT8* in_, int xsize) { int x; FLOAT32* in = (FLOAT32*) in_; for (x = 0; x < xsize; x++, in++, out++) { if (*in <= 0.0) *out = 0; else if (*in >= 255.0) *out = 255; else *out = (UINT8) *in; } } static void f2i(UINT8* out_, const UINT8* in_, int xsize) { int x; FLOAT32* in = (FLOAT32*) in_; INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++) *out++ = (INT32) *in++; } /* ----------------- */ /* YCbCr conversions */ /* ----------------- */ /* See ConvertYCbCr.c for RGB/YCbCr tables */ static void l2ycbcr(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { *out++ = *in++; *out++ = 128; *out++ = 128; *out++ = 255; } } static void ycbcr2l(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++, in += 4) *out++ = in[0]; } /* ------------------------- */ /* I;16 (16-bit) conversions */ /* ------------------------- */ static void i2i16(UINT8* out, const UINT8* in_, int xsize) { int x, v; INT32* in = (INT32*) in_; for (x = 0; x < xsize; x++, in++) { v = CLIP16(*in); *out++ = (UINT8) v; *out++ = (UINT8) (v >> 8); } } static void i2i16b(UINT8* out, const UINT8* in_, int xsize) { int x, v; INT32* in = (INT32*) in_; for (x = 0; x < xsize; x++, in++) { v = CLIP16(*in); *out++ = (UINT8) (v >> 8); *out++ = (UINT8) v; } } static void i162i(UINT8* out_, const UINT8* in, int xsize) { int x; INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++, in += 2) *out++ = in[0] + ((int) in[1] << 8); } static void i16b2i(UINT8* out_, const UINT8* in, int xsize) { int x; INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++, in += 2) *out++ = ((int) in[0] << 8) + in[1]; } static struct { const char* from; const char* to; ImagingShuffler convert; } converters[] = { { "1", "L", bit2l }, { "1", "I", bit2i }, { "1", "F", bit2f }, { "1", "RGB", bit2rgb }, { "1", "RGBA", bit2rgb }, { "1", "RGBX", bit2rgb }, { "1", "CMYK", bit2cmyk }, { "1", "YCbCr", bit2ycbcr }, { "L", "1", l2bit }, { "L", "I", l2i }, { "L", "F", l2f }, { "L", "RGB", l2rgb }, { "L", "RGBA", l2rgb }, { "L", "RGBX", l2rgb }, { "L", "CMYK", l2cmyk }, { "L", "YCbCr", l2ycbcr }, { "I", "L", i2l }, { "I", "F", i2f }, { "F", "L", f2l }, { "F", "I", f2i }, { "RGB", "1", rgb2bit }, { "RGB", "L", rgb2l }, { "RGB", "I", rgb2i }, { "RGB", "F", rgb2f }, { "RGB", "BGR;15", rgb2bgr15 }, { "RGB", "BGR;16", rgb2bgr16 }, { "RGB", "BGR;24", rgb2bgr24 }, { "RGB", "RGBA", rgb2rgba }, { "RGB", "RGBX", rgb2rgba }, { "RGB", "CMYK", rgb2cmyk }, { "RGB", "YCbCr", ImagingConvertRGB2YCbCr }, { "RGBA", "1", rgb2bit }, { "RGBA", "L", rgb2l }, { "RGBA", "I", rgb2i }, { "RGBA", "F", rgb2f }, { "RGBA", "RGB", rgba2rgb }, { "RGBA", "RGBa", rgba2rgba }, { "RGBA", "RGBX", rgb2rgba }, { "RGBA", "CMYK", rgb2cmyk }, { "RGBA", "YCbCr", ImagingConvertRGB2YCbCr }, { "RGBX", "1", rgb2bit }, { "RGBX", "L", rgb2l }, { "RGBA", "I", rgb2i }, { "RGBA", "F", rgb2f }, { "RGBX", "RGB", rgba2rgb }, { "RGBX", "CMYK", rgb2cmyk }, { "RGBX", "YCbCr", ImagingConvertRGB2YCbCr }, { "CMYK", "RGB", cmyk2rgb }, { "CMYK", "RGBA", cmyk2rgb }, { "CMYK", "RGBX", cmyk2rgb }, { "YCbCr", "L", ycbcr2l }, { "YCbCr", "RGB", ImagingConvertYCbCr2RGB }, { "I", "I;16", i2i16 }, { "I;16", "I", i162i }, { "I", "I;16B", i2i16b }, { "I;16B", "I", i16b2i }, { NULL } }; /* FIXME: translate indexed versions to pointer versions below this line */ /* ------------------- */ /* Palette conversions */ /* ------------------- */ static void p2bit(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) { int x; /* FIXME: precalculate greyscale palette? */ for (x = 0; x < xsize; x++) *out++ = (L(&palette[in[x]*4]) >= 1000) ? 255 : 0; } static void p2l(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) { int x; /* FIXME: precalculate greyscale palette? */ for (x = 0; x < xsize; x++) *out++ = L(&palette[in[x]*4]) / 1000; } static void p2i(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette) { int x; INT32* out = (INT32*) out_; for (x = 0; x < xsize; x++) *out++ = L(&palette[in[x]*4]) / 1000; } static void p2f(UINT8* out_, const UINT8* in, int xsize, const UINT8* palette) { int x; FLOAT32* out = (FLOAT32*) out_; for (x = 0; x < xsize; x++) *out++ = L(&palette[in[x]*4]) / 1000.0F; } static void p2rgb(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) { int x; for (x = 0; x < xsize; x++) { const UINT8* rgb = &palette[*in++ * 4]; *out++ = rgb[0]; *out++ = rgb[1]; *out++ = rgb[2]; *out++ = 255; } } static void p2rgba(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) { int x; for (x = 0; x < xsize; x++) { const UINT8* rgba = &palette[*in++ * 4]; *out++ = rgba[0]; *out++ = rgba[1]; *out++ = rgba[2]; *out++ = rgba[3]; } } static void p2cmyk(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) { p2rgb(out, in, xsize, palette); rgb2cmyk(out, out, xsize); } static void p2ycbcr(UINT8* out, const UINT8* in, int xsize, const UINT8* palette) { p2rgb(out, in, xsize, palette); ImagingConvertRGB2YCbCr(out, out, xsize); } static Imaging frompalette(Imaging imOut, Imaging imIn, const char *mode) { int y; void (*convert)(UINT8*, const UINT8*, int, const UINT8*); /* Map palette image to L, RGB, RGBA, or CMYK */ if (!imIn->palette) return (Imaging) ImagingError_ValueError("no palette"); if (strcmp(mode, "1") == 0) convert = p2bit; else if (strcmp(mode, "L") == 0) convert = p2l; else if (strcmp(mode, "I") == 0) convert = p2i; else if (strcmp(mode, "F") == 0) convert = p2f; else if (strcmp(mode, "RGB") == 0) convert = p2rgb; else if (strcmp(mode, "RGBA") == 0) convert = p2rgba; else if (strcmp(mode, "RGBX") == 0) convert = p2rgba; else if (strcmp(mode, "CMYK") == 0) convert = p2cmyk; else if (strcmp(mode, "YCbCr") == 0) convert = p2ycbcr; else return (Imaging) ImagingError_ValueError("conversion not supported"); imOut = ImagingNew2(mode, imOut, imIn); if (!imOut) return NULL; for (y = 0; y < imIn->ysize; y++) (*convert)((UINT8*) imOut->image[y], (UINT8*) imIn->image[y], imIn->xsize, imIn->palette->palette); return imOut; } static Imaging topalette(Imaging imOut, Imaging imIn, ImagingPalette inpalette, int dither) { int x, y; ImagingPalette palette = inpalette;; /* Map L or RGB/RGBX/RGBA to palette image */ if (strcmp(imIn->mode, "L") != 0 && strncmp(imIn->mode, "RGB", 3) != 0) return (Imaging) ImagingError_ValueError("conversion not supported"); if (palette == NULL) { /* FIXME: make user configurable */ if (imIn->bands == 1) palette = ImagingPaletteNew("RGB"); /* Initialised to grey ramp */ else palette = ImagingPaletteNewBrowser(); /* Standard colour cube */ } if (!palette) return (Imaging) ImagingError_ValueError("no palette"); imOut = ImagingNew2("P", imOut, imIn); if (!imOut) { if (palette != inpalette) ImagingPaletteDelete(palette); return NULL; } imOut->palette = ImagingPaletteDuplicate(palette); if (imIn->bands == 1) { /* greyscale image */ /* Greyscale palette: copy data as is */ for (y = 0; y < imIn->ysize; y++) memcpy(imOut->image[y], imIn->image[y], imIn->linesize); } else { /* colour image */ /* Create mapping cache */ if (ImagingPaletteCachePrepare(palette) < 0) { ImagingDelete(imOut); if (palette != inpalette) ImagingPaletteDelete(palette); return NULL; } if (dither) { /* floyd-steinberg dither */ int* errors; errors = calloc(imIn->xsize + 1, sizeof(int) * 3); if (!errors) { ImagingDelete(imOut); ImagingError_MemoryError(); return NULL; } /* Map each pixel to the nearest palette entry */ for (y = 0; y < imIn->ysize; y++) { int r, r0, r1, r2; int g, g0, g1, g2; int b, b0, b1, b2; UINT8* in = (UINT8*) imIn->image[y]; UINT8* out = imOut->image8[y]; int* e = errors; r = r0 = r1 = 0; g = g0 = g1 = 0; b = b0 = b1 = 0; for (x = 0; x < imIn->xsize; x++, in += 4) { int d2; INT16* cache; r = CLIP(in[0] + (r + e[3+0])/16); g = CLIP(in[1] + (g + e[3+1])/16); b = CLIP(in[2] + (b + e[3+2])/16); /* get closest colour */ cache = &ImagingPaletteCache(palette, r, g, b); if (cache[0] == 0x100) ImagingPaletteCacheUpdate(palette, r, g, b); out[x] = cache[0]; r -= (int) palette->palette[cache[0]*4]; g -= (int) palette->palette[cache[0]*4+1]; b -= (int) palette->palette[cache[0]*4+2]; /* propagate errors (don't ask ;-)*/ r2 = r; d2 = r + r; r += d2; e[0] = r + r0; r += d2; r0 = r + r1; r1 = r2; r += d2; g2 = g; d2 = g + g; g += d2; e[1] = g + g0; g += d2; g0 = g + g1; g1 = g2; g += d2; b2 = b; d2 = b + b; b += d2; e[2] = b + b0; b += d2; b0 = b + b1; b1 = b2; b += d2; e += 3; } e[0] = b0; e[1] = b1; e[2] = b2; } free(errors); } else { /* closest colour */ for (y = 0; y < imIn->ysize; y++) { int r, g, b; UINT8* in = (UINT8*) imIn->image[y]; UINT8* out = imOut->image8[y]; for (x = 0; x < imIn->xsize; x++, in += 4) { INT16* cache; r = in[0]; g = in[1]; b = in[2]; /* get closest colour */ cache = &ImagingPaletteCache(palette, r, g, b); if (cache[0] == 0x100) ImagingPaletteCacheUpdate(palette, r, g, b); out[x] = cache[0]; } } } if (inpalette != palette) ImagingPaletteCacheDelete(palette); } if (inpalette != palette) ImagingPaletteDelete(palette); return imOut; } static Imaging tobilevel(Imaging imOut, Imaging imIn, int dither) { int x, y; int* errors; /* Map L or RGB to dithered 1 image */ if (strcmp(imIn->mode, "L") != 0 && strcmp(imIn->mode, "RGB") != 0) return (Imaging) ImagingError_ValueError("conversion not supported"); imOut = ImagingNew2("1", imOut, imIn); if (!imOut) return NULL; errors = calloc(imIn->xsize + 1, sizeof(int)); if (!errors) { ImagingDelete(imOut); ImagingError_MemoryError(); return NULL; } if (imIn->bands == 1) { /* map each pixel to black or white, using error diffusion */ for (y = 0; y < imIn->ysize; y++) { int l, l0, l1, l2, d2; UINT8* in = (UINT8*) imIn->image[y]; UINT8* out = imOut->image8[y]; l = l0 = l1 = 0; for (x = 0; x < imIn->xsize; x++) { /* pick closest colour */ l = CLIP(in[x] + (l + errors[x+1])/16); out[x] = (l > 128) ? 255 : 0; /* propagate errors */ l -= (int) out[x]; l2 = l; d2 = l + l; l += d2; errors[x] = l + l0; l += d2; l0 = l + l1; l1 = l2; l += d2; } errors[x] = l0; } } else { /* map each pixel to black or white, using error diffusion */ for (y = 0; y < imIn->ysize; y++) { int l, l0, l1, l2, d2; UINT8* in = (UINT8*) imIn->image[y]; UINT8* out = imOut->image8[y]; l = l0 = l1 = 0; for (x = 0; x < imIn->xsize; x++, in += 4) { /* pick closest colour */ l = CLIP(L(in)/1000 + (l + errors[x+1])/16); out[x] = (l > 128) ? 255 : 0; /* propagate errors */ l -= (int) out[x]; l2 = l; d2 = l + l; l += d2; errors[x] = l + l0; l += d2; l0 = l + l1; l1 = l2; l += d2; } errors[x] = l0; } } free(errors); return imOut; } static Imaging convert(Imaging imOut, Imaging imIn, const char *mode, ImagingPalette palette, int dither) { int y; ImagingShuffler convert; if (!imIn) return (Imaging) ImagingError_ModeError(); if (!mode) { /* Map palette image to full depth */ if (!imIn->palette) return (Imaging) ImagingError_ModeError(); mode = imIn->palette->mode; } else /* Same mode? */ if (!strcmp(imIn->mode, mode)) return ImagingCopy2(imOut, imIn); /* test for special conversions */ if (strcmp(imIn->mode, "P") == 0) return frompalette(imOut, imIn, mode); if (strcmp(mode, "P") == 0) return topalette(imOut, imIn, palette, dither); if (dither && strcmp(mode, "1") == 0) return tobilevel(imOut, imIn, dither); /* standard conversion machinery */ convert = NULL; for (y = 0; converters[y].from; y++) if (!strcmp(imIn->mode, converters[y].from) && !strcmp(mode, converters[y].to)) { convert = converters[y].convert; break; } if (!convert) return (Imaging) ImagingError_ValueError("conversion not supported"); imOut = ImagingNew2(mode, imOut, imIn); if (!imOut) return NULL; for (y = 0; y < imIn->ysize; y++) (*convert)((UINT8*) imOut->image[y], (UINT8*) imIn->image[y], imIn->xsize); return imOut; } Imaging ImagingConvert(Imaging imIn, const char *mode, ImagingPalette palette, int dither) { return convert(NULL, imIn, mode, palette, dither); } Imaging ImagingConvert2(Imaging imOut, Imaging imIn) { return convert(imOut, imIn, imOut->mode, NULL, 0); } Imaging-1.1.3/libImaging/ConvertYCbCr.c0100444000076400007640000005157707442710204017464 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/ConvertYCbCr.c#2 $ * * code to convert YCbCr data * * history: * 98-07-01 hk Created * * Copyright (c) Secret Labs AB 1998 * * See the README file for information on usage and redistribution. */ #include "Imaging.h" /* JPEG/JFIF YCbCr conversions Y = R * 0.29900 + G * 0.58700 + B * 0.11400 Cb = R * -0.16874 + G * -0.33126 + B * 0.50000 + 128 Cr = R * 0.50000 + G * -0.41869 + B * -0.08131 + 128 R = Y + + (Cr - 128) * 1.40200 G = Y + (Cb - 128) * -0.34414 + (Cr - 128) * -0.71414 B = Y + (Cb - 128) * 1.77200 */ #define SCALE 6 /* bits */ static INT16 Y_R[] = { 0, 19, 38, 57, 77, 96, 115, 134, 153, 172, 191, 210, 230, 249, 268, 287, 306, 325, 344, 364, 383, 402, 421, 440, 459, 478, 498, 517, 536, 555, 574, 593, 612, 631, 651, 670, 689, 708, 727, 746, 765, 785, 804, 823, 842, 861, 880, 899, 919, 938, 957, 976, 995, 1014, 1033, 1052, 1072, 1091, 1110, 1129, 1148, 1167, 1186, 1206, 1225, 1244, 1263, 1282, 1301, 1320, 1340, 1359, 1378, 1397, 1416, 1435, 1454, 1473, 1493, 1512, 1531, 1550, 1569, 1588, 1607, 1627, 1646, 1665, 1684, 1703, 1722, 1741, 1761, 1780, 1799, 1818, 1837, 1856, 1875, 1894, 1914, 1933, 1952, 1971, 1990, 2009, 2028, 2048, 2067, 2086, 2105, 2124, 2143, 2162, 2182, 2201, 2220, 2239, 2258, 2277, 2296, 2315, 2335, 2354, 2373, 2392, 2411, 2430, 2449, 2469, 2488, 2507, 2526, 2545, 2564, 2583, 2602, 2622, 2641, 2660, 2679, 2698, 2717, 2736, 2756, 2775, 2794, 2813, 2832, 2851, 2870, 2890, 2909, 2928, 2947, 2966, 2985, 3004, 3023, 3043, 3062, 3081, 3100, 3119, 3138, 3157, 3177, 3196, 3215, 3234, 3253, 3272, 3291, 3311, 3330, 3349, 3368, 3387, 3406, 3425, 3444, 3464, 3483, 3502, 3521, 3540, 3559, 3578, 3598, 3617, 3636, 3655, 3674, 3693, 3712, 3732, 3751, 3770, 3789, 3808, 3827, 3846, 3865, 3885, 3904, 3923, 3942, 3961, 3980, 3999, 4019, 4038, 4057, 4076, 4095, 4114, 4133, 4153, 4172, 4191, 4210, 4229, 4248, 4267, 4286, 4306, 4325, 4344, 4363, 4382, 4401, 4420, 4440, 4459, 4478, 4497, 4516, 4535, 4554, 4574, 4593, 4612, 4631, 4650, 4669, 4688, 4707, 4727, 4746, 4765, 4784, 4803, 4822, 4841, 4861, 4880 }; static INT16 Y_G[] = { 0, 38, 75, 113, 150, 188, 225, 263, 301, 338, 376, 413, 451, 488, 526, 564, 601, 639, 676, 714, 751, 789, 826, 864, 902, 939, 977, 1014, 1052, 1089, 1127, 1165, 1202, 1240, 1277, 1315, 1352, 1390, 1428, 1465, 1503, 1540, 1578, 1615, 1653, 1691, 1728, 1766, 1803, 1841, 1878, 1916, 1954, 1991, 2029, 2066, 2104, 2141, 2179, 2217, 2254, 2292, 2329, 2367, 2404, 2442, 2479, 2517, 2555, 2592, 2630, 2667, 2705, 2742, 2780, 2818, 2855, 2893, 2930, 2968, 3005, 3043, 3081, 3118, 3156, 3193, 3231, 3268, 3306, 3344, 3381, 3419, 3456, 3494, 3531, 3569, 3607, 3644, 3682, 3719, 3757, 3794, 3832, 3870, 3907, 3945, 3982, 4020, 4057, 4095, 4132, 4170, 4208, 4245, 4283, 4320, 4358, 4395, 4433, 4471, 4508, 4546, 4583, 4621, 4658, 4696, 4734, 4771, 4809, 4846, 4884, 4921, 4959, 4997, 5034, 5072, 5109, 5147, 5184, 5222, 5260, 5297, 5335, 5372, 5410, 5447, 5485, 5522, 5560, 5598, 5635, 5673, 5710, 5748, 5785, 5823, 5861, 5898, 5936, 5973, 6011, 6048, 6086, 6124, 6161, 6199, 6236, 6274, 6311, 6349, 6387, 6424, 6462, 6499, 6537, 6574, 6612, 6650, 6687, 6725, 6762, 6800, 6837, 6875, 6913, 6950, 6988, 7025, 7063, 7100, 7138, 7175, 7213, 7251, 7288, 7326, 7363, 7401, 7438, 7476, 7514, 7551, 7589, 7626, 7664, 7701, 7739, 7777, 7814, 7852, 7889, 7927, 7964, 8002, 8040, 8077, 8115, 8152, 8190, 8227, 8265, 8303, 8340, 8378, 8415, 8453, 8490, 8528, 8566, 8603, 8641, 8678, 8716, 8753, 8791, 8828, 8866, 8904, 8941, 8979, 9016, 9054, 9091, 9129, 9167, 9204, 9242, 9279, 9317, 9354, 9392, 9430, 9467, 9505, 9542, 9580 }; static INT16 Y_B[] = { 0, 7, 15, 22, 29, 36, 44, 51, 58, 66, 73, 80, 88, 95, 102, 109, 117, 124, 131, 139, 146, 153, 161, 168, 175, 182, 190, 197, 204, 212, 219, 226, 233, 241, 248, 255, 263, 270, 277, 285, 292, 299, 306, 314, 321, 328, 336, 343, 350, 358, 365, 372, 379, 387, 394, 401, 409, 416, 423, 430, 438, 445, 452, 460, 467, 474, 482, 489, 496, 503, 511, 518, 525, 533, 540, 547, 554, 562, 569, 576, 584, 591, 598, 606, 613, 620, 627, 635, 642, 649, 657, 664, 671, 679, 686, 693, 700, 708, 715, 722, 730, 737, 744, 751, 759, 766, 773, 781, 788, 795, 803, 810, 817, 824, 832, 839, 846, 854, 861, 868, 876, 883, 890, 897, 905, 912, 919, 927, 934, 941, 948, 956, 963, 970, 978, 985, 992, 1000, 1007, 1014, 1021, 1029, 1036, 1043, 1051, 1058, 1065, 1073, 1080, 1087, 1094, 1102, 1109, 1116, 1124, 1131, 1138, 1145, 1153, 1160, 1167, 1175, 1182, 1189, 1197, 1204, 1211, 1218, 1226, 1233, 1240, 1248, 1255, 1262, 1270, 1277, 1284, 1291, 1299, 1306, 1313, 1321, 1328, 1335, 1342, 1350, 1357, 1364, 1372, 1379, 1386, 1394, 1401, 1408, 1415, 1423, 1430, 1437, 1445, 1452, 1459, 1466, 1474, 1481, 1488, 1496, 1503, 1510, 1518, 1525, 1532, 1539, 1547, 1554, 1561, 1569, 1576, 1583, 1591, 1598, 1605, 1612, 1620, 1627, 1634, 1642, 1649, 1656, 1663, 1671, 1678, 1685, 1693, 1700, 1707, 1715, 1722, 1729, 1736, 1744, 1751, 1758, 1766, 1773, 1780, 1788, 1795, 1802, 1809, 1817, 1824, 1831, 1839, 1846, 1853, 1860 }; static INT16 Cb_R[] = { 0, -10, -21, -31, -42, -53, -64, -75, -85, -96, -107, -118, -129, -139, -150, -161, -172, -183, -193, -204, -215, -226, -237, -247, -258, -269, -280, -291, -301, -312, -323, -334, -345, -355, -366, -377, -388, -399, -409, -420, -431, -442, -453, -463, -474, -485, -496, -507, -517, -528, -539, -550, -561, -571, -582, -593, -604, -615, -625, -636, -647, -658, -669, -679, -690, -701, -712, -723, -733, -744, -755, -766, -777, -787, -798, -809, -820, -831, -841, -852, -863, -874, -885, -895, -906, -917, -928, -939, -949, -960, -971, -982, -993, -1003, -1014, -1025, -1036, -1047, -1057, -1068, -1079, -1090, -1101, -1111, -1122, -1133, -1144, -1155, -1165, -1176, -1187, -1198, -1209, -1219, -1230, -1241, -1252, -1263, -1273, -1284, -1295, -1306, -1317, -1327, -1338, -1349, -1360, -1371, -1381, -1392, -1403, -1414, -1425, -1435, -1446, -1457, -1468, -1479, -1489, -1500, -1511, -1522, -1533, -1543, -1554, -1565, -1576, -1587, -1597, -1608, -1619, -1630, -1641, -1651, -1662, -1673, -1684, -1694, -1705, -1716, -1727, -1738, -1748, -1759, -1770, -1781, -1792, -1802, -1813, -1824, -1835, -1846, -1856, -1867, -1878, -1889, -1900, -1910, -1921, -1932, -1943, -1954, -1964, -1975, -1986, -1997, -2008, -2018, -2029, -2040, -2051, -2062, -2072, -2083, -2094, -2105, -2116, -2126, -2137, -2148, -2159, -2170, -2180, -2191, -2202, -2213, -2224, -2234, -2245, -2256, -2267, -2278, -2288, -2299, -2310, -2321, -2332, -2342, -2353, -2364, -2375, -2386, -2396, -2407, -2418, -2429, -2440, -2450, -2461, -2472, -2483, -2494, -2504, -2515, -2526, -2537, -2548, -2558, -2569, -2580, -2591, -2602, -2612, -2623, -2634, -2645, -2656, -2666, -2677, -2688, -2699, -2710, -2720, -2731, -2742, -2753 }; static INT16 Cb_G[] = { 0, -20, -41, -63, -84, -105, -126, -147, -169, -190, -211, -232, -253, -275, -296, -317, -338, -359, -381, -402, -423, -444, -465, -487, -508, -529, -550, -571, -593, -614, -635, -656, -677, -699, -720, -741, -762, -783, -805, -826, -847, -868, -889, -911, -932, -953, -974, -995, -1017, -1038, -1059, -1080, -1101, -1123, -1144, -1165, -1186, -1207, -1229, -1250, -1271, -1292, -1313, -1335, -1356, -1377, -1398, -1419, -1441, -1462, -1483, -1504, -1525, -1547, -1568, -1589, -1610, -1631, -1653, -1674, -1695, -1716, -1737, -1759, -1780, -1801, -1822, -1843, -1865, -1886, -1907, -1928, -1949, -1971, -1992, -2013, -2034, -2055, -2077, -2098, -2119, -2140, -2161, -2183, -2204, -2225, -2246, -2267, -2289, -2310, -2331, -2352, -2373, -2395, -2416, -2437, -2458, -2479, -2501, -2522, -2543, -2564, -2585, -2607, -2628, -2649, -2670, -2691, -2713, -2734, -2755, -2776, -2797, -2819, -2840, -2861, -2882, -2903, -2925, -2946, -2967, -2988, -3009, -3031, -3052, -3073, -3094, -3115, -3137, -3158, -3179, -3200, -3221, -3243, -3264, -3285, -3306, -3328, -3349, -3370, -3391, -3412, -3434, -3455, -3476, -3497, -3518, -3540, -3561, -3582, -3603, -3624, -3646, -3667, -3688, -3709, -3730, -3752, -3773, -3794, -3815, -3836, -3858, -3879, -3900, -3921, -3942, -3964, -3985, -4006, -4027, -4048, -4070, -4091, -4112, -4133, -4154, -4176, -4197, -4218, -4239, -4260, -4282, -4303, -4324, -4345, -4366, -4388, -4409, -4430, -4451, -4472, -4494, -4515, -4536, -4557, -4578, -4600, -4621, -4642, -4663, -4684, -4706, -4727, -4748, -4769, -4790, -4812, -4833, -4854, -4875, -4896, -4918, -4939, -4960, -4981, -5002, -5024, -5045, -5066, -5087, -5108, -5130, -5151, -5172, -5193, -5214, -5236, -5257, -5278, -5299, -5320, -5342, -5363, -5384, -5405 }; static INT16 Cb_B[] = { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800, 832, 864, 896, 928, 960, 992, 1024, 1056, 1088, 1120, 1152, 1184, 1216, 1248, 1280, 1312, 1344, 1376, 1408, 1440, 1472, 1504, 1536, 1568, 1600, 1632, 1664, 1696, 1728, 1760, 1792, 1824, 1856, 1888, 1920, 1952, 1984, 2016, 2048, 2080, 2112, 2144, 2176, 2208, 2240, 2272, 2304, 2336, 2368, 2400, 2432, 2464, 2496, 2528, 2560, 2592, 2624, 2656, 2688, 2720, 2752, 2784, 2816, 2848, 2880, 2912, 2944, 2976, 3008, 3040, 3072, 3104, 3136, 3168, 3200, 3232, 3264, 3296, 3328, 3360, 3392, 3424, 3456, 3488, 3520, 3552, 3584, 3616, 3648, 3680, 3712, 3744, 3776, 3808, 3840, 3872, 3904, 3936, 3968, 4000, 4032, 4064, 4096, 4128, 4160, 4192, 4224, 4256, 4288, 4320, 4352, 4384, 4416, 4448, 4480, 4512, 4544, 4576, 4608, 4640, 4672, 4704, 4736, 4768, 4800, 4832, 4864, 4896, 4928, 4960, 4992, 5024, 5056, 5088, 5120, 5152, 5184, 5216, 5248, 5280, 5312, 5344, 5376, 5408, 5440, 5472, 5504, 5536, 5568, 5600, 5632, 5664, 5696, 5728, 5760, 5792, 5824, 5856, 5888, 5920, 5952, 5984, 6016, 6048, 6080, 6112, 6144, 6176, 6208, 6240, 6272, 6304, 6336, 6368, 6400, 6432, 6464, 6496, 6528, 6560, 6592, 6624, 6656, 6688, 6720, 6752, 6784, 6816, 6848, 6880, 6912, 6944, 6976, 7008, 7040, 7072, 7104, 7136, 7168, 7200, 7232, 7264, 7296, 7328, 7360, 7392, 7424, 7456, 7488, 7520, 7552, 7584, 7616, 7648, 7680, 7712, 7744, 7776, 7808, 7840, 7872, 7904, 7936, 7968, 8000, 8032, 8064, 8096, 8128, 8160 }; #define Cr_R Cb_B static INT16 Cr_G[] = { 0, -26, -53, -79, -106, -133, -160, -187, -213, -240, -267, -294, -321, -347, -374, -401, -428, -455, -481, -508, -535, -562, -589, -615, -642, -669, -696, -722, -749, -776, -803, -830, -856, -883, -910, -937, -964, -990, -1017, -1044, -1071, -1098, -1124, -1151, -1178, -1205, -1232, -1258, -1285, -1312, -1339, -1366, -1392, -1419, -1446, -1473, -1500, -1526, -1553, -1580, -1607, -1634, -1660, -1687, -1714, -1741, -1768, -1794, -1821, -1848, -1875, -1902, -1928, -1955, -1982, -2009, -2036, -2062, -2089, -2116, -2143, -2169, -2196, -2223, -2250, -2277, -2303, -2330, -2357, -2384, -2411, -2437, -2464, -2491, -2518, -2545, -2571, -2598, -2625, -2652, -2679, -2705, -2732, -2759, -2786, -2813, -2839, -2866, -2893, -2920, -2947, -2973, -3000, -3027, -3054, -3081, -3107, -3134, -3161, -3188, -3215, -3241, -3268, -3295, -3322, -3349, -3375, -3402, -3429, -3456, -3483, -3509, -3536, -3563, -3590, -3616, -3643, -3670, -3697, -3724, -3750, -3777, -3804, -3831, -3858, -3884, -3911, -3938, -3965, -3992, -4018, -4045, -4072, -4099, -4126, -4152, -4179, -4206, -4233, -4260, -4286, -4313, -4340, -4367, -4394, -4420, -4447, -4474, -4501, -4528, -4554, -4581, -4608, -4635, -4662, -4688, -4715, -4742, -4769, -4796, -4822, -4849, -4876, -4903, -4929, -4956, -4983, -5010, -5037, -5063, -5090, -5117, -5144, -5171, -5197, -5224, -5251, -5278, -5305, -5331, -5358, -5385, -5412, -5439, -5465, -5492, -5519, -5546, -5573, -5599, -5626, -5653, -5680, -5707, -5733, -5760, -5787, -5814, -5841, -5867, -5894, -5921, -5948, -5975, -6001, -6028, -6055, -6082, -6109, -6135, -6162, -6189, -6216, -6243, -6269, -6296, -6323, -6350, -6376, -6403, -6430, -6457, -6484, -6510, -6537, -6564, -6591, -6618, -6644, -6671, -6698, -6725, -6752, -6778, -6805, -6832 }; static INT16 Cr_B[] = { 0, -4, -9, -15, -20, -25, -30, -35, -41, -46, -51, -56, -61, -67, -72, -77, -82, -87, -93, -98, -103, -108, -113, -119, -124, -129, -134, -140, -145, -150, -155, -160, -166, -171, -176, -181, -186, -192, -197, -202, -207, -212, -218, -223, -228, -233, -238, -244, -249, -254, -259, -264, -270, -275, -280, -285, -290, -296, -301, -306, -311, -316, -322, -327, -332, -337, -342, -348, -353, -358, -363, -368, -374, -379, -384, -389, -394, -400, -405, -410, -415, -421, -426, -431, -436, -441, -447, -452, -457, -462, -467, -473, -478, -483, -488, -493, -499, -504, -509, -514, -519, -525, -530, -535, -540, -545, -551, -556, -561, -566, -571, -577, -582, -587, -592, -597, -603, -608, -613, -618, -623, -629, -634, -639, -644, -649, -655, -660, -665, -670, -675, -681, -686, -691, -696, -702, -707, -712, -717, -722, -728, -733, -738, -743, -748, -754, -759, -764, -769, -774, -780, -785, -790, -795, -800, -806, -811, -816, -821, -826, -832, -837, -842, -847, -852, -858, -863, -868, -873, -878, -884, -889, -894, -899, -904, -910, -915, -920, -925, -930, -936, -941, -946, -951, -957, -962, -967, -972, -977, -983, -988, -993, -998, -1003, -1009, -1014, -1019, -1024, -1029, -1035, -1040, -1045, -1050, -1055, -1061, -1066, -1071, -1076, -1081, -1087, -1092, -1097, -1102, -1107, -1113, -1118, -1123, -1128, -1133, -1139, -1144, -1149, -1154, -1159, -1165, -1170, -1175, -1180, -1185, -1191, -1196, -1201, -1206, -1211, -1217, -1222, -1227, -1232, -1238, -1243, -1248, -1253, -1258, -1264, -1269, -1274, -1279, -1284, -1290, -1295, -1300, -1305, -1310, -1316, -1321, -1326 }; static INT16 R_Cr[] = { -11484, -11394, -11305, -11215, -11125, -11036, -10946, -10856, -10766, -10677, -10587, -10497, -10407, -10318, -10228, -10138, -10049, -9959, -9869, -9779, -9690, -9600, -9510, -9420, -9331, -9241, -9151, -9062, -8972, -8882, -8792, -8703, -8613, -8523, -8433, -8344, -8254, -8164, -8075, -7985, -7895, -7805, -7716, -7626, -7536, -7446, -7357, -7267, -7177, -7088, -6998, -6908, -6818, -6729, -6639, -6549, -6459, -6370, -6280, -6190, -6101, -6011, -5921, -5831, -5742, -5652, -5562, -5472, -5383, -5293, -5203, -5113, -5024, -4934, -4844, -4755, -4665, -4575, -4485, -4396, -4306, -4216, -4126, -4037, -3947, -3857, -3768, -3678, -3588, -3498, -3409, -3319, -3229, -3139, -3050, -2960, -2870, -2781, -2691, -2601, -2511, -2422, -2332, -2242, -2152, -2063, -1973, -1883, -1794, -1704, -1614, -1524, -1435, -1345, -1255, -1165, -1076, -986, -896, -807, -717, -627, -537, -448, -358, -268, -178, -89, 0, 90, 179, 269, 359, 449, 538, 628, 718, 808, 897, 987, 1077, 1166, 1256, 1346, 1436, 1525, 1615, 1705, 1795, 1884, 1974, 2064, 2153, 2243, 2333, 2423, 2512, 2602, 2692, 2782, 2871, 2961, 3051, 3140, 3230, 3320, 3410, 3499, 3589, 3679, 3769, 3858, 3948, 4038, 4127, 4217, 4307, 4397, 4486, 4576, 4666, 4756, 4845, 4935, 5025, 5114, 5204, 5294, 5384, 5473, 5563, 5653, 5743, 5832, 5922, 6012, 6102, 6191, 6281, 6371, 6460, 6550, 6640, 6730, 6819, 6909, 6999, 7089, 7178, 7268, 7358, 7447, 7537, 7627, 7717, 7806, 7896, 7986, 8076, 8165, 8255, 8345, 8434, 8524, 8614, 8704, 8793, 8883, 8973, 9063, 9152, 9242, 9332, 9421, 9511, 9601, 9691, 9780, 9870, 9960, 10050, 10139, 10229, 10319, 10408, 10498, 10588, 10678, 10767, 10857, 10947, 11037, 11126, 11216, 11306, 11395 }; static INT16 G_Cb[] = { 2819, 2797, 2775, 2753, 2731, 2709, 2687, 2665, 2643, 2621, 2599, 2577, 2555, 2533, 2511, 2489, 2467, 2445, 2423, 2401, 2379, 2357, 2335, 2313, 2291, 2269, 2247, 2225, 2202, 2180, 2158, 2136, 2114, 2092, 2070, 2048, 2026, 2004, 1982, 1960, 1938, 1916, 1894, 1872, 1850, 1828, 1806, 1784, 1762, 1740, 1718, 1696, 1674, 1652, 1630, 1608, 1586, 1564, 1542, 1520, 1498, 1476, 1454, 1432, 1410, 1388, 1366, 1344, 1321, 1299, 1277, 1255, 1233, 1211, 1189, 1167, 1145, 1123, 1101, 1079, 1057, 1035, 1013, 991, 969, 947, 925, 903, 881, 859, 837, 815, 793, 771, 749, 727, 705, 683, 661, 639, 617, 595, 573, 551, 529, 507, 485, 463, 440, 418, 396, 374, 352, 330, 308, 286, 264, 242, 220, 198, 176, 154, 132, 110, 88, 66, 44, 22, 0, -21, -43, -65, -87, -109, -131, -153, -175, -197, -219, -241, -263, -285, -307, -329, -351, -373, -395, -417, -439, -462, -484, -506, -528, -550, -572, -594, -616, -638, -660, -682, -704, -726, -748, -770, -792, -814, -836, -858, -880, -902, -924, -946, -968, -990, -1012, -1034, -1056, -1078, -1100, -1122, -1144, -1166, -1188, -1210, -1232, -1254, -1276, -1298, -1320, -1343, -1365, -1387, -1409, -1431, -1453, -1475, -1497, -1519, -1541, -1563, -1585, -1607, -1629, -1651, -1673, -1695, -1717, -1739, -1761, -1783, -1805, -1827, -1849, -1871, -1893, -1915, -1937, -1959, -1981, -2003, -2025, -2047, -2069, -2091, -2113, -2135, -2157, -2179, -2201, -2224, -2246, -2268, -2290, -2312, -2334, -2356, -2378, -2400, -2422, -2444, -2466, -2488, -2510, -2532, -2554, -2576, -2598, -2620, -2642, -2664, -2686, -2708, -2730, -2752, -2774, -2796 }; static INT16 G_Cr[] = { 5850, 5805, 5759, 5713, 5667, 5622, 5576, 5530, 5485, 5439, 5393, 5347, 5302, 5256, 5210, 5165, 5119, 5073, 5028, 4982, 4936, 4890, 4845, 4799, 4753, 4708, 4662, 4616, 4570, 4525, 4479, 4433, 4388, 4342, 4296, 4251, 4205, 4159, 4113, 4068, 4022, 3976, 3931, 3885, 3839, 3794, 3748, 3702, 3656, 3611, 3565, 3519, 3474, 3428, 3382, 3336, 3291, 3245, 3199, 3154, 3108, 3062, 3017, 2971, 2925, 2879, 2834, 2788, 2742, 2697, 2651, 2605, 2559, 2514, 2468, 2422, 2377, 2331, 2285, 2240, 2194, 2148, 2102, 2057, 2011, 1965, 1920, 1874, 1828, 1782, 1737, 1691, 1645, 1600, 1554, 1508, 1463, 1417, 1371, 1325, 1280, 1234, 1188, 1143, 1097, 1051, 1006, 960, 914, 868, 823, 777, 731, 686, 640, 594, 548, 503, 457, 411, 366, 320, 274, 229, 183, 137, 91, 46, 0, -45, -90, -136, -182, -228, -273, -319, -365, -410, -456, -502, -547, -593, -639, -685, -730, -776, -822, -867, -913, -959, -1005, -1050, -1096, -1142, -1187, -1233, -1279, -1324, -1370, -1416, -1462, -1507, -1553, -1599, -1644, -1690, -1736, -1781, -1827, -1873, -1919, -1964, -2010, -2056, -2101, -2147, -2193, -2239, -2284, -2330, -2376, -2421, -2467, -2513, -2558, -2604, -2650, -2696, -2741, -2787, -2833, -2878, -2924, -2970, -3016, -3061, -3107, -3153, -3198, -3244, -3290, -3335, -3381, -3427, -3473, -3518, -3564, -3610, -3655, -3701, -3747, -3793, -3838, -3884, -3930, -3975, -4021, -4067, -4112, -4158, -4204, -4250, -4295, -4341, -4387, -4432, -4478, -4524, -4569, -4615, -4661, -4707, -4752, -4798, -4844, -4889, -4935, -4981, -5027, -5072, -5118, -5164, -5209, -5255, -5301, -5346, -5392, -5438, -5484, -5529, -5575, -5621, -5666, -5712, -5758, -5804 }; static INT16 B_Cb[] = { -14515, -14402, -14288, -14175, -14062, -13948, -13835, -13721, -13608, -13495, -13381, -13268, -13154, -13041, -12928, -12814, -12701, -12587, -12474, -12360, -12247, -12134, -12020, -11907, -11793, -11680, -11567, -11453, -11340, -11226, -11113, -11000, -10886, -10773, -10659, -10546, -10433, -10319, -10206, -10092, -9979, -9865, -9752, -9639, -9525, -9412, -9298, -9185, -9072, -8958, -8845, -8731, -8618, -8505, -8391, -8278, -8164, -8051, -7938, -7824, -7711, -7597, -7484, -7371, -7257, -7144, -7030, -6917, -6803, -6690, -6577, -6463, -6350, -6236, -6123, -6010, -5896, -5783, -5669, -5556, -5443, -5329, -5216, -5102, -4989, -4876, -4762, -4649, -4535, -4422, -4309, -4195, -4082, -3968, -3855, -3741, -3628, -3515, -3401, -3288, -3174, -3061, -2948, -2834, -2721, -2607, -2494, -2381, -2267, -2154, -2040, -1927, -1814, -1700, -1587, -1473, -1360, -1246, -1133, -1020, -906, -793, -679, -566, -453, -339, -226, -112, 0, 113, 227, 340, 454, 567, 680, 794, 907, 1021, 1134, 1247, 1361, 1474, 1588, 1701, 1815, 1928, 2041, 2155, 2268, 2382, 2495, 2608, 2722, 2835, 2949, 3062, 3175, 3289, 3402, 3516, 3629, 3742, 3856, 3969, 4083, 4196, 4310, 4423, 4536, 4650, 4763, 4877, 4990, 5103, 5217, 5330, 5444, 5557, 5670, 5784, 5897, 6011, 6124, 6237, 6351, 6464, 6578, 6691, 6804, 6918, 7031, 7145, 7258, 7372, 7485, 7598, 7712, 7825, 7939, 8052, 8165, 8279, 8392, 8506, 8619, 8732, 8846, 8959, 9073, 9186, 9299, 9413, 9526, 9640, 9753, 9866, 9980, 10093, 10207, 10320, 10434, 10547, 10660, 10774, 10887, 11001, 11114, 11227, 11341, 11454, 11568, 11681, 11794, 11908, 12021, 12135, 12248, 12361, 12475, 12588, 12702, 12815, 12929, 13042, 13155, 13269, 13382, 13496, 13609, 13722, 13836, 13949, 14063, 14176, 14289, 14403 }; void ImagingConvertRGB2YCbCr(UINT8* out, const UINT8* in, int pixels) { int x; UINT8 a; int r, g, b; int y, cr, cb; for (x = 0; x < pixels; x++, in +=4, out += 4) { r = in[0]; g = in[1]; b = in[2]; a = in[3]; y = (Y_R[r] + Y_G[g] + Y_B[b]) >> SCALE; cb = ((Cb_R[r] + Cb_G[g] + Cb_B[b]) >> SCALE) + 128; cr = ((Cr_R[r] + Cr_G[g] + Cr_B[b]) >> SCALE) + 128; out[0] = (UINT8) y; out[1] = (UINT8) cb; out[2] = (UINT8) cr; out[3] = a; } } void ImagingConvertYCbCr2RGB(UINT8* out, const UINT8* in, int pixels) { int x; UINT8 a; int r, g, b; int y, cr, cb; for (x = 0; x < pixels; x++, in += 4, out += 4) { y = in[0]; cb = in[1]; cr = in[2]; a = in[3]; r = y + (( R_Cr[cr]) >> SCALE); g = y + ((G_Cb[cb] + G_Cr[cr]) >> SCALE); b = y + ((B_Cb[cb] ) >> SCALE); out[0] = (r <= 0) ? 0 : (r >= 255) ? 255 : r; out[1] = (g <= 0) ? 0 : (g >= 255) ? 255 : g; out[2] = (b <= 0) ? 0 : (b >= 255) ? 255 : b; out[3] = a; } } Imaging-1.1.3/libImaging/Copy.c0100444000076400007640000000206607442710204016060 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Copy.c#2 $ * * copy image * * history: * 95-11-26 fl: Moved from Imaging.c * 97-05-12 fl: Added ImagingCopy2 * 97-08-28 fl: Allow imOut == NULL in ImagingCopy2 * * Copyright (c) Fredrik Lundh 1995-97. * Copyright (c) Secret Labs AB 1997. * * See the README file for details on usage and redistribution. */ #include "Imaging.h" static Imaging _copy(Imaging imOut, Imaging imIn) { int y; if (!imIn) return (Imaging) ImagingError_ValueError(NULL); imOut = ImagingNew2(imIn->mode, imOut, imIn); if (!imOut) return NULL; ImagingCopyInfo(imOut, imIn); if (imIn->block != NULL && imOut->block != NULL) memcpy(imOut->block, imIn->block, imIn->ysize * imIn->linesize); else for (y = 0; y < imIn->ysize; y++) memcpy(imOut->image[y], imIn->image[y], imIn->linesize); return imOut; } Imaging ImagingCopy(Imaging imIn) { return _copy(NULL, imIn); } Imaging ImagingCopy2(Imaging imOut, Imaging imIn) { return _copy(imOut, imIn); } Imaging-1.1.3/libImaging/Crc32.c0100444000076400007640000000762007442710204016023 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Crc32.c#2 $ * * calculate ISO 3307 checksum * * history: * 96-12-10 fl: Created (based on example in the PNG spec) * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" /* Precalculated CRC values (created by makecrctable.py) */ static UINT32 crc32table[] = { 0x0, 0x77073096L, 0xEE0E612CL, 0x990951BAL, 0x76DC419L, 0x706AF48FL, 0xE963A535L, 0x9E6495A3L, 0xEDB8832L, 0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L, 0x9B64C2BL, 0x7EB17CBDL, 0xE7B82D07L, 0x90BF1D91L, 0x1DB71064L, 0x6AB020F2L, 0xF3B97148L, 0x84BE41DEL, 0x1ADAD47DL, 0x6DDDE4EBL, 0xF4D4B551L, 0x83D385C7L, 0x136C9856L, 0x646BA8C0L, 0xFD62F97AL, 0x8A65C9ECL, 0x14015C4FL, 0x63066CD9L, 0xFA0F3D63L, 0x8D080DF5L, 0x3B6E20C8L, 0x4C69105EL, 0xD56041E4L, 0xA2677172L, 0x3C03E4D1L, 0x4B04D447L, 0xD20D85FDL, 0xA50AB56BL, 0x35B5A8FAL, 0x42B2986CL, 0xDBBBC9D6L, 0xACBCF940L, 0x32D86CE3L, 0x45DF5C75L, 0xDCD60DCFL, 0xABD13D59L, 0x26D930ACL, 0x51DE003AL, 0xC8D75180L, 0xBFD06116L, 0x21B4F4B5L, 0x56B3C423L, 0xCFBA9599L, 0xB8BDA50FL, 0x2802B89EL, 0x5F058808L, 0xC60CD9B2L, 0xB10BE924L, 0x2F6F7C87L, 0x58684C11L, 0xC1611DABL, 0xB6662D3DL, 0x76DC4190L, 0x1DB7106L, 0x98D220BCL, 0xEFD5102AL, 0x71B18589L, 0x6B6B51FL, 0x9FBFE4A5L, 0xE8B8D433L, 0x7807C9A2L, 0xF00F934L, 0x9609A88EL, 0xE10E9818L, 0x7F6A0DBBL, 0x86D3D2DL, 0x91646C97L, 0xE6635C01L, 0x6B6B51F4L, 0x1C6C6162L, 0x856530D8L, 0xF262004EL, 0x6C0695EDL, 0x1B01A57BL, 0x8208F4C1L, 0xF50FC457L, 0x65B0D9C6L, 0x12B7E950L, 0x8BBEB8EAL, 0xFCB9887CL, 0x62DD1DDFL, 0x15DA2D49L, 0x8CD37CF3L, 0xFBD44C65L, 0x4DB26158L, 0x3AB551CEL, 0xA3BC0074L, 0xD4BB30E2L, 0x4ADFA541L, 0x3DD895D7L, 0xA4D1C46DL, 0xD3D6F4FBL, 0x4369E96AL, 0x346ED9FCL, 0xAD678846L, 0xDA60B8D0L, 0x44042D73L, 0x33031DE5L, 0xAA0A4C5FL, 0xDD0D7CC9L, 0x5005713CL, 0x270241AAL, 0xBE0B1010L, 0xC90C2086L, 0x5768B525L, 0x206F85B3L, 0xB966D409L, 0xCE61E49FL, 0x5EDEF90EL, 0x29D9C998L, 0xB0D09822L, 0xC7D7A8B4L, 0x59B33D17L, 0x2EB40D81L, 0xB7BD5C3BL, 0xC0BA6CADL, 0xEDB88320L, 0x9ABFB3B6L, 0x3B6E20CL, 0x74B1D29AL, 0xEAD54739L, 0x9DD277AFL, 0x4DB2615L, 0x73DC1683L, 0xE3630B12L, 0x94643B84L, 0xD6D6A3EL, 0x7A6A5AA8L, 0xE40ECF0BL, 0x9309FF9DL, 0xA00AE27L, 0x7D079EB1L, 0xF00F9344L, 0x8708A3D2L, 0x1E01F268L, 0x6906C2FEL, 0xF762575DL, 0x806567CBL, 0x196C3671L, 0x6E6B06E7L, 0xFED41B76L, 0x89D32BE0L, 0x10DA7A5AL, 0x67DD4ACCL, 0xF9B9DF6FL, 0x8EBEEFF9L, 0x17B7BE43L, 0x60B08ED5L, 0xD6D6A3E8L, 0xA1D1937EL, 0x38D8C2C4L, 0x4FDFF252L, 0xD1BB67F1L, 0xA6BC5767L, 0x3FB506DDL, 0x48B2364BL, 0xD80D2BDAL, 0xAF0A1B4CL, 0x36034AF6L, 0x41047A60L, 0xDF60EFC3L, 0xA867DF55L, 0x316E8EEFL, 0x4669BE79L, 0xCB61B38CL, 0xBC66831AL, 0x256FD2A0L, 0x5268E236L, 0xCC0C7795L, 0xBB0B4703L, 0x220216B9L, 0x5505262FL, 0xC5BA3BBEL, 0xB2BD0B28L, 0x2BB45A92L, 0x5CB36A04L, 0xC2D7FFA7L, 0xB5D0CF31L, 0x2CD99E8BL, 0x5BDEAE1DL, 0x9B64C2B0L, 0xEC63F226L, 0x756AA39CL, 0x26D930AL, 0x9C0906A9L, 0xEB0E363FL, 0x72076785L, 0x5005713L, 0x95BF4A82L, 0xE2B87A14L, 0x7BB12BAEL, 0xCB61B38L, 0x92D28E9BL, 0xE5D5BE0DL, 0x7CDCEFB7L, 0xBDBDF21L, 0x86D3D2D4L, 0xF1D4E242L, 0x68DDB3F8L, 0x1FDA836EL, 0x81BE16CDL, 0xF6B9265BL, 0x6FB077E1L, 0x18B74777L, 0x88085AE6L, 0xFF0F6A70L, 0x66063BCAL, 0x11010B5CL, 0x8F659EFFL, 0xF862AE69L, 0x616BFFD3L, 0x166CCF45L, 0xA00AE278L, 0xD70DD2EEL, 0x4E048354L, 0x3903B3C2L, 0xA7672661L, 0xD06016F7L, 0x4969474DL, 0x3E6E77DBL, 0xAED16A4AL, 0xD9D65ADCL, 0x40DF0B66L, 0x37D83BF0L, 0xA9BCAE53L, 0xDEBB9EC5L, 0x47B2CF7FL, 0x30B5FFE9L, 0xBDBDF21CL, 0xCABAC28AL, 0x53B39330L, 0x24B4A3A6L, 0xBAD03605L, 0xCDD70693L, 0x54DE5729L, 0x23D967BFL, 0xB3667A2EL, 0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L, 0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL }; UINT32 ImagingCRC32(UINT32 crc, UINT8* buffer, int bytes) { int i; crc ^= 0xFFFFFFFFL; for (i = 0; i < bytes; i++) crc = crc32table[(UINT8) crc ^ buffer[i]] ^ (crc >> 8); return crc ^ 0xFFFFFFFFL; } Imaging-1.1.3/libImaging/Crop.c0100444000076400007640000000220507442710204016044 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Crop.c#2 $ * * cut region from image * * history: * 95-11-27 fl Created * 98-07-10 fl Fixed "null result" error * 99-02-05 fl Rewritten to use Paste primitive * * Copyright (c) Secret Labs AB 1997-99. * Copyright (c) Fredrik Lundh 1995. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" Imaging ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1) { Imaging imOut; int xsize, ysize; int dx0, dy0, dx1, dy1; if (!imIn) return (Imaging) ImagingError_ModeError(); xsize = sx1 - sx0; if (xsize < 0) xsize = 0; ysize = sy1 - sy0; if (ysize < 0) ysize = 0; imOut = ImagingNew(imIn->mode, xsize, ysize); if (!imOut) return NULL; ImagingCopyInfo(imOut, imIn); dx0 = -sx0; dy0 = -sy0; dx1 = imIn->xsize - sx0; dy1 = imIn->ysize - sy0; /* paste the source image on top of the output image!!! */ if (ImagingPaste(imOut, imIn, NULL, dx0, dy0, dx1, dy1) < 0) { ImagingDelete(imOut); return NULL; } return imOut; } Imaging-1.1.3/libImaging/Dib.c0100444000076400007640000001650507442710204015647 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Dib.c#3 $ * * imaging display object for Windows * * history: * 2025-05-12 fl Created * 2025-05-17 fl Up and running * 2025-05-21 fl Added palette stuff * 2025-05-26 fl Added query palette and mode inquery * 2025-09-21 fl Added draw primitive * 2025-01-20 fl Use StretchDIBits instead of StretchBlt * 2024-12-30 fl Plugged a resource leak in DeleteDIB (from Roger Burnham) * * Copyright (c) Secret Labs AB 1997-2001. * Copyright (c) Fredrik Lundh 1996. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #ifdef WIN32 #include "ImDib.h" char* ImagingGetModeDIB(int size_out[2]) { /* Get device characteristics */ HDC dc; char* mode; dc = CreateCompatibleDC(NULL); mode = "P"; if (!(GetDeviceCaps(dc, RASTERCAPS) & RC_PALETTE)) { mode = "RGB"; if (GetDeviceCaps(dc, BITSPIXEL) == 1) mode = "1"; } if (size_out) { size_out[0] = GetDeviceCaps(dc, HORZRES); size_out[1] = GetDeviceCaps(dc, VERTRES); } DeleteDC(dc); return mode; } ImagingDIB ImagingNewDIB(const char *mode, int xsize, int ysize) { /* Create a Windows bitmap */ ImagingDIB dib; RGBQUAD *palette; int i; /* Check mode */ if (strcmp(mode, "1") != 0 && strcmp(mode, "L") != 0 && strcmp(mode, "RGB") != 0) return (ImagingDIB) ImagingError_ModeError(); /* Create DIB context and info header */ dib = (ImagingDIB) malloc(sizeof(*dib)); if (!dib) return (ImagingDIB) ImagingError_MemoryError(); dib->info = (BITMAPINFO*) malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); if (!dib->info) { free(dib); return (ImagingDIB) ImagingError_MemoryError(); } memset(dib->info, 0, sizeof(BITMAPINFOHEADER)); dib->info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); dib->info->bmiHeader.biWidth = xsize; dib->info->bmiHeader.biHeight = ysize; dib->info->bmiHeader.biPlanes = 1; dib->info->bmiHeader.biBitCount = strlen(mode)*8; dib->info->bmiHeader.biCompression = BI_RGB; /* Create DIB */ dib->dc = CreateCompatibleDC(NULL); if (!dib->dc) { free(dib->info); free(dib); return (ImagingDIB) ImagingError_MemoryError(); } dib->bitmap = CreateDIBSection(dib->dc, dib->info, DIB_RGB_COLORS, &dib->bits, NULL, 0); if (!dib->bitmap) { free(dib->info); free(dib); return (ImagingDIB) ImagingError_MemoryError(); } strcpy(dib->mode, mode); dib->xsize = xsize; dib->ysize = ysize; dib->pixelsize = strlen(mode); dib->linesize = (xsize * dib->pixelsize + 3) & -4; if (dib->pixelsize == 1) dib->pack = dib->unpack = (ImagingShuffler) memcpy; else { dib->pack = ImagingPackBGR; dib->unpack = ImagingPackBGR; } /* Bind the DIB to the device context */ dib->old_bitmap = SelectObject(dib->dc, dib->bitmap); palette = dib->info->bmiColors; /* Bind a palette to it as well (only required for 8-bit DIBs) */ if (dib->pixelsize == 1) { for (i = 0; i < 256; i++) { palette[i].rgbRed = palette[i].rgbGreen = palette[i].rgbBlue = i; palette[i].rgbReserved = 0; } SetDIBColorTable(dib->dc, 0, 256, palette); } /* Create an associated palette (for 8-bit displays only) */ if (strcmp(ImagingGetModeDIB(NULL), "P") == 0) { char palbuf[sizeof(LOGPALETTE)+256*sizeof(PALETTEENTRY)]; LPLOGPALETTE pal = (LPLOGPALETTE) palbuf; int i, r, g, b; /* Load system palette */ pal->palVersion = 0x300; pal->palNumEntries = 256; GetSystemPaletteEntries(dib->dc, 0, 256, pal->palPalEntry); if (strcmp(mode, "L") == 0) { /* Greyscale DIB. Fill all 236 slots with a greyscale ramp * (this is usually overkill on Windows since VGA only offers * 6 bits greyscale resolution). Ignore the slots already * allocated by Windows */ i = 10; for (r = 0; r < 236; r++) { pal->palPalEntry[i].peRed = pal->palPalEntry[i].peGreen = pal->palPalEntry[i].peBlue = i; i++; } dib->palette = CreatePalette(pal); } else if (strcmp(mode, "RGB") == 0) { #ifdef CUBE216 /* Colour DIB. Create a 6x6x6 colour cube (216 entries) and * add 20 extra greylevels for best result with greyscale * images. */ i = 10; for (r = 0; r < 256; r += 51) for (g = 0; g < 256; g += 51) for (b = 0; b < 256; b += 51) { pal->palPalEntry[i].peRed = r; pal->palPalEntry[i].peGreen = g; pal->palPalEntry[i].peBlue = b; i++; } for (r = 1; r < 22-1; r++) { /* Black and white are already provided by the cube. */ pal->palPalEntry[i].peRed = pal->palPalEntry[i].peGreen = pal->palPalEntry[i].peBlue = r * 255 / (22-1); i++; } #else /* Colour DIB. Alternate palette. */ i = 10; for (r = 0; r < 256; r += 37) for (g = 0; g < 256; g += 32) for (b = 0; b < 256; b += 64) { pal->palPalEntry[i].peRed = r; pal->palPalEntry[i].peGreen = g; pal->palPalEntry[i].peBlue = b; i++; } #endif #if 0 { /* DEBUG: dump palette to file */ FILE *err = fopen("dib.pal", "w"); for (i = 0; i < 256; i++) fprintf(err, "%d: %d/%d/%d\n", i, pal->palPalEntry[i].peRed, pal->palPalEntry[i].peGreen, pal->palPalEntry[i].peBlue); fclose(err); } #endif dib->palette = CreatePalette(pal); } } return dib; } void ImagingPasteDIB(ImagingDIB dib, Imaging im, int xy[4]) { /* Paste image data into a bitmap */ /* FIXME: check size! */ int y; for (y = 0; y < im->ysize; y++) dib->pack(dib->bits + dib->linesize*(dib->ysize-(xy[1]+y)-1) + xy[0]*dib->pixelsize, im->image[y], im->xsize); } void ImagingExposeDIB(ImagingDIB dib, int dc) { /* Copy bitmap to display */ if (dib->palette != 0) SelectPalette((HDC) dc, dib->palette, FALSE); BitBlt((HDC) dc, 0, 0, dib->xsize, dib->ysize, dib->dc, 0, 0, SRCCOPY); } void ImagingDrawDIB(ImagingDIB dib, int dc, int dst[4], int src[4]) { /* Copy bitmap to printer/display */ if (GetDeviceCaps((HDC) dc, RASTERCAPS) & RC_STRETCHDIB) { /* stretchdib (printers) */ StretchDIBits((HDC) dc, dst[0], dst[1], dst[2]-dst[0], dst[3]-dst[1], src[0], src[1], src[2]-src[0], src[3]-src[1], dib->bits, dib->info, DIB_RGB_COLORS, SRCCOPY); } else { /* stretchblt (displays) */ if (dib->palette != 0) SelectPalette((HDC) dc, dib->palette, FALSE); StretchBlt((HDC) dc, dst[0], dst[1], dst[2]-dst[0], dst[3]-dst[1], dib->dc, src[0], src[1], src[2]-src[0], src[3]-src[1], SRCCOPY); } } int ImagingQueryPaletteDIB(ImagingDIB dib, int dc) { /* Install bitmap palette */ int n; if (dib->palette != 0) { /* Realize associated palette */ HPALETTE now = SelectPalette((HDC) dc, dib->palette, FALSE); n = RealizePalette((HDC) dc); /* Restore palette */ SelectPalette((HDC) dc, now, FALSE); } else n = 0; return n; /* number of colours that was changed */ } void ImagingDeleteDIB(ImagingDIB dib) { /* Clean up */ if (dib->palette) DeleteObject(dib->palette); if (dib->bitmap) { SelectObject(dib->dc, dib->old_bitmap); DeleteObject(dib->bitmap); } if (dib->dc) DeleteDC(dib->dc); free(dib->info); } #endif /* WIN32 */ Imaging-1.1.3/libImaging/Draw.c0100444000076400007640000004522507442710204016047 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/Draw.c#3 $ * * a simple drawing package for the Imaging library * * history: * 96-04-13 fl Created. * 96-04-30 fl Added transforms and polygon support. * 96-08-12 fl Added filled polygons. * 96-11-05 fl Fixed float/int confusion in polygon filler * 97-07-04 fl Support 32-bit images (C++ would have been nice) * 98-09-09 fl Eliminated qsort casts; improved rectangle clipping * 98-09-10 fl Fixed fill rectangle to include lower edge (!) * 98-12-29 fl Added arc, chord, and pieslice primitives * 99-01-10 fl Added some level 2 ("arrow") stuff (experimental) * 99-02-06 fl Added bitmap primitive * 99-07-26 fl Eliminated a compiler warning * 99-07-31 fl Pass ink as void* instead of int * * Copyright (c) Fredrik Lundh 1996-97. * Copyright (c) Secret Labs AB 1997-99. * * See the README file for information on usage and redistribution. */ /* FIXME: support fill/outline attribute for all filled shapes */ /* FIXME: support zero-winding fill */ /* FIXME: support affine transform */ /* FIXME: support clip window (and mask?) */ #include #include "Imaging.h" #define CEIL(v) (int) ceil(v) #define FLOOR(v) ((v) >= 0.0 ? (int) (v) : (int) floor(v)) #define INK8(ink) (*(UINT8*)ink) #define INK32(ink) (*(INT32*)ink) /* -------------------------------------------------------------------- */ /* Primitives */ /* -------------------------------------------------------------------- */ typedef struct { /* edge descriptor for polygon engine */ int d; int x0, y0; int xmin, ymin, xmax, ymax; float dx; } Edge; static inline void point8(Imaging im, int x, int y, int ink) { if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) im->image8[y][x] = (UINT8) ink; } static inline void point32(Imaging im, int x, int y, int ink) { if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) im->image32[y][x] = ink; } static inline void hline8(Imaging im, int x0, int y0, int x1, int ink) { int tmp; if (y0 >= 0 && y0 < im->ysize) { if (x0 > x1) tmp = x0, x0 = x1, x1 = tmp; if (x0 < 0) x0 = 0; else if (x0 >= im->xsize) return; if (x1 < 0) return; else if (x1 >= im->xsize) x1 = im->xsize-1; if (x0 <= x1) memset(im->image8[y0] + x0, (UINT8) ink, x1 - x0 + 1); } } static inline void hline32(Imaging im, int x0, int y0, int x1, int ink) { int tmp; INT32* p; if (y0 >= 0 && y0 < im->ysize) { if (x0 > x1) tmp = x0, x0 = x1, x1 = tmp; if (x0 < 0) x0 = 0; else if (x0 >= im->xsize) return; if (x1 < 0) return; else if (x1 >= im->xsize) x1 = im->xsize-1; p = im->image32[y0]; while (x0 <= x1) p[x0++] = ink; } } static inline void line8(Imaging im, int x0, int y0, int x1, int y1, int ink) { int i, n, e; int dx, dy; int xs, ys; /* normalize coordinates */ dx = x1-x0; if (dx < 0) dx = -dx, xs = -1; else xs = 1; dy = y1-y0; if (dy < 0) dy = -dy, ys = -1; else ys = 1; n = (dx > dy) ? dx : dy; if (dx == 0) /* vertical */ for (i = 0; i < dy; i++) { point8(im, x0, y0, ink); y0 += ys; } else if (dy == 0) /* horizontal */ hline8(im, x0, y0, x1, ink); else if (dx > dy) { /* bresenham, horizontal slope */ n = dx; dy += dy; e = dy - dx; dx += dx; for (i = 0; i < n; i++) { point8(im, x0, y0, ink); if (e >= 0) { y0 += ys; e -= dx; } e += dy; x0 += xs; } } else { /* bresenham, vertical slope */ n = dy; dx += dx; e = dx - dy; dy += dy; for (i = 0; i < n; i++) { point8(im, x0, y0, ink); if (e >= 0) { x0 += xs; e -= dy; } e += dx; y0 += ys; } } } static inline void line32(Imaging im, int x0, int y0, int x1, int y1, int ink) { int i, n, e; int dx, dy; int xs, ys; /* normalize coordinates */ dx = x1-x0; if (dx < 0) dx = -dx, xs = -1; else xs = 1; dy = y1-y0; if (dy < 0) dy = -dy, ys = -1; else ys = 1; n = (dx > dy) ? dx : dy; if (dx == 0) /* vertical */ for (i = 0; i < dy; i++) { point32(im, x0, y0, ink); y0 += ys; } else if (dy == 0) /* horizontal */ hline32(im, x0, y0, x1, ink); else if (dx > dy) { /* bresenham, horizontal slope */ n = dx; dy += dy; e = dy - dx; dx += dx; for (i = 0; i < n; i++) { point32(im, x0, y0, ink); if (e >= 0) { y0 += ys; e -= dx; } e += dy; x0 += xs; } } else { /* bresenham, vertical slope */ n = dy; dx += dx; e = dx - dy; dy += dy; for (i = 0; i < n; i++) { point32(im, x0, y0, ink); if (e >= 0) { x0 += xs; e -= dy; } e += dx; y0 += ys; } } } static int x_cmp(const void *x0, const void *x1) { return *((float*)x0) - *((float*)x1); } static inline int polygon8(Imaging im, int n, Edge *e, int ink, int eofill) { int i, j; float *xx; int ymin, ymax; float y; if (n <= 0) return 0; /* Find upper and lower polygon boundary (within image) */ ymin = e[0].ymin; ymax = e[0].ymax; for (i = 1; i < n; i++) { if (e[i].ymin < ymin) ymin = e[i].ymin; if (e[i].ymax > ymax) ymax = e[i].ymax; } if (ymin < 0) ymin = 0; if (ymax >= im->ysize) ymax = im->ysize-1; /* Process polygon edges */ xx = malloc(n * sizeof(float)); if (!xx) return -1; for (;ymin <= ymax; ymin++) { y = ymin+0.5; for (i = j = 0; i < n; i++) if (y >= e[i].ymin && y <= e[i].ymax) if (e[i].d == 0) hline8(im, e[i].xmin, ymin, e[i].xmax, ink); else xx[j++] = (y-e[i].y0) * e[i].dx + e[i].x0; if (j == 2) { if (xx[0] < xx[1]) hline8(im, CEIL(xx[0]-0.5), ymin, FLOOR(xx[1]+0.5), ink); else hline8(im, CEIL(xx[1]-0.5), ymin, FLOOR(xx[0]+0.5), ink); } else { qsort(xx, j, sizeof(float), x_cmp); for (i = 0; i < j-1 ; i += 2) hline8(im, CEIL(xx[i]-0.5), ymin, FLOOR(xx[i+1]+0.5), ink); } } free(xx); return 0; } static inline int polygon32(Imaging im, int n, Edge *e, int ink, int eofill) { int i, j; float *xx; int ymin, ymax; float y; if (n <= 0) return 0; /* Find upper and lower polygon boundary (within image) */ ymin = e[0].ymin; ymax = e[0].ymax; for (i = 1; i < n; i++) { if (e[i].ymin < ymin) ymin = e[i].ymin; if (e[i].ymax > ymax) ymax = e[i].ymax; } if (ymin < 0) ymin = 0; if (ymax >= im->ysize) ymax = im->ysize-1; /* Process polygon edges */ xx = malloc(n * sizeof(float)); if (!xx) return -1; for (;ymin <= ymax; ymin++) { y = ymin+0.5; for (i = j = 0; i < n; i++) { if (y >= e[i].ymin && y <= e[i].ymax) if (e[i].d == 0) hline32(im, e[i].xmin, ymin, e[i].xmax, ink); else xx[j++] = (y-e[i].y0) * e[i].dx + e[i].x0; } if (j == 2) { if (xx[0] < xx[1]) hline32(im, CEIL(xx[0]-0.5), ymin, FLOOR(xx[1]+0.5), ink); else hline32(im, CEIL(xx[1]-0.5), ymin, FLOOR(xx[0]+0.5), ink); } else { qsort(xx, j, sizeof(float), x_cmp); for (i = 0; i < j-1 ; i += 2) hline32(im, CEIL(xx[i]-0.5), ymin, FLOOR(xx[i+1]+0.5), ink); } } free(xx); return 0; } static inline void add_edge(Edge *e, int x0, int y0, int x1, int y1) { /* printf("edge %d %d %d %d\n", x0, y0, x1, y1); */ if (x0 <= x1) e->xmin = x0, e->xmax = x1; else e->xmin = x1, e->xmax = x0; if (y0 <= y1) e->ymin = y0, e->ymax = y1; else e->ymin = y1, e->ymax = y0; if (y0 == y1) { e->d = 0; e->dx = 0.0; } else { e->dx = ((float)(x1-x0)) / (y1-y0); if (y0 == e->ymin) e->d = 1; else e->d = -1; } e->x0 = x0; e->y0 = y0; } typedef struct { void (*point)(Imaging im, int x, int y, int ink); void (*hline)(Imaging im, int x0, int y0, int x1, int ink); void (*line)(Imaging im, int x0, int y0, int x1, int y1, int ink); int (*polygon)(Imaging im, int n, Edge *e, int ink, int eofill); } DRAW; DRAW draw8 = { point8, hline8, line8, polygon8 }; DRAW draw32 = { point32, hline32, line32, polygon32 }; /* -------------------------------------------------------------------- */ /* Interface */ /* -------------------------------------------------------------------- */ int ImagingDrawPoint(Imaging im, int x0, int y0, const void* ink) { if (im->image8) draw8.point(im, x0, y0, INK8(ink)); else draw32.point(im, x0, y0, INK32(ink)); return 0; } int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink) { if (im->image8) draw8.line(im, x0, y0, x1, y1, INK8(ink)); else draw32.line(im, x0, y0, x1, y1, INK32(ink)); return 0; } int ImagingDrawRectangle(Imaging im, int x0, int y0, int x1, int y1, const void* ink_, int fill) { int y; int tmp; DRAW* draw; INT32 ink; if (im->image8) { draw = &draw8; ink = INK8(ink_); } else { draw = &draw32; ink = INK32(ink_); } if (y0 > y1) tmp = y0, y0 = y1, y1 = tmp; if (fill) { if (y0 < 0) y0 = 0; else if (y0 >= im->ysize) return 0; if (y1 < 0) return 0; else if (y1 > im->ysize) y1 = im->ysize; for (y = y0; y <= y1; y++) draw->hline(im, x0, y, x1, ink); } else { /* outline */ draw->line(im, x0, y0, x1, y0, ink); draw->line(im, x1, y0, x1, y1, ink); draw->line(im, x1, y1, x0, y1, ink); draw->line(im, x0, y1, x0, y0, ink); } return 0; } int ImagingDrawPolygon(Imaging im, int count, int* xy, const void* ink_, int fill) { int i, n; DRAW* draw; INT32 ink; if (count <= 0) return 0; if (im->image8) { draw = &draw8; ink = INK8(ink_); } else { draw = &draw32; ink = INK32(ink_); } if (fill) { /* Build edge list */ Edge* e = malloc(count * sizeof(Edge)); if (!e) { ImagingError_MemoryError(); return -1; } for (i = n = 0; i < count-1; i++) add_edge(&e[n++], xy[i+i], xy[i+i+1], xy[i+i+2], xy[i+i+3]); if (xy[i+i] != xy[0] || xy[i+i+1] != xy[1]) add_edge(&e[n++], xy[i+i], xy[i+i+1], xy[0], xy[1]); draw->polygon(im, n, e, ink, 0); free(e); } else { /* Outline */ for (i = 0; i < count-1; i++) draw->line(im, xy[i+i], xy[i+i+1], xy[i+i+2], xy[i+i+3], ink); draw->line(im, xy[i+i], xy[i+i+1], xy[0], xy[1], ink); } return 0; } int ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap, const void* ink) { return ImagingFill2( im, ink, bitmap, x0, y0, x0 + bitmap->xsize, y0 + bitmap->ysize ); } /* -------------------------------------------------------------------- */ /* standard shapes */ #define ARC 0 #define CHORD 1 #define PIESLICE 2 static int ellipse(Imaging im, int x0, int y0, int x1, int y1, int start, int end, const void* ink_, int fill, int mode) { int i, n; int cx, cy; int w, h; int x, y; int lx, ly; int sx, sy; DRAW* draw; INT32 ink; w = x1 - x0; h = y1 - y0; if (w < 0 || h < 0) return 0; if (im->image8) { draw = &draw8; ink = INK8(ink_); } else { draw = &draw32; ink = INK32(ink_); } cx = (x0 + x1) / 2; cy = (y0 + y1) / 2; while (end < start) end += 360; if (mode != ARC && fill) { /* Build edge list */ Edge* e = malloc((end - start + 3) * sizeof(Edge)); if (!e) { ImagingError_MemoryError(); return -1; } n = 0; for (i = start; i <= end; i++) { x = FLOOR((cos(i*M_PI/180) * w/2) + cx + 0.5); y = FLOOR((sin(i*M_PI/180) * h/2) + cy + 0.5); if (i != start) add_edge(&e[n++], lx, ly, x, y); else sx = x, sy = y; lx = x, ly = y; } if (n > 0) { /* close and draw polygon */ if (mode == PIESLICE) { if (x != cx || y != cy) { add_edge(&e[n++], x, y, cx, cy); add_edge(&e[n++], cx, cy, sx, sy); } } else { if (x != sx || y != sy) add_edge(&e[n++], x, y, sx, sy); } draw->polygon(im, n, e, ink, 0); } free(e); } else { for (i = start; i <= end; i++) { x = FLOOR((cos(i*M_PI/180) * w/2) + cx + 0.5); y = FLOOR((sin(i*M_PI/180) * h/2) + cy + 0.5); if (i != start) draw->line(im, lx, ly, x, y, ink); else sx = x, sy = y; lx = x, ly = y; } if (i != start) { if (mode == PIESLICE) { if (x != cx || y != cy) { draw->line(im, x, y, cx, cy, ink); draw->line(im, cx, cy, sx, sy, ink); } } else if (mode == CHORD) { if (x != sx || y != sy) draw->line(im, x, y, sx, sy, ink); } } } return 0; } int ImagingDrawArc(Imaging im, int x0, int y0, int x1, int y1, int start, int end, const void* ink) { return ellipse(im, x0, y0, x1, y1, start, end, ink, 0, ARC); } int ImagingDrawChord(Imaging im, int x0, int y0, int x1, int y1, int start, int end, const void* ink, int fill) { return ellipse(im, x0, y0, x1, y1, start, end, ink, fill, CHORD); } int ImagingDrawEllipse(Imaging im, int x0, int y0, int x1, int y1, const void* ink, int fill) { return ellipse(im, x0, y0, x1, y1, 0, 360, ink, fill, CHORD); } int ImagingDrawPieslice(Imaging im, int x0, int y0, int x1, int y1, int start, int end, const void* ink, int fill) { return ellipse(im, x0, y0, x1, y1, start, end, ink, fill, PIESLICE); } /* -------------------------------------------------------------------- */ /* experimental level 2 ("arrow") graphics stuff. this implements portions of the arrow api on top of the Edge structure. the semantics are ok, except that "curve" flattens the bezier curves by itself */ #if 1 /* ARROW_GRAPHICS */ struct ImagingOutlineInstance { float x0, y0; float x, y; int count; Edge *edges; int size; }; ImagingOutline ImagingOutlineNew(void) { ImagingOutline outline; outline = calloc(1, sizeof(struct ImagingOutlineInstance)); if (!outline) return (ImagingOutline) ImagingError_MemoryError(); outline->edges = NULL; outline->count = outline->size = 0; ImagingOutlineMove(outline, 0, 0); return outline; } void ImagingOutlineDelete(ImagingOutline outline) { if (!outline) return; if (outline->edges) free(outline->edges); free(outline); } static Edge* allocate(ImagingOutline outline, int extra) { Edge* e; if (outline->count + extra > outline->size) { /* expand outline buffer */ outline->size += extra + 25; if (!outline->edges) e = malloc(outline->size * sizeof(Edge)); else e = realloc(outline->edges, outline->size * sizeof(Edge)); if (!e) return NULL; outline->edges = e; } e = outline->edges + outline->count; outline->count += extra; return e; } int ImagingOutlineMove(ImagingOutline outline, float x0, float y0) { outline->x = outline->x0 = x0; outline->y = outline->y0 = y0; return 0; } int ImagingOutlineLine(ImagingOutline outline, float x1, float y1) { Edge* e; e = allocate(outline, 1); if (!e) return -1; /* out of memory */ add_edge(e, (int) outline->x, (int) outline->y, (int) x1, (int) y1); outline->x = x1; outline->y = y1; return 0; } int ImagingOutlineCurve(ImagingOutline outline, float x1, float y1, float x2, float y2, float x3, float y3) { Edge* e; int i; float xo, yo; #define STEPS 32 e = allocate(outline, STEPS); if (!e) return -1; /* out of memory */ xo = outline->x; yo = outline->y; /* flatten the bezier segment */ for (i = 1; i <= STEPS; i++) { float t = ((float) i) / STEPS; float t2 = t*t; float t3 = t2*t; float u = 1.0 - t; float u2 = u*u; float u3 = u2*u; float x = outline->x*u3 + 3*(x1*t*u2 + x2*t2*u) + x3*t3; float y = outline->y*u3 + 3*(y1*t*u2 + y2*t2*u) + y3*t3; add_edge(e++, xo, yo, x, y); xo = x, yo = y; } outline->x = xo; outline->y = yo; return 0; } int ImagingOutlineCurve2(ImagingOutline outline, float cx, float cy, float x3, float y3) { /* add bezier curve based on three control points (as in the Flash file format) */ return ImagingOutlineCurve( outline, (outline->x + cx + cx)/3, (outline->y + cy + cy)/3, (cx + cx + x3)/3, (cy + cy + y3)/3, x3, y3); } int ImagingOutlineClose(ImagingOutline outline) { if (outline->x == outline->x0 && outline->y == outline->y0) return 0; return ImagingOutlineLine(outline, outline->x0, outline->y0); } int ImagingOutlineTransform(ImagingOutline outline, double a[6]) { Edge *eIn; Edge *eOut; int i, n; int x0, y0, x1, y1; int X0, Y0, X1, Y1; double a0 = a[0]; double a1 = a[1]; double a2 = a[2]; double a3 = a[3]; double a4 = a[4]; double a5 = a[5]; eIn = outline->edges; n = outline->count; /* FIXME: ugly! */ outline->edges = NULL; outline->count = outline->size = 0; eOut = allocate(outline, n); if (!eOut) { outline->edges = eIn; outline->count = outline->size = n; ImagingError_MemoryError(); return -1; } for (i = 0; i < n; i++) { x0 = eIn->x0; y0 = eIn->y0; /* FIXME: ouch! */ if (eIn->x0 == eIn->xmin) x1 = eIn->xmax; else x1 = eIn->xmin; if (eIn->y0 == eIn->ymin) y1 = eIn->ymax; else y1 = eIn->ymin; /* full moon tonight! if this doesn't work, you may need to upgrade your compiler (make sure you have the right service pack) */ X0 = (int) (a0*x0 + a1*y0 + a2); Y0 = (int) (a3*x0 + a4*y0 + a5); X1 = (int) (a0*x1 + a1*y1 + a2); Y1 = (int) (a3*x1 + a4*y1 + a5); add_edge(eOut, X0, Y0, X1, Y1); eIn++; eOut++; } free(eIn); return 0; } int ImagingDrawOutline(Imaging im, ImagingOutline outline, const void* ink, int fill) { if (im->image8) draw8.polygon(im, outline->count, outline->edges, INK8(ink), 0); else draw32.polygon(im, outline->count, outline->edges, INK32(ink), 0); return 0; } #endif Imaging-1.1.3/libImaging/Effects.c0100444000076400007640000000653707442710204016534 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Effects.c#2 $ * * various special effects and image generators * * history: * 97-05-21 fl: Just for fun * 97-06-05 fl: Added mandelbrot generator * * Copyright (c) Fredrik Lundh 1997. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" Imaging ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality) { /* Generate a Mandelbrot set covering the given extent */ Imaging im; int x, y, k; double width, height; double x1, y1, xi2, yi2, cr, ci, radius; double dr, di; /* Check arguments */ width = extent[2] - extent[0]; height = extent[3] - extent[1]; if (width < 0.0 || height < 0.0 || quality < 2) return (Imaging) ImagingError_ValueError(NULL); im = ImagingNew("L", xsize, ysize); if (!im) return NULL; dr = width/(xsize-1); di = height/(ysize-1); radius = 100.0; for (y = 0; y < ysize; y++) { UINT8* buf = im->image8[y]; for (x = 0; x < xsize; x++) { x1 = y1 = xi2 = yi2 = 0.0; cr = x*dr + extent[0]; ci = y*di + extent[1]; for (k = 1;; k++) { y1 = 2*x1*y1 + ci; x1 = xi2 - yi2 + cr; xi2 = x1*x1; yi2 = y1*y1; if ((xi2 + yi2) > radius) { buf[x] = k*255/quality; break; } if (k > quality) { buf[x] = 0; break; } } } } return im; } Imaging ImagingEffectNoise(int xsize, int ysize, float sigma) { /* Generate gaussian noise centered around 128 */ Imaging imOut; int x, y; int nextok; double this, next; imOut = ImagingNew("L", xsize, ysize); if (!imOut) return NULL; next = 0.0; nextok = 0; for (y = 0; y < imOut->ysize; y++) { UINT8* out = imOut->image8[y]; for (x = 0; x < imOut->xsize; x++) { if (nextok) { this = next; nextok = 0; } else { /* after numerical recepies */ double v1, v2, radius, factor; do { v1 = rand()*(2.0/32767.0) - 1.0; v2 = rand()*(2.0/32767.0) - 1.0; radius= v1*v1 + v2*v2; } while (radius >= 1.0); factor = sqrt(-2.0*log(radius)/radius); this = factor * v1; next = factor * v2; } out[x] = 128 + sigma * this; } } return imOut; } Imaging ImagingEffectSpread(Imaging imIn, int distance) { /* Randomly spread pixels in an image */ Imaging imOut; int x, y; imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize); if (!imOut) return NULL; #define SPREAD(type, image)\ for (y = 0; y < imIn->ysize; y++)\ for (x = 0; x < imIn->xsize; x++) {\ int xx = x + (rand() % distance) - distance/2;\ int yy = y + (rand() % distance) - distance/2;\ if (xx >= 0 && xx < imIn->xsize && yy >= 0 && yy < imIn->ysize) {\ imOut->image[yy][xx] = imIn->image[y][x];\ imOut->image[y][x] = imIn->image[yy][xx];\ } else\ imOut->image[y][x] = imIn->image[y][x];\ } if (imIn->image8) { SPREAD(UINT8, image8); } else { SPREAD(INT32, image32); } ImagingCopyInfo(imOut, imIn); return imOut; } Imaging-1.1.3/libImaging/Except.c0100444000076400007640000000225107442710204016372 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Except.c#2 $ * * default exception handling * * This module is usually overridden by application code (e.g. * _imaging.c for PIL's standard Python bindings). If you get * linking errors, remove this file from your project/library. * * history: * 95-06-15 fl Created * 98-12-29 fl Minor tweaks * * Copyright (c) Fredrik Lundh 1995. * Copyright (c) Secret Labs AB 1997-98. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" void * ImagingError_IOError(void) { fprintf(stderr, "*** exception: file access error\n"); return NULL; } void * ImagingError_MemoryError(void) { fprintf(stderr, "*** exception: out of memory\n"); return NULL; } void * ImagingError_ModeError(void) { return ImagingError_ValueError("bad image mode"); return NULL; } void * ImagingError_Mismatch(void) { return ImagingError_ValueError("images don't match"); return NULL; } void * ImagingError_ValueError(const char *message) { if (!message) message = "exception: bad argument to function"; fprintf(stderr, "*** %s\n", message); return NULL; } Imaging-1.1.3/libImaging/File.c0100444000076400007640000000632307442710204016025 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/File.c#2 $ * * built-in image file handling * * history: * 95-11-26 fl Created, supports PGM/PPM * 96-08-07 fl Write "1" images as PGM * 99-02-21 fl Don't write non-standard modes * * Copyright (c) Secret Labs AB 1997-99. * Copyright (c) Fredrik Lundh 1995-96. * * See the README file for information on usage and redistribution. */ #include /* isspace(), isdigit() */ #include "Imaging.h" Imaging ImagingOpenPPM(const char* infile) { FILE* fp; int i, c, v; char* mode; int x, y, max; Imaging im; if (!infile) return ImagingError_ValueError(NULL); fp = fopen(infile, "rb"); if (!fp) return ImagingError_IOError(); /* PPM magic */ if (fgetc(fp) != 'P') goto syntax; switch (fgetc(fp)) { case '4': /* FIXME: 1-bit images are not yet supported */ goto syntax; case '5': mode = "L"; break; case '6': mode = "RGB"; break; default: goto syntax; } i = 0; c = fgetc(fp); x = y = max = 0; while (i < 3) { /* Ignore optional comment fields */ while (c == '\n') { c = fgetc(fp); if (c == '#') { do { c = fgetc(fp); if (c == EOF) goto syntax; } while (c != '\n'); c = fgetc(fp); } } /* Skip forward to next value */ while (isspace(c)) c = fgetc(fp); /* And parse it */ v = 0; while (isdigit(c)) { v = v * 10 + (c - '0'); c = fgetc(fp); } if (c == EOF) goto syntax; switch (i++) { case 0: x = v; break; case 1: y = v; break; case 2: max = v; break; } } im = ImagingNew(mode, x, y); if (!im) return NULL; /* if (max != 255) ... FIXME: does anyone ever use this feature? */ if (strcmp(im->mode, "L") == 0) { /* PPM "L" */ for (y = 0; y < im->ysize; y++) fread(im->image[y], 1, im->xsize, fp); } else { /* PPM "RGB" or PyPPM mode */ for (y = 0; y < im->ysize; y++) for (x = i = 0; x < im->xsize; x++, i += im->pixelsize) fread(im->image[y]+i, 1, im->bands, fp); } fclose(fp); return im; syntax: fclose(fp); return ImagingError_IOError(); } int ImagingSaveRaw(Imaging im, FILE* fp) { int x, y, i; if (strcmp(im->mode, "1") == 0 || strcmp(im->mode, "L") == 0) { /* PPM "L" */ for (y = 0; y < im->ysize; y++) fwrite(im->image[y], 1, im->xsize, fp); } else { /* PPM "RGB" or other internal format */ for (y = 0; y < im->ysize; y++) for (x = i = 0; x < im->xsize; x++, i += im->pixelsize) fwrite(im->image[y]+i, 1, im->bands, fp); } return 1; } int ImagingSavePPM(Imaging im, const char* outfile) { FILE* fp; if (!im) { ImagingError_ValueError(NULL); return 0; } fp = fopen(outfile, "wb"); if (!fp) { ImagingError_IOError(); return 0; } if (strcmp(im->mode, "1") == 0 || strcmp(im->mode, "L") == 0) { /* Write "PGM" */ fprintf(fp, "P5\n%d %d\n255\n", im->xsize, im->ysize); } else if (strcmp(im->mode, "RGB") == 0) { /* Write "PPM" */ fprintf(fp, "P6\n%d %d\n255\n", im->xsize, im->ysize); } else { ImagingError_ModeError(); return 0; } ImagingSaveRaw(im, fp); fclose(fp); return 1; } Imaging-1.1.3/libImaging/Fill.c0100444000076400007640000000327407442710204016036 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Fill.c#3 $ * * fill image with constant pixel value * * history: * 95-11-26 fl moved from Imaging.c * 96-05-17 fl added radial fill, renamed wedge to linear * 98-06-23 fl changed ImageFill signature * * Copyright (c) Secret Labs AB 1997-98. All rights reserved. * Copyright (c) Fredrik Lundh 1995-96. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #include "math.h" Imaging ImagingFill(Imaging im, const void* colour) { INT32 c; int x, y; c = 0L; memcpy(&c, colour, im->pixelsize); if (im->image32 && c != 0L) { for (y = 0; y < im->ysize; y++) for (x = 0; x < im->xsize; x++) im->image32[y][x] = c; } else { unsigned char cc = (unsigned char) *(UINT8*) colour; for (y = 0; y < im->ysize; y++) memset(im->image[y], cc, im->linesize); } return im; } Imaging ImagingFillLinearGradient(const char *mode) { Imaging im; int y; if (strlen(mode) != 1) return (Imaging) ImagingError_ModeError(); im = ImagingNew(mode, 256, 256); if (!im) return NULL; for (y = 0; y < 256; y++) memset(im->image8[y], (unsigned char) y, 256); return im; } Imaging ImagingFillRadialGradient(const char *mode) { Imaging im; int x, y; int d; if (strlen(mode) != 1) return (Imaging) ImagingError_ModeError(); im = ImagingNew(mode, 256, 256); if (!im) return NULL; for (y = 0; y < 256; y++) for (x = 0; x < 256; x++) { d = (int) sqrt((double) ((x-128)*(x-128) + (y-128)*(y-128)) * 2.0); if (d >= 255) im->image8[y][x] = 255; else im->image8[y][x] = d; } return im; } Imaging-1.1.3/libImaging/Filter.c0100444000076400007640000001442707442710204016377 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Filter.c#2 $ * * apply convolution kernel to image * * history: * 95-11-26 fl Created, supports 3x3 kernels * 95-11-27 fl Added 5x5 kernels, copy border * 99-07-26 fl Eliminated a few compiler warnings * * Copyright (c) Secret Labs AB 1997-99. All rights reserved. * Copyright (c) Fredrik Lundh 1995. * * See the README file for information on usage and redistribution. */ /* * FIXME: Support RGB and RGBA/CMYK modes as well * FIXME: Expand image border (current version leaves border as is) * FIXME: Implement image processing gradient filters */ #include "Imaging.h" /* Image enhancement filters. This set was snatched from LVIEW Pro. */ int _ImagingFilterSmooth[] = { 3, 3, 13, 0, 1, 1, 1, 1, 5, 1, 1, 1, 1 }; Imaging ImagingFilterSmooth(Imaging im) { return ImagingFilter(im, _ImagingFilterSmooth); } int _ImagingFilterSmoothMore[] = { 5, 5, 100, 0, 1, 1, 1, 1, 1, 1, 5, 5, 5, 1, 1, 5, 44, 5, 1, 1, 5, 5, 5, 1, 1, 1, 1, 1, 1 }; Imaging ImagingFilterSmoothMore(Imaging im) { return ImagingFilter(im, _ImagingFilterSmoothMore); } int _ImagingFilterBlur[] = { 5, 5, 16, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1 }; Imaging ImagingFilterBlur(Imaging im) { return ImagingFilter(im, _ImagingFilterBlur); } int _ImagingFilterSharpen[] = { 3, 3, 16, 0, -2, -2, -2, -2, 32, -2, -2, -2, -2 }; Imaging ImagingFilterSharpen(Imaging im) { return ImagingFilter(im, _ImagingFilterSharpen); } int _ImagingFilterDetail[] = { 3, 3, 6, 0, 0, -1, 0, -1, 10, -1, 0, -1, 0 }; Imaging ImagingFilterDetail(Imaging im) { return ImagingFilter(im, _ImagingFilterDetail); } int _ImagingFilterEdgeEnhance[] = { 3, 3, 2, 0, -1, -1, -1, -1, 10, -1, -1, -1, -1 }; Imaging ImagingFilterEdgeEnhance(Imaging im) { return ImagingFilter(im, _ImagingFilterEdgeEnhance); } int _ImagingFilterEdgeEnhanceMore[] = { 3, 3, 1, 0, -1, -1, -1, -1, 9, -1, -1, -1, -1 }; Imaging ImagingFilterEdgeEnhanceMore(Imaging im) { return ImagingFilter(im, _ImagingFilterEdgeEnhanceMore); } int _ImagingFilterFindEdges[] = { 3, 3, 1, 0, -1, -1, -1, -1, 8, -1, -1, -1, -1 }; Imaging ImagingFilterFindEdges(Imaging im) { return ImagingFilter(im, _ImagingFilterFindEdges); } int _ImagingFilterContour[] = { 3, 3, 1, 255, -1, -1, -1, -1, 8, -1, -1, -1, -1 }; Imaging ImagingFilterContour(Imaging im) { return ImagingFilter(im, _ImagingFilterContour); } /* Special effects filters */ int _ImagingFilterEmboss[] = { 3, 3, 1, 128, -1, 0, 0, 0, 1, 0, 0, 0, 0 }; Imaging ImagingFilterEmboss(Imaging im) { return ImagingFilter(im, _ImagingFilterEmboss); } Imaging ImagingFilter(Imaging im, const int* kernel) { Imaging imOut; int x, y; int xkernel, ykernel; int sum, divisor, offset; if (!im || strcmp(im->mode, "L") != 0) return (Imaging) ImagingError_ModeError(); xkernel = kernel[0]; ykernel = kernel[1]; if ((xkernel != 3 && xkernel != 5) || xkernel != ykernel) return (Imaging) ImagingError_ValueError("bad kernel size"); divisor = kernel[2]; offset = kernel[3]; kernel += 4; imOut = ImagingNew(im->mode, im->xsize, im->ysize); if (!imOut) return NULL; /* brute force kernel implementations */ #define KERNEL3x3(image, kernel, d) ( \ (int) image[y+1][x-d] * kernel[0] + \ (int) image[y+1][x] * kernel[1] + \ (int) image[y+1][x+d] * kernel[2] + \ (int) image[y][x-d] * kernel[3] + \ (int) image[y][x] * kernel[4] + \ (int) image[y][x+d] * kernel[5] + \ (int) image[y-1][x-d] * kernel[6] + \ (int) image[y-1][x] * kernel[7] + \ (int) image[y-1][x+d] * kernel[8]) #define KERNEL5x5(image, kernel, d) ( \ (int) image[y+2][x-d-d] * kernel[0] + \ (int) image[y+2][x-d] * kernel[1] + \ (int) image[y+2][x] * kernel[2] + \ (int) image[y+2][x+d] * kernel[3] + \ (int) image[y+2][x+d+d] * kernel[4] + \ (int) image[y+1][x-d-d] * kernel[5] + \ (int) image[y+1][x-d] * kernel[6] + \ (int) image[y+1][x] * kernel[7] + \ (int) image[y+1][x+d] * kernel[8] + \ (int) image[y+1][x+d+d] * kernel[9] + \ (int) image[y][x-d-d] * kernel[10] + \ (int) image[y][x-d] * kernel[11] + \ (int) image[y][x] * kernel[12] + \ (int) image[y][x+d] * kernel[13] + \ (int) image[y][x+d+d] * kernel[14] + \ (int) image[y-1][x-d-d] * kernel[15] + \ (int) image[y-1][x-d] * kernel[16] + \ (int) image[y-1][x] * kernel[17] + \ (int) image[y-1][x+d] * kernel[18] + \ (int) image[y-1][x+d+d] * kernel[19] + \ (int) image[y-2][x-d-d] * kernel[20] + \ (int) image[y-2][x-d] * kernel[21] + \ (int) image[y-2][x] * kernel[22] + \ (int) image[y-2][x+d] * kernel[23] + \ (int) image[y-2][x+d+d] * kernel[24]) if (xkernel == 3) { /* 3x3 kernel. */ for (x = 0; x < im->xsize; x++) imOut->image[0][x] = im->image8[0][x]; for (y = 1; y < im->ysize-1; y++) { imOut->image[y][0] = im->image8[y][0]; for (x = 1; x < im->xsize-1; x++) { sum = KERNEL3x3(im->image8, kernel, 1) / divisor + offset; if (sum <= 0) imOut->image8[y][x] = 0; else if (sum >= 255) imOut->image8[y][x] = 255; else imOut->image8[y][x] = sum; } imOut->image8[y][x] = im->image8[y][x]; } for (x = 0; x < im->xsize; x++) imOut->image8[y][x] = im->image8[y][x]; } else { /* 5x5 kernel. */ for (y = 0; y < 2; y++) for (x = 0; x < im->xsize; x++) imOut->image8[y][x] = im->image8[y][x]; for (; y < im->ysize-2; y++) { for (x = 0; x < 2; x++) imOut->image8[y][x] = im->image8[y][x]; for (; x < im->xsize-2; x++) { sum = KERNEL5x5(im->image8, kernel, 1) / divisor + offset; if (sum <= 0) imOut->image8[y][x] = 0; else if (sum >= 255) imOut->image8[y][x] = 255; else imOut->image8[y][x] = sum; } for (; x < im->xsize; x++) imOut->image8[y][x] = im->image8[y][x]; } for (; y < im->ysize; y++) for (x = 0; x < im->xsize; x++) imOut->image8[y][x] = im->image8[y][x]; } return imOut; } Imaging-1.1.3/libImaging/Geometry.c0100444000076400007640000005130507442710204016741 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Geometry.c#3 $ * * the imaging geometry methods * * history: * 2025-06-15 fl Created * 2025-04-15 fl Changed origin * 2025-05-18 fl Fixed rotate90/270 for rectangular images * 2025-05-27 fl Added general purpose transform * 2025-11-22 fl Don't crash when resizing from outside source image * 2025-08-09 fl Fixed rounding error in resize * 2025-09-21 fl Incorporated transformation patches (from Zircon #2) * 2025-09-22 fl Added bounding box to transform engines * 2025-02-03 fl Fixed bicubic filtering for RGB images * 2025-02-16 fl Added fixed-point version of affine transform * 2025-03-28 fl Fixed transform(EXTENT) for xoffset < 0 * * Copyright (c) 1997-2001 by Secret Labs AB * Copyright (c) 1995-1997 by Fredrik Lundh * * See the README file for information on usage and redistribution. */ #include "Imaging.h" /* Undef if you don't need resampling filters */ #define WITH_FILTERS #define COORD(v) ((v) < 0.0 ? -1 : ((int)(v))) #define FLOOR(v) ((v) < 0.0 ? ((int)floor(v)) : ((int)(v))) /* -------------------------------------------------------------------- */ /* Transpose operations */ Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn) { int x, y, xr; if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); if (imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); ImagingCopyInfo(imOut, imIn); #define FLIP_HORIZ(image)\ for (y = 0; y < imIn->ysize; y++) {\ xr = imIn->xsize-1;\ for (x = 0; x < imIn->xsize; x++, xr--)\ imOut->image[y][x] = imIn->image[y][xr];\ } if (imIn->image8) FLIP_HORIZ(image8) else FLIP_HORIZ(image32) return imOut; } Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn) { int y, yr; if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); if (imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); ImagingCopyInfo(imOut, imIn); yr = imIn->ysize-1; for (y = 0; y < imIn->ysize; y++, yr--) memcpy(imOut->image[yr], imIn->image[y], imIn->linesize); return imOut; } Imaging ImagingRotate90(Imaging imOut, Imaging imIn) { int x, y, xr; if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); if (imIn->xsize != imOut->ysize || imIn->ysize != imOut->xsize) return (Imaging) ImagingError_Mismatch(); ImagingCopyInfo(imOut, imIn); #define ROTATE_90(image)\ for (y = 0; y < imIn->ysize; y++) {\ xr = imIn->xsize-1;\ for (x = 0; x < imIn->xsize; x++, xr--)\ imOut->image[xr][y] = imIn->image[y][x];\ } if (imIn->image8) ROTATE_90(image8) else ROTATE_90(image32) return imOut; } Imaging ImagingRotate180(Imaging imOut, Imaging imIn) { int x, y, xr, yr; if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); if (imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); ImagingCopyInfo(imOut, imIn); yr = imIn->ysize-1; #define ROTATE_180(image)\ for (y = 0; y < imIn->ysize; y++, yr--) {\ xr = imIn->xsize-1;\ for (x = 0; x < imIn->xsize; x++, xr--)\ imOut->image[y][x] = imIn->image[yr][xr];\ } if (imIn->image8) ROTATE_180(image8) else ROTATE_180(image32) return imOut; } Imaging ImagingRotate270(Imaging imOut, Imaging imIn) { int x, y, yr; if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); if (imIn->xsize != imOut->ysize || imIn->ysize != imOut->xsize) return (Imaging) ImagingError_Mismatch(); ImagingCopyInfo(imOut, imIn); yr = imIn->ysize - 1; #define ROTATE_270(image)\ for (y = 0; y < imIn->ysize; y++, yr--)\ for (x = 0; x < imIn->xsize; x++)\ imOut->image[x][y] = imIn->image[yr][x]; if (imIn->image8) ROTATE_270(image8) else ROTATE_270(image32) return imOut; } /* -------------------------------------------------------------------- */ /* Transforms */ /* transform primitives (ImagingTransformMap) */ static int affine_transform(double* xin, double* yin, int x, int y, void* data) { /* full moon tonight. your compiler will generate bogus code for simple expressions, unless you reorganize the code, or install Service Pack 3 */ double* a = (double*) data; double a0 = a[0]; double a1 = a[1]; double a2 = a[2]; double a3 = a[3]; double a4 = a[4]; double a5 = a[5]; xin[0] = a0 + a1*x + a2*y; yin[0] = a3 + a4*x + a5*y; return 1; } static int quadratic_transform(double* xin, double* yin, int x, int y, void* data) { double* a = (double*) data; double a0 = a[0]; double a1 = a[1]; double a2 = a[2]; double a3 = a[3]; double a4 = a[4]; double a5 = a[5]; double a6 = a[6]; double a7 = a[7]; double a8 = a[8]; double a9 = a[9]; double a10 = a[10]; double a11 = a[11]; xin[0] = a0 + a1*x + a2*y + a3*x*x + a4*x*y + a5*y*y; yin[0] = a6 + a7*x + a8*y + a9*x*x + a10*x*y + a11*y*y; return 1; } static int quad_transform(double* xin, double* yin, int x, int y, void* data) { /* quad warp: map quadrilateral to rectangle */ double* a = (double*) data; double a0 = a[0]; double a1 = a[1]; double a2 = a[2]; double a3 = a[3]; double a4 = a[4]; double a5 = a[5]; double a6 = a[6]; double a7 = a[7]; xin[0] = a0 + a1*x + a2*y + a3*x*y; yin[0] = a4 + a5*x + a6*y + a7*x*y; return 1; } /* transform filters (ImagingTransformFilter) */ #ifdef WITH_FILTERS static int nearest_filter8(void* out, Imaging im, double xin, double yin, void* data) { int x = COORD(xin); int y = COORD(yin); if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) return 0; ((UINT8*)out)[0] = im->image8[y][x]; return 1; } static int nearest_filter16(void* out, Imaging im, double xin, double yin, void* data) { int x = COORD(xin); int y = COORD(yin); if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) return 0; ((INT16*)out)[0] = ((INT16*)(im->image8[y]))[x]; return 1; } static int nearest_filter32(void* out, Imaging im, double xin, double yin, void* data) { int x = COORD(xin); int y = COORD(yin); if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) return 0; ((INT32*)out)[0] = im->image32[y][x]; return 1; } #define XCLIP(im, x) ( ((x) < 0) ? 0 : ((x) < im->xsize) ? (x) : im->xsize-1 ) #define YCLIP(im, y) ( ((y) < 0) ? 0 : ((y) < im->ysize) ? (y) : im->ysize-1 ) #define BILINEAR(v, a, b, d)\ (v = (a) + ( (b) - (a) ) * (d)) #define BILINEAR_HEAD(type)\ int x, y;\ int x0, x1;\ double v1, v2;\ double dx, dy;\ type* in;\ if (xin < 0.0 || xin >= im->xsize || yin < 0.0 || yin >= im->ysize)\ return 0;\ xin -= 0.5;\ yin -= 0.5;\ x = FLOOR(xin);\ y = FLOOR(yin);\ dx = xin - x;\ dy = yin - y; #define BILINEAR_BODY(type, image, step, offset) {\ in = (type*) ((image)[YCLIP(im, y)] + offset);\ x0 = XCLIP(im, x+0)*step;\ x1 = XCLIP(im, x+1)*step;\ BILINEAR(v1, in[x0], in[x1], dx);\ if (y+1 >= 0 && y+1 < im->ysize) {\ in = (type*) ((image)[y+1] + offset);\ BILINEAR(v2, in[x0], in[x1], dx);\ } else\ v2 = v1;\ BILINEAR(v1, v1, v2, dy);\ } static int bilinear_filter8(void* out, Imaging im, double xin, double yin, void* data) { BILINEAR_HEAD(UINT8); BILINEAR_BODY(UINT8, im->image8, 1, 0); ((UINT8*)out)[0] = v1; return 1; } static int bilinear_filter32I(void* out, Imaging im, double xin, double yin, void* data) { BILINEAR_HEAD(INT32); BILINEAR_BODY(INT32, im->image32, 1, 0); ((INT32*)out)[0] = v1; return 1; } static int bilinear_filter32F(void* out, Imaging im, double xin, double yin, void* data) { BILINEAR_HEAD(FLOAT32); BILINEAR_BODY(FLOAT32, im->image32, 1, 0); ((FLOAT32*)out)[0] = v1; return 1; } static int bilinear_filter32RGB(void* out, Imaging im, double xin, double yin, void* data) { int b; BILINEAR_HEAD(UINT8); for (b = 0; b < im->bands; b++) { BILINEAR_BODY(UINT8, im->image, 4, b); ((UINT8*)out)[b] = v1; } return 1; } #define BICUBIC(v, v1, v2, v3, v4, d) {\ double p1 = v2;\ double p2 = -v1 + v3;\ double p3 = 2*(v1 - v2) + v3 - v4;\ double p4 = -v1 + v2 - v3 + v4;\ v = p1 + (d)*(p2 + (d)*(p3 + (d)*p4));\ } #define BICUBIC_HEAD(type)\ int x = FLOOR(xin);\ int y = FLOOR(yin);\ int x0, x1, x2, x3;\ double v1, v2, v3, v4;\ double dx, dy;\ type* in;\ if (xin < 0.0 || xin >= im->xsize || yin < 0.0 || yin >= im->ysize)\ return 0;\ xin -= 0.5;\ yin -= 0.5;\ x = FLOOR(xin);\ y = FLOOR(yin);\ dx = xin - x;\ dy = yin - y;\ x--; y--; #define BICUBIC_BODY(type, image, step, offset) {\ in = (type*) ((image)[YCLIP(im, y)] + offset);\ x0 = XCLIP(im, x+0)*step;\ x1 = XCLIP(im, x+1)*step;\ x2 = XCLIP(im, x+2)*step;\ x3 = XCLIP(im, x+3)*step;\ BICUBIC(v1, in[x0], in[x1], in[x2], in[x3], dx);\ if (y+1 >= 0 && y+1 < im->ysize) {\ in = (type*) ((image)[y+1] + offset);\ BICUBIC(v2, in[x0], in[x1], in[x2], in[x3], dx);\ } else\ v2 = v1;\ if (y+2 >= 0 && y+2 < im->ysize) {\ in = (type*) ((image)[y+2] + offset);\ BICUBIC(v3, in[x0], in[x1], in[x2], in[x3], dx);\ } else\ v3 = v2;\ if (y+3 >= 0 && y+3 < im->ysize) {\ in = (type*) ((image)[y+3] + offset);\ BICUBIC(v4, in[x0], in[x1], in[x2], in[x3], dx);\ } else\ v4 = v3;\ BICUBIC(v1, v1, v2, v3, v4, dy);\ } static int bicubic_filter8(void* out, Imaging im, double xin, double yin, void* data) { BICUBIC_HEAD(UINT8); BICUBIC_BODY(UINT8, im->image8, 1, 0); if (v1 <= 0.0) ((UINT8*)out)[0] = 0; else if (v1 >= 255.0) ((UINT8*)out)[0] = 255; else ((UINT8*)out)[0] = (UINT8) v1; return 1; } static int bicubic_filter32I(void* out, Imaging im, double xin, double yin, void* data) { BICUBIC_HEAD(INT32); BICUBIC_BODY(INT32, im->image32, 1, 0); ((INT32*)out)[0] = v1; return 1; } static int bicubic_filter32F(void* out, Imaging im, double xin, double yin, void* data) { BICUBIC_HEAD(FLOAT32); BICUBIC_BODY(FLOAT32, im->image32, 1, 0); ((FLOAT32*)out)[0] = v1; return 1; } static int bicubic_filter32RGB(void* out, Imaging im, double xin, double yin, void* data) { int b; BICUBIC_HEAD(UINT8); for (b = 0; b < im->bands; b++) { BICUBIC_BODY(UINT8, im->image, 4, b); if (v1 <= 0.0) ((UINT8*)out)[b] = 0; else if (v1 >= 255.0) ((UINT8*)out)[b] = 255; else ((UINT8*)out)[b] = (UINT8) v1; } return 1; } static ImagingTransformFilter getfilter(Imaging im, int filterid) { switch (filterid) { case IMAGING_TRANSFORM_NEAREST: if (im->image8) switch (im->type) { case IMAGING_TYPE_UINT8: return nearest_filter8; case IMAGING_TYPE_SPECIAL: switch (im->pixelsize) { case 1: return nearest_filter8; case 2: return nearest_filter16; case 4: return nearest_filter32; } } else return nearest_filter32; break; case IMAGING_TRANSFORM_BILINEAR: if (im->image8) return bilinear_filter8; else if (im->image32) { switch (im->type) { case IMAGING_TYPE_UINT8: return bilinear_filter32RGB; case IMAGING_TYPE_INT32: return bilinear_filter32I; case IMAGING_TYPE_FLOAT32: return bilinear_filter32F; } } break; case IMAGING_TRANSFORM_BICUBIC: if (im->image8) return bicubic_filter8; else if (im->image32) { switch (im->type) { case IMAGING_TYPE_UINT8: return bicubic_filter32RGB; case IMAGING_TYPE_INT32: return bicubic_filter32I; case IMAGING_TYPE_FLOAT32: return bicubic_filter32F; } } break; } /* no such filter */ return NULL; } #else #define getfilter(im, id) NULL #endif /* transformation engines */ Imaging ImagingTransform( Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, ImagingTransformMap transform, void* transform_data, ImagingTransformFilter filter, void* filter_data, int fill) { /* slow generic transformation. use ImagingTransformAffine or ImagingScaleAffine where possible. */ int x, y; char *out; double xx, yy; if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); ImagingCopyInfo(imOut, imIn); if (x0 < 0) x0 = 0; if (y0 < 0) y0 = 0; if (x1 > imOut->xsize) x1 = imOut->xsize; if (y1 > imOut->ysize) y1 = imOut->ysize; for (y = y0; y < y1; y++) { out = imOut->image[y] + x0*imOut->pixelsize; for (x = x0; x < x1; x++) { if (!transform(&xx, &yy, x-x0, y-y0, transform_data) || !filter(out, imIn, xx, yy, filter_data)) { if (fill) memset(out, 0, imOut->pixelsize); } out += imOut->pixelsize; } } return imOut; } static Imaging ImagingScaleAffine(Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, double a[6], int fill) { /* scale, nearest neighbour resampling */ int x, y; int xin; double xo, yo; int xmin, xmax; int *xintab; if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); ImagingCopyInfo(imOut, imIn); if (x0 < 0) x0 = 0; if (y0 < 0) y0 = 0; if (x1 > imOut->xsize) x1 = imOut->xsize; if (y1 > imOut->ysize) y1 = imOut->ysize; xintab = (int*) malloc(imOut->xsize * sizeof(int)); if (!xintab) { ImagingDelete(imOut); return (Imaging) ImagingError_MemoryError(); } xo = a[0]; yo = a[3]; xmin = x1; xmax = x0; /* Pretabulate horizontal pixel positions */ for (x = x0; x < x1; x++) { xin = COORD(xo); if (xin >= 0 && xin < (int) imIn->xsize) { xmax = x+1; if (x < xmin) xmin = x; xintab[x] = xin; } xo += a[1]; } #define AFFINE_SCALE(pixel, image)\ for (y = y0; y < y1; y++) {\ int yi = COORD(yo);\ pixel *in, *out;\ out = imOut->image[y];\ if (fill && x1 > x0)\ memset(out+x0, 0, (x1-x0)*sizeof(pixel));\ if (yi >= 0 && yi < imIn->ysize) {\ in = imIn->image[yi];\ for (x = xmin; x < xmax; x++)\ out[x] = in[xintab[x]];\ }\ yo += a[5];\ } if (imIn->image8) { AFFINE_SCALE(UINT8, image8); } else { AFFINE_SCALE(INT32, image32); } free(xintab); return imOut; } static inline int check_fixed(double a[6], int x, int y) { return (fabs(a[0] + x*a[1] + y*a[2]) < 32768.0 && fabs(a[3] + x*a[4] + y*a[5]) < 32768.0); } static inline Imaging affine_fixed(Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, double a[6], int filterid, int fill) { /* affine transform, nearest neighbour resampling, fixed point arithmetics */ int x, y; int xin, yin; int xsize, ysize; int xx, yy; int a0, a1, a2, a3, a4, a5; ImagingCopyInfo(imOut, imIn); xsize = (int) imIn->xsize; ysize = (int) imIn->ysize; /* use 16.16 fixed point arithmetics */ #define FIX(v) FLOOR((v)*65536.0 + 0.5) a0 = FIX(a[0]); a1 = FIX(a[1]); a2 = FIX(a[2]); a3 = FIX(a[3]); a4 = FIX(a[4]); a5 = FIX(a[5]); #define AFFINE_TRANSFORM_FIXED(pixel, image)\ for (y = y0; y < y1; y++) {\ pixel *out;\ xx = a0;\ yy = a3;\ out = imOut->image[y];\ if (fill && x1 > x0)\ memset(out+x0, 0, (x1-x0)*sizeof(pixel));\ for (x = x0; x < x1; x++, out++) {\ xin = xx >> 16;\ if (xin >= 0 && xin < xsize) {\ yin = yy >> 16;\ if (yin >= 0 && yin < ysize)\ *out = imIn->image[yin][xin];\ }\ xx += a1;\ yy += a4;\ }\ a0 += a2;\ a3 += a5;\ } if (imIn->image8) AFFINE_TRANSFORM_FIXED(UINT8, image8) else AFFINE_TRANSFORM_FIXED(INT32, image32) return imOut; } Imaging ImagingTransformAffine(Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, double a[6], int filterid, int fill) { /* affine transform, nearest neighbour resampling, floating point arithmetics*/ int x, y; int xin, yin; int xsize, ysize; double xx, yy; double xo, yo; if (filterid || imIn->type == IMAGING_TYPE_SPECIAL) { /* Filtered transform */ ImagingTransformFilter filter = getfilter(imIn, filterid); if (!filter) return (Imaging) ImagingError_ValueError("unknown filter"); return ImagingTransform( imOut, imIn, x0, y0, x1, y1, affine_transform, a, filter, NULL, fill); } if (a[2] == 0 && a[4] == 0) /* Scaling */ return ImagingScaleAffine(imOut, imIn, x0, y0, x1, y1, a, fill); if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); if (x0 < 0) x0 = 0; if (y0 < 0) y0 = 0; if (x1 > imOut->xsize) x1 = imOut->xsize; if (y1 > imOut->ysize) y1 = imOut->ysize; ImagingCopyInfo(imOut, imIn); /* translate all four corners to check if they are within the range that can be represented by the fixed point arithmetics */ if (check_fixed(a, 0, 0) && check_fixed(a, x1-x0, y1-y0) && check_fixed(a, 0, y1-y0) && check_fixed(a, x1-x0, 0)) return affine_fixed(imOut, imIn, x0, y0, x1, y1, a, filterid, fill); /* FIXME: cannot really think of any reasonable case when the following code is used. maybe we should fall back on the slow generic transform engine in this case? */ xsize = (int) imIn->xsize; ysize = (int) imIn->ysize; xo = a[0]; yo = a[3]; #define AFFINE_TRANSFORM(pixel, image)\ for (y = y0; y < y1; y++) {\ pixel *out;\ xx = xo;\ yy = yo;\ out = imOut->image[y];\ if (fill && x1 > x0)\ memset(out+x0, 0, (x1-x0)*sizeof(pixel));\ for (x = x0; x < x1; x++, out++) {\ xin = COORD(xx);\ if (xin >= 0 && xin < xsize) {\ yin = COORD(yy);\ if (yin >= 0 && yin < ysize)\ *out = imIn->image[yin][xin];\ }\ xx += a[1];\ yy += a[4];\ }\ xo += a[2];\ yo += a[5];\ } if (imIn->image8) AFFINE_TRANSFORM(UINT8, image8) else AFFINE_TRANSFORM(INT32, image32) return imOut; } Imaging ImagingTransformQuad(Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, double a[8], int filterid, int fill) { ImagingTransformFilter filter = getfilter(imIn, filterid); if (!filter) return (Imaging) ImagingError_ValueError("bad filter number"); return ImagingTransform( imOut, imIn, x0, y0, x1, y1, quad_transform, a, filter, NULL, fill); } /* -------------------------------------------------------------------- */ /* Convenience functions */ Imaging ImagingResize(Imaging imOut, Imaging imIn, int filterid) { double a[6]; if (imOut->xsize == imIn->xsize && imOut->ysize == imIn->ysize) return ImagingCopy2(imOut, imIn); memset(a, 0, sizeof a); a[1] = (double) imIn->xsize / imOut->xsize; a[5] = (double) imIn->ysize / imOut->ysize; if (!filterid && imIn->type != IMAGING_TYPE_SPECIAL) return ImagingScaleAffine( imOut, imIn, 0, 0, imOut->xsize, imOut->ysize, a, 1); return ImagingTransformAffine( imOut, imIn, 0, 0, imOut->xsize, imOut->ysize, a, filterid, 1); } Imaging ImagingRotate(Imaging imOut, Imaging imIn, double theta, int filterid) { int xsize, ysize; double sintheta, costheta; double a[6]; /* Setup an affine transform to rotate around the image center */ theta = -theta * M_PI / 180.0; sintheta = sin(theta); costheta = cos(theta); xsize = imOut->xsize; ysize = imOut->ysize; a[0] = -costheta * xsize/2 - sintheta * ysize/2 + xsize/2; a[1] = costheta; a[2] = sintheta; a[3] = sintheta * xsize/2 - costheta * ysize/2 + ysize/2; a[4] = -sintheta; a[5] = costheta; return ImagingTransformAffine( imOut, imIn, 0, 0, imOut->xsize, imOut->ysize, a, filterid, 1); } Imaging-1.1.3/libImaging/GetBBox.c0100444000076400007640000000734607442710204016446 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/GetBBox.c#2 $ * * get bounding box for image * * history: * 96-07-22 fl: Created * 96-12-30 fl: Added projection stuff * 98-07-12 fl: Added extrema stuff * * Copyright (c) Secret Labs AB 1997-98. * Copyright (c) Fredrik Lundh 1996. * * See the README file for details on usage and redistribution. */ #include "Imaging.h" int ImagingGetBBox(Imaging im, int bbox[4]) { /* Get the bounding box for any non-zero data in the image.*/ int x, y; int has_data; /* Initialize bounding box to max values */ bbox[0] = im->xsize; bbox[1] = -1; bbox[2] = bbox[3] = 0; #define GETBBOX(image, mask)\ for (y = 0; y < im->ysize; y++) {\ has_data = 0;\ for (x = 0; x < im->xsize; x++)\ if (im->image[y][x] & mask) {\ has_data = 1;\ if (x < bbox[0])\ bbox[0] = x;\ if (x >= bbox[2])\ bbox[2] = x+1;\ }\ if (has_data) {\ if (bbox[1] < 0)\ bbox[1] = y;\ bbox[3] = y+1;\ }\ } if (im->image8) { GETBBOX(image8, 0xff); } else { INT32 mask = 0xffffffff; if (im->bands == 3) ((UINT8*) &mask)[3] = 0; GETBBOX(image32, mask); } /* Check that we got a box */ if (bbox[1] < 0) return 0; /* no data */ return 1; /* ok */ } int ImagingGetProjection(Imaging im, UINT8* xproj, UINT8* yproj) { /* Get projection arrays for non-zero data in the image.*/ int x, y; int has_data; /* Initialize projection arrays */ memset(xproj, 0, im->xsize); memset(yproj, 0, im->ysize); #define GETPROJ(image, mask)\ for (y = 0; y < im->ysize; y++) {\ has_data = 0;\ for (x = 0; x < im->xsize; x++)\ if (im->image[y][x] & mask) {\ has_data = 1;\ xproj[x] = 1;\ }\ if (has_data)\ yproj[y] = 1;\ } if (im->image8) { GETPROJ(image8, 0xff); } else { INT32 mask = 0xffffffff; if (im->bands == 3) ((UINT8*) &mask)[3] = 0; GETPROJ(image32, mask); } return 1; /* ok */ } int ImagingGetExtrema(Imaging im, void *extrema) { int x, y; INT32 imin, imax; FLOAT32 fmin, fmax; if (im->bands != 1) { ImagingError_ModeError(); return -1; /* mismatch */ } if (!im->xsize || !im->ysize) return 0; /* zero size */ switch (im->type) { case IMAGING_TYPE_UINT8: imin = imax = im->image8[0][0]; for (y = 0; y < im->ysize; y++) { UINT8* in = im->image8[y]; for (x = 0; x < im->xsize; x++) { if (imin > in[x]) imin = in[x]; else if (imax < in[x]) imax = in[x]; } } ((UINT8*) extrema)[0] = (UINT8) imin; ((UINT8*) extrema)[1] = (UINT8) imax; break; case IMAGING_TYPE_INT32: imin = imax = im->image32[0][0]; for (y = 0; y < im->ysize; y++) { INT32* in = im->image32[y]; for (x = 0; x < im->xsize; x++) { if (imin > in[x]) imin = in[x]; else if (imax < in[x]) imax = in[x]; } } ((INT32*) extrema)[0] = imin; ((INT32*) extrema)[1] = imax; break; case IMAGING_TYPE_FLOAT32: fmin = fmax = ((FLOAT32*)im->image32[0])[0]; for (y = 0; y < im->ysize; y++) { FLOAT32* in = (FLOAT32*) im->image32[y]; for (x = 0; x < im->xsize; x++) { if (fmin > in[x]) fmin = in[x]; else if (fmax < in[x]) fmax = in[x]; } } ((FLOAT32*) extrema)[0] = fmin; ((FLOAT32*) extrema)[1] = fmax; break; default: ImagingError_ModeError(); return -1; } return 1; /* ok */ } Imaging-1.1.3/libImaging/Histo.c0100444000076400007640000001077407442710204016241 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Histo.c#2 $ * * histogram support * * history: * 95-06-15 fl Created. * 96-04-05 fl Fixed histogram for multiband images. * 97-02-23 fl Added mask support * 98-07-01 fl Added basic 32-bit float/integer support * * Copyright (c) Secret Labs AB 1997-98. * Copyright (c) Fredrik Lundh 1995-97. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" /* HISTOGRAM */ /* -------------------------------------------------------------------- * Take a histogram of an image. Returns a histogram object containing * 256 slots per band in the input image. */ void ImagingHistogramDelete(ImagingHistogram h) { if (h->histogram) free(h->histogram); free(h); } ImagingHistogram ImagingHistogramNew(Imaging im) { ImagingHistogram h; /* Create histogram descriptor */ h = calloc(1, sizeof(struct ImagingHistogramInstance)); strcpy(h->mode, im->mode); h->bands = im->bands; h->histogram = calloc(im->pixelsize, 256 * sizeof(long)); return h; } ImagingHistogram ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) { int x, y, i; ImagingHistogram h; INT32 imin, imax; FLOAT32 fmin, fmax, scale; if (!im) return ImagingError_ModeError(); if (imMask) { /* Validate mask */ if (im->xsize != imMask->xsize || im->ysize != imMask->ysize) return ImagingError_Mismatch(); if (strcmp(imMask->mode, "1") != 0 && strcmp(imMask->mode, "L") != 0) return ImagingError_ValueError("bad transparency mask"); } h = ImagingHistogramNew(im); if (imMask) { /* mask */ if (im->image8) { for (y = 0; y < im->ysize; y++) for (x = 0; x < im->xsize; x++) if (imMask->image8[y][x] != 0) h->histogram[im->image8[y][x]]++; } else { /* yes, we need the braces. C isn't Python! */ if (im->type != IMAGING_TYPE_UINT8) return ImagingError_ModeError(); for (y = 0; y < im->ysize; y++) { UINT8* in = (UINT8*) im->image32[y]; for (x = 0; x < im->xsize; x++) if (imMask->image8[y][x] != 0) { h->histogram[(*in++)]++; h->histogram[(*in++)+256]++; h->histogram[(*in++)+512]++; h->histogram[(*in++)+768]++; } else in += 4; } } } else { /* mask not given; process pixels in image */ if (im->image8) for (y = 0; y < im->ysize; y++) for (x = 0; x < im->xsize; x++) h->histogram[im->image8[y][x]]++; else { switch (im->type) { case IMAGING_TYPE_UINT8: for (y = 0; y < im->ysize; y++) { UINT8* in = (UINT8*) im->image[y]; for (x = 0; x < im->xsize; x++) { h->histogram[(*in++)]++; h->histogram[(*in++)+256]++; h->histogram[(*in++)+512]++; h->histogram[(*in++)+768]++; } } break; case IMAGING_TYPE_INT32: if (!minmax) return ImagingError_ValueError("min/max not given"); if (!im->xsize || !im->ysize) break; imin = ((INT32*) minmax)[0]; imax = ((INT32*) minmax)[1]; if (imin >= imax) break; scale = 255.0 / (imax - imin); for (y = 0; y < im->ysize; y++) { INT32* in = im->image32[y]; for (x = 0; x < im->xsize; x++) { i = (int) (((*in++)-imin)*scale); if (i >= 0 && i < 256) h->histogram[i]++; } } break; case IMAGING_TYPE_FLOAT32: if (!minmax) return ImagingError_ValueError("min/max not given"); if (!im->xsize || !im->ysize) break; fmin = ((FLOAT32*) minmax)[0]; fmax = ((FLOAT32*) minmax)[1]; if (fmin >= fmax) break; scale = 255.0 / (fmax - fmin); for (y = 0; y < im->ysize; y++) { FLOAT32* in = (FLOAT32*) im->image32[y]; for (x = 0; x < im->xsize; x++) { i = (int) (((*in++)-fmin)*scale); if (i >= 0 && i < 256) h->histogram[i]++; } } break; } } } return h; } Imaging-1.1.3/libImaging/Matrix.c0100444000076400007640000000321107442710204016403 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Matrix.c#2 $ * * colour and luminance matrix transforms * * history: * 96-05-18 fl: created (brute force implementation) * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #define CLIP(v) ((v <= 0) ? 0 : (v >= 255) ? 255 : v) Imaging ImagingConvertMatrix(Imaging im, const char *mode, float m[]) { Imaging imOut; int x, y; /* Assume there's enough data in the buffer */ if (!im) return (Imaging) ImagingError_ModeError(); if (strcmp(mode, "L") == 0 && im->bands == 3) { imOut = ImagingNew("L", im->xsize, im->ysize); if (!imOut) return NULL; for (y = 0; y < im->ysize; y++) { UINT8* in = (UINT8*) im->image[y]; UINT8* out = (UINT8*) imOut->image[y]; for (x = 0; x < im->xsize; x++) { int v = m[0]*in[0] + m[1]*in[1] + m[2]*in[2] + m[3]; out[x] = CLIP(v); in += 4; } } } else if (strlen(mode) == 3 && im->bands == 3) { imOut = ImagingNew(mode, im->xsize, im->ysize); if (!imOut) return NULL; for (y = 0; y < im->ysize; y++) { UINT8* in = (UINT8*) im->image[y]; UINT8* out = (UINT8*) imOut->image[y]; for (x = 0; x < im->xsize; x++) { int v0 = m[0]*in[0] + m[1]*in[1] + m[2]*in[2] + m[3]; int v1 = m[4]*in[0] + m[5]*in[1] + m[6]*in[2] + m[7]; int v2 = m[8]*in[0] + m[9]*in[1] + m[10]*in[2] + m[11]; out[0] = CLIP(v0); out[1] = CLIP(v1); out[2] = CLIP(v2); in += 4; out += 4; } } } else return (Imaging) ImagingError_ModeError(); return imOut; } Imaging-1.1.3/libImaging/Negative.c0100444000076400007640000000136307442710204016707 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Negative.c#2 $ * * negate image * * to do: * FIXME: Maybe this should be implemented using ImagingPoint() * * history: * 95-11-27 fl: Created * * Copyright (c) Fredrik Lundh 1995. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" Imaging ImagingNegative(Imaging im) { Imaging imOut; int x, y; if (!im) return (Imaging) ImagingError_ModeError(); imOut = ImagingNew(im->mode, im->xsize, im->ysize); if (!imOut) return NULL; for (y = 0; y < im->ysize; y++) for (x = 0; x < im->linesize; x++) imOut->image[y][x] = ~im->image[y][x]; return imOut; } Imaging-1.1.3/libImaging/Offset.c0100444000076400007640000000235107442710204016371 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Offset.c#2 $ * * offset an image in x and y directions * * history: * 96-07-22 fl: Created * 98-11-01 cgw@pgt.com: Fixed negative-array index bug * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" Imaging ImagingOffset(Imaging im, int xoffset, int yoffset) { int x, y; Imaging imOut; if (!im) return (Imaging) ImagingError_ModeError(); imOut = ImagingNew(im->mode, im->xsize, im->ysize); if (!imOut) return NULL; ImagingCopyInfo(imOut, im); /* make offsets positive to avoid negative coordinates */ xoffset %= im->xsize; xoffset = im->xsize - xoffset; if (xoffset < 0) xoffset += im->xsize; yoffset %= im->ysize; yoffset = im->ysize - yoffset; if (yoffset < 0) yoffset += im->ysize; #define OFFSET(image)\ for (y = 0; y < im->ysize; y++)\ for (x = 0; x < im->xsize; x++) {\ int yi = (y + yoffset) % im->ysize;\ int xi = (x + xoffset) % im->xsize;\ imOut->image[y][x] = im->image[yi][xi];\ } if (im->image8) OFFSET(image8) else OFFSET(image32) return imOut; } Imaging-1.1.3/libImaging/Pack.c0100444000076400007640000002347507442710204016033 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/Pack.c#2 $ * * code to pack raw data * * history: * 96-04-30 fl Created * 96-05-12 fl Published a few RGB packers * 96-11-01 fl More RGB packers (Tk booster stuff) * 96-12-30 fl Added P;1, P;2 and P;4 packers * 97-06-02 fl Added F (F;32NF) packer * 97-08-28 fl Added 1 as L packer * 98-02-08 fl Added I packer * 98-03-09 fl Added mode field, RGBA/RGBX as RGB packers * 98-07-01 fl Added YCbCr support * 98-07-12 fl Added I 16 packer * 99-02-03 fl Added BGR packers * * Copyright (c) Secret Labs AB 1997-98. * Copyright (c) Fredrik Lundh 1996-97. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #define R 0 #define G 1 #define B 2 #define X 3 /* byte swapping macros */ #define C16N\ (out[0]=tmp[0], out[1]=tmp[1]); #define C16S\ (out[1]=tmp[0], out[0]=tmp[1]); #define C32N\ (out[0]=tmp[0], out[1]=tmp[1], out[2]=tmp[2], out[3]=tmp[3]); #define C32S\ (out[3]=tmp[0], out[2]=tmp[1], out[1]=tmp[2], out[0]=tmp[3]); #define C64N\ (out[0]=tmp[0], out[1]=tmp[1], out[2]=tmp[2], out[3]=tmp[3],\ out[4]=tmp[4], out[5]=tmp[5], out[6]=tmp[6], out[7]=tmp[7]); #define C64S\ (out[7]=tmp[0], out[6]=tmp[1], out[5]=tmp[2], out[4]=tmp[3],\ out[3]=tmp[4], out[2]=tmp[5], out[1]=tmp[6], out[0]=tmp[7]); #ifdef WORDS_BIGENDIAN #define C16B C16N #define C16L C16S #define C32B C32N #define C32L C32S #define C64B C64N #define C64L C64S #else #define C16B C16S #define C16L C16N #define C32B C32S #define C32L C32N #define C64B C64S #define C64L C64N #endif static void pack1(UINT8* out, const UINT8* in, int pixels) { int i, m, b; /* bilevel (black is 0) */ b = 0; m = 128; for (i = 0; i < pixels; i++) { if (in[i] != 0) b |= m; m >>= 1; if (m == 0) { *out++ = b; b = 0; m = 128; } } if (m != 128) *out++ = b; } static void pack1I(UINT8* out, const UINT8* in, int pixels) { int i, m, b; /* bilevel (black is 1) */ b = 0; m = 128; for (i = 0; i < pixels; i++) { if (in[i] == 0) b |= m; m >>= 1; if (m == 0) { *out++ = b; b = 0; m = 128; } } if (m != 128) *out++ = b; } static void pack1R(UINT8* out, const UINT8* in, int pixels) { int i, m, b; /* bilevel, lsb first (black is 0) */ b = 0; m = 1; for (i = 0; i < pixels; i++) { if (in[i] != 0) b |= m; m <<= 1; if (m == 256){ *out++ = b; b = 0; m = 1; } } if (m != 1) *out++ = b; } static void pack1IR(UINT8* out, const UINT8* in, int pixels) { int i, m, b; /* bilevel, lsb first (black is 1) */ b = 0; m = 1; for (i = 0; i < pixels; i++) { if (in[i] == 0) b |= m; m <<= 1; if (m == 256){ *out++ = b; b = 0; m = 1; } } if (m != 1) *out++ = b; } static void pack1L(UINT8* out, const UINT8* in, int pixels) { int i; /* bilevel, stored as bytes */ for (i = 0; i < pixels; i++) out[i] = (in[i] != 0) ? 255 : 0; } static void packP4(UINT8* out, const UINT8* in, int pixels) { while (pixels >= 2) { *out++ = (in[0] << 4) | (in[1] & 15); in += 2; pixels -= 2; } if (pixels) out[0] = (in[0] << 4); } static void packP2(UINT8* out, const UINT8* in, int pixels) { while (pixels >= 4) { *out++ = (in[0] << 6) | ((in[1] & 3) << 4) | ((in[2] & 3) << 2) | (in[3] & 3); in += 4; pixels -= 4; } switch (pixels) { case 3: out[0] = (in[0] << 6) | ((in[1] & 3) << 4) | ((in[2] & 3) << 2); break; case 2: out[0] = (in[0] << 6) | ((in[1] & 3) << 4); case 1: out[0] = (in[0] << 6); } } void ImagingPackRGB(UINT8* out, const UINT8* in, int pixels) { int i; /* RGB triplets */ for (i = 0; i < pixels; i++) { out[0] = in[R]; out[1] = in[G]; out[2] = in[B]; out += 3; in += 4; } } void ImagingPackXRGB(UINT8* out, const UINT8* in, int pixels) { int i; /* XRGB, triplets with left padding */ for (i = 0; i < pixels; i++) { out[0] = 0; out[1] = in[R]; out[2] = in[G]; out[3] = in[B]; out += 4; in += 4; } } void ImagingPackBGR(UINT8* out, const UINT8* in, int pixels) { int i; /* RGB, reversed bytes */ for (i = 0; i < pixels; i++) { out[0] = in[B]; out[1] = in[G]; out[2] = in[R]; out += 3; in += 4; } } void ImagingPackBGRX(UINT8* out, const UINT8* in, int pixels) { int i; /* BGRX, reversed bytes with right padding */ for (i = 0; i < pixels; i++) { out[0] = in[B]; out[1] = in[G]; out[2] = in[R]; out[3] = 0; out += 4; in += 4; } } void ImagingPackXBGR(UINT8* out, const UINT8* in, int pixels) { int i; /* XBGR, reversed bytes with left padding */ for (i = 0; i < pixels; i++) { out[0] = 0; out[1] = in[B]; out[2] = in[G]; out[3] = in[R]; out += 4; in += 4; } } static void packRGBL(UINT8* out, const UINT8* in, int pixels) { int i; /* RGB, line interleaved */ for (i = 0; i < pixels; i++) { out[i] = in[R]; out[i+pixels] = in[G]; out[i+pixels+pixels] = in[B]; in += 4; } } static void packRGBXL(UINT8* out, const UINT8* in, int pixels) { int i; /* RGBX, line interleaved */ for (i = 0; i < pixels; i++) { out[i] = in[R]; out[i+pixels] = in[G]; out[i+pixels+pixels] = in[B]; out[i+pixels+pixels+pixels] = in[X]; in += 4; } } static void packI16B(UINT8* out, const UINT8* in_, int pixels) { int i; INT32* in = (INT32*) in_; UINT16 tmp_; UINT8* tmp = (UINT8*) &tmp_; for (i = 0; i < pixels; i++) { if (in[0] <= 0) tmp_ = 0; else if (in[0] > 65535) tmp_ = 65535; else tmp_ = in[0]; C16B; out += 2; in++; } } static void packI32S(UINT8* out, const UINT8* in, int pixels) { int i; UINT8* tmp = (UINT8*) in; for (i = 0; i < pixels; i++) { C32L; out += 4; tmp += 4; } } static void copy1(UINT8* out, const UINT8* in, int pixels) { /* L, P */ memcpy(out, in, pixels); } static void copy2(UINT8* out, const UINT8* in, int pixels) { /* I;16, etc */ memcpy(out, in, pixels*2); } static void copy3(UINT8* out, const UINT8* in, int pixels) { /* BGR;24, etc */ memcpy(out, in, pixels*3); } static void copy4(UINT8* out, const UINT8* in, int pixels) { /* RGBA, CMYK quadruples */ memcpy(out, in, 4*pixels); } static void band0(UINT8* out, const UINT8* in, int pixels) { int i; for (i = 0; i < pixels; i++, in += 4) out[i] = in[0]; } static void band1(UINT8* out, const UINT8* in, int pixels) { int i; for (i = 0; i < pixels; i++, in += 4) out[i] = in[1]; } static void band2(UINT8* out, const UINT8* in, int pixels) { int i; for (i = 0; i < pixels; i++, in += 4) out[i] = in[2]; } static void band3(UINT8* out, const UINT8* in, int pixels) { int i; for (i = 0; i < pixels; i++, in += 4) out[i] = in[3]; } static struct { const char* mode; const char* rawmode; int bits; ImagingShuffler pack; } packers[] = { /* bilevel */ {"1", "1", 1, pack1}, {"1", "1;I", 1, pack1I}, {"1", "1;R", 1, pack1R}, {"1", "1;IR", 1, pack1IR}, {"1", "L", 8, pack1L}, /* greyscale */ {"L", "L", 8, copy1}, /* palette */ {"P", "P;1", 1, pack1}, {"P", "P;2", 2, packP2}, {"P", "P;4", 4, packP4}, {"P", "P", 8, copy1}, /* true colour */ {"RGB", "RGB", 24, ImagingPackRGB}, {"RGB", "RGBX", 32, copy4}, {"RGB", "XRGB", 32, ImagingPackXRGB}, {"RGB", "BGR", 24, ImagingPackBGR}, {"RGB", "BGRX", 32, ImagingPackBGRX}, {"RGB", "XBGR", 32, ImagingPackXBGR}, {"RGB", "RGB;L", 24, packRGBL}, {"RGB", "R", 8, band0}, {"RGB", "G", 8, band1}, {"RGB", "B", 8, band2}, /* true colour w. transparency */ {"RGBA", "RGBA", 32, copy4}, {"RGBA", "RGBA;L", 32, packRGBXL}, {"RGBA", "RGB", 24, ImagingPackRGB}, {"RGBA", "R", 8, band0}, {"RGBA", "G", 8, band1}, {"RGBA", "B", 8, band2}, {"RGBA", "A", 8, band3}, /* true colour w. padding */ {"RGBX", "RGBX", 32, copy4}, {"RGBX", "RGBX;L", 32, packRGBXL}, {"RGBX", "RGB", 32, ImagingPackRGB}, {"RGBX", "R", 8, band0}, {"RGBX", "G", 8, band1}, {"RGBX", "B", 8, band2}, {"RGBX", "X", 8, band3}, /* colour separation */ {"CMYK", "CMYK", 32, copy4}, {"CMYK", "CMYK;L", 32, packRGBXL}, {"CMYK", "C", 8, band0}, {"CMYK", "M", 8, band1}, {"CMYK", "Y", 8, band2}, {"CMYK", "K", 8, band3}, /* video (YCbCr) */ {"YCbCr", "YCbCr", 24, ImagingPackRGB}, {"YCbCr", "YCbCr;L", 24, packRGBL}, {"YCbCr", "YCbCrX", 32, copy4}, {"YCbCr", "YCbCrK", 32, copy4}, {"YCbCr", "Y", 8, band0}, {"YCbCr", "Cb", 8, band1}, {"YCbCr", "Cr", 8, band2}, /* integer */ {"I", "I", 32, copy4}, {"I", "I;16B", 16, packI16B}, {"I", "I;32S", 32, packI32S}, {"I", "I;32NS", 32, copy4}, /* floating point */ {"F", "F", 32, copy4}, {"F", "F;32F", 32, packI32S}, {"F", "F;32NF", 32, copy4}, /* storage modes */ {"I;16", "I;16", 16, copy2}, {"I;16B", "I;16B", 16, copy2}, {"BGR;15", "BGR;15", 16, copy2}, {"BGR;16", "BGR;16", 16, copy2}, {"BGR;24", "BGR;24", 24, copy3}, {NULL} /* sentinel */ }; ImagingShuffler ImagingFindPacker(const char* mode, const char* rawmode, int* bits_out) { int i; /* find a suitable pixel packer */ for (i = 0; packers[i].rawmode; i++) if (strcmp(packers[i].mode, mode) == 0 && strcmp(packers[i].rawmode, rawmode) == 0) { if (bits_out) *bits_out = packers[i].bits; return packers[i].pack; } return NULL; } Imaging-1.1.3/libImaging/Palette.c0100444000076400007640000001536507442710204016552 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Palette.c#2 $ * * imaging palette object * * history: * 96-05-05 fl: Added to library * 96-05-27 fl: Added colour mapping stuff * 97-05-12 fl: Support RGBA palettes * * Copyright (c) Fredrik Lundh 1995-97. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include #include "Imaging.h" ImagingPalette ImagingPaletteNew(const char* mode) { /* Create a palette object */ int i; ImagingPalette palette; palette = calloc(1, sizeof(struct ImagingPaletteInstance)); if (!palette) return (ImagingPalette) ImagingError_MemoryError(); if (strcmp(mode, "RGB") && strcmp(mode, "RGBA")) return (ImagingPalette) ImagingError_ModeError(); strcpy(palette->mode, mode); /* Initialize to ramp */ for (i = 0; i < 256; i++) { palette->palette[i*4+0] = palette->palette[i*4+1] = palette->palette[i*4+2] = (UINT8) i; palette->palette[i*4+3] = 255; /* opaque */ } return palette; } ImagingPalette ImagingPaletteNewBrowser(void) { /* Create a standard "browser" palette object */ int i, r, g, b; ImagingPalette palette; palette = ImagingPaletteNew("RGB"); if (!palette) return NULL; /* Simple 6x6x6 colour cube */ i = 10; for (b = 0; b < 256; b += 51) for (g = 0; g < 256; g += 51) for (r = 0; r < 256; r += 51) { palette->palette[i*4+0] = r; palette->palette[i*4+1] = g; palette->palette[i*4+2] = b; i++; } return palette; } ImagingPalette ImagingPaletteDuplicate(ImagingPalette palette) { /* Duplicate palette descriptor */ ImagingPalette new_palette; if (!palette) return NULL; new_palette = malloc(sizeof(struct ImagingPaletteInstance)); if (!new_palette) return (ImagingPalette) ImagingError_MemoryError(); memcpy(new_palette, palette, sizeof(struct ImagingPaletteInstance)); /* Don't share the cache */ new_palette->cache = NULL; return new_palette; } void ImagingPaletteDelete(ImagingPalette palette) { /* Destroy palette object */ if (palette) { if (palette->cache) free(palette->cache); free(palette); } } /* -------------------------------------------------------------------- */ /* Colour mapping */ /* -------------------------------------------------------------------- */ /* This code is used to map RGB triplets to palette indices, using a palette index cache. */ /* * This implementation is loosely based on the corresponding code in * the IJG JPEG library by Thomas G. Lane. Original algorithms by * Paul Heckbert and Spencer W. Thomas. * * The IJG JPEG library is copyright (C) 1991-1995, Thomas G. Lane. */ #define DIST(a, b, s) (a - b) * (a - b) * s /* Colour weights (no scaling, for now) */ #define RSCALE 1 #define GSCALE 1 #define BSCALE 1 /* Calculated scaled distances */ #define RDIST(a, b) DIST(a, b, RSCALE*RSCALE) #define GDIST(a, b) DIST(a, b, GSCALE*GSCALE) #define BDIST(a, b) DIST(a, b, BSCALE*BSCALE) /* Incremental steps */ #define RSTEP (4 * RSCALE) #define GSTEP (4 * GSCALE) #define BSTEP (4 * BSCALE) #define BOX 8 #define BOXVOLUME BOX*BOX*BOX void ImagingPaletteCacheUpdate(ImagingPalette palette, int r, int g, int b) { int i, j; unsigned int dmin[256], dmax; int r0, g0, b0; int r1, g1, b1; int rc, gc, bc; unsigned int d[BOXVOLUME]; UINT8 c[BOXVOLUME]; /* Get box boundaries for the given (r,g,b)-triplet. Each box covers eight cache slots (32 colour values, that is). */ r0 = r & 0xe0; r1 = r0 + 0x1f; rc = (r0 + r1) / 2; g0 = g & 0xe0; g1 = g0 + 0x1f; gc = (g0 + g1) / 2; b0 = b & 0xe0; b1 = b0 + 0x1f; bc = (b0 + b1) / 2; /* Step 1 -- Select relevant palette entries (after Heckbert) */ /* For each palette entry, calculate the min and max distances to * any position in the box given by the colour we're looking for. */ dmax = (unsigned int) ~0; for (i = 0; i < 256; i++) { int r, g, b; unsigned int tmin, tmax; /* Find min and max distances to any point in the box */ r = palette->palette[i*4+0]; tmin = (r < r0) ? RDIST(r, r1) : (r > r1) ? RDIST(r, r0) : 0; tmax = (r <= rc) ? RDIST(r, r1) : RDIST(r, r0); g = palette->palette[i*4+1]; tmin += (g < g0) ? GDIST(g, g1) : (g > g1) ? GDIST(g, g0) : 0; tmax += (g <= gc) ? GDIST(g, g1) : GDIST(g, g0); b = palette->palette[i*4+2]; tmin += (b < b0) ? BDIST(b, b1) : (b > b1) ? BDIST(b, b0) : 0; tmax += (b <= bc) ? BDIST(b, b1) : BDIST(b, b0); dmin[i] = tmin; if (tmax < dmax) dmax = tmax; /* keep the smallest max distance only */ } /* Step 2 -- Incrementally update cache slot (after Thomas) */ /* Find the box containing the nearest palette entry, and update * all slots in that box. We only check boxes for which the min * distance is less than or equal the smallest max distance */ for (i = 0; i < BOXVOLUME; i++) d[i] = (unsigned int) ~0; for (i = 0; i < 256; i++) if (dmin[i] <= dmax) { int rd, gd, bd; int ri, gi, bi; int rx, gx, bx; ri = (r0 - palette->palette[i*4+0]) * RSCALE; gi = (g0 - palette->palette[i*4+1]) * GSCALE; bi = (b0 - palette->palette[i*4+2]) * BSCALE; rd = ri*ri + gi*gi + bi*bi; ri = ri * (2 * RSTEP) + RSTEP * RSTEP; gi = gi * (2 * GSTEP) + GSTEP * GSTEP; bi = bi * (2 * BSTEP) + BSTEP * BSTEP; rx = ri; for (r = j = 0; r < BOX; r++) { gd = rd; gx = gi; for (g = 0; g < BOX; g++) { bd = gd; bx = bi; for (b = 0; b < BOX; b++) { if ((unsigned int) bd < d[j]) { d[j] = bd; c[j] = (UINT8) i; } bd += bx; bx += 2 * BSTEP * BSTEP; j++; } gd += gx; gx += 2 * GSTEP * GSTEP; } rd += rx; rx += 2 * RSTEP * RSTEP; } } /* Step 3 -- Update cache */ /* The c array now contains the closest match for each * cache slot in the box. Update the cache. */ j = 0; for (r = r0; r < r1; r+=4) for (g = g0; g < g1; g+=4) for (b = b0; b < b1; b+=4) ImagingPaletteCache(palette, r, g, b) = c[j++]; } int ImagingPaletteCachePrepare(ImagingPalette palette) { /* Add a colour cache to a palette */ int i; int entries = 64*64*64; if (palette->cache == NULL) { /* The cache is 512k. It might be a good idea to break it up into a pointer array (e.g. an 8-bit image?) */ palette->cache = (INT16*) malloc(entries * sizeof(INT16)); if (!palette->cache) { ImagingError_MemoryError(); return -1; } /* Mark all entries as empty */ for (i = 0; i < entries; i++) palette->cache[i] = 0x100; } return 0; } void ImagingPaletteCacheDelete(ImagingPalette palette) { /* Release the colour cache, if any */ if (palette && palette->cache) { free(palette->cache); palette->cache = NULL; } } Imaging-1.1.3/libImaging/Paste.c0100444000076400007640000003327107442710204016224 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Paste.c#2 $ * * paste image on another image * * history: * 96-03-27 fl Created * 96-07-16 fl Support "1", "L" and "RGBA" masks * 96-08-16 fl Merged with opaque paste * 97-01-17 fl Faster blending, added support for RGBa images * 97-08-27 fl Faster masking for 32-bit images * 98-02-02 fl Fixed MULDIV255 macro for gcc * 99-02-02 fl Added "RGBa" mask support * 99-02-06 fl Rewritten. Added support for masked fill operations. * 99-12-08 fl Fixed matte fill. * * Copyright (c) Fredrik Lundh 1996-97. * Copyright (c) Secret Labs AB 1997-99. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" /* like (a * b + 127) / 255), but much faster on most platforms */ #define MULDIV255NEW(a, b, tmp)\ (tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8)) #define MULDIV255OLD(a, b, tmp)\ (((a) * (b) + 127) / 255) #define MULDIV255 MULDIV255NEW #define BLEND(mask, in1, in2, tmp1, tmp2)\ (MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2)) #define PREBLEND(mask, in1, in2, tmp1)\ (MULDIV255(in1, 255 - mask, tmp1) + in2) static inline void paste(Imaging imOut, Imaging imIn, int dx, int dy, int sx, int sy, int xsize, int ysize, int pixelsize) { /* paste opaque region */ int y; dx *= pixelsize; sx *= pixelsize; xsize *= pixelsize; for (y = 0; y < ysize; y++) memcpy(imOut->image[y+dy]+dx, imIn->image[y+sy]+sx, xsize); } static inline void paste_mask_1(Imaging imOut, Imaging imIn, Imaging imMask, int dx, int dy, int sx, int sy, int xsize, int ysize, int pixelsize) { /* paste with mode "1" mask */ int x, y; if (imOut->image8) { for (y = 0; y < ysize; y++) { UINT8* out = imOut->image8[y+dy]+dx; UINT8* in = imIn->image8[y+sy]+sx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { if (*mask++) *out = *in; out++, in++; } } } else { for (y = 0; y < ysize; y++) { INT32* out = imOut->image32[y+dy]+dx; INT32* in = imIn->image32[y+sy]+sx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { if (*mask++) *out = *in; out++, in++; } } } } static inline void paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask, int dx, int dy, int sx, int sy, int xsize, int ysize, int pixelsize) { /* paste with mode "L" matte */ int x, y, i; unsigned int tmp1, tmp2; if (imOut->image8) { for (y = 0; y < ysize; y++) { UINT8* out = imOut->image8[y+dy]+dx; UINT8* in = imIn->image8[y+sy]+sx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { *out = BLEND(*mask, *out, *in, tmp1, tmp2); out++, in++, mask++; } } } else { for (y = 0; y < ysize; y++) { UINT8* out = (UINT8*) imOut->image[y+dy]+dx*pixelsize; UINT8* in = (UINT8*) imIn->image[y+sy]+sx*pixelsize; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { *out = BLEND(*mask, *out, *in, tmp1, tmp2); out++, in++; } mask++; } } } } static inline void paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask, int dx, int dy, int sx, int sy, int xsize, int ysize, int pixelsize) { /* paste with mode "RGBA" matte */ int x, y, i; unsigned int tmp1, tmp2; if (imOut->image8) { for (y = 0; y < ysize; y++) { UINT8* out = imOut->image8[y+dy]+dx; UINT8* in = imIn->image8[y+sy]+sx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3; for (x = 0; x < xsize; x++) { *out = BLEND(*mask, *out, *in, tmp1, tmp2); out++, in++, mask += 4; } } } else { for (y = 0; y < ysize; y++) { UINT8* out = (UINT8*) imOut->image[y+dy]+dx*pixelsize; UINT8* in = (UINT8*) imIn->image[y+sy]+sx*pixelsize; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { *out = BLEND(*mask, *out, *in, tmp1, tmp2); out++, in++; } mask += 4; } } } } static inline void paste_mask_RGBa(Imaging imOut, Imaging imIn, Imaging imMask, int dx, int dy, int sx, int sy, int xsize, int ysize, int pixelsize) { /* paste with mode "RGBa" matte */ int x, y, i; unsigned int tmp1; if (imOut->image8) { for (y = 0; y < ysize; y++) { UINT8* out = imOut->image8[y+dy]+dx; UINT8* in = imIn->image8[y+sy]+sx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3; for (x = 0; x < xsize; x++) { *out = PREBLEND(*mask, *out, *in, tmp1); out++, in++, mask += 4; } } } else { for (y = 0; y < ysize; y++) { UINT8* out = (UINT8*) imOut->image[y+dy]+dx*pixelsize; UINT8* in = (UINT8*) imIn->image[y+sy]+sx*pixelsize; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { *out = PREBLEND(*mask, *out, *in, tmp1); out++, in++; } mask += 4; } } } } int ImagingPaste(Imaging imOut, Imaging imIn, Imaging imMask, int dx0, int dy0, int dx1, int dy1) { int xsize, ysize; int pixelsize; int sx0, sy0; if (!imOut || !imIn) { ImagingError_ModeError(); return -1; } pixelsize = imOut->pixelsize; xsize = dx1 - dx0; ysize = dy1 - dy0; if (xsize != imIn->xsize || ysize != imIn->ysize || pixelsize != imIn->pixelsize) { ImagingError_Mismatch(); return -1; } if (imMask && (xsize != imMask->xsize || ysize != imMask->ysize)) { ImagingError_Mismatch(); return -1; } /* Determine which region to copy */ sx0 = sy0 = 0; if (dx0 < 0) xsize += dx0, sx0 = -dx0, dx0 = 0; if (dx0 + xsize > imOut->xsize) xsize = imOut->xsize - dx0; if (dy0 < 0) ysize += dy0, sy0 = -dy0, dy0 = 0; if (dy0 + ysize > imOut->ysize) ysize = imOut->ysize - dy0; if (xsize <= 0 || ysize <= 0) return 0; if (!imMask) paste(imOut, imIn, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize); else if (strcmp(imMask->mode, "1") == 0) paste_mask_1(imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize); else if (strcmp(imMask->mode, "L") == 0) paste_mask_L(imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize); else if (strcmp(imMask->mode, "RGBA") == 0) paste_mask_RGBA(imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize); else if (strcmp(imMask->mode, "RGBa") == 0) paste_mask_RGBa(imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize); else { ImagingError_ValueError("bad transparency mask"); return -1; } return 0; } static inline void fill(Imaging imOut, const void* ink_, int dx, int dy, int xsize, int ysize, int pixelsize) { /* fill opaque region */ int x, y; INT32 ink = 0L; memcpy(&ink, ink_, pixelsize); if (imOut->image8 || ink == 0L) { dx *= pixelsize; xsize *= pixelsize; for (y = 0; y < ysize; y++) memset(imOut->image[y+dy]+dx, (UINT8) ink, xsize); } else { for (y = 0; y < ysize; y++) { INT32* out = imOut->image32[y+dy]+dx; for (x = 0; x < xsize; x++) out[x] = ink; } } } static inline void fill_mask_1(Imaging imOut, const void* ink_, Imaging imMask, int dx, int dy, int sx, int sy, int xsize, int ysize, int pixelsize) { /* fill with mode "1" mask */ int x, y; INT32 ink = 0L; memcpy(&ink, ink_, pixelsize); if (imOut->image8) { for (y = 0; y < ysize; y++) { UINT8* out = imOut->image8[y+dy]+dx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { if (*mask++) *out = (UINT8) ink; out++; } } } else { for (y = 0; y < ysize; y++) { INT32* out = imOut->image32[y+dy]+dx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { if (*mask++) *out = ink; out++; } } } } static inline void fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask, int dx, int dy, int sx, int sy, int xsize, int ysize, int pixelsize) { /* fill with mode "L" matte */ int x, y, i; unsigned int tmp1, tmp2; if (imOut->image8) { for (y = 0; y < ysize; y++) { UINT8* out = imOut->image8[y+dy]+dx; UINT8* mask = imMask->image8[y+sy]+sx; for (x = 0; x < xsize; x++) { *out = BLEND(*mask, *out, ink[0], tmp1, tmp2); out++, mask++; } } } else { for (y = 0; y < ysize; y++) { UINT8* out = (UINT8*) imOut->image[y+dy]+dx*pixelsize; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { *out = BLEND(*mask, *out, ink[i], tmp1, tmp2); out++; } mask++; } } } } static inline void fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask, int dx, int dy, int sx, int sy, int xsize, int ysize, int pixelsize) { /* fill with mode "RGBA" matte */ int x, y, i; unsigned int tmp1, tmp2; if (imOut->image8) { sx = sx*4+3; for (y = 0; y < ysize; y++) { UINT8* out = imOut->image8[y+dy]+dx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { *out = BLEND(*mask, *out, ink[0], tmp1, tmp2); out++, mask += 4; } } } else { dx *= pixelsize; sx = sx*4 + 3; for (y = 0; y < ysize; y++) { UINT8* out = (UINT8*) imOut->image[y+dy]+dx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { *out = BLEND(*mask, *out, ink[i], tmp1, tmp2); out++; } mask += 4; } } } } static inline void fill_mask_RGBa(Imaging imOut, const UINT8* ink, Imaging imMask, int dx, int dy, int sx, int sy, int xsize, int ysize, int pixelsize) { /* fill with mode "RGBa" matte */ int x, y, i; unsigned int tmp1; if (imOut->image8) { sx = sx*4 + 3; for (y = 0; y < ysize; y++) { UINT8* out = imOut->image8[y+dy]+dx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { *out = PREBLEND(*mask, *out, ink[0], tmp1); out++, mask += 4; } } } else { dx *= pixelsize; sx = sx*4 + 3; for (y = 0; y < ysize; y++) { UINT8* out = (UINT8*) imOut->image[y+dy]+dx; UINT8* mask = (UINT8*) imMask->image[y+sy]+sx; for (x = 0; x < xsize; x++) { for (i = 0; i < pixelsize; i++) { *out = PREBLEND(*mask, *out, ink[i], tmp1); out++; } mask += 4; } } } } int ImagingFill2(Imaging imOut, const void* ink, Imaging imMask, int dx0, int dy0, int dx1, int dy1) { int xsize, ysize; int pixelsize; int sx0, sy0; if (!imOut || !ink) { ImagingError_ModeError(); return -1; } pixelsize = imOut->pixelsize; xsize = dx1 - dx0; ysize = dy1 - dy0; if (imMask && (xsize != imMask->xsize || ysize != imMask->ysize)) { ImagingError_Mismatch(); return -1; } /* Determine which region to fill */ sx0 = sy0 = 0; if (dx0 < 0) xsize += dx0, sx0 = -dx0, dx0 = 0; if (dx0 + xsize > imOut->xsize) xsize = imOut->xsize - dx0; if (dy0 < 0) ysize += dy0, sy0 = -dy0, dy0 = 0; if (dy0 + ysize > imOut->ysize) ysize = imOut->ysize - dy0; if (xsize <= 0 || ysize <= 0) return 0; if (!imMask) fill(imOut, ink, dx0, dy0, xsize, ysize, pixelsize); else if (strcmp(imMask->mode, "1") == 0) fill_mask_1(imOut, ink, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize); else if (strcmp(imMask->mode, "L") == 0) fill_mask_L(imOut, ink, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize); else if (strcmp(imMask->mode, "RGBA") == 0) fill_mask_RGBA(imOut, ink, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize); else if (strcmp(imMask->mode, "RGBa") == 0) fill_mask_RGBa(imOut, ink, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize); else { ImagingError_ValueError("bad transparency mask"); return -1; } return 0; } Imaging-1.1.3/libImaging/Point.c0100444000076400007640000000777007442710204016246 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Point.c#2 $ * * point (pixel) translation * * history: * 95-11-27 fl: Created * 96-03-31 fl: Fixed colour support * 96-08-13 fl: Support 8-bit to "1" thresholding * 97-05-31 fl: Added floating point transform * 98-07-02 fl: Added integer point transform * 98-07-17 fl: Support 8-bit to anything lookup * * Copyright (c) Secret Labs AB 1997-98. * Copyright (c) Fredrik Lundh 1995-97. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" Imaging ImagingPoint(Imaging imIn, const char* mode, const void* table_) { /* lookup table transform */ Imaging imOut; int x, y; if (!imIn) return (Imaging) ImagingError_ModeError(); if (mode && !imIn->image8) return (Imaging) ImagingError_Mismatch(); imOut = ImagingNew((mode) ? mode : imIn->mode, imIn->xsize, imIn->ysize); if (!imOut) return NULL; ImagingCopyInfo(imOut, imIn); if (imIn->image8) { if (imOut->image8) { /* 8-bit source, 8-bit destination */ UINT8* table = (UINT8*) table_; for (y = 0; y < imIn->ysize; y++) { UINT8* in = imIn->image8[y]; UINT8* out = imOut->image8[y]; for (x = 0; x < imIn->xsize; x++) imOut->image[y][x] = table[imIn->image8[y][x]]; } } else { /* 8-bit source, 32-bit destination */ INT32* table = (INT32*) table_; for (y = 0; y < imIn->ysize; y++) { UINT8* in = imIn->image8[y]; INT32* out = imOut->image32[y]; for (x = 0; x < imIn->xsize; x++) out[x] = table[in[x]]; } } } else { /* nx8-bit source, nx8-bit destination */ UINT8* table = (UINT8*) table_; switch (imIn->bands) { case 3: for (y = 0; y < imIn->ysize; y++) { UINT8* in = (UINT8*) imIn->image[y]; UINT8* out = (UINT8*) imOut->image[y]; for (x = 0; x < imIn->xsize; x++) { out[0] = table[in[0]]; out[1] = table[in[1]+256]; out[2] = table[in[2]+512]; in += 4; out += 4; } } break; case 4: for (y = 0; y < imIn->ysize; y++) { UINT8* in = (UINT8*) imIn->image[y]; UINT8* out = (UINT8*) imOut->image[y]; for (x = 0; x < imIn->xsize; x++) { out[0] = table[in[0]]; out[1] = table[in[1]+256]; out[2] = table[in[2]+512]; out[3] = table[in[3]+768]; in += 4; out += 4; } } break; } } return imOut; } Imaging ImagingPointTransform(Imaging imIn, double scale, double offset) { /* scale/offset transform */ Imaging imOut; int x, y; if (!imIn || strcmp(imIn->mode, "I") != 0 && strcmp(imIn->mode, "F") != 0) return (Imaging) ImagingError_ModeError(); imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize); if (!imOut) return NULL; ImagingCopyInfo(imOut, imIn); switch (imIn->type) { case IMAGING_TYPE_INT32: for (y = 0; y < imIn->ysize; y++) { INT32* in = imIn->image32[y]; INT32* out = imOut->image32[y]; /* FIXME: add clipping? */ for (x = 0; x < imIn->xsize; x++) out[x] = in[x] * scale + offset; } break; case IMAGING_TYPE_FLOAT32: for (y = 0; y < imIn->ysize; y++) { FLOAT32* in = (FLOAT32*) imIn->image32[y]; FLOAT32* out = (FLOAT32*) imOut->image32[y]; for (x = 0; x < imIn->xsize; x++) out[x] = in[x] * scale + offset; } break; default: ImagingDelete(imOut); return (Imaging) ImagingError_ValueError("internal error"); } return imOut; } Imaging-1.1.3/libImaging/Quant.c0100444000076400007640000012313407442710204016236 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Quant.c#3 $ * * image quantizer * * history: * 98-09-10 tjs Contributed * 98-12-29 fl Added to PIL 1.0b1 * * Written by Toby J Sargeant . * * Copyright (c) 1998 by Toby J Sargeant * Copyright (c) 1998 by Secret Labs AB * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #include #include #include #include #include "Quant.h" #include "QuantDefines.h" #include "QuantHash.h" #include "QuantHeap.h" #define NO_OUTPUT typedef struct { unsigned long scale; } PixelHashData; typedef struct _PixelList { struct _PixelList *next[3],*prev[3]; Pixel p; unsigned int flag:1; int count; } PixelList; typedef struct _BoxNode { struct _BoxNode *l,*r; PixelList *head[3],*tail[3]; int axis; int volume; unsigned long pixelCount; } BoxNode; #define _SQR(x) ((x)*(x)) #define _DISTSQR(p1,p2) \ _SQR((int)((p1)->c.r)-(int)((p2)->c.r))+ \ _SQR((int)((p1)->c.g)-(int)((p2)->c.g))+ \ _SQR((int)((p1)->c.b)-(int)((p2)->c.b)) #define MAX_HASH_ENTRIES 65536 #define PIXEL_HASH(r,g,b) \ (((unsigned int)(r) )*463 ^ \ ((unsigned int)(g)<< 8)*10069 ^ \ ((unsigned int)(b)<<16)*64997) #define PIXEL_UNSCALE(p,q,s) \ ((q)->c.r=(p)->c.r<<(s)), \ ((q)->c.g=(p)->c.g<<(s)), \ ((q)->c.b=(p)->c.b<<(s)) #define PIXEL_SCALE(p,q,s)\ ((q)->c.r=(p)->c.r>>(s)), \ ((q)->c.g=(p)->c.g>>(s)), \ ((q)->c.b=(p)->c.b>>(s)) static unsigned long unshifted_pixel_hash(const HashTable h, const void *p) { Pixel *pixel=(Pixel *)&p; unsigned long hash=PIXEL_HASH(pixel->c.r, pixel->c.g, pixel->c.b); return hash; } static int unshifted_pixel_cmp(const HashTable h, const void *a, const void *b) { Pixel *pixel1=(Pixel *)&a; Pixel *pixel2=(Pixel *)&b; if (pixel1->c.r==pixel2->c.r) { if (pixel1->c.g==pixel2->c.g) { if (pixel1->c.b==pixel2->c.b) { return 0; } else { return (int)(pixel1->c.b)-(int)(pixel2->c.b); } } else { return (int)(pixel1->c.g)-(int)(pixel2->c.g); } } else { return (int)(pixel1->c.r)-(int)(pixel2->c.r); } } static unsigned long pixel_hash(const HashTable h,const void *p) { PixelHashData *d=(PixelHashData *)hashtable_get_user_data(h); Pixel *pixel=(Pixel *)&p; unsigned long hash=PIXEL_HASH(pixel->c.r>>d->scale, pixel->c.g>>d->scale, pixel->c.b>>d->scale); return hash; } static int pixel_cmp(const HashTable h,const void *a,const void *b) { PixelHashData *d=(PixelHashData *)hashtable_get_user_data(h); Pixel *pixel1=(Pixel *)&a; Pixel *pixel2=(Pixel *)&b; unsigned long A,B; A=PIXEL_HASH(pixel1->c.r>>d->scale, pixel1->c.g>>d->scale, pixel1->c.b>>d->scale); B=PIXEL_HASH(pixel2->c.r>>d->scale, pixel2->c.g>>d->scale, pixel2->c.b>>d->scale); return (A==B)?0:((Ascale=0; timer=timer3=clock(); for (i=0;iMAX_HASH_ENTRIES) { d->scale++; #ifndef NO_OUTPUT printf ("rehashing - new scale: %d\n",(int)d->scale); #endif timer2=clock(); hashtable_rehash_compute(hash,rehash_collide); timer2=clock()-timer2; #ifndef NO_OUTPUT printf ("rehash took %f sec\n",timer2/(double)CLOCKS_PER_SEC); #endif timer+=timer2; } } #ifndef NO_OUTPUT printf ("inserts took %f sec\n",(clock()-timer)/(double)CLOCKS_PER_SEC); #endif #ifndef NO_OUTPUT printf ("total %f sec\n",(clock()-timer3)/(double)CLOCKS_PER_SEC); #endif return hash; } static void destroy_pixel_hash(HashTable hash) { PixelHashData *d=(PixelHashData *)hashtable_get_user_data(hash); if (d) free(d); hashtable_free(hash); } /* 1. hash quantized pixels. */ /* 2. create R,G,B lists of sorted quantized pixels. */ /* 3. median cut. */ /* 4. build hash table from median cut boxes. */ /* 5. for each pixel, compute entry in hash table, and hence median cut box. */ /* 6. compute median cut box pixel averages. */ /* 7. map each pixel to nearest average. */ static int compute_box_volume(BoxNode *b) { unsigned char rl,rh,gl,gh,bl,bh; if (b->volume>=0) return b->volume; if (!b->head[0]) { b->volume=0; } else { rh=b->head[0]->p.c.r; rl=b->tail[0]->p.c.r; gh=b->head[1]->p.c.g; gl=b->tail[1]->p.c.g; bh=b->head[2]->p.c.b; bl=b->tail[2]->p.c.b; b->volume=(rh-rl+1)*(gh-gl+1)*(bh-bl+1); } return b->volume; } static void hash_to_list(HashTable h, const void *key, const void *val, void *u) { PixelHashData *d=(PixelHashData *)hashtable_get_user_data(h); PixelList **pl=(PixelList **)u; PixelList *p; Pixel *pixel=(Pixel *)&key; int i; Pixel q; int count=*(int *)&val; PIXEL_SCALE(pixel,&q,d->scale); p=malloc(sizeof(PixelList)); if (!p) return; p->flag=0; p->p=q; p->count=count; for (i=0;i<3;i++) { p->next[i]=pl[i]; p->prev[i]=NULL; if (pl[i]) pl[i]->prev[i]=p; pl[i]=p; } } static PixelList * mergesort_pixels(PixelList *head, int i) { PixelList *c,*t,*a,*b,*p; if (!head||!head->next[i]) { if (head) { head->next[i]=NULL; head->prev[i]=NULL; } return head; } for (c=t=head;c&&t;c=c->next[i],t=(t->next[i])?t->next[i]->next[i]:NULL); if (c) { if (c->prev[i]) c->prev[i]->next[i]=NULL; c->prev[i]=NULL; } a=mergesort_pixels(head,i); b=mergesort_pixels(c,i); head=NULL; p=NULL; while (a&&b) { if (a->p.a.v[i]>b->p.a.v[i]) { c=a; a=a->next[i]; } else { c=b; b=b->next[i]; } c->prev[i]=p; c->next[i]=NULL; if (p) p->next[i]=c; p=c; if (!head) head=c; } if (a) { c->next[i]=a; a->prev[i]=c; } else if (b) { c->next[i]=b; b->prev[i]=c; } return head; } static int test_sorted(PixelList *pl[3]) { int i,n,l; PixelList *t; for(i=0;i<3;i++) { n=0; l=256; for (t=pl[i];t;t=t->next[i]) { if (lp.a.v[i]) return 0; l=t->p.a.v[i]; } } return 1; } static int box_heap_cmp(const Heap h, const void *A, const void *B) { BoxNode *a=(BoxNode *)A; BoxNode *b=(BoxNode *)B; return (int)a->pixelCount-(int)b->pixelCount; } #define LUMINANCE(p) (77*(p)->c.r+150*(p)->c.g+29*(p)->c.b) static int splitlists(PixelList *h[3], PixelList *t[3], PixelList *nh[2][3], PixelList *nt[2][3], unsigned long nCount[2], int axis, unsigned long pixelCount) { unsigned long left; PixelList *l,*r,*c,*n; int i; int nRight,nLeft; int splitColourVal; #ifdef TEST_SPLIT { PixelList *_prevTest,*_nextTest; int _i,_nextCount[3],_prevCount[3]; for (_i=0;_i<3;_i++) { for (_nextCount[_i]=0,_nextTest=h[_i];_nextTest&&_nextTest->next[_i];_nextTest=_nextTest->next[_i],_nextCount[_i]++); for (_prevCount[_i]=0,_prevTest=t[_i];_prevTest&&_prevTest->prev[_i];_prevTest=_prevTest->prev[_i],_prevCount[_i]++); if (_nextTest!=t[_i]) { printf ("next-list of axis %d does not end at tail\n",_i); exit(1); } if (_prevTest!=h[_i]) { printf ("prev-list of axis %d does not end at head\n",_i); exit(1); } for (;_nextTest&&_nextTest->prev[_i];_nextTest=_nextTest->prev[_i]); for (;_prevTest&&_prevTest->next[_i];_prevTest=_prevTest->next[_i]); if (_nextTest!=h[_i]) { printf ("next-list of axis %d does not loop back to head\n",_i); exit(1); } if (_prevTest!=t[_i]) { printf ("prev-list of axis %d does not loop back to tail\n",_i); exit(1); } } for (_i=1;_i<3;_i++) { if (_prevCount[_i]!=_prevCount[_i-1] || _nextCount[_i]!=_nextCount[_i-1] || _prevCount[_i]!=_nextCount[_i]) { printf ("{%d %d %d} {%d %d %d}\n", _prevCount[0], _prevCount[1], _prevCount[2], _nextCount[0], _nextCount[1], _nextCount[2]); exit(1); } } } #endif nCount[0]=nCount[1]=0; nLeft=nRight=0; for (left=0,c=h[axis];c;) { left=left+c->count; nCount[0]+=c->count; c->flag=0; nLeft++; c=c->next[axis]; if (left*2>pixelCount) { break; } } if (c) { splitColourVal=c->prev[axis]->p.a.v[axis]; for (;c;c=c->next[axis]) { if (splitColourVal!=c->p.a.v[axis]) { break; } c->flag=0; nLeft++; nCount[0]+=c->count; } } for (;c;c=c->next[axis]) { c->flag=1; nRight++; nCount[1]+=c->count; } if (!nRight) { for (c=t[axis],splitColourVal=t[axis]->p.a.v[axis];c;c=c->prev[axis]) { if (splitColourVal!=c->p.a.v[axis]) { break; } c->flag=1; nRight++; nLeft--; nCount[0]-=c->count; nCount[1]+=c->count; } } #ifndef NO_OUTPUT if (!nLeft) { for (c=h[axis];c;c=c->next[axis]) { printf ("[%d %d %d]\n",c->p.c.r,c->p.c.g,c->p.c.b); } printf ("warning... trivial split\n"); } #endif for (i=0;i<3;i++) { l=r=NULL; nh[0][i]=nt[0][i]=NULL; nh[1][i]=nt[1][i]=NULL; for (c=h[i];c;c=n) { n=c->next[i]; if (c->flag) { /* move pixel to right list*/ if (r) r->next[i]=c; else nh[1][i]=c; c->prev[i]=r; r=c; } else { /* move pixel to left list */ if (l) l->next[i]=c; else nh[0][i]=c; c->prev[i]=l; l=c; } } if (l) l->next[i]=NULL; if (r) r->next[i]=NULL; nt[0][i]=l; nt[1][i]=r; } return 1; } static int split(BoxNode *node) { unsigned char rl,rh,gl,gh,bl,bh; int f[3]; int best,axis; int i; PixelList *heads[2][3]; PixelList *tails[2][3]; unsigned long newCounts[2]; BoxNode *left,*right; rh=node->head[0]->p.c.r; rl=node->tail[0]->p.c.r; gh=node->head[1]->p.c.g; gl=node->tail[1]->p.c.g; bh=node->head[2]->p.c.b; bl=node->tail[2]->p.c.b; #ifdef TEST_SPLIT printf ("splitting node [%d %d %d] [%d %d %d] ",rl,gl,bl,rh,gh,bh); #endif f[0]=(rh-rl)*77; f[1]=(gh-gl)*150; f[2]=(bh-bl)*29; best=f[0]; axis=0; for (i=1;i<3;i++) { if (besttail[_i]->next[_i]) { printf ("tail is not tail\n"); printf ("node->tail[%d]->next[%d]=%p\n",_i,_i,node->tail[_i]->next[_i]); } if (node->head[_i]->prev[_i]) { printf ("head is not head\n"); printf ("node->head[%d]->prev[%d]=%p\n",_i,_i,node->head[_i]->prev[_i]); } } for (_i=0;_i<3;_i++) { for (_nextCount[_i]=0,_nextTest=node->head[_i];_nextTest&&_nextTest->next[_i];_nextTest=_nextTest->next[_i],_nextCount[_i]++); for (_prevCount[_i]=0,_prevTest=node->tail[_i];_prevTest&&_prevTest->prev[_i];_prevTest=_prevTest->prev[_i],_prevCount[_i]++); if (_nextTest!=node->tail[_i]) { printf ("next-list of axis %d does not end at tail\n",_i); } if (_prevTest!=node->head[_i]) { printf ("prev-list of axis %d does not end at head\n",_i); } for (;_nextTest&&_nextTest->prev[_i];_nextTest=_nextTest->prev[_i]); for (;_prevTest&&_prevTest->next[_i];_prevTest=_prevTest->next[_i]); if (_nextTest!=node->head[_i]) { printf ("next-list of axis %d does not loop back to head\n",_i); } if (_prevTest!=node->tail[_i]) { printf ("prev-list of axis %d does not loop back to tail\n",_i); } } for (_i=1;_i<3;_i++) { if (_prevCount[_i]!=_prevCount[_i-1] || _nextCount[_i]!=_nextCount[_i-1] || _prevCount[_i]!=_nextCount[_i]) { printf ("{%d %d %d} {%d %d %d}\n", _prevCount[0], _prevCount[1], _prevCount[2], _nextCount[0], _nextCount[1], _nextCount[2]); } } } #endif node->axis=axis; if (!splitlists(node->head, node->tail, heads, tails, newCounts, axis, node->pixelCount)) { #ifndef NO_OUTPUT printf ("list split failed.\n"); #endif return 0; } #ifdef TEST_SPLIT if (!test_sorted(heads[0])) { printf ("bug in split"); exit(1); } if (!test_sorted(heads[1])) { printf ("bug in split"); exit(1); } #endif left=malloc(sizeof(BoxNode)); right=malloc(sizeof(BoxNode)); if (!left||!right) { return 0; } for(i=0;i<3;i++) { left->head[i]=heads[0][i]; left->tail[i]=tails[0][i]; right->head[i]=heads[1][i]; right->tail[i]=tails[1][i]; node->head[i]=NULL; node->tail[i]=NULL; } #ifdef TEST_SPLIT if (left->head[0]) { rh=left->head[0]->p.c.r; rl=left->tail[0]->p.c.r; gh=left->head[1]->p.c.g; gl=left->tail[1]->p.c.g; bh=left->head[2]->p.c.b; bl=left->tail[2]->p.c.b; printf (" left node [%3d %3d %3d] [%3d %3d %3d]\n",rl,gl,bl,rh,gh,bh); } if (right->head[0]) { rh=right->head[0]->p.c.r; rl=right->tail[0]->p.c.r; gh=right->head[1]->p.c.g; gl=right->tail[1]->p.c.g; bh=right->head[2]->p.c.b; bl=right->tail[2]->p.c.b; printf (" right node [%3d %3d %3d] [%3d %3d %3d]\n",rl,gl,bl,rh,gh,bh); } #endif left->l=left->r=NULL; right->l=right->r=NULL; left->axis=right->axis=-1; left->volume=right->volume=-1; left->pixelCount=newCounts[0]; right->pixelCount=newCounts[1]; node->l=left; node->r=right; return 1; } static BoxNode * median_cut(PixelList *hl[3], unsigned long imPixelCount, int nPixels) { PixelList *tl[3]; int i; BoxNode *root; Heap h; BoxNode *thisNode; h=ImagingQuantHeapNew(box_heap_cmp); root=malloc(sizeof(BoxNode)); if (!root) { ImagingQuantHeapFree(h); return NULL; } for(i=0;i<3;i++) { for (tl[i]=hl[i];tl[i]&&tl[i]->next[i];tl[i]=tl[i]->next[i]); root->head[i]=hl[i]; root->tail[i]=tl[i]; } root->l=root->r=NULL; root->axis=-1; root->volume=-1; root->pixelCount=imPixelCount; ImagingQuantHeapAdd(h,(void *)root); while (--nPixels) { do { if (!ImagingQuantHeapRemove(h,(void **)&thisNode)) { goto done; } } while (compute_box_volume(thisNode)==1); if (!split(thisNode)) { #ifndef NO_OUTPUT printf ("Oops, split failed...\n"); #endif exit (1); } ImagingQuantHeapAdd(h,(void *)(thisNode->l)); ImagingQuantHeapAdd(h,(void *)(thisNode->r)); } ImagingQuantHeapFree(h); done: return root; } static void free_box_tree(BoxNode *n) { PixelList *p,*pp; if (n->l) free_box_tree(n->l); if (n->r) free_box_tree(n->r); for (p=n->head[0];p;p=pp) { pp=p->next[0]; free(p); } free(n); } static int checkContained(BoxNode *n,Pixel *pp) { if (n->l&&n->r) { return checkContained(n->l,pp)+checkContained(n->r,pp); } if (n->l||n->r) { #ifndef NO_OUTPUT printf ("box tree is dead\n"); #endif return 0; } if ( pp->c.r<=n->head[0]->p.c.r && pp->c.r>=n->tail[0]->p.c.r && pp->c.g<=n->head[1]->p.c.g && pp->c.g>=n->tail[1]->p.c.g && pp->c.b<=n->head[2]->p.c.b && pp->c.b>=n->tail[2]->p.c.b) { return 1; } return 0; } static int annotate_hash_table(BoxNode *n,HashTable h,unsigned long *box) { PixelList *p; PixelHashData *d=(PixelHashData *)hashtable_get_user_data(h); Pixel q; if (n->l&&n->r) { return annotate_hash_table(n->l,h,box) && annotate_hash_table(n->r,h,box); } if (n->l||n->r) { #ifndef NO_OUTPUT printf ("box tree is dead\n"); #endif return 0; } for (p=n->head[0];p;p=p->next[0]) { PIXEL_UNSCALE(&(p->p),&q,d->scale); if (!hashtable_insert(h,(void *)q.v,(void *)*box)) { #ifndef NO_OUTPUT printf ("hashtable insert failed\n"); #endif return 0; } } if (n->head[0]) (*box)++; return 1; } static int _sort_ulong_ptr_keys(const void *a, const void *b) { unsigned long A=**(unsigned long **)a; unsigned long B=**(unsigned long **)b; return (A==B)?0:((A*(skRow[k]));k--) { skRow[k]=skRow[k-1]; } if (k!=j) skRow[k]=skElt; } } return 1; } static int build_distance_tables(unsigned long *avgDist, unsigned long **avgDistSortKey, Pixel *p, unsigned long nEntries) { unsigned long i,j; for (i=0;i1) { printf ("pixel in two boxes\n"); for(i=0;i<3;i++) free (avg[i]); free(count); return 0; } #endif if (!hashtable_lookup(medianBoxHash,(void *)pixelData[i].v,(void **)&paletteEntry)) { #ifndef NO_OUTPUT printf ("pixel lookup failed\n"); #endif for(i=0;i<3;i++) free (avg[i]); free(count); return 0; } if (paletteEntry>=nPaletteEntries) { #ifndef NO_OUTPUT printf ("panic - paletteEntry>=nPaletteEntries (%d>=%d)\n",(int)paletteEntry,(int)nPaletteEntries); #endif for(i=0;i<3;i++) free (avg[i]); free(count); return 0; } avg[0][paletteEntry]+=pixelData[i].c.r; avg[1][paletteEntry]+=pixelData[i].c.g; avg[2][paletteEntry]+=pixelData[i].c.b; count[paletteEntry]++; } p=malloc(sizeof(Pixel)*nPaletteEntries); if (!p) { for(i=0;i<3;i++) free (avg[i]); free(count); return 0; } for (i=0;i=nPaletteEntries) { #ifndef NO_OUTPUT printf ("scream\n"); #endif return 0; } avg[0][qp[i]]+=pixelData[i].c.r; avg[1][qp[i]]+=pixelData[i].c.g; avg[2][qp[i]]+=pixelData[i].c.b; count[qp[i]]++; } for (i=0;i { unsigned long bestmatch,bestdist,dist; HashTable h2; printf ("nearest neighbour search (full search)..."); fflush(stdout); timer=clock(); h2=hashtable_new(unshifted_pixel_hash,unshifted_pixel_cmp); for (i=0;inew),pixel); if (data->secondPixel || newDistdata->furthestDistance) { data->furthestDistance=oldDist; data->furthest.v=pixel->v; } } int quantize2(Pixel *pixelData, unsigned long nPixels, unsigned long nQuantPixels, Pixel **palette, unsigned long *paletteLength, unsigned long **quantizedPixels, int kmeans) { HashTable h; unsigned long i; unsigned long mean[3]; Pixel *p; DistanceData data; unsigned long *qp; unsigned long *avgDist; unsigned long **avgDistSortKey; p=malloc(sizeof(Pixel)*nQuantPixels); if (!p) return 0; mean[0]=mean[1]=mean[2]=0; h=hashtable_new(unshifted_pixel_hash,unshifted_pixel_cmp); for (i=0;imode, "L") != 0 && strcmp(im->mode, "P") != 0 && strcmp(im->mode, "RGB")) return ImagingError_ModeError(); p = malloc(sizeof(Pixel) * im->xsize * im->ysize); if (!p) return ImagingError_MemoryError(); /* collect statistics */ /* FIXME: maybe we could load the hash tables directly from the image data? */ if (!strcmp(im->mode, "L")) { /* greyscale */ /* FIXME: converting a "L" image to "P" with 256 colours should be done by a simple copy... */ for (i = y = 0; y < im->ysize; y++) for (x = 0; x < im->xsize; x++, i++) p[i].c.r = p[i].c.g = p[i].c.b = im->image8[y][x]; } else if (!strcmp(im->mode, "P")) { /* palette */ pp = im->palette->palette; for (i = y = 0; y < im->ysize; y++) for (x = 0; x < im->xsize; x++, i++) { v = im->image8[y][x]; p[i].c.r = pp[v*4+0]; p[i].c.g = pp[v*4+1]; p[i].c.b = pp[v*4+2]; } } else if (!strcmp(im->mode, "RGB")) { /* true colour */ for (i = y = 0; y < im->ysize; y++) for (x = 0; x < im->xsize; x++, i++) p[i].v = im->image32[y][x]; } else { free(p); return (Imaging) ImagingError_ValueError("internal error"); } switch (mode) { case 0: /* median cut */ result = quantize( p, im->xsize*im->ysize, colours, &palette, &paletteLength, &newData, kmeans ); break; case 1: /* maximum coverage */ result = quantize2( p, im->xsize*im->ysize, colours, &palette, &paletteLength, &newData, kmeans ); break; default: result = 0; break; } free(p); if (result) { imOut = ImagingNew("P", im->xsize, im->ysize); for (i = y = 0; y < im->ysize; y++) for (x=0; x < im->xsize; x++) imOut->image8[y][x] = (unsigned char) newData[i++]; free(newData); pp = imOut->palette->palette; for (i = j = 0; i < (int) paletteLength; i++) { *pp++ = palette[i].c.r; *pp++ = palette[i].c.g; *pp++ = palette[i].c.b; *pp++ = 255; } for (; i < 256; i++) { *pp++ = 0; *pp++ = 0; *pp++ = 0; *pp++ = 255; } free(palette); return imOut; } else { free(p); return (Imaging) ImagingError_ValueError("quantization error"); } } Imaging-1.1.3/libImaging/QuantHash.c0100444000076400007640000002724507442710204017050 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/QuantHash.c#2 $ * * hash tables used by the image quantizer * * history: * 98-09-10 tjs Contributed * 98-12-29 fl Added to PIL 1.0b1 * * Written by Toby J Sargeant . * * Copyright (c) 1998 by Toby J Sargeant * Copyright (c) 1998 by Secret Labs AB * * See the README file for information on usage and redistribution. */ #include #include #include #include #include "QuantHash.h" #include "QuantDefines.h" typedef struct _IntHashNode { struct _IntHashNode *next; void *key,*value; } IntHashNode; typedef struct _IntHashTable { IntHashNode **table; unsigned long length; unsigned long count; HashFunc hashFunc; HashCmpFunc cmpFunc; DestroyFunc keyDestroyFunc; DestroyFunc valDestroyFunc; void *userData; } IntHashTable; #define MIN_LENGTH 11 #define RESIZE_FACTOR 3 static int _hashtable_insert_node(IntHashTable *,IntHashNode *,int,int,CollisionFunc); static int _hashtable_test(IntHashTable *); HashTable hashtable_new(HashFunc hf,HashCmpFunc cf) { IntHashTable *h; h=malloc(sizeof(IntHashTable)); if (!h) { return NULL; } h->hashFunc=hf; h->cmpFunc=cf; h->keyDestroyFunc=NULL; h->valDestroyFunc=NULL; h->length=MIN_LENGTH; h->count=0; h->userData=NULL; h->table=malloc(sizeof(IntHashNode *)*h->length); if (!h->table) { free(h); return NULL; } memset (h->table,0,sizeof(IntHashNode *)*h->length); return (HashTable)h; } static void _hashtable_destroy(HashTable H,const void *key,const void *val,void *u) { IntHashTable *h=(IntHashTable *)H; if (h->keyDestroyFunc&&key) { h->keyDestroyFunc((HashTable)h,(void *)key); } if (h->valDestroyFunc&&val) { h->valDestroyFunc((HashTable)h,(void *)val); } } static unsigned long _findPrime(unsigned long start,int dir) { static int unit[]={0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0}; unsigned long t; while (start>1) { if (!unit[start&0x0f]) { start+=dir; continue; } for (t=2;t=sqrt((double)start)) { break; } start+=dir; } return start; } static void _hashtable_rehash(IntHashTable *h, CollisionFunc cf, unsigned long newSize) { IntHashNode **oldTable=h->table; unsigned long i; IntHashNode *n,*nn; unsigned long oldSize; oldSize=h->length; h->table=malloc(sizeof(IntHashNode *)*newSize); if (!h->table) { h->table=oldTable; return; } h->length=newSize; h->count=0; memset (h->table,0,sizeof(IntHashNode *)*h->length); for (i=0;inext; _hashtable_insert_node(h,n,0,0,cf); } } free(oldTable); } static void _hashtable_resize(IntHashTable *h) { unsigned long newSize; unsigned long oldSize; oldSize=h->length; newSize=oldSize; if (h->count*RESIZE_FACTORlength) { newSize=_findPrime(h->length/2-1,-1); } else if (h->length*RESIZE_FACTORcount) { newSize=_findPrime(h->length*2+1,+1); } if (newSizelength;i++) { for (n=h->table[i];n&&n->next;n=n->next) { j=h->cmpFunc((HashTable)h,n->key,n->next->key); printf ("%c",j?(j<0?'-':'+'):'='); } printf ("\n"); } return 0; } static int _hashtable_insert_node(IntHashTable *h,IntHashNode *node,int resize,int update,CollisionFunc cf) { unsigned long hash=h->hashFunc((HashTable)h,node->key)%h->length; IntHashNode **n,*nv; int i; for (n=&(h->table[hash]);*n;n=&((*n)->next)) { nv=*n; i=h->cmpFunc((HashTable)h,nv->key,node->key); if (!i) { if (cf) { nv->key=node->key; cf((HashTable)h,&(nv->key),&(nv->value),node->key,node->value); free(node); return 1; } else { if (h->valDestroyFunc) { h->valDestroyFunc((HashTable)h,nv->value); } if (h->keyDestroyFunc) { h->keyDestroyFunc((HashTable)h,nv->key); } nv->key=node->key; nv->value=node->value; free(node); return 1; } } else if (i>0) { break; } } if (!update) { node->next=*n; *n=node; h->count++; if (resize) _hashtable_resize(h); return 1; } else { return 0; } } static int _hashtable_insert(IntHashTable *h,void *key,void *val,int resize,int update) { IntHashNode **n,*nv; IntHashNode *t; int i; unsigned long hash=h->hashFunc((HashTable)h,key)%h->length; for (n=&(h->table[hash]);*n;n=&((*n)->next)) { nv=*n; i=h->cmpFunc((HashTable)h,nv->key,key); if (!i) { if (h->valDestroyFunc) { h->valDestroyFunc((HashTable)h,nv->value); } nv->value=val; return 1; } else if (i>0) { break; } } if (!update) { t=malloc(sizeof(IntHashNode)); if (!t) return 0; t->next=*n; *n=t; t->key=key; t->value=val; h->count++; if (resize) _hashtable_resize(h); return 1; } else { return 0; } } static int _hashtable_lookup_or_insert(IntHashTable *h,void *key,void **retVal,void *newVal,int resize) { IntHashNode **n,*nv; IntHashNode *t; int i; unsigned long hash=h->hashFunc((HashTable)h,key)%h->length; for (n=&(h->table[hash]);*n;n=&((*n)->next)) { nv=*n; i=h->cmpFunc((HashTable)h,nv->key,key); if (!i) { *retVal=nv->value; return 1; } else if (i>0) { break; } } t=malloc(sizeof(IntHashNode)); if (!t) return 0; t->next=*n; *n=t; t->key=key; t->value=newVal; *retVal=newVal; h->count++; if (resize) _hashtable_resize(h); return 1; } int hashtable_insert_or_update_computed(HashTable H, void *key, ComputeFunc newFunc, ComputeFunc existsFunc) { IntHashTable *h=(IntHashTable *)H; IntHashNode **n,*nv; IntHashNode *t; int i; unsigned long hash=h->hashFunc((HashTable)h,key)%h->length; for (n=&(h->table[hash]);*n;n=&((*n)->next)) { nv=*n; i=h->cmpFunc((HashTable)h,nv->key,key); if (!i) { void *old=nv->value; if (existsFunc) { existsFunc(H,nv->key,&(nv->value)); if (nv->value!=old) { if (h->valDestroyFunc) { h->valDestroyFunc((HashTable)h,old); } } } else { return 0; } return 1; } else if (i>0) { break; } } t=malloc(sizeof(IntHashNode)); if (!t) return 0; t->key=key; t->next=*n; *n=t; if (newFunc) { newFunc(H,t->key,&(t->value)); } else { free(t); return 0; } h->count++; _hashtable_resize(h); return 1; } int hashtable_update(HashTable H,void *key,void *val) { IntHashTable *h=(IntHashTable *)H; return _hashtable_insert(h,key,val,1,0); } int hashtable_insert(HashTable H,void *key,void *val) { IntHashTable *h=(IntHashTable *)H; return _hashtable_insert(h,key,val,1,0); } void hashtable_foreach_update(HashTable H,IteratorUpdateFunc i,void *u) { IntHashTable *h=(IntHashTable *)H; IntHashNode *n; unsigned long x; if (h->table) { for (x=0;xlength;x++) { for (n=h->table[x];n;n=n->next) { i((HashTable)h,n->key,(void **)&(n->value),u); } } } } void hashtable_foreach(HashTable H,IteratorFunc i,void *u) { IntHashTable *h=(IntHashTable *)H; IntHashNode *n; unsigned long x; if (h->table) { for (x=0;xlength;x++) { for (n=h->table[x];n;n=n->next) { i((HashTable)h,n->key,n->value,u); } } } } void hashtable_free(HashTable H) { IntHashTable *h=(IntHashTable *)H; IntHashNode *n,*nn; unsigned long i; if (h->table) { if (h->keyDestroyFunc || h->keyDestroyFunc) { hashtable_foreach(H,_hashtable_destroy,NULL); } for (i=0;ilength;i++) { for (n=h->table[i];n;n=nn) { nn=n->next; free(n); } } free(h->table); } free(h); } DestroyFunc hashtable_set_value_destroy_func(HashTable H,DestroyFunc d) { IntHashTable *h=(IntHashTable *)H; DestroyFunc r=h->valDestroyFunc; h->valDestroyFunc=d; return r; } DestroyFunc hashtable_set_key_destroy_func(HashTable H,DestroyFunc d) { IntHashTable *h=(IntHashTable *)H; DestroyFunc r=h->keyDestroyFunc; h->keyDestroyFunc=d; return r; } static int _hashtable_remove(IntHashTable *h, const void *key, void **keyRet, void **valRet, int resize) { unsigned long hash=h->hashFunc((HashTable)h,key)%h->length; IntHashNode *n,*p; int i; for (p=NULL,n=h->table[hash];n;p=n,n=n->next) { i=h->cmpFunc((HashTable)h,n->key,key); if (!i) { if (p) p=n->next; else h->table[hash]=n->next; *keyRet=n->key; *valRet=n->value; free(n); h->count++; return 1; } else if (i>0) { break; } } return 0; } static int _hashtable_delete(IntHashTable *h,const void *key,int resize) { unsigned long hash=h->hashFunc((HashTable)h,key)%h->length; IntHashNode *n,*p; int i; for (p=NULL,n=h->table[hash];n;p=n,n=n->next) { i=h->cmpFunc((HashTable)h,n->key,key); if (!i) { if (p) p=n->next; else h->table[hash]=n->next; if (h->valDestroyFunc) { h->valDestroyFunc((HashTable)h,n->value); } if (h->keyDestroyFunc) { h->keyDestroyFunc((HashTable)h,n->key); } free(n); h->count++; return 1; } else if (i>0) { break; } } return 0; } int hashtable_remove(HashTable H,const void *key,void **keyRet,void **valRet) { IntHashTable *h=(IntHashTable *)H; return _hashtable_remove(h,key,keyRet,valRet,1); } int hashtable_delete(HashTable H,const void *key) { IntHashTable *h=(IntHashTable *)H; return _hashtable_delete(h,key,1); } void hashtable_rehash_compute(HashTable H,CollisionFunc cf) { IntHashTable *h=(IntHashTable *)H; _hashtable_rehash(h,cf,h->length); } void hashtable_rehash(HashTable H) { IntHashTable *h=(IntHashTable *)H; _hashtable_rehash(h,NULL,h->length); } int hashtable_lookup_or_insert(HashTable H,void *key,void **valp,void *val) { IntHashTable *h=(IntHashTable *)H; return _hashtable_lookup_or_insert(h,key,valp,val,1); } int hashtable_lookup(const HashTable H,const void *key,void **valp) { IntHashTable *h=(IntHashTable *)H; unsigned long hash=h->hashFunc((HashTable)h,key)%h->length; IntHashNode *n; int i; for (n=h->table[hash];n;n=n->next) { i=h->cmpFunc((HashTable)h,n->key,key); if (!i) { *valp=n->value; return 1; } else if (i>0) { break; } } return 0; } unsigned long hashtable_get_count(const HashTable H) { IntHashTable *h=(IntHashTable *)H; return h->count; } void *hashtable_get_user_data(const HashTable H) { IntHashTable *h=(IntHashTable *)H; return h->userData; } void *hashtable_set_user_data(HashTable H,void *data) { IntHashTable *h=(IntHashTable *)H; void *r=h->userData; h->userData=data; return r; } Imaging-1.1.3/libImaging/QuantHeap.c0100444000076400007640000000577407442710204017045 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/QuantHeap.c#3 $ * * heap data type used by the image quantizer * * history: * 98-09-10 tjs Contributed * 98-12-29 fl Added to PIL 1.0b1 * * Written by Toby J Sargeant . * * Copyright (c) 1998 by Toby J Sargeant * Copyright (c) 1998 by Secret Labs AB * * See the README file for information on usage and redistribution. */ #include #include #include #include #include "QuantHash.h" #include "QuantDefines.h" typedef struct { void **heap; int heapsize; int heapcount; HeapCmpFunc cf; } IntHeap; #define INITIAL_SIZE 256 #define DEBUG #ifdef DEBUG static int _heap_test(Heap); #endif void ImagingQuantHeapFree(Heap H) { IntHeap *h=(IntHeap *)H; free(h->heap); free(h); } static int _heap_grow(IntHeap *h,int newsize) { void *newheap; if (!newsize) newsize=h->heapsize<<1; if (newsizeheapsize) return 0; newheap=malloc(sizeof(void *)*newsize); if (!newheap) return 0; memcpy(newheap,h->heap,sizeof(void *)*h->heapsize); free(h->heap); h->heap=newheap; h->heapsize=newsize; return 1; } #ifdef DEBUG static int _heap_test(Heap H) { IntHeap *h=(IntHeap *)H; int k; for (k=1;k*2<=h->heapcount;k++) { if (h->cf(H,h->heap[k],h->heap[k*2])<0) { printf ("heap is bad\n"); return 0; } if (k*2+1<=h->heapcount && h->cf(H,h->heap[k],h->heap[k*2+1])<0) { printf ("heap is bad\n"); return 0; } } return 1; } #endif int ImagingQuantHeapRemove(Heap H,void **r) { IntHeap *h=(IntHeap *)H; int k,l; void *v; if (!h->heapcount) { return 0; } *r=h->heap[1]; v=h->heap[h->heapcount--]; for (k=1;k*2<=h->heapcount;k=l) { l=k*2; if (lheapcount) { if (h->cf(H,h->heap[l],h->heap[l+1])<0) { l++; } } if (h->cf(H,v,h->heap[l])>0) { break; } h->heap[k]=h->heap[l]; } h->heap[k]=v; #ifdef DEBUG if (!_heap_test(H)) { printf ("oops - heap_remove messed up the heap\n"); exit(1); } #endif return 1; } int ImagingQuantHeapAdd(Heap H,void *val) { IntHeap *h=(IntHeap *)H; int k; if (h->heapcount==h->heapsize-1) { _heap_grow(h,0); } k=++h->heapcount; while (k!=1) { if (h->cf(H,val,h->heap[k/2])<=0) { break; } h->heap[k]=h->heap[k/2]; k>>=1; } h->heap[k]=val; #ifdef DEBUG if (!_heap_test(H)) { printf ("oops - heap_add messed up the heap\n"); exit(1); } #endif return 1; } int ImagingQuantHeapTop(Heap H,void **r) { IntHeap *h=(IntHeap *)H; if (!h->heapcount) { return 0; } *r=h->heap[1]; return 1; } Heap *ImagingQuantHeapNew(HeapCmpFunc cf) { IntHeap *h; h=malloc(sizeof(IntHeap)); if (!h) return NULL; h->heapsize=INITIAL_SIZE; h->heap=malloc(sizeof(void *)*h->heapsize); if (!h->heap) { free(h); return NULL; } h->heapcount=0; h->cf=cf; return (Heap)h; } Imaging-1.1.3/libImaging/Storage.c0100444000076400007640000002074307442710204016554 0ustar fredrikfredrik/* * The Python Imaging Library * $Id: //modules/pil/libImaging/Storage.c#2 $ * * imaging storage object * * This baseline implementation is designed to efficiently handle * large images, provided they fit into the available memory. * * history: * 95-06-15 fl Created * 95-09-12 fl Updated API, compiles silently under ANSI C++ * 95-11-26 fl Compiles silently under Borland 4.5 as well * 96-05-05 fl Correctly test status from Prologue * 97-05-12 fl Increased THRESHOLD (to speed up Tk interface) * 97-05-30 fl Added support for floating point images * 97-11-17 fl Added support for "RGBX" images * 98-01-11 fl Added support for integer images * 98-03-05 fl Exported Prologue/Epilogue functions * 98-07-01 fl Added basic "YCrCb" support * 98-07-03 fl Attach palette in prologue for "P" images * 98-07-09 hk Don't report MemoryError on zero-size images * 98-07-12 fl Change "YCrCb" to "YCbCr" (!) * 98-10-26 fl Added "I;16" and "I;16B" storage modes (experimental) * 98-12-29 fl Fixed allocation bug caused by previous fix * 99-02-03 fl Added "RGBa" and "BGR" modes (experimental) * * Copyright (c) Secret Labs AB 1998-99. * Copyright (c) Fredrik Lundh 1995-97. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" /* -------------------------------------------------------------------- * Standard image object. */ Imaging ImagingNewPrologue(const char *mode, unsigned xsize, unsigned ysize) { Imaging im; im = (Imaging) calloc(1, sizeof(struct ImagingMemoryInstance)); if (!im) return (Imaging) ImagingError_MemoryError(); /* Setup image descriptor */ im->xsize = xsize; im->ysize = ysize; im->type = IMAGING_TYPE_UINT8; if (strcmp(mode, "1") == 0) { /* 1-bit images */ im->bands = im->pixelsize = 1; im->linesize = xsize; } else if (strcmp(mode, "P") == 0) { /* 8-bit palette mapped images */ im->bands = im->pixelsize = 1; im->linesize = xsize; im->palette = ImagingPaletteNew("RGB"); } else if (strcmp(mode, "L") == 0) { /* 8-bit greyscale (luminance) images */ im->bands = im->pixelsize = 1; im->linesize = xsize; } else if (strcmp(mode, "F") == 0) { /* 32-bit floating point images */ im->bands = 1; im->pixelsize = 4; im->linesize = xsize * 4; im->type = IMAGING_TYPE_FLOAT32; } else if (strcmp(mode, "I") == 0) { /* 32-bit integer images */ im->bands = 1; im->pixelsize = 4; im->linesize = xsize * 4; im->type = IMAGING_TYPE_INT32; } else if (strcmp(mode, "I;16") == 0 || strcmp(mode, "I;16B") == 0) { /* EXPERIMENTAL */ /* 16-bit raw integer images */ im->bands = 1; im->pixelsize = 2; im->linesize = xsize * 2; im->type = IMAGING_TYPE_SPECIAL; } else if (strcmp(mode, "RGB") == 0) { /* 24-bit true colour images */ im->bands = 3; im->pixelsize = 4; im->linesize = xsize * 4; } else if (strcmp(mode, "BGR;15") == 0) { /* EXPERIMENTAL */ /* 15-bit true colour */ im->bands = 1; im->pixelsize = 2; im->linesize = (xsize*2 + 3) & -4; im->type = IMAGING_TYPE_SPECIAL; } else if (strcmp(mode, "BGR;16") == 0) { /* EXPERIMENTAL */ /* 16-bit reversed true colour */ im->bands = 1; im->pixelsize = 2; im->linesize = (xsize*2 + 3) & -4; im->type = IMAGING_TYPE_SPECIAL; } else if (strcmp(mode, "BGR;24") == 0) { /* EXPERIMENTAL */ /* 24-bit reversed true colour */ im->bands = 1; im->pixelsize = 3; im->linesize = (xsize*3 + 3) & -4; im->type = IMAGING_TYPE_SPECIAL; } else if (strcmp(mode, "RGBX") == 0) { /* 32-bit true colour images with padding */ im->bands = im->pixelsize = 4; im->linesize = xsize * 4; } else if (strcmp(mode, "RGBA") == 0) { /* 32-bit true colour images with alpha */ im->bands = im->pixelsize = 4; im->linesize = xsize * 4; } else if (strcmp(mode, "RGBa") == 0) { /* EXPERIMENTAL */ /* 32-bit true colour images with premultiplied alpha */ im->bands = im->pixelsize = 4; im->linesize = xsize * 4; } else if (strcmp(mode, "CMYK") == 0) { /* 32-bit colour separation */ im->bands = im->pixelsize = 4; im->linesize = xsize * 4; } else if (strcmp(mode, "YCbCr") == 0) { /* 24-bit video format */ im->bands = 3; im->pixelsize = 4; im->linesize = xsize * 4; } else { free(im); return (Imaging) ImagingError_ValueError("unrecognized mode"); } /* Setup image descriptor */ strcpy(im->mode, mode); /* Pointer array (allocate at least one line, to avoid MemoryError exceptions on platforms where calloc(0, x) returns NULL) */ im->image = (char **) calloc((ysize > 0) ? ysize : 1, sizeof(void *)); if (!im->image) { free(im); return (Imaging) ImagingError_MemoryError(); } return im; } Imaging ImagingNewEpilogue(Imaging im) { /* If the raster data allocator didn't setup a destructor, assume that it couldn't allocate the required amount of memory. */ if (!im->destroy) return (Imaging) ImagingError_MemoryError(); /* Initialize alias pointers to pixel data. */ switch (im->pixelsize) { case 1: case 2: case 3: im->image8 = (UINT8 **) im->image; break; case 4: im->image32 = (INT32 **) im->image; break; } return im; } void ImagingDelete(Imaging im) { if (!im) return; if (im->palette) ImagingPaletteDelete(im->palette); if (im->destroy) im->destroy(im); if (im->image) free(im->image); free(im); } /* Array Storage Type */ /* ------------------ */ /* Allocate image as an array of line buffers. */ static void ImagingDestroyArray(Imaging im) { int y; if (im->image) for (y = 0; y < im->ysize; y++) if (im->image[y]) free(im->image[y]); } Imaging ImagingNewArray(const char *mode, int xsize, int ysize) { Imaging im; int y; char* p; im = ImagingNewPrologue(mode, xsize, ysize); if (!im) return NULL; /* Allocate image as an array of lines */ for (y = 0; y < im->ysize; y++) { p = (char *) malloc(im->linesize); if (!p) { ImagingDestroyArray(im); break; } im->image[y] = p; } if (y == im->ysize) im->destroy = ImagingDestroyArray; return ImagingNewEpilogue(im); } /* Block Storage Type */ /* ------------------ */ /* Allocate image as a single block. */ static void ImagingDestroyBlock(Imaging im) { if (im->block) free(im->block); } Imaging ImagingNewBlock(const char *mode, int xsize, int ysize) { Imaging im; int y, i; int bytes; im = ImagingNewPrologue(mode, xsize, ysize); if (!im) return NULL; /* Use a single block */ bytes = im->ysize * im->linesize; if (bytes <= 0) /* some platforms return NULL for malloc(0); this fix prevents MemoryError on zero-sized images on such platforms */ bytes = 1; im->block = (char *) malloc(bytes); if (im->block) { for (y = i = 0; y < im->ysize; y++) { im->image[y] = im->block + i; i += im->linesize; } im->destroy = ImagingDestroyBlock; } return ImagingNewEpilogue(im); } /* -------------------------------------------------------------------- * Create a new, internally allocated, image. */ #if defined(IMAGING_SMALL_MODEL) #define THRESHOLD 16384L #else #define THRESHOLD 1048576L #endif Imaging ImagingNew(const char* mode, int xsize, int ysize) { /* FIXME: strlen(mode) is no longer accurate */ if ((long) xsize * ysize * strlen(mode) <= THRESHOLD) return ImagingNewBlock(mode, xsize, ysize); else return ImagingNewArray(mode, xsize, ysize); } Imaging ImagingNew2(const char* mode, Imaging imOut, Imaging imIn) { /* allocate or validate output image */ if (imOut) { /* make sure images match */ if (strcmp(imOut->mode, mode) != 0 || imOut->xsize != imIn->xsize || imOut->ysize != imIn->ysize) { ImagingError_Mismatch(); return NULL; } } else { /* create new image */ imOut = ImagingNew(mode, imIn->xsize, imIn->ysize); if (!imOut) return NULL; } return imOut; } void ImagingCopyInfo(Imaging destination, Imaging source) { if (source->palette) destination->palette = ImagingPaletteDuplicate(source->palette); } Imaging-1.1.3/libImaging/Unpack.c0100444000076400007640000005064407442710204016374 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/Unpack.c#2 $ * * code to unpack raw data from various file formats * * history: * 96-03-07 fl Created (from various decoders) * 96-04-19 fl Added band unpackers * 96-05-12 fl Published RGB unpackers * 96-05-27 fl Added nibble unpacker * 96-12-10 fl Added complete set of PNG unpackers * 96-12-29 fl Set alpha byte in RGB unpackers * 97-01-05 fl Added remaining TGA unpackers * 97-01-18 fl Added inverting band unpackers * 97-01-25 fl Added FlashPix unpackers * 97-05-31 fl Added floating point unpackers * 98-02-08 fl Added I unpacker * 98-07-01 fl Added YCbCr unpacker * 98-07-02 fl Added full set of integer unpackers * 98-12-29 fl Added mode field, I;16 unpackers * 98-12-30 fl Added RGBX modes * 99-02-04 fl Fixed I;16 unpackers * * Copyright (c) Secret Labs AB 1997-99. * Copyright (c) Fredrik Lundh 1996-97. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #define R 0 #define G 1 #define B 2 #define X 3 #define A 3 #define C 0 #define M 1 #define Y 2 #define K 3 /* byte-swapping macros */ #define C16N\ (tmp[0]=in[0], tmp[1]=in[1]); #define C16S\ (tmp[1]=in[0], tmp[0]=in[1]); #define C32N\ (tmp[0]=in[0], tmp[1]=in[1], tmp[2]=in[2], tmp[3]=in[3]); #define C32S\ (tmp[3]=in[0], tmp[2]=in[1], tmp[1]=in[2], tmp[0]=in[3]); #define C64N\ (tmp[0]=in[0], tmp[1]=in[1], tmp[2]=in[2], tmp[3]=in[3],\ tmp[4]=in[4], tmp[5]=in[5], tmp[6]=in[6], tmp[7]=in[7]); #define C64S\ (tmp[7]=in[0], tmp[6]=in[1], tmp[5]=in[2], tmp[4]=in[3],\ tmp[3]=in[4], tmp[2]=in[5], tmp[1]=in[6], tmp[0]=in[7]); #ifdef WORDS_BIGENDIAN #define C16B C16N #define C16L C16S #define C32B C32N #define C32L C32S #define C64B C64N #define C64L C64S #else #define C16B C16S #define C16L C16N #define C32B C32S #define C32L C32N #define C64B C64S #define C64L C64N #endif /* Unpack to "1" image */ static void unpack1(UINT8* out, const UINT8* in, int pixels) { /* bits (msb first, white is non-zero) */ while (pixels > 0) { UINT8 byte = *in++; switch (pixels) { default: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; case 7: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; case 6: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; case 5: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; case 4: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; case 3: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; case 2: *out++ = (byte & 128) ? 255 : 0; byte <<= 1; case 1: *out++ = (byte & 128) ? 255 : 0; } pixels -= 8; } } static void unpack1I(UINT8* out, const UINT8* in, int pixels) { /* bits (msb first, white is zero) */ while (pixels > 0) { UINT8 byte = *in++; switch (pixels) { default: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; case 7: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; case 6: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; case 5: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; case 4: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; case 3: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; case 2: *out++ = (byte & 128) ? 0 : 255; byte <<= 1; case 1: *out++ = (byte & 128) ? 0 : 255; } pixels -= 8; } } static void unpack1R(UINT8* out, const UINT8* in, int pixels) { /* bits (lsb first, white is non-zero) */ while (pixels > 0) { UINT8 byte = *in++; switch (pixels) { default: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; case 7: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; case 6: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; case 5: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; case 4: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; case 3: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; case 2: *out++ = (byte & 1) ? 255 : 0; byte >>= 1; case 1: *out++ = (byte & 1) ? 255 : 0; } pixels -= 8; } } static void unpack1IR(UINT8* out, const UINT8* in, int pixels) { /* bits (lsb first, white is zero) */ while (pixels > 0) { UINT8 byte = *in++; switch (pixels) { default: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; case 7: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; case 6: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; case 5: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; case 4: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; case 3: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; case 2: *out++ = (byte & 1) ? 0 : 255; byte >>= 1; case 1: *out++ = (byte & 1) ? 0 : 255; } pixels -= 8; } } /* Unpack to "L" image */ static void unpackL2(UINT8* out, const UINT8* in, int pixels) { /* nibbles */ while (pixels > 0) { UINT8 byte = *in++; switch (pixels) { default: *out++ = ((byte >> 6) & 3) * 255 / 3; byte <<= 2; case 3: *out++ = ((byte >> 6) & 3) * 255 / 3; byte <<= 2; case 2: *out++ = ((byte >> 6) & 3) * 255 / 3; byte <<= 2; case 1: *out++ = ((byte >> 6) & 3) * 255 / 3; } pixels -= 4; } } static void unpackL4(UINT8* out, const UINT8* in, int pixels) { /* nibbles */ while (pixels > 0) { UINT8 byte = *in++; switch (pixels) { default: *out++ = ((byte >> 4) & 15) * 255 / 15; byte <<= 4; case 1: *out++ = ((byte >> 4) & 15) * 255 / 15; } pixels -= 2; } } static void unpackLI(UINT8* out, const UINT8* in, int pixels) { /* negative */ int i; for (i = 0; i < pixels; i++) out[i] = ~in[i]; } static void unpackL16(UINT8* out, const UINT8* in, int pixels) { /* int16 (upper byte, little endian) */ int i; for (i = 0; i < pixels; i++) { out[i] = in[1]; in += 2; } } static void unpackL16B(UINT8* out, const UINT8* in, int pixels) { int i; /* int16 (upper byte, big endian) */ for (i = 0; i < pixels; i++) { out[i] = in[0]; in += 2; } } /* Unpack to "P" image */ static void unpackP1(UINT8* out, const UINT8* in, int pixels) { /* bits */ while (pixels > 0) { UINT8 byte = *in++; switch (pixels) { default: *out++ = (byte >> 7) & 1; byte <<= 1; case 7: *out++ = (byte >> 7) & 1; byte <<= 1; case 6: *out++ = (byte >> 7) & 1; byte <<= 1; case 5: *out++ = (byte >> 7) & 1; byte <<= 1; case 4: *out++ = (byte >> 7) & 1; byte <<= 1; case 3: *out++ = (byte >> 7) & 1; byte <<= 1; case 2: *out++ = (byte >> 7) & 1; byte <<= 1; case 1: *out++ = (byte >> 7) & 1; } pixels -= 8; } } static void unpackP2(UINT8* out, const UINT8* in, int pixels) { /* bit pairs */ while (pixels > 0) { UINT8 byte = *in++; switch (pixels) { default: *out++ = (byte >> 6) & 3; byte <<= 2; case 3: *out++ = (byte >> 6) & 3; byte <<= 2; case 2: *out++ = (byte >> 6) & 3; byte <<= 2; case 1: *out++ = (byte >> 6) & 3; } pixels -= 4; } } static void unpackP4(UINT8* out, const UINT8* in, int pixels) { /* nibbles */ while (pixels > 0) { UINT8 byte = *in++; switch (pixels) { default: *out++ = (byte >> 4) & 15; byte <<= 4; case 1: *out++ = (byte >> 4) & 15; } pixels -= 2; } } static void unpackP2L(UINT8* out, const UINT8* in, int pixels) { int i, j, m, s; /* bit layers */ m = 128; s = (pixels+7)/8; for (i = j = 0; i < pixels; i++) { out[i] = ((in[j] & m) ? 1 : 0) + ((in[j + s] & m) ? 2 : 0); if ((m >>= 1) == 0) { m = 128; j++; } } } static void unpackP4L(UINT8* out, const UINT8* in, int pixels) { int i, j, m, s; /* bit layers (trust the optimizer ;-) */ m = 128; s = (pixels+7)/8; for (i = j = 0; i < pixels; i++) { out[i] = ((in[j] & m) ? 1 : 0) + ((in[j + s] & m) ? 2 : 0) + ((in[j + 2*s] & m) ? 4 : 0) + ((in[j + 3*s] & m) ? 8 : 0); if ((m >>= 1) == 0) { m = 128; j++; } } } /* Unpack to "RGB" image */ void ImagingUnpackRGB(UINT8* out, const UINT8* in, int pixels) { int i; /* RGB triplets */ for (i = 0; i < pixels; i++) { out[R] = in[0]; out[G] = in[1]; out[B] = in[2]; out[A] = 255; out += 4; in += 3; } } void unpackRGB16B(UINT8* out, const UINT8* in, int pixels) { int i; /* 16-bit RGB triplets, big-endian order */ for (i = 0; i < pixels; i++) { out[R] = in[0]; out[G] = in[2]; out[B] = in[4]; out[A] = 255; out += 4; in += 6; } } static void unpackRGBL(UINT8* out, const UINT8* in, int pixels) { int i; /* RGB, line interleaved */ for (i = 0; i < pixels; i++) { out[R] = in[i]; out[G] = in[i+pixels]; out[B] = in[i+pixels+pixels]; out[A] = 255; out += 4; } } void ImagingUnpackBGR(UINT8* out, const UINT8* in, int pixels) { int i; /* RGB, reversed bytes */ for (i = 0; i < pixels; i++) { out[R] = in[2]; out[G] = in[1]; out[B] = in[0]; out[A] = 255; out += 4; in += 3; } } void ImagingUnpackBGR5(UINT8* out, const UINT8* in, int pixels) { int i, pixel; /* RGB, reversed bytes, 5 bits per pixel */ for (i = 0; i < pixels; i++) { pixel = in[0] + (in[1] << 8); out[B] = (pixel & 31) * 255 / 31; out[G] = ((pixel>>5) & 31) * 255 / 31; out[R] = ((pixel>>10) & 31) * 255 / 31; out[A] = 255; out += 4; in += 2; } } static void ImagingUnpackBGRX(UINT8* out, const UINT8* in, int pixels) { int i; /* RGB, reversed bytes with padding */ for (i = 0; i < pixels; i++) { out[R] = in[2]; out[G] = in[1]; out[B] = in[0]; out[A] = 255; out += 4; in += 4; } } static void ImagingUnpackXRGB(UINT8* out, const UINT8* in, int pixels) { int i; /* RGB, leading pad */ for (i = 0; i < pixels; i++) { out[R] = in[1]; out[G] = in[2]; out[B] = in[3]; out[A] = 255; out += 4; in += 4; } } static void ImagingUnpackXBGR(UINT8* out, const UINT8* in, int pixels) { int i; /* RGB, reversed bytes, leading pad */ for (i = 0; i < pixels; i++) { out[R] = in[3]; out[G] = in[2]; out[B] = in[1]; out[A] = 255; out += 4; in += 4; } } /* Unpack to "RGBA" image */ static void unpackLA(UINT8* out, const UINT8* in, int pixels) { int i; /* greyscale with alpha */ for (i = 0; i < pixels; i++) { out[R] = out[G] = out[B] = in[0]; out[A] = in[1]; out += 4; in += 2; } } static void unpackLA16B(UINT8* out, const UINT8* in, int pixels) { int i; /* 16-bit greyscale with alpha, big-endian */ for (i = 0; i < pixels; i++) { out[R] = out[G] = out[B] = in[0]; out[A] = in[2]; out += 4; in += 4; } } static void unpackRGBAI(UINT8* out, const UINT8* in, int pixels) { int i; /* RGBA, inverted RGB bytes (FlashPix) */ for (i = 0; i < pixels; i++) { out[R] = ~in[0]; out[G] = ~in[1]; out[B] = ~in[2]; out[A] = in[3]; out += 4; in += 4; } } static void unpackRGBAL(UINT8* out, const UINT8* in, int pixels) { int i; /* RGBA, line interleaved */ for (i = 0; i < pixels; i++) { out[R] = in[i]; out[G] = in[i+pixels]; out[B] = in[i+pixels+pixels]; out[A] = in[i+pixels+pixels+pixels]; out += 4; } } void unpackRGBA16B(UINT8* out, const UINT8* in, int pixels) { int i; /* 16-bit RGBA, big-endian order */ for (i = 0; i < pixels; i++) { out[R] = in[0]; out[G] = in[2]; out[B] = in[4]; out[A] = in[6]; out += 4; in += 8; } } static void unpackARGB(UINT8* out, const UINT8* in, int pixels) { int i; /* RGBA, leading pad */ for (i = 0; i < pixels; i++) { out[R] = in[1]; out[G] = in[2]; out[B] = in[3]; out[A] = in[0]; out += 4; in += 4; } } static void unpackABGR(UINT8* out, const UINT8* in, int pixels) { int i; /* RGBA, reversed bytes */ for (i = 0; i < pixels; i++) { out[R] = in[3]; out[G] = in[2]; out[B] = in[1]; out[A] = in[0]; out += 4; in += 4; } } static void unpackBGRA(UINT8* out, const UINT8* in, int pixels) { int i; /* RGBA, reversed bytes */ for (i = 0; i < pixels; i++) { out[R] = in[2]; out[G] = in[1]; out[B] = in[0]; out[A] = in[3]; out += 4; in += 4; } } /* Unpack to "CMYK" image */ static void unpackCMYKI(UINT8* out, const UINT8* in, int pixels) { int i; /* CMYK, inverted bytes (Photoshop 2.5) */ for (i = 0; i < pixels; i++) { out[C] = ~in[0]; out[M] = ~in[1]; out[Y] = ~in[2]; out[K] = ~in[3]; out += 4; in += 4; } } static void copy1(UINT8* out, const UINT8* in, int pixels) { /* L, P */ memcpy(out, in, pixels); } static void copy2(UINT8* out, const UINT8* in, int pixels) { /* I;16 */ memcpy(out, in, pixels*2); } static void copy4(UINT8* out, const UINT8* in, int pixels) { /* RGBA, CMYK quadruples */ memcpy(out, in, 4 * pixels); } /* Unpack to "I" and "F" images */ #define UNPACK_RAW(NAME, GET, INTYPE, OUTTYPE)\ static void NAME(UINT8* out_, const UINT8* in, int pixels)\ {\ int i;\ OUTTYPE* out = (OUTTYPE*) out_;\ for (i = 0; i < pixels; i++, in += sizeof(INTYPE))\ out[i] = (OUTTYPE) ((INTYPE) GET);\ } #define UNPACK(NAME, COPY, INTYPE, OUTTYPE)\ static void NAME(UINT8* out_, const UINT8* in, int pixels)\ {\ int i;\ OUTTYPE* out = (OUTTYPE*) out_;\ INTYPE tmp_;\ UINT8* tmp = (UINT8*) &tmp_;\ for (i = 0; i < pixels; i++, in += sizeof(INTYPE)) {\ COPY;\ out[i] = (OUTTYPE) tmp_;\ }\ } UNPACK_RAW(unpackI8, in[0], UINT8, INT32) UNPACK_RAW(unpackI8S, in[0], INT8, INT32) UNPACK(unpackI16, C16L, UINT16, INT32) UNPACK(unpackI16S, C16L, INT16, INT32) UNPACK(unpackI16B, C16B, UINT16, INT32) UNPACK(unpackI16BS, C16B, INT16, INT32) UNPACK(unpackI16N, C16N, UINT16, INT32) UNPACK(unpackI16NS, C16N, INT16, INT32) UNPACK(unpackI32, C32L, UINT32, INT32) UNPACK(unpackI32S, C32L, INT32, INT32) UNPACK(unpackI32B, C32B, UINT32, INT32) UNPACK(unpackI32BS, C32B, INT32, INT32) UNPACK(unpackI32N, C32N, UINT32, INT32) UNPACK(unpackI32NS, C32N, INT32, INT32) UNPACK_RAW(unpackF8, in[0], UINT8, FLOAT32) UNPACK_RAW(unpackF8S, in[0], INT8, FLOAT32) UNPACK(unpackF16, C16L, UINT16, FLOAT32) UNPACK(unpackF16S, C16L, INT16, FLOAT32) UNPACK(unpackF16B, C16B, UINT16, FLOAT32) UNPACK(unpackF16BS, C16B, INT16, FLOAT32) UNPACK(unpackF16N, C16N, UINT16, FLOAT32) UNPACK(unpackF16NS, C16N, INT16, FLOAT32) UNPACK(unpackF32, C32L, UINT32, FLOAT32) UNPACK(unpackF32S, C32L, INT32, FLOAT32) UNPACK(unpackF32B, C32B, UINT32, FLOAT32) UNPACK(unpackF32BS, C32B, INT32, FLOAT32) UNPACK(unpackF32N, C32N, UINT32, FLOAT32) UNPACK(unpackF32NS, C32N, INT32, FLOAT32) UNPACK(unpackF32F, C32L, FLOAT32, FLOAT32) UNPACK(unpackF32BF, C32B, FLOAT32, FLOAT32) UNPACK(unpackF32NF, C32N, FLOAT32, FLOAT32) #ifdef FLOAT64 UNPACK(unpackF64F, C64L, FLOAT64, FLOAT32) UNPACK(unpackF64BF, C64B, FLOAT64, FLOAT32) UNPACK(unpackF64NF, C64N, FLOAT64, FLOAT32) #endif /* Misc. unpackers */ static void band0(UINT8* out, const UINT8* in, int pixels) { int i; /* band 0 only */ for (i = 0; i < pixels; i++) { out[0] = in[i]; out += 4; } } static void band1(UINT8* out, const UINT8* in, int pixels) { int i; /* band 1 only */ for (i = 0; i < pixels; i++) { out[1] = in[i]; out += 4; } } static void band2(UINT8* out, const UINT8* in, int pixels) { int i; /* band 2 only */ for (i = 0; i < pixels; i++) { out[2] = in[i]; out += 4; } } static void band3(UINT8* out, const UINT8* in, int pixels) { /* band 3 only */ int i; for (i = 0; i < pixels; i++) { out[3] = in[i]; out += 4; } } static void band0I(UINT8* out, const UINT8* in, int pixels) { int i; /* band 0 only */ for (i = 0; i < pixels; i++) { out[0] = ~in[i]; out += 4; } } static void band1I(UINT8* out, const UINT8* in, int pixels) { int i; /* band 1 only */ for (i = 0; i < pixels; i++) { out[1] = ~in[i]; out += 4; } } static void band2I(UINT8* out, const UINT8* in, int pixels) { int i; /* band 2 only */ for (i = 0; i < pixels; i++) { out[2] = ~in[i]; out += 4; } } static void band3I(UINT8* out, const UINT8* in, int pixels) { /* band 3 only */ int i; for (i = 0; i < pixels; i++) { out[3] = ~in[i]; out += 4; } } static struct { const char* mode; const char* rawmode; int bits; ImagingShuffler unpack; } unpackers[] = { /* bilevel */ {"1", "1", 1, unpack1}, {"1", "1;I", 1, unpack1I}, {"1", "1;R", 1, unpack1R}, {"1", "1;IR", 1, unpack1IR}, /* greyscale */ {"L", "L;2", 2, unpackL2}, {"L", "L;4", 4, unpackL4}, {"L", "L", 8, copy1}, {"L", "L;I", 8, unpackLI}, {"L", "L;16", 16, unpackL16}, {"L", "L;16B", 16, unpackL16B}, /* palette */ {"P", "P;1", 1, unpackP1}, {"P", "P;2", 2, unpackP2}, {"P", "P;2L", 2, unpackP2L}, {"P", "P;4", 4, unpackP4}, {"P", "P;4L", 4, unpackP4L}, {"P", "P", 8, copy1}, /* true colour */ {"RGB", "RGB", 24, ImagingUnpackRGB}, {"RGB", "RGB;L", 24, unpackRGBL}, {"RGB", "RGB;16B", 48, unpackRGB16B}, {"RGB", "BGR", 24, ImagingUnpackBGR}, {"RGB", "BGR;5", 16, ImagingUnpackBGR5}, {"RGB", "RGBX", 32, copy4}, {"RGB", "RGBX;L", 32, unpackRGBAL}, {"RGB", "BGRX", 32, ImagingUnpackBGRX}, {"RGB", "XRGB", 24, ImagingUnpackXRGB}, {"RGB", "XBGR", 32, ImagingUnpackXBGR}, {"RGB", "YCC;P", 24, ImagingUnpackYCC}, {"RGB", "R", 8, band0}, {"RGB", "G", 8, band1}, {"RGB", "B", 8, band2}, /* true colour w. transparency */ {"RGBA", "LA", 16, unpackLA}, {"RGBA", "LA;16B", 32, unpackLA16B}, {"RGBA", "RGBA", 32, copy4}, {"RGBA", "RGBA;I", 32, unpackRGBAI}, {"RGBA", "RGBA;L", 32, unpackRGBAL}, {"RGBA", "RGBA;16B", 64, unpackRGBA16B}, {"RGBA", "BGRA", 32, unpackBGRA}, {"RGBA", "ARGB", 32, unpackARGB}, {"RGBA", "ABGR", 32, unpackABGR}, {"RGBA", "YCCA;P", 32, ImagingUnpackYCCA}, {"RGBA", "R", 8, band0}, {"RGBA", "G", 8, band1}, {"RGBA", "B", 8, band2}, {"RGBA", "A", 8, band3}, /* true colour w. padding */ {"RGBX", "RGB", 24, ImagingUnpackRGB}, {"RGBX", "RGB;L", 24, unpackRGBL}, {"RGBX", "RGB;16B", 48, unpackRGB16B}, {"RGBX", "BGR", 24, ImagingUnpackBGR}, {"RGBX", "BGR;5", 16, ImagingUnpackBGR5}, {"RGBX", "RGBX", 32, copy4}, {"RGBX", "RGBX;L", 32, unpackRGBAL}, {"RGBX", "BGRX", 32, ImagingUnpackBGRX}, {"RGBX", "XRGB", 24, ImagingUnpackXRGB}, {"RGBX", "XBGR", 32, ImagingUnpackXBGR}, {"RGBX", "YCC;P", 24, ImagingUnpackYCC}, {"RGBX", "R", 8, band0}, {"RGBX", "G", 8, band1}, {"RGBX", "B", 8, band2}, {"RGBX", "X", 8, band3}, /* colour separation */ {"CMYK", "CMYK", 32, copy4}, {"CMYK", "CMYK;I", 32, unpackCMYKI}, {"CMYK", "CMYK;L", 32, unpackRGBAL}, {"CMYK", "C", 8, band0}, {"CMYK", "M", 8, band1}, {"CMYK", "Y", 8, band2}, {"CMYK", "K", 8, band3}, {"CMYK", "C;I", 8, band0I}, {"CMYK", "M;I", 8, band1I}, {"CMYK", "Y;I", 8, band2I}, {"CMYK", "K;I", 8, band3I}, /* video (YCbCr) */ {"YCbCr", "YCbCr", 24, ImagingUnpackRGB}, {"YCbCr", "YCbCr;L", 24, unpackRGBL}, {"YCbCr", "YCbCrX", 32, copy4}, {"YCbCr", "YCbCrK", 32, copy4}, /* integer variations */ {"I", "I", 32, copy4}, {"I", "I;8", 8, unpackI8}, {"I", "I;8S", 8, unpackI8S}, {"I", "I;16", 16, unpackI16}, {"I", "I;16S", 16, unpackI16S}, {"I", "I;16B", 16, unpackI16B}, {"I", "I;16BS", 16, unpackI16BS}, {"I", "I;16N", 16, unpackI16N}, {"I", "I;16NS", 16, unpackI16NS}, {"I", "I;32", 32, unpackI32}, {"I", "I;32S", 32, unpackI32S}, {"I", "I;32B", 32, unpackI32B}, {"I", "I;32BS", 32, unpackI32BS}, {"I", "I;32N", 32, unpackI32N}, {"I", "I;32NS", 32, unpackI32NS}, /* floating point variations */ {"F", "F", 32, copy4}, {"F", "F;8", 8, unpackF8}, {"F", "F;8S", 8, unpackF8S}, {"F", "F;16", 16, unpackF16}, {"F", "F;16S", 16, unpackF16S}, {"F", "F;16B", 16, unpackF16B}, {"F", "F;16BS", 16, unpackF16BS}, {"F", "F;16N", 16, unpackF16N}, {"F", "F;16NS", 16, unpackF16NS}, {"F", "F;32", 32, unpackF32}, {"F", "F;32S", 32, unpackF32S}, {"F", "F;32B", 32, unpackF32B}, {"F", "F;32BS", 32, unpackF32BS}, {"F", "F;32N", 32, unpackF32N}, {"F", "F;32NS", 32, unpackF32NS}, {"F", "F;32F", 32, unpackF32F}, {"F", "F;32BF", 32, unpackF32BF}, {"F", "F;32NF", 32, unpackF32NF}, #ifdef FLOAT64 {"F", "F;64F", 64, unpackF64F}, {"F", "F;64BF", 64, unpackF64BF}, {"F", "F;64NF", 64, unpackF64NF}, #endif /* storage modes */ {"I;16", "I;16", 16, copy2}, {"I;16B", "I;16B", 16, copy2}, {NULL} /* sentinel */ }; ImagingShuffler ImagingFindUnpacker(const char* mode, const char* rawmode, int* bits_out) { int i; /* find a suitable pixel unpacker */ for (i = 0; unpackers[i].rawmode; i++) if (strcmp(unpackers[i].mode, mode) == 0 && strcmp(unpackers[i].rawmode, rawmode) == 0) { if (bits_out) *bits_out = unpackers[i].bits; return unpackers[i].unpack; } return NULL; } Imaging-1.1.3/libImaging/UnpackYCC.c0100444000076400007640000001710607442710204016727 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/UnpackYCC.c#2 $ * * code to convert and unpack PhotoYCC data * * history: * 97-01-25 fl Moved from PcdDecode.c * * Copyright (c) Fredrik Lundh 1996-97. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" /* Tables generated by pcdtables.py, based on transforms taken from the "Colour Space Conversions FAQ" by Roberts/Ford. */ static INT16 L[] = { 0, 1, 3, 4, 5, 7, 8, 10, 11, 12, 14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 29, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 45, 46, 48, 49, 50, 52, 53, 54, 56, 57, 58, 60, 61, 62, 64, 65, 67, 68, 69, 71, 72, 73, 75, 76, 77, 79, 80, 82, 83, 84, 86, 87, 88, 90, 91, 92, 94, 95, 96, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 111, 113, 114, 115, 117, 118, 120, 121, 122, 124, 125, 126, 128, 129, 130, 132, 133, 134, 136, 137, 139, 140, 141, 143, 144, 145, 147, 148, 149, 151, 152, 153, 155, 156, 158, 159, 160, 162, 163, 164, 166, 167, 168, 170, 171, 173, 174, 175, 177, 178, 179, 181, 182, 183, 185, 186, 187, 189, 190, 192, 193, 194, 196, 197, 198, 200, 201, 202, 204, 205, 206, 208, 209, 211, 212, 213, 215, 216, 217, 219, 220, 221, 223, 224, 225, 227, 228, 230, 231, 232, 234, 235, 236, 238, 239, 240, 242, 243, 245, 246, 247, 249, 250, 251, 253, 254, 255, 257, 258, 259, 261, 262, 264, 265, 266, 268, 269, 270, 272, 273, 274, 276, 277, 278, 280, 281, 283, 284, 285, 287, 288, 289, 291, 292, 293, 295, 296, 297, 299, 300, 302, 303, 304, 306, 307, 308, 310, 311, 312, 314, 315, 317, 318, 319, 321, 322, 323, 325, 326, 327, 329, 330, 331, 333, 334, 336, 337, 338, 340, 341, 342, 344, 345, 346 }; static INT16 CB[] = { -345, -343, -341, -338, -336, -334, -332, -329, -327, -325, -323, -321, -318, -316, -314, -312, -310, -307, -305, -303, -301, -298, -296, -294, -292, -290, -287, -285, -283, -281, -278, -276, -274, -272, -270, -267, -265, -263, -261, -258, -256, -254, -252, -250, -247, -245, -243, -241, -239, -236, -234, -232, -230, -227, -225, -223, -221, -219, -216, -214, -212, -210, -207, -205, -203, -201, -199, -196, -194, -192, -190, -188, -185, -183, -181, -179, -176, -174, -172, -170, -168, -165, -163, -161, -159, -156, -154, -152, -150, -148, -145, -143, -141, -139, -137, -134, -132, -130, -128, -125, -123, -121, -119, -117, -114, -112, -110, -108, -105, -103, -101, -99, -97, -94, -92, -90, -88, -85, -83, -81, -79, -77, -74, -72, -70, -68, -66, -63, -61, -59, -57, -54, -52, -50, -48, -46, -43, -41, -39, -37, -34, -32, -30, -28, -26, -23, -21, -19, -17, -15, -12, -10, -8, -6, -3, -1, 0, 2, 4, 7, 9, 11, 13, 16, 18, 20, 22, 24, 27, 29, 31, 33, 35, 38, 40, 42, 44, 47, 49, 51, 53, 55, 58, 60, 62, 64, 67, 69, 71, 73, 75, 78, 80, 82, 84, 86, 89, 91, 93, 95, 98, 100, 102, 104, 106, 109, 111, 113, 115, 118, 120, 122, 124, 126, 129, 131, 133, 135, 138, 140, 142, 144, 146, 149, 151, 153, 155, 157, 160, 162, 164, 166, 169, 171, 173, 175, 177, 180, 182, 184, 186, 189, 191, 193, 195, 197, 200, 202, 204, 206, 208, 211, 213, 215, 217, 220 }; static INT16 GB[] = { 67, 67, 66, 66, 65, 65, 65, 64, 64, 63, 63, 62, 62, 62, 61, 61, 60, 60, 59, 59, 59, 58, 58, 57, 57, 56, 56, 56, 55, 55, 54, 54, 53, 53, 52, 52, 52, 51, 51, 50, 50, 49, 49, 49, 48, 48, 47, 47, 46, 46, 46, 45, 45, 44, 44, 43, 43, 43, 42, 42, 41, 41, 40, 40, 40, 39, 39, 38, 38, 37, 37, 37, 36, 36, 35, 35, 34, 34, 34, 33, 33, 32, 32, 31, 31, 31, 30, 30, 29, 29, 28, 28, 28, 27, 27, 26, 26, 25, 25, 25, 24, 24, 23, 23, 22, 22, 22, 21, 21, 20, 20, 19, 19, 19, 18, 18, 17, 17, 16, 16, 15, 15, 15, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 6, 6, 5, 5, 4, 4, 3, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, -1, -1, -2, -2, -2, -3, -3, -4, -4, -5, -5, -5, -6, -6, -7, -7, -8, -8, -8, -9, -9, -10, -10, -11, -11, -11, -12, -12, -13, -13, -14, -14, -14, -15, -15, -16, -16, -17, -17, -18, -18, -18, -19, -19, -20, -20, -21, -21, -21, -22, -22, -23, -23, -24, -24, -24, -25, -25, -26, -26, -27, -27, -27, -28, -28, -29, -29, -30, -30, -30, -31, -31, -32, -32, -33, -33, -33, -34, -34, -35, -35, -36, -36, -36, -37, -37, -38, -38, -39, -39, -39, -40, -40, -41, -41, -42 }; static INT16 CR[] = { -249, -247, -245, -243, -241, -239, -238, -236, -234, -232, -230, -229, -227, -225, -223, -221, -219, -218, -216, -214, -212, -210, -208, -207, -205, -203, -201, -199, -198, -196, -194, -192, -190, -188, -187, -185, -183, -181, -179, -178, -176, -174, -172, -170, -168, -167, -165, -163, -161, -159, -157, -156, -154, -152, -150, -148, -147, -145, -143, -141, -139, -137, -136, -134, -132, -130, -128, -127, -125, -123, -121, -119, -117, -116, -114, -112, -110, -108, -106, -105, -103, -101, -99, -97, -96, -94, -92, -90, -88, -86, -85, -83, -81, -79, -77, -76, -74, -72, -70, -68, -66, -65, -63, -61, -59, -57, -55, -54, -52, -50, -48, -46, -45, -43, -41, -39, -37, -35, -34, -32, -30, -28, -26, -25, -23, -21, -19, -17, -15, -14, -12, -10, -8, -6, -4, -3, -1, 0, 2, 4, 5, 7, 9, 11, 13, 15, 16, 18, 20, 22, 24, 26, 27, 29, 31, 33, 35, 36, 38, 40, 42, 44, 46, 47, 49, 51, 53, 55, 56, 58, 60, 62, 64, 66, 67, 69, 71, 73, 75, 77, 78, 80, 82, 84, 86, 87, 89, 91, 93, 95, 97, 98, 100, 102, 104, 106, 107, 109, 111, 113, 115, 117, 118, 120, 122, 124, 126, 128, 129, 131, 133, 135, 137, 138, 140, 142, 144, 146, 148, 149, 151, 153, 155, 157, 158, 160, 162, 164, 166, 168, 169, 171, 173, 175, 177, 179, 180, 182, 184, 186, 188, 189, 191, 193, 195, 197, 199, 200, 202, 204, 206, 208, 209, 211, 213, 215 }; static INT16 GR[] = { 127, 126, 125, 124, 123, 122, 121, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 6, 5, 4, 3, 2, 1, 0, 0, -1, -2, -3, -4, -5, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -18, -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, -30, -31, -31, -32, -33, -34, -35, -36, -37, -38, -39, -40, -41, -42, -43, -44, -44, -45, -46, -47, -48, -49, -50, -51, -52, -53, -54, -55, -56, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69, -69, -70, -71, -72, -73, -74, -75, -76, -77, -78, -79, -80, -81, -82, -82, -83, -84, -85, -86, -87, -88, -89, -90, -91, -92, -93, -94, -94, -95, -96, -97, -98, -99, -100, -101, -102, -103, -104, -105, -106, -107, -107, -108 }; #define R 0 #define G 1 #define B 2 #define A 3 #define YCC2RGB(rgb, y, cb, cr) {\ int l = L[y];\ int r = l + CR[cr];\ int g = l + GR[cr] + GB[cb];\ int b = l + CB[cb];\ rgb[0] = (r <= 0) ? 0 : (r >= 255) ? 255 : r;\ rgb[1] = (g <= 0) ? 0 : (g >= 255) ? 255 : g;\ rgb[2] = (b <= 0) ? 0 : (b >= 255) ? 255 : b;\ } void ImagingUnpackYCC(UINT8* out, const UINT8* in, int pixels) { int i; /* PhotoYCC triplets */ for (i = 0; i < pixels; i++) { YCC2RGB(out, in[0], in[1], in[2]); out[A] = 255; out += 4; in += 3; } } void ImagingUnpackYCCA(UINT8* out, const UINT8* in, int pixels) { int i; /* PhotoYCC triplets plus premultiplied alpha */ for (i = 0; i < pixels; i++) { /* Divide by alpha */ UINT8 rgb[3]; rgb[0] = (in[3] == 0) ? 0 : (((int) in[0] * 255) / in[3]); rgb[1] = (in[3] == 0) ? 0 : (((int) in[1] * 255) / in[3]); rgb[2] = (in[3] == 0) ? 0 : (((int) in[2] * 255) / in[3]); /* Convert non-multiplied data to RGB */ YCC2RGB(out, rgb[0], rgb[1], rgb[2]); out[A] = in[3]; out += 4; in += 4; } } Imaging-1.1.3/libImaging/Bit.h0100444000076400007640000000103507442710204015664 0ustar fredrikfredrik/* Bit.h */ typedef struct { /* CONFIGURATION */ /* Number of bits per pixel */ int bits; /* Line padding (0 or 8) */ int pad; /* Fill order */ /* 0=msb/msb, 1=msbfill/lsbshift, 2=lsbfill/msbshift, 3=lsb/lsb */ int fill; /* Signed integers (0=unsigned, 1=signed) */ int sign; /* Lookup table (not implemented) */ unsigned long lutsize; FLOAT32* lut; /* INTERNAL */ unsigned long mask; unsigned long signmask; unsigned long bitbuffer; int bitcount; } BITSTATE; Imaging-1.1.3/libImaging/Gif.h0100444000076400007640000000504507442710204015660 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/Gif.h#2 $ * * Declarations for a fast, suspendable GIF decoder. * * Copyright (c) Fredrik Lundh 1995-96. */ /* Max size for a LZW code word. */ #define GIFBITS 12 #define GIFTABLE (1< typedef struct { struct jpeg_error_mgr pub; /* "public" fields */ jmp_buf setjmp_buffer; /* for return to caller */ } JPEGERROR; /* -------------------------------------------------------------------- */ /* Decoder */ typedef struct { struct jpeg_source_mgr pub; int skip; } JPEGSOURCE; typedef struct { /* CONFIGURATION */ /* Jpeg file mode (empty if not known) */ char jpegmode[8+1]; /* Converter output mode (input to the shuffler). If empty, convert conversions are disabled */ char rawmode[8+1]; /* If set, trade quality for speed */ int draft; /* Scale factor (1, 2, 4, 8) */ int scale; /* PRIVATE CONTEXT (set by decoder) */ struct jpeg_decompress_struct cinfo; JPEGERROR error; JPEGSOURCE source; } JPEGSTATE; /* -------------------------------------------------------------------- */ /* Encoder */ typedef struct { struct jpeg_destination_mgr pub; /* might add something some other day */ } JPEGDESTINATION; typedef struct { /* CONFIGURATION */ /* Quality (1-100, 0 means default) */ int quality; /* Progressive mode */ int progressive; /* Smoothing factor (1-100, 0 means none) */ int smooth; /* Optimize Huffman tables (slow) */ int optimize; /* Stream type (0=full, 1=tables only, 2=image only) */ int streamtype; /* DPI setting (0=square pixels, otherwide DPI) */ int xdpi, ydpi; /* PRIVATE CONTEXT (set by encoder) */ struct jpeg_compress_struct cinfo; JPEGERROR error; JPEGDESTINATION destination; } JPEGENCODERSTATE; Imaging-1.1.3/libImaging/Lzw.h0100444000076400007640000000155507442710204015731 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/Lzw.h#2 $ * * declarations for the TIFF LZW decoder. * * Copyright (c) Fredrik Lundh 1995-96. */ /* Max size for LZW code words */ #define LZWBITS 12 #define LZWTABLE (1<context; UINT8* ptr; if (state->state == 0) { /* Initialize context variables */ /* this decoder only works for float32 image buffers */ if (im->type != IMAGING_TYPE_FLOAT32) { state->errcode = IMAGING_CODEC_CONFIG; return -1; } /* sanity check */ if (bitstate->bits < 1 || bitstate->bits >= 32) { state->errcode = IMAGING_CODEC_CONFIG; return -1; } bitstate->mask = (1<bits)-1; if (bitstate->sign) bitstate->signmask = (1<<(bitstate->bits-1)); /* check image orientation */ if (state->ystep < 0) { state->y = state->ysize-1; state->ystep = -1; } else state->ystep = 1; state->state = 1; } ptr = buf; while (bytes > 0) { UINT8 byte = *ptr; ptr++; bytes--; /* get a byte from the input stream and insert in the bit buffer */ if (bitstate->fill&1) /* fill LSB first */ bitstate->bitbuffer |= (unsigned long) byte << bitstate->bitcount; else /* fill MSB first */ bitstate->bitbuffer = (bitstate->bitbuffer << 8) | byte; bitstate->bitcount += 8; while (bitstate->bitcount >= bitstate->bits) { /* get a pixel from the bit buffer */ unsigned long data; FLOAT32 pixel; if (bitstate->fill&2) { /* store LSB first */ data = bitstate->bitbuffer & bitstate->mask; if (bitstate->bitcount > 32) /* bitbuffer overflow; restore it from last input byte */ bitstate->bitbuffer = byte >> (8 - (bitstate->bitcount - bitstate->bits)); else bitstate->bitbuffer >>= bitstate->bits; } else /* store MSB first */ data = (bitstate->bitbuffer >> (bitstate->bitcount - bitstate->bits)) & bitstate->mask; bitstate->bitcount -= bitstate->bits; if (bitstate->lutsize > 0) { /* map through lookup table */ if (data <= 0) pixel = bitstate->lut[0]; else if (data >= bitstate->lutsize) pixel = bitstate->lut[bitstate->lutsize-1]; else pixel = bitstate->lut[data]; } else { /* convert */ if (data & bitstate->signmask) /* image memory contains signed data */ pixel = (FLOAT32) (INT32) (data | ~bitstate->mask); else pixel = (FLOAT32) data; } *(FLOAT32*)(&im->image32[state->y][state->x]) = pixel; /* step forward */ if (++state->x >= state->xsize) { /* new line */ state->y += state->ystep; if (state->y < 0 || state->y >= state->ysize) { /* end of file (errcode = 0) */ return -1; } state->x = 0; /* reset bit buffer */ if (bitstate->pad > 0) bitstate->bitcount = 0; } } } return ptr - buf; } Imaging-1.1.3/libImaging/EpsEncode.c0100444000076400007640000000262107442710204017010 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/EpsEncode.c#2 $ * * encoder for EPS hex data * * history: * 96-04-19 fl created * 96-06-27 fl don't drop last block of encoded data * * notes: * FIXME: rename to HexEncode.c ?? * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" int ImagingEpsEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { enum { HEXBYTE=1, NEWLINE }; const char *hex = "0123456789abcdef"; UINT8* ptr = buf; UINT8* in, i; if (!state->state) { state->state = HEXBYTE; state->xsize *= im->pixelsize; /* Hack! */ } in = (UINT8*) im->image[state->y]; for (;;) { if (state->state == NEWLINE) { if (bytes < 1) break; *ptr++ = '\n'; bytes--; state->state = HEXBYTE; } if (bytes < 2) break; i = in[state->x++]; *ptr++ = hex[(i>>4)&15]; *ptr++ = hex[i&15]; bytes -= 2; /* Skip junk bytes */ if (im->bands == 3 && (state->x & 3) == 3) state->x++; if (++state->count >= 79/2) { state->state = NEWLINE; state->count = 0; } if (state->x >= state->xsize) { state->x = 0; if (++state->y >= state->ysize) { state->errcode = IMAGING_CODEC_END; break; } in = (UINT8*) im->image[state->y]; } } return ptr - buf; } Imaging-1.1.3/libImaging/FliDecode.c0100444000076400007640000001144207442710204016762 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/FliDecode.c#2 $ * * decoder for Autodesk Animator FLI/FLC animations * * history: * 97-01-03 fl Created * 97-01-17 fl Added SS2 support (FLC) * * Copyright (c) Fredrik Lundh 1997. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #define I16(ptr)\ ((ptr)[0] + ((ptr)[1] << 8)) #define I32(ptr)\ ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24)) int ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { UINT8* ptr; int framesize; int c, chunks; int l, lines; int i, j, x, y, ymax; /* If not even the chunk size is present, we'd better leave */ if (bytes < 4) return 0; /* We don't decode anything unless we have a full chunk in the input buffer (on the other hand, the Python part of the driver makes sure this is always the case) */ ptr = buf; framesize = I32(ptr); if (framesize < I32(ptr)) return 0; /* Make sure this is a frame chunk. The Python driver takes case of other chunk types. */ if (I16(ptr+4) != 0xF1FA) { state->errcode = IMAGING_CODEC_UNKNOWN; return -1; } chunks = I16(ptr+6); ptr += 16; /* Process subchunks */ for (c = 0; c < chunks; c++) { UINT8 *data = ptr + 6; switch (I16(ptr+4)) { case 4: case 11: /* FLI COLOR chunk */ break; /* ignored; handled by Python code */ case 7: /* FLI SS2 chunk (word delta) */ lines = I16(data); data += 2; for (l = y = 0; l < lines && y < state->ysize; l++, y++) { UINT8* buf = (UINT8*) im->image[y]; int p, packets; packets = I16(data); data += 2; while (packets & 0x8000) { /* flag word */ if (packets & 0x4000) { y += 65536 - packets; /* skip lines */ if (y >= state->ysize) { state->errcode = IMAGING_CODEC_OVERRUN; return -1; } buf = (UINT8*) im->image[y]; } else { /* store last byte (used if line width is odd) */ buf[state->xsize-1] = (UINT8) packets; } packets = I16(data); data += 2; } for (p = x = 0; p < packets; p++) { x += data[0]; /* pixel skip */ if (data[1] >= 128) { i = 256-data[1]; /* run */ if (x + i + i > state->xsize) break; for (j = 0; j < i; j++) { buf[x++] = data[2]; buf[x++] = data[3]; } data += 2 + 2; } else { i = 2 * (int) data[1]; /* chunk */ if (x + i > state->xsize) break; memcpy(buf + x, data + 2, i); data += 2 + i; x += i; } } if (p < packets) break; /* didn't process all packets */ } if (l < lines) { /* didn't process all lines */ state->errcode = IMAGING_CODEC_OVERRUN; return -1; } break; case 12: /* FLI LC chunk (byte delta) */ y = I16(data); ymax = y + I16(data+2); data += 4; for (; y < ymax && y < state->ysize; y++) { UINT8* out = (UINT8*) im->image[y]; int p, packets = *data++; for (p = x = 0; p < packets; p++, x += i) { x += data[0]; /* skip pixels */ if (data[1] & 0x80) { i = 256-data[1]; /* run */ if (x + i > state->xsize) break; memset(out + x, data[2], i); data += 3; } else { i = data[1]; /* chunk */ if (x + i > state->xsize) break; memcpy(out + x, data + 2, i); data += i + 2; } } if (p < packets) break; /* didn't process all packets */ } if (y < ymax) { /* didn't process all lines */ state->errcode = IMAGING_CODEC_OVERRUN; return -1; } break; case 13: /* FLI BLACK chunk */ for (y = 0; y < state->ysize; y++) memset(im->image[y], 0, state->xsize); break; case 15: /* FLI BRUN chunk */ for (y = 0; y < state->ysize; y++) { UINT8* out = (UINT8*) im->image[y]; data += 1; /* ignore packetcount byte */ for (x = 0; x < state->xsize; x += i) { if (data[0] & 0x80) { i = 256 - data[0]; if (x + i > state->xsize) break; /* safety first */ memcpy(out + x, data + 1, i); data += i + 1; } else { i = data[0]; if (x + i > state->xsize) break; /* safety first */ memset(out + x, data[1], i); data += 2; } } if (x != state->xsize) { /* didn't unpack whole line */ state->errcode = IMAGING_CODEC_OVERRUN; return -1; } } break; case 16: /* COPY chunk */ for (y = 0; y < state->ysize; y++) { UINT8* buf = (UINT8*) im->image[y]; memcpy(buf+x, data, state->xsize); data += state->xsize; } break; case 18: /* PSTAMP chunk */ break; /* ignored */ default: /* unknown chunk */ /* printf("unknown FLI/FLC chunk: %d\n", I16(ptr+4)); */ state->errcode = IMAGING_CODEC_UNKNOWN; return -1; } ptr += I32(ptr); } return -1; /* end of frame */ } Imaging-1.1.3/libImaging/GifDecode.c0100444000076400007640000001454407442710204016763 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/GifDecode.c#2 $ * * a fast, suspendable GIF decoder * * history: * 95-09-03 fl Created * 95-09-05 fl Fixed sign problem on 16-bit platforms * 95-09-13 fl Added some storage shortcuts * 96-03-28 fl Revised API, integrated with PIL * 96-12-10 fl Added interlace support * 96-12-16 fl Fixed premature termination bug introduced by last fix * 97-01-05 fl Don't mess up on bogus configuration * 97-01-17 fl Don't mess up on very small, interlaced files * 99-02-07 fl Minor speedups * * Copyright (c) Secret Labs AB 1997-99. * Copyright (c) Fredrik Lundh 1995-97. * * See the README file for information on usage and redistribution. */ #include #include /* memcpy() */ #include "Imaging.h" #include "Gif.h" #define NEWLINE(state, context) {\ state->x = 0;\ state->y += context->step;\ while (state->y >= state->ysize)\ switch (context->interlace) {\ case 1:\ context->repeat = state->y = 4;\ context->interlace = 2;\ break;\ case 2:\ context->step = 4;\ context->repeat = state->y = 2;\ context->interlace = 3;\ break;\ case 3:\ context->step = 2;\ context->repeat = state->y = 1;\ context->interlace = 0;\ break;\ default:\ return -1;\ }\ if (state->y < state->ysize)\ out = im->image8[state->y + state->yoff] + state->xoff;\ } int ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes) { UINT8* p; UINT8* out; int c, i; int thiscode; GIFDECODERSTATE *context = (GIFDECODERSTATE*) state->context; UINT8 *ptr = buffer; if (!state->state) { /* Initialise state */ if (context->bits < 0 || context->bits > 8) { state->errcode = IMAGING_CODEC_CONFIG; return -1; } /* Clear code */ context->clear = 1 << context->bits; /* End code */ context->end = context->clear + 1; /* Interlace */ if (context->interlace) { context->interlace = 1; context->step = context->repeat = 8; } else context->step = 1; state->state = 1; } if (state->y < state->ysize) out = im->image8[state->y + state->yoff] + state->xoff + state->x; for (;;) { if (state->state == 1) { /* First free entry in table */ context->next = context->clear + 2; /* Initial code size */ context->codesize = context->bits + 1; context->codemask = (1 << context->codesize) - 1; /* Buffer pointer. We fill the buffer from right, which allows us to return all of it in one operation. */ context->bufferindex = GIFBUFFER; state->state = 2; } if (context->bufferindex < GIFBUFFER) { /* Return whole buffer in one chunk */ i = GIFBUFFER - context->bufferindex; p = &context->buffer[context->bufferindex]; context->bufferindex = GIFBUFFER; } else { /* Get current symbol */ while (context->bitcount < context->codesize) { if (context->blocksize > 0) { /* Read next byte */ c = *ptr++; bytes--; context->blocksize--; /* New bits are shifted in from from the left. */ context->bitbuffer |= (INT32) c << context->bitcount; context->bitcount += 8; } else { /* New GIF block */ /* We don't start decoding unless we have a full block */ if (bytes < 1) return ptr - buffer; c = *ptr; if (bytes < c+1) return ptr - buffer; context->blocksize = c; ptr++; bytes--; } } /* Extract current symbol from bit buffer. */ c = (int) context->bitbuffer & context->codemask; /* Adjust buffer */ context->bitbuffer >>= context->codesize; context->bitcount -= context->codesize; /* If c is less than "clear", it's a data byte. Otherwise, it's either clear/end or a code symbol which should be expanded. */ if (c == context->clear) { if (state->state != 2) state->state = 1; continue; } if (c == context->end) break; i = 1; p = &context->lastdata; if (state->state == 2) { /* First valid symbol after clear; use as is */ if (c > context->clear) { state->errcode = IMAGING_CODEC_BROKEN; return -1; } context->lastdata = context->lastcode = c; state->state = 3; } else { thiscode = c; if (c > context->next) { state->errcode = IMAGING_CODEC_BROKEN; return -1; } if (c == context->next) { /* c == next is allowed. not sure why. */ if (context->bufferindex <= 0) { state->errcode = IMAGING_CODEC_BROKEN; return -1; } context->buffer[--context->bufferindex] = context->lastdata; c = context->lastcode; } while (c >= context->clear) { /* Copy data string to buffer (beginning from right) */ if (context->bufferindex <= 0 || c >= GIFTABLE) { state->errcode = IMAGING_CODEC_BROKEN; return -1; } context->buffer[--context->bufferindex] = context->data[c]; c = context->link[c]; } context->lastdata = c; if (context->next < GIFTABLE) { /* We'll only add this symbol if we have room for it (take advise, Netscape!) */ context->data[context->next] = c; context->link[context->next] = context->lastcode; if (context->next == context->codemask && context->codesize < GIFBITS) { /* Expand code size */ context->codesize++; context->codemask = (1 << context->codesize) - 1; } context->next++; } context->lastcode = thiscode; } } /* Copy the bytes into the image */ if (state->y >= state->ysize) { state->errcode = IMAGING_CODEC_OVERRUN; return -1; } /* To squeeze some extra pixels out of this loop, we test for some common cases and handle them separately. */ /* FIXME: should we handle the transparency index in here??? */ if (i == 1) { if (state->x < state->xsize-1) { /* Single pixel, not at the end of the line. */ *out++ = p[0]; state->x++; continue; } } else if (state->x + i <= state->xsize) { /* This string fits into current line. */ memcpy(out, p, i); out += i; state->x += i; if (state->x == state->xsize) { NEWLINE(state, context); } continue; } /* No shortcut, copy pixel by pixel */ for (c = 0; c < i; c++) { *out++ = p[c]; if (++state->x >= state->xsize) { NEWLINE(state, context); } } } return ptr - buffer; } Imaging-1.1.3/libImaging/GifEncode.c0100444000076400007640000002121207442710204016763 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/GifEncode.c#2 $ * * encoder for uncompressed GIF data * * history: * 97-01-05 fl created (writes uncompressed data) * 97-08-27 fl fixed off-by-one error in buffer size test * 98-07-09 fl added interlace write support * 99-02-07 fl rewritten, now uses a run-length encoding strategy * 99-02-08 fl improved run-length encoding for long runs * * Copyright (c) Secret Labs AB 1997-99. * Copyright (c) Fredrik Lundh 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #include "Gif.h" /* codes from 0 to 255 are literals */ #define CLEAR_CODE 256 #define EOF_CODE 257 #define FIRST_CODE 258 #define LAST_CODE 511 enum { INIT, ENCODE, ENCODE_EOF, FLUSH, EXIT }; /* to make things a little less complicated, we use a simple output queue to hold completed blocks. the following inlined function adds a byte to the current block. it allocates a new block if necessary. */ static inline int emit(GIFENCODERSTATE *context, int byte) { /* write a byte to the output buffer */ if (!context->block || context->block->size == 255) { GIFENCODERBLOCK* block; /* no room in the current block (or no current block); allocate a new one */ /* add current block to end of flush queue */ if (context->block) { block = context->flush; while (block && block->next) block = block->next; if (block) block->next = context->block; else context->flush = context->block; } /* get a new block */ if (context->free) { block = context->free; context->free = NULL; } else { block = malloc(sizeof(GIFENCODERBLOCK)); if (!block) return 0; } block->size = 0; block->next = NULL; context->block = block; } /* write new byte to block */ context->block->data[context->block->size++] = byte; return 1; } /* write a code word to the current block. this is a macro to make sure it's inlined on all platforms */ #define EMIT(code) {\ context->bitbuffer |= ((INT32) (code)) << context->bitcount;\ context->bitcount += 9;\ while (context->bitcount >= 8) {\ if (!emit(context, (UINT8) context->bitbuffer)) {\ state->errcode = IMAGING_CODEC_MEMORY;\ return 0;\ }\ context->bitbuffer >>= 8;\ context->bitcount -= 8;\ }\ } /* write a run. we use a combination of literals and combinations of literals. this can give quite decent compression for images with long stretches of identical pixels. but remember: if you want really good compression, use another file format. */ #define EMIT_RUN(label) {\ label:\ while (context->count > 0) {\ int run = 2;\ EMIT(context->last);\ context->count--;\ if (state->count++ == LAST_CODE) {\ EMIT(CLEAR_CODE);\ state->count = FIRST_CODE;\ goto label;\ }\ while (context->count >= run) {\ EMIT(state->count - 1);\ context->count -= run;\ run++;\ if (state->count++ == LAST_CODE) {\ EMIT(CLEAR_CODE);\ state->count = FIRST_CODE;\ goto label;\ }\ }\ if (context->count > 1) {\ EMIT(state->count - 1 - (run - context->count));\ context->count = 0;\ if (state->count++ == LAST_CODE) {\ EMIT(CLEAR_CODE);\ state->count = FIRST_CODE;\ }\ break;\ }\ }\ } int ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { UINT8* ptr; int this; GIFENCODERBLOCK* block; GIFENCODERSTATE *context = (GIFENCODERSTATE*) state->context; if (!state->state) { /* place a clear code in the output buffer */ context->bitbuffer = CLEAR_CODE; context->bitcount = 9; state->count = FIRST_CODE; if (context->interlace) { context->interlace = 1; context->step = 8; } else context->step = 1; context->last = -1; /* sanity check */ if (state->xsize <= 0 || state->ysize <= 0) state->state = ENCODE_EOF; } ptr = buf; for (;;) switch (state->state) { case INIT: case ENCODE: /* identify and store a run of pixels */ if (state->x == 0 || state->x >= state->xsize) { if (!context->interlace && state->y >= state->ysize) { state->state = ENCODE_EOF; break; } if (context->flush) { state->state = FLUSH; break; } /* get another line of data */ state->shuffle( state->buffer, (UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->xsize ); state->x = 0; if (state->state == INIT) { /* preload the run-length buffer and get going */ context->last = state->buffer[0]; context->count = state->x = 1; state->state = ENCODE; } /* step forward, according to the interlace settings */ state->y += context->step; while (context->interlace && state->y >= state->ysize) switch (context->interlace) { case 1: state->y = 4; context->interlace = 2; break; case 2: context->step = 4; state->y = 2; context->interlace = 3; break; case 3: context->step = 2; state->y = 1; context->interlace = 0; break; default: /* just make sure we don't loop forever */ context->interlace = 0; } } this = state->buffer[state->x++]; if (this == context->last) context->count++; else { EMIT_RUN(label1); context->last = this; context->count = 1; } break; case ENCODE_EOF: /* write the final run */ EMIT_RUN(label2); /* write an end of image marker */ EMIT(EOF_CODE); /* empty the bit buffer */ while (context->bitcount > 0) { if (!emit(context, (UINT8) context->bitbuffer)) { state->errcode = IMAGING_CODEC_MEMORY; return 0; } context->bitbuffer >>= 8; context->bitcount -= 8; } /* flush the last block, and exit */ if (context->block) { GIFENCODERBLOCK* block; block = context->flush; while (block && block->next) block = block->next; if (block) block->next = context->block; else context->flush = context->block; context->block = NULL; } state->state = EXIT; /* fall through... */ case EXIT: case FLUSH: while (context->flush) { /* get a block from the flush queue */ block = context->flush; if (block->size > 0) { /* make sure it fits into the output buffer */ if (bytes < block->size+1) return ptr - buf; ptr[0] = block->size; memcpy(ptr+1, block->data, block->size); ptr += block->size+1; bytes -= block->size+1; } context->flush = block->next; if (context->free) free(context->free); context->free = block; } if (state->state == EXIT) { /* this was the last block! */ if (context->free) free(context->free); state->errcode = IMAGING_CODEC_END; return ptr - buf; } state->state = ENCODE; break; } } Imaging-1.1.3/libImaging/HexDecode.c0100444000076400007640000000216107442710204016772 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/HexDecode.c#2 $ * * decoder for hex encoded image data * * history: * 96-05-16 fl Created * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #define HEX(v) ((v >= '0' && v <= '9') ? v - '0' :\ (v >= 'a' && v <= 'f') ? v - 'a' + 10 :\ (v >= 'A' && v <= 'F') ? v - 'A' + 10 : -1) int ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { UINT8* ptr; int a, b; ptr = buf; for (;;) { if (bytes < 2) return ptr - buf; a = HEX(ptr[0]); b = HEX(ptr[1]); if (a < 0 || b < 0) { ptr++; bytes--; } else { ptr += 2; bytes -= 2; state->buffer[state->x] = (a<<4) + b; if (++state->x >= state->bytes) { /* Got a full line, unpack it */ state->shuffle((UINT8*) im->image[state->y], state->buffer, state->xsize); state->x = 0; if (++state->y >= state->ysize) { /* End of file (errcode = 0) */ return -1; } } } } } Imaging-1.1.3/libImaging/JpegDecode.c0100444000076400007640000001552107442710204017137 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/JpegDecode.c#2 $ * * decoder for JPEG image data. * * history: * 2025-05-02 fl Created * 2025-05-05 fl Handle small JPEG files correctly * 2025-05-28 fl Added "draft mode" support * 2025-01-25 fl Added colour conversion override * 2025-01-31 fl Adapted to libjpeg 6a * 2025-07-12 fl Extended YCbCr support * 2024-12-29 fl Added new state to handle suspension in multipass modes * 2025-10-12 fl Suppress warnings * 2025-12-04 fl Suppress errors beyond end of image data * * Copyright (c) 1998-2000 Secret Labs AB * Copyright (c) 1996-2000 Fredrik Lundh * * See the README file for details on usage and redistribution. */ #include "Imaging.h" #ifdef HAVE_LIBJPEG #undef HAVE_PROTOTYPES #undef HAVE_STDLIB_H #undef UINT8 #undef UINT16 #undef UINT32 #undef INT16 #undef INT32 #include "Jpeg.h" /* -------------------------------------------------------------------- */ /* Suspending input handler */ /* -------------------------------------------------------------------- */ METHODDEF(void) stub(j_decompress_ptr cinfo) { /* empty */ } METHODDEF(boolean) fill_input_buffer(j_decompress_ptr cinfo) { /* Suspension */ return FALSE; } METHODDEF(void) skip_input_data(j_decompress_ptr cinfo, long num_bytes) { JPEGSOURCE* source = (JPEGSOURCE*) cinfo->src; if (num_bytes > (long) source->pub.bytes_in_buffer) { /* We need to skip more data than we have in the buffer. This will force the JPEG library to suspend decoding. */ source->skip = num_bytes - source->pub.bytes_in_buffer; source->pub.next_input_byte += source->pub.bytes_in_buffer; source->pub.bytes_in_buffer = 0; } else { /* Skip portion of the buffer */ source->pub.bytes_in_buffer -= num_bytes; source->pub.next_input_byte += num_bytes; source->skip = 0; } } GLOBAL(void) jpeg_buffer_src(j_decompress_ptr cinfo, JPEGSOURCE* source) { cinfo->src = (void*) source; /* Prepare for suspending reader */ source->pub.init_source = stub; source->pub.fill_input_buffer = fill_input_buffer; source->pub.skip_input_data = skip_input_data; source->pub.resync_to_restart = jpeg_resync_to_restart; source->pub.term_source = stub; source->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ source->skip = 0; } /* -------------------------------------------------------------------- */ /* Error handler */ /* -------------------------------------------------------------------- */ METHODDEF(void) error(j_common_ptr cinfo) { JPEGERROR* error; error = (JPEGERROR*) cinfo->err; longjmp(error->setjmp_buffer, 1); } METHODDEF(void) output(j_common_ptr cinfo) { /* nothing */ } /* -------------------------------------------------------------------- */ /* Decoder */ /* -------------------------------------------------------------------- */ int ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { JPEGSTATE* context = (JPEGSTATE*) state->context; int ok; if (setjmp(context->error.setjmp_buffer)) { /* JPEG error handler */ jpeg_destroy_decompress(&context->cinfo); state->errcode = IMAGING_CODEC_BROKEN; return -1; } if (!state->state) { /* Setup decompression context */ context->cinfo.err = jpeg_std_error(&context->error.pub); context->error.pub.error_exit = error; context->error.pub.output_message = output; jpeg_create_decompress(&context->cinfo); jpeg_buffer_src(&context->cinfo, &context->source); /* Ready to decode */ state->state = 1; } /* Load the source buffer */ context->source.pub.next_input_byte = buf; context->source.pub.bytes_in_buffer = bytes; if (context->source.skip > 0) { skip_input_data(&context->cinfo, context->source.skip); if (context->source.skip > 0) return context->source.pub.next_input_byte - buf; } switch (state->state) { case 1: /* Read JPEG header, until we find an image body. */ do { /* Note that we cannot return unless we have decoded as much data as possible. */ ok = jpeg_read_header(&context->cinfo, FALSE); } while (ok == JPEG_HEADER_TABLES_ONLY); if (ok == JPEG_SUSPENDED) break; /* Decoder settings */ /* jpegmode indicates whats in the file; if not set, we'll trust the decoder */ if (strcmp(context->jpegmode, "L") == 0) context->cinfo.jpeg_color_space = JCS_GRAYSCALE; else if (strcmp(context->jpegmode, "RGB") == 0) context->cinfo.jpeg_color_space = JCS_RGB; else if (strcmp(context->jpegmode, "CMYK") == 0) context->cinfo.jpeg_color_space = JCS_CMYK; else if (strcmp(context->jpegmode, "YCbCr") == 0) context->cinfo.jpeg_color_space = JCS_YCbCr; else if (strcmp(context->jpegmode, "YCbCrK") == 0) { context->cinfo.jpeg_color_space = JCS_YCCK; } /* rawmode indicates what we want from the decoder. if not set, conversions are disabled */ if (strcmp(context->rawmode, "L") == 0) context->cinfo.out_color_space = JCS_GRAYSCALE; else if (strcmp(context->rawmode, "RGB") == 0) context->cinfo.out_color_space = JCS_RGB; else if (strcmp(context->rawmode, "CMYK") == 0) context->cinfo.out_color_space = JCS_CMYK; else if (strcmp(context->rawmode, "YCbCr") == 0) context->cinfo.out_color_space = JCS_YCbCr; else if (strcmp(context->rawmode, "YCbCrK") == 0) context->cinfo.out_color_space = JCS_YCCK; else { /* Disable decoder conversions */ context->cinfo.jpeg_color_space = JCS_UNKNOWN; context->cinfo.out_color_space = JCS_UNKNOWN; } if (context->scale > 1) { context->cinfo.scale_num = 1; context->cinfo.scale_denom = context->scale; } if (context->draft) { context->cinfo.do_fancy_upsampling = FALSE; context->cinfo.dct_method = JDCT_FASTEST; } state->state++; /* fall through */ case 2: /* Set things up for decompression (this processes the entire file if necessary to return data line by line) */ if (!jpeg_start_decompress(&context->cinfo)) break; state->state++; /* fall through */ case 3: /* Decompress a single line of data */ ok = 1; while (state->y < state->ysize) { ok = jpeg_read_scanlines(&context->cinfo, &state->buffer, 1); if (ok != 1) break; state->shuffle((UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->buffer, state->xsize); state->y++; } if (ok != 1) break; state->state++; /* fall through */ case 4: /* Finish decompression */ if (!jpeg_finish_decompress(&context->cinfo)) { /* FIXME: add strictness mode test */ if (state->y < state->ysize) break; } /* Clean up */ jpeg_destroy_decompress(&context->cinfo); /* if (jerr.pub.num_warnings) return BROKEN; */ return -1; } /* Return number of bytes consumed */ return context->source.pub.next_input_byte - buf; } #endif Imaging-1.1.3/libImaging/JpegEncode.c0100444000076400007640000001240407442710204017146 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/JpegEncode.c#2 $ * * coder for JPEG data * * history: * 2025-05-06 fl created * 2025-07-16 fl don't drop last block of encoded data * 2024-12-30 fl added quality and progressive settings * 2025-01-08 fl added streamtype settings * 2025-01-31 fl adapted to libjpeg 6a * 2025-07-12 fl added YCbCr support * 2025-04-16 fl added DPI write support * * Copyright (c) 1997-2001 by Secret Labs AB * Copyright (c) 1995-1997 by Fredrik Lundh * * See the README file for details on usage and redistribution. */ #include "Imaging.h" #ifdef HAVE_LIBJPEG #undef HAVE_PROTOTYPES #undef HAVE_STDLIB_H #undef UINT8 #undef UINT16 #undef UINT32 #undef INT16 #undef INT32 #include "Jpeg.h" /* -------------------------------------------------------------------- */ /* Suspending output handler */ /* -------------------------------------------------------------------- */ METHODDEF(void) stub(j_compress_ptr cinfo) { /* empty */ } METHODDEF(boolean) empty_output_buffer (j_compress_ptr cinfo) { /* Suspension */ return FALSE; } GLOBAL(void) jpeg_buffer_dest(j_compress_ptr cinfo, JPEGDESTINATION* destination) { cinfo->dest = (void*) destination; destination->pub.init_destination = stub; destination->pub.empty_output_buffer = empty_output_buffer; destination->pub.term_destination = stub; } /* -------------------------------------------------------------------- */ /* Error handler */ /* -------------------------------------------------------------------- */ METHODDEF(void) error(j_common_ptr cinfo) { JPEGERROR* error; error = (JPEGERROR*) cinfo->err; (*cinfo->err->output_message) (cinfo); longjmp(error->setjmp_buffer, 1); } /* -------------------------------------------------------------------- */ /* Encoder */ /* -------------------------------------------------------------------- */ int ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { JPEGENCODERSTATE* context = (JPEGENCODERSTATE*) state->context; int ok; if (setjmp(context->error.setjmp_buffer)) { /* JPEG error handler */ jpeg_destroy_compress(&context->cinfo); state->errcode = IMAGING_CODEC_BROKEN; return -1; } if (!state->state) { /* Setup compression context (very similar to the decoder) */ context->cinfo.err = jpeg_std_error(&context->error.pub); context->error.pub.error_exit = error; jpeg_create_compress(&context->cinfo); jpeg_buffer_dest(&context->cinfo, &context->destination); /* Ready to encode */ state->state = 1; } /* Load the destination buffer */ context->destination.pub.next_output_byte = buf; context->destination.pub.free_in_buffer = bytes; switch (state->state) { case 1: context->cinfo.image_width = state->xsize; context->cinfo.image_height = state->ysize; switch (state->bits) { case 8: context->cinfo.input_components = 1; context->cinfo.in_color_space = JCS_GRAYSCALE; break; case 24: context->cinfo.input_components = 3; if (strcmp(im->mode, "YCbCr") == 0) context->cinfo.in_color_space = JCS_YCbCr; else context->cinfo.in_color_space = JCS_RGB; break; case 32: context->cinfo.input_components = 4; context->cinfo.in_color_space = JCS_CMYK; break; default: state->errcode = IMAGING_CODEC_CONFIG; return -1; } /* Compressor configuration */ jpeg_set_defaults(&context->cinfo); if (context->quality > 0) jpeg_set_quality(&context->cinfo, context->quality, 1); if (context->progressive) jpeg_simple_progression(&context->cinfo); context->cinfo.smoothing_factor = context->smooth; context->cinfo.optimize_coding = (boolean) context->optimize; if (context->xdpi > 0 && context->ydpi > 0) { context->cinfo.density_unit = 1; /* dots per inch */ context->cinfo.X_density = context->xdpi; context->cinfo.Y_density = context->ydpi; } switch (context->streamtype) { case 1: /* tables only -- not yet implemented */ state->errcode = IMAGING_CODEC_CONFIG; return -1; case 2: /* image only */ jpeg_suppress_tables(&context->cinfo, TRUE); jpeg_start_compress(&context->cinfo, FALSE); break; default: /* interchange stream */ jpeg_start_compress(&context->cinfo, TRUE); break; } state->state++; /* fall through */ case 2: ok = 1; while (state->y < state->ysize) { state->shuffle(state->buffer, (UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->xsize); ok = jpeg_write_scanlines(&context->cinfo, &state->buffer, 1); if (ok != 1) break; state->y++; } if (ok != 1) break; state->state++; /* fall through */ case 3: /* Finish compression */ if (context->destination.pub.free_in_buffer < 100) break; jpeg_finish_compress(&context->cinfo); /* Clean up */ jpeg_destroy_compress(&context->cinfo); /* if (jerr.pub.num_warnings) return BROKEN; */ state->errcode = IMAGING_CODEC_END; break; } /* Return number of bytes in output buffer */ return context->destination.pub.next_output_byte - buf; } #endif Imaging-1.1.3/libImaging/LzwDecode.c0100444000076400007640000001202707442710204017024 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/LzwDecode.c#2 $ * * a fast, suspendable TIFF LZW decoder * * description: * This code is based on the GIF decoder. There are some * subtle differences between GIF and TIFF LZW, though: * - The fill order is different. In the TIFF file, you * must shift new bits in to the right, not to the left. * - There is no blocking in the input data stream. * - The code size is increased one step earlier than * for GIF * - Image data are seen as a byte stream, not a pixel * stream. This means that the code size will always * start at 9 bits. * * history: * 95-09-13 fl Created (derived from GifDecode.c) * 96-03-28 fl Revised API, integrated with PIL * 97-01-05 fl Added filter support, added extra consistency checks * * Copyright (c) Fredrik Lundh 1995-97. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include #include /* memcpy() */ #include "Imaging.h" #include "Lzw.h" int ImagingLzwDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { UINT8* p; int c, i; int thiscode; LZWSTATE* context = (LZWSTATE*) state->context; unsigned char *ptr = buf; if (!state->state) { /* Clear code */ context->clear = 1 << 8; /* End code */ context->end = context->clear + 1; state->state = 1; } for (;;) { if (state->state == 1) { /* First free entry in table */ context->next = context->clear + 2; /* Initial code size */ context->codesize = 8 + 1; context->codemask = (1 << context->codesize) - 1; /* Buffer pointer. We fill the buffer from right, which allows us to return all of it in one operation. */ context->bufferindex = LZWBUFFER; state->state = 2; } if (context->bufferindex < LZWBUFFER) { /* Return whole buffer in one chunk */ i = LZWBUFFER - context->bufferindex; p = &context->buffer[context->bufferindex]; context->bufferindex = LZWBUFFER; } else { /* Get current symbol */ while (context->bitcount < context->codesize) { if (bytes < 1) return ptr - buf;; /* Read next byte */ c = *ptr++; bytes--; /* New bits are shifted in from from the right. */ context->bitbuffer = (context->bitbuffer << 8) | c; context->bitcount += 8; } /* Extract current symbol from bit buffer. */ c = (context->bitbuffer >> (context->bitcount - context->codesize)) & context->codemask; /* Adjust buffer */ context->bitcount -= context->codesize; /* If c is less than clear, it's a data byte. Otherwise, it's either clear/end or a code symbol which should be expanded. */ if (c == context->clear) { if (state->state != 2) state->state = 1; continue; } if (c == context->end) break; i = 1; p = &context->lastdata; if (state->state == 2) { /* First valid symbol after clear; use as is */ if (c > context->clear) { state->errcode = IMAGING_CODEC_BROKEN; return -1; } context->lastdata = context->lastcode = c; state->state = 3; } else { thiscode = c; if (c > context->next) { state->errcode = IMAGING_CODEC_BROKEN; return -1; } if (c == context->next) { /* c == next is allowed, by some strange reason */ if (context->bufferindex <= 0) { state->errcode = IMAGING_CODEC_BROKEN; return -1; } context->buffer[--context->bufferindex] = context->lastdata; c = context->lastcode; } while (c >= context->clear) { /* Copy data string to buffer (beginning from right) */ if (context->bufferindex <= 0 || c >= LZWTABLE) { state->errcode = IMAGING_CODEC_BROKEN; return -1; } context->buffer[--context->bufferindex] = context->data[c]; c = context->link[c]; } context->lastdata = c; if (context->next < LZWTABLE) { /* While we still have room for it, add this symbol to the table. */ context->data[context->next] = c; context->link[context->next] = context->lastcode; context->next++; if (context->next == context->codemask && context->codesize < LZWBITS) { /* Expand code size */ context->codesize++; context->codemask = (1 << context->codesize) - 1; } } context->lastcode = thiscode; } } /* Update the output image */ for (c = 0; c < i; c++) { state->buffer[state->x] = p[c]; if (++state->x >= state->bytes) { int x, bpp; /* Apply filter */ switch (context->filter) { case 2: /* Horizontal differing ("prior") */ bpp = (state->bits + 7) / 8; for (x = bpp; x < state->bytes; x++) state->buffer[x] += state->buffer[x-bpp]; } /* Got a full line, unpack it */ state->shuffle((UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->buffer, state->xsize); state->x = 0; if (++state->y >= state->ysize) /* End of file (errcode = 0) */ return -1; } } } return ptr - buf; } Imaging-1.1.3/libImaging/MspDecode.c0100444000076400007640000000271107442710204017006 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/MspDecode.c#2 $ * * decoder for MSP version 2 data. * * history: * 97-01-03 fl Created * * Copyright (c) Fredrik Lundh 1997. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" int ImagingMspDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { int n; UINT8* ptr; ptr = buf; for (;;) { if (bytes < 1) return ptr - buf; if (ptr[0] == 0) { /* Run (3 bytes block) */ if (bytes < 3) break; n = ptr[1]; if (state->x + n > state->bytes) { state->errcode = IMAGING_CODEC_OVERRUN; return -1; } memset(state->buffer + state->x, ptr[2], n); ptr += 3; bytes -= 3; } else { /* Literal (1+n bytes block) */ n = ptr[0]; if (bytes < 1 + n) break; if (state->x + n > state->bytes) { state->errcode = IMAGING_CODEC_OVERRUN; return -1; } memcpy(state->buffer + state->x, ptr + 1, n); ptr += 1 + n; bytes -= 1 + n; } state->x += n; if (state->x >= state->bytes) { /* Got a full line, unpack it */ state->shuffle((UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->buffer, state->xsize); state->x = 0; if (++state->y >= state->ysize) { /* End of file (errcode = 0) */ return -1; } } } return ptr - buf; } Imaging-1.1.3/libImaging/PackDecode.c0100444000076400007640000000302707442710204017126 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/PackDecode.c#2 $ * * decoder for PackBits image data. * * history: * 96-04-19 fl Created * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" int ImagingPackbitsDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { UINT8 n; UINT8* ptr; int i; ptr = buf; for (;;) { if (bytes < 1) return ptr - buf; if (ptr[0] & 0x80) { if (ptr[0] == 0x80) { /* Nop */ ptr++; bytes--; continue; } /* Run */ if (bytes < 2) return ptr - buf; for (n = 257 - ptr[0]; n > 0; n--) { if (state->x >= state->bytes) { /* state->errcode = IMAGING_CODEC_OVERRUN; */ break; } state->buffer[state->x++] = ptr[1]; } ptr += 2; bytes -= 2; } else { /* Literal */ n = ptr[0]+2; if (bytes < n) return ptr - buf; for (i = 1; i < n; i++) { if (state->x >= state->bytes) { /* state->errcode = IMAGING_CODEC_OVERRUN; */ break; } state->buffer[state->x++] = ptr[i]; } ptr += n; bytes -= n; } if (state->x >= state->bytes) { /* Got a full line, unpack it */ state->shuffle((UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->buffer, state->xsize); state->x = 0; if (++state->y >= state->ysize) { /* End of file (errcode = 0) */ return -1; } } } } Imaging-1.1.3/libImaging/PcdDecode.c0100444000076400007640000000307407442710204016760 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/PcdDecode.c#2 $ * * decoder for uncompressed PCD image data. * * history: * 96-05-10 fl Created * 96-05-18 fl New tables * 97-01-25 fl Use PhotoYCC unpacker * * notes: * This driver supports uncompressed PCD modes only * (resolutions up to 768x512). * * Copyright (c) Fredrik Lundh 1996-97. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" int ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { int x; int chunk; UINT8* out; UINT8* ptr; ptr = buf; chunk = 3 * state->xsize; for (;;) { /* We need data for two full lines before we can do anything */ if (bytes < chunk) return ptr - buf; /* Unpack first line */ out = state->buffer; for (x = 0; x < state->xsize; x++) { out[0] = ptr[x]; out[1] = ptr[(x+4*state->xsize)/2]; out[2] = ptr[(x+5*state->xsize)/2]; out += 4; } state->shuffle((UINT8*) im->image[state->y], state->buffer, state->xsize); if (++state->y >= state->ysize) return -1; /* This can hardly happen */ /* Unpack second line */ out = state->buffer; for (x = 0; x < state->xsize; x++) { out[0] = ptr[x+state->xsize]; out[1] = ptr[(x+4*state->xsize)/2]; out[2] = ptr[(x+5*state->xsize)/2]; out += 4; } state->shuffle((UINT8*) im->image[state->y], state->buffer, state->xsize); if (++state->y >= state->ysize) return -1; ptr += chunk; bytes -= chunk; } } Imaging-1.1.3/libImaging/PcxEncode.c0100444000076400007640000000722707442710204017022 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/PcxEncode.c#2 $ * * encoder for PCX data * * history: * 99-02-07 fl created * * Copyright (c) Fredrik Lundh 1999. * Copyright (c) Secret Labs AB 1999. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" enum { INIT, FETCH, ENCODE }; /* we're reusing "ystep" to store the last value */ #define LAST ystep int ImagingPcxEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { UINT8* ptr; int this; ptr = buf; if (!state->state) { /* sanity check */ if (state->xsize <= 0 || state->ysize <= 0) { state->errcode = IMAGING_CODEC_END; return 0; } state->bytes = (state->xsize*state->bits + 7) / 8; state->state = FETCH; } for (;;) switch (state->state) { case FETCH: /* get a line of data */ if (state->y >= state->ysize) { state->errcode = IMAGING_CODEC_END; return ptr - buf; } state->shuffle(state->buffer, (UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->xsize); state->y++; state->count = 1; state->LAST = state->buffer[0]; state->x = 1; state->state = ENCODE; /* fall through */ case ENCODE: /* compress this line */ /* when we arrive here, "count" contains the number of bytes having the value of "LAST" that we've already seen */ while (state->x < state->bytes) { if (state->count == 63) { /* this run is full; flush it */ if (bytes < 2) return ptr - buf; *ptr++ = 0xff; *ptr++ = state->LAST; bytes -= 2; state->count = 0; } this = state->buffer[state->x]; if (this == state->LAST) { /* extend the current run */ state->x++; state->count++; } else { /* start a new run */ if (state->count == 1 && (state->LAST < 0xc0)) { if (bytes < 1) return ptr - buf; *ptr++ = state->LAST; bytes--; } else { if (state->count > 0) { if (bytes < 2) return ptr - buf; *ptr++ = 0xc0 | state->count; *ptr++ = state->LAST; bytes -= 2; } } state->LAST = this; state->count = 1; state->x++; } } /* end of line; flush the current run */ if (state->count == 1 && (state->LAST < 0xc0)) { if (bytes < 1) return ptr - buf; *ptr++ = state->LAST; bytes--; } else { if (state->count > 0) { if (bytes < 2) return ptr - buf; *ptr++ = 0xc0 | state->count; *ptr++ = state->LAST; bytes -= 2; } } /* read next line */ state->state = FETCH; break; } } Imaging-1.1.3/libImaging/PcxDecode.c0100444000076400007640000000236007442710204017001 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/PcxDecode.c#2 $ * * decoder for PCX image data. * * history: * 95-09-14 fl Created * * Copyright (c) Fredrik Lundh 1995. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" int ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { UINT8 n; UINT8* ptr; ptr = buf; for (;;) { if (bytes < 1) return ptr - buf; if ((*ptr & 0xC0) == 0xC0) { /* Run */ if (bytes < 2) return ptr - buf; n = ptr[0] & 0x3F; while (n > 0) { if (state->x >= state->bytes) { state->errcode = IMAGING_CODEC_OVERRUN; break; } state->buffer[state->x++] = ptr[1]; n--; } ptr += 2; bytes -= 2; } else { /* Literal */ state->buffer[state->x++] = ptr[0]; ptr++; bytes--; } if (state->x >= state->bytes) { /* Got a full line, unpack it */ state->shuffle((UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->buffer, state->xsize); state->x = 0; if (++state->y >= state->ysize) { /* End of file (errcode = 0) */ return -1; } } } } Imaging-1.1.3/libImaging/RawDecode.c0100444000076400007640000000310607442710204016777 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/RawDecode.c#2 $ * * decoder for raw (uncompressed) image data * * history: * 96-03-07 fl rewritten * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #include "Raw.h" int ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { enum { LINE = 1, SKIP }; RAWSTATE* rawstate = state->context; UINT8* ptr; if (state->state == 0) { /* Initialize context variables */ /* get size of image data and padding */ state->bytes = (state->xsize * state->bits + 7) / 8; rawstate->skip = (rawstate->stride) ? rawstate->stride - state->bytes : 0; /* check image orientation */ if (state->ystep < 0) { state->y = state->ysize-1; state->ystep = -1; } else state->ystep = 1; state->state = LINE; } ptr = buf; for (;;) { if (state->state == SKIP) { /* Skip padding between lines */ if (bytes < rawstate->skip) return ptr - buf; ptr += rawstate->skip; bytes -= rawstate->skip; state->state = LINE; } if (bytes < state->bytes) return ptr - buf; /* Unpack data */ state->shuffle((UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, ptr, state->xsize); ptr += state->bytes; bytes -= state->bytes; state->y += state->ystep; if (state->y < 0 || state->y >= state->ysize) { /* End of file (errcode = 0) */ return -1; } state->state = SKIP; } } Imaging-1.1.3/libImaging/RawEncode.c0100444000076400007640000000363107442710204017014 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/RawEncode.c#2 $ * * coder for raw data * * FIXME: This encoder will fail if the buffer is not large enough to * hold one full line of data. There's a workaround for this problem * in ImageFile.py, but it should be solved here instead. * * history: * 96-04-30 fl created * 97-01-03 fl fixed padding * * Copyright (c) Fredrik Lundh 1996-97. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" int ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { UINT8* ptr; if (!state->state) { /* The "count" field holds the stride, if specified. Fix things up so "bytes" is the full size, and "count" the packed size */ if (state->count > 0) { int bytes = state->count; /* stride must not be less than real size */ if (state->count < state->bytes) { state->errcode = IMAGING_CODEC_CONFIG; return -1; } state->count = state->bytes; state->bytes = bytes; } else state->count = state->bytes; /* The "ystep" field specifies the orientation */ if (state->ystep < 0) { state->y = state->ysize-1; state->ystep = -1; } else state->ystep = 1; state->state = 1; } if (bytes < state->bytes) { state->errcode = IMAGING_CODEC_CONFIG; return 0; } ptr = buf; while (bytes >= state->bytes) { state->shuffle(ptr, (UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->xsize); if (state->bytes > state->count) /* zero-pad the buffer, if necessary */ memset(ptr + state->count, 0, state->bytes - state->count); ptr += state->bytes; bytes -= state->bytes; state->y += state->ystep; if (state->y < 0 || state->y >= state->ysize) { state->errcode = IMAGING_CODEC_END; break; } } return ptr - buf; } Imaging-1.1.3/libImaging/SunRleDecode.c0100444000076400007640000000332207442710204017456 0ustar fredrikfredrik/* * THIS IS WORK IN PROGRESS * * The Python Imaging Library. * $Id: //modules/pil/libImaging/SunRleDecode.c#2 $ * * decoder for SUN RLE data. * * history: * 97-01-04 fl Created * * Copyright (c) Fredrik Lundh 1997. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" int ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { int n; UINT8* ptr; ptr = buf; for (;;) { if (bytes < 1) return ptr - buf; if (ptr[0] == 0x80) { if (bytes < 2) break; n = ptr[1]; if (n == 0) { /* Literal 0x80 (2 bytes) */ n = 1; state->buffer[state->x] = 0x80; ptr += 2; bytes -= 2; } else { /* Run (3 bytes) */ if (bytes < 3) break; if (state->x + n > state->bytes) { /* FIXME: is this correct? */ state->errcode = IMAGING_CODEC_OVERRUN; return -1; } memset(state->buffer + state->x, ptr[2], n); ptr += 3; bytes -= 3; } } else { /* Literal (1+n bytes block) */ n = ptr[0]; if (bytes < 1 + n) break; if (state->x + n > state->bytes) { /* FIXME: is this correct? */ state->errcode = IMAGING_CODEC_OVERRUN; return -1; } memcpy(state->buffer + state->x, ptr + 1, n); ptr += 1 + n; bytes -= 1 + n; } state->x += n; if (state->x >= state->bytes) { /* Got a full line, unpack it */ state->shuffle((UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->buffer, state->xsize); state->x = 0; if (++state->y >= state->ysize) { /* End of file (errcode = 0) */ return -1; } } } return ptr - buf; } Imaging-1.1.3/libImaging/TgaRleDecode.c0100444000076400007640000000421307442710204017424 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/TgaRleDecode.c#2 $ * * decoder for Targa RLE data. * * history: * 97-01-04 fl created * 98-09-11 fl don't one byte per pixel; take orientation into account * * Copyright (c) Fredrik Lundh 1997. * Copyright (c) Secret Labs AB 1997-98. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" int ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { int n, depth; UINT8* ptr; ptr = buf; if (state->state == 0) { /* check image orientation */ if (state->ystep < 0) { state->y = state->ysize-1; state->ystep = -1; } else state->ystep = 1; state->state = 1; } depth = state->count; for (;;) { if (bytes < 1) return ptr - buf; if (ptr[0] & 0x80) { /* Run (1 + pixelsize bytes) */ if (bytes < 1 + depth) break; n = depth * ((ptr[0] & 0x7f) + 1); if (state->x + n > state->bytes) { state->errcode = IMAGING_CODEC_OVERRUN; return -1; } if (depth == 1) memset(state->buffer + state->x, ptr[1], n); else { int i; for (i = 0; i < n; i += depth) memcpy(state->buffer + state->x + i, ptr+1, depth); } ptr += 1 + depth; bytes -= 1 + depth; } else { /* Literal (1+n+1 bytes block) */ n = depth * (ptr[0] + 1); if (bytes < 1 + n) break; if (state->x + n > state->bytes) { state->errcode = IMAGING_CODEC_OVERRUN; return -1; } memcpy(state->buffer + state->x, ptr + 1, n); ptr += 1 + n; bytes -= 1 + n; } state->x += n; if (state->x >= state->bytes) { /* Got a full line, unpack it */ state->shuffle((UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->buffer, state->xsize); state->x = 0; state->y += state->ystep; if (state->y < 0 || state->y >= state->ysize) { /* End of file (errcode = 0) */ return -1; } } } return ptr - buf; } Imaging-1.1.3/libImaging/XbmDecode.c0100444000076400007640000000250307442710204016774 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/XbmDecode.c#2 $ * * decoder for XBM hex image data * * history: * 96-04-13 fl Created * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #define HEX(v) ((v >= '0' && v <= '9') ? v - '0' :\ (v >= 'a' && v <= 'f') ? v - 'a' + 10 :\ (v >= 'A' && v <= 'F') ? v - 'A' + 10 : 0) int ImagingXbmDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { enum { BYTE = 1, SKIP }; UINT8* ptr; if (!state->state) state->state = SKIP; ptr = buf; for (;;) { if (state->state == SKIP) { /* Skip forward until next 'x' */ while (bytes > 0) { if (*ptr == 'x') break; ptr++; bytes--; } if (bytes == 0) return ptr - buf; state->state = BYTE; } if (bytes < 3) return ptr - buf; state->buffer[state->x] = (HEX(ptr[1])<<4) + HEX(ptr[2]); if (++state->x >= state->bytes) { /* Got a full line, unpack it */ state->shuffle((UINT8*) im->image[state->y], state->buffer, state->xsize); state->x = 0; if (++state->y >= state->ysize) { /* End of file (errcode = 0) */ return -1; } } ptr += 3; bytes -= 3; state->state = SKIP; } } Imaging-1.1.3/libImaging/XbmEncode.c0100444000076400007640000000334107442710204017007 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/XbmEncode.c#2 $ * * encoder for Xbm data * * history: * 96-11-01 fl created * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" int ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { const char *hex = "0123456789abcdef"; UINT8* ptr = buf; int i, n; if (!state->state) { /* 8 pixels are stored in no more than 6 bytes */ state->bytes = 6*(state->xsize+7)/8; state->state = 1; } if (bytes < state->bytes) { state->errcode = IMAGING_CODEC_MEMORY; return 0; } ptr = buf; while (bytes >= state->bytes) { state->shuffle(state->buffer, (UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->xsize); if (state->y < state->ysize-1) { /* any line but the last */ for (n = 0; n < state->xsize; n += 8) { i = state->buffer[n/8]; *ptr++ = '0'; *ptr++ = 'x'; *ptr++ = hex[(i>>4)&15]; *ptr++ = hex[i&15]; *ptr++ = ','; bytes -= 5; if (++state->count >= 79/5) { *ptr++ = '\n'; bytes--; state->count = 0; } } state->y++; } else { /* last line */ for (n = 0; n < state->xsize; n += 8) { i = state->buffer[n/8]; *ptr++ = '0'; *ptr++ = 'x'; *ptr++ = hex[(i>>4)&15]; *ptr++ = hex[i&15]; if (n < state->xsize-8) { *ptr++ = ','; if (++state->count >= 79/5) { *ptr++ = '\n'; bytes--; state->count = 0; } } else *ptr++ = '\n'; bytes -= 5; } state->errcode = IMAGING_CODEC_END; break; } } return ptr - buf; } Imaging-1.1.3/libImaging/ZipDecode.c0100444000076400007640000001212107442710204017005 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/ZipDecode.c#3 $ * * decoder for ZIP (deflated) image data. * * history: * 2025-12-14 fl Created (for PNG) * 2025-01-15 fl Prepared to read TIFF/ZIP * 2025-11-19 fl PNG incomplete read patch (from Bernhard Herzog) * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997-2001. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #ifdef HAVE_LIBZ #include "Zip.h" /* -------------------------------------------------------------------- */ /* Decoder */ /* -------------------------------------------------------------------- */ int ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { ZIPSTATE* context = (ZIPSTATE*) state->context; int err; int n; UINT8* ptr; int i, bpp; if (!state->state) { /* Initialization */ if (context->mode == ZIP_PNG || context->mode == ZIP_PNG_PALETTE) context->prefix = 1; /* PNG */ /* Expand standard buffer to make room for the (optional) filter prefix, and allocate a buffer to hold the previous line */ free(state->buffer); state->buffer = (UINT8*) malloc(state->bytes+1); context->previous = (UINT8*) malloc(state->bytes+1); if (!state->buffer || !context->previous) { state->errcode = IMAGING_CODEC_MEMORY; return -1; } context->last_output = 0; /* Initialize to black */ memset(context->previous, 0, state->bytes+1); /* Setup decompression context */ context->z_stream.zalloc = (alloc_func)0; context->z_stream.zfree = (free_func)0; context->z_stream.opaque = (voidpf)0; err = inflateInit(&context->z_stream); if (err < 0) { state->errcode = IMAGING_CODEC_CONFIG; return -1; } /* Ready to decode */ state->state = 1; } /* Setup the source buffer */ context->z_stream.next_in = buf; context->z_stream.avail_in = bytes; /* Decompress what we've got this far */ while (context->z_stream.avail_in > 0) { context->z_stream.next_out = state->buffer + context->last_output; context->z_stream.avail_out = state->bytes + context->prefix - context->last_output; err = inflate(&context->z_stream, Z_NO_FLUSH); if (err < 0) { /* Something went wrong inside the compression library */ if (err == Z_DATA_ERROR) state->errcode = IMAGING_CODEC_BROKEN; else if (err == Z_MEM_ERROR) state->errcode = IMAGING_CODEC_MEMORY; else state->errcode = IMAGING_CODEC_CONFIG; free(context->previous); inflateEnd(&context->z_stream); return -1; } n = state->bytes + context->prefix - context->z_stream.avail_out; if (n < state->bytes + context->prefix) { context->last_output = n; break; /* need more input data */ } /* Apply predictor */ switch (context->mode) { case ZIP_PNG: switch (state->buffer[0]) { case 0: break; case 1: /* prior */ bpp = (state->bits + 7) / 8; for (i = bpp+1; i <= state->bytes; i++) state->buffer[i] += state->buffer[i-bpp]; break; case 2: /* up */ for (i = 1; i <= state->bytes; i++) state->buffer[i] += context->previous[i]; break; case 3: /* average */ bpp = (state->bits + 7) / 8; for (i = 1; i <= bpp; i++) state->buffer[i] += context->previous[i]/2; for (; i <= state->bytes; i++) state->buffer[i] += (state->buffer[i-bpp] + context->previous[i])/2; break; case 4: /* paeth filtering */ bpp = (state->bits + 7) / 8; for (i = 1; i <= bpp; i++) state->buffer[i] += context->previous[i]; for (; i <= state->bytes; i++) { int a, b, c; int pa, pb, pc; /* fetch pixels */ a = state->buffer[i-bpp]; b = context->previous[i]; c = context->previous[i-bpp]; /* distances to surrounding pixels */ pa = abs(b - c); pb = abs(a - c); pc = abs(a + b - 2*c); /* pick predictor with the shortest distance */ state->buffer[i] += (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c; } break; default: state->errcode = IMAGING_CODEC_UNKNOWN; free(context->previous); inflateEnd(&context->z_stream); return -1; } break; case ZIP_TIFF_PREDICTOR: bpp = (state->bits + 7) / 8; for (i = bpp+1; i <= state->bytes; i++) state->buffer[i] += state->buffer[i-bpp]; break; } /* Stuff data into the image */ state->shuffle((UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->buffer + context->prefix, state->xsize); state->y++; /* all inflate output has been consumed */ context->last_output = 0; if (state->y >= state->ysize || err == Z_STREAM_END) { /* The image and the data should end simultaneously */ /* if (state->y < state->ysize || err != Z_STREAM_END) state->errcode = IMAGING_CODEC_BROKEN; */ free(context->previous); inflateEnd(&context->z_stream); return -1; /* end of file (errcode=0) */ } /* Swap buffer pointers */ ptr = state->buffer; state->buffer = context->previous; context->previous = ptr; } return bytes; /* consumed all of it */ } #endif Imaging-1.1.3/libImaging/ZipEncode.c0100444000076400007640000001727407442710204017035 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/ZipEncode.c#2 $ * * coder for ZIP (deflated) image data * * History: * 96-12-29 fl created * 96-12-30 fl adaptive filter selection, encoder tuning * * Copyright (c) Fredrik Lundh 1996. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include "Imaging.h" #ifdef HAVE_LIBZ #include "Zip.h" int ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) { ZIPSTATE* context = (ZIPSTATE*) state->context; int err; UINT8* ptr; int i, bpp, s, sum; if (!state->state) { /* Initialization */ /* Valid modes are ZIP_PNG, ZIP_PNG_PALETTE, and ZIP_TIFF */ /* Expand standard buffer to make room for the filter selector, and allocate filter buffers */ free(state->buffer); state->buffer = (UINT8*) malloc(state->bytes+1); context->previous = (UINT8*) malloc(state->bytes+1); context->prior = (UINT8*) malloc(state->bytes+1); context->up = (UINT8*) malloc(state->bytes+1); context->average = (UINT8*) malloc(state->bytes+1); context->paeth = (UINT8*) malloc(state->bytes+1); if (!state->buffer || !context->previous || !context->prior || !context->up || !context->average || !context->paeth) { free(context->paeth); free(context->average); free(context->up); free(context->prior); free(context->previous); state->errcode = IMAGING_CODEC_MEMORY; return -1; } /* Initalise filter buffers */ state->buffer[0] = 0; context->prior[0] = 1; context->up[0] = 2; context->average[0] = 3; context->paeth[0] = 4; /* Initialise previous buffer to black */ memset(context->previous, 0, state->bytes+1); /* Setup compression context */ context->z_stream.zalloc = (alloc_func)0; context->z_stream.zfree = (free_func)0; context->z_stream.opaque = (voidpf)0; err = deflateInit2(&context->z_stream, /* compression level */ (context->optimize) ? Z_BEST_COMPRESSION : Z_DEFAULT_COMPRESSION, /* compression method */ Z_DEFLATED, /* compression memory resources */ 15, 9, /* compression strategy (image data are filtered)*/ (context->mode == ZIP_PNG) ? Z_FILTERED : Z_DEFAULT_STRATEGY); if (err < 0) { state->errcode = IMAGING_CODEC_CONFIG; return -1; } if (context->dictionary && context->dictionary_size > 0) { err = deflateSetDictionary(&context->z_stream, (unsigned char *)context->dictionary, context->dictionary_size); if (err < 0) { state->errcode = IMAGING_CODEC_CONFIG; return -1; } } /* Ready to decode */ state->state = 1; } /* Setup the destination buffer */ context->z_stream.next_out = buf; context->z_stream.avail_out = bytes; for (;;) { switch (state->state) { case 1: /* Compress image data */ while (context->z_stream.avail_out > 0) { if (state->y >= state->ysize) { /* End of image; now flush compressor buffers */ state->state = 2; break; } /* Stuff image data into the compressor */ state->shuffle(state->buffer+1, (UINT8*) im->image[state->y + state->yoff] + state->xoff * im->pixelsize, state->xsize); state->y++; context->output = state->buffer; if (context->mode == ZIP_PNG) { /* Filter the image data. For each line, select the filter that gives the least total distance from zero for the filtered data (taken from LIBPNG) */ bpp = (state->bits + 7) / 8; /* 0. No filter */ for (i = 1, sum = 0; i <= state->bytes; i++) { UINT8 v = state->buffer[i]; sum += (v < 128) ? v : 256 - v; } /* 2. Up. We'll test this first to save time when an image line is identical to the one above. */ if (sum > 0) { for (i = 1, s = 0; i <= state->bytes; i++) { UINT8 v = state->buffer[i] - context->previous[i]; context->up[i] = v; s += (v < 128) ? v : 256 - v; } if (s < sum) { context->output = context->up; sum = s; /* 0 if line was duplicated */ } } /* 1. Prior */ if (sum > 0) { for (i = 1, s = 0; i <= bpp; i++) { UINT8 v = state->buffer[i]; context->prior[i] = v; s += (v < 128) ? v : 256 - v; } for (; i <= state->bytes; i++) { UINT8 v = state->buffer[i] - state->buffer[i-bpp]; context->prior[i] = v; s += (v < 128) ? v : 256 - v; } if (s < sum) { context->output = context->prior; sum = s; /* 0 if line is solid */ } } /* 3. Average (not very common in real-life images, so its only used with the optimize option) */ if (context->optimize && sum > 0) { for (i = 1, s = 0; i <= bpp; i++) { UINT8 v = state->buffer[i] - context->previous[i]/2; context->average[i] = v; s += (v < 128) ? v : 256 - v; } for (; i <= state->bytes; i++) { UINT8 v = state->buffer[i] - (state->buffer[i-bpp] + context->previous[i])/2; context->average[i] = v; s += (v < 128) ? v : 256 - v; } if (s < sum) { context->output = context->average; sum = s; } } /* 4. Paeth */ if (sum > 0) { for (i = 1, s = 0; i <= bpp; i++) { UINT8 v = state->buffer[i] - context->previous[i]; context->paeth[i] = v; s += (v < 128) ? v : 256 - v; } for (; i <= state->bytes; i++) { UINT8 v; int a, b, c; int pa, pb, pc; /* fetch pixels */ a = state->buffer[i-bpp]; b = context->previous[i]; c = context->previous[i-bpp]; /* distances to surrounding pixels */ pa = abs(b - c); pb = abs(a - c); pc = abs(a + b - 2*c); /* pick predictor with the shortest distance */ v = state->buffer[i] - ((pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c); context->paeth[i] = v; s += (v < 128) ? v : 256 - v; } if (s < sum) { context->output = context->paeth; sum = s; } } } /* Compress this line */ context->z_stream.next_in = context->output; context->z_stream.avail_in = state->bytes+1; /* err = deflate(&context->z_stream, Z_NO_FLUSH); */ /* FIXME: temporary workaround for problem with recent versions of zlib -- 990709/fl */ err = deflate(&context->z_stream, Z_SYNC_FLUSH); if (err < 0) { /* Something went wrong inside the compression library */ if (err == Z_DATA_ERROR) state->errcode = IMAGING_CODEC_BROKEN; else if (err == Z_MEM_ERROR) state->errcode = IMAGING_CODEC_MEMORY; else state->errcode = IMAGING_CODEC_CONFIG; free(context->paeth); free(context->average); free(context->up); free(context->prior); free(context->previous); deflateEnd(&context->z_stream); return -1; } /* Swap buffer pointers */ ptr = state->buffer; state->buffer = context->previous; context->previous = ptr; } if (context->z_stream.avail_out == 0) break; /* Buffer full */ case 2: /* End of image data; flush compressor buffers */ while (context->z_stream.avail_out > 0) { err = deflate(&context->z_stream, Z_FINISH); if (err == Z_STREAM_END) { free(context->paeth); free(context->average); free(context->up); free(context->prior); free(context->previous); deflateEnd(&context->z_stream); state->errcode = IMAGING_CODEC_END; break; } if (context->z_stream.avail_out == 0) break; /* Buffer full */ } } return bytes - context->z_stream.avail_out; } /* Should never ever arrive here... */ state->errcode = IMAGING_CODEC_CONFIG; return -1; } #endif Imaging-1.1.3/libImaging/coretest.c0100444000076400007640000000326107442710204016774 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/libImaging/coretest.c#2 $ * * minimal test hack for the core library * * history: * 95-11-26 fl: Created * * Copyright (c) Fredrik Lundh 1995. * Copyright (c) Secret Labs AB 1997. * * See the README file for information on usage and redistribution. */ #include /* clock() */ #include "Imaging.h" #ifdef macintosh #define TESTFILE "::Images:lena.ppm" #else #define TESTFILE "../Images/lena.ppm" #endif /* macintosh */ int main() { Imaging im, im1, im2, im3; time_t t; /* Configuration sanity checks */ if (sizeof(UINT8) != 1) printf("*** ERROR! Wrong type chosen for 8-bit pixels...\n"); if (sizeof(INT32) != 4) printf("*** ERROR! Wrong type chosen for 32-bit pixels...\n"); t = clock(); /* Library test */ im = ImagingOpenPPM(TESTFILE); im1 = ImagingFillRadialGradient("L"); im3 = ImagingNew(im1->mode, im->xsize, im->ysize); ImagingResize(im3, im1, IMAGING_TRANSFORM_NEAREST); ImagingDelete(im1); ImagingSavePPM(im3, "wedge.ppm"); if (im) { /* Just rush through some library code and see what happens */ printf(">>> processing lena.ppm...\n"); im3 = ImagingCrop(im3, 5, 5, im->xsize-5, im->ysize-5); im2 = ImagingCrop(im, 5, 5, im->xsize-5, im->ysize-5); im1 = ImagingNegative(im2); ImagingDelete(im2); im2 = im1; ImagingPaste(im, im2, im3, 5, 5, im->xsize-5, im->ysize-5); ImagingDelete(im3); ImagingSavePPM(im, "test.ppm"); } printf(">>> elapsed time: %ld\n", (long) (clock() - t)); ImagingDelete(im); printf(">>> as far as we tested, everything seems to be ok...\n"); return 0; } Imaging-1.1.3/libImaging/configure0100555000076400007640000020046507442710204016714 0ustar fredrikfredrik#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated automatically using autoconf version 2.12 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. # Defaults: ac_help= ac_default_prefix=/usr/local # Any additions from configure.in: ac_help="$ac_help --without-gcc never use gcc" ac_help="$ac_help --with-jpeg=DIRECTORY IJG JPEG library location" ac_help="$ac_help --with-zlib=DIRECTORY ZLIB library location" ac_help="$ac_help --with-libm=STRING math library" ac_help="$ac_help --with-libc=STRING C library" # Initialize some variables set by options. # The variables have the same names as the options, with # dashes changed to underlines. build=NONE cache_file=./config.cache exec_prefix=NONE host=NONE no_create= nonopt=NONE no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= target=NONE verbose= x_includes=NONE x_libraries=NONE bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datadir='${prefix}/share' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' libdir='${exec_prefix}/lib' includedir='${prefix}/include' oldincludedir='/usr/include' infodir='${prefix}/info' mandir='${prefix}/man' # Initialize some other variables. subdirs= MFLAGS= MAKEFLAGS= # Maximum number of lines to put in a shell here document. ac_max_here_lines=12 ac_prev= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval "$ac_prev=\$ac_option" ac_prev= continue fi case "$ac_option" in -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) ac_optarg= ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case "$ac_option" in -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir="$ac_optarg" ;; -build | --build | --buil | --bui | --bu) ac_prev=build ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build="$ac_optarg" ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file="$ac_optarg" ;; -datadir | --datadir | --datadi | --datad | --data | --dat | --da) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ | --da=*) datadir="$ac_optarg" ;; -disable-* | --disable-*) ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` # Reject names that are not valid shell variable names. if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } fi ac_feature=`echo $ac_feature| sed 's/-/_/g'` eval "enable_${ac_feature}=no" ;; -enable-* | --enable-*) ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` # Reject names that are not valid shell variable names. if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } fi ac_feature=`echo $ac_feature| sed 's/-/_/g'` case "$ac_option" in *=*) ;; *) ac_optarg=yes ;; esac eval "enable_${ac_feature}='$ac_optarg'" ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix="$ac_optarg" ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he) # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat << EOF Usage: configure [options] [host] Options: [defaults in brackets after descriptions] Configuration: --cache-file=FILE cache test results in FILE --help print this message --no-create do not create output files --quiet, --silent do not print \`checking...' messages --version print the version of autoconf that created configure Directory and file names: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [same as prefix] --bindir=DIR user executables in DIR [EPREFIX/bin] --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] --libexecdir=DIR program executables in DIR [EPREFIX/libexec] --datadir=DIR read-only architecture-independent data in DIR [PREFIX/share] --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data in DIR [PREFIX/com] --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] --libdir=DIR object code libraries in DIR [EPREFIX/lib] --includedir=DIR C header files in DIR [PREFIX/include] --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] --infodir=DIR info documentation in DIR [PREFIX/info] --mandir=DIR man documentation in DIR [PREFIX/man] --srcdir=DIR find the sources in DIR [configure dir or ..] --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names EOF cat << EOF Host type: --build=BUILD configure for building on BUILD [BUILD=HOST] --host=HOST configure for HOST [guessed] --target=TARGET configure for TARGET [TARGET=HOST] Features and packages: --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --x-includes=DIR X include files are in DIR --x-libraries=DIR X library files are in DIR EOF if test -n "$ac_help"; then echo "--enable and --with options recognized:$ac_help" fi exit 0 ;; -host | --host | --hos | --ho) ac_prev=host ;; -host=* | --host=* | --hos=* | --ho=*) host="$ac_optarg" ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir="$ac_optarg" ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir="$ac_optarg" ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir="$ac_optarg" ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir="$ac_optarg" ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst \ | --locals | --local | --loca | --loc | --lo) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* \ | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) localstatedir="$ac_optarg" ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir="$ac_optarg" ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir="$ac_optarg" ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix="$ac_optarg" ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix="$ac_optarg" ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix="$ac_optarg" ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name="$ac_optarg" ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir="$ac_optarg" ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir="$ac_optarg" ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site="$ac_optarg" ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir="$ac_optarg" ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir="$ac_optarg" ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target="$ac_optarg" ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers) echo "configure generated by autoconf version 2.12" exit 0 ;; -with-* | --with-*) ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` # Reject names that are not valid shell variable names. if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } fi ac_package=`echo $ac_package| sed 's/-/_/g'` case "$ac_option" in *=*) ;; *) ac_optarg=yes ;; esac eval "with_${ac_package}='$ac_optarg'" ;; -without-* | --without-*) ac_package=`echo $ac_option|sed -e 's/-*without-//'` # Reject names that are not valid shell variable names. if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } fi ac_package=`echo $ac_package| sed 's/-/_/g'` eval "with_${ac_package}=no" ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes="$ac_optarg" ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries="$ac_optarg" ;; -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } ;; *) if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then echo "configure: warning: $ac_option: invalid host type" 1>&2 fi if test "x$nonopt" != xNONE; then { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } fi nonopt="$ac_option" ;; esac done if test -n "$ac_prev"; then { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } fi trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 # File descriptor usage: # 0 standard input # 1 file creation # 2 errors and warnings # 3 some systems may open it to /dev/tty # 4 used on the Kubota Titan # 6 checking for... messages and results # 5 compiler messages saved in config.log if test "$silent" = yes; then exec 6>/dev/null else exec 6>&1 fi exec 5>./config.log echo "\ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. " 1>&5 # Strip out --no-create and --no-recursion so they do not pile up. # Also quote any args containing shell metacharacters. ac_configure_args= for ac_arg do case "$ac_arg" in -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c) ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) ac_configure_args="$ac_configure_args '$ac_arg'" ;; *) ac_configure_args="$ac_configure_args $ac_arg" ;; esac done # NLS nuisances. # Only set these to C if already set. These must not be set unconditionally # because not all systems understand e.g. LANG=C (notably SCO). # Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'! # Non-C LC_CTYPE values break the ctype check. if test "${LANG+set}" = set; then LANG=C; export LANG; fi if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -rf conftest* confdefs.h # AIX cpp loses on an empty file, so make sure it contains at least a newline. echo > confdefs.h # A filename unique to this package, relative to the directory that # configure is in, which we can look for to find out if srcdir is correct. ac_unique_file=Imaging.h # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then its parent. ac_prog=$0 ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. srcdir=$ac_confdir if test ! -r $srcdir/$ac_unique_file; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r $srcdir/$ac_unique_file; then if test "$ac_srcdir_defaulted" = yes; then { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } else { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } fi fi srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` # Prefer explicitly selected file to automatically selected ones. if test -z "$CONFIG_SITE"; then if test "x$prefix" != xNONE; then CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" else CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" fi fi for ac_site_file in $CONFIG_SITE; do if test -r "$ac_site_file"; then echo "loading site script $ac_site_file" . "$ac_site_file" fi done if test -r "$cache_file"; then echo "loading cache $cache_file" . $cache_file else echo "creating cache $cache_file" > $cache_file fi ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' cross_compiling=$ac_cv_prog_cc_cross if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then ac_n= ac_c=' ' ac_t=' ' else ac_n=-n ac_c= ac_t= fi else ac_n= ac_c='\c' ac_t= fi if test "$program_transform_name" = s,x,x,; then program_transform_name= else # Double any \ or $. echo might interpret backslashes. cat <<\EOF_SED > conftestsed s,\\,\\\\,g; s,\$,$$,g EOF_SED program_transform_name="`echo $program_transform_name|sed -f conftestsed`" rm -f conftestsed fi test "$program_prefix" != NONE && program_transform_name="s,^,${program_prefix},; $program_transform_name" # Use a double $ so make ignores it. test "$program_suffix" != NONE && program_transform_name="s,\$\$,${program_suffix},; $program_transform_name" # sed with no file args requires a program. test "$program_transform_name" = "" && program_transform_name="s,x,x," # From configure.in Id: configure.in # checks for alternative programs echo $ac_n "checking for --without-gcc""... $ac_c" 1>&6 echo "configure:558: checking for --without-gcc" >&5 # Check whether --with-gcc or --without-gcc was given. if test "${with_gcc+set}" = set; then withval="$with_gcc" case $withval in no) CC=cc without_gcc=yes;; yes) CC=gcc without_gcc=no;; *) CC=$withval without_gcc=$withval;; esac else without_gcc=no fi echo "$ac_t""$without_gcc" 1>&6 # If the user switches compilers, we can't believe the cache if test ! -z "$ac_cv_prog_CC" -a ! -z "$CC" -a "$CC" != "$ac_cv_prog_CC" then { echo "configure: error: cached CC is different -- throw away $cache_file (it is also a good idea to do 'make clean' before compiling)" 1>&2; exit 1; } fi # check for programs # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo "configure:588: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_CC="gcc" break fi done IFS="$ac_save_ifs" fi fi CC="$ac_cv_prog_CC" if test -n "$CC"; then echo "$ac_t""$CC" 1>&6 else echo "$ac_t""no" 1>&6 fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo "configure:617: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" ac_prog_rejected=no for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" break fi done IFS="$ac_save_ifs" if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# -gt 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift set dummy "$ac_dir/$ac_word" "$@" shift ac_cv_prog_CC="$@" fi fi fi fi CC="$ac_cv_prog_CC" if test -n "$CC"; then echo "$ac_t""$CC" 1>&6 else echo "$ac_t""no" 1>&6 fi test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 echo "configure:665: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then ac_cv_prog_cc_cross=no else ac_cv_prog_cc_cross=yes fi else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 ac_cv_prog_cc_works=no fi rm -fr conftest* echo "$ac_t""$ac_cv_prog_cc_works" 1>&6 if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 echo "configure:699: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 echo "configure:704: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.c <&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no fi fi echo "$ac_t""$ac_cv_prog_gcc" 1>&6 if test $ac_cv_prog_gcc = yes; then GCC=yes ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 echo "configure:728: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else echo 'void f(){}' > conftest.c if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then ac_cv_prog_cc_g=yes else ac_cv_prog_cc_g=no fi rm -f conftest* fi echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 if test "$ac_test_CFLAGS" = set; then CFLAGS="$ac_save_CFLAGS" elif test $ac_cv_prog_cc_g = yes; then CFLAGS="-g -O2" else CFLAGS="-O2" fi else GCC= test "${CFLAGS+set}" = set || CFLAGS="-g" fi # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo "configure:758: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_RANLIB="ranlib" break fi done IFS="$ac_save_ifs" test -z "$ac_cv_prog_RANLIB" && ac_cv_prog_RANLIB=":" fi fi RANLIB="$ac_cv_prog_RANLIB" if test -n "$RANLIB"; then echo "$ac_t""$RANLIB" 1>&6 else echo "$ac_t""no" 1>&6 fi for ac_prog in ar aal do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo "configure:790: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_AR'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$AR"; then ac_cv_prog_AR="$AR" # Let the user override the test. else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_AR="$ac_prog" break fi done IFS="$ac_save_ifs" fi fi AR="$ac_cv_prog_AR" if test -n "$AR"; then echo "$ac_t""$AR" 1>&6 else echo "$ac_t""no" 1>&6 fi test -n "$AR" && break done test -n "$AR" || AR="ar" # Optimizer/debugger flags passed between Makefiles if test -z "$OPT" then OPT=-O fi # Set name for machine-dependent library files echo $ac_n "checking MACHDEP""... $ac_c" 1>&6 echo "configure:829: checking MACHDEP" >&5 if test -z "$MACHDEP" then ac_sys_system=`uname -s | tr -d ' ' | tr '[A-Z]' '[a-z]'` ac_sys_release=`uname -r | tr -d ' ' | sed 's/\..*//'` MACHDEP="$ac_sys_system$ac_sys_release" case MACHDEP in '') MACHDEP=unknown;; esac fi echo "$ac_t""$MACHDEP" 1>&6 # checks for libraries # Check whether --with-jpeg or --without-jpeg was given. if test "${with_jpeg+set}" = set; then withval="$with_jpeg" cat >> confdefs.h <<\EOF #define WITH_JPEG 1 EOF if test -d "$withval" then LDFLAGS="$LDFLAGS -L$withval" fi fi echo $ac_n "checking for jpeg_destroy_compress in -ljpeg""... $ac_c" 1>&6 echo "configure:857: checking for jpeg_destroy_compress in -ljpeg" >&5 ac_lib_var=`echo jpeg'_'jpeg_destroy_compress | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-ljpeg $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_lib=HAVE_LIB`echo jpeg | sed -e 's/[^a-zA-Z0-9_]/_/g' \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` cat >> confdefs.h <&6 fi # AC_CHECK_LIB(mpeg, OpenMPEG) # Check whether --with-zlib or --without-zlib was given. if test "${with_zlib+set}" = set; then withval="$with_zlib" cat >> confdefs.h <<\EOF #define WITH_ZLIB 1 EOF if test -d "$withval" then LDFLAGS="$LDFLAGS -L$withval" fi fi echo $ac_n "checking for deflate in -lz""... $ac_c" 1>&6 echo "configure:920: checking for deflate in -lz" >&5 ac_lib_var=`echo z'_'deflate | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_save_LIBS="$LIBS" LIBS="-lz $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=no" fi rm -f conftest* LIBS="$ac_save_LIBS" fi if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_lib=HAVE_LIB`echo z | sed -e 's/[^a-zA-Z0-9_]/_/g' \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` cat >> confdefs.h <&6 fi # checks for header files echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 echo "configure:969: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else # This must be in double quotes, not single quotes, because CPP may get # substituted into the Makefile and "${CC-cc}" will confuse make. CPP="${CC-cc} -E" # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:990: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:1007: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* CPP=/lib/cpp fi rm -f conftest* fi rm -f conftest* ac_cv_prog_CPP="$CPP" fi CPP="$ac_cv_prog_CPP" else ac_cv_prog_CPP="$CPP" fi echo "$ac_t""$CPP" 1>&6 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 echo "configure:1030: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include #include #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:1043: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* ac_cv_header_stdc=yes else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* ac_cv_header_stdc=no fi rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | egrep "memchr" >/dev/null 2>&1; then : else rm -rf conftest* ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | egrep "free" >/dev/null 2>&1; then : else rm -rf conftest* ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF if { (eval echo configure:1110: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then : else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_header_stdc=no fi rm -fr conftest* fi fi fi echo "$ac_t""$ac_cv_header_stdc" 1>&6 if test $ac_cv_header_stdc = yes; then cat >> confdefs.h <<\EOF #define STDC_HEADERS 1 EOF fi # checks for compiler/platform characteristics echo $ac_n "checking for inline""... $ac_c" 1>&6 echo "configure:1136: checking for inline" >&5 if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_inline=no for ac_kw in inline __inline__ __inline; do cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_inline=$ac_kw; break else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 fi rm -f conftest* done fi echo "$ac_t""$ac_cv_c_inline" 1>&6 case "$ac_cv_c_inline" in inline | yes) ;; no) cat >> confdefs.h <<\EOF #define inline EOF ;; *) cat >> confdefs.h <&6 echo "configure:1177: checking whether byte ordering is bigendian" >&5 if eval "test \"`echo '$''{'ac_cv_c_bigendian'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_bigendian=unknown # See if sys/param.h defines the BYTE_ORDER macro. cat > conftest.$ac_ext < #include int main() { #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN bogus endian macros #endif ; return 0; } EOF if { (eval echo configure:1195: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* # It does; now see whether it defined to BIG_ENDIAN or not. cat > conftest.$ac_ext < #include int main() { #if BYTE_ORDER != BIG_ENDIAN not big endian #endif ; return 0; } EOF if { (eval echo configure:1210: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_bigendian=yes else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* ac_cv_c_bigendian=no fi rm -f conftest* else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 fi rm -f conftest* if test $ac_cv_c_bigendian = unknown; then if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_c_bigendian=no else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_c_bigendian=yes fi rm -fr conftest* fi fi fi echo "$ac_t""$ac_cv_c_bigendian" 1>&6 if test $ac_cv_c_bigendian = yes; then cat >> confdefs.h <<\EOF #define WORDS_BIGENDIAN 1 EOF fi echo $ac_n "checking size of char""... $ac_c" 1>&6 echo "configure:1268: checking size of char" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_char'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(char)); exit(0); } EOF if { (eval echo configure:1287: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_char=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_char=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_char" 1>&6 cat >> confdefs.h <&6 echo "configure:1307: checking size of short" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_short'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(short)); exit(0); } EOF if { (eval echo configure:1326: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_short=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_short=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_short" 1>&6 cat >> confdefs.h <&6 echo "configure:1346: checking size of int" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_int'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(int)); exit(0); } EOF if { (eval echo configure:1365: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_int=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_int=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_int" 1>&6 cat >> confdefs.h <&6 echo "configure:1385: checking size of long" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_long'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(long)); exit(0); } EOF if { (eval echo configure:1404: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_long=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_long=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_long" 1>&6 cat >> confdefs.h <&6 echo "configure:1425: checking size of float" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_float'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(float)); exit(0); } EOF if { (eval echo configure:1444: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_float=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_float=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_float" 1>&6 cat >> confdefs.h <&6 echo "configure:1464: checking size of double" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_double'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < main() { FILE *f=fopen("conftestval", "w"); if (!f) exit(1); fprintf(f, "%d\n", sizeof(double)); exit(0); } EOF if { (eval echo configure:1483: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_double=`cat conftestval` else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_sizeof_double=0 fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_sizeof_double" 1>&6 cat >> confdefs.h <&6 echo "configure:1504: checking for working const" >&5 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <j = 5; } { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ const int foo = 10; } ; return 0; } EOF if { (eval echo configure:1558: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_const=yes else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* ac_cv_c_const=no fi rm -f conftest* fi echo "$ac_t""$ac_cv_c_const" 1>&6 if test $ac_cv_c_const = no; then cat >> confdefs.h <<\EOF #define const EOF fi have_prototypes=no echo $ac_n "checking for prototypes""... $ac_c" 1>&6 echo "configure:1581: checking for prototypes" >&5 cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* cat >> confdefs.h <<\EOF #define HAVE_PROTOTYPES 1 EOF have_prototypes=yes else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 fi rm -f conftest* echo "$ac_t""$have_prototypes" 1>&6 # checks for library functions for ac_hdr in unistd.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 echo "configure:1608: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" { (eval echo configure:1618: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* eval "ac_cv_header_$ac_safe=yes" else echo "$ac_err" >&5 echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_header_$ac_safe=no" fi rm -f conftest* fi if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` cat >> confdefs.h <&6 fi done for ac_func in getpagesize do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:1647: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 builtin and then its argument prototype would still apply. */ char $ac_func(); int main() { /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined (__stub_$ac_func) || defined (__stub___$ac_func) choke me #else $ac_func(); #endif ; return 0; } EOF if { (eval echo configure:1675: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -rf conftest* eval "ac_cv_func_$ac_func=no" fi rm -f conftest* fi if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then echo "$ac_t""yes" 1>&6 ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` cat >> confdefs.h <&6 fi done echo $ac_n "checking for working mmap""... $ac_c" 1>&6 echo "configure:1700: checking for working mmap" >&5 if eval "test \"`echo '$''{'ac_cv_func_mmap_fixed_mapped'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then ac_cv_func_mmap_fixed_mapped=no else cat > conftest.$ac_ext < #include #include /* This mess was copied from the GNU getpagesize.h. */ #ifndef HAVE_GETPAGESIZE # ifdef HAVE_UNISTD_H # include # endif /* Assume that all systems that can run configure have sys/param.h. */ # ifndef HAVE_SYS_PARAM_H # define HAVE_SYS_PARAM_H 1 # endif # ifdef _SC_PAGESIZE # define getpagesize() sysconf(_SC_PAGESIZE) # else /* no _SC_PAGESIZE */ # ifdef HAVE_SYS_PARAM_H # include # ifdef EXEC_PAGESIZE # define getpagesize() EXEC_PAGESIZE # else /* no EXEC_PAGESIZE */ # ifdef NBPG # define getpagesize() NBPG * CLSIZE # ifndef CLSIZE # define CLSIZE 1 # endif /* no CLSIZE */ # else /* no NBPG */ # ifdef NBPC # define getpagesize() NBPC # else /* no NBPC */ # ifdef PAGESIZE # define getpagesize() PAGESIZE # endif /* PAGESIZE */ # endif /* no NBPC */ # endif /* no NBPG */ # endif /* no EXEC_PAGESIZE */ # else /* no HAVE_SYS_PARAM_H */ # define getpagesize() 8192 /* punt totally */ # endif /* no HAVE_SYS_PARAM_H */ # endif /* no _SC_PAGESIZE */ #endif /* no HAVE_GETPAGESIZE */ #ifdef __cplusplus extern "C" { void *malloc(unsigned); } #else char *malloc(); #endif int main() { char *data, *data2, *data3; int i, pagesize; int fd; pagesize = getpagesize(); /* * First, make a file with some known garbage in it. */ data = malloc(pagesize); if (!data) exit(1); for (i = 0; i < pagesize; ++i) *(data + i) = rand(); umask(0); fd = creat("conftestmmap", 0600); if (fd < 0) exit(1); if (write(fd, data, pagesize) != pagesize) exit(1); close(fd); /* * Next, try to mmap the file at a fixed address which * already has something else allocated at it. If we can, * also make sure that we see the same garbage. */ fd = open("conftestmmap", O_RDWR); if (fd < 0) exit(1); data2 = malloc(2 * pagesize); if (!data2) exit(1); data2 += (pagesize - ((int) data2 & (pagesize - 1))) & (pagesize - 1); if (data2 != mmap(data2, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, 0L)) exit(1); for (i = 0; i < pagesize; ++i) if (*(data + i) != *(data2 + i)) exit(1); /* * Finally, make sure that changes to the mapped area * do not percolate back to the file as seen by read(). * (This is a bug on some variants of i386 svr4.0.) */ for (i = 0; i < pagesize; ++i) *(data2 + i) = *(data2 + i) + 1; data3 = malloc(pagesize); if (!data3) exit(1); if (read(fd, data3, pagesize) != pagesize) exit(1); for (i = 0; i < pagesize; ++i) if (*(data + i) != *(data3 + i)) exit(1); close(fd); unlink("conftestmmap"); exit(0); } EOF if { (eval echo configure:1848: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then ac_cv_func_mmap_fixed_mapped=yes else echo "configure: failed program was:" >&5 cat conftest.$ac_ext >&5 rm -fr conftest* ac_cv_func_mmap_fixed_mapped=no fi rm -fr conftest* fi fi echo "$ac_t""$ac_cv_func_mmap_fixed_mapped" 1>&6 if test $ac_cv_func_mmap_fixed_mapped = yes; then cat >> confdefs.h <<\EOF #define HAVE_MMAP 1 EOF fi # checks for system services # check for --with-libm=... LIBM=-lm # Check whether --with-libm or --without-libm was given. if test "${with_libm+set}" = set; then withval="$with_libm" if test "$withval" != yes then LIBM=$withval else { echo "configure: error: proper usage is --with-libm=STRING" 1>&2; exit 1; } fi fi # check for --with-libc=... # Check whether --with-libc or --without-libc was given. if test "${with_libc+set}" = set; then withval="$with_libc" if test "$withval" != yes then LIBC=$withval else { echo "configure: error: proper usage is --with-libc=STRING" 1>&2; exit 1; } fi fi # generate output files trap '' 1 2 15 cat > confcache <<\EOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs. It is not useful on other systems. # If it contains results you don't want to keep, you may remove or edit it. # # By default, configure uses ./config.cache as the cache file, # creating it if it does not exist already. You can give configure # the --cache-file=FILE option to use a different cache file; that is # what configure does when it calls configure scripts in # subdirectories, so they share the cache. # Giving --cache-file=/dev/null disables caching, for debugging configure. # config.status only pays attention to the cache file if you give it the # --recheck option to rerun configure. # EOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, don't put newlines in cache variables' values. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. (set) 2>&1 | case `(ac_space=' '; set) 2>&1` in *ac_space=\ *) # `set' does not quote correctly, so add quotes (double-quote substitution # turns \\\\ into \\, and sed turns \\ into \). sed -n \ -e "s/'/'\\\\''/g" \ -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" ;; *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' ;; esac >> confcache if cmp -s $cache_file confcache; then : else if test -w $cache_file; then echo "updating cache $cache_file" cat confcache > $cache_file else echo "not updating unwritable cache $cache_file" fi fi rm -f confcache trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' # Any assignment to VPATH causes Sun make to only execute # the first set of double-colon rules, so remove it if not needed. # If there is a colon in the path, we need to keep it. if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d' fi trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 DEFS=-DHAVE_CONFIG_H # Without the "./", some shells look in PATH for config.status. : ${CONFIG_STATUS=./config.status} echo creating $CONFIG_STATUS rm -f $CONFIG_STATUS cat > $CONFIG_STATUS </dev/null | sed 1q`: # # $0 $ac_configure_args # # Compiler output produced by configure, useful for debugging # configure, is in ./config.log if it exists. ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" for ac_option do case "\$ac_option" in -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; -version | --version | --versio | --versi | --vers | --ver | --ve | --v) echo "$CONFIG_STATUS generated by autoconf version 2.12" exit 0 ;; -help | --help | --hel | --he | --h) echo "\$ac_cs_usage"; exit 0 ;; *) echo "\$ac_cs_usage"; exit 1 ;; esac done ac_given_srcdir=$srcdir trap 'rm -fr `echo "Makefile ImConfig.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 EOF cat >> $CONFIG_STATUS < conftest.subs <<\\CEOF $ac_vpsub $extrasub s%@CFLAGS@%$CFLAGS%g s%@CPPFLAGS@%$CPPFLAGS%g s%@CXXFLAGS@%$CXXFLAGS%g s%@DEFS@%$DEFS%g s%@LDFLAGS@%$LDFLAGS%g s%@LIBS@%$LIBS%g s%@exec_prefix@%$exec_prefix%g s%@prefix@%$prefix%g s%@program_transform_name@%$program_transform_name%g s%@bindir@%$bindir%g s%@sbindir@%$sbindir%g s%@libexecdir@%$libexecdir%g s%@datadir@%$datadir%g s%@sysconfdir@%$sysconfdir%g s%@sharedstatedir@%$sharedstatedir%g s%@localstatedir@%$localstatedir%g s%@libdir@%$libdir%g s%@includedir@%$includedir%g s%@oldincludedir@%$oldincludedir%g s%@infodir@%$infodir%g s%@mandir@%$mandir%g s%@CC@%$CC%g s%@RANLIB@%$RANLIB%g s%@AR@%$AR%g s%@OPT@%$OPT%g s%@MACHDEP@%$MACHDEP%g s%@CPP@%$CPP%g s%@LIBM@%$LIBM%g s%@LIBC@%$LIBC%g CEOF EOF cat >> $CONFIG_STATUS <<\EOF # Split the substitutions into bite-sized pieces for seds with # small command number limits, like on Digital OSF/1 and HP-UX. ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script. ac_file=1 # Number of current file. ac_beg=1 # First line for current file. ac_end=$ac_max_sed_cmds # Line after last line for current file. ac_more_lines=: ac_sed_cmds="" while $ac_more_lines; do if test $ac_beg -gt 1; then sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file else sed "${ac_end}q" conftest.subs > conftest.s$ac_file fi if test ! -s conftest.s$ac_file; then ac_more_lines=false rm -f conftest.s$ac_file else if test -z "$ac_sed_cmds"; then ac_sed_cmds="sed -f conftest.s$ac_file" else ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file" fi ac_file=`expr $ac_file + 1` ac_beg=$ac_end ac_end=`expr $ac_end + $ac_max_sed_cmds` fi done if test -z "$ac_sed_cmds"; then ac_sed_cmds=cat fi EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". case "$ac_file" in *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; *) ac_file_in="${ac_file}.in" ;; esac # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories. # Remove last slash and all that follows it. Not all systems have dirname. ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then # The file is in a subdirectory. test ! -d "$ac_dir" && mkdir "$ac_dir" ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`" # A "../" for each directory in $ac_dir_suffix. ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` else ac_dir_suffix= ac_dots= fi case "$ac_given_srcdir" in .) srcdir=. if test -z "$ac_dots"; then top_srcdir=. else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; *) # Relative path. srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix" top_srcdir="$ac_dots$ac_given_srcdir" ;; esac echo creating "$ac_file" rm -f "$ac_file" configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." case "$ac_file" in *Makefile*) ac_comsub="1i\\ # $configure_input" ;; *) ac_comsub= ;; esac ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` sed -e "$ac_comsub s%@configure_input@%$configure_input%g s%@srcdir@%$srcdir%g s%@top_srcdir@%$top_srcdir%g " $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file fi; done rm -f conftest.s* # These sed commands are passed to sed as "A NAME B NAME C VALUE D", where # NAME is the cpp macro being defined and VALUE is the value it is being given. # # ac_d sets the value in "#define NAME VALUE" lines. ac_dA='s%^\([ ]*\)#\([ ]*define[ ][ ]*\)' ac_dB='\([ ][ ]*\)[^ ]*%\1#\2' ac_dC='\3' ac_dD='%g' # ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE". ac_uA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' ac_uB='\([ ]\)%\1#\2define\3' ac_uC=' ' ac_uD='\4%g' # ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE". ac_eA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' ac_eB='$%\1#\2define\3' ac_eC=' ' ac_eD='%g' if test "${CONFIG_HEADERS+set}" != set; then EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF fi for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". case "$ac_file" in *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; *) ac_file_in="${ac_file}.in" ;; esac echo creating $ac_file rm -f conftest.frag conftest.in conftest.out ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` cat $ac_file_inputs > conftest.in EOF # Transform confdefs.h into a sed script conftest.vals that substitutes # the proper values into config.h.in to produce config.h. And first: # Protect against being on the right side of a sed subst in config.status. # Protect against being in an unquoted here document in config.status. rm -f conftest.vals cat > conftest.hdr <<\EOF s/[\\&%]/\\&/g s%[\\$`]%\\&%g s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp s%ac_d%ac_u%gp s%ac_u%ac_e%gp EOF sed -n -f conftest.hdr confdefs.h > conftest.vals rm -f conftest.hdr # This sed command replaces #undef with comments. This is necessary, for # example, in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. cat >> conftest.vals <<\EOF s%^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */% EOF # Break up conftest.vals because some shells have a limit on # the size of here documents, and old seds have small limits too. rm -f conftest.tail while : do ac_lines=`grep -c . conftest.vals` # grep -c gives empty output for an empty file on some AIX systems. if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi # Write a limited-size here document to conftest.frag. echo ' cat > conftest.frag <> $CONFIG_STATUS sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS echo 'CEOF sed -f conftest.frag conftest.in > conftest.out rm -f conftest.in mv conftest.out conftest.in ' >> $CONFIG_STATUS sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail rm -f conftest.vals mv conftest.tail conftest.vals done rm -f conftest.vals cat >> $CONFIG_STATUS <<\EOF rm -f conftest.frag conftest.h echo "/* $ac_file. Generated automatically by configure. */" > conftest.h cat conftest.in >> conftest.h rm -f conftest.in if cmp -s $ac_file conftest.h 2>/dev/null; then echo "$ac_file is unchanged" rm -f conftest.h else # Remove last slash and all that follows it. Not all systems have dirname. ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then # The file is in a subdirectory. test ! -d "$ac_dir" && mkdir "$ac_dir" fi rm -f $ac_file mv conftest.h $ac_file fi fi; done EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF exit 0 EOF chmod +x $CONFIG_STATUS rm -fr confdefs* $ac_clean_files test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 Imaging-1.1.3/libImaging/ImConfig.h.in0100444000076400007640000000241607442710204017252 0ustar fredrikfredrik/* $Id: ImConfig.h.in,v 1.1 2025/03/25 08:52:16 fredrik Exp fredrik $ * * The Python Imaging Library. * * File: * ImConfig.h.in -- ImConfig.h template for the imaging core library * * Copyright (c) Fredrik Lundh 1995. All rights reserved. */ /* Define to empty if the keyword does not work. */ #undef const /* Define as __inline if that's what the C compiler calls it. */ #undef inline /* Define if you have ANSI prototypes. */ #undef HAVE_PROTOTYPES /* Define if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ #undef WORDS_BIGENDIAN /* The number of bytes in a char. */ #undef SIZEOF_CHAR /* The number of bytes in a double. */ #undef SIZEOF_DOUBLE /* The number of bytes in a float. */ #undef SIZEOF_FLOAT /* The number of bytes in a int. */ #undef SIZEOF_INT /* The number of bytes in a long. */ #undef SIZEOF_LONG /* The number of bytes in a short. */ #undef SIZEOF_SHORT /* Define if you have the IJG jpeg library (-ljpeg). */ #undef HAVE_LIBJPEG /* Define if you have the Greg Ward's mpeg library (-lmpeg). */ #undef HAVE_LIBMPEG /* Define if you have the zlib compression library (-lz). */ #undef HAVE_LIBZ Imaging-1.1.3/libImaging/Makefile.in0100444000076400007640000000561207442710204017047 0ustar fredrikfredrik# # The Python Imaging Library # $Makefile.in$ # # makefile template for PIL # # Makefile.in is converted into Makefile by the configure script # in the parent directory. Once configure has run, you can recreate # the Makefile by running just config.status. # # Copyright (c) 1998-2002 by Secret Labs AB # Copyright (c) 1995-2002 by Fredrik Lundh # # -------------------------------------------------------------------- # Variables set by config.stat srcdir= @srcdir@ VPATH= @srcdir@ CC= @CC@ RANLIB= @RANLIB@ AR= @AR@ DEFS= @DEFS@ LIBS= @LIBS@ @LIBM@ # -------------------------------------------------------------------- # Other things that are customizable but not by configure INCLDIR= $(srcdir)/. JPEGINCLUDE= /usr/local/include OPT= @OPT@ #OPT= -g CFLAGS= $(OPT) -I$(INCLDIR) -I$(JPEGINCLUDE) $(DEFS) MKDEP= mkdep SHELL= /bin/sh # -------------------------------------------------------------------- # Fixed definitions OBJS= Storage.o Access.o Except.o \ Antialias.o \ Bands.o Blend.o \ Chops.o Convert.o ConvertYCbCr.o Copy.o Crop.o Crc32.o \ Dib.o Draw.o \ Effects.o \ File.o Fill.o Filter.o \ Geometry.o GetBBox.o \ Histo.o \ Matrix.o Negative.o \ Offset.o \ Pack.o Palette.o Paste.o Point.o \ Quant.o QuantHash.o QuantHeap.o \ Unpack.o \ UnpackYCC.o \ BitDecode.o \ EpsEncode.o \ FliDecode.o \ GifDecode.o GifEncode.o \ HexDecode.o \ JpegDecode.o JpegEncode.o \ LzwDecode.o \ MspDecode.o \ PackDecode.o \ PcdDecode.o \ PcxDecode.o PcxEncode.o \ RawDecode.o RawEncode.o \ SunRleDecode.o \ TgaRleDecode.o \ XbmDecode.o XbmEncode.o \ ZipDecode.o ZipEncode.o LIB= libImaging.a # -------------------------------------------------------------------- # Rules all: coretest $(LIB) coretest: coretest.o $(LIB) $(CC) -o coretest coretest.o $(LIB) $(LIBS) $(LIB): $& $(OBJS) -rm -f $(LIB) $(AR) cr $(LIB) $(OBJS) $(RANLIB) $(LIB) clean: -rm -f *.o *.so core *~ [@,#]* *.old *.orig *.rej *.pyc\ test.ppm Imaging_wrap.c clobber: clean -rm -f coretest *.a tags TAGS distclean: clobber -rm -f Makefile ImConfig.h -rm -f config.log config.status config.cache Makefile: $(srcdir)/Makefile.in ./config.status (CONFIG_FILES=Makefile CONFIG_HEADERS= \ $(SHELL) config.status) depend: $(MKDEP) $(CFLAGS) `echo $(OBJS) | tr ' ' '\012' | \ sed 's|\(.*\)\.o|$(srcdir)/\1.c|'` .PRECIOUS: Makefile # -------------------------------------------------------------------- # Tests check: coretest ./coretest -xv test.ppm Imaging_wrap.c: wrap -python -dnone Imaging.i exercise: Imaging_wrap.c gcc -I../../../Include Imaging_wrap.c -c ld -shared -expect_unresolved "*" Imaging_wrap.o\ libImaging.a -o Imaging.so python exerciseImaging.py # -------------------------------------------------------------------- # DO NOT DELETE THIS LINE -- mkdep uses it. # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. Imaging-1.1.3/_imaging.c0100444000076400007640000017625307442710204014670 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/_imaging.c#11 $ * * the imaging library bindings * * history: * 2025-09-24 fl Created * 2025-03-24 fl Ready for first public release (release 0.0) * 2025-03-25 fl Added fromstring (for Jack's "img" library) * 2025-03-28 fl Added channel operations * 2025-03-31 fl Added point operation * 2025-04-08 fl Added new/new_block/new_array factories * 2025-04-13 fl Added decoders * 2025-05-04 fl Added palette hack * 2025-05-12 fl Compile cleanly as C++ * 2025-05-19 fl Added matrix conversions, gradient fills * 2025-05-27 fl Added display_mode * 2025-07-22 fl Added getbbox, offset * 2025-07-23 fl Added sequence semantics * 2025-08-13 fl Added logical operators, point mode * 2025-08-16 fl Modified paste interface * 2025-09-06 fl Added putdata methods, use abstract interface * 2025-11-01 fl Added xbm encoder * 2025-11-04 fl Added experimental path stuff, draw_lines, etc * 2025-12-10 fl Added zip decoder, crc32 interface * 2025-12-14 fl Added modulo arithmetics * 2024-12-29 fl Added zip encoder * 2025-01-03 fl Added fli and msp decoders * 2025-01-04 fl Added experimental sun_rle and tga_rle decoders * 2025-01-05 fl Added gif encoder, getpalette hack * 2025-02-23 fl Added histogram mask * 2025-05-12 fl Minor tweaks to match the IFUNC95 interface * 2025-05-21 fl Added noise generator, spread effect * 2025-06-05 fl Added mandelbrot generator * 2025-08-02 fl Modified putpalette to coerce image mode if necessary * 2025-01-11 fl Added INT32 support * 2025-01-22 fl Fixed draw_points to draw the last point too * 2025-06-28 fl Added getpixel, getink, draw_ink * 2025-07-12 fl Added getextrema * 2025-07-17 fl Added point conversion to arbitrary formats * 2025-09-21 fl Added support for resampling filters * 2025-09-22 fl Added support for quad transform * 2024-12-29 fl Added support for arcs, chords, and pieslices * 2025-01-10 fl Added some experimental arrow graphics stuff * 2025-02-06 fl Added draw_bitmap, font acceleration stuff * 2025-04-17 fl Fixed some egcs compiler nits * 2025-09-17 fl Added screen grab primitives (win32) * 2025-03-09 fl Added stretch primitive * 2025-03-10 fl * * Copyright (c) 1997-2002 by Secret Labs AB * Copyright (c) 1995-2002 by Fredrik Lundh * * See the README file for information on usage and redistribution. */ #include "Python.h" #include "Imaging.h" /* Configuration stuff. Feel free to undef things you don't need. */ #define WITH_IMAGECHOPS /* ImageChops support */ #define WITH_IMAGEDRAW /* ImageDraw support */ #define WITH_MAPPING /* use memory mapping to read some file formats */ #define WITH_IMAGEPATH /* ImagePath stuff */ #define WITH_ARROW /* arrow graphics stuff (experimental) */ #define WITH_EFFECTS /* special effects */ #define WITH_QUANTIZE /* quantization support */ #define WITH_DEBUG /* extra debugging stuff */ #undef VERBOSE #define CLIP(x) ((x) <= 0 ? 0 : (x) < 256 ? (x) : 255) #define B16(p, i) ((((int)p[(i)]) << 8) + p[(i)+1]) #define L16(p, i) ((((int)p[(i)+1]) << 8) + p[(i)]) #define S16(v) ((v) < 32768 ? (v) : ((v) - 65536)) /* -------------------------------------------------------------------- */ /* OBJECT ADMINISTRATION */ /* -------------------------------------------------------------------- */ typedef struct { PyObject_HEAD Imaging image; } ImagingObject; staticforward PyTypeObject Imaging_Type; #ifdef WITH_IMAGEDRAW typedef struct { /* to write a character, cut out sxy from glyph data, place at current position plus dxy, and advance by (dx, dy) */ int dx, dy; int dx0, dy0, dx1, dy1; int sx0, sy0, sx1, sy1; } Glyph; typedef struct { PyObject_HEAD ImagingObject* ref; Imaging bitmap; int ysize; int baseline; Glyph glyphs[256]; } ImagingFontObject; staticforward PyTypeObject ImagingFont_Type; #endif PyObject* PyImagingNew(Imaging imOut) { ImagingObject* imagep; if (!imOut) return NULL; imagep = PyObject_NEW(ImagingObject, &Imaging_Type); if (imagep == NULL) { ImagingDelete(imOut); return NULL; } #ifdef VERBOSE printf("imaging %p allocated\n", imagep); #endif imagep->image = imOut; return (PyObject*) imagep; } static void _dealloc(ImagingObject* imagep) { #ifdef VERBOSE printf("imaging %p deleted\n", imagep); #endif ImagingDelete(imagep->image); PyMem_DEL(imagep); } #define PyImaging_Check(op) ((op)->ob_type == &Imaging_Type) Imaging PyImaging_AsImaging(PyObject *op) { if (!PyImaging_Check(op)) { PyErr_BadInternalCall(); return NULL; } return ((ImagingObject *)op)->image; } /* -------------------------------------------------------------------- */ /* EXCEPTION REROUTING */ /* -------------------------------------------------------------------- */ /* error messages */ static const char* must_be_sequence = "argument must be a sequence"; static const char* wrong_mode = "unrecognized image mode"; static const char* wrong_raw_mode = "unrecognized raw mode"; static const char* outside_image = "image index out of range"; static const char* outside_palette = "palette index out of range"; static const char* no_palette = "image has no palette"; void * ImagingError_IOError(void) { PyErr_SetString(PyExc_IOError, "error when accessing file"); return NULL; } void * ImagingError_MemoryError(void) { return PyErr_NoMemory(); } void * ImagingError_Mismatch(void) { PyErr_SetString(PyExc_ValueError, "images do not match"); return NULL; } void * ImagingError_ModeError(void) { PyErr_SetString(PyExc_ValueError, "image has wrong mode"); return NULL; } void * ImagingError_ValueError(const char *message) { PyErr_SetString( PyExc_ValueError, (message) ? (char*) message : "unrecognized argument value" ); return NULL; } /* -------------------------------------------------------------------- */ /* HELPERS */ /* -------------------------------------------------------------------- */ static int getbands(const char* mode) { Imaging im; int bands; /* FIXME: add primitive to libImaging to avoid extra allocation */ im = ImagingNew(mode, 0, 0); if (!im) return -1; bands = im->bands; ImagingDelete(im); return bands; } #define TYPE_UINT8 (0x100|sizeof(UINT8)) #define TYPE_INT32 (0x200|sizeof(INT32)) #define TYPE_FLOAT32 (0x300|sizeof(FLOAT32)) #define TYPE_DOUBLE (0x400|sizeof(double)) static void* getlist(PyObject* arg, int* length, const char* wrong_length, int type) { int i, n; void* list; if (!PySequence_Check(arg)) { PyErr_SetString(PyExc_TypeError, must_be_sequence); return NULL; } n = PyObject_Length(arg); if (length && wrong_length && n != *length) { PyErr_SetString(PyExc_ValueError, wrong_length); return NULL; } list = malloc(n * (type & 0xff)); if (!list) { PyErr_NoMemory(); return NULL; } switch (type) { case TYPE_UINT8: if (PyList_Check(arg)) { for (i = 0; i < n; i++) { PyObject *op = PyList_GET_ITEM(arg, i); int temp = PyInt_AsLong(op); ((UINT8*)list)[i] = CLIP(temp); } } else { for (i = 0; i < n; i++) { PyObject *op = PySequence_GetItem(arg, i); int temp = PyInt_AsLong(op); Py_XDECREF(op); ((UINT8*)list)[i] = CLIP(temp); } } break; case TYPE_INT32: if (PyList_Check(arg)) { for (i = 0; i < n; i++) { PyObject *op = PyList_GET_ITEM(arg, i); int temp = PyInt_AsLong(op); ((INT32*)list)[i] = temp; } } else { for (i = 0; i < n; i++) { PyObject *op = PySequence_GetItem(arg, i); int temp = PyInt_AsLong(op); Py_XDECREF(op); ((INT32*)list)[i] = temp; } } break; case TYPE_FLOAT32: if (PyList_Check(arg)) { for (i = 0; i < n; i++) { PyObject *op = PyList_GET_ITEM(arg, i); double temp = PyFloat_AsDouble(op); ((FLOAT32*)list)[i] = temp; } } else { for (i = 0; i < n; i++) { PyObject *op = PySequence_GetItem(arg, i); double temp = PyFloat_AsDouble(op); Py_XDECREF(op); ((FLOAT32*)list)[i] = temp; } } break; case TYPE_DOUBLE: if (PyList_Check(arg)) { for (i = 0; i < n; i++) { PyObject *op = PyList_GET_ITEM(arg, i); double temp = PyFloat_AsDouble(op); ((double*)list)[i] = temp; } } else { for (i = 0; i < n; i++) { PyObject *op = PySequence_GetItem(arg, i); double temp = PyFloat_AsDouble(op); Py_XDECREF(op); ((double*)list)[i] = temp; } } break; } if (length) *length = n; PyErr_Clear(); return list; } static PyObject* getpixel(Imaging im, int x, int y) { UINT8 *p; if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) { PyErr_SetString(PyExc_IndexError, outside_image); return NULL; } /* single layer */ if (im->image8 != NULL) { p = (UINT8*) &im->image8[y][x]; switch (im->type) { case IMAGING_TYPE_UINT8: return Py_BuildValue("i", p[0]); case IMAGING_TYPE_SPECIAL: /* FIXME: are 16-bit images signed or unsigned??? */ p = (UINT8*) &im->image8[y][x+x]; if (strcmp(im->mode, "I;16") == 0) return Py_BuildValue("i", L16(p, 0)); else if (strcmp(im->mode, "I;16B") == 0) return Py_BuildValue("i", B16(p, 0)); } } /* multilayer */ if (im->image32 != NULL) { p = (UINT8*) &im->image32[y][x]; switch (im->type) { case 0: /* unsigned integer */ if (im->bands == 3) return Py_BuildValue("iii", p[0], p[1], p[2]); return Py_BuildValue("iiii", p[0], p[1], p[2], p[3]); case 1: /* signed integer */ return Py_BuildValue("i", *(INT32*) p); case 2: /* floating point */ return Py_BuildValue("d", *(FLOAT32*) p); } } /* unknown type */ Py_INCREF(Py_None); return Py_None; } static char* getink(PyObject* color, Imaging im, char* ink) { int r, g, b, a; double f; /* fill ink buffer (four bytes) with something that can be cast to either UINT8 or INT32 */ if (im->image8) { /* unsigned integer, single layer */ r = PyInt_AsLong(color); if (r == -1 && PyErr_Occurred()) return NULL; ink[0] = CLIP(r); ink[1] = ink[2] = ink[3] = 0; return ink; } else { switch (im->type) { case 0: /* unsigned integer */ a = 0; if (!PyArg_ParseTuple(color, "iii|i", &r, &g, &b, &a)) { PyErr_Clear(); r = PyInt_AsLong(color); if (r == -1 && PyErr_Occurred()) return NULL; /* compatibility: ABGR */ a = (UINT8) (r >> 24); b = (UINT8) (r >> 16); g = (UINT8) (r >> 8); r = (UINT8) r; } ink[0] = CLIP(r); ink[1] = CLIP(g); ink[2] = CLIP(b); ink[3] = CLIP(a); return ink; case 1: /* signed integer */ r = PyInt_AsLong(color); if (r == -1 && PyErr_Occurred()) return NULL; *(INT32*) ink = r; return ink; case 2: /* floating point */ f = PyFloat_AsDouble(color); if (f == -1.0 && PyErr_Occurred()) return NULL; *(FLOAT32*) ink = f; return ink; } } PyErr_SetString(PyExc_ValueError, wrong_mode); return NULL; } /* -------------------------------------------------------------------- */ /* FACTORIES */ /* -------------------------------------------------------------------- */ static PyObject* _fill(PyObject* self, PyObject* args) { char* mode; int xsize, ysize; PyObject* color; char buffer[4]; Imaging im; xsize = ysize = 256; color = NULL; if (!PyArg_ParseTuple(args, "s|(ii)O", &mode, &xsize, &ysize, &color)) return NULL; im = ImagingNew(mode, xsize, ysize); if (!im) return NULL; if (color) { if (!getink(color, im, buffer)) { ImagingDelete(im); return NULL; } } else buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0; ImagingFill(im, buffer); return PyImagingNew(im); } static PyObject* _new(PyObject* self, PyObject* args) { char* mode; int xsize, ysize; if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize)) return NULL; return PyImagingNew(ImagingNew(mode, xsize, ysize)); } static PyObject* _new_array(PyObject* self, PyObject* args) { char* mode; int xsize, ysize; if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize)) return NULL; return PyImagingNew(ImagingNewArray(mode, xsize, ysize)); } static PyObject* _new_block(PyObject* self, PyObject* args) { char* mode; int xsize, ysize; if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize)) return NULL; return PyImagingNew(ImagingNewBlock(mode, xsize, ysize)); } static PyObject* _linear_gradient(PyObject* self, PyObject* args) { char* mode; if (!PyArg_ParseTuple(args, "s", &mode)) return NULL; return PyImagingNew(ImagingFillLinearGradient(mode)); } static PyObject* _radial_gradient(PyObject* self, PyObject* args) { char* mode; if (!PyArg_ParseTuple(args, "s", &mode)) return NULL; return PyImagingNew(ImagingFillRadialGradient(mode)); } static PyObject* _open_ppm(PyObject* self, PyObject* args) { char* filename; if (!PyArg_ParseTuple(args, "s", &filename)) return NULL; return PyImagingNew(ImagingOpenPPM(filename)); } static PyObject* _blend(ImagingObject* self, PyObject* args) { ImagingObject* imagep1; ImagingObject* imagep2; double alpha; alpha = 0.5; if (!PyArg_ParseTuple(args, "O!O!|d", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2, &alpha)) return NULL; return PyImagingNew(ImagingBlend(imagep1->image, imagep2->image, (float) alpha)); } /* -------------------------------------------------------------------- */ /* METHODS */ /* -------------------------------------------------------------------- */ static PyObject* _convert(ImagingObject* self, PyObject* args) { char* mode; int dither = 0; ImagingObject *paletteimage = NULL; if (!PyArg_ParseTuple(args, "s|iO", &mode, &dither, &paletteimage)) return NULL; if (paletteimage != NULL) { if (!PyImaging_Check(paletteimage)) { PyObject_Print((PyObject *)paletteimage, stderr, 0); PyErr_SetString(PyExc_ValueError, "palette argument must be image with mode 'P'"); return NULL; } if (paletteimage->image->palette == NULL) { PyErr_SetString(PyExc_ValueError, "null palette"); return NULL; } } return PyImagingNew(ImagingConvert(self->image, mode, paletteimage ? paletteimage->image->palette : NULL, dither)); } static PyObject* _convert2(ImagingObject* self, PyObject* args) { ImagingObject* imagep1; ImagingObject* imagep2; if (!PyArg_ParseTuple(args, "O!O!", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2)) return NULL; if (!ImagingConvert2(imagep1->image, imagep2->image)) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _convert_matrix(ImagingObject* self, PyObject* args) { char* mode; float m[12]; if (!PyArg_ParseTuple(args, "s(ffff)", &mode, m+0, m+1, m+2, m+3)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "s(ffffffffffff)", &mode, m+0, m+1, m+2, m+3, m+4, m+5, m+6, m+7, m+8, m+9, m+10, m+11)) return NULL; } return PyImagingNew(ImagingConvertMatrix(self->image, mode, m)); } static PyObject* _copy(ImagingObject* self, PyObject* args) { if (!PyArg_ParseTuple(args, "")) return NULL; return PyImagingNew(ImagingCopy(self->image)); } static PyObject* _copy2(ImagingObject* self, PyObject* args) { ImagingObject* imagep1; ImagingObject* imagep2; if (!PyArg_ParseTuple(args, "O!O!", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2)) return NULL; if (!ImagingCopy2(imagep1->image, imagep2->image)) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _crop(ImagingObject* self, PyObject* args) { int x0, y0, x1, y1; if (!PyArg_ParseTuple(args, "(iiii)", &x0, &y0, &x1, &y1)) return NULL; return PyImagingNew(ImagingCrop(self->image, x0, y0, x1, y1)); } static PyObject* _filter(ImagingObject* self, PyObject* args) { Imaging im; int id; if (!PyArg_ParseTuple(args, "i", &id)) return NULL; /* FIXME: replace with user-defined filter kernels */ switch (id) { case 0: im = ImagingFilterBlur(self->image); break; case 1: im = ImagingFilterContour(self->image); break; case 2: im = ImagingFilterDetail(self->image); break; case 3: im = ImagingFilterEdgeEnhance(self->image); break; case 4: im = ImagingFilterEdgeEnhanceMore(self->image); break; case 5: im = ImagingFilterEmboss(self->image); break; case 6: im = ImagingFilterFindEdges(self->image); break; case 7: im = ImagingFilterSmooth(self->image); break; case 8: im = ImagingFilterSmoothMore(self->image); break; case 9: im = ImagingFilterSharpen(self->image); break; default: PyErr_SetString(PyExc_ValueError, "No such builtin kernel"); return NULL; } return PyImagingNew(im); } static PyObject* _getpalette(ImagingObject* self, PyObject* args) { PyObject* palette; int palettesize = 256; int bits; ImagingShuffler pack; char* mode = "RGB"; char* rawmode = "RGB"; if (!PyArg_ParseTuple(args, "|ss", &mode, &rawmode)) return NULL; if (!self->image->palette) { PyErr_SetString(PyExc_ValueError, no_palette); return NULL; } pack = ImagingFindPacker(mode, rawmode, &bits); if (!pack) { PyErr_SetString(PyExc_ValueError, wrong_raw_mode); return NULL; } palette = PyString_FromStringAndSize(NULL, palettesize * bits / 8); if (!palette) return NULL; pack((UINT8*) PyString_AsString(palette), self->image->palette->palette, palettesize); return palette; } static PyObject* _getpixel(ImagingObject* self, PyObject* args) { int x, y; if (!PyArg_ParseTuple(args, "(ii)", &x, &y)) return NULL; return getpixel(self->image, x, y); } static PyObject* _histogram(ImagingObject* self, PyObject* args) { ImagingHistogram h; PyObject* list; int i; union { UINT8 u[2]; INT32 i[2]; FLOAT32 f[2]; } extrema; void* ep; int i0, i1; double f0, f1; PyObject* extremap = NULL; ImagingObject* maskp = NULL; if (!PyArg_ParseTuple(args, "|OO!", &extremap, &Imaging_Type, &maskp)) return NULL; if (extremap) { ep = &extrema; switch (self->image->type) { case 0: if (!PyArg_ParseTuple(extremap, "ii", &i0, &i1)) return NULL; /* FIXME: clip */ extrema.u[0] = i0; extrema.u[1] = i1; break; case 1: if (!PyArg_ParseTuple(extremap, "ii", &i0, &i1)) return NULL; extrema.i[0] = i0; extrema.i[1] = i1; break; case 2: if (!PyArg_ParseTuple(extremap, "dd", &f0, &f1)) return NULL; extrema.f[0] = f0; extrema.f[1] = f1; break; default: ep = NULL; break; } } else ep = NULL; h = ImagingGetHistogram(self->image, (maskp) ? maskp->image : NULL, ep); if (!h) return NULL; /* Build an integer list containing the histogram */ list = PyList_New(h->bands * 256); for (i = 0; i < h->bands * 256; i++) { PyObject* item; item = PyInt_FromLong(h->histogram[i]); if (item == NULL) { Py_DECREF(list); list = NULL; break; } PyList_SetItem(list, i, item); } ImagingHistogramDelete(h); return list; } static PyObject* _offset(ImagingObject* self, PyObject* args) { int xoffset, yoffset; if (!PyArg_ParseTuple(args, "ii", &xoffset, &yoffset)) return NULL; return PyImagingNew(ImagingOffset(self->image, xoffset, yoffset)); } static PyObject* _paste(ImagingObject* self, PyObject* args) { int status; char ink[4]; PyObject* source; int x0, y0, x1, y1; ImagingObject* maskp = NULL; if (!PyArg_ParseTuple(args, "O(iiii)|O!", &source, &x0, &y0, &x1, &y1, &Imaging_Type, &maskp)) return NULL; if (PyImaging_Check(source)) status = ImagingPaste( self->image, PyImaging_AsImaging(source), (maskp) ? maskp->image : NULL, x0, y0, x1, y1 ); else { if (!getink(source, self->image, ink)) return NULL; status = ImagingFill2( self->image, ink, (maskp) ? maskp->image : NULL, x0, y0, x1, y1 ); } if (status < 0) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _point(ImagingObject* self, PyObject* args) { static const char* wrong_number = "wrong number of lut entries"; int n, i; int bands; Imaging im; PyObject* list; char* mode; if (!PyArg_ParseTuple(args, "Oz", &list, &mode)) return NULL; if (mode && strcmp(mode, "F") == 0) { FLOAT32* data; /* map to floating point */ n = 256; data = getlist(list, &n, wrong_number, TYPE_FLOAT32); if (!data) return NULL; im = ImagingPoint(self->image, mode, data); free(data); } else { INT32* data; UINT8 lut[1024]; if (mode) { bands = getbands(mode); if (bands < 0) return NULL; } else bands = self->image->bands; /* map to integer data */ n = 256 * bands; data = getlist(list, &n, wrong_number, TYPE_INT32); if (!data) return NULL; if (mode && strcmp(mode, "I") == 0) im = ImagingPoint(self->image, mode, data); else if (mode && bands > 1) { for (i = 0; i < 256; i++) { lut[i*4] = CLIP(data[i]); lut[i*4+1] = CLIP(data[i+256]); lut[i*4+2] = CLIP(data[i+512]); if (n > 768) lut[i*4+3] = CLIP(data[i+768]); } im = ImagingPoint(self->image, mode, lut); } else { /* map individual bands */ for (i = 0; i < n; i++) lut[i] = CLIP(data[i]); im = ImagingPoint(self->image, mode, lut); } free(data); } return PyImagingNew(im); } static PyObject* _point_transform(ImagingObject* self, PyObject* args) { double scale = 1.0; double offset = 0.0; if (!PyArg_ParseTuple(args, "|dd", &scale, &offset)) return NULL; return PyImagingNew(ImagingPointTransform(self->image, scale, offset)); } static PyObject* _putdata(ImagingObject* self, PyObject* args) { Imaging image; int n, i, x, y; PyObject* data; double scale = 1.0; double offset = 0.0; if (!PyArg_ParseTuple(args, "O|dd", &data, &scale, &offset)) return NULL; if (!PySequence_Check(data)) { PyErr_SetString(PyExc_TypeError, must_be_sequence); return NULL; } image = self->image; if (!image->image8) { PyErr_SetString(PyExc_TypeError, wrong_mode); return NULL; } n = PyObject_Length(data); if (n > (int) (image->xsize * image->ysize)) { PyErr_SetString(PyExc_TypeError, "too many data entries"); return NULL; } if (PyString_Check(data)) { unsigned char* p; p = (unsigned char*) PyString_AS_STRING((PyStringObject*) data); if (scale == 1.0 && offset == 0.0) /* Plain string data */ for (i = y = 0; i < n; i += image->xsize, y++) { x = n - i; if (x > (int) image->xsize) x = image->xsize; memcpy(image->image8[y], p+i, x); } else /* Scaled and clipped string data */ for (i = x = y = 0; i < n; i++) { image->image8[y][x] = CLIP((int) (p[i] * scale + offset)); if (++x >= (int) image->xsize) x = 0, y++; } } else { if (scale == 1.0 && offset == 0.0) { /* Clipped data */ if (PyList_Check(data)) { for (i = x = y = 0; i < n; i++) { PyObject *op = PyList_GET_ITEM(data, i); image->image8[y][x] = CLIP(PyInt_AsLong(op)); if (++x >= (int) image->xsize) x = 0, y++; } } else { for (i = x = y = 0; i < n; i++) { PyObject *op = PySequence_GetItem(data, i); image->image8[y][x] = CLIP(PyInt_AsLong(op)); Py_XDECREF(op); if (++x >= (int) image->xsize) x = 0, y++; } } } else { if (PyList_Check(data)) { /* Scaled and clipped data */ for (i = x = y = 0; i < n; i++) { PyObject *op = PyList_GET_ITEM(data, i); image->image8[y][x] = CLIP( (int) (PyFloat_AsDouble(op) * scale + offset)); if (++x >= (int) image->xsize) x = 0, y++; } } else { for (i = x = y = 0; i < n; i++) { PyObject *op = PySequence_GetItem(data, i); image->image8[y][x] = CLIP( (int) (PyFloat_AsDouble(op) * scale + offset)); Py_XDECREF(op); if (++x >= (int) image->xsize) x = 0, y++; } } } PyErr_Clear(); /* Avoid weird exceptions */ } Py_INCREF(Py_None); return Py_None; } #ifdef WITH_QUANTIZE #include "Quant.h" static PyObject* _quantize(ImagingObject* self, PyObject* args) { int colours = 256; int method = 0; int kmeans = 0; if (!PyArg_ParseTuple(args, "|iii", &colours, &method, &kmeans)) return NULL; return PyImagingNew(ImagingQuantize(self->image, colours, method, kmeans)); } #endif static PyObject* _putpalette(ImagingObject* self, PyObject* args) { ImagingShuffler unpack; int bits; char* rawmode; UINT8* palette; int palettesize; if (!PyArg_ParseTuple(args, "ss#", &rawmode, &palette, &palettesize)) return NULL; if (strcmp(self->image->mode, "L") != 0 && strcmp(self->image->mode, "P")) { PyErr_SetString(PyExc_ValueError, wrong_mode); return NULL; } unpack = ImagingFindUnpacker("RGB", rawmode, &bits); if (!unpack) { PyErr_SetString(PyExc_ValueError, wrong_raw_mode); return NULL; } ImagingPaletteDelete(self->image->palette); strcpy(self->image->mode, "P"); self->image->palette = ImagingPaletteNew("RGB"); unpack(self->image->palette->palette, palette, palettesize * 8 / bits); Py_INCREF(Py_None); return Py_None; } static PyObject* _putpalettealpha(ImagingObject* self, PyObject* args) { int index; int alpha = 0; if (!PyArg_ParseTuple(args, "i|i", &index, &alpha)) return NULL; if (!self->image->palette) { PyErr_SetString(PyExc_ValueError, no_palette); return NULL; } if (index < 0 || index >= 256) { PyErr_SetString(PyExc_ValueError, outside_palette); return NULL; } strcpy(self->image->palette->mode, "RGBA"); self->image->palette->palette[index*4+3] = (UINT8) alpha; Py_INCREF(Py_None); return Py_None; } static PyObject* _putpixel(ImagingObject* self, PyObject* args) { Imaging im; char ink[4]; int x, y; PyObject* color; if (!PyArg_ParseTuple(args, "(ii)O", &x, &y, &color)) return NULL; im = self->image; if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) { PyErr_SetString(PyExc_IndexError, outside_image); return NULL; } if (!getink(color, im, ink)) return NULL; if (im->image8) im->image8[y][x] = ink[0]; else im->image32[y][x] = *((INT32*) ink); Py_INCREF(Py_None); return Py_None; } static PyObject* _resize(ImagingObject* self, PyObject* args) { Imaging imIn; Imaging imOut; int xsize, ysize; int filter = IMAGING_TRANSFORM_NEAREST; if (!PyArg_ParseTuple(args, "(ii)|i", &xsize, &ysize, &filter)) return NULL; imIn = self->image; imOut = ImagingNew(imIn->mode, xsize, ysize); if (imOut) ImagingResize(imOut, imIn, filter); return PyImagingNew(imOut); } static PyObject* _rotate(ImagingObject* self, PyObject* args) { Imaging imOut; Imaging imIn; double theta; int filter = IMAGING_TRANSFORM_NEAREST; if (!PyArg_ParseTuple(args, "d|i", &theta, &filter)) return NULL; imIn = self->image; theta = fmod(theta, 360.0); if (theta < 0.0) theta += 360; if (filter && imIn->type != IMAGING_TYPE_SPECIAL) { /* Rotate with resampling filter */ imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize); ImagingRotate(imOut, imIn, theta, filter); } else if (theta == 90.0 || theta == 270.0) { /* Use fast version */ imOut = ImagingNew(imIn->mode, imIn->ysize, imIn->xsize); if (imOut) { if (theta == 90.0) ImagingRotate90(imOut, imIn); else ImagingRotate270(imOut, imIn); } } else { imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize); if (imOut) { if (theta == 0.0) /* No rotation: simply copy the input image */ ImagingCopy2(imOut, imIn); else if (theta == 180.0) /* Use fast version */ ImagingRotate180(imOut, imIn); else /* Use ordinary version */ ImagingRotate(imOut, imIn, theta, 0); } } return PyImagingNew(imOut); } static PyObject* _stretch(ImagingObject* self, PyObject* args) { Imaging imIn; Imaging imTemp; Imaging imOut; int xsize, ysize; int filter = IMAGING_TRANSFORM_NEAREST; if (!PyArg_ParseTuple(args, "(ii)|i", &xsize, &ysize, &filter)) return NULL; imIn = self->image; /* two-pass resize: minimize size of intermediate image */ if (imIn->xsize * ysize < xsize * imIn->ysize) imTemp = ImagingNew(imIn->mode, imIn->xsize, ysize); else imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize); if (!imTemp) return NULL; /* first pass */ if (!ImagingStretch(imTemp, imIn, filter)) { ImagingDelete(imTemp); return NULL; } imOut = ImagingNew(imIn->mode, xsize, ysize); if (!imOut) { ImagingDelete(imTemp); return NULL; } /* second pass */ if (!ImagingStretch(imOut, imTemp, filter)) { ImagingDelete(imOut); ImagingDelete(imTemp); return NULL; } ImagingDelete(imTemp); return PyImagingNew(imOut); } static PyObject* _transform2(ImagingObject* self, PyObject* args) { static const char* wrong_number = "wrong number of matrix entries"; Imaging imIn; Imaging imOut; int n; double *a; ImagingObject* imagep; int x0, y0, x1, y1; int method; PyObject* data; int filter = IMAGING_TRANSFORM_NEAREST; int fill = 1; if (!PyArg_ParseTuple(args, "(iiii)O!iO|ii", &x0, &y0, &x1, &y1, &Imaging_Type, &imagep, &method, &data, &filter, &fill)) return NULL; switch (method) { case IMAGING_TRANSFORM_AFFINE: n = 6; break; case IMAGING_TRANSFORM_QUAD: n = 8; break; default: n = -1; /* force error */ } a = getlist(data, &n, wrong_number, TYPE_DOUBLE); if (!a) return NULL; imOut = self->image; imIn = imagep->image; /* FIXME: move transform dispatcher into libImaging */ switch (method) { case IMAGING_TRANSFORM_AFFINE: imOut = ImagingTransformAffine( imOut, imIn, x0, y0, x1, y1, a, filter, 1 ); break; case IMAGING_TRANSFORM_QUAD: imOut = ImagingTransformQuad( imOut, imIn, x0, y0, x1, y1, a, filter, 1 ); break; default: ImagingError_ValueError("bad transform method"); } free(a); if (!imOut) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _transpose(ImagingObject* self, PyObject* args) { Imaging imIn; Imaging imOut; int op; if (!PyArg_ParseTuple(args, "i", &op)) return NULL; imIn = self->image; switch (op) { case 0: /* flip left right */ case 1: /* flip top bottom */ case 3: /* rotate 180 */ imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize); break; case 2: /* rotate 90 */ case 4: /* rotate 270 */ imOut = ImagingNew(imIn->mode, imIn->ysize, imIn->xsize); break; default: PyErr_SetString(PyExc_ValueError, "No such transpose operation"); return NULL; } if (imOut) switch (op) { case 0: ImagingFlipLeftRight(imOut, imIn); break; case 1: ImagingFlipTopBottom(imOut, imIn); break; case 2: ImagingRotate90(imOut, imIn); break; case 3: ImagingRotate180(imOut, imIn); break; case 4: ImagingRotate270(imOut, imIn); break; } return PyImagingNew(imOut); } /* -------------------------------------------------------------------- */ static PyObject* _isblock(ImagingObject* self, PyObject* args) { return Py_BuildValue("l", (long) self->image->block); } static PyObject* _getbbox(ImagingObject* self, PyObject* args) { int bbox[4]; if (!ImagingGetBBox(self->image, bbox)) { Py_INCREF(Py_None); return Py_None; } return Py_BuildValue("iiii", bbox[0], bbox[1], bbox[2], bbox[3]); } static PyObject* _getextrema(ImagingObject* self, PyObject* args) { union { UINT8 u[2]; INT32 i[2]; FLOAT32 f[2]; } extrema; int status; status = ImagingGetExtrema(self->image, &extrema); if (status < 0) return NULL; if (status) switch (self->image->type) { case 0: return Py_BuildValue("ii", extrema.u[0], extrema.u[1]); case 1: return Py_BuildValue("ii", extrema.i[0], extrema.i[1]); case 2: return Py_BuildValue("dd", extrema.f[0], extrema.f[1]); } Py_INCREF(Py_None); return Py_None; } static PyObject* _getprojection(ImagingObject* self, PyObject* args) { unsigned char* xprofile; unsigned char* yprofile; PyObject* result; xprofile = malloc(self->image->xsize); yprofile = malloc(self->image->ysize); if (xprofile == NULL || yprofile == NULL) { free(xprofile); free(yprofile); PyErr_NoMemory(); return NULL; } ImagingGetProjection(self->image, (unsigned char *)xprofile, (unsigned char *)yprofile); result = Py_BuildValue("s#s#", xprofile, self->image->xsize, yprofile, self->image->ysize); free(xprofile); free(yprofile); return result; } /* -------------------------------------------------------------------- */ static PyObject* _getband(ImagingObject* self, PyObject* args) { int band; if (!PyArg_ParseTuple(args, "i", &band)) return NULL; return PyImagingNew(ImagingGetBand(self->image, band)); } static PyObject* _putband(ImagingObject* self, PyObject* args) { ImagingObject* imagep; int band; if (!PyArg_ParseTuple(args, "O!i", &Imaging_Type, &imagep, &band)) return NULL; if (!ImagingPutBand(self->image, imagep->image, band)) return NULL; Py_INCREF(Py_None); return Py_None; } /* -------------------------------------------------------------------- */ #ifdef WITH_IMAGECHOPS static PyObject* _chop_invert(ImagingObject* self, PyObject* args) { return PyImagingNew(ImagingNegative(self->image)); } static PyObject* _chop_lighter(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopLighter(self->image, imagep->image)); } static PyObject* _chop_darker(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopDarker(self->image, imagep->image)); } static PyObject* _chop_difference(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopDifference(self->image, imagep->image)); } static PyObject* _chop_multiply(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopMultiply(self->image, imagep->image)); } static PyObject* _chop_screen(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopScreen(self->image, imagep->image)); } static PyObject* _chop_add(ImagingObject* self, PyObject* args) { ImagingObject* imagep; float scale; int offset; scale = 1.0; offset = 0; if (!PyArg_ParseTuple(args, "O!|fi", &Imaging_Type, &imagep, &scale, &offset)) return NULL; return PyImagingNew(ImagingChopAdd(self->image, imagep->image, scale, offset)); } static PyObject* _chop_subtract(ImagingObject* self, PyObject* args) { ImagingObject* imagep; float scale; int offset; scale = 1.0; offset = 0; if (!PyArg_ParseTuple(args, "O!|fi", &Imaging_Type, &imagep, &scale, &offset)) return NULL; return PyImagingNew(ImagingChopSubtract(self->image, imagep->image, scale, offset)); } static PyObject* _chop_and(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopAnd(self->image, imagep->image)); } static PyObject* _chop_or(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopOr(self->image, imagep->image)); } static PyObject* _chop_xor(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopXor(self->image, imagep->image)); } static PyObject* _chop_add_modulo(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopAddModulo(self->image, imagep->image)); } static PyObject* _chop_subtract_modulo(ImagingObject* self, PyObject* args) { ImagingObject* imagep; if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) return NULL; return PyImagingNew(ImagingChopSubtractModulo(self->image, imagep->image)); } #endif /* -------------------------------------------------------------------- */ #ifdef WITH_IMAGEDRAW static PyObject* _font_new(PyObject* self_, PyObject* args) { ImagingFontObject *self; int i, y0, y1; static const char* wrong_length = "descriptor table has wrong size"; ImagingObject* imagep; unsigned char* glyphdata; int glyphdata_length; if (!PyArg_ParseTuple(args, "O!s#", &Imaging_Type, &imagep, &glyphdata, &glyphdata_length)) return NULL; if (glyphdata_length != 256 * 20) { PyErr_SetString(PyExc_ValueError, wrong_length); return NULL; } self = PyObject_NEW(ImagingFontObject, &ImagingFont_Type); if (self == NULL) return NULL; /* glyph bitmap */ self->bitmap = imagep->image; y0 = y1 = 0; /* glyph glyphs */ for (i = 0; i < 256; i++) { self->glyphs[i].dx = S16(B16(glyphdata, 0)); self->glyphs[i].dy = S16(B16(glyphdata, 2)); self->glyphs[i].dx0 = S16(B16(glyphdata, 4)); self->glyphs[i].dy0 = S16(B16(glyphdata, 6)); self->glyphs[i].dx1 = S16(B16(glyphdata, 8)); self->glyphs[i].dy1 = S16(B16(glyphdata, 10)); self->glyphs[i].sx0 = S16(B16(glyphdata, 12)); self->glyphs[i].sy0 = S16(B16(glyphdata, 14)); self->glyphs[i].sx1 = S16(B16(glyphdata, 16)); self->glyphs[i].sy1 = S16(B16(glyphdata, 18)); if (self->glyphs[i].dy0 < y0) y0 = self->glyphs[i].dy0; if (self->glyphs[i].dy1 > y1) y1 = self->glyphs[i].dy1; glyphdata += 20; } self->baseline = -y0; self->ysize = y1 - y0; /* keep a reference to the bitmap object */ Py_INCREF(imagep); self->ref = imagep; return (PyObject*) self; } static void _font_dealloc(ImagingFontObject* self) { Py_XDECREF(self->ref); PyMem_DEL(self); } static inline int textwidth(ImagingFontObject* self, const unsigned char* text) { int xsize; for (xsize = 0; *text; text++) xsize += self->glyphs[*text].dx; return xsize; } static PyObject* _font_getmask(ImagingFontObject* self, PyObject* args) { Imaging im; Imaging bitmap; int x, b; int status; Glyph* glyph; unsigned char* text; if (!PyArg_ParseTuple(args, "s", &text)) return NULL; im = ImagingNew(self->bitmap->mode, textwidth(self, text), self->ysize); if (!im) return NULL; b = 0; ImagingFill(im, &b); b = self->baseline; for (x = 0; *text; text++) { glyph = &self->glyphs[*text]; bitmap = ImagingCrop( self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1 ); if (!bitmap) goto failed; status = ImagingPaste( im, bitmap, NULL, glyph->dx0+x, glyph->dy0+b, glyph->dx1+x, glyph->dy1+b ); ImagingDelete(bitmap); if (status < 0) goto failed; x = x + glyph->dx; b = b + glyph->dy; } return PyImagingNew(im); failed: ImagingDelete(im); return NULL; } static PyObject* _font_getsize(ImagingFontObject* self, PyObject* args) { unsigned char* text; if (!PyArg_ParseTuple(args, "s", &text)) return NULL; return Py_BuildValue("ii", textwidth(self, text), self->ysize); } static struct PyMethodDef _font_methods[] = { {"getmask", (PyCFunction)_font_getmask, 1}, {"getsize", (PyCFunction)_font_getsize, 1}, {NULL, NULL} /* sentinel */ }; static PyObject* _font_getattr(ImagingFontObject* self, char* name) { return Py_FindMethod(_font_methods, (PyObject*) self, name); } static PyObject* _draw_ink(ImagingObject* self, PyObject* args) { INT32 ink = 0; PyObject* color; if (!PyArg_ParseTuple(args, "O", &color)) return NULL; if (!getink(color, self->image, (char*) &ink)) return NULL; return Py_BuildValue("i", (int) ink); } static PyObject* _draw_arc(ImagingObject* self, PyObject* args) { int x0, y0, x1, y1; int ink; int start, end; if (!PyArg_ParseTuple(args, "(iiii)iii", &x0, &y0, &x1, &y1, &start, &end, &ink)) return NULL; if (ImagingDrawArc(self->image, x0, y0, x1, y1, start, end, &ink) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _draw_bitmap(ImagingObject* self, PyObject* args) { int x0, y0; ImagingObject* bitmap; int ink; if (!PyArg_ParseTuple(args, "(ii)O!i", &x0, &y0, &Imaging_Type, &bitmap, &ink)) return NULL; if (ImagingDrawBitmap(self->image, x0, y0, bitmap->image, &ink) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _draw_chord(ImagingObject* self, PyObject* args) { int x0, y0, x1, y1; int ink, fill; int start, end; if (!PyArg_ParseTuple(args, "(iiii)iiii", &x0, &y0, &x1, &y1, &start, &end, &ink, &fill)) return NULL; if (ImagingDrawChord(self->image, x0, y0, x1, y1, start, end, &ink, fill) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _draw_ellipse(ImagingObject* self, PyObject* args) { int x0, y0, x1, y1; int ink, fill; if (!PyArg_ParseTuple(args, "(iiii)ii", &x0, &y0, &x1, &y1, &ink, &fill)) return NULL; if (ImagingDrawEllipse(self->image, x0, y0, x1, y1, &ink, fill) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _draw_line(ImagingObject* self, PyObject* args) { int x0, y0, x1, y1; int ink; if (!PyArg_ParseTuple(args, "(ii)(ii)i", &x0, &y0, &x1, &y1, &ink)) return NULL; if (ImagingDrawLine(self->image, x0, y0, x1, y1, &ink) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } extern int PyPath_Flatten(PyObject* data, double **xy); static PyObject* _draw_lines(ImagingObject* self, PyObject* args) { double *xy; int i, n; PyObject *data; int ink; if (!PyArg_ParseTuple(args, "Oi", &data, &ink)) return NULL; n = PyPath_Flatten(data, &xy); if (n < 0) return NULL; for (i = 0; i < n-1; i++) { double *p = &xy[i+i]; if (ImagingDrawLine(self->image, (int) p[0], (int) p[1], (int) p[2], (int) p[3], &ink) < 0) { free(xy); return NULL; } } free(xy); Py_INCREF(Py_None); return Py_None; } static PyObject* _draw_point(ImagingObject* self, PyObject* args) { int x, y; int ink; if (!PyArg_ParseTuple(args, "(ii)i", &x, &y, &ink)) return NULL; if (ImagingDrawPoint(self->image, x, y, &ink) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _draw_points(ImagingObject* self, PyObject* args) { double *xy; int i, n; PyObject *data; int ink; if (!PyArg_ParseTuple(args, "Oi", &data, &ink)) return NULL; n = PyPath_Flatten(data, &xy); if (n < 0) return NULL; for (i = 0; i < n; i++) { double *p = &xy[i+i]; if (ImagingDrawPoint(self->image, (int) p[0], (int) p[1], &ink) < 0) { free(xy); return NULL; } } free(xy); Py_INCREF(Py_None); return Py_None; } #ifdef WITH_ARROW /* from outline.c */ extern ImagingOutline PyOutline_AsOutline(PyObject* outline); static PyObject* _draw_outline(ImagingObject* self, PyObject* args) { ImagingOutline outline; PyObject* outline_; int ink; int fill = 0; if (!PyArg_ParseTuple(args, "Oi|i", &outline_, &ink, &fill)) return NULL; outline = PyOutline_AsOutline(outline_); if (!outline) { PyErr_SetString(PyExc_TypeError, "expected outline object"); return NULL; } if (ImagingDrawOutline(self->image, outline, &ink, fill) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } #endif static PyObject* _draw_pieslice(ImagingObject* self, PyObject* args) { int x0, y0, x1, y1; int ink, fill; int start, end; if (!PyArg_ParseTuple(args, "(iiii)iiii", &x0, &y0, &x1, &y1, &start, &end, &ink, &fill)) return NULL; if (ImagingDrawPieslice(self->image, x0, y0, x1, y1, start, end, &ink, fill) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject* _draw_polygon(ImagingObject* self, PyObject* args) { double *xy; int *ixy; int n, i; PyObject* data; int ink; int fill = 0; if (!PyArg_ParseTuple(args, "Oi|i", &data, &ink, &fill)) return NULL; n = PyPath_Flatten(data, &xy); if (n < 0) return NULL; /* Copy list of vertices to array */ ixy = (int*) malloc(n * 2 * sizeof(int)); for (i = 0; i < n; i++) { ixy[i+i] = (int) xy[i+i]; ixy[i+i+1] = (int) xy[i+i+1]; } free(xy); if (ImagingDrawPolygon(self->image, n, ixy, &ink, fill) < 0) { free(ixy); return NULL; } free(ixy); Py_INCREF(Py_None); return Py_None; } static PyObject* _draw_rectangle(ImagingObject* self, PyObject* args) { float x0, y0, x1, y1; int ink; int fill = 0; if (!PyArg_ParseTuple(args, "(ffff)i|i", &x0, &y0, &x1, &y1, &ink, &fill)) return NULL; if (ImagingDrawRectangle(self->image, x0, y0, x1, y1, &ink, fill) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } #endif /* -------------------------------------------------------------------- */ /* EFFECTS (experimental) */ /* -------------------------------------------------------------------- */ #ifdef WITH_EFFECTS static PyObject* _effect_mandelbrot(ImagingObject* self, PyObject* args) { int xsize = 512; int ysize = 512; double extent[4]; int quality = 100; extent[0] = -3; extent[1] = -2.5; extent[2] = 2; extent[3] = 2.5; if (!PyArg_ParseTuple(args, "|(ii)(dddd)i", &xsize, &ysize, &extent[0], &extent[1], &extent[2], &extent[3], &quality)) return NULL; return PyImagingNew(ImagingEffectMandelbrot(xsize, ysize, extent, quality)); } static PyObject* _effect_noise(ImagingObject* self, PyObject* args) { int xsize, ysize; float sigma = 128; if (!PyArg_ParseTuple(args, "(ii)|f", &xsize, &ysize, &sigma)) return NULL; return PyImagingNew(ImagingEffectNoise(xsize, ysize, sigma)); } static PyObject* _effect_spread(ImagingObject* self, PyObject* args) { int dist; if (!PyArg_ParseTuple(args, "i", &dist)) return NULL; return PyImagingNew(ImagingEffectSpread(self->image, dist)); } #endif /* -------------------------------------------------------------------- */ /* UTILITIES */ /* -------------------------------------------------------------------- */ static PyObject* _crc32(PyObject* self, PyObject* args) { unsigned char* buffer; int bytes; int hi, lo; UINT32 crc; hi = lo = 0; if (!PyArg_ParseTuple(args, "s#|(ii)", &buffer, &bytes, &hi, &lo)) return NULL; crc = ((UINT32) (hi & 0xFFFF) << 16) + (lo & 0xFFFF); crc = ImagingCRC32(crc, (unsigned char *)buffer, bytes); return Py_BuildValue("ii", (crc >> 16) & 0xFFFF, crc & 0xFFFF); } static PyObject* _getcodecstatus(PyObject* self, PyObject* args) { int status; char* msg; if (!PyArg_ParseTuple(args, "i", &status)) return NULL; switch (status) { case IMAGING_CODEC_OVERRUN: msg = "buffer overrun."; break; case IMAGING_CODEC_BROKEN: msg = "broken data stream."; break; case IMAGING_CODEC_UNKNOWN: msg = "unrecognized data stream contents."; break; case IMAGING_CODEC_CONFIG: msg = "codec configuration error."; break; case IMAGING_CODEC_MEMORY: msg = "out of memory."; break; default: Py_INCREF(Py_None); return Py_None; } return Py_BuildValue("s", msg); } /* -------------------------------------------------------------------- */ /* DEBUGGING HELPERS */ /* -------------------------------------------------------------------- */ #ifdef WITH_DEBUG static PyObject* _save_ppm(ImagingObject* self, PyObject* args) { char* filename; if (!PyArg_ParseTuple(args, "s", &filename)) return NULL; if (!ImagingSavePPM(self->image, filename)) return NULL; Py_INCREF(Py_None); return Py_None; } #endif /* -------------------------------------------------------------------- */ /* methods */ static struct PyMethodDef methods[] = { /* Put commonly used methods first */ {"getpixel", (PyCFunction)_getpixel, 1}, {"putpixel", (PyCFunction)_putpixel, 1}, #ifdef WITH_IMAGEDRAW /* Graphics (ImageDraw) */ {"draw_line", (PyCFunction)_draw_line, 1}, {"draw_lines", (PyCFunction)_draw_lines, 1}, #ifdef WITH_ARROW {"draw_outline", (PyCFunction)_draw_outline, 1}, #endif {"draw_polygon", (PyCFunction)_draw_polygon, 1}, {"draw_rectangle", (PyCFunction)_draw_rectangle, 1}, {"draw_point", (PyCFunction)_draw_point, 1}, {"draw_points", (PyCFunction)_draw_points, 1}, {"draw_arc", (PyCFunction)_draw_arc, 1}, {"draw_bitmap", (PyCFunction)_draw_bitmap, 1}, {"draw_chord", (PyCFunction)_draw_chord, 1}, {"draw_ellipse", (PyCFunction)_draw_ellipse, 1}, {"draw_pieslice", (PyCFunction)_draw_pieslice, 1}, {"draw_ink", (PyCFunction)_draw_ink, 1}, #endif /* Standard processing methods (Image) */ {"convert", (PyCFunction)_convert, 1}, {"convert2", (PyCFunction)_convert2, 1}, {"convert_matrix", (PyCFunction)_convert_matrix, 1}, {"copy", (PyCFunction)_copy, 1}, {"copy2", (PyCFunction)_copy2, 1}, #ifdef WITH_CRACKCODE {"crackcode", (PyCFunction)_crackcode, 1}, #endif {"crop", (PyCFunction)_crop, 1}, {"filter", (PyCFunction)_filter, 1}, {"histogram", (PyCFunction)_histogram, 1}, {"offset", (PyCFunction)_offset, 1}, {"paste", (PyCFunction)_paste, 1}, {"point", (PyCFunction)_point, 1}, {"point_transform", (PyCFunction)_point_transform, 1}, {"putdata", (PyCFunction)_putdata, 1}, #ifdef WITH_QUANTIZE {"quantize", (PyCFunction)_quantize, 1}, #endif {"resize", (PyCFunction)_resize, 1}, {"rotate", (PyCFunction)_rotate, 1}, {"stretch", (PyCFunction)_stretch, 1}, {"transpose", (PyCFunction)_transpose, 1}, {"transform2", (PyCFunction)_transform2, 1}, {"isblock", (PyCFunction)_isblock, 1}, {"getbbox", (PyCFunction)_getbbox, 1}, {"getextrema", (PyCFunction)_getextrema, 1}, {"getprojection", (PyCFunction)_getprojection, 1}, {"getband", (PyCFunction)_getband, 1}, {"putband", (PyCFunction)_putband, 1}, {"getpalette", (PyCFunction)_getpalette, 1}, {"putpalette", (PyCFunction)_putpalette, 1}, {"putpalettealpha", (PyCFunction)_putpalettealpha, 1}, #ifdef WITH_IMAGECHOPS /* Channel operations (ImageChops) */ {"chop_invert", (PyCFunction)_chop_invert, 1}, {"chop_lighter", (PyCFunction)_chop_lighter, 1}, {"chop_darker", (PyCFunction)_chop_darker, 1}, {"chop_difference", (PyCFunction)_chop_difference, 1}, {"chop_multiply", (PyCFunction)_chop_multiply, 1}, {"chop_screen", (PyCFunction)_chop_screen, 1}, {"chop_add", (PyCFunction)_chop_add, 1}, {"chop_subtract", (PyCFunction)_chop_subtract, 1}, {"chop_add_modulo", (PyCFunction)_chop_add_modulo, 1}, {"chop_subtract_modulo", (PyCFunction)_chop_subtract_modulo, 1}, {"chop_and", (PyCFunction)_chop_and, 1}, {"chop_or", (PyCFunction)_chop_or, 1}, {"chop_xor", (PyCFunction)_chop_xor, 1}, #endif #ifdef WITH_EFFECTS /* Special effects */ {"effect_spread", (PyCFunction)_effect_spread, 1}, #endif /* Misc. */ {"new_array", (PyCFunction)_new_array, 1}, {"new_block", (PyCFunction)_new_block, 1}, {"save_ppm", (PyCFunction)_save_ppm, 1}, {NULL, NULL} /* sentinel */ }; /* attributes */ static PyObject* _getattr(ImagingObject* self, char* name) { PyObject* res; res = Py_FindMethod(methods, (PyObject*) self, name); if (res) return res; PyErr_Clear(); if (strcmp(name, "mode") == 0) return Py_BuildValue("s", self->image->mode); if (strcmp(name, "size") == 0) return Py_BuildValue("ii", self->image->xsize, self->image->ysize); if (strcmp(name, "bands") == 0) return Py_BuildValue("i", self->image->bands); if (strcmp(name, "id") == 0) return Py_BuildValue("l", (long) self->image); PyErr_SetString(PyExc_AttributeError, name); return NULL; } /* basic sequence semantics */ static int image_length(ImagingObject *self) { Imaging im = self->image; return im->xsize * im->ysize; } static PyObject * image_item(ImagingObject *self, int i) { int x, y; Imaging im = self->image; x = i % im->xsize; y = i / im->xsize; return getpixel(im, x, y); } static PySequenceMethods image_as_sequence = { (inquiry)image_length, /*sq_length*/ (binaryfunc)0, /*sq_concat*/ (intargfunc)0, /*sq_repeat*/ (intargfunc)image_item, /*sq_item*/ (intintargfunc)0, /*sq_slice*/ (intobjargproc)0, /*sq_ass_item*/ (intintobjargproc)0, /*sq_ass_slice*/ }; /* type description */ statichere PyTypeObject Imaging_Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "ImagingCore", /*tp_name*/ sizeof(ImagingObject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number */ &image_as_sequence, /*tp_as_sequence */ 0, /*tp_as_mapping */ 0 /*tp_hash*/ }; #ifdef WITH_IMAGEDRAW statichere PyTypeObject ImagingFont_Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "ImagingFont", /*tp_name*/ sizeof(ImagingFontObject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)_font_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)_font_getattr, /*tp_getattr*/ }; #endif /* -------------------------------------------------------------------- */ /* FIXME: this is something of a mess. Should replace this with pluggable codecs, but not before PIL 1.1 */ /* Decoders (in decode.c) */ extern PyObject* PyImaging_BitDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_FliDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_GifDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_HexDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_JpegDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_TiffLzwDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_MspDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_PackbitsDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_PcdDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_PcxDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_RawDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_SunRleDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_TgaRleDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_XbmDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_ZipDecoderNew(PyObject* self, PyObject* args); /* Encoders (in encode.c) */ extern PyObject* PyImaging_EpsEncoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_GifEncoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_JpegEncoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_PcxEncoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_RawEncoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_XbmEncoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_ZipEncoderNew(PyObject* self, PyObject* args); /* Display support (in display.c) */ extern PyObject* PyImaging_DisplayWin32(PyObject* self, PyObject* args); extern PyObject* PyImaging_DisplayModeWin32(PyObject* self, PyObject* args); extern PyObject* PyImaging_GrabScreenWin32(PyObject* self, PyObject* args); /* Experimental path stuff (in path.c) */ extern PyObject* PyPath_Create(ImagingObject* self, PyObject* args); /* Experimental outline stuff (in outline.c) */ extern PyObject* PyOutline_Create(ImagingObject* self, PyObject* args); extern PyObject* PyImaging_Mapper(PyObject* self, PyObject* args); static PyMethodDef functions[] = { /* Object factories */ {"blend", (PyCFunction)_blend, 1}, {"fill", (PyCFunction)_fill, 1}, {"new", (PyCFunction)_new, 1}, /* Functions */ {"convert", (PyCFunction)_convert2, 1}, {"copy", (PyCFunction)_copy2, 1}, /* Codecs */ {"bit_decoder", (PyCFunction)PyImaging_BitDecoderNew, 1}, {"eps_encoder", (PyCFunction)PyImaging_EpsEncoderNew, 1}, {"fli_decoder", (PyCFunction)PyImaging_FliDecoderNew, 1}, {"gif_decoder", (PyCFunction)PyImaging_GifDecoderNew, 1}, {"gif_encoder", (PyCFunction)PyImaging_GifEncoderNew, 1}, {"hex_decoder", (PyCFunction)PyImaging_HexDecoderNew, 1}, {"hex_encoder", (PyCFunction)PyImaging_EpsEncoderNew, 1}, /* EPS=HEX! */ #ifdef HAVE_LIBJPEG {"jpeg_decoder", (PyCFunction)PyImaging_JpegDecoderNew, 1}, {"jpeg_encoder", (PyCFunction)PyImaging_JpegEncoderNew, 1}, #endif {"tiff_lzw_decoder", (PyCFunction)PyImaging_TiffLzwDecoderNew, 1}, {"msp_decoder", (PyCFunction)PyImaging_MspDecoderNew, 1}, {"packbits_decoder", (PyCFunction)PyImaging_PackbitsDecoderNew, 1}, {"pcd_decoder", (PyCFunction)PyImaging_PcdDecoderNew, 1}, {"pcx_decoder", (PyCFunction)PyImaging_PcxDecoderNew, 1}, {"pcx_encoder", (PyCFunction)PyImaging_PcxEncoderNew, 1}, {"raw_decoder", (PyCFunction)PyImaging_RawDecoderNew, 1}, {"raw_encoder", (PyCFunction)PyImaging_RawEncoderNew, 1}, {"sun_rle_decoder", (PyCFunction)PyImaging_SunRleDecoderNew, 1}, {"tga_rle_decoder", (PyCFunction)PyImaging_TgaRleDecoderNew, 1}, {"xbm_decoder", (PyCFunction)PyImaging_XbmDecoderNew, 1}, {"xbm_encoder", (PyCFunction)PyImaging_XbmEncoderNew, 1}, #ifdef HAVE_LIBZ {"zip_decoder", (PyCFunction)PyImaging_ZipDecoderNew, 1}, {"zip_encoder", (PyCFunction)PyImaging_ZipEncoderNew, 1}, #endif /* Memory mapping */ #ifdef WITH_MAPPING #ifdef WIN32 {"map", (PyCFunction)PyImaging_Mapper, 1}, #endif #endif /* Display support */ #ifdef WIN32 {"display", (PyCFunction)PyImaging_DisplayWin32, 1}, {"display_mode", (PyCFunction)PyImaging_DisplayModeWin32, 1}, {"grabscreen", (PyCFunction)PyImaging_GrabScreenWin32, 1}, #endif /* Utilities */ {"crc32", (PyCFunction)_crc32, 1}, {"getcodecstatus", (PyCFunction)_getcodecstatus, 1}, /* Debugging stuff */ {"open_ppm", (PyCFunction)_open_ppm, 1}, /* Special effects (experimental) */ #ifdef WITH_EFFECTS {"effect_mandelbrot", (PyCFunction)_effect_mandelbrot, 1}, {"effect_noise", (PyCFunction)_effect_noise, 1}, {"linear_gradient", (PyCFunction)_linear_gradient, 1}, {"radial_gradient", (PyCFunction)_radial_gradient, 1}, {"wedge", (PyCFunction)_linear_gradient, 1}, /* Compatibility */ #endif /* Drawing support stuff */ #ifdef WITH_IMAGEDRAW {"font", (PyCFunction)_font_new, 1}, #endif /* Experimental path stuff */ #ifdef WITH_IMAGEPATH {"path", (PyCFunction)PyPath_Create, 1}, #endif /* Experimental arrow graphics stuff */ #ifdef WITH_ARROW {"outline", (PyCFunction)PyOutline_Create, 1}, #endif {NULL, NULL} /* sentinel */ }; DL_EXPORT(void) init_imaging(void) { /* Patch object type */ Imaging_Type.ob_type = &PyType_Type; #ifdef WITH_IMAGEDRAW ImagingFont_Type.ob_type = &PyType_Type; #endif Py_InitModule("_imaging", functions); } Imaging-1.1.3/decode.c0100444000076400007640000003737407442710204014341 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/decode.c#2 $ * * standard decoder interfaces for the Imaging library * * history: * 96-03-28 fl Moved from _imagingmodule.c * 96-04-15 fl Support subregions in setimage * 96-04-19 fl Allocate decoder buffer (where appropriate) * 96-05-02 fl Added jpeg decoder * 96-05-12 fl Compile cleanly as C++ * 96-05-16 fl Added hex decoder * 96-05-26 fl Added jpeg configuration parameters * 96-12-14 fl Added zip decoder * 96-12-30 fl Plugged potential memory leak for tiled images * 97-01-03 fl Added fli and msp decoders * 97-01-04 fl Added sun_rle and tga_rle decoders * 97-05-31 fl Added bitfield decoder * 98-09-11 fl Added orientation and pixelsize fields to tga_rle decoder * 98-12-29 fl Added mode/rawmode argument to decoders * 98-12-30 fl Added mode argument to *all* decoders * * Copyright (c) Secret Labs AB 1997-98. * Copyright (c) Fredrik Lundh 1995-97. * * See the README file for information on usage and redistribution. */ /* FIXME: make these pluggable! */ #include "Python.h" #include "Imaging.h" #include "Gif.h" #include "Lzw.h" #include "Raw.h" #include "Bit.h" /* -------------------------------------------------------------------- */ /* Common */ /* -------------------------------------------------------------------- */ typedef struct { PyObject_HEAD int (*decode)(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); struct ImagingCodecStateInstance state; Imaging im; PyObject* lock; } ImagingDecoderObject; staticforward PyTypeObject ImagingDecoderType; static ImagingDecoderObject* PyImaging_DecoderNew(int contextsize) { ImagingDecoderObject *decoder; void *context; ImagingDecoderType.ob_type = &PyType_Type; decoder = PyObject_NEW(ImagingDecoderObject, &ImagingDecoderType); if (decoder == NULL) return NULL; /* Clear the decoder state */ memset(&decoder->state, 0, sizeof(decoder->state)); /* Allocate decoder context */ if (contextsize > 0) { context = (void*) calloc(1, contextsize); if (!context) { Py_DECREF(decoder); PyErr_NoMemory(); return NULL; } } else context = 0; /* Initialize decoder context */ decoder->state.context = context; /* Target image */ decoder->lock = NULL; decoder->im = NULL; return decoder; } static void _dealloc(ImagingDecoderObject* decoder) { free(decoder->state.buffer); free(decoder->state.context); Py_XDECREF(decoder->lock); PyMem_DEL(decoder); } static PyObject* _decode(ImagingDecoderObject* decoder, PyObject* args) { UINT8* buffer; int bufsize, status; if (!PyArg_ParseTuple(args, "s#", &buffer, &bufsize)) return NULL; status = decoder->decode(decoder->im, &decoder->state, buffer, bufsize); return Py_BuildValue("ii", status, decoder->state.errcode); } extern Imaging PyImaging_AsImaging(PyObject *op); static PyObject* _setimage(ImagingDecoderObject* decoder, PyObject* args) { PyObject* op; Imaging im; ImagingCodecState state; int x0, y0, x1, y1; x0 = y0 = x1 = y1 = 0; /* FIXME: should publish the ImagingType descriptor */ if (!PyArg_ParseTuple(args, "O|(iiii)", &op, &x0, &y0, &x1, &y1)) return NULL; im = PyImaging_AsImaging(op); if (!im) return NULL; decoder->im = im; state = &decoder->state; /* Setup decoding tile extent */ if (x0 == 0 && x1 == 0) { state->xsize = im->xsize; state->ysize = im->ysize; } else { state->xoff = x0; state->yoff = y0; state->xsize = x1 - x0; state->ysize = y1 - y0; } if (state->xsize <= 0 || state->xsize + state->xoff > (int) im->xsize || state->ysize <= 0 || state->ysize + state->yoff > (int) im->ysize) { PyErr_SetString(PyExc_ValueError, "tile cannot extend outside image"); return NULL; } /* Allocate memory buffer (if bits field is set) */ if (state->bits > 0) { state->bytes = (state->bits * state->xsize+7)/8; state->buffer = (UINT8*) malloc(state->bytes); if (!state->buffer) { PyErr_NoMemory(); return NULL; } } /* Keep a reference to the image object, to make sure it doesn't go away before we do */ Py_INCREF(op); Py_XDECREF(decoder->lock); decoder->lock = op; Py_INCREF(Py_None); return Py_None; } static struct PyMethodDef methods[] = { {"decode", (PyCFunction)_decode, 1}, {"setimage", (PyCFunction)_setimage, 1}, {NULL, NULL} /* sentinel */ }; static PyObject* _getattr(ImagingDecoderObject* self, char* name) { return Py_FindMethod(methods, (PyObject*) self, name); } statichere PyTypeObject ImagingDecoderType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "ImagingDecoder", /*tp_name*/ sizeof(ImagingDecoderObject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_hash*/ }; /* -------------------------------------------------------------------- */ int get_unpacker(ImagingDecoderObject* decoder, const char* mode, const char* rawmode) { int bits; ImagingShuffler unpack; unpack = ImagingFindUnpacker(mode, rawmode, &bits); if (!unpack) { Py_DECREF(decoder); PyErr_SetString(PyExc_ValueError, "unknown raw mode"); return -1; } decoder->state.shuffle = unpack; decoder->state.bits = bits; return 0; } /* -------------------------------------------------------------------- */ /* BIT (packed fields) */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_BitDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; int bits = 8; int pad = 8; int fill = 0; int sign = 0; int ystep = 1; if (!PyArg_ParseTuple(args, "s|iiiii", &mode, &bits, &pad, &fill, &sign, &ystep)) return NULL; if (strcmp(mode, "F") != 0) { PyErr_SetString(PyExc_ValueError, "bad image mode"); return NULL; } decoder = PyImaging_DecoderNew(sizeof(BITSTATE)); if (decoder == NULL) return NULL; decoder->decode = ImagingBitDecode; decoder->state.ystep = ystep; ((BITSTATE*)decoder->state.context)->bits = bits; ((BITSTATE*)decoder->state.context)->pad = pad; ((BITSTATE*)decoder->state.context)->fill = fill; ((BITSTATE*)decoder->state.context)->sign = sign; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* FLI */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_FliDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; decoder->decode = ImagingFliDecode; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* GIF */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_GifDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; int bits = 8; int interlace = 0; if (!PyArg_ParseTuple(args, "s|ii", &mode, &bits, &interlace)) return NULL; if (strcmp(mode, "L") != 0 && strcmp(mode, "P") != 0) { PyErr_SetString(PyExc_ValueError, "bad image mode"); return NULL; } decoder = PyImaging_DecoderNew(sizeof(GIFDECODERSTATE)); if (decoder == NULL) return NULL; decoder->decode = ImagingGifDecode; ((GIFDECODERSTATE*)decoder->state.context)->bits = bits; ((GIFDECODERSTATE*)decoder->state.context)->interlace = interlace; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* HEX */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_HexDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; if (!PyArg_ParseTuple(args, "ss", &mode, &rawmode)) return NULL; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingHexDecode; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* LZW */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_TiffLzwDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; int filter = 0; if (!PyArg_ParseTuple(args, "ss|i", &mode, &rawmode, &filter)) return NULL; decoder = PyImaging_DecoderNew(sizeof(LZWSTATE)); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingLzwDecode; ((LZWSTATE*)decoder->state.context)->filter = filter; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* MSP */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_MspDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, "1", "1") < 0) return NULL; decoder->decode = ImagingMspDecode; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* PackBits */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_PackbitsDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; if (!PyArg_ParseTuple(args, "ss", &mode, &rawmode)) return NULL; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingPackbitsDecode; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* PCD */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_PcdDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; /* Unpack from PhotoYCC to RGB */ if (get_unpacker(decoder, "RGB", "YCC;P") < 0) return NULL; decoder->decode = ImagingPcdDecode; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* PCX */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_PcxDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; if (!PyArg_ParseTuple(args, "ss", &mode, &rawmode)) return NULL; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingPcxDecode; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* RAW */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_RawDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; int stride = 0; int ystep = 1; if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &stride, &ystep)) return NULL; decoder = PyImaging_DecoderNew(sizeof(RAWSTATE)); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingRawDecode; decoder->state.ystep = ystep; ((RAWSTATE*)decoder->state.context)->stride = stride; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* SUN RLE */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_SunRleDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; if (!PyArg_ParseTuple(args, "ss", &mode, &rawmode)) return NULL; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingSunRleDecode; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* TGA RLE */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_TgaRleDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; int ystep = 1; int depth = 8; if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &ystep, &depth)) return NULL; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingTgaRleDecode; decoder->state.ystep = ystep; decoder->state.count = depth / 8; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* XBM */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_XbmDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, "1", "1;R") < 0) return NULL; decoder->decode = ImagingXbmDecode; return (PyObject*) decoder; } /* -------------------------------------------------------------------- */ /* ZIP */ /* -------------------------------------------------------------------- */ #ifdef HAVE_LIBZ #include "Zip.h" PyObject* PyImaging_ZipDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; if (!PyArg_ParseTuple(args, "ss", &mode, &rawmode)) return NULL; decoder = PyImaging_DecoderNew(sizeof(ZIPSTATE)); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingZipDecode; return (PyObject*) decoder; } #endif /* -------------------------------------------------------------------- */ /* JPEG */ /* -------------------------------------------------------------------- */ #ifdef HAVE_LIBJPEG /* We better define this decoder last in this file, so the following undef's won't mess things up for the Imaging library proper. */ #undef HAVE_PROTOTYPES #undef HAVE_STDDEF_H #undef HAVE_STDLIB_H #undef UINT8 #undef UINT16 #undef UINT32 #undef INT8 #undef INT16 #undef INT32 #include "Jpeg.h" PyObject* PyImaging_JpegDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; /* what we wan't from the decoder */ char* jpegmode; /* what's in the file */ int scale = 1; int draft = 0; if (!PyArg_ParseTuple(args, "ssz|ii", &mode, &rawmode, &jpegmode, &scale, &draft)) return NULL; if (!jpegmode) jpegmode = ""; decoder = PyImaging_DecoderNew(sizeof(JPEGSTATE)); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingJpegDecode; strncpy(((JPEGSTATE*)decoder->state.context)->rawmode, rawmode, 8); strncpy(((JPEGSTATE*)decoder->state.context)->jpegmode, jpegmode, 8); ((JPEGSTATE*)decoder->state.context)->scale = scale; ((JPEGSTATE*)decoder->state.context)->draft = draft; return (PyObject*) decoder; } #endif Imaging-1.1.3/encode.c0100444000076400007640000003021107442710204014332 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/encode.c#3 $ * * standard encoder interfaces for the Imaging library * * History: * 2025-04-19 fl Based on decoders.c * 2025-05-12 fl Compile cleanly as C++ * 2024-12-30 fl Plugged potential memory leak for tiled images * 2025-01-03 fl Added GIF encoder * 2025-01-05 fl Plugged encoder buffer leaks * 2025-01-11 fl Added encode_to_file method * 2025-03-09 fl Added mode/rawmode argument to encoders * 2025-07-09 fl Added interlace argument to GIF encoder * 2025-02-07 fl Added PCX encoder * * Copyright (c) 1997-2001 by Secret Labs AB * Copyright (c) 1996-1997 by Fredrik Lundh * * See the README file for information on usage and redistribution. */ /* FIXME: make these pluggable! */ #include "Python.h" #include "Imaging.h" #include "Gif.h" #ifdef HAVE_UNISTD_H #include /* write */ #endif /* -------------------------------------------------------------------- */ /* Common */ /* -------------------------------------------------------------------- */ typedef struct { PyObject_HEAD int (*encode)(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); struct ImagingCodecStateInstance state; Imaging im; PyObject* lock; } ImagingEncoderObject; staticforward PyTypeObject ImagingEncoderType; static ImagingEncoderObject* PyImaging_EncoderNew(int contextsize) { ImagingEncoderObject *encoder; void *context; ImagingEncoderType.ob_type = &PyType_Type; encoder = PyObject_NEW(ImagingEncoderObject, &ImagingEncoderType); if (encoder == NULL) return NULL; /* Clear the encoder state */ memset(&encoder->state, 0, sizeof(encoder->state)); /* Allocate encoder context */ if (contextsize > 0) { context = (void*) calloc(1, contextsize); if (!context) { Py_DECREF(encoder); PyErr_NoMemory(); return NULL; } } else context = 0; /* Initialize encoder context */ encoder->state.context = context; /* Target image */ encoder->lock = NULL; encoder->im = NULL; return encoder; } static void _dealloc(ImagingEncoderObject* encoder) { free(encoder->state.buffer); free(encoder->state.context); Py_XDECREF(encoder->lock); PyMem_DEL(encoder); } static PyObject* _encode(ImagingEncoderObject* encoder, PyObject* args) { PyObject* buf; PyObject* result; int status; /* Encode to a Python string (allocated by this method) */ int bufsize = 16384; if (!PyArg_ParseTuple(args, "|i", &bufsize)) return NULL; buf = PyString_FromStringAndSize(NULL, bufsize); if (!buf) return NULL; status = encoder->encode(encoder->im, &encoder->state, (UINT8*) PyString_AsString(buf), bufsize); /* adjust string length to avoid slicing in encoder */ _PyString_Resize(&buf, (status > 0) ? status : 0); result = Py_BuildValue("iiO", status, encoder->state.errcode, buf); Py_DECREF(buf); /* must release buffer!!! */ return result; } static PyObject* _encode_to_file(ImagingEncoderObject* encoder, PyObject* args) { UINT8* buf; int status; /* Encode to a file handle */ int fh; int bufsize = 16384; if (!PyArg_ParseTuple(args, "i|i", &fh, &bufsize)) return NULL; /* Allocate an encoder buffer */ buf = (UINT8*) malloc(bufsize); if (!buf) { PyErr_NoMemory(); return NULL; } do { /* This replaces the inner loop in the ImageFile _save function. */ status = encoder->encode(encoder->im, &encoder->state, buf, bufsize); if (status > 0) if (write(fh, buf, status) < 0) { free(buf); return PyErr_SetFromErrno(PyExc_IOError); } } while (encoder->state.errcode == 0); free(buf); return Py_BuildValue("i", encoder->state.errcode); } extern Imaging PyImaging_AsImaging(PyObject *op); static PyObject* _setimage(ImagingEncoderObject* encoder, PyObject* args) { PyObject* op; Imaging im; ImagingCodecState state; int x0, y0, x1, y1; /* Define where image data should be stored */ x0 = y0 = x1 = y1 = 0; /* FIXME: should publish the ImagingType descriptor */ if (!PyArg_ParseTuple(args, "O|(iiii)", &op, &x0, &y0, &x1, &y1)) return NULL; im = PyImaging_AsImaging(op); if (!im) return NULL; encoder->im = im; state = &encoder->state; if (x0 == 0 && x1 == 0) { state->xsize = im->xsize; state->ysize = im->ysize; } else { state->xoff = x0; state->yoff = y0; state->xsize = x1 - x0; state->ysize = y1 - y0; } if (state->xsize <= 0 || state->xsize + state->xoff > im->xsize || state->ysize <= 0 || state->ysize + state->yoff > im->ysize) { PyErr_SetString(PyExc_SystemError, "tile cannot extend outside image"); return NULL; } /* Allocate memory buffer (if bits field is set) */ if (state->bits > 0) { state->bytes = (state->bits * state->xsize+7)/8; state->buffer = (UINT8*) malloc(state->bytes); if (!state->buffer) { PyErr_NoMemory(); return NULL; } } /* Keep a reference to the image object, to make sure it doesn't go away before we do */ Py_INCREF(op); Py_XDECREF(encoder->lock); encoder->lock = op; Py_INCREF(Py_None); return Py_None; } static struct PyMethodDef methods[] = { {"encode", (PyCFunction)_encode, 1}, {"encode_to_file", (PyCFunction)_encode_to_file, 1}, {"setimage", (PyCFunction)_setimage, 1}, {NULL, NULL} /* sentinel */ }; static PyObject* _getattr(ImagingEncoderObject* self, char* name) { return Py_FindMethod(methods, (PyObject*) self, name); } statichere PyTypeObject ImagingEncoderType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "ImagingEncoder", /*tp_name*/ sizeof(ImagingEncoderObject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_hash*/ }; /* -------------------------------------------------------------------- */ int get_packer(ImagingEncoderObject* encoder, const char* mode, const char* rawmode) { int bits; ImagingShuffler pack; pack = ImagingFindPacker(mode, rawmode, &bits); if (!pack) { Py_DECREF(encoder); PyErr_SetString(PyExc_SystemError, "unknown raw mode"); return -1; } encoder->state.shuffle = pack; encoder->state.bits = bits; return 0; } /* -------------------------------------------------------------------- */ /* EPS */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_EpsEncoderNew(PyObject* self, PyObject* args) { ImagingEncoderObject* encoder; encoder = PyImaging_EncoderNew(0); if (encoder == NULL) return NULL; encoder->encode = ImagingEpsEncode; return (PyObject*) encoder; } /* -------------------------------------------------------------------- */ /* GIF */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_GifEncoderNew(PyObject* self, PyObject* args) { ImagingEncoderObject* encoder; char *mode; char *rawmode; int bits = 8; int interlace = 0; if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &bits, &interlace)) return NULL; encoder = PyImaging_EncoderNew(sizeof(GIFENCODERSTATE)); if (encoder == NULL) return NULL; if (get_packer(encoder, mode, rawmode) < 0) return NULL; encoder->encode = ImagingGifEncode; ((GIFENCODERSTATE*)encoder->state.context)->bits = bits; ((GIFENCODERSTATE*)encoder->state.context)->interlace = interlace; return (PyObject*) encoder; } /* -------------------------------------------------------------------- */ /* PCX */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_PcxEncoderNew(PyObject* self, PyObject* args) { ImagingEncoderObject* encoder; char *mode; char *rawmode; int bits = 8; if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &bits)) return NULL; encoder = PyImaging_EncoderNew(0); if (encoder == NULL) return NULL; if (get_packer(encoder, mode, rawmode) < 0) return NULL; encoder->encode = ImagingPcxEncode; return (PyObject*) encoder; } /* -------------------------------------------------------------------- */ /* RAW */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_RawEncoderNew(PyObject* self, PyObject* args) { ImagingEncoderObject* encoder; char *mode; char *rawmode; int stride = 0; int ystep = 1; if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &stride, &ystep)) return NULL; encoder = PyImaging_EncoderNew(0); if (encoder == NULL) return NULL; if (get_packer(encoder, mode, rawmode) < 0) return NULL; encoder->encode = ImagingRawEncode; encoder->state.ystep = ystep; encoder->state.count = stride; return (PyObject*) encoder; } /* -------------------------------------------------------------------- */ /* XBM */ /* -------------------------------------------------------------------- */ PyObject* PyImaging_XbmEncoderNew(PyObject* self, PyObject* args) { ImagingEncoderObject* encoder; encoder = PyImaging_EncoderNew(0); if (encoder == NULL) return NULL; if (get_packer(encoder, "1", "1;R") < 0) return NULL; encoder->encode = ImagingXbmEncode; return (PyObject*) encoder; } /* -------------------------------------------------------------------- */ /* ZIP */ /* -------------------------------------------------------------------- */ #ifdef HAVE_LIBZ #include "Zip.h" PyObject* PyImaging_ZipEncoderNew(PyObject* self, PyObject* args) { ImagingEncoderObject* encoder; char* mode; char* rawmode; int optimize = 0; char* dictionary = NULL; int dictionary_size = 0; if (!PyArg_ParseTuple(args, "ss|is#", &mode, &rawmode, &optimize, &dictionary, &dictionary_size)) return NULL; encoder = PyImaging_EncoderNew(sizeof(ZIPSTATE)); if (encoder == NULL) return NULL; if (get_packer(encoder, mode, rawmode) < 0) return NULL; encoder->encode = ImagingZipEncode; if (rawmode[0] == 'P') /* disable filtering */ ((ZIPSTATE*)encoder->state.context)->mode = ZIP_PNG_PALETTE; ((ZIPSTATE*)encoder->state.context)->optimize = optimize; ((ZIPSTATE*)encoder->state.context)->dictionary = dictionary; ((ZIPSTATE*)encoder->state.context)->dictionary_size = dictionary_size; return (PyObject*) encoder; } #endif /* -------------------------------------------------------------------- */ /* JPEG */ /* -------------------------------------------------------------------- */ #ifdef HAVE_LIBJPEG /* We better define this encoder last in this file, so the following undef's won't mess things up for the Imaging library proper. */ #undef HAVE_PROTOTYPES #undef HAVE_STDDEF_H #undef HAVE_STDLIB_H #undef UINT8 #undef UINT16 #undef UINT32 #undef INT8 #undef INT16 #undef INT32 #include "Jpeg.h" PyObject* PyImaging_JpegEncoderNew(PyObject* self, PyObject* args) { ImagingEncoderObject* encoder; char *mode; char *rawmode; int quality = 0; int progressive = 0; int smooth = 0; int optimize = 0; int streamtype = 0; /* 0=interchange, 1=tables only, 2=image only */ int xdpi = 0, ydpi = 0; if (!PyArg_ParseTuple(args, "ss|iiiiiii", &mode, &rawmode, &quality, &progressive, &smooth, &optimize, &streamtype, &xdpi, &ydpi)) return NULL; encoder = PyImaging_EncoderNew(sizeof(JPEGENCODERSTATE)); if (encoder == NULL) return NULL; if (get_packer(encoder, mode, rawmode) < 0) return NULL; encoder->encode = ImagingJpegEncode; ((JPEGENCODERSTATE*)encoder->state.context)->quality = quality; ((JPEGENCODERSTATE*)encoder->state.context)->progressive = progressive; ((JPEGENCODERSTATE*)encoder->state.context)->smooth = smooth; ((JPEGENCODERSTATE*)encoder->state.context)->optimize = optimize; ((JPEGENCODERSTATE*)encoder->state.context)->streamtype = streamtype; ((JPEGENCODERSTATE*)encoder->state.context)->xdpi = xdpi; ((JPEGENCODERSTATE*)encoder->state.context)->ydpi = ydpi; return (PyObject*) encoder; } #endif Imaging-1.1.3/display.c0100444000076400007640000001356407442710204014556 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/display.c#3 $ * * display support * * History: * 2025-05-13 fl Windows DIB support * 2025-05-21 fl Added palette stuff * 2025-05-28 fl Added display_mode stuff * 2025-09-21 fl Added draw primitive * 2025-09-17 fl Added ImagingGrabScreen (from _grabscreen.c) * * Copyright (c) Secret Labs AB 1997. * Copyright (c) Fredrik Lundh 1996-97. * * See the README file for information on usage and redistribution. */ #include "Python.h" #include "Imaging.h" /* -------------------------------------------------------------------- */ /* Windows DIB support */ /* -------------------------------------------------------------------- */ #ifdef WIN32 #include "ImDib.h" typedef struct { PyObject_HEAD ImagingDIB dib; } ImagingDisplayObject; staticforward PyTypeObject ImagingDisplayType; static ImagingDisplayObject* _new(const char* mode, int xsize, int ysize) { ImagingDisplayObject *display; display = PyObject_NEW(ImagingDisplayObject, &ImagingDisplayType); if (display == NULL) return NULL; display->dib = ImagingNewDIB(mode, xsize, ysize); if (!display->dib) { Py_DECREF(display); return NULL; } return display; } static void _delete(ImagingDisplayObject* display) { if (display->dib) ImagingDeleteDIB(display->dib); PyMem_DEL(display); } static PyObject* _expose(ImagingDisplayObject* display, PyObject* args) { int hdc; if (!PyArg_ParseTuple(args, "i", &hdc)) return NULL; ImagingExposeDIB(display->dib, hdc); Py_INCREF(Py_None); return Py_None; } static PyObject* _draw(ImagingDisplayObject* display, PyObject* args) { int hdc; int dst[4]; int src[4]; if (!PyArg_ParseTuple(args, "i(iiii)(iiii)", &hdc, dst+0, dst+1, dst+2, dst+3, src+0, src+1, src+2, src+3)) return NULL; ImagingDrawDIB(display->dib, hdc, dst, src); Py_INCREF(Py_None); return Py_None; } extern Imaging PyImaging_AsImaging(PyObject *op); static PyObject* _paste(ImagingDisplayObject* display, PyObject* args) { Imaging im; PyObject* op; int xy[4]; xy[0] = xy[1] = xy[2] = xy[3] = 0; if (!PyArg_ParseTuple(args, "O|(iiii)", &op, xy+0, xy+1, xy+2, xy+3)) return NULL; im = PyImaging_AsImaging(op); if (!im) return NULL; if (xy[2] <= xy[0]) xy[2] = xy[0] + im->xsize; if (xy[3] <= xy[1]) xy[3] = xy[1] + im->ysize; ImagingPasteDIB(display->dib, im, xy); Py_INCREF(Py_None); return Py_None; } static PyObject* _query_palette(ImagingDisplayObject* display, PyObject* args) { int hdc; int status; if (!PyArg_ParseTuple(args, "i", &hdc)) return NULL; status = ImagingQueryPaletteDIB(display->dib, hdc); return Py_BuildValue("i", status); } static struct PyMethodDef methods[] = { {"draw", (PyCFunction)_draw, 1}, {"expose", (PyCFunction)_expose, 1}, {"paste", (PyCFunction)_paste, 1}, {"query_palette", (PyCFunction)_query_palette, 1}, {NULL, NULL} /* sentinel */ }; static PyObject* _getattr(ImagingDisplayObject* self, char* name) { PyObject* res; res = Py_FindMethod(methods, (PyObject*) self, name); if (res) return res; PyErr_Clear(); if (!strcmp(name, "mode")) return Py_BuildValue("s", self->dib->mode); if (!strcmp(name, "size")) return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize); PyErr_SetString(PyExc_AttributeError, name); return NULL; } statichere PyTypeObject ImagingDisplayType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "ImagingDisplay", /*tp_name*/ sizeof(ImagingDisplayObject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)_delete, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_hash*/ }; PyObject* PyImaging_DisplayWin32(PyObject* self, PyObject* args) { ImagingDisplayObject* display; char *mode; int xsize, ysize; if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize)) return NULL; display = _new(mode, xsize, ysize); if (display == NULL) return NULL; return (PyObject*) display; } PyObject* PyImaging_DisplayModeWin32(PyObject* self, PyObject* args) { char *mode; int size[2]; mode = ImagingGetModeDIB(size); return Py_BuildValue("s(ii)", mode, size[0], size[1]); } PyObject* PyImaging_GrabScreenWin32(PyObject* self, PyObject* args) { int width, height; HBITMAP bitmap; BITMAPCOREHEADER core; HDC screen, screen_copy; PyObject* buffer; /* step 1: create a memory DC large enough to hold the entire screen */ screen = CreateDC("DISPLAY", NULL, NULL, NULL); screen_copy = CreateCompatibleDC(screen); width = GetDeviceCaps(screen, HORZRES); height = GetDeviceCaps(screen, VERTRES); bitmap = CreateCompatibleBitmap(screen, width, height); if (!bitmap) goto error; if (!SelectObject(screen_copy, bitmap)) goto error; /* step 2: copy bits into memory DC bitmap */ if (!BitBlt(screen_copy, 0, 0, width, height, screen, 0, 0, SRCCOPY)) goto error; /* step 3: extract bits from bitmap */ buffer = PyString_FromStringAndSize(NULL, height * ((width*3 + 3) & -4)); if (!buffer) return NULL; core.bcSize = sizeof(core); core.bcWidth = width; core.bcHeight = height; core.bcPlanes = 1; core.bcBitCount = 24; if (!GetDIBits(screen_copy, bitmap, 0, height, PyString_AS_STRING(buffer), (BITMAPINFO*) &core, DIB_RGB_COLORS)) goto error; DeleteObject(bitmap); DeleteDC(screen_copy); DeleteDC(screen); return Py_BuildValue("(ii)N", width, height, buffer); error: PyErr_SetString(PyExc_IOError, "screen grab failed"); DeleteDC(screen_copy); DeleteDC(screen); return NULL; } #endif /* WIN32 */ Imaging-1.1.3/map.c0100444000076400007640000001422707442710204013663 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/map.c#2 $ * * standard memory mapping interface for the Imaging library * * history: * 98-03-05 fl Added Win32 read mapping * 99-02-06 fl Added "I;16" support * * Copyright (c) Secret Labs AB 1998. * * See the README file for information on usage and redistribution. */ /* * FIXME: should move the memory mapping primitives into libImaging! */ #include "Python.h" #include "Imaging.h" #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include "windows.h" #endif typedef struct { PyObject_HEAD char* base; int size; int offset; #ifdef WIN32 HANDLE hFile; HANDLE hMap; #endif } ImagingMapperObject; staticforward PyTypeObject ImagingMapperType; ImagingMapperObject* PyImaging_MapperNew(const char* filename, int readonly) { ImagingMapperObject *mapper; ImagingMapperType.ob_type = &PyType_Type; mapper = PyObject_NEW(ImagingMapperObject, &ImagingMapperType); if (mapper == NULL) return NULL; mapper->base = NULL; mapper->size = mapper->offset = 0; #ifdef WIN32 mapper->hFile = (HANDLE)-1; mapper->hMap = (HANDLE)-1; /* FIXME: currently supports readonly mappings only */ mapper->hFile = CreateFile( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (mapper->hFile == (HANDLE)-1) { PyErr_SetString(PyExc_IOError, "cannot open file"); PyMem_DEL(mapper); return NULL; } mapper->hMap = CreateFileMapping( mapper->hFile, NULL, PAGE_READONLY, 0, 0, NULL); if (mapper->hMap == (HANDLE)-1) { CloseHandle(mapper->hFile); PyErr_SetString(PyExc_IOError, "cannot map file"); PyMem_DEL(mapper); return NULL; } mapper->base = (char*) MapViewOfFile( mapper->hMap, FILE_MAP_READ, 0, 0, 0); mapper->size = GetFileSize(mapper->hFile, 0); #endif return mapper; } static void mapping_dealloc(ImagingMapperObject* mapper) { #ifdef WIN32 if (mapper->base != 0) UnmapViewOfFile(mapper->base); if (mapper->hMap != (HANDLE)-1) CloseHandle(mapper->hMap); if (mapper->hFile != (HANDLE)-1) CloseHandle(mapper->hFile); mapper->base = 0; mapper->hMap = mapper->hFile = (HANDLE)-1; #endif PyMem_DEL(mapper); } /* -------------------------------------------------------------------- */ /* standard file operations */ static PyObject* mapping_read(ImagingMapperObject* mapper, PyObject* args) { PyObject* buf; int size = -1; if (!PyArg_ParseTuple(args, "|i", &size)) return NULL; /* check size */ if (size < 0 || mapper->offset + size > mapper->size) size = mapper->size - mapper->offset; if (size < 0) size = 0; buf = PyString_FromStringAndSize(NULL, size); if (!buf) return NULL; if (size > 0) { memcpy(PyString_AsString(buf), mapper->base + mapper->offset, size); mapper->offset += size; } return buf; } static PyObject* mapping_seek(ImagingMapperObject* mapper, PyObject* args) { int offset; int whence = 0; if (!PyArg_ParseTuple(args, "i|i", &offset, &whence)) return NULL; switch (whence) { case 0: /* SEEK_SET */ mapper->offset = offset; break; case 1: /* SEEK_CUR */ mapper->offset += offset; break; case 2: /* SEEK_END */ mapper->offset = mapper->size + offset; break; default: /* FIXME: raise ValueError? */ break; } Py_INCREF(Py_None); return Py_None; } /* -------------------------------------------------------------------- */ /* map entire image */ extern PyObject*PyImagingNew(Imaging im); static void ImagingDestroyMap(Imaging im) { return; /* nothing to do! */ } static PyObject* mapping_readimage(ImagingMapperObject* mapper, PyObject* args) { int y, size; Imaging im; char* mode; int xsize; int ysize; int stride; int orientation; if (!PyArg_ParseTuple(args, "s(ii)ii", &mode, &xsize, &ysize, &stride, &orientation)) return NULL; if (stride <= 0) { /* FIXME: maybe we should call ImagingNewPrologue instead */ if (!strcmp(mode, "L") || !strcmp(mode, "P")) stride = xsize; else if (!strcmp(mode, "I;16") || !strcmp(mode, "I;16B")) stride = xsize * 2; else stride = xsize * 4; } size = ysize * stride; if (mapper->offset + size > mapper->size) { PyErr_SetString(PyExc_IOError, "image file truncated"); return NULL; } im = ImagingNewPrologue(mode, xsize, ysize); if (!im) return NULL; /* setup file pointers */ if (orientation > 0) for (y = 0; y < ysize; y++) im->image[y] = mapper->base + mapper->offset + y * stride; else for (y = 0; y < ysize; y++) im->image[ysize-y-1] = mapper->base + mapper->offset + y * stride; im->destroy = ImagingDestroyMap; if (!ImagingNewEpilogue(im)) return NULL; mapper->offset += size; return PyImagingNew(im); } static struct PyMethodDef methods[] = { /* standard file interface */ {"read", (PyCFunction)mapping_read, 1}, {"seek", (PyCFunction)mapping_seek, 1}, /* extensions */ {"readimage", (PyCFunction)mapping_readimage, 1}, {NULL, NULL} /* sentinel */ }; static PyObject* mapping_getattr(ImagingMapperObject* self, char* name) { return Py_FindMethod(methods, (PyObject*) self, name); } statichere PyTypeObject ImagingMapperType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "ImagingMapper", /*tp_name*/ sizeof(ImagingMapperObject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)mapping_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)mapping_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_hash*/ }; PyObject* PyImaging_Mapper(PyObject* self, PyObject* args) { char* filename; if (!PyArg_ParseTuple(args, "s", &filename)) return NULL; return (PyObject*) PyImaging_MapperNew(filename, 1); } Imaging-1.1.3/outline.c0100444000076400007640000000720307442710204014561 0ustar fredrikfredrik/* * THIS IS WORK IN PROGRESS. * * The Python Imaging Library. * $Id: //modules/pil/outline.c#2 $ * * "arrow" outline stuff. the contents of this module * will be merged with the path module and the rest of * the arrow graphics package, but not before PIL 1.1. * use at your own risk. * * history: * 99-01-10 fl Added to PIL (experimental) * * Copyright (c) Secret Labs AB 1999. * Copyright (c) Fredrik Lundh 1999. * * See the README file for information on usage and redistribution. */ #include "Python.h" #include "Imaging.h" /* -------------------------------------------------------------------- */ /* Class */ typedef struct { PyObject_HEAD ImagingOutline outline; } OutlineObject; staticforward PyTypeObject OutlineType; #define PyOutline_Check(op) ((op)->ob_type == &OutlineType) static OutlineObject* _outline_new(void) { OutlineObject *self; self = PyObject_NEW(OutlineObject, &OutlineType); if (self == NULL) return NULL; self->outline = ImagingOutlineNew(); return self; } static void _outline_dealloc(OutlineObject* self) { ImagingOutlineDelete(self->outline); PyMem_DEL(self); } ImagingOutline PyOutline_AsOutline(PyObject* outline) { if (PyOutline_Check(outline)) return ((OutlineObject*) outline)->outline; return NULL; } /* -------------------------------------------------------------------- */ /* Factories */ PyObject* PyOutline_Create(PyObject* self, PyObject* args) { /* FIXME: NoArgs */ return (PyObject*) _outline_new(); } /* -------------------------------------------------------------------- */ /* Methods */ static PyObject* _outline_move(OutlineObject* self, PyObject* args) { float x0, y0; if (!PyArg_ParseTuple(args, "ff", &x0, &y0)) return NULL; ImagingOutlineMove(self->outline, x0, y0); Py_INCREF(Py_None); return Py_None; } static PyObject* _outline_line(OutlineObject* self, PyObject* args) { float x1, y1; if (!PyArg_ParseTuple(args, "ff", &x1, &y1)) return NULL; ImagingOutlineLine(self->outline, x1, y1); Py_INCREF(Py_None); return Py_None; } static PyObject* _outline_curve(OutlineObject* self, PyObject* args) { float x1, y1, x2, y2, x3, y3; if (!PyArg_ParseTuple(args, "ffffff", &x1, &y1, &x2, &y2, &x3, &y3)) return NULL; ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3); Py_INCREF(Py_None); return Py_None; } static PyObject* _outline_close(OutlineObject* self, PyObject* args) { /* FIXME: NoArgs */ ImagingOutlineClose(self->outline); Py_INCREF(Py_None); return Py_None; } static PyObject* _outline_transform(OutlineObject* self, PyObject* args) { double a[6]; if (!PyArg_ParseTuple(args, "(dddddd)", a+0, a+1, a+2, a+3, a+4, a+5)) return NULL; ImagingOutlineTransform(self->outline, a); Py_INCREF(Py_None); return Py_None; } static struct PyMethodDef _outline_methods[] = { {"line", (PyCFunction)_outline_line, 1}, {"curve", (PyCFunction)_outline_curve, 1}, {"move", (PyCFunction)_outline_move, 1}, {"close", (PyCFunction)_outline_close, 1}, {"transform", (PyCFunction)_outline_transform, 1}, {NULL, NULL} /* sentinel */ }; static PyObject* _outline_getattr(OutlineObject* self, char* name) { return Py_FindMethod(_outline_methods, (PyObject*) self, name); } statichere PyTypeObject OutlineType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "Outline", /*tp_name*/ sizeof(OutlineObject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)_outline_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)_outline_getattr, /*tp_getattr*/ 0 /*tp_setattr*/ }; Imaging-1.1.3/path.c0100444000076400007640000002716107442710204014043 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/path.c#2 $ * * 2D path utilities * * history: * 2025-11-04 fl Added to PIL (incomplete) * 2025-11-05 fl Added sequence semantics * 2025-02-28 fl Fixed getbbox * 2025-06-12 fl Added id attribute * 2025-06-14 fl Added slicing and setitem * 2024-12-29 fl Improved sequence handling (from Richard Jones) * 2025-01-10 fl Fixed IndexError test for 1.5 (from Fred Drake) * 2025-10-12 fl Added special cases for tuples and lists * * notes: * FIXME: fill in remaining slots in the sequence api * * Copyright (c) 1997-2000 by Secret Labs AB * Copyright (c) 1997-2000 by Fredrik Lundh * * See the README file for information on usage and redistribution. */ #include #include "Python.h" /* -------------------------------------------------------------------- */ /* Class */ /* -------------------------------------------------------------------- */ typedef struct { PyObject_HEAD int count; double *xy; int index; /* temporary use, e.g. in decimate */ } PyPathObject; staticforward PyTypeObject PyPathType; static PyPathObject* _new(int count, double* xy, int duplicate) { PyPathObject *path; if (duplicate) { /* duplicate path */ double* p; p = malloc(count * 2 * sizeof(double)); if (!p) { PyErr_NoMemory(); return NULL; } memcpy(p, xy, count * 2 * sizeof(double)); xy = p; } path = PyObject_NEW(PyPathObject, &PyPathType); if (path == NULL) return NULL; path->count = count; path->xy = xy; return path; } static void _dealloc(PyPathObject* path) { free(path->xy); PyMem_DEL(path); } /* -------------------------------------------------------------------- */ /* Helpers */ /* -------------------------------------------------------------------- */ #define PyPath_Check(op) ((op)->ob_type == &PyPathType) int PyPath_Flatten(PyObject* data, double **pxy) { int i, j, n; double *xy; if (PyPath_Check(data)) { /* This was a path object. */ PyPathObject *path = (PyPathObject*) data; n = 2 * path->count * sizeof(double); xy = malloc(n); if (!xy) { PyErr_NoMemory(); return -1; } memcpy(xy, path->xy, n); *pxy = xy; return path->count; } if (!PySequence_Check(data)) { PyErr_SetString(PyExc_TypeError, "argument must be sequence"); return -1; } j = 0; n = PyObject_Length(data); /* Just in case __len__ breaks (or doesn't exist) */ if (PyErr_Occurred()) return -1; /* Allocate for worst case */ xy = malloc(2 * n * sizeof(double)); if (!xy) { PyErr_NoMemory(); return -1; } /* Copy table to path array */ if (PyList_Check(data)) { for (i = 0; i < n; i++) { double x, y; PyObject *op = PyList_GET_ITEM(data, i); if (PyFloat_Check(op)) xy[j++] = PyFloat_AS_DOUBLE(op); else if (PyInt_Check(op)) xy[j++] = (float) PyInt_AS_LONG(op); else if (PyNumber_Check(op)) xy[j++] = PyFloat_AsDouble(op); else if (PyArg_ParseTuple(op, "dd", &x, &y)) { xy[j++] = x; xy[j++] = y; } else { free(xy); return -1; } } } else if (PyTuple_Check(data)) { for (i = 0; i < n; i++) { double x, y; PyObject *op = PyTuple_GET_ITEM(data, i); if (PyFloat_Check(op)) xy[j++] = PyFloat_AS_DOUBLE(op); else if (PyInt_Check(op)) xy[j++] = (float) PyInt_AS_LONG(op); else if (PyNumber_Check(op)) xy[j++] = PyFloat_AsDouble(op); else if (PyArg_ParseTuple(op, "dd", &x, &y)) { xy[j++] = x; xy[j++] = y; } else { free(xy); return -1; } } } else { for (i = 0; i < n; i++) { double x, y; PyObject *op = PySequence_GetItem(data, i); if (!op) { /* treat IndexError as end of sequence */ if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_IndexError)) { PyErr_Clear(); break; } else { free(xy); return -1; } } if (PyFloat_Check(op)) xy[j++] = PyFloat_AS_DOUBLE(op); else if (PyInt_Check(op)) xy[j++] = (float) PyInt_AS_LONG(op); else if (PyNumber_Check(op)) xy[j++] = PyFloat_AsDouble(op); else if (PyArg_ParseTuple(op, "dd", &x, &y)) { xy[j++] = x; xy[j++] = y; } else { Py_DECREF(op); free(xy); return -1; } Py_DECREF(op); } } if (j & 1) { PyErr_SetString(PyExc_ValueError, "wrong number of coordinates"); free(xy); return -1; } *pxy = xy; return j/2; } /* -------------------------------------------------------------------- */ /* Factories */ /* -------------------------------------------------------------------- */ PyObject* PyPath_Create(PyObject* self, PyObject* args) { PyObject* data; int count; double *xy; if (PyArg_ParseTuple(args, "i", &count)) { /* number of vertices */ xy = malloc(2 * count * sizeof(double)); if (!xy) { PyErr_NoMemory(); return NULL; } } else { /* sequence or other path */ PyErr_Clear(); if (!PyArg_ParseTuple(args, "O", &data)) return NULL; count = PyPath_Flatten(data, &xy); if (count < 0) return NULL; } return (PyObject*) _new(count, xy, 0); } /* -------------------------------------------------------------------- */ /* Methods */ /* -------------------------------------------------------------------- */ static PyObject* _compact(PyPathObject* self, PyObject* args) { /* Simple-minded method to shorten path. A point is removed if the city block distance to the previous point is less than the given distance */ int i, j; double *xy; double cityblock = 2.0; if (!PyArg_ParseTuple(args, "|d", &cityblock)) return NULL; xy = self->xy; /* remove bogus vertices */ for (i = j = 1; i < self->count; i++) { if (fabs(xy[j+j-2]-xy[i+i]) + fabs(xy[j+j-1]-xy[i+i+1]) >= cityblock) { xy[j+j] = xy[i+i]; xy[j+j+1] = xy[i+i+1]; j++; } } i = self->count - j; self->count = j; /* shrink coordinate array */ realloc(self->xy, 2 * self->count * sizeof(double)); return Py_BuildValue("i", i); /* number of removed vertices */ } static PyObject* _getbbox(PyPathObject* self, PyObject* args) { /* Find bounding box */ int i; double *xy; double x0, y0, x1, y1; xy = self->xy; x0 = x1 = xy[0]; y0 = y1 = xy[1]; for (i = 1; i < self->count; i++) { if (xy[i+i] < x0) x0 = xy[i+i]; if (xy[i+i] > x1) x1 = xy[i+i]; if (xy[i+i+1] < y0) y0 = xy[i+i+1]; if (xy[i+i+1] > y1) y1 = xy[i+i+1]; } return Py_BuildValue("dddd", x0, y0, x1, y1); } static PyObject* _getitem(PyPathObject* self, int i) { if (i < 0 || i >= self->count) { PyErr_SetString(PyExc_IndexError, "path index out of range"); return NULL; } return Py_BuildValue("dd", self->xy[i+i], self->xy[i+i+1]); } static PyObject* _getslice(PyPathObject* self, int ilow, int ihigh) { /* adjust arguments */ if (ilow < 0) ilow = 0; else if (ilow >= self->count) ilow = self->count; if (ihigh < 0) ihigh = 0; if (ihigh < ilow) ihigh = ilow; else if (ihigh > self->count) ihigh = self->count; return (PyObject*) _new(ihigh - ilow, self->xy + ilow * 2, 1); } static int _len(PyPathObject* self) { return self->count; } static PyObject* _map(PyPathObject* self, PyObject* args) { /* Map coordinate set through function */ int i; double *xy; PyObject* function; if (!PyArg_ParseTuple(args, "O", &function)) return NULL; xy = self->xy; /* apply function to coordinate set */ for (i = 0; i < self->count; i++) { double x = xy[i+i]; double y = xy[i+i+1]; PyObject* item = PyObject_CallFunction(function, "dd", x, y); if (!item || !PyArg_ParseTuple(item, "dd", &x, &y)) { Py_XDECREF(item); return NULL; } xy[i+i] = x; xy[i+i+1] = y; Py_DECREF(item); } Py_INCREF(Py_None); return Py_None; } static int _setitem(PyPathObject* self, int i, PyObject* op) { double* xy; if (i < 0 || i >= self->count) { PyErr_SetString(PyExc_IndexError, "path assignment index out of range"); return -1; } if (op == NULL) { PyErr_SetString(PyExc_TypeError, "cannot delete from path"); return -1; } xy = &self->xy[i+i]; if (!PyArg_ParseTuple(op, "dd", &xy[0], &xy[1])) return -1; return 0; } static PyObject* _tolist(PyPathObject* self, PyObject* args) { PyObject *list; int i; list = PyList_New(self->count); for (i = 0; i < self->count; i++) { PyObject* item; item = Py_BuildValue("dd", self->xy[i+i], self->xy[i+i+1]); if (!item) { Py_DECREF(list); list = NULL; break; } PyList_SetItem(list, i, item); } return list; } static PyObject* _transform(PyPathObject* self, PyObject* args) { /* Apply affine transform to coordinate set */ int i; double *xy; double a, b, c, d, e, f; double wrap = 0.0; if (!PyArg_ParseTuple(args, "(dddddd)|d", &a, &b, &c, &d, &e, &f, &wrap)) return NULL; xy = self->xy; /* transform the coordinate set */ if (b == 0.0 && d == 0.0) /* scaling */ for (i = 0; i < self->count; i++) { xy[i+i] = a*xy[i+i]+c; xy[i+i+1] = e*xy[i+i+1]+f; } else /* affine transform */ for (i = 0; i < self->count; i++) { double x = xy[i+i]; double y = xy[i+i+1]; xy[i+i] = a*x+b*y+c; xy[i+i+1] = d*x+e*y+f; } /* special treatment of geographical map data */ if (wrap != 0.0) for (i = 0; i < self->count; i++) xy[i+i] = fmod(xy[i+i], wrap); Py_INCREF(Py_None); return Py_None; } static struct PyMethodDef methods[] = { {"compact", (PyCFunction)_compact, 1}, {"getbbox", (PyCFunction)_getbbox, 1}, {"map", (PyCFunction)_map, 1}, {"tolist", (PyCFunction)_tolist, 1}, {"transform", (PyCFunction)_transform, 1}, {NULL, NULL} /* sentinel */ }; static PyObject* _getattr(PyPathObject* self, char* name) { PyObject* res; res = Py_FindMethod(methods, (PyObject*) self, name); if (res) return res; PyErr_Clear(); if (strcmp(name, "id") == 0) return Py_BuildValue("l", (long) self->xy); PyErr_SetString(PyExc_AttributeError, name); return NULL; } static PySequenceMethods path_as_sequence = { (inquiry)_len, /*sq_length*/ (binaryfunc)0, /*sq_concat*/ (intargfunc)0, /*sq_repeat*/ (intargfunc)_getitem, /*sq_item*/ (intintargfunc)_getslice, /*sq_slice*/ (intobjargproc)_setitem, /*sq_ass_item*/ (intintobjargproc)0, /*sq_ass_slice*/ }; statichere PyTypeObject PyPathType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "Path", /*tp_name*/ sizeof(PyPathObject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number */ &path_as_sequence, /*tp_as_sequence */ 0, /*tp_as_mapping */ 0, /*tp_hash*/ }; Imaging-1.1.3/_imagingtk.c0100444000076400007640000000272707442710204015221 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: //modules/pil/_imagingtk.c#3 $ * * tkinter hooks * * history: * 99-07-26 fl created * 99-08-15 fl moved to its own support module * * Copyright (c) Secret Labs AB 1999. * * See the README file for information on usage and redistribution. */ #include "Python.h" #include "Imaging.h" #include "tk.h" /* must link with Tk/tkImaging.c */ extern void TkImaging_Init(Tcl_Interp* interp); /* copied from _tkinter.c (this isn't as bad as it may seem: for new versions, we use _tkinter's interpaddr hook instead, and all older versions use this structure layout) */ typedef struct { PyObject_HEAD Tcl_Interp* interp; } TkappObject; static PyObject* _tkinit(PyObject* self, PyObject* args) { Tcl_Interp* interp; long arg; int is_interp; if (!PyArg_ParseTuple(args, "li", &arg, &is_interp)) return NULL; if (is_interp) interp = (Tcl_Interp*) arg; else { TkappObject* app; /* Do it the hard way. This will break if the TkappObject layout changes */ app = (TkappObject*) arg; interp = app->interp; } /* This will bomb if interp is invalid... */ TkImaging_Init(interp); Py_INCREF(Py_None); return Py_None; } static PyMethodDef functions[] = { /* Tkinter interface stuff */ {"tkinit", (PyCFunction)_tkinit, 1}, {NULL, NULL} /* sentinel */ }; DL_EXPORT(void) init_imagingtk(void) { Py_InitModule("_imagingtk", functions); } Imaging-1.1.3/PIL.pth0100444000076400007640000000000407442710203014066 0ustar fredrikfredrikPIL Imaging-1.1.3/PIL/__init__.py0100444000076400007640000000033107442710203015465 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/__init__.py#2 $ # # package placeholder # # Copyright (c) 1999 by Secret Labs AB. # # See the README file for information on usage and redistribution. # # ;-) Imaging-1.1.3/PIL/ArgImagePlugin.py0100444000076400007640000003407007442710203016570 0ustar fredrikfredrik# # THIS IS WORK IN PROGRESS # # The Python Imaging Library. # $Id: //modules/pil/PIL/ArgImagePlugin.py#2 $ # # ARG animation support code # # history: # 96-12-30 fl Created # 96-01-06 fl Added safe scripting environment # 96-01-10 fl Added JHDR, UHDR and sYNC support # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996-97. # # See the README file for information on usage and redistribution. # __version__ = "0.3" import marshal, rexec, string import Image, ImageFile, ImagePalette from PngImagePlugin import i16, i32, ChunkStream, _MODES MAGIC = "\212ARG\r\n\032\n" APPLET_HOOK = None # must be explicitly enabled to support embedded scripts # -------------------------------------------------------------------- # ARG parser class ArgStream(ChunkStream): "Parser callbacks for ARG data" def __init__(self, fp): ChunkStream.__init__(self, fp) self.eof = 0 self.im = None self.palette = None self.__reset() def __reset(self): # reset decoder state (called on init and sync) self.count = 0 self.id = None self.action = ("NONE",) self.images = {} self.names = {} self.applets = {} # level 2 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[(ord(s[8]), ord(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_AFRM(self, offset, bytes): "AFRM -- next frame follows" # assertions if self.count != 0: raise SyntaxError, "misplaced AFRM chunk" self.show = 1 self.id = 0 self.count = 1 self.repair = None s = self.fp.read(bytes) if len(s) >= 2: self.id = i16(s) if len(s) >= 4: self.count = i16(s[2:4]) if len(s) >= 6: self.repair = i16(s[4:6]) else: self.repair = None if Image.DEBUG: print "AFRM", self.id, self.count return s def chunk_ADEF(self, offset, bytes): "ADEF -- store image" # assertions if self.count != 0: raise SyntaxError, "misplaced ADEF chunk" self.show = 0 self.id = 0 self.count = 1 self.repair = None s = self.fp.read(bytes) if len(s) >= 2: self.id = i16(s) if len(s) >= 4: self.count = i16(s[2:4]) if Image.DEBUG: print "ADEF", self.id, self.count return s def chunk_NAME(self, offset, bytes): "NAME -- name the current image" # assertions if self.count == 0: raise SyntaxError, "misplaced NAME chunk" name = self.fp.read(bytes) self.names[self.id] = name return name def chunk_AEND(self, offset, bytes): "AEND -- end of animation" if Image.DEBUG: print "AEND" self.eof = 1 raise EOFError, "end of ARG file" def __getmodesize(self, s, full=1): size = i32(s), i32(s[4:]) try: mode, rawmode = _MODES[(ord(s[8]), ord(s[9]))] except: raise SyntaxError, "unknown image mode" if full: if ord(s[12]): pass # interlace not yet supported if ord(s[11]): raise SyntaxError, "unknown filter category" return size, mode, rawmode 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 def chunk_BLNK(self, offset, bytes): "BLNK -- create blank image" # assertions if self.count == 0: raise SyntaxError, "misplaced BLNK chunk" s = self.fp.read(bytes) size, mode, rawmode = self.__getmodesize(s, 0) # store image (FIXME: handle colour) self.action = ("BLNK",) self.im = Image.core.fill(mode, size, 0) self.__store() return s def chunk_IHDR(self, offset, bytes): "IHDR -- full image follows" # assertions if self.count == 0: raise SyntaxError, "misplaced IHDR chunk" # image header s = self.fp.read(bytes) size, mode, rawmode = self.__getmodesize(s) # decode and store image self.action = ("IHDR",) self.im = Image.core.new(mode, size) self.decoder = Image.core.zip_decoder(rawmode) self.decoder.setimage(self.im, (0,0) + size) self.data = "" return s 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 = ord(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 = "" return s def chunk_JHDR(self, offset, bytes): "JHDR -- JPEG image follows" # assertions if self.count == 0: raise SyntaxError, "misplaced JHDR chunk" # image header s = self.fp.read(bytes) size, mode, rawmode = self.__getmodesize(s, 0) # decode and store image self.action = ("JHDR",) self.im = Image.core.new(mode, size) self.decoder = Image.core.jpeg_decoder(rawmode) self.decoder.setimage(self.im, (0,0) + size) self.data = "" return s def chunk_UHDR(self, offset, bytes): "UHDR -- uncompressed image data follows (EXPERIMENTAL)" # assertions if self.count == 0: raise SyntaxError, "misplaced UHDR chunk" # image header s = self.fp.read(bytes) size, mode, rawmode = self.__getmodesize(s, 0) # decode and store image self.action = ("UHDR",) self.im = Image.core.new(mode, size) self.decoder = Image.core.raw_decoder(rawmode) self.decoder.setimage(self.im, (0,0) + size) self.data = "" return s def chunk_IDAT(self, offset, bytes): "IDAT -- image data block" # pass compressed chunks through the decoder s = self.fp.read(bytes) self.data = self.data + s n, e = self.decoder.decode(self.data) if n < 0: # end of image if e < 0: raise IOError, "decoder error %d" % e else: self.data = self.data[n:] return s def chunk_DEND(self, offset, bytes): return self.chunk_IEND(offset, bytes) def chunk_JEND(self, offset, bytes): return self.chunk_IEND(offset, bytes) def chunk_UEND(self, offset, bytes): return self.chunk_IEND(offset, bytes) def chunk_IEND(self, offset, bytes): "IEND -- end of image" # we now have a new image. carry out the operation # defined by the image header. # won't need these anymore del self.decoder del self.data self.__store() return self.fp.read(bytes) def __store(self): # apply operation cid = self.action[0] if cid in ["BLNK", "IHDR", "JHDR", "UHDR"]: # store self.images[self.id] = self.im elif cid == "DHDR": # paste cid, mode, bbox = self.action im0 = self.images[self.id] im1 = self.im if mode == 0: im1 = im1.chop_add_modulo(im0.crop(bbox)) im0.paste(im1, bbox) self.count = self.count - 1 if self.count == 0 and self.show: self.im = self.images[self.id] raise EOFError # end of this frame def chunk_PLTE(self, offset, bytes): "PLTE -- palette data" s = self.fp.read(bytes) if self.mode == "P": self.palette = ImagePalette.raw("RGB", s) return s def chunk_sYNC(self, offset, bytes): "SYNC -- reset decoder" if self.count != 0: raise SyntaxError, "misplaced sYNC chunk" s = self.fp.read(bytes) self.__reset() return s # # LEVEL 2 STUFF def chunk_aAPP(self, offset, bytes): "aAPP -- store application" s = self.fp.read(bytes) # extract type, name and code chunk j = string.find(s, "\0") name = s[:j] i = j + 1 j = string.find(s, "\0", i) type = s[i:j] code = s[j+1:] if Image.DEBUG: print "AAPP", repr(type), repr(name) if not code: # delete existing applet if self.applets.has_key(name): del self.applets[name] else: # store or execute applet if type != "python": raise IOError, "unsupported script type " + type # convert to executable object code = marshal.loads(code) if not name: # unnamed; execute immediately self.__applet(code) else: try: # named applet; store in dictionary self.applets[name] = marshal.loads(code) except: pass # applet loading error return s def chunk_aRUN(self, offset, bytes): "aRUN -- execute application" s = self.fp.read(bytes) j = string.find(s, "\0") name = s[:j] # FIXME: should handle arguments print "ARUN", name self.__applet(self.applets[name]) return s def __applet(self, code): if not APPLET_HOOK: return # run script in safe environment safe = rexec.RExec() safe.r_exec(code) # must convert images to Image object form images = {} for id, im in self.images.items(): # FIXME: this is crude: support for this operation # should be moved to the Image module itself (or # better; change this module to use Image objects # instead of core objects) i = Image.new(im.mode, im.size) i.im = im images[id] = i if self.names.has_key(id): # add named image images[self.names[id]] = i APPLET_HOOK(safe.modules["__main__"].Animation, images) # -------------------------------------------------------------------- # ARG reader def _accept(prefix): return prefix[:8] == MAGIC class ArgImageFile(ImageFile.ImageFile): format = "ARG" format_description = "Animated raster graphics" def _open(self): if self.fp.read(8) != MAGIC: raise SyntaxError, "not an ARG file" self.arg = ArgStream(self.fp) # read and process the first chunk (AHDR) cid, offset, bytes = self.arg.read() if cid != "AHDR": raise SyntaxError, "expected an AHDR chunk" s = self.arg.call(cid, offset, bytes) self.arg.crc(cid, s) # image characteristics self.mode = self.arg.mode self.size = self.arg.size def load(self): if self.arg.im is None: self.seek(0) # image data self.im = self.arg.im self.palette = self.arg.palette # set things up for further processing Image.Image.load(self) def seek(self, frame): if self.arg.eof: raise EOFError, "end of animation" self.fp = self.arg.fp while 1: # # process chunks cid, offset, bytes = self.arg.read() if self.arg.eof: raise EOFError, "end of animation" try: s = self.arg.call(cid, offset, bytes) except EOFError: break except "glurk": # AttributeError 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") Imaging-1.1.3/PIL/BdfFontFile.py0100444000076400007640000000573007442710203016060 0ustar fredrikfredrik# # THIS IS WORK IN PROGRESS # # The Python Imaging Library # $Id: //modules/pil/PIL/BdfFontFile.py#3 $ # # bitmap distribution font file parser # # history: # 2025-05-16 fl created (as bdf2pil) # 2025-08-25 fl converted to FontFile driver # 2025-05-25 fl removed bogus __init__ call # # Copyright (c) Secret Labs AB 1997-2001. # Copyright (c) Fredrik Lundh 1997-2001. # # See the README file for information on usage and redistribution. # import Image import FontFile import string # -------------------------------------------------------------------- # parse X Bitmap Distribution Format (BDF) # -------------------------------------------------------------------- bdf_slant = { "R": "Roman", "I": "Italic", "O": "Oblique", "RI": "Reverse Italic", "RO": "Reverse Oblique", "OT": "Other" } bdf_spacing = { "P": "Proportional", "M": "Monospaced", "C": "Cell" } def bdf_char(f): # skip to STARTCHAR while 1: s = f.readline() if not s: return None if s[:9] == "STARTCHAR": break id = string.strip(s[9:]) # load symbol properties props = {} while 1: s = f.readline() if not s or s[:6] == "BITMAP": break i = string.find(s, " ") props[s[:i]] = s[i+1:-1] # load bitmap bitmap = [] while 1: s = f.readline() if not s or s[:7] == "ENDCHAR": break bitmap.append(s[:-1]) bitmap = string.join(bitmap, "") [x, y, l, d] = map(string.atoi, string.split(props["BBX"])) [dx, dy] = map(string.atoi, string.split(props["DWIDTH"])) bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y) im = Image.fromstring("1", (x, y), bitmap, "hex", "1") return id, string.atoi(props["ENCODING"]), bbox, im class BdfFontFile(FontFile.FontFile): def __init__(self, fp): FontFile.FontFile.__init__(self) s = fp.readline() if s[:13] != "STARTFONT 2.1": raise SyntaxError, "not a valid BDF file" props = {} comments = [] while 1: s = fp.readline() if not s or s[:13] == "ENDPROPERTIES": break i = string.find(s, " ") props[s[:i]] = s[i+1:-1] if s[:i] in ["COMMENT", "COPYRIGHT"]: if string.find(s, "LogicalFontDescription") < 0: comments.append(s[i+1:-1]) font = string.split(props["FONT"], "-") font[4] = bdf_slant[font[4]] font[11] = bdf_spacing[font[11]] ascent = string.atoi(props["FONT_ASCENT"]) descent = string.atoi(props["FONT_DESCENT"]) fontname = string.join(font[1:], ";") # print "#", fontname # for i in comments: # print "#", i font = [] while 1: c = bdf_char(fp) if not c: break id, ch, (xy, dst, src), im = c if ch >= 0: self.glyph[ch] = xy, dst, src, im Imaging-1.1.3/PIL/BmpImagePlugin.py0100444000076400007640000001240107442710203016567 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/BmpImagePlugin.py#3 $ # # BMP file handler # # Windows (and OS/2) native bitmap storage format. # # History: # 95-09-01 fl Created # 96-04-30 fl Added save # 97-08-27 fl Fixed save of 1-bit images # 98-03-06 fl Load P images as L where possible # 98-07-03 fl Load P images as 1 where possible # 98-12-29 fl Handle small palettes # # Copyright (c) Secret Labs AB 1997-98. # Copyright (c) Fredrik Lundh 1995-97. # # See the README file for information on usage and redistribution. # __version__ = "0.5" import string import Image, ImageFile, ImagePalette # # -------------------------------------------------------------------- # Read BMP file def i16(c): return ord(c[0]) + (ord(c[1])<<8) def i32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) BIT2MODE = { # mode, rawmode 1: ("P", "1"), 4: ("P", "P;4"), 8: ("P", "P"), 24: ("RGB", "BGR") } def _accept(prefix): return prefix[:2] == "BM" class BmpImageFile(ImageFile.ImageFile): format = "BMP" format_description = "Windows Bitmap" def _bitmap(self, header = 0, offset = 0): if header: self.fp.seek(header) # CORE/INFO s = self.fp.read(4) s = s + self.fp.read(i32(s)-4) if len(s) == 12: # OS/2 1.0 CORE bits = i16(s[10:]) self.size = i16(s[4:]), i16(s[6:]) lutsize = 3 colors = 0 elif len(s) in [40, 64]: # WIN 3.1 or OS/2 2.0 INFO bits = i16(s[14:]) self.size = i32(s[4:]), i32(s[8:]) self.info["compression"] = i32(s[16:]) lutsize = 4 colors = i32(s[32:]) else: raise IOError, "Unknown BMP header type" if not colors: colors = 1 << bits # MODE try: self.mode, rawmode = BIT2MODE[bits] except KeyError: raise IOError, "Unsupported BMP pixel depth" # LUT if self.mode == "P": palette = [] greyscale = 1 if colors == 2: indices = (0, 255) else: indices = range(colors) for i in indices: rgb = self.fp.read(lutsize)[:3] if rgb != chr(i)*3: greyscale = 0 palette.append(rgb) if greyscale: if colors == 2: self.mode = "1" else: self.mode = rawmode = "L" else: self.mode = "P" self.palette = ImagePalette.raw( "BGR", string.join(palette, "") ) if not offset: offset = self.fp.tell() self.tile = [("raw", (0, 0) + self.size, offset, (rawmode, ((self.size[0]*bits+31)>>3)&(~3), -1))] def _open(self): # HEAD s = self.fp.read(14) if s[:2] != "BM": raise SyntaxError, "Not a BMP file" offset = i32(s[10:]) self._bitmap() # # -------------------------------------------------------------------- # Write BMP file def o16(i): return chr(i&255) + chr(i>>8&255) def o32(i): return chr(i&255) + chr(i>>8&255) + chr(i>>16&255) + chr(i>>24&255) SAVE = { "1": ("1", 1, 2), "L": ("L", 8, 256), "P": ("P", 8, 256), "RGB": ("BGR", 24, 0), } def _save(im, fp, filename, check=0): try: rawmode, bits, colors = SAVE[im.mode] except KeyError: raise IOError, "cannot write mode %s as BMP" % im.mode if check: return check stride = ((im.size[0]*bits+7)/8+3)&(~3) header = 40 # or 64 for OS/2 version 2 offset = 14 + header + colors * 4 image = stride * im.size[1] # bitmap header fp.write("BM" + # file type (magic) o32(offset+image) + # file size o32(0) + # reserved o32(offset)) # image data offset # bitmap info header fp.write(o32(header) + # info header size o32(im.size[0]) + # width o32(im.size[1]) + # height o16(1) + # planes o16(bits) + # depth o32(0) + # compression (0=uncompressed) o32(image) + # size of bitmap o32(1) + o32(1) + # resolution o32(colors) + # colors used o32(colors)) # colors important fp.write("\000" * (header - 40)) # padding (for OS/2 format) if im.mode == "1": for i in (0, 255): fp.write(chr(i) * 4) elif im.mode == "L": for i in range(256): fp.write(chr(i) * 4) elif im.mode == "P": fp.write(im.im.getpalette("RGB", "BGRX")) ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, stride, -1))]) # # -------------------------------------------------------------------- # Registry Image.register_open(BmpImageFile.format, BmpImageFile, _accept) Image.register_save(BmpImageFile.format, _save) Image.register_extension(BmpImageFile.format, ".bmp") Imaging-1.1.3/PIL/ContainerIO.py0100444000076400007640000000345007442710203016105 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ContainerIO.py#2 $ # # a class to read from a container file # # History: # 2025-06-18 fl Created # 2025-09-07 fl Added readline(), readlines() # # Copyright (c) 1997-2001 by Secret Labs AB # Copyright (c) 1995 by Fredrik Lundh # # See the README file for information on usage and redistribution. # # -------------------------------------------------------------------- # Return a restricted file object allowing a user to read and # seek/tell an individual file within a container file (for example # a TAR file). class ContainerIO: def __init__(self, fh, offset, length): self.fh = fh self.pos = 0 self.offset = offset self.length = length self.fh.seek(offset) def isatty(self): return 0 def seek(self, offset, mode = 0): if mode == 1: self.pos = self.pos + offset elif mode == 2: self.pos = self.length + offset else: self.pos = offset # clamp self.pos = max(0, min(self.pos, self.length)) self.fh.seek(self.offset + self.pos) def tell(self): return self.pos def read(self, n = 0): if n: n = min(n, self.length - self.pos) else: n = self.length - self.pos if not n: # EOF return "" self.pos = self.pos + n return self.fh.read(n) def readline(self): s = "" while 1: c = self.read(1) if not c: break s = s + c if c == "\n": break return s def readlines(self): l = [] while 1: s = self.readline() if not s: break l.append(s) return l Imaging-1.1.3/PIL/CurImagePlugin.py0100444000076400007640000000374507442710203016615 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/CurImagePlugin.py#3 $ # # Windows Cursor support for PIL # # notes: # uses BmpImagePlugin.py to read the bitmap data. # # history: # 96-05-27 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import string import Image, BmpImagePlugin # # -------------------------------------------------------------------- def i16(c): return ord(c[0]) + (ord(c[1])<<8) def i32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) def _accept(prefix): return prefix[:4] == "\0\0\2\0" class CurImageFile(BmpImagePlugin.BmpImageFile): format = "CUR" format_description = "Windows Cursor" def _open(self): offset = self.fp.tell() # check magic s = self.fp.read(6) if not _accept(s): raise SyntaxError, "not an CUR file" # pick the largest cursor in the file m = "" for i in range(i16(s[4:])): s = self.fp.read(16) if not m: m = s elif ord(s[0]) > ord(m[0]) and ord(s[1]) > ord(m[1]): m = s #print "width", ord(s[0]) #print "height", ord(s[1]) #print "colors", ord(s[2]) #print "reserved", ord(s[3]) #print "hotspot x", i16(s[4:]) #print "hotspot y", i16(s[6:]) #print "bytes", i32(s[8:]) #print "offset", i32(s[12:]) # load as bitmap self._bitmap(i32(m[12:]) + offset) # patch up the bitmap height self.size = self.size[0], self.size[1]/2 d, e, o, a = self.tile[0] self.tile[0] = d, (0,0)+self.size, o, a return # # -------------------------------------------------------------------- Image.register_open("CUR", CurImageFile, _accept) Image.register_extension("CUR", ".cur") Imaging-1.1.3/PIL/DcxImagePlugin.py0100444000076400007640000000335607442710203016600 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/DcxImagePlugin.py#3 $ # # DCX file handling # # DCX is a container file format defined by Intel, commonly used # for fax applications. Each DCX file consists of a directory # (a list of file offsets) followed by a set of (usually 1-bit) # PCX files. # # History: # 95-09-09 fl Created # 96-03-20 fl Properly derived from PcxImageFile. # 98-07-15 fl Renamed offset attribute to avoid name clash # # Copyright (c) Secret Labs AB 1997-98. # Copyright (c) Fredrik Lundh 1995-96. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import Image, ImageFile from PcxImagePlugin import PcxImageFile MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then? def i32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) def _accept(prefix): return i32(prefix) == MAGIC class DcxImageFile(PcxImageFile): format = "DCX" format_description = "Intel DCX" def _open(self): # Header s = self.fp.read(4) if i32(s) != MAGIC: raise SyntaxError, "not a DCX file" # Component directory self._offset = [] for i in range(1024): offset = i32(self.fp.read(4)) if not offset: break self._offset.append(offset) self.seek(0) def seek(self, frame): if frame >= len(self._offset): raise IndexError, "attempt to seek outside DCX directory" self.frame = frame self.fp.seek(self._offset[frame]) PcxImageFile._open(self) def tell(self): return self.frame Image.register_open("DCX", DcxImageFile, _accept) Image.register_extension("DCX", ".dcx") Imaging-1.1.3/PIL/EpsImagePlugin.py0100444000076400007640000002245507442710203016612 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/EpsImagePlugin.py#2 $ # # EPS file handling # # History: # 2025-09-01 fl Created (0.1) # 2025-05-18 fl Don't choke on "atend" fields, Ghostscript interface (0.2) # 2025-08-22 fl Don't choke on floating point BoundingBox values # 2025-08-23 fl Handle files from Macintosh (0.3) # 2025-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.4) # # Copyright (c) Secret Labs AB 1997-2001. # Copyright (c) Fredrik Lundh 1995-96-2001 # # See the README file for information on usage and redistribution. # __version__ = "0.4" import re, string import Image, ImageFile # # -------------------------------------------------------------------- def i32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) def o32(i): return chr(i&255) + chr(i>>8&255) + chr(i>>16&255) + chr(i>>24&255) split = re.compile(r"^%%([^:]*):[ \t]*(.*)[ \t]*$") field = re.compile(r"^%[%!\w]([^:]*)[ \t]*$") def Ghostscript(tile, size, fp): """Render an image using Ghostscript (Unix only)""" # Unpack decoder tile decoder, tile, offset, data = tile[0] length, bbox = data import tempfile, os file = tempfile.mktemp() # Build ghostscript command command = ["gs", "-q", # quite mode "-g%dx%d" % size, # set output geometry (pixels) "-dNOPAUSE -dSAFER", # don't pause between pages, safe mode "-sDEVICE=ppmraw", # ppm driver "-sOutputFile=%s" % file,# output file "- >/dev/tty 2>/dev/tty"] command = string.join(command) # push data through ghostscript try: gs = os.popen(command, "w") # adjust for image origin if bbox[0] != 0 or bbox[1] != 0: gs.write("%d %d translate\n" % (-bbox[0], -bbox[1])) fp.seek(offset) while length > 0: s = fp.read(8192) if not s: break length = length - len(s) gs.write(s) gs.close() im = Image.core.open_ppm(file) finally: try: os.unlink(file) except: pass return im class PSFile: """Wrapper that treats either CR or LF as end of line.""" def __init__(self, fp): self.fp = fp self.char = None def __getattr__(self, id): v = getattr(self.fp, id) setattr(self, id, v) return v def seek(self, offset, whence=0): self.char = None self.fp.seek(offset, whence) def tell(self): pos = self.fp.tell() if self.char: pos = pos - 1 return pos def readline(self): s = "" if self.char: c = self.char self.char = None else: c = self.fp.read(1) while c not in "\r\n": s = s + c c = self.fp.read(1) if c == "\r": self.char = self.fp.read(1) if self.char == "\n": self.char = None return s + "\n" def _accept(prefix): return prefix[:4] == "%!PS" or i32(prefix) == 0xC6D3D0C5 class EpsImageFile(ImageFile.ImageFile): """EPS File Parser for the Python Imaging Library""" format = "EPS" format_description = "Encapsulated Postscript" def _open(self): # FIXME: should check the first 512 bytes to see if this # really is necessary (platform-dependent, though...) fp = PSFile(self.fp) # HEAD s = fp.read(512) if s[:4] == "%!PS": offset = 0 fp.seek(0, 2) length = fp.tell() elif i32(s) == 0xC6D3D0C5: offset = i32(s[4:]) length = i32(s[8:]) fp.seek(offset) else: raise SyntaxError, "not an EPS file" fp.seek(offset) box = None self.mode = "RGB" self.size = 1, 1 # FIXME: huh? # # Load EPS header s = fp.readline() while s: if len(s) > 255: raise SyntaxError, "not an EPS file" if s[-2:] == '\r\n': s = s[:-2] elif s[-1:] == '\n': s = s[:-1] try: m = split.match(s) except re.error, v: raise SyntaxError, "not an EPS file" if m: k, v = m.group(1, 2) self.info[k] = v if k == "BoundingBox": try: # Note: The DSC spec says that BoundingBox # fields should be integers, but some drivers # put floating point values there anyway. box = map(int, map(string.atof, string.split(v))) self.size = box[2] - box[0], box[3] - box[1] self.tile = [("eps", (0,0) + self.size, offset, (length, box))] except: pass else: m = field.match(s) if m: k = m.group(1) if k == "EndComments": break if k[:8] == "PS-Adobe": self.info[k[:8]] = k[9:] else: self.info[k] = "" else: raise IOError, "bad EPS header" s = fp.readline() if s[:1] != "%": break # # Scan for an "ImageData" descriptor while s[0] == "%": if len(s) > 255: raise SyntaxError, "not an EPS file" if s[-2:] == '\r\n': s = s[:-2] elif s[-1:] == '\n': s = s[:-1] if s[:11] == "%ImageData:": [x, y, bi, mo, z3, z4, en, id] =\ string.split(s[11:], maxsplit=7) x = int(x); y = int(y) bi = int(bi) mo = int(mo) en = int(en) if en == 1: decoder = "eps_binary" elif en == 2: decoder = "eps_hex" else: break if bi != 8: break if mo == 1: self.mode = "L" elif mo == 2: self.mode = "LAB" elif mo == 3: self.mode = "RGB" else: break if id[:1] == id[-1:] == '"': id = id[1:-1] # Scan forward to the actual image data while 1: s = fp.readline() if not s: break if s[:len(id)] == id: self.size = x, y self.tile2 = [(decoder, (0, 0, x, y), fp.tell(), 0)] return s = fp.readline() if not s: break if not box: raise IOError, "cannot determine EPS bounding box" def load(self): # Load EPS via Ghostscript if not self.tile: return self.im = Ghostscript(self.tile, self.size, self.fp) self.mode = self.im.mode self.size = self.im.size self.tile = [] # # -------------------------------------------------------------------- def _save(im, fp, filename, eps=1): """EPS Writer for the Python Imaging Library.""" # # make sure image data is available im.load() # # determine postscript image mode if im.mode == "L": operator = (8, 1, "image") elif im.mode == "RGB": operator = (8, 3, "false 3 colorimage") elif im.mode == "CMYK": operator = (8, 4, "false 4 colorimage") else: raise ValueError, "image mode is not supported" if eps: # # write EPS header fp.write("%!PS-Adobe-3.0 EPSF-3.0\n") fp.write("%%Creator: PIL 0.1 EpsEncode\n") #fp.write("%%CreationDate: %s"...) fp.write("%%%%BoundingBox: 0 0 %d %d\n" % im.size) fp.write("%%Pages: 1\n") fp.write("%%EndComments\n") fp.write("%%Page: 1 1\n") fp.write("%%ImageData: %d %d " % im.size) fp.write("%d %d 0 1 1 \"%s\"\n" % operator) # # image header fp.write("gsave\n") fp.write("10 dict begin\n") fp.write("/buf %d string def\n" % (im.size[0] * operator[1])) fp.write("%d %d scale\n" % im.size) fp.write("%d %d 8\n" % im.size) # <= bits fp.write("[%d 0 0 -%d 0 %d]\n" % (im.size[0], im.size[1], im.size[1])) fp.write("{ currentfile buf readhexstring pop } bind\n") fp.write("%s\n" % operator[2]) ImageFile._save(im, fp, [("eps", (0,0)+im.size, 0, None)]) fp.write("\n%%%%EndBinary\n") fp.write("grestore end\n") fp.flush() # # -------------------------------------------------------------------- Image.register_open(EpsImageFile.format, EpsImageFile, _accept) Image.register_save(EpsImageFile.format, _save) Image.register_extension(EpsImageFile.format, ".ps") Image.register_extension(EpsImageFile.format, ".eps") Image.register_mime(EpsImageFile.format, "application/postscript") Imaging-1.1.3/PIL/FliImagePlugin.py0100444000076400007640000000644407442710203016575 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/FliImagePlugin.py#3 $ # # FLI/FLC file handling. # # History: # 95-09-01 fl Created # 97-01-03 fl Fixed parser, setup decoder tile # 98-07-15 fl Renamed offset attribute to avoid name clash # # Copyright (c) Secret Labs AB 1997-98. # Copyright (c) Fredrik Lundh 1995-97. # # See the README file for information on usage and redistribution. # __version__ = "0.2" import Image, ImageFile, ImagePalette import string def i16(c): return ord(c[0]) + (ord(c[1])<<8) def i32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) # # decoder def _accept(prefix): return i16(prefix[4:6]) in [0xAF11, 0xAF12] class FliImageFile(ImageFile.ImageFile): format = "FLI" format_description = "Autodesk FLI/FLC Animation" def _open(self): # HEAD s = self.fp.read(128) magic = i16(s[4:6]) if magic not in [0xAF11, 0xAF12]: raise SyntaxError, "not an FLI/FLC file" # image characteristics self.mode = "P" self.size = i16(s[8:10]), i16(s[10:12]) # animation speed duration = i32(s[16:20]) if magic == 0xAF11: duration = (duration * 1000) / 70 self.info["duration"] = duration # look for palette palette = map(lambda a: (a,a,a), range(256)) s = self.fp.read(16) self.__offset = 128 if i16(s[4:6]) == 0xF100: # prefix chunk; ignore it self.__offset = self.__offset + i32(s) s = self.fp.read(16) if i16(s[4:6]) == 0xF1FA: # look for palette chunk s = self.fp.read(6) if i16(s[4:6]) == 11: self._palette(palette, 2) elif i16(s[4:6]) == 4: self._palette(palette, 0) palette = map(lambda (r,g,b): chr(r)+chr(g)+chr(b), palette) self.palette = ImagePalette.raw("RGB", string.join(palette, "")) # set things up to decode first frame self.frame = -1 self.__fp = self.fp self.seek(0) def _palette(self, palette, shift): # load palette i = 0 for e in range(i16(self.fp.read(2))): s = self.fp.read(2) i = i + ord(s[0]) n = ord(s[1]) if n == 0: n = 256 s = self.fp.read(n * 3) for n in range(0, len(s), 3): r = ord(s[n]) << shift g = ord(s[n+1]) << shift b = ord(s[n+2]) << shift palette[i] = (r, g, b) i = i + 1 def seek(self, frame): if frame != self.frame + 1: raise ValueError, "cannot seek to frame %d" % frame self.frame = frame # move to next frame self.fp = self.__fp self.fp.seek(self.__offset) s = self.fp.read(4) if not s: raise EOFError framesize = i32(s) self.decodermaxblock = framesize self.tile = [("fli", (0,0)+self.size, self.__offset, None)] self.__offset = self.__offset + framesize def tell(self): return self.frame # # registry Image.register_open("FLI", FliImageFile, _accept) Image.register_extension("FLI", ".fli") Image.register_extension("FLI", ".flc") Imaging-1.1.3/PIL/FontFile.py0100444000076400007640000000640007442710203015437 0ustar fredrikfredrik# # THIS IS WORK IN PROGRESS # # The Python Imaging Library # $Id: //modules/pil/PIL/FontFile.py#3 $ # # base class for raster font file parsers # # history: # 97-06-05 fl created # 97-08-19 fl restrict image width # # Copyright (c) Secret Labs AB 1997-98. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # import os import Image import marshal try: import zlib except ImportError: zlib = None WIDTH = 800 def puti16(fp, values): # write network order (big-endian) 16-bit sequence for v in values: if v < 0: v = v + 65536 fp.write(chr(v>>8&255) + chr(v&255)) class FontFile: bitmap = None def __init__(self): self.info = {} self.glyph = [None] * 256 def __getitem__(self, ix): return self.glyph[ix] def compile(self): "Create metrics and bitmap" if self.bitmap: return # create bitmap large enough to hold all data h = w = maxwidth = 0 lines = 1 for glyph in self: if glyph: d, dst, src, im = glyph h = max(h, src[3] - src[1]) w = w + (src[2] - src[0]) if w > WIDTH: lines = lines + 1 w = (src[2] - src[0]) maxwidth = max(maxwidth, w) xsize = maxwidth ysize = lines * h if xsize == 0 and ysize == 0: return "" self.ysize = h # paste glyphs into bitmap self.bitmap = Image.new("1", (xsize, ysize)) self.metrics = [None] * 256 x = y = 0 for i in range(256): glyph = self[i] if glyph: d, dst, src, im = glyph xx, yy = src[2] - src[0], src[3] - src[1] x0, y0 = x, y x = x + xx if x > WIDTH: x, y = 0, y + h x0, y0 = x, y x = xx s = src[0] + x0, src[1] + y0, src[2] + x0, src[3] + y0 self.bitmap.paste(im.crop(src), s) # print chr(i), dst, s self.metrics[i] = d, dst, s def save1(self, filename): "Save font in version 1 format" self.compile() # font data self.bitmap.save(os.path.splitext(filename)[0] + ".pbm", "PNG") # font metrics fp = open(os.path.splitext(filename)[0] + ".pil", "wb") fp.write("PILfont\n") fp.write(";;;;;;%d;\n" % self.ysize) # HACK!!! fp.write("DATA\n") for id in range(256): m = self.metrics[id] if not m: puti16(fp, [0] * 10) else: puti16(fp, m[0] + m[1] + m[2]) fp.close() def save2(self, filename): "Save font in version 2 format" self.compile() data = marshal.dumps((self.metrics, self.info)) if zlib: data = "z" + zlib.compress(data, 9) else: data = "u" + data fp = open(os.path.splitext(filename)[0] + ".pil", "wb") fp.write("PILfont2\n" + self.name + "\n" + "DATA\n") fp.write(data) self.bitmap.save(fp, "PNG") fp.close() save = save1 # for now Imaging-1.1.3/PIL/FpxImagePlugin.py0100444000076400007640000001407507442710203016617 0ustar fredrikfredrik# # THIS IS WORK IN PROGRESS # # The Python Imaging Library. # $Id: //modules/pil/PIL/FpxImagePlugin.py#3 $ # # FlashPix support for PIL # # History: # 97-01-25 fl Created (reads uncompressed RGB images only) # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import string import Image, ImageFile from OleFileIO import * # we map from colour field tuples to (mode, rawmode) descriptors MODES = { # opacity (0x00007ffe): ("A", "L"), # monochrome (0x00010000,): ("L", "L"), (0x00018000, 0x00017ffe): ("RGBA", "LA"), # photo YCC (0x00020000, 0x00020001, 0x00020002): ("RGB", "YCC;P"), (0x00028000, 0x00028001, 0x00028002, 0x00027ffe): ("RGBA", "YCCA;P"), # standard RGB (NIFRGB) (0x00030000, 0x00030001, 0x00030002): ("RGB","RGB"), (0x00038000, 0x00038001, 0x00038002, 0x00037ffe): ("RGBA","RGBA"), } # # -------------------------------------------------------------------- def _accept(prefix): return prefix[:8] == MAGIC class FpxImageFile(ImageFile.ImageFile): format = "FPX" format_description = "FlashPix" def _open(self): # # read the OLE directory and see if this is a likely # to be a FlashPix file try: self.ole = OleFileIO(self.fp) except IOError: raise SyntaxError, "not an FPX file; invalid OLE file" if self.ole.root.clsid != "56616700-C154-11CE-8553-00AA00A1F95B": raise SyntaxError, "not an FPX file; bad root CLSID" self._open_index(1) def _open_index(self, index = 1): # # get the Image Contents Property Set prop = self.ole.getproperties([ "Data Object Store %06d" % index, "\005Image Contents" ]) # size (highest resolution) self.size = prop[0x1000002], prop[0x1000003] size = max(self.size) i = 1 while size > 64: size = size / 2 i = i + 1 self.maxid = i - 1 # mode. instead of using a single field for this, flashpix # requires you to specify the mode for each channel in each # resolution subimage, and leaves it to the decoder to make # sure that they all match. for now, we'll cheat and assume # that this is always the case. id = self.maxid << 16 s = prop[0x2000002|id] colors = [] for i in range(i32(s, 4)): # note: for now, we ignore the "uncalibrated" flag colors.append(i32(s, 8+i*4) & 0x7fffffff) self.mode, self.rawmode = MODES[tuple(colors)] # load JPEG tables, if any self.jpeg = {} for i in range(256): id = 0x3000001|(i << 16) if prop.has_key(id): self.jpeg[i] = prop[id] # print len(self.jpeg), "tables loaded" self._open_subimage(1, self.maxid) def _open_subimage(self, index = 1, subimage = 0): # # setup tile descriptors for a given subimage stream = [ "Data Object Store %06d" % index, "Resolution %04d" % subimage, "Subimage 0000 Header" ] fp = self.ole.openstream(stream) # skip prefix p = fp.read(28) # header stream s = fp.read(36) size = i32(s, 4), i32(s, 8) tilecount = i32(s, 12) tilesize = i32(s, 16), i32(s, 20) channels = i32(s, 24) offset = i32(s, 28) length = i32(s, 32) # print size, self.mode, self.rawmode if size != self.size: raise IOError, "subimage mismatch" # get tile descriptors fp.seek(28 + offset) s = fp.read(i32(s, 12) * length) x = y = 0 xsize, ysize = size xtile, ytile = tilesize self.tile = [] for i in range(0, len(s), length): compression = i32(s, i+8) if compression == 0: self.tile.append(("raw", (x,y,x+xtile,y+ytile), i32(s, i) + 28, (self.rawmode))) elif compression == 1: # FIXME: the fill decoder is not implemented self.tile.append(("fill", (x,y,x+xtile,y+ytile), i32(s, i) + 28, (self.rawmode, s[12:16]))) elif compression == 2: internal_color_conversion = ord(s[14]) jpeg_tables = ord(s[15]) rawmode = self.rawmode if internal_color_conversion: # The image is stored as usual (usually YCbCr). if rawmode == "RGBA": # For "RGBA", data is stored as YCbCrA based on # negative RGB. The following trick works around # this problem : jpegmode, rawmode = "YCbCrK", "CMYK" else: jpegmode = None # let the decoder decide else: # The image is stored as defined by rawmode jpegmode = rawmode self.tile.append(("jpeg", (x,y,x+xtile,y+ytile), i32(s, i) + 28, (rawmode, jpegmode))) # FIXME: jpeg tables are tile dependent; the prefix # data must be placed in the tile descriptor itself! if jpeg_tables: self.tile_prefix = self.jpeg[jpeg_tables] else: raise IOError, "unknown/invalid compression" x = x + xtile if x >= xsize: x, y = 0, y + ytile if y >= ysize: break # isn't really required self.stream = stream self.fp = None def load(self): if not self.fp: self.fp = self.ole.openstream(self.stream[:2] + ["Subimage 0000 Data"]) ImageFile.ImageFile.load(self) # # -------------------------------------------------------------------- Image.register_open("FPX", FpxImageFile, _accept) Image.register_extension("FPX", ".fpx") Imaging-1.1.3/PIL/GbrImagePlugin.py0100444000076400007640000000312507442710203016566 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/PIL/GbrImagePlugin.py#3 $ # # load a GIMP brush file # # History: # 96-03-14 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # import Image, ImageFile def i32(c): return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24) def _accept(prefix): return i32(prefix) >= 20 and i32(prefix[4:8]) == 1 class GbrImageFile(ImageFile.ImageFile): format = "GBR" format_description = "GIMP brush file" def _open(self): header_size = i32(self.fp.read(4)) version = i32(self.fp.read(4)) if header_size < 20 or version != 1: raise SyntaxError, "not a GIMP brush" width = i32(self.fp.read(4)) height = i32(self.fp.read(4)) bytes = i32(self.fp.read(4)) if width <= 0 or height <= 0 or bytes != 1: raise SyntaxError, "not a GIMP brush" comment = self.fp.read(header_size - 20)[:-1] self.mode = "L" self.size = width, height self.info["comment"] = comment # Since the brush is so small, we read the data immediately self.data = self.fp.read(width * height) def load(self): if not self.data: return # create an image out of the brush data block self.im = Image.core.new(self.mode, self.size) self.im.fromstring(self.data) self.data = "" # # registry Image.register_open("GBR", GbrImageFile, _accept) Image.register_extension("GBR", ".gbr") Imaging-1.1.3/PIL/GdImageFile.py0100444000076400007640000000326007442710203016027 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/GdImageFile.py#3 $ # # GD file handling # # History: # 96-04-12 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # # NOTE: This format cannot be automatically recognized, so the # class is not registered for use with Image.open(). To open a # gd file, use the GdImageFile.open() function instead. # THE GD FORMAT IS NOT DESIGNED FOR DATA INTERCHANGE. This # implementation is provided for convenience and demonstrational # purposes only. __version__ = "0.1" import string import Image, ImageFile, ImagePalette def i16(c): return ord(c[1]) + (ord(c[0])<<8) class GdImageFile(ImageFile.ImageFile): format = "GD" format_description = "GD uncompressed images" def _open(self): # Header s = self.fp.read(775) self.mode = "L" # FIXME: "P" self.size = i16(s[0:2]), i16(s[2:4]) # transparency index tindex = i16(s[5:7]) if tindex < 256: self.info["transparent"] = tindex self.palette = ImagePalette.raw("RGB", s[7:]) self.tile = [("raw", (0,0)+self.size, 775, ("L", 0, -1))] def open(fp, mode = "r"): "Open a GD image file, without loading the raster data" if mode != "r": raise ValueError, "bad mode" if type(fp) == type(""): import __builtin__ filename = fp fp = __builtin__.open(fp, "rb") else: filename = "" try: return GdImageFile(fp, filename) except SyntaxError: raise IOError, "cannot identify this image file" # save is not supported Imaging-1.1.3/PIL/GifImagePlugin.py0100444000076400007640000002401707442710203016564 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/GifImagePlugin.py#2 $ # # GIF file handling # # History: # 2025-09-01 fl Created # 2025-12-14 fl Added interlace support # 2024-12-30 fl Added animation support # 2025-01-05 fl Added write support, fixed local colour map bug # 2025-02-23 fl Make sure to load raster data in getdata() # 2025-07-05 fl Support external decoder (0.4) # 2025-07-09 fl Handle all modes when saving (0.5) # 2025-07-15 fl Renamed offset attribute to avoid name clash # 2025-04-16 fl Added rewind support (seek to frame 0) (0.6) # 2025-04-17 fl Added palette optimization (0.7) # # Copyright (c) 1997-2001 by Secret Labs AB # Copyright (c) 1995-1997 by Fredrik Lundh # # See the README file for information on usage and redistribution. # __version__ = "0.7" import Image, ImageFile, ImagePalette # -------------------------------------------------------------------- # Helpers def i16(c): return ord(c[0]) + (ord(c[1])<<8) def o16(i): return chr(i&255) + chr(i>>8&255) # -------------------------------------------------------------------- # Identify/read GIF files def _accept(prefix): return prefix[:6] in ["GIF87a", "GIF89a"] class GifImageFile(ImageFile.ImageFile): format = "GIF" format_description = "Compuserve GIF" global_palette = None def data(self): s = self.fp.read(1) if s and ord(s): return self.fp.read(ord(s)) return None def _open(self): # Screen s = self.fp.read(13) if s[:6] not in ["GIF87a", "GIF89a"]: raise SyntaxError, "not a GIF file" self.info["version"] = s[:6] self.size = i16(s[6:]), i16(s[8:]) self.tile = [] flags = ord(s[10]) bits = (flags & 7) + 1 if flags & 128: # get global palette self.info["background"] = ord(s[11]) # check if palette contains colour indices p = self.fp.read(3<%s" % (file, filename)) else: os.system("ppmquant 256 %s | ppmtogif >%s" % (file, filename)) try: os.unlink(file) except: pass # -------------------------------------------------------------------- # GIF utilities def getheader(im, info=None): """Return a list of strings representing a GIF header""" optimize = info and info.get("optimize", 0) s = [ "GIF87a" + # magic o16(im.size[0]) + # size o16(im.size[1]) + chr(7 + 128) + # flags: bits + palette chr(0) + # background chr(0) # reserved/aspect ] if optimize: # minimize color palette i = 0 maxcolor = 0 for count in im.histogram(): if count: maxcolor = i i = i + 1 else: maxcolor = 256 # global palette if im.mode == "P": # colour palette s.append(im.im.getpalette("RGB")[:maxcolor*3]) else: # greyscale for i in range(maxcolor): s.append(chr(i) * 3) return s def getdata(im, offset = (0, 0), **params): """Return a list of strings representing this image. The first string is a local image header, the rest contains encoded image data.""" class collector: data = [] def write(self, data): self.data.append(data) im.load() # make sure raster data is available fp = collector() try: im.encoderinfo = params # local image header fp.write("," + 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) Imaging-1.1.3/PIL/GimpGradientFile.py0100444000076400007640000000630407442710203017106 0ustar fredrikfredrik# # Python Imaging Library # $Id: //modules/pil/PIL/GimpGradientFile.py#2 $ # # stuff to read (and render) GIMP gradient files # # History: # 97-08-23 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # from math import pi, log, sin, sqrt import string # -------------------------------------------------------------------- # Stuff to translate curve segments to palette values (derived from # the corresponding code in GIMP, written by Federico Mena Quintero. # See the GIMP distribution for more information.) # EPSILON = 1e-10 def linear(middle, pos): if pos <= middle: if middle < EPSILON: return 0.0 else: return 0.5 * pos / middle else: pos = pos - middle middle = 1.0 - middle if middle < EPSILON: return 1.0 else: return 0.5 + 0.5 * pos / middle def curved(middle, pos): return pos ** (log(0.5) / log(max(middle, EPSILON))) def sine(middle, pos): return (sin((-pi / 2.0) + pi * linear(middle, pos)) + 1.0) / 2.0 def sphere_increasing(middle, pos): return sqrt(1.0 - (linear(middle, pos) - 1.0) ** 2) def sphere_decreasing(middle, pos): return 1.0 - sqrt(1.0 - linear(middle, pos) ** 2) SEGMENTS = [ linear, curved, sine, sphere_increasing, sphere_decreasing ] # -------------------------------------------------------------------- # class GradientFile: gradient = None def getpalette(self, entries = 256): palette = [] ix = 0 x0, x1, xm, rgb0, rgb1, segment = self.gradient[ix] for i in range(entries): x = i / float(entries-1) while x1 < x: ix = ix + 1 x0, x1, xm, rgb0, rgb1, segment = self.gradient[ix] w = x1 - x0 if w < EPSILON: scale = segment(0.5, 0.5) else: scale = segment((xm - x0) / w, (x - x0) / w) # expand to RGBA r = chr(int(255 * ((rgb1[0] - rgb0[0]) * scale + rgb0[0]) + 0.5)) g = chr(int(255 * ((rgb1[1] - rgb0[1]) * scale + rgb0[1]) + 0.5)) b = chr(int(255 * ((rgb1[2] - rgb0[2]) * scale + rgb0[2]) + 0.5)) a = chr(int(255 * ((rgb1[3] - rgb0[3]) * scale + rgb0[3]) + 0.5)) # add to palette palette.append(r + g + b + a) return string.join(palette, ""), "RGBA" class GimpGradientFile(GradientFile): def __init__(self, fp): if fp.readline()[:13] != "GIMP Gradient": raise SyntaxError, "not a GIMP gradient file" count = string.atoi(fp.readline()) gradient = [] for i in range(count): s = string.split(fp.readline()) w = map(string.atof, s[:11]) x0, x1 = w[0], w[2] xm = w[1] rgb0 = w[3:7] rgb1 = w[7:11] segment = SEGMENTS[string.atoi(s[11])] cspace = string.atoi(s[12]) if cspace != 0: raise IOError, "cannot handle HSV colour space" gradient.append((x0, x1, xm, rgb0, rgb1, segment)) self.gradient = gradient Imaging-1.1.3/PIL/GimpPaletteFile.py0100444000076400007640000000226307442710203016747 0ustar fredrikfredrik# # Python Imaging Library # $Id: //modules/pil/PIL/GimpPaletteFile.py#3 $ # # stuff to read GIMP palette files # # History: # 97-08-23 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # import string class GimpPaletteFile: rawmode = "RGB" def __init__(self, fp): self.palette = map(lambda i: chr(i)*3, range(256)) if fp.readline()[:12] != "GIMP Palette": raise SyntaxError, "not a GIMP palette file" i = 0 while i <= 255: s = fp.readline() if not s: break if len(s) > 100: raise SyntaxError, "bad palette file" if s[0] == "#": continue v = tuple(map(string.atoi, string.split(s)[:3])) if len(v) != 3: raise ValueError, "bad palette entry" if 0 <= i <= 255: self.palette[i] = chr(v[0]) + chr(v[1]) + chr(v[2]) i = i + 1 self.palette = string.join(self.palette, "") def getpalette(self): return self.palette, self.rawmode Imaging-1.1.3/PIL/IcoImagePlugin.py0100444000076400007640000000366107442710203016573 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/IcoImagePlugin.py#3 $ # # Windows Icon support for PIL # # Notes: # uses BmpImagePlugin.py to read the bitmap data. # # History: # 96-05-27 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import string import Image, BmpImagePlugin # # -------------------------------------------------------------------- def i16(c): return ord(c[0]) + (ord(c[1])<<8) def i32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) def _accept(prefix): return prefix[:4] == "\0\0\1\0" class IcoImageFile(BmpImagePlugin.BmpImageFile): format = "ICO" format_description = "Windows Icon" def _open(self): # check magic s = self.fp.read(6) if not _accept(s): raise SyntaxError, "not an ICO file" # pick the largest icon in the file m = "" for i in range(i16(s[4:])): s = self.fp.read(16) if not m: m = s elif ord(s[0]) > ord(m[0]) and ord(s[1]) > ord(m[1]): m = s #print "width", ord(s[0]) #print "height", ord(s[1]) #print "colors", ord(s[2]) #print "reserved", ord(s[3]) #print "planes", i16(s[4:]) #print "bitcount", i16(s[6:]) #print "bytes", i32(s[8:]) #print "offset", i32(s[12:]) # load as bitmap self._bitmap(i32(m[12:])) # patch up the bitmap height self.size = self.size[0], self.size[1]/2 d, e, o, a = self.tile[0] self.tile[0] = d, (0,0)+self.size, o, a return # # -------------------------------------------------------------------- Image.register_open("ICO", IcoImageFile, _accept) Image.register_extension("ICO", ".ico") Imaging-1.1.3/PIL/Image.py0100444000076400007640000007045607444200030014761 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/Image.py#17 $ # # the Image class wrapper # # history: # 2025-09-09 fl Created # 2025-03-11 fl PIL release 0.0 (proof of concept) # 2025-04-30 fl PIL release 0.1b1 # 2025-05-27 fl PIL release 0.1b2 # 2025-11-04 fl PIL release 0.2b1 # 2025-12-08 fl PIL release 0.2b2 # 2025-12-16 fl PIL release 0.2b3 # 2025-01-14 fl PIL release 0.2b4 # 2025-07-02 fl PIL release 0.3b1 # 2025-07-17 fl PIL release 0.3b2 # 2025-01-01 fl PIL release 1.0b1 # 2025-02-08 fl PIL release 1.0b2 # 2025-07-28 fl PIL release 1.0 final # 2025-08-15 fl PIL release 1.0.1 (internal maintenance release) # 2025-06-07 fl PIL release 1.1 # 2025-10-20 fl PIL release 1.1.1 # 2025-05-07 fl PIL release 1.1.2 # 2025-01-14 fl PIL release 1.2b1 (imToolkit) # 2025-03-15 fl PIL release 1.1.3 # # Copyright (c) 1997-2002 by Secret Labs AB. All rights reserved. # Copyright (c) 1995-2002 by Fredrik Lundh. # # See the README file for information on usage and redistribution. # VERSION = "1.1.3" class _imaging_not_installed: # module placeholder def __getattr__(self, id): raise ImportError, "The _imaging C module is not installed" try: # give Tk a chance to set up the environment, in case we're # using an _imaging module linked against libtcl/libtk import FixTk except ImportError: pass try: # If the _imaging C module is not present, you can still use # the "open" function to identify files, but you cannot load # them. Note that other modules should not refer to _imaging # directly; import Image and use the Image.core variable instead. import _imaging core = _imaging del _imaging except ImportError: core = _imaging_not_installed() import ImagePalette import os, string, sys # type stuff from types import IntType, StringType, TupleType try: UnicodeStringType = type(unicode("")) def isStringType(t): return isinstance(t, StringType) or isinstance(t, UnicodeStringType) except NameError: def isStringType(t): return isinstance(t, StringType) def isTupleType(t): return isinstance(t, TupleType) def isImageType(t): return hasattr(t, "im") def isDirectory(f): return isStringType(f) and os.path.isdir(f) from operator import isNumberType, isSequenceType # # Debug level DEBUG = 0 # # Constants (also defined in _imagingmodule.c!) NONE = 0 # transpose FLIP_LEFT_RIGHT = 0 FLIP_TOP_BOTTOM = 1 ROTATE_90 = 2 ROTATE_180 = 3 ROTATE_270 = 4 # transforms AFFINE = 0 EXTENT = 1 PERSPECTIVE = 2 # Not yet implemented QUAD = 3 MESH = 4 # resampling filters NONE = 0 NEAREST = 0 ANTIALIAS = 1 # 3-lobed lanczos LINEAR = BILINEAR = 2 CUBIC = BICUBIC = 3 # dithers NONE = 0 NEAREST = 0 ORDERED = 1 # Not yet implemented RASTERIZE = 2 # Not yet implemented FLOYDSTEINBERG = 3 # default # palettes/quantizers WEB = 0 ADAPTIVE = 1 # categories NORMAL = 0 SEQUENCE = 1 CONTAINER = 2 # -------------------------------------------------------------------- # Registries ID = [] OPEN = {} MIME = {} SAVE = {} EXTENSION = {} # -------------------------------------------------------------------- # Modes supported by this version _MODEINFO = { # official modes "1": ("L", "L", ("1",)), "L": ("L", "L", ("L",)), "I": ("L", "I", ("I",)), "F": ("L", "F", ("F",)), "P": ("RGB", "L", ("P",)), "RGB": ("RGB", "L", ("R", "G", "B")), "RGBX": ("RGB", "L", ("R", "G", "B", "X")), "RGBA": ("RGB", "L", ("R", "G", "B", "A")), "CMYK": ("RGB", "L", ("C", "M", "Y", "K")), "YCbCr": ("RGB", "L", ("Y", "Cb", "Cr")), # Experimental modes include I;16, I;16B, RGBa, BGR;15, # and BGR;24. Use these modes only if you know exactly # what you're doing... } MODES = _MODEINFO.keys() MODES.sort() def getmodebase(mode): # corresponding "base" mode (grayscale or colour) return _MODEINFO[mode][0] def getmodetype(mode): # storage type (per band) return _MODEINFO[mode][1] def getmodebands(mode): # subcomponents return len(_MODEINFO[mode][2]) # -------------------------------------------------------------------- # Helpers _initialized = 0 def preinit(): "Load standard file format drivers." global _initialized if _initialized >= 1: return for m in ("Bmp", "Gif", "Jpeg", "Ppm", "Png", "Tiff"): try: __import__("%sImagePlugin" % m, globals(), locals(), []) except ImportError: pass # ignore missing driver for now _initialized = 1 def init(): "Load all file format drivers." global _initialized if _initialized >= 2: return visited = {} directories = sys.path try: directories = directories + [os.path.dirname(__file__)] except NameError: pass # only check directories (including current, if present in the path) for directory in filter(isDirectory, directories): fullpath = os.path.abspath(directory) if visited.has_key(fullpath): continue for file in os.listdir(directory): if file[-14:] == "ImagePlugin.py": f, e = os.path.splitext(file) try: sys.path.insert(0, directory) try: __import__(f, globals(), locals(), []) finally: del sys.path[0] except ImportError: if DEBUG: print "Image: failed to import", print f, ":", sys.exc_value visited[fullpath] = None if OPEN or SAVE: _initialized = 2 # -------------------------------------------------------------------- # Codec factories (used by tostring/fromstring and ImageFile.load) def _getdecoder(mode, decoder_name, args, extra=()): # tweak arguments if args is None: args = () elif not isTupleType(args): args = (args,) try: # get decoder decoder = getattr(core, decoder_name + "_decoder") # print decoder, (mode,) + args + extra return apply(decoder, (mode,) + args + extra) except AttributeError: raise IOError("decoder %s not available" % decoder_name) def _getencoder(mode, encoder_name, args, extra=()): # tweak arguments if args is None: args = () elif not isTupleType(args): args = (args,) try: # get encoder encoder = getattr(core, encoder_name + "_encoder") # print encoder, (mode,) + args + extra return apply(encoder, (mode,) + args + extra) except AttributeError: raise IOError("encoder %s not available" % encoder_name) # -------------------------------------------------------------------- # Simple expression analyzer class _E: def __init__(self, data): self.data = data def __coerce__(self, other): return self, _E(other) def __add__(self, other): return _E((self.data, "__add__", other.data)) def __mul__(self, other): return _E((self.data, "__mul__", other.data)) def _getscaleoffset(expr): stub = ["stub"] data = expr(_E(stub)).data try: (a, b, c) = data # simplified syntax if (a is stub and b == "__mul__" and isNumberType(c)): return c, 0.0 if (a is stub and b == "__add__" and isNumberType(c)): return 1.0, c except TypeError: pass try: ((a, b, c), d, e) = data # full syntax if (a is stub and b == "__mul__" and isNumberType(c) and d == "__add__" and isNumberType(e)): return c, e except TypeError: pass raise ValueError("illegal expression") # -------------------------------------------------------------------- # Implementation wrapper class Image: format = None format_description = None def __init__(self): self.im = None self.mode = "" self.size = (0, 0) self.palette = None self.info = {} self.category = NORMAL self.readonly = 0 def _new(self, im): new = Image() new.im = im new.mode = im.mode new.size = im.size new.palette = self.palette try: new.info = self.info.copy() except AttributeError: # fallback (pre-1.5.2) new.info = {} for k, v in self.info: new.info[k] = v return new _makeself = _new # compatibility def _copy(self): self.load() self.im = self.im.copy() self.readonly = 0 def _dump(self, file=None, format=None): import tempfile if not file: file = tempfile.mktemp() self.load() if not format or format == "PPM": self.im.save_ppm(file) else: file = file + "." + format self.save(file, format) return file def tostring(self, encoder_name="raw", *args): "Return image as a binary string" # may pass tuple instead of argument list if len(args) == 1 and isTupleType(args[0]): args = args[0] if encoder_name == "raw" and args == (): args = self.mode self.load() # unpack data e = _getencoder(self.mode, encoder_name, args) e.setimage(self.im) data = [] while 1: l, s, d = e.encode(65536) data.append(d) if s: break if s < 0: raise RuntimeError("encoder error %d in tostring" % s) return string.join(data, "") def tobitmap(self, name="image"): "Return image as an XBM bitmap" self.load() if self.mode != "1": raise ValueError("not a bitmap") data = self.tostring("xbm") return string.join(["#define %s_width %d\n" % (name, self.size[0]), "#define %s_height %d\n"% (name, self.size[1]), "static char %s_bits[] = {\n" % name, data, "};"], "") def fromstring(self, data, decoder_name="raw", *args): "Load data to image from binary string" # may pass tuple instead of argument list if len(args) == 1 and isTupleType(args[0]): args = args[0] # default format if decoder_name == "raw" and args == (): args = self.mode # unpack data d = _getdecoder(self.mode, decoder_name, args) d.setimage(self.im) s = d.decode(data) if s[0] >= 0: raise ValueError("not enough image data") if s[1] != 0: raise ValueError("cannot decode image data") def load(self): if self.im and self.palette and self.palette.rawmode: self.im.putpalette(self.palette.rawmode, self.palette.data) self.palette.mode = "RGB" self.palette.rawmode = None if self.info.has_key("transparency"): self.im.putpalettealpha(self.info["transparency"], 0) self.palette.mode = "RGBA" # # function wrappers def convert(self, mode=None, data=None, dither=None, palette=WEB, colors=256): "Convert to other pixel format" if not mode: # determine default mode if self.mode == "P": self.load() if self.palette: mode = self.palette.mode else: mode = "RGB" else: return self.copy() self.load() if data: # matrix conversion if mode not in ("L", "RGB"): raise ValueError("illegal conversion") im = self.im.convert_matrix(mode, data) return self._new(im) if mode == "P" and palette == ADAPTIVE: im = self.im.quantize(colors) return self._new(im) # colourspace conversion if dither is None: dither = FLOYDSTEINBERG try: im = self.im.convert(mode, dither) except ValueError: try: # normalize source image and try again im = self.im.convert(getmodebase(self.mode)) im = im.convert(mode, dither) except KeyError: raise ValueError("illegal conversion") return self._new(im) def quantize(self, colors=256, method=0, kmeans=0, palette=None): # methods: # 0 = median cut # 1 = maximum coverage # NOTE: this functionality will be moved to the extended # quantizer interface in a later versions of PIL. self.load() if palette: # use palette from reference image palette.load() if palette.mode != "P": raise ValueError("bad mode for palette image") if self.mode != "RGB" and self.mode != "L": raise ValueError( "only RGB or L mode images can be quantized to a palette" ) im = self.im.convert("P", 1, palette.im) return self._makeself(im) im = self.im.quantize(colors, method, kmeans) return self._new(im) def copy(self): "Copy raster data" self.load() im = self.im.copy() return self._new(im) def crop(self, box=None): "Crop region from image" self.load() if box is None: return self.copy() # lazy operation return _ImageCrop(self, box) def draft(self, mode, size): "Configure image decoder" pass def filter(self, kernel): "Apply environment filter to image" if self.mode == "P": raise ValueError("cannot filter palette images") self.load() id = kernel.id if self.im.bands == 1: return self._new(self.im.filter(id)) # fix to handle multiband images since _imaging doesn't ims = [] for c in range(self.im.bands): ims.append(self._new(self.im.getband(c).filter(id))) return merge(self.mode, ims) def getbands(self): "Get band names" return _MODEINFO[self.mode][2] def getbbox(self): "Get bounding box of actual data (non-zero pixels) in image" self.load() return self.im.getbbox() def getdata(self, band = None): "Get image data as sequence object." self.load() if band is not None: return self.im.getband(band) return self.im # could be abused def getextrema(self): "Get min/max value" self.load() if self.im.bands > 1: extrema = [] for i in range(self.im.bands): extrema.append(self.im.getband(i).getextrema()) return tuple(extrema) return self.im.getextrema() def getpixel(self, xy): "Get pixel value" self.load() return self.im.getpixel(xy) def getprojection(self): "Get projection to x and y axes" self.load() x, y = self.im.getprojection() return map(ord, x), map(ord, y) def histogram(self, mask=None, extrema=None): "Take histogram of image" self.load() if mask: mask.load() return self.im.histogram((0, 0), mask.im) if self.mode in ("I", "F"): if extrema is None: extrema = self.getextrema() return self.im.histogram(extrema) return self.im.histogram() def offset(self, xoffset, yoffset=None): "(deprecated) Offset image in horizontal and/or vertical direction" import ImageChops return ImageChops.offset(self, xoffset, yoffset) def paste(self, im, box=None, mask=None): "Paste other image into region" if box is None: # cover all of self box = (0, 0) + self.size if len(box) == 2: # lower left corner given; get size from image or mask if isImageType(im): box = box + (box[0]+im.size[0], box[1]+im.size[1]) else: box = box + (box[0]+mask.size[0], box[1]+mask.size[1]) if isImageType(im): im.load() if self.mode != im.mode: if self.mode != "RGB" or im.mode not in ("RGBA", "RGBa"): # should use an adapter for this! im = im.convert(self.mode) im = im.im self.load() if self.readonly: self._copy() if mask: mask.load() self.im.paste(im, box, mask.im) else: self.im.paste(im, box) def point(self, lut, mode=None): "Map image through lookup table" if self.mode in ("I", "F"): # floating point; lut must be a valid expression scale, offset = _getscaleoffset(lut) self.load() im = self.im.point_transform(scale, offset); else: # integer image; use lut and mode self.load() if not isSequenceType(lut): # if it isn't a list, it should be a function lut = map(lut, range(256)) * self.im.bands im = self.im.point(lut, mode) return self._new(im) def putalpha(self, im): "Set alpha layer" if self.mode != "RGBA" or im.mode not in ("1", "L"): raise ValueError("illegal image mode") im.load() self.load() if im.mode == "1": im = im.convert("L") self.im.putband(im.im, 3) def putdata(self, data, scale=1.0, offset=0.0): "Put data from a sequence object into an image." self.load() # hmm... self.im.putdata(data, scale, offset) def putpalette(self, data, rawmode="RGB"): "Put palette data into an image." if self.mode not in ("L", "P"): raise ValueError("illegal image mode") if not isStringType(data): data = string.join(map(chr, data), "") self.mode = "P" self.palette = ImagePalette.raw(rawmode, data) self.palette.mode = "RGB" def putpixel(self, xy, value): "Set pixel value" self.load() return self.im.putpixel(xy, value) def resize(self, size, resample=NEAREST): "Resize image" if resample not in (NEAREST, BILINEAR, BICUBIC, ANTIALIAS): raise ValueError("unknown resampling filter") self.load() if self.mode in ("1", "P"): resample = NEAREST if resample == ANTIALIAS: # requires stretch support (imToolkit & PIL 1.1.3) try: im = self.im.stretch(size, resample) except AttributeError: raise ValueError("unsupported resampling filter") else: im = self.im.resize(size, resample) return self._new(im) def rotate(self, angle, resample=NEAREST): "Rotate image. Angle given as degrees counter-clockwise." if resample not in (NEAREST, BILINEAR, BICUBIC): raise ValueError("unknown resampling filter") self.load() if self.mode in ("1", "P"): resample = NEAREST return self._new(self.im.rotate(angle, resample)) def save(self, fp, format=None, **params): "Save image to file or stream" if isStringType(fp): import __builtin__ filename = fp fp = __builtin__.open(fp, "wb") close = 1 else: filename = "" close = 0 self.encoderinfo = params self.encoderconfig = () self.load() preinit() ext = string.lower(os.path.splitext(filename)[1]) try: if not format: format = EXTENSION[ext] SAVE[string.upper(format)](self, fp, filename) except KeyError, v: init() if not format: format = EXTENSION[ext] SAVE[string.upper(format)](self, fp, filename) if close: fp.close() def seek(self, frame): "Seek to given frame in sequence file" # overridden by file handlers if frame != 0: raise EOFError def show(self, title=None, command=None): "Display image (for debug purposes only)" try: import ImageTk ImageTk._show(self, title) # note: caller must enter mainloop! except: _showxv(self, title, command) def split(self): "Split image into bands" ims = [] self.load() for i in range(self.im.bands): ims.append(self._new(self.im.getband(i))) return tuple(ims) def tell(self): "Return current frame number" return 0 def thumbnail(self, size, resample=NEAREST): "Create thumbnail representation (modifies image in place)" # FIXME: the default resampling filter will be changed # to ANTIALIAS in future versions # preserve aspect ratio x, y = self.size if x > size[0]: y = y * size[0] / x; x = size[0] if y > size[1]: x = x * size[1] / y; y = size[1] size = x, y if size == self.size: return self.draft(None, size) self.load() try: im = self.resize(size, resample) except ValueError: if resample != ANTIALIAS: raise im = self.resize(size, NEAREST) # fallback self.im = im.im self.mode = im.mode self.size = size self.readonly = 0 def transform(self, size, method, data, resample=NEAREST, fill=1): "Transform image" im = new(self.mode, size, None) if method == MESH: # list of quads for box, quad in data: im.__transformer(box, self, QUAD, quad, resample, fill) else: im.__transformer((0, 0)+size, self, method, data, resample, fill) return im def __transformer(self, box, image, method, data, resample=NEAREST, fill=1): "Transform into current image" # FIXME: this should be turned into a lazy operation (?) w = box[2]-box[0] h = box[3]-box[1] if method == AFFINE: # change argument order to match implementation data = (data[2], data[0], data[1], data[5], data[3], data[4]) elif method == EXTENT: # convert extent to an affine transform x0, y0, x1, y1 = data xs = float(x1 - x0) / w ys = float(y1 - y0) / h method = AFFINE data = (x0 + xs/2, xs, 0, y0 + ys/2, 0, ys) elif method == QUAD: # quadrilateral warp. data specifies the four corners # given as NW, SW, SE, and NE. nw = data[0:2]; sw = data[2:4]; se = data[4:6]; ne = data[6:8] x0, y0 = nw; As = 1.0 / w; At = 1.0 / h data = (x0, (ne[0]-x0)*As, (sw[0]-x0)*At, (se[0]-sw[0]-ne[0]+x0)*As*At, y0, (ne[1]-y0)*As, (sw[1]-y0)*At, (se[1]-sw[1]-ne[1]+y0)*As*At) else: raise ValueError("unknown transformation method") if resample not in (NEAREST, BILINEAR, BICUBIC): raise ValueError("unknown resampling filter") image.load() self.load() if image.mode in ("1", "P"): resample = NEAREST self.im.transform2(box, image.im, method, data, resample, fill) def transpose(self, method): "Transpose image (flip or rotate in 90 degree steps)" self.load() im = self.im.transpose(method) return self._new(im) # # test/extension hooks (don't use in production code!) def _stretch(self, size, resample=NEAREST): # same as resize if resample not in (NEAREST, BILINEAR, BICUBIC, ANTIALIAS): raise ValueError("unknown resampling filter") self.load() if self.mode in ("1", "P"): resample = NEAREST return self._new(self.im.stretch(size, resample)) # -------------------------------------------------------------------- # Lazy operations class _ImageCrop(Image): def __init__(self, im, box): Image.__init__(self) self.mode = im.mode self.size = box[2]-box[0], box[3]-box[1] self.__crop = box self.im = im.im def load(self): # lazy evaluation! if self.__crop: self.im = self.im.crop(self.__crop) self.__crop = None # FIXME: future versions should optimize crop/paste # sequences! # -------------------------------------------------------------------- # Factories # # Debugging def _wedge(): "Create greyscale wedge (for debugging only)" return Image()._new(core.wedge("L")) # # Create/open images. def new(mode, size, color=0): "Create a new image" if color is None: # don't initialize return Image()._new(core.new(mode, size)) return Image()._new(core.fill(mode, size, color)) def fromstring(mode, size, data, decoder_name="raw", *args): "Load image from string" # may pass tuple instead of argument list if len(args) == 1 and isTupleType(args[0]): args = args[0] if decoder_name == "raw" and args == (): args = mode im = new(mode, size) im.fromstring(data, decoder_name, args) return im def open(fp, mode="r"): "Open an image file, without loading the raster data" if mode != "r": raise ValueError("bad mode") if isStringType(fp): import __builtin__ filename = fp fp = __builtin__.open(fp, "rb") else: filename = "" prefix = fp.read(16) preinit() for i in ID: try: factory, accept = OPEN[i] if not accept or accept(prefix): fp.seek(0) return factory(fp, filename) except (SyntaxError, IndexError, TypeError): pass init() for i in ID: try: factory, accept = OPEN[i] if not accept or accept(prefix): fp.seek(0) return factory(fp, filename) except (SyntaxError, IndexError, TypeError): pass raise IOError("cannot identify image file") # # Image processing. def blend(im1, im2, alpha): "Interpolate between images." if alpha <= 0.0: return im1 elif alpha >= 1.0: return im2 im1.load() im2.load() return im1._new(core.blend(im1.im, im2.im, alpha)) def composite(image1, image2, mask): "Create composite image by blending images using a transparency mask" image = image2.copy() image.paste(image1, None, mask) return image def eval(image, *args): "Evaluate image expression" return image.point(args[0]) def merge(mode, bands): "Merge a set of single band images into a new multiband image." if getmodebands(mode) != len(bands) or "*" in mode: raise ValueError("wrong number of bands") for im in bands[1:]: if im.mode != getmodetype(mode): raise ValueError("mode mismatch") if im.size != bands[0].size: raise ValueError("size mismatch") im = core.new(mode, bands[0].size) for i in range(getmodebands(mode)): bands[i].load() im.putband(bands[i].im, i) return bands[0]._new(im) # -------------------------------------------------------------------- # Plugin registry def register_open(id, factory, accept=None): id = string.upper(id) ID.append(id) OPEN[id] = factory, accept def register_mime(id, mimetype): MIME[string.upper(id)] = mimetype def register_save(id, driver): SAVE[string.upper(id)] = driver def register_extension(id, extension): EXTENSION[string.lower(extension)] = string.upper(id) # -------------------------------------------------------------------- # Simple display support def _showxv(self, title=None, command=None): if os.name == "nt": format = "BMP" if not command: command = "start" else: format = None if not command: command = "xv" if title: command = command + " -name \"%s\"" % title base = getmodebase(self.mode) if base != self.mode and self.mode != "1": file = self.convert(base)._dump(format=format) else: file = self._dump(format=format) if os.name == "nt": os.system("%s %s" % (command, file)) # FIXME: this leaves temporary files around... else: os.system("(%s %s; rm -f %s)&" % (command, file, file)) Imaging-1.1.3/PIL/ImageChops.py0100444000076400007640000000635507442710203015761 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageChops.py#2 $ # # standard channel operations # # History: # 2025-03-24 fl Created # 2025-08-13 fl Added logical operations (for "1" images) # 2025-10-12 fl Added offset method (from Image.py) # # Copyright (c) 1997-2000 by Secret Labs AB # Copyright (c) 1996-2000 by Fredrik Lundh # # See the README file for information on usage and redistribution. # import Image def constant(image, value): "Fill a channel with a given grey level" return Image.new("L", image.size, value) def duplicate(image): "Create a copy of a channel" return image.copy() def invert(image): "Invert a channel" image.load() return image._new(image.im.chop_invert()) def lighter(image1, image2): "Select the lighter pixels from each image" image1.load() image2.load() return image1._new(image1.im.chop_lighter(image2.im)) def darker(image1, image2): "Select the darker pixels from each image" image1.load() image2.load() return image1._new(image1.im.chop_darker(image2.im)) def difference(image1, image2): "Subtract one image from another" image1.load() image2.load() return image1._new(image1.im.chop_difference(image2.im)) def multiply(image1, image2): "Superimpose two positive images" image1.load() image2.load() return image1._new(image1.im.chop_multiply(image2.im)) def screen(image1, image2): "Superimpose two negative images" image1.load() image2.load() return image1._new(image1.im.chop_screen(image2.im)) def add(image1, image2, scale=1.0, offset=0): "Add two images" image1.load() image2.load() return image1._new(image1.im.chop_add(image2.im, scale, offset)) def subtract(image1, image2, scale=1.0, offset=0): "Subtract two images" image1.load() image2.load() return image1._new(image1.im.chop_subtract(image2.im, scale, offset)) def add_modulo(image1, image2): "Add two images without clipping" image1.load() image2.load() return image1._new(image1.im.chop_add_modulo(image2.im)) def subtract_modulo(image1, image2): "Subtract two images without clipping" image1.load() image2.load() return image1._new(image1.im.chop_subtract_modulo(image2.im)) def logical_and(image1, image2): "Logical and between two images" image1.load() image2.load() return image1._new(image1.im.chop_and(image2.im)) def logical_or(image1, image2): "Logical or between two images" image1.load() image2.load() return image1._new(image1.im.chop_or(image2.im)) def logical_xor(image1, image2): "Logical xor between two images" image1.load() image2.load() return image1._new(image1.im.chop_xor(image2.im)) def blend(image1, image2, alpha): "Blend two images using a constant transparency weight" return Image.blend(image1, image2, alpha) def composite(image1, image2, mask): "Create composite image by blending images using a transparency mask" return Image.composite(image1, image2, mask) def offset(image, xoffset, yoffset=None): "Offset image in horizontal and/or vertical direction" if yoffset is None: yoffset = xoffset image.load() return image._new(image.im.offset(xoffset, yoffset)) Imaging-1.1.3/PIL/ImageDraw.py0100444000076400007640000001153407442710203015575 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/PIL/ImageDraw.py#2 $ # # drawing interface operations # # History: # 2025-04-13 fl Created (experimental) # 2025-08-07 fl Filled polygons, ellipses. # 2025-08-13 fl Added text support # 2025-06-28 fl Handle I and F images # 2024-12-29 fl Added arc; use arc primitive to draw ellipses # 2025-01-10 fl Added shape stuff (experimental) # 2025-02-06 fl Added bitmap support # 2025-02-11 fl Changed all primitives to take options # 2025-02-20 fl Fixed backwards compatibility # 2025-10-12 fl Copy on write, when necessary # 2025-02-18 fl Use default ink for bitmap/text also in fill mode # # Copyright (c) 1997-2001 by Secret Labs AB # Copyright (c) 1996-2001 by Fredrik Lundh # # See the README file for information on usage and redistribution. # import Image class Draw: def __init__(self, im): im.load() if im.readonly: im._copy() # make it writable self.im = im.im if im.mode in ("I", "F"): self.ink = self.im.draw_ink(1) else: self.ink = self.im.draw_ink(-1) self.fill = 0 self.font = None # # attributes def setink(self, ink): # compatibility self.ink = self.im.draw_ink(ink) def setfill(self, onoff): # compatibility self.fill = onoff def setfont(self, font): # compatibility self.font = font def getfont(self): if not self.font: # FIXME: should add a font repository import ImageFont self.font = ImageFont.load_path("BDF/courR14.pil") return self.font def textsize(self, text, font=None): if font is None: font = self.getfont() return font.getsize(text) def _getink(self, ink, fill=None): if ink is None and fill is None: if self.fill: fill = self.ink else: ink = self.ink else: if ink is not None: ink = self.im.draw_ink(ink) if fill is not None: fill = self.im.draw_ink(fill) return ink, fill # # primitives def arc(self, xy, start, end, fill=None): ink, fill = self._getink(fill) if ink is not None: self.im.draw_arc(xy, start, end, ink) def bitmap(self, xy, bitmap, fill=None): bitmap.load() ink, fill = self._getink(fill) if ink is None: ink = fill if ink is not None: self.im.draw_bitmap(xy, bitmap.im, ink) def chord(self, xy, start, end, fill=None, outline=None): ink, fill = self._getink(outline, fill) if fill is not None: self.im.draw_chord(xy, start, end, fill, 1) if ink is not None: self.im.draw_chord(xy, start, end, ink, 0) def ellipse(self, xy, fill=None, outline=None): ink, fill = self._getink(outline, fill) if fill is not None: self.im.draw_ellipse(xy, fill, 1) if ink is not None: self.im.draw_ellipse(xy, ink, 0) def line(self, xy, fill=None): ink, fill = self._getink(fill) if ink is not None: self.im.draw_lines(xy, ink) def shape(self, shape, fill=None, outline=None): # experimental shape.close() ink, fill = self._getink(outline, fill) if fill is not None: self.im.draw_outline(shape, fill, 1) if ink is not None: self.im.draw_outline(shape, ink, 0) def pieslice(self, xy, start, end, fill=None, outline=None): ink, fill = self._getink(outline, fill) if fill is not None: self.im.draw_pieslice(xy, start, end, fill, 1) if ink is not None: self.im.draw_pieslice(xy, start, end, ink, 0) def point(self, xy, fill=None): ink, fill = self._getink(fill) if ink is not None: self.im.draw_points(xy, ink) def polygon(self, xy, fill=None, outline=None): ink, fill = self._getink(outline, fill) if fill is not None: self.im.draw_polygon(xy, fill, 1) if ink is not None: self.im.draw_polygon(xy, ink, 0) def rectangle(self, xy, fill=None, outline=None): ink, fill = self._getink(outline, fill) if fill is not None: self.im.draw_rectangle(xy, fill, 1) if ink is not None: self.im.draw_rectangle(xy, ink, 0) def text(self, xy, text, fill=None, font=None, anchor=None): ink, fill = self._getink(fill) if font is None: font = self.getfont() if ink is None: ink = fill if ink is not None: self.im.draw_bitmap(xy, font.getmask(text), ink) # backwards compatibility ImageDraw = Draw # experimental access to the outline API try: Outline = Image.core.outline except: Outline = None Imaging-1.1.3/PIL/ImageEnhance.py0100444000076400007640000000261307442710203016237 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageEnhance.py#3 $ # # image enhancement classes # # For a background, see "Image Processing By Interpolation and # Extrapolation", Paul Haeberli and Douglas Voorhies. Available # at http://www.sgi.com/grafica/interp/index.html # # History: # 96-03-23 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # import Image, ImageFilter class _Enhance: def enhance(self, alpha): return Image.blend(self.degenerate, self.image, alpha) class Color(_Enhance): "Adjust image colour balance" def __init__(self, image): self.image = image self.degenerate = image.convert("L").convert(image.mode) class Contrast(_Enhance): "Adjust image contrast" def __init__(self, image): self.image = image mean = reduce(lambda a,b: a+b, image.convert("L").histogram())/256.0 self.degenerate = Image.new("L", image.size, mean).convert(image.mode) class Brightness(_Enhance): "Adjust image brightness" def __init__(self, image): self.image = image self.degenerate = Image.new(image.mode, image.size, 0) class Sharpness(_Enhance): "Adjust image sharpness" def __init__(self, image): self.image = image self.degenerate = image.filter(ImageFilter.SMOOTH) Imaging-1.1.3/PIL/ImageFile.py0100444000076400007640000002503307442710203015556 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageFile.py#2 $ # # base class for image file handlers # # history: # 2025-09-09 fl Created # 2025-03-11 fl Fixed load mechanism. # 2025-04-15 fl Added pcx/xbm decoders. # 2025-04-30 fl Added encoders. # 2025-12-14 fl Added load helpers # 2025-01-11 fl Use encode_to_file where possible # 2025-08-27 fl Flush output in _save # 2025-03-05 fl Use memory mapping for some modes # 2025-02-04 fl Use memory mapping also for "I;16" and "I;16B" # 2025-05-31 fl Added image parser # 2025-10-12 fl Set readonly flag on memory-mapped images # # Copyright (c) 1997-2000 by Secret Labs AB # Copyright (c) 1995-2000 by Fredrik Lundh # # See the README file for information on usage and redistribution. # import Image import traceback, sys MAXBLOCK = 65536 # raw modes that may be memory mapped. NOTE: if you change this, you # may have to modify the stride calculation in map.c too! MAPMODES = ("L", "P", "RGBX", "RGBA", "CMYK", "I;16", "I;16B") # # -------------------------------------------------------------------- # Helpers def _tilesort(t1, t2): # sort on offset return cmp(t1[2], t2[2]) # # -------------------------------------------------------------------- # ImageFile base class class ImageFile(Image.Image): "Base class for image file format handlers." def __init__(self, fp=None, filename=None): Image.Image.__init__(self) self.tile = None self.readonly = 1 # until we know better self.decoderconfig = () self.decodermaxblock = MAXBLOCK if type(fp) == type(""): # filename self.fp = open(fp, "rb") self.filename = fp else: # stream self.fp = fp self.filename = filename try: self._open() except IndexError, v: # end of data if Image.DEBUG > 1: traceback.print_exc() raise SyntaxError, v except TypeError, v: # end of data (ord) if Image.DEBUG > 1: traceback.print_exc() raise SyntaxError, v except KeyError, v: # unsupported mode if Image.DEBUG > 1: traceback.print_exc() raise SyntaxError, v if not self.mode or self.size[0] <= 0: raise SyntaxError, "not identified by this driver" def draft(self, mode, size): "Set draft mode" pass def verify(self): "Check file integrity" # raise exception if something's wrong. must be called # directly after open, and closes file when finished. self.fp = None def load(self): "Load image data based on tile list" Image.Image.load(self) if self.tile is None: raise IOError, "cannot load this image" if not self.tile: return self.map = None readonly = 0 if self.filename and len(self.tile) == 1: # try memory mapping d, e, o, a = self.tile[0] if d == "raw" and a[0] == self.mode and a[0] in MAPMODES: try: self.map = Image.core.map(self.filename) self.map.seek(o) self.im = self.map.readimage( self.mode, self.size, a[1], a[2] ) readonly = 1 except (AttributeError, IOError): self.map = None self.load_prepare() if not self.map: # sort tiles in file order self.tile.sort(_tilesort) try: # FIXME: This is a hack to handle TIFF's JpegTables tag. prefix = self.tile_prefix except AttributeError: prefix = "" for d, e, o, a in self.tile: d = Image._getdecoder(self.mode, d, a, self.decoderconfig) self.load_seek(o) try: d.setimage(self.im, e) except ValueError: continue b = prefix t = len(b) while 1: s = self.load_read(self.decodermaxblock) if not s: self.tile = [] raise IOError, "image file is truncated, %d bytes left in buffer" % len(b) b = b + s n, e = d.decode(b) if n < 0: break b = b[n:] t = t + n self.tile = [] self.readonly = readonly self.fp = None # might be shared if not self.map and e < 0: raise IOError, "decoder error %d when reading image file" % e # post processing if hasattr(self, "tile_post_rotate"): # FIXME: This is a hack to handle rotated PCD's self.im = self.im.rotate(self.tile_post_rotate) self.size = self.im.size self.load_end() def load_prepare(self): # create image memory if necessary if not self.im or\ self.im.mode != self.mode or self.im.size != self.size: self.im = Image.core.new(self.mode, self.size) # create palette (optional) if self.mode == "P": Image.Image.load(self) def load_end(self): # may be overridden pass def load_seek(self, pos): # may be overridden for contained formats self.fp.seek(pos) def load_read(self, bytes): # may be overridden for blocked formats (e.g. PNG) return self.fp.read(bytes) class _ParserFile: # parser support class. def __init__(self, data): self.data = data self.offset = 0 def close(self): self.data = self.offset = None def tell(self): return self.offset def seek(self, offset, whence=0): if whence == 0: self.offset = offset elif whence == 1: self.offset = self.offset + offset else: # force error in Image.open raise IOError, "illegal argument to seek" def read(self, bytes=0): pos = self.offset if bytes: data = self.data[pos:pos+bytes] else: data = self.data[pos:] self.offset = pos + len(data) return data def readline(self): # FIXME: this is slow! s = "" while 1: c = self.read(1) if not c: break s = s + c if c == "\n": break return s class Parser: # incremental image parser. implements the consumer # interface. image = None data = None decoder = None finished = 0 def reset(self): assert self.data is None, "cannot reuse parsers" def feed(self, data): # collect data if self.finished: return if self.data is None: self.data = data else: self.data = self.data + data # parse what we have if self.decoder: if self.offset > 0: # skip header skip = min(len(self.data), self.offset) self.data = self.data[skip:] self.offset = self.offset - skip if self.offset > 0 or not self.data: return n, e = self.decoder.decode(self.data) if n < 0: # end of stream self.data = None self.finished = 1 if e < 0: # decoding error self.image = None raise IOError,\ "decoder error %d when reading image file" % e else: # end of image return self.data = self.data[n:] else: # attempt to open this file try: try: fp = _ParserFile(self.data) im = Image.open(fp) finally: fp.close() # explicitly close the virtual file except IOError: pass # not enough data else: # sanity check if len(im.tile) != 1: raise IOError, "cannot parse this image" # initialize decoder im.load_prepare() d, e, o, a = im.tile[0] im.tile = [] self.decoder = Image._getdecoder( im.mode, d, a, im.decoderconfig ) self.decoder.setimage(im.im, e) # calculate decoder offset self.offset = o if self.offset <= len(self.data): self.data = self.data[self.offset:] self.offset = 0 self.image = im def close(self): # finish decoding if self.decoder: # get rid of what's left in the buffers self.feed("") self.data = self.decoder = None if not self.finished: raise IOError, "image was incomplete" if not self.image: raise IOError, "cannot parse this image" return self.image # # -------------------------------------------------------------------- # Save image body def _save(im, fp, tile): "Helper to save image based on tile list" im.load() if not hasattr(im, "encoderconfig"): im.encoderconfig = () tile.sort(_tilesort) bufsize = max(MAXBLOCK, im.size[0] * 4) # see RawEncode.c try: fh = fp.fileno() fp.flush() except AttributeError: # compress to Python file-compatible object for e, b, o, a in tile: e = Image._getencoder(im.mode, e, a, im.encoderconfig) if o > 0: fp.seek(o, 0) e.setimage(im.im, b) while 1: l, s, d = e.encode(bufsize) fp.write(d) if s: break if s < 0: raise IOError, "encoder error %d when writing image file" % s else: # slight speedup: compress to real file object for e, b, o, a in tile: e = Image._getencoder(im.mode, e, a, im.encoderconfig) if o > 0: fp.seek(o, 0) e.setimage(im.im, b) s = e.encode_to_file(fh, bufsize) if s < 0: raise IOError, "encoder error %d when writing image file" % s try: fp.flush() except: pass Imaging-1.1.3/PIL/ImageFileIO.py0100444000076400007640000000122507442710203016003 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageFileIO.py#2 $ # # kludge to get basic ImageFileIO functionality # # History: # 98-08-06 fl Recreated # # Copyright (c) Secret Labs AB 1998. # # See the README file for information on usage and redistribution. # from StringIO import StringIO # this module is deprecated class ImageFileIO(StringIO): def __init__(self, fp): data = fp.read() StringIO.__init__(self, data) if __name__ == "__main__": import Image fp = open("/images/clenna.im", "rb") im = Image.open(ImageFileIO(fp)) im.load() # make sure we can read the raster data print im.mode, im.size Imaging-1.1.3/PIL/ImageFilter.py0100444000076400007640000000167207442710203016127 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageFilter.py#3 $ # # standard filters # # History: # 95-11-27 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1995. # # See the README file for information on usage and redistribution. # class _BuiltinFilter: def __init__(self, id, name = None): self.id = id self.name = name # FIXME: numbers correspond to table in _imagingmodule.c BLUR = _BuiltinFilter(0, "Blur") CONTOUR = _BuiltinFilter(1, "Contour") DETAIL = _BuiltinFilter(2, "Detail") EDGE_ENHANCE = _BuiltinFilter(3, "Edge-enhance") EDGE_ENHANCE_MORE = _BuiltinFilter(4, "Edge-enhance More") EMBOSS = _BuiltinFilter(5, "Emboss") FIND_EDGES = _BuiltinFilter(6, "Find Edges") SMOOTH = _BuiltinFilter(7, "Smooth") SMOOTH_MORE = _BuiltinFilter(8, "Smooth More") SHARPEN = _BuiltinFilter(9, "Sharpen") # User defined filters are not supported in release 0.1. Sorry for that. Imaging-1.1.3/PIL/ImageFont.py0100444000076400007640000001146207442710203015606 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageFont.py#4 $ # # PIL raster font management # # History: # 2025-08-07 fl created (experimental) # 2025-08-25 fl minor adjustments to handle fonts from pilfont 0.3 # 2025-02-06 fl rewrote most font management stuff in C # 2025-03-17 fl take pth files into account in load_path (from Richard Jones) # 2025-02-17 fl added freetype support # 2025-05-09 fl added TransposedFont wrapper class # 2025-03-04 fl make sure we have a "L" or "1" font # # Todo: # Adapt to PILFONT2 format (16-bit fonts, compressed, single file) # # Copyright (c) 1997-2002 by Secret Labs AB # Copyright (c) 1996-2001 by Fredrik Lundh # # See the README file for information on usage and redistribution. # import Image import os, string, sys # -------------------------------------------------------------------- # Font metrics format: # "PILfont" LF # fontdescriptor LF # (optional) key=value... LF # "DATA" LF # binary data: 256*10*2 bytes (dx, dy, dstbox, srcbox) # # To place a character, cut out srcbox and paste at dstbox, # relative to the character position. Then move the character # position according to dx, dy. # -------------------------------------------------------------------- # FIXME: add support for pilfont2 format (see FontFile.py) class ImageFont: "PIL font wrapper" def _load_pilfont(self, filename): fp = open(filename, "rb") # read PILfont header if fp.readline() != "PILfont\n": raise SyntaxError, "Not a PILfont file" d = string.split(fp.readline(), ";") self.info = [] # FIXME: should be a dictionary s = fp.readline() while s and s != "DATA\n": self.info.append(s) # read PILfont metrics data = fp.read(256*20) # read PILfont bitmap for ext in (".png", ".gif", ".pbm"): try: fullname = os.path.splitext(filename)[0] + ext image = Image.open(fullname) except: pass else: if image and image.mode in ("1", "L"): break else: raise IOError, "cannot find glyph data file" image.load() self.file = fullname self.font = Image.core.font(image.im, data) # delegate critical operations to internal type self.getsize = self.font.getsize self.getmask = self.font.getmask class FreeTypeFont: "FreeType font wrapper (requires _imagingft service)" def __init__(self, file, size, index=0): # FIXME: use service provider instead import _imagingft self.font = _imagingft.getfont(file, size, index) def getsize(self, text): return self.font.getsize(text) def getmask(self, text, fill=Image.core.fill): size = self.font.getsize(text) im = fill("L", size, 0) self.font.render(text, im.id) return im class TransposedFont: "Wrapper for writing rotated or mirrored text" def __init__(self, font, orientation=None): self.font = font self.orientation = orientation # any 'transpose' argument, or None def getsize(self, text): w, h = self.font.getsize(text) if self.orientation in (Image.ROTATE_90, Image.ROTATE_270): return h, w return w, h def getmask(self, text): im = self.font.getmask(text) if self.orientation is not None: return im.transpose(self.orientation) return im # # -------------------------------------------------------------------- def load(filename): "Load a font file." f = ImageFont() f._load_pilfont(filename) return f def truetype(filename, size, index=0): "Load a truetype font file." try: return FreeTypeFont(filename, size, index) except IOError: if sys.platform == "win32": # check the windows font repository # NOTE: must use uppercase WINDIR, to work around bugs in # 1.5.2's os.environ.get() windir = os.environ.get("WINDIR") if windir: filename = os.path.join(windir, "fonts", filename) return FreeTypeFont(filename, size, index) raise def load_path(filename): "Load a font file, searching along the Python path." for dir in sys.path: try: return load(os.path.join(dir, filename)) except IOError: pass # disabled: site.py already does this for us ## import glob ## for extra in glob.glob(os.path.join(dir, "*.pth")): ## try: ## dir = os.path.join(dir, string.strip(open(extra).read())) ## return load(os.path.join(dir, filename)) ## except IOError: ## pass raise IOError, "cannot find font file" Imaging-1.1.3/PIL/ImageOps.py0100444000076400007640000002200507442710203015434 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageOps.py#1 $ # # standard image operations # # History: # 2025-10-20 fl Created # 2025-10-23 fl Added autocontrast operator # 2025-12-18 fl Added Kevin's fit operator # # Copyright (c) 2001 by Secret Labs AB # Copyright (c) 2001 by Fredrik Lundh # # See the README file for information on usage and redistribution. # import Image # # helpers def _border(border): if type(border) is type(()): if len(border) == 2: left, top = right, bottom = border elif len(border) == 4: left, top, right, bottom = border else: left = top = right = bottom = border return left, top, right, bottom def _lut(image, lut): if image.mode == "P": # FIXME: apply to lookup table, not image data raise NotImplemented, "mode P support coming soon" elif image.mode in ("L", "RGB"): if image.mode == "RGB" and len(lut) == 256: lut = lut + lut + lut return image.point(lut) else: raise IOError, "not supported for this image mode" # # actions def autocontrast(image, cutoff=0, ignore=None): "Maximize image contrast, based on histogram" histogram = image.histogram() lut = [] for layer in range(0, len(histogram), 256): h = histogram[layer:layer+256] if ignore is not None: # get rid of outliers try: h[ignore] = 0 except TypeError: # assume sequence for ix in ignore: h[ix] = 0 if cutoff: # cut off pixels from both ends of the histogram # get number of pixels n = 0 for ix in range(256): n = n + h[ix] # remove cutoff% pixels from the low end cut = n * cutoff / 100 for lo in range(256): if cut > h[lo]: cut = cut - h[lo] h[lo] = 0 else: h[lo] = h[lo] - cut cut = 0 if cut <= 0: break # remove cutoff% samples from the hi end cut = n * cutoff / 100 for hi in range(255, -1, -1): if cut > h[hi]: cut = cut - h[hi] h[hi] = 0 else: h[hi] = h[hi] - cut cut = 0 if cut <= 0: break # find lowest/highest samples after preprocessing for lo in range(256): if h[lo]: break for hi in range(255, -1, -1): if h[hi]: break if hi <= lo: # don't bother lut.extend(range(256)) else: scale = 255.0 / (hi - lo) offset = -lo * scale for ix in range(256): ix = int(ix * scale + offset) if ix < 0: ix = 0 elif ix > 255: ix = 255 lut.append(ix) return _lut(image, lut) def colorize(image, black, white): "Colorize a grayscale image" assert image.mode == "L" red = []; green = []; blue = [] for i in range(256): red.append(black[0]+i*(white[0]-black[0])/255) green.append(black[1]+i*(white[1]-black[1])/255) blue.append(black[2]+i*(white[2]-black[2])/255) image = image.convert("RGB") return _lut(image, red + green + blue) def crop(image, border=0): "Crop border off image" left, top, right, bottom = _border(border) return image.crop( (left, top, image.size[0]-right, image.size[1]-bottom) ) def deform(image, deformer, resample=Image.BILINEAR): "Deform image using the given deformer" return image.transform( image.size, MESH, deformer.getmesh(image), resample ) def equalize(image): "Equalize image histogram" if image.mode == "P": h = image.convert("RGB").histogram() else: h = image.histogram() lut = [] for b in range(0, len(h), 256): step = reduce(operator.add, h[b:b+256]) / 255 n = 0 for i in range(256): lut.append(n / step) n = n + h[i+b] return _lut(image, lut) def expand(image, border=0, fill=0): "Add border to image" left, top, right, bottom = _border(border) width = left + image.size[0] + right height = top + image.size[1] + buttom out = Image.new(image.mode, (width, height), fill) out.paste((left, top), image) return out def fit(image, size, method=Image.NEAREST, bleed=0.0, centering=(0.5, 0.5)): """ This method returns a sized and cropped version of the image, cropped to the aspect ratio and size that you request. It can be customized to your needs with "method", "bleed", and "centering" as required. image: a PIL Image object size: output size in pixels, given as a (width, height) tuple method: resampling method bleed: decimal percentage (0-0.49999) of width/height to crop off as a minumum around the outside of the image This allows you to remove a default amount of the image around the outside, for 'cleaning up' scans that may have edges of negs showing, or whatever. This percentage is removed from EACH side, not a total amount. centering: (left, top), percentages to crop of each side to fit the aspect ratio you require. This function allows you to customize where the crop occurs, whether it is a 'center crop' or a 'top crop', or whatever. Default is center-cropped. (0.5, 0.5) is center cropping (i.e. if cropping the width, take 50% off of the left side (and therefore 50% off the right side), and same with Top/Bottom) (0.0, 0.0) will crop from the top left corner (i.e. if cropping the width, take all of the crop off of the right side, and if cropping the height, take all of it off the bottom) (1.0, 0.0) will crop from the bottom left corner, etc. (i.e. if cropping the width, take all of the crop off the left side, and if cropping the height take none from the Top (and therefore all off the bottom)) by Kevin Cazabon, Feb 17/2000 kevin@cazabon.com http://www.cazabon.com """ # ensure inputs are valid if type(centering) != type([]): centering = [centering[0], centering[1]] if centering[0] > 1.0 or centering[0] < 0.0: centering [0] = 0.50 if centering[1] > 1.0 or centering[1] < 0.0: centering[1] = 0.50 if bleed > 0.49999 or bleed < 0.0: bleed = 0.0 # calculate the area to use for resizing and cropping, subtracting # the 'bleed' around the edges # number of pixels to trim off on Top and Bottom, Left and Right bleedPixels = ( int((float(bleed) * float(image.size[0])) + 0.5), int((float(bleed) * float(image.size[1])) + 0.5) ) liveArea = ( bleedPixels[0], bleedPixels[1], image.size[0] - bleedPixels[0] - 1, image.size[1] - bleedPixels[1] - 1 ) liveSize = (liveArea[2] - liveArea[0], liveArea[3] - liveArea[1]) # calculate the aspect ratio of the liveArea liveAreaAspectRatio = float(liveSize[0])/float(liveSize[1]) # calculate the aspect ratio of the output image aspectRatio = float(size[0]) / float(size[1]) # figure out if the sides or top/bottom will be cropped off if liveAreaAspectRatio >= aspectRatio: # liveArea is wider than what's needed, crop the sides cropWidth = int((aspectRatio * float(liveSize[1])) + 0.5) cropHeight = liveSize[1] else: # liveArea is taller than what's needed, crop the top and bottom cropWidth = liveSize[0] cropHeight = int((float(liveSize[0])/aspectRatio) + 0.5) # make the crop leftSide = int(liveArea[0] + (float(liveSize[0]-cropWidth) * centering[0])) if leftSide < 0: leftSide = 0 topSide = int(liveArea[1] + (float(liveSize[1]-cropHeight) * centering[1])) if topSide < 0: topSide = 0 out = image.crop( (leftSide, topSide, leftSide + cropWidth, topSide + cropHeight) ) # resize the image and return it return out.resize(size, method) def flip(image): "Flip image vertically" return image.transpose(Image.FLIP_TOP_BOTTOM) def grayscale(image): "Convert to grayscale" return image.convert("L") def invert(image): "Invert image (negative)" lut = [] for i in range(256): lut.append(255-i) return _lut(image, lut) def mirror(image): "Flip image horizontally" return image.transpose(Image.FLIP_LEFT_RIGHT) def posterize(image, bits): "Reduce the number of bits per color channel" lut = [] mask = ~(2**(8-bits)-1) for i in range(256): lut.append(i & mask) return _lut(image, lut) def solarize(image, threshold=128): "Invert all values above threshold" lut = [] for i in range(256): if i < threshold: lut.append(i) else: lut.append(255-i) return _lut(image, lut) Imaging-1.1.3/PIL/ImagePalette.py0100444000076400007640000000552107442710203016275 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImagePalette.py#2 $ # # image palette object # # History: # 2025-03-11 fl Rewritten. # 2025-01-03 fl Up and running. # 2025-08-23 fl Added load hack # 2025-04-16 fl Fixed randint shadow bug in random() # # Copyright (c) 1997-2001 by Secret Labs AB # Copyright (c) 1996-1997 by Fredrik Lundh # # See the README file for information on usage and redistribution. # import array import Image class ImagePalette: "Colour palette for palette mapped images" def __init__(self, mode = "RGB", palette = None): self.mode = mode self.palette = palette or range(256)*len(self.mode) if len(self.mode)*256 != len(self.palette): raise ValueError, "wrong palette size" def tostring(self): return array.array("b", self.palette).tostring() def save(self, fp): if type(fp) == type(""): fp = open(fp, "w") fp.write("# Palette\n") fp.write("# Mode: %s\n" % self.mode) for i in range(256): fp.write("%d" % i) for j in range(i, len(self.palette), 256): fp.write(" %d" % self.palette[j]) fp.write("\n") fp.close() # -------------------------------------------------------------------- # Internal class raw: def __init__(self, rawmode, data): self.rawmode = rawmode self.data = data # -------------------------------------------------------------------- # Factories def new(mode, data): Image.core.new_palette(mode, data) def negative(mode = "RGB"): palette = range(256) palette.reverse() return ImagePalette(mode, palette * len(mode)) def random(mode = "RGB"): from random import randint palette = map(lambda a, randint=randint: randint(0, 255), [0]*256*len(mode)) return ImagePalette(mode, palette) def wedge(mode = "RGB"): return ImagePalette(mode, range(256) * len(mode)) def load(filename): # FIXME: supports GIMP gradients only fp = open(filename, "rb") lut = None if not lut: try: import GimpPaletteFile fp.seek(0) p = GimpPaletteFile.GimpPaletteFile(fp) lut = p.getpalette() except (SyntaxError, ValueError): pass if not lut: try: import GimpGradientFile fp.seek(0) p = GimpGradientFile.GimpGradientFile(fp) lut = p.getpalette() except (SyntaxError, ValueError): pass if not lut: try: import PaletteFile fp.seek(0) p = PaletteFile.PaletteFile(fp) lut = p.getpalette() except (SyntaxError, ValueError): pass if not lut: raise IOError, "cannot load palette" return lut # data, rawmode # add some psuedocolour palettes as well Imaging-1.1.3/PIL/ImagePath.py0100444000076400007640000000050107442710203015564 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/PIL/ImagePath.py#3 $ # # path interface # # History: # 96-11-04 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # import Image Path = Image.core.path Imaging-1.1.3/PIL/ImageSequence.py0100444000076400007640000000131707442710203016446 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageSequence.py#3 $ # # some sequence support stuff # # history: # 97-02-20 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # class Iterator: """Sequence iterator (use with the for-statement)""" def __init__(self, im): if not hasattr(im, "seek"): raise AttributeError, "im must have seek method" self.im = im def __getitem__(self, ix): try: if ix: self.im.seek(ix) return self.im except EOFError: raise IndexError # end of sequence Imaging-1.1.3/PIL/ImageStat.py0100444000076400007640000001022507442710203015607 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageStat.py#3 $ # # global statistics # # History: # 96-04-05 fl Created # 97-05-21 fl Added mask; added rms, var, stddev attributes # 97-08-05 fl Added median # 98-07-05 hk Fixed integer overflow error # # Notes: # This class shows how to implement delayed evaluation of # attributes. To get a certain value, simply access the # corresponding attribute. The __getattr__ dispatcher takes # care of the rest. # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996-97. # # See the README file for information on usage and redistribution. # import Image import operator, math class Stat: "Get image or feature statistics" def __init__(self, image_or_list, mask = None): try: if mask: self.h = image_or_list.histogram(mask) else: self.h = image_or_list.histogram() except AttributeError: self.h = image_or_list # assume it to be a histogram list if type(self.h) != type([]): raise TypeError, "first argument must be image or list" self.bands = range(len(self.h) / 256) def __getattr__(self, id): "Calculate missing attribute" if id[:4] == "_get": raise AttributeError, id # calculate missing attribute v = getattr(self, "_get" + id)() setattr(self, id, v) return v def _getextrema(self): "Get min/max values for each band in the image" def minmax(histogram): n = 255 x = 0 for i in range(256): if histogram[i]: n = min(n, i) x = max(x, i) return n, x # returns (255, 0) if there's no data in the histogram v = [] for i in range(0, len(self.h), 256): v.append(minmax(self.h[i:])) return v def _getcount(self): "Get total number of pixels in each layer" v = [] for i in range(0, len(self.h), 256): v.append(reduce(operator.add, self.h[i:i+256])) return v def _getsum(self): "Get sum of all pixels in each layer" v = [] for i in range(0, len(self.h), 256): sum = 0.0 for j in range(256): sum = sum + j * self.h[i+j] v.append(sum) return v def _getsum2(self): "Get squared sum of all pixels in each layer" v = [] for i in range(0, len(self.h), 256): sum2 = 0.0 for j in range(256): sum2 = sum2 + (j ** 2) * float(self.h[i+j]) v.append(sum2) return v def _getmean(self): "Get average pixel level for each layer" v = [] for i in self.bands: v.append(self.sum[i] / self.count[i]) return v def _getmedian(self): "Get median pixel level for each layer" v = [] for i in self.bands: s = 0 l = self.count[i]/2 b = i * 256 for j in range(256): s = s + self.h[b+j] if s > l: break v.append(j) return v def _getrms(self): "Get RMS for each layer" v = [] for i in self.bands: v.append(math.sqrt(self.sum2[i] / self.count[i])) return v def _getvar(self): "Get variance for each layer" v = [] for i in self.bands: n = self.count[i] v.append((self.sum2[i]-(self.sum[i]**2.0)/n)/n) return v def _getstddev(self): "Get standard deviation for each layer" v = [] for i in self.bands: v.append(math.sqrt(self.var[i])) return v Global = Stat # compatibility if __name__ == "__main__": im = Image.open("Images/lena.ppm") st = Stat(im) print "extrema", st.extrema print "sum ", st.sum print "mean ", st.mean print "median ", st.median print "rms ", st.rms print "sum2 ", st.sum2 print "var ", st.var print "stddev ", st.stddev Imaging-1.1.3/PIL/ImageTk.py0100444000076400007640000001366607442710203015266 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageTk.py#2 $ # # a Tk display interface # # History: # 96-04-08 fl Created # 96-09-06 fl Added getimage method # 96-11-01 fl Rewritten, removed image attribute and crop method # 97-05-09 fl Use PyImagingPaste method instead of image type # 97-05-12 fl Minor tweaks to match the IFUNC95 interface # 97-05-17 fl Support the "pilbitmap" booster patch # 97-06-05 fl Added file= and data= argument to image constructors # 98-03-09 fl Added width and height methods to Image classes # 98-07-02 fl Use default mode for "P" images without palette attribute # 98-07-02 fl Explicitly destroy Tkinter image objects # 99-07-24 fl Support multiple Tk interpreters (from Greg Couch) # 99-07-26 fl Automatically hook into Tkinter (if possible) # 99-08-15 fl Hook uses _imagingtk instead of _imaging # # Copyright (c) 1997-1999 by Secret Labs AB # Copyright (c) 1996-1997 by Fredrik Lundh # # See the README file for information on usage and redistribution. # import Tkinter, Image # -------------------------------------------------------------------- # Check for Tkinter interface hooks _pilbitmap_ok = None def _pilbitmap_check(): global _pilbitmap_ok if _pilbitmap_ok is None: try: im = Image.new("1", (1,1)) Tkinter.BitmapImage(data="PIL:%d" % im.im.id) _pilbitmap_ok = 1 except: _pilbitmap_ok = 0 return _pilbitmap_ok # -------------------------------------------------------------------- # PhotoImage class PhotoImage: def __init__(self, image=None, size=None, **kw): # Tk compatibility: file or data if image is None: if kw.has_key("file"): image = Image.open(kw["file"]) del kw["file"] elif kw.has_key("data"): from StringIO import StringIO image = Image.open(StringIO(kw["data"])) del kw["data"] if hasattr(image, "mode") and hasattr(image, "size"): # got an image instead of a mode mode = image.mode if mode == "P": # palette mapped data image.load() try: mode = image.palette.mode except AttributeError: mode = "RGB" # default size = image.size kw["width"], kw["height"] = size else: mode = image image = None if mode not in ["1", "L", "RGB", "RGBA"]: mode = Image.getmodebase(mode) self.__mode = mode self.__size = size self.__photo = apply(Tkinter.PhotoImage, (), kw) if image: self.paste(image) def __del__(self): name = self.__photo.name self.__photo.name = None try: self.__photo.tk.call("image", "delete", name) except: pass # ignore internal errors def __str__(self): return str(self.__photo) def width(self): return self.__size[0] def height(self): return self.__size[1] def paste(self, im, box = None): # convert to blittable im.load() image = im.im if image.isblock() and im.mode == self.__mode: block = image else: block = image.new_block(self.__mode, im.size) image.convert2(block, image) # convert directly between buffers tk = self.__photo.tk try: tk.call("PyImagingPhoto", self.__photo, block.id) except Tkinter.TclError, v: # activate Tkinter hook try: import _imagingtk try: _imagingtk.tkinit(tk.interpaddr(), 1) except AttributeError: _imagingtk.tkinit(id(tk), 0) tk.call("PyImagingPhoto", self.__photo, block.id) except (ImportError, AttributeError, Tkinter.TclError): raise # configuration problem; cannot attach to Tkinter # -------------------------------------------------------------------- # BitmapImage class BitmapImage: def __init__(self, image = None, **kw): # Tk compatibility: file or data if image is None: if kw.has_key("file"): image = Image.open(kw["file"]) del kw["file"] elif kw.has_key("data"): from StringIO import StringIO image = Image.open(StringIO(kw["data"])) del kw["data"] self.__mode = image.mode self.__size = image.size if _pilbitmap_check(): # fast way (requires the pilbitmap booster patch) image.load() kw["data"] = "PIL:%d" % image.im.id self.__im = image # must keep a reference else: # slow but safe way kw["data"] = image.tobitmap() self.__photo = apply(Tkinter.BitmapImage, (), kw) def __del__(self): name = self.__photo.name self.__photo.name = None try: self.__photo.tk.call("image", "delete", name) except: pass # ignore internal errors def width(self): return self.__size[0] def height(self): return self.__size[1] def __str__(self): return str(self.__photo) # -------------------------------------------------------------------- # Helper for the Image.show method. def _show(image, title): class UI(Tkinter.Label): def __init__(self, master, im): if im.mode == "1": self.image = BitmapImage(im, foreground="white", master=master) else: self.image = PhotoImage(im, master=master) Tkinter.Label.__init__(self, master, image=self.image, bg="black", bd=0) if not Tkinter._default_root: raise IOError, "tkinter not initialized" top = Tkinter.Toplevel() if title: top.title(title) UI(top, image).pack() Imaging-1.1.3/PIL/ImageWin.py0100444000076400007640000000273207442710203015435 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImageWin.py#3 $ # # a Windows DIB display interface # # History: # 96-05-20 fl Created # 96-09-20 fl Fixed subregion exposure # 97-09-21 fl Added draw primitive (for tzPrint) # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996-97. # # See the README file for information on usage and redistribution. # import Image # # Class wrapper for the Windows display buffer interface # # Create an object of this type, paste your data into it, and call # expose with an hDC casted to a Python int... In PythonWin, you # can use the GetHandleAttrib() method of the CDC class to get an # appropriate hDC. # class Dib: def __init__(self, mode, size): if mode not in ["1", "L", "P", "RGB"]: mode = "RGB" self.image = Image.core.display(mode, size) self.mode = mode self.size = size def expose(self, dc): return self.image.expose(dc) def draw(self, dc, dst, src = None): if not src: src = (0,0) + self.size return self.image.draw(dc, dst, src) def query_palette(self, dc): return self.image.query_palette(dc) def paste(self, im, box = None): # fix to handle conversion when pasting im.load() if self.mode != im.mode: im = im.convert(self.mode) if box: self.image.paste(im.im, box) else: self.image.paste(im.im) Imaging-1.1.3/PIL/ImImagePlugin.py0100444000076400007640000002177707442710203016436 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImImagePlugin.py#2 $ # # IFUNC IM file handling for PIL # # history: # 2025-09-01 fl Created. # 2025-01-03 fl Save palette images # 2025-01-08 fl Added sequence support # 2025-01-23 fl Added P and RGB save support # 2025-05-31 fl Read floating point images # 2025-06-22 fl Save floating point images # 2025-08-27 fl Read and save 1-bit images # 2025-06-25 fl Added support for RGB+LUT images # 2025-07-02 fl Added support for YCC images # 2025-07-15 fl Renamed offset attribute to avoid name clash # 2024-12-29 fl Added I;16 support # 2025-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.7) # # Copyright (c) Secret Labs AB 1997-2001. # Copyright (c) Fredrik Lundh 1995-2001. # # See the README file for information on usage and redistribution. # __version__ = "0.7" import re, string import Image, ImageFile, ImagePalette # -------------------------------------------------------------------- # Standard tags COMMENT = "Comment" DATE = "Date" EQUIPMENT = "Digitalization equipment" FRAMES = "File size (no of images)" LUT = "Lut" NAME = "Name" SCALE = "Scale (x,y)" SIZE = "Image size (x*y)" MODE = "Image type" TAGS = { COMMENT:0, DATE:0, EQUIPMENT:0, FRAMES:0, LUT:0, NAME:0, SCALE:0, SIZE:0, MODE:0 } OPEN = { # ifunc93/p3cfunc formats "0 1 image": ("1", "1"), "L 1 image": ("1", "1"), "Greyscale image": ("L", "L"), "Grayscale image": ("L", "L"), "RGB image": ("RGB", "RGB;L"), "RLB image": ("RGB", "RLB"), "RYB image": ("RGB", "RLB"), "B1 image": ("1", "1"), "B2 image": ("P", "P;2"), "B4 image": ("P", "P;4"), "X 24 image": ("RGB", "RGB"), "L 32 S image": ("I", "I;32"), "L 32 F image": ("F", "F;32"), # old p3cfunc formats "RGB3 image": ("RGB", "RGB;T"), "RYB3 image": ("RGB", "RYB;T"), # extensions "RGBA image": ("RGBA", "RGBA;L"), "RGBX image": ("RGBX", "RGBX;L"), "CMYK image": ("CMYK", "CMYK;L"), "YCC image": ("YCbCr", "YCbCr;L"), } # ifunc95 extensions for i in ["8", "8S", "16", "16S", "32", "32F"]: OPEN["L %s image" % i] = ("F", "F;%s" % i) OPEN["L*%s image" % i] = ("F", "F;%s" % i) for i in ["16", "16B"]: OPEN["L %s image" % i] = ("I;%s" % i, "I;%s" % i) OPEN["L*%s image" % i] = ("I;%s" % i, "I;%s" % i) for i in ["32S"]: OPEN["L %s image" % i] = ("I", "I;%s" % i) OPEN["L*%s image" % i] = ("I", "I;%s" % i) for i in range(2, 33): OPEN["L*%s image" % i] = ("F", "F;%s" % i) # -------------------------------------------------------------------- # Read IM directory split = re.compile(r"^([A-Za-z][^:]*):[ \t]*(.*)[ \t]*$") class ImImageFile(ImageFile.ImageFile): format = "IM" format_description = "IFUNC Image Memory" def _open(self): # Quick rejection: if there's not an LF among the first # 100 bytes, this is (probably) not a text header. if not "\n" in self.fp.read(100): raise SyntaxError, "not an IM file" self.fp.seek(0) n = 0 # Default values self.info[MODE] = "L" self.info[SIZE] = (512, 512) self.info[FRAMES] = 1 self.rawmode = "L" while 1: s = self.fp.read(1) # Some versions of IFUNC uses \n\r instead of \r\n... if s == "\r": continue if not s or s[0] == chr(0) or s[0] == chr(26): break # FIXME: this may read whole file if not a text file s = s + self.fp.readline() if len(s) > 100: raise SyntaxError, "not an IM file" if s[-2:] == '\r\n': s = s[:-2] elif s[-1:] == '\n': s = s[:-1] try: m = split.match(s) except re.error, v: raise SyntaxError, "not an IM file" if m: k, v = m.group(1,2) # Convert value as appropriate if k in [FRAMES, SCALE, SIZE]: i = string.find(v, "*") if i >= 0: v = v[:i] + "," + v[i+1:] v = eval(v) elif k == MODE and OPEN.has_key(v): v, self.rawmode = OPEN[v] # Add to dictionary. Note that COMMENT tags are # combined into a list of strings. if k == COMMENT: if self.info.has_key(k): self.info[k].append(v) else: self.info[k] = [v] else: self.info[k] = v if TAGS.has_key(k): n = n + 1 else: raise SyntaxError, "Syntax error in IM header: " + s if not n: raise SyntaxError, "Not an IM file" # Basic attributes self.size = self.info[SIZE] self.mode = self.info[MODE] # Skip forward to start of image data while s and s[0] != chr(26): s = self.fp.read(1) if not s: raise SyntaxError, "File truncated" if self.info.has_key(LUT): # convert lookup table to palette or lut attribute palette = self.fp.read(768) greyscale = 1 # greyscale palette linear = 1 # linear greyscale palette for i in range(256): if palette[i] == palette[i+256] == palette[i+512]: if palette[i] != chr(i): linear = 0 else: greyscale = 0 if self.mode == "L": if greyscale: if not linear: self.lut = map(ord, palette[:256]) else: self.mode = self.rawmode = "P" self.palette = ImagePalette.raw("RGB;L", palette) elif self.mode == "RGB": if not greyscale or not linear: self.lut = map(ord, palette) self.frame = 0 self.__offset = offs = self.fp.tell() self.__fp = self.fp # FIXME: hack if self.rawmode[:2] == "F;": # ifunc95 formats try: # use bit decoder (if necessary) bits = int(self.rawmode[2:]) if bits not in [8, 16, 32]: self.tile = [("bit", (0,0)+self.size, offs, (bits, 8, 3, 0, -1))] return except ValueError: pass if self.rawmode in ["RGB;T", "RYB;T"]: # Old LabEye/3PC files. Would be very surprised if anyone # ever stumbled upon such a file ;-) size = self.size[0] * self.size[1] self.tile = [("raw", (0,0)+self.size, offs, ("G", 0, -1)), ("raw", (0,0)+self.size, offs+size, ("R", 0, -1)), ("raw", (0,0)+self.size, offs+2*size, ("B", 0, -1))] else: # LabEye/IFUNC files self.tile = [("raw", (0,0)+self.size, offs, (self.rawmode, 0, -1))] def seek(self, frame): if frame < 0 or frame >= self.info[FRAMES]: raise EOFError, "seek outside sequence" if self.frame == frame: return self.frame = frame if self.mode == "1": bits = 1 else: bits = 8 * len(self.mode) size = ((self.size[0] * bits + 7) / 8) * self.size[1] offs = self.__offset + frame * size self.fp = self.__fp self.tile = [("raw", (0,0)+self.size, offs, (self.rawmode, 0, -1))] def tell(self): return self.frame # # -------------------------------------------------------------------- # Save IM files SAVE = { # mode: (im type, raw mode) "1": ("0 1", "1"), "L": ("Greyscale", "L"), "P": ("Greyscale", "P"), "I": ("L 32S", "I;32S"), "I;16": ("L 16", "I;16"), "I;16B": ("L 16B", "I;16B"), "F": ("L 32F", "F;32F"), "RGB": ("RGB", "RGB;L"), "RGBA": ("RGBA", "RGBA;L"), "RGBX": ("RGBX", "RGBX;L"), "CMYK": ("CMYK", "CMYK;L"), "YCbCr": ("YCC", "YCbCr;L") } def _save(im, fp, filename, check=0): try: type, rawmode = SAVE[im.mode] except KeyError: raise ValueError, "Cannot save %s images as IM" % im.mode try: frames = im.encoderinfo["frames"] except KeyError: frames = 1 if check: return check fp.write("Image type: %s image\r\n" % type) if filename: fp.write("Name: %s\r\n" % filename) fp.write("Image size (x*y): %d*%d\r\n" % im.size) fp.write("File size (no of images): %d\r\n" % frames) if im.mode == "P": fp.write("Lut: 1\r\n") fp.write("\000" * (511-fp.tell()) + "\032") if im.mode == "P": fp.write(im.im.getpalette("RGB", "RGB;L")) # 768 bytes ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, 0, -1))]) # # -------------------------------------------------------------------- # Registry Image.register_open("IM", ImImageFile) Image.register_save("IM", _save) Image.register_extension("IM", ".im") Imaging-1.1.3/PIL/ImtImagePlugin.py0100444000076400007640000000424307442710203016607 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/ImtImagePlugin.py#2 $ # # IM Tools support for PIL # # history: # 2025-05-27 fl Created (read 8-bit images only) # 2025-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.2) # # Copyright (c) Secret Labs AB 1997-2001. # Copyright (c) Fredrik Lundh 1996-2001. # # See the README file for information on usage and redistribution. # __version__ = "0.2" import string, re import Image, ImageFile # # -------------------------------------------------------------------- field = re.compile(r"([a-z]*) ([^ \r\n]*)") class ImtImageFile(ImageFile.ImageFile): format = "IMT" format_description = "IM Tools" def _open(self): # Quick rejection: if there's not a LF among the first # 100 bytes, this is (probably) not a text header. if not "\n" in self.fp.read(100): raise SyntaxError, "not an IM file" self.fp.seek(0) xsize = ysize = 0 while 1: s = self.fp.read(1) if not s: break if s == chr(12): # image data begins self.tile = [("raw", (0,0)+self.size, self.fp.tell(), (self.mode, 0, 1))] break else: # read key/value pair # FIXME: dangerous, may read whole file s = s + self.fp.readline() if len(s) == 1 or len(s) > 100: break if s[0] == "*": continue # comment m = field.match(s) if not m: break k, v = m.group(1,2) if k == "width": xsize = int(v) self.size = xsize, ysize elif k == "height": ysize = int(v) self.size = xsize, ysize elif k == "pixel" and v == "n8": self.mode = "L" # # -------------------------------------------------------------------- Image.register_open("IMT", ImtImageFile) # # no extension registered (".im" is simply too common) Imaging-1.1.3/PIL/IptcImagePlugin.py0100444000076400007640000001130507442710203016752 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/IptcImagePlugin.py#3 $ # # IPTC/NAA file handling # # history: # 95-10-01 fl Created # 98-03-09 fl Cleaned up and added to PIL # # Copyright (c) Secret Labs AB 1997-2000. # Copyright (c) Fredrik Lundh 1995. # # See the README file for information on usage and redistribution. # __version__ = "0.2" import Image, ImageFile import os, tempfile COMPRESSION = { 1: "raw", 5: "jpeg" } PAD = chr(0) * 4 # # Helpers def i16(c): return ord(c[1]) + (ord(c[0])<<8) def i32(c): return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24) def i(c): return i32((PAD + c)[-4:]) def dump(c): for i in c: print "%02x" % ord(i), print # # Parser class IptcImageFile(ImageFile.ImageFile): format = "IPTC" format_description = "IPTC/NAA" def getint(self, key): return i(self.info[key]) def field(self): # # get a IPTC field header s = self.fp.read(5) if not len(s): return None, 0 tag = ord(s[1]), ord(s[2]) # syntax if ord(s[0]) != 0x1C or tag[0] < 1 or tag[0] > 9: raise SyntaxError, "invalid IPTC/NAA file" # field size size = ord(s[3]) if size > 132: raise IOError, "illegal field length in IPTC/NAA file" elif size == 128: size = 0 elif size > 128: size = i(self.fp.read(size-128)) else: size = i16(s[3:]) return tag, size def _is_raw(self, offset, size): # # check if the file can be mapped # DISABLED: the following only slows things down... return 0 self.fp.seek(offset) t, sz = self.field() if sz != size[0]: return 0 y = 1 while 1: self.fp.seek(sz, 1) t, s = self.field() if t != (8, 10): break if s != sz: return 0 y = y + 1 return y == size[1] def _open(self): # load descriptive fields while 1: offset = self.fp.tell() tag, size = self.field() if not tag or tag == (8,10): break if size: self.info[tag] = self.fp.read(size) else: self.info[tag] = None # print tag, self.info[tag] # mode layers = ord(self.info[(3,60)][0]) component = ord(self.info[(3,60)][1]) if self.info.has_key((3,65)): id = ord(self.info[(3,65)][0])-1 else: id = 0 if layers == 1 and not component: self.mode = "L" elif layers == 3 and component: self.mode = "RGB"[id] elif layers == 4 and component: self.mode = "CMYK"[id] # size self.size = self.getint((3,20)), self.getint((3,30)) # compression try: compression = COMPRESSION[self.getint((3,120))] except KeyError: raise IOError, "Unknown IPTC image compression" # tile if tag == (8,10): if compression == "raw" and self._is_raw(offset, self.size): self.tile = [(compression, (offset, size + 5, -1), (0, 0, self.size[0], self.size[1]))] else: self.tile = [("iptc", (compression, offset), (0, 0, self.size[0], self.size[1]))] def load(self): if len(self.tile) != 1 or self.tile[0][0] != "iptc": return ImageFile.ImageFile.load(self) type, tile, box = self.tile[0] encoding, offset = tile self.fp.seek(offset) # Copy image data to temporary file outfile = tempfile.mktemp() o = open(outfile, "wb") if encoding == "raw": # To simplify access to the extracted file, # prepend a PPM header o.write("P5\n%d %d\n255\n" % self.size) while 1: type, size = self.field() if type != (8, 10): break while size > 0: s = self.fp.read(min(size, 8192)) if not s: break o.write(s) size = size - len(s) o.close() try: try: # fast self.im = Image.core.open_ppm(outfile) except: # slightly slower im = Image.open(outfile) im.load() self.im = im.im finally: try: os.unlink(outfile) except: pass Image.register_open("IPTC", IptcImageFile) Image.register_extension("IPTC", ".iim") Imaging-1.1.3/PIL/JpegImagePlugin.py0100444000076400007640000002571007442710203016745 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/JpegImagePlugin.py#2 $ # # JPEG (JFIF) file handling # # See "Digital Compression and Coding of Continous-Tone Still Images, # Part 1, Requirements and Guidelines" (CCITT T.81 / ISO 10918-1) # # History: # 2025-09-09 fl Created # 2025-09-13 fl Added full parser # 2025-03-25 fl Added hack to use the IJG command line utilities # 2025-05-05 fl Workaround Photoshop 2.5 CMYK polarity bug # 2025-05-28 fl Added draft support, JFIF version (0.1) # 2024-12-30 fl Added encoder options, added progression property (0.2) # 2025-08-27 fl Save mode 1 images as BW (0.3) # 2025-07-12 fl Added YCbCr to draft and save methods (0.4) # 2025-10-19 fl Don't hang on files using 16-bit DQT's (0.4.1) # 2025-04-16 fl Extract DPI settings from JFIF files (0.4.2) # # Copyright (c) 1997-2001 by Secret Labs AB. # Copyright (c) 1995-1996 by Fredrik Lundh. # # See the README file for information on usage and redistribution. # __version__ = "0.4.2" import array, string import Image, ImageFile def i16(c,o=0): return ord(c[o+1]) + (ord(c[o])<<8) def i32(c,o=0): return ord(c[o+3]) + (ord(c[o+2])<<8) + (ord(c[o+1])<<16) + (ord(c[o])<<24) # # Parser def Skip(self, marker): self.fp.read(i16(self.fp.read(2))-2) def APP(self, marker): # # Application marker. Store these in the APP dictionary. # Also look for well-known application markers. s = self.fp.read(i16(self.fp.read(2))-2) self.app["APP%d" % (marker&15)] = s if marker == 0xFFE0 and s[:4] == "JFIF": self.info["jfif"] = version = i16(s, 5) # version self.info["jfif_version"] = divmod(version, 256) # extract JFIF properties try: jfif_unit = ord(s[7]) jfif_density = i16(s, 8), i16(s, 10) except: pass else: if jfif_unit == 1: self.info["dpi"] = jfif_density self.info["jfif_unit"] = jfif_unit self.info["jfif_density"] = jfif_density elif marker == 0xFFEE and s[:5] == "Adobe": self.info["adobe"] = i16(s, 5) # extract Adobe custom properties try: adobe_transform = ord(s[1]) except: pass else: self.info["adobe_transform"] = adobe_transform def SOF(self, marker): # # Start of frame marker. Defines the size and mode of the # image. JPEG is colour blind, so we use some simple # heuristics to map the number of layers to an appropriate # mode. Note that this could be made a bit brighter, by # looking for JFIF and Adobe APP markers. s = self.fp.read(i16(self.fp.read(2))-2) self.size = i16(s[3:]), i16(s[1:]) self.bits = ord(s[0]) if self.bits != 8: raise SyntaxError, "cannot handle %d-bit layers" % self.bits self.layers = ord(s[5]) if self.layers == 1: self.mode = "L" elif self.layers == 3: self.mode = "RGB" elif self.layers == 4: self.mode = "CMYK" else: raise SyntaxError, "cannot handle %d-layer images" % self.layers if marker in [0xFFC2, 0xFFC6, 0xFFCA, 0xFFCE]: self.info["progression"] = 1 for i in range(6, len(s), 3): t = s[i:i+3] # 4-tuples: id, vsamp, hsamp, qtable self.layer.append((t[0], ord(t[1])/16, ord(t[1])&15, ord(t[2]))) def DQT(self, marker): # # Define quantization table. Support baseline 8-bit tables # only. Note that there might be more than one table in # each marker. # FIXME: The quantization tables can be used to estimate the # compression quality. s = self.fp.read(i16(self.fp.read(2))-2) while len(s): if len(s) < 65: raise SyntaxError, "bad quantization table marker" v = ord(s[0]) if v/16 == 0: self.quantization[v&15] = array.array("b", s[1:65]) s = s[65:] else: return # FIXME: add code to read 16-bit tables! # raise SyntaxError, "bad quantization table element size" # # JPEG marker table MARKER = { 0xFFC0: ("SOF0", "Baseline DCT", SOF), 0xFFC1: ("SOF1", "Extended Sequential DCT", SOF), 0xFFC2: ("SOF2", "Progressive DCT", SOF), 0xFFC3: ("SOF3", "Spatial lossless", SOF), 0xFFC4: ("DHT", "Define Huffman table", Skip), 0xFFC5: ("SOF5", "Differential sequential DCT", SOF), 0xFFC6: ("SOF6", "Differential progressive DCT", SOF), 0xFFC7: ("SOF7", "Differential spatial", SOF), 0xFFC8: ("JPG", "Extension", None), 0xFFC9: ("SOF9", "Extended sequential DCT (AC)", SOF), 0xFFCA: ("SOF10", "Progressive DCT (AC)", SOF), 0xFFCB: ("SOF11", "Spatial lossless DCT (AC)", SOF), 0xFFCC: ("DAC", "Define arithmetic coding conditioning", Skip), 0xFFCD: ("SOF13", "Differential sequential DCT (AC)", SOF), 0xFFCE: ("SOF14", "Differential progressive DCT (AC)", SOF), 0xFFCF: ("SOF15", "Differential spatial (AC)", SOF), 0xFFD0: ("RST0", "Restart 0", None), 0xFFD1: ("RST1", "Restart 1", None), 0xFFD2: ("RST2", "Restart 2", None), 0xFFD3: ("RST3", "Restart 3", None), 0xFFD4: ("RST4", "Restart 4", None), 0xFFD5: ("RST5", "Restart 5", None), 0xFFD6: ("RST6", "Restart 6", None), 0xFFD7: ("RST7", "Restart 7", None), 0xFFD8: ("SOI", "Start of image", None), 0xFFD9: ("EOI", "End of image", None), 0xFFDA: ("SOS", "Start of scan", Skip), 0xFFDB: ("DQT", "Define quantization table", DQT), 0xFFDC: ("DNL", "Define number of lines", Skip), 0xFFDD: ("DRI", "Define restart interval", Skip), 0xFFDE: ("DHP", "Define hierarchical progression", SOF), 0xFFDF: ("EXP", "Expand reference component", Skip), 0xFFE0: ("APP0", "Application segment 0", APP), 0xFFE1: ("APP1", "Application segment 1", APP), 0xFFE2: ("APP2", "Application segment 2", APP), 0xFFE3: ("APP3", "Application segment 3", APP), 0xFFE4: ("APP4", "Application segment 4", APP), 0xFFE5: ("APP5", "Application segment 5", APP), 0xFFE6: ("APP6", "Application segment 6", APP), 0xFFE7: ("APP7", "Application segment 7", APP), 0xFFE8: ("APP8", "Application segment 8", APP), 0xFFE9: ("APP9", "Application segment 9", APP), 0xFFEA: ("APP10", "Application segment 10", APP), 0xFFEB: ("APP11", "Application segment 11", APP), 0xFFEC: ("APP12", "Application segment 12", APP), 0xFFED: ("APP13", "Application segment 13", APP), 0xFFEE: ("APP14", "Application segment 14", APP), 0xFFEF: ("APP15", "Application segment 15", APP), 0xFFF0: ("JPG0", "Extension 0", None), 0xFFF1: ("JPG1", "Extension 1", None), 0xFFF2: ("JPG2", "Extension 2", None), 0xFFF3: ("JPG3", "Extension 3", None), 0xFFF4: ("JPG4", "Extension 4", None), 0xFFF5: ("JPG5", "Extension 5", None), 0xFFF6: ("JPG6", "Extension 6", None), 0xFFF7: ("JPG7", "Extension 7", None), 0xFFF8: ("JPG8", "Extension 8", None), 0xFFF9: ("JPG9", "Extension 9", None), 0xFFFA: ("JPG10", "Extension 10", None), 0xFFFB: ("JPG11", "Extension 11", None), 0xFFFC: ("JPG12", "Extension 12", None), 0xFFFD: ("JPG13", "Extension 13", None), 0xFFFE: ("COM", "Comment", Skip) } def _accept(prefix): return prefix[0] == "\377" class JpegImageFile(ImageFile.ImageFile): format = "JPEG" format_description = "JPEG (ISO 10918)" def _open(self): s = self.fp.read(1) if ord(s[0]) != 255: raise SyntaxError, "not an JPEG file" # Create attributes self.bits = self.layers = 0 # JPEG specifics (internal) self.layer = [] self.huffman_dc = {} self.huffman_ac = {} self.quantization = {} self.app = {} while 1: s = s + self.fp.read(1) i = i16(s) if MARKER.has_key(i): name, description, handler = MARKER[i] # print hex(i), name, description if handler is not None: handler(self, i) if i == 0xFFDA: # start of scan rawmode = self.mode if self.mode == "CMYK" and self.info.has_key("adobe"): rawmode = "CMYK;I" # Photoshop 2.5 is broken! self.tile = [("jpeg", (0,0) + self.size, 0, (rawmode, ""))] # self.__offset = self.fp.tell() break s = self.fp.read(1) else: raise SyntaxError, "no marker found" def draft(self, mode, size): if len(self.tile) != 1: return d, e, o, a = self.tile[0] scale = 0 if a[0] == "RGB" and mode in ["L", "YCbCr"]: self.mode = mode a = mode, "" if size: scale = max(self.size[0] / size[0], self.size[1] / size[1]) for s in [8, 4, 2, 1]: if scale >= s: break e = e[0], e[1], (e[2]-e[0]+s-1)/s+e[0], (e[3]-e[1]+s-1)/s+e[1] self.size = ((self.size[0]+s-1)/s, (self.size[1]+s-1)/s) scale = s self.tile = [(d, e, o, a)] self.decoderconfig = (scale, 1) return self def load_djpeg(self): # ALTERNATIVE: handle JPEGs via the IJG command line utilities import tempfile, os file = tempfile.mktemp() os.system("djpeg %s >%s" % (self.filename, file)) try: self.im = Image.core.open_ppm(file) finally: try: os.unlink(file) except: pass self.mode = self.im.mode self.size = self.im.size self.tile = [] def _fetch(dict, key, default = 0): try: return dict[key] except KeyError: return default RAWMODE = { "1": "L", "L": "L", "RGB": "RGB", "RGBA": "RGB", "RGBX": "RGB", "CMYK": "CMYK", "YCbCr": "YCbCr", } def _save(im, fp, filename): try: rawmode = RAWMODE[im.mode] except KeyError: raise IOError, "cannot write mode %s as JPEG" % im.mode dpi = _fetch(im.encoderinfo, "dpi", (0, 0)) # get keyword arguments im.encoderconfig = (_fetch(im.encoderinfo, "quality", 0), im.encoderinfo.has_key("progressive"), _fetch(im.encoderinfo, "smooth", 0), im.encoderinfo.has_key("optimize"), _fetch(im.encoderinfo, "streamtype", 0), dpi[0], dpi[1]) 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") Imaging-1.1.3/PIL/McIdasImagePlugin.py0100444000076400007640000000323707442710203017220 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/McIdasImagePlugin.py#2 $ # # Basic McIdas support for PIL # # History: # 97-05-05 fl Created (8-bit images only) # # Thanks to Richard Jones for specs # and samples. # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import string import Image, ImageFile def i16(c,i=0): return ord(c[1+i])+(ord(c[i])<<8) def i32(c,i=0): return ord(c[3+i])+(ord(c[2+i])<<8)+(ord(c[1+i])<<16)+(ord(c[i])<<24) def _accept(s): return i32(s) == 0 and i32(s, 4) == 4 class McIdasImageFile(ImageFile.ImageFile): format = "MCIDAS" format_description = "McIdas area file" def _open(self): # parse area file directory s = self.fp.read(256) if not _accept(s): raise SyntaxError, "not an McIdas area file" # get mode if i32(s, 40) != 1 or i32(s, 52) != 1: raise SyntaxError, "unsupported McIdas format" self.mode = "L" # get size self.size = i32(s, 36), i32(s, 32) # setup image descriptor prefix = i32(s, 56) offset = i32(s, 132) self.tile = [("raw", (0, 0) + self.size, offset, ("L", prefix + self.size[0], 1))] # FIXME: should store the navigation and calibration blocks # somewhere (or perhaps extract some basic information from # them...) # -------------------------------------------------------------------- # registry Image.register_open("MCIDAS", McIdasImageFile, _accept) # no default extension Imaging-1.1.3/PIL/MicImagePlugin.py0100444000076400007640000000415007442710203016563 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/MicImagePlugin.py#3 $ # # Microsoft Image Composer support for PIL # # Notes: # uses TiffImagePlugin.py to read the actual image streams # # History: # 97-01-20 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import string import Image, TiffImagePlugin from OleFileIO import * # # -------------------------------------------------------------------- def _accept(prefix): return prefix[:8] == MAGIC class MicImageFile(TiffImagePlugin.TiffImageFile): format = "MIC" format_description = "Microsoft Image Composer" def _open(self): # read the OLE directory and see if this is a likely # to be a Microsoft Image Composer file try: self.ole = OleFileIO(self.fp) except IOError: raise SyntaxError, "not an MIC file; invalid OLE file" # find ACI subfiles with Image members (maybe not the # best way to identify MIC files, but what the... ;-) self.images = [] for file in self.ole.listdir(): if file[1:] and file[0][-4:] == ".ACI" and file[1] == "Image": self.images.append(file) # if we didn't find any images, this is probably not # an MIC file. if not self.images: raise SyntaxError, "not an MIC file; no image entries" self.__fp = self.fp self.frame = 0 if len(self.images) > 1: self.category = Image.CONTAINER self.seek(0) def seek(self, frame): try: filename = self.images[frame] except IndexError: raise EOFError, "no such frame" self.fp = self.ole.openstream(filename) TiffImagePlugin.TiffImageFile._open(self) self.frame = frame def tell(self): return self.frame # # -------------------------------------------------------------------- Image.register_open("MIC", MicImageFile, _accept) Image.register_extension("MIC", ".mic") Imaging-1.1.3/PIL/MpegImagePlugin.py0100444000076400007640000000334607442710203016751 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/MpegImagePlugin.py#3 $ # # MPEG file handling # # History: # 95-09-09 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1995. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import array, string import Image, ImageFile # # Bitstream parser class BitStream: def __init__(self, fp): self.fp = fp self.bits = 0 self.bitbuffer = 0 def next(self): return ord(self.fp.read(1)) def peek(self, bits): while self.bits < bits: c = self.next() if c < 0: self.bits = 0 continue self.bitbuffer = (self.bitbuffer << 8) + c self.bits = self.bits + 8 return self.bitbuffer >> (self.bits - bits) & (1 << bits) - 1 def skip(self, bits): while self.bits < bits: self.bitbuffer = (self.bitbuffer << 8) + ord(self.fp.read(1)) self.bits = self.bits + 8 self.bits = self.bits - bits def read(self, bits): v = self.peek(bits) self.bits = self.bits - bits return v 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") Imaging-1.1.3/PIL/MspImagePlugin.py0100444000076400007640000000414407442710203016615 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/MspImagePlugin.py#3 $ # # MSP file handling # # This is the format used by the Paint program in Windows 1 and 2. # # History: # 95-09-05 fl Created # 97-01-03 fl Read/write MSP images # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1995-97. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import Image, ImageFile # # read MSP files def i16(c): return ord(c[0]) + (ord(c[1])<<8) def _accept(prefix): return prefix[:4] in ["DanM", "LinS"] class MspImageFile(ImageFile.ImageFile): format = "MSP" format_description = "Windows Paint" def _open(self): # Header s = self.fp.read(32) if s[:4] not in ["DanM", "LinS"]: raise SyntaxError, "not an MSP file" # Header checksum sum = 0 for i in range(0, 32, 2): sum = sum ^ i16(s[i:i+2]) if sum != 0: raise SyntaxError, "bad MSP checksum" self.mode = "1" self.size = i16(s[4:]), i16(s[6:]) if s[:4] == "DanM": self.tile = [("raw", (0,0)+self.size, 32, ("1", 0, 1))] else: self.tile = [("msp", (0,0)+self.size, 32+2*self.size[1], None)] # # write MSP files (uncompressed only) def o16(i): return chr(i&255) + chr(i>>8&255) def _save(im, fp, filename): if im.mode != "1": raise IOError, "cannot write mode %s as MSP" % im.mode # create MSP header header = [0] * 16 header[0], header[1] = i16("Da"), i16("nM") # version 1 header[2], header[3] = im.size header[4], header[5] = 1, 1 header[6], header[7] = 1, 1 header[8], header[9] = im.size sum = 0 for h in header: sum = sum ^ h header[12] = sum # FIXME: is this the right field? # header for h in header: fp.write(o16(h)) # image body ImageFile._save(im, fp, [("raw", (0,0)+im.size, 32, ("1", 0, 1))]) # # registry Image.register_open("MSP", MspImageFile, _accept) Image.register_save("MSP", _save) Image.register_extension("MSP", ".msp") Imaging-1.1.3/PIL/OleFileIO.py0100444000076400007640000003615707442710203015514 0ustar fredrikfredrik# # THIS IS WORK IN PROGRESS # # The Python Imaging Library # $Id: //modules/pil/PIL/OleFileIO.py#3 $ # # stuff to deal with OLE2 Structured Storage files. this module is # used by PIL to read Image Composer and FlashPix files, but can also # be used to read other files of this type. # # History: # 97-01-20 fl Created # 97-01-22 fl Fixed 64-bit portability quirk # # Notes: # FIXME: change filename to use "a/b/c" instead of ["a", "b", "c"] # FIXME: provide a glob mechanism function (using fnmatchcase) # # Literature: # # "FlashPix Format Specification, Appendix A", Kodak and Microsoft, # September 1996. # # Quotes: # # "If this document and functionality of the Software conflict, # the actual functionality of the Software represents the correct # functionality" -- Microsoft, in the OLE format specification # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # import string, StringIO def i16(c, o = 0): return ord(c[o])+(ord(c[o+1])<<8) def i32(c, o = 0): return ord(c[o])+(ord(c[o+1])<<8)+(ord(c[o+2])<<16)+(ord(c[o+3])<<24) MAGIC = '\320\317\021\340\241\261\032\341' # # -------------------------------------------------------------------- # property types VT_EMPTY=0; VT_NULL=1; VT_I2=2; VT_I4=3; VT_R4=4; VT_R8=5; VT_CY=6; VT_DATE=7; VT_BSTR=8; VT_DISPATCH=9; VT_ERROR=10; VT_BOOL=11; VT_VARIANT=12; VT_UNKNOWN=13; VT_DECIMAL=14; VT_I1=16; VT_UI1=17; VT_UI2=18; VT_UI4=19; VT_I8=20; VT_UI8=21; VT_INT=22; VT_UINT=23; VT_VOID=24; VT_HRESULT=25; VT_PTR=26; VT_SAFEARRAY=27; VT_CARRAY=28; VT_USERDEFINED=29; VT_LPSTR=30; VT_LPWSTR=31; VT_FILETIME=64; VT_BLOB=65; VT_STREAM=66; VT_STORAGE=67; VT_STREAMED_OBJECT=68; VT_STORED_OBJECT=69; VT_BLOB_OBJECT=70; VT_CF=71; VT_CLSID=72; VT_VECTOR=0x1000; # map property id to name (for debugging purposes) VT = {} for k, v in vars().items(): if k[:3] == "VT_": VT[v] = k # # -------------------------------------------------------------------- # Some common document types (root.clsid fields) WORD_CLSID = "00020900-0000-0000-C000-000000000046" # # -------------------------------------------------------------------- class _OleStream(StringIO.StringIO): """OLE2 Stream Returns a read-only file object which can be used to read the contents of a OLE stream. To open a stream, use the openstream method in the OleFile class. This function can be used with either ordinary streams, or ministreams, depending on the offset, sectorsize, and fat table arguments. """ # FIXME: should store the list of sects obtained by following # the fat chain, and load new sectors on demand instead of # loading it all in one go. def __init__(self, fp, sect, size, offset, sectorsize, fat): data = [] while sect != 0xFFFFFFFE: fp.seek(offset + sectorsize * sect) data.append(fp.read(sectorsize)) sect = fat[sect] data = string.join(data, "") # print len(data), size StringIO.StringIO.__init__(self, data[:size]) # # -------------------------------------------------------------------- # FIXME: should add a counter in here to avoid looping forever # if the tree is broken. class _OleDirectoryEntry: """OLE2 Directory Entry Encapsulates a stream directory entry. Note that the constructor builds a tree of all subentries, so we only have to call it with the root object. """ def __init__(self, sidlist, sid): # store directory parameters. the caller provides # a complete list of directory entries, as read from # the directory stream. name, type, sect, size, sids, clsid = sidlist[sid] self.sid = sid self.name = name self.type = type # 1=storage 2=stream self.sect = sect self.size = size self.clsid = clsid # process child nodes, if any self.kids = [] sid = sidlist[sid][4][2] if sid != -1: # the directory entries are organized as a red-black tree. # the following piece of code does an ordered traversal of # such a tree (at least that's what I hope ;-) stack = [self.sid] # start at leftmost position left, right, child = sidlist[sid][4] while left != 0xFFFFFFFF: stack.append(sid) sid = left left, right, child = sidlist[sid][4] while sid != self.sid: self.kids.append(_OleDirectoryEntry(sidlist, sid)) # try to move right left, right, child = sidlist[sid][4] if right != 0xFFFFFFFF: # and then back to the left sid = right while 1: left, right, child = sidlist[sid][4] if left == 0xFFFFFFFF: break stack.append(sid) sid = left else: # couldn't move right; move up instead while 1: ptr = stack[-1] del stack[-1] left, right, child = sidlist[ptr][4] if right != sid: break sid = right left, right, child = sidlist[sid][4] if right != ptr: sid = ptr # in the OLE file, entries are sorted on (length, name). # for convenience, we sort them on name instead. self.kids.sort() def __cmp__(self, other): "Compare entries by name" return cmp(self.name, other.name) def dump(self, tab = 0): "Dump this entry, and all its subentries (for debug purposes only)" TYPES = ["(invalid)", "(storage)", "(stream)", "(lockbytes)", "(property)", "(root)"] print " "*tab + repr(self.name), TYPES[self.type], if self.type in (2, 5): print self.size, "bytes", print if self.type in (1, 5) and self.clsid: print " "*tab + "{%s}" % self.clsid for kid in self.kids: kid.dump(tab + 2) # # -------------------------------------------------------------------- class OleFileIO: """OLE container object This class encapsulates the interface to an OLE 2 structured storage file. Use the listdir and openstream methods to access the contents of this file. Object names are given as a list of strings, one for each subentry level. The root entry should be omitted. For example, the following code extracts all image streams from a Microsoft Image Composer file: ole = OleFileIO("fan.mic") for entry in ole.listdir(): if entry[1:2] == "Image": fin = ole.openstream(entry) fout = open(entry[0:1], "wb") while 1: s = fin.read(8192) if not s: break fout.write(s) You can use the viewer application provided with the Python Imaging Library to view the resulting files (which happens to be standard TIFF files). """ def __init__(self, filename = None): if filename: self.open(filename) def open(self, filename): """Connect to a OLE2 file""" if type(filename) == type(""): self.fp = open(filename, "rb") else: self.fp = filename header = self.fp.read(512) if len(header) != 512 or header[:8] != MAGIC: raise IOError, "not an OLE2 structured storage file" # file clsid (probably never used, so we don't store it) clsid = self._clsid(header[8:24]) # FIXME: could check version and byte order fields self.sectorsize = 1 << i16(header, 30) self.minisectorsize = 1 << i16(header, 32) self.minisectorcutoff = i32(header, 56) # Load file allocation tables self.loadfat(header) # Load direcory. This sets both the sidlist (ordered by id) # and the root (ordered by hierarchy) members. self.loaddirectory(i32(header, 48)) self.ministream = None self.minifatsect = i32(header, 60) def loadfat(self, header): # Load the FAT table. The header contains a sector numbers # for the first 109 FAT sectors. Additional sectors are # described by DIF blocks (FIXME: not yet implemented) sect = header[76:512] fat = [] for i in range(0, len(sect), 4): ix = i32(sect, i) if ix in [0xFFFFFFFE, 0xFFFFFFFF]: break s = self.getsect(ix) fat = fat + map(lambda i, s=s: i32(s, i), range(0, len(s), 4)) self.fat = fat def loadminifat(self): # Load the MINIFAT table. This is stored in a standard sub- # stream, pointed to by a header field. s = self._open(self.minifatsect).read() self.minifat = map(lambda i, s=s: i32(s, i), range(0, len(s), 4)) def getsect(self, sect): # Read given sector self.fp.seek(512 + self.sectorsize * sect) return self.fp.read(self.sectorsize) def _unicode(self, s): # Map unicode string to Latin 1 # FIXME: some day, Python will provide an official way to handle # Unicode strings, but until then, this will have to do... return filter(ord, s) def loaddirectory(self, sect): # Load the directory. The directory is stored in a standard # substream, independent of its size. # read directory stream fp = self._open(sect) # create list of sid entries self.sidlist = [] while 1: entry = fp.read(128) if not entry: break type = ord(entry[66]) name = self._unicode(entry[0:0+i16(entry, 64)]) ptrs = i32(entry, 68), i32(entry, 72), i32(entry, 76) sect, size = i32(entry, 116), i32(entry, 120) clsid = self._clsid(entry[80:96]) self.sidlist.append((name, type, sect, size, ptrs, clsid)) # create hierarchical list of directory entries self.root = _OleDirectoryEntry(self.sidlist, 0) def dumpdirectory(self): # Dump directory (for debugging only) self.root.dump() def _clsid(self, clsid): if clsid == "\0" * len(clsid): return "" return (("%08X-%04X-%04X-%02X%02X-" + "%02X" * 6) % ((i32(clsid, 0), i16(clsid, 4), i16(clsid, 6)) + tuple(map(ord, clsid[8:16])))) def _list(self, files, prefix, node): # listdir helper prefix = prefix + [node.name] for entry in node.kids: if entry.kids: self._list(files, prefix, entry) else: files.append(prefix[1:] + [entry.name]) def _find(self, filename): # openstream helper node = self.root for name in filename: for kid in node.kids: if kid.name == name: break else: raise IOError, "file not found" node = kid return node.sid def _open(self, start, size = 0x7FFFFFFF): # openstream helper. if size < self.minisectorcutoff: # ministream object if not self.ministream: self.loadminifat() self.ministream = self._open(self.sidlist[0][2]) return _OleStream(self.ministream, start, size, 0, self.minisectorsize, self.minifat) # standard stream return _OleStream(self.fp, start, size, 512, self.sectorsize, self.fat) # # public interface def listdir(self): """Return a list of streams stored in this file""" files = [] self._list(files, [], self.root) return files def openstream(self, filename): """Open a stream as a read-only file object""" slot = self._find(filename) name, type, sect, size, sids, clsid = self.sidlist[slot] if type != 2: raise IOError, "this file is not a stream" return self._open(sect, size) def getproperties(self, filename): """Return properties described in substream""" fp = self.openstream(filename) data = {} # header s = fp.read(28) clsid = self._clsid(s[8:24]) # format id s = fp.read(20) fmtid = self._clsid(s[:16]) fp.seek(i32(s, 16)) # get section s = "****" + fp.read(i32(fp.read(4))-4) for i in range(i32(s, 4)): id = i32(s, 8+i*8) offset = i32(s, 12+i*8) type = i32(s, offset) # test for common types first (should perhaps use # a dictionary instead?) if type == VT_I2: value = i16(s, offset+4) if value >= 32768: value = value - 65536 elif type == VT_UI2: value = i16(s, offset+4) elif type in (VT_I4, VT_ERROR): value = i32(s, offset+4) elif type == VT_UI4: value = i32(s, offset+4) # FIXME elif type in (VT_BSTR, VT_LPSTR): count = i32(s, offset+4) value = s[offset+8:offset+8+count-1] elif type == VT_BLOB: count = i32(s, offset+4) value = s[offset+8:offset+8+count] elif type == VT_LPWSTR: count = i32(s, offset+4) value = self._unicode(s[offset+8:offset+8+count*2]) elif type == VT_FILETIME: value = long(i32(s, offset+4)) + (long(i32(s, offset+8))<<32) # FIXME: this is a 64-bit int: "number of 100ns periods # since Jan 1,2025". Should map this to Python time value = value / 10000000L # seconds elif type == VT_UI1: value = ord(s[offset+4]) elif type == VT_CLSID: value = self._clsid(s[offset+4:offset+20]) elif type == VT_CF: count = i32(s, offset+4) value = s[offset+8:offset+8+count] else: value = None # everything else yields "None" # FIXME: add support for VT_VECTOR #print "%08x" % id, repr(value), #print "(%s)" % VT[i32(s, offset) & 0xFFF] data[id] = value return data # # -------------------------------------------------------------------- # This script can be used to dump the directory of any OLE2 structured # storage file. if __name__ == "__main__": import sys for file in sys.argv[1:]: try: ole = OleFileIO(file) print "-" * 68 print file print "-" * 68 ole.dumpdirectory() for file in ole.listdir(): if file[-1][0] == "\005": print file ole.getproperties(file) except IOError: pass Imaging-1.1.3/PIL/PaletteFile.py0100444000076400007640000000203307442710203016125 0ustar fredrikfredrik# # Python Imaging Library # $Id: //modules/pil/PIL/PaletteFile.py#3 $ # # stuff to read simple, teragon-style palette files # # History: # 97-08-23 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # import string class PaletteFile: rawmode = "RGB" def __init__(self, fp): self.palette = map(lambda i: (i, i, i), range(256)) while 1: s = fp.readline() if not s: break if len(s) > 100: raise SyntaxError, "bad palette file" v = map(string.atoi, string.split(s)) try: [i, r, g, b] = v except ValueError: [i, r] = v g = b = r if 0 <= i <= 255: self.palette[i] = chr(r) + chr(g) + chr(b) self.palette = string.join(self.palette, "") def getpalette(self): return self.palette, self.rawmode Imaging-1.1.3/PIL/PcdImagePlugin.py0100444000076400007640000000317007442710203016562 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/PcdImagePlugin.py#3 $ # # PCD file handling # # History: # 96-05-10 fl Created # 96-05-27 fl Added draft mode (128x192, 256x384) # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import Image, ImageFile class PcdImageFile(ImageFile.ImageFile): format = "PCD" format_description = "Kodak PhotoCD" def _open(self): # rough self.fp.seek(2048) s = self.fp.read(2048) if s[:4] != "PCD_": raise SyntaxError, "not a PCD file" orientation = ord(s[1538]) & 3 if orientation == 1: self.tile_post_rotate = 90 # hack elif orientation == 3: self.tile_post_rotate = -90 self.mode = "RGB" self.size = 768, 512 # FIXME: not correct for rotated images! self.tile = [("pcd", (0,0)+self.size, 96*2048, None)] def draft(self, mode, size): if len(self.tile) != 1: return d, e, o, a = self.tile[0] if size: scale = max(self.size[0] / size[0], self.size[1] / size[1]) for s, o in [(4,0*2048), (2,0*2048), (1,96*2048)]: if scale >= s: break # e = e[0], e[1], (e[2]-e[0]+s-1)/s+e[0], (e[3]-e[1]+s-1)/s+e[1] # self.size = ((self.size[0]+s-1)/s, (self.size[1]+s-1)/s) self.tile = [(d, e, o, a)] return self # # registry Image.register_open("PCD", PcdImageFile) Image.register_extension("PCD", ".pcd") Imaging-1.1.3/PIL/PcfFontFile.py0100444000076400007640000001364407442710203016100 0ustar fredrikfredrik# # THIS IS WORK IN PROGRESS # # The Python Imaging Library # $Id: //modules/pil/PIL/PcfFontFile.py#3 $ # # portable compiled font file parser # # history: # 97-08-19 fl created # # Copyright (c) Secret Labs AB 1997-98. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # import Image import FontFile import string # -------------------------------------------------------------------- # declarations PCF_MAGIC = 0x70636601 PCF_PROPERTIES = (1<<0) PCF_ACCELERATORS = (1<<1) PCF_METRICS = (1<<2) PCF_BITMAPS = (1<<3) PCF_INK_METRICS = (1<<4) PCF_BDF_ENCODINGS = (1<<5) PCF_SWIDTHS = (1<<6) PCF_GLYPH_NAMES = (1<<7) PCF_BDF_ACCELERATORS = (1<<8) BYTES_PER_ROW = [ lambda bits: ((bits+7) >> 3), lambda bits: ((bits+15) >> 3) & ~1, lambda bits: ((bits+31) >> 3) & ~3, lambda bits: ((bits+63) >> 3) & ~7, ] def l16(c): return ord(c[0]) + (ord(c[1])<<8) def l32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) def b16(c): return ord(c[1]) + (ord(c[0])<<8) def b32(c): return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24) def sz(s, o): return s[o:string.index(s, "\0", o)] # -------------------------------------------------------------------- # parser class PcfFontFile(FontFile.FontFile): name = "name" def __init__(self, fp): magic = l32(fp.read(4)) if magic != PCF_MAGIC: raise SyntaxError, "not a PCF file" FontFile.FontFile.__init__(self) count = l32(fp.read(4)) self.toc = {} for i in range(count): type = l32(fp.read(4)) self.toc[type] = l32(fp.read(4)), l32(fp.read(4)), l32(fp.read(4)) self.fp = fp self.info = self._load_properties() metrics = self._load_metrics() bitmaps = self._load_bitmaps(metrics) encoding = self._load_encoding() # # create glyph structure for ch in range(256): ix = encoding[ch] if ix is not None: x, y, l, r, w, a, d, f = metrics[ix] self.glyph[ch] = (w, 0), (l, d-y, x+l, d), (0, 0, x, y), bitmaps[ix] def _getformat(self, tag): format, size, offset = self.toc[tag] fp = self.fp fp.seek(offset) format = l32(fp.read(4)) if format & 4: i16, i32 = b16, b32 else: i16, i32 = l16, l32 return fp, format, i16, i32 def _load_properties(self): # # font properties properties = {} fp, format, i16, i32 = self._getformat(PCF_PROPERTIES) nprops = i32(fp.read(4)) # read property description p = [] for i in range(nprops): p.append((i32(fp.read(4)), ord(fp.read(1)), i32(fp.read(4)))) if nprops & 3: fp.seek(4 - (nprops & 3), 1) # pad data = fp.read(i32(fp.read(4))) for k, s, v in p: k = sz(data, k) if s: v = sz(data, v) properties[k] = v return properties def _load_metrics(self): # # font metrics metrics = [] fp, format, i16, i32 = self._getformat(PCF_METRICS) append = metrics.append if (format & 0xff00) == 0x100: # "compressed" metrics for i in range(i16(fp.read(2))): left = ord(fp.read(1)) - 128 right = ord(fp.read(1)) - 128 width = ord(fp.read(1)) - 128 ascent = ord(fp.read(1)) - 128 descent = ord(fp.read(1)) - 128 xsize = right - left ysize = ascent + descent append( (xsize, ysize, left, right, width, ascent, descent, 0) ) else: # "jumbo" metrics for i in range(i32(fp.read(4))): left = i16(fp.read(2)) right = i16(fp.read(2)) width = i16(fp.read(2)) ascent = i16(fp.read(2)) descent = i16(fp.read(2)) attributes = i16(fp.read(2)) append( (xsize, ysize, left, right, width, ascent, descent, attributes) ) return metrics def _load_bitmaps(self, metrics): # # bitmap data bitmaps = [] fp, format, i16, i32 = self._getformat(PCF_BITMAPS) nbitmaps = i32(fp.read(4)) if nbitmaps != len(metrics): raise IOError, "Wrong number of bitmaps" offsets = [] for i in range(nbitmaps): offsets.append(i32(fp.read(4))) bitmapSizes = [] for i in range(4): bitmapSizes.append(i32(fp.read(4))) byteorder = format & 4 # non-zero => MSB bitorder = format & 8 # non-zero => MSB padindex = format & 3 bitmapsize = bitmapSizes[padindex] offsets.append(bitmapsize) data = fp.read(bitmapsize) pad = BYTES_PER_ROW[padindex] mode = "1;R" if bitorder: mode = "1" for i in range(nbitmaps): x, y, l, r, w, a, d, f = metrics[i] b, e = offsets[i], offsets[i+1] im = Image.fromstring("1", (x, y), data[b:e], "raw", mode, pad(x)) bitmaps.append(im) return bitmaps def _load_encoding(self): encoding = [None] * 256 fp, format, i16, i32 = self._getformat(PCF_BDF_ENCODINGS) firstCol, lastCol = i16(fp.read(2)), i16(fp.read(2)) firstRow, lastRow = i16(fp.read(2)), i16(fp.read(2)) default = i16(fp.read(2)) nencoding = (lastCol - firstCol + 1) * (lastRow - firstRow + 1) for i in range(nencoding): encodingOffset = i16(fp.read(2)) if encodingOffset != 0xFFFF: encoding[i+firstCol] = encodingOffset return encoding Imaging-1.1.3/PIL/PcxImagePlugin.py0100444000076400007640000001034007442710203016603 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/PcxImagePlugin.py#3 $ # # PCX file handling # # This format was originally used by ZSoft's popular PaintBrush # program for the IBM PC. It is also supported by many MS-DOS and # Windows applications, including the Windows PaintBrush program in # Windows 3. # # history: # 95-09-01 fl Created # 96-05-20 fl Fixed RGB support # 97-01-03 fl Fixed 2-bit and 4-bit support # 99-02-03 fl Fixed 8-bit support (broken in 1.0b1) # 99-02-07 fl Added write support # # Copyright (c) Secret Labs AB 1997-98. # Copyright (c) Fredrik Lundh 1995-97. # # See the README file for information on usage and redistribution. # __version__ = "0.4" import Image, ImageFile, ImagePalette def i16(c): return ord(c[0]) + (ord(c[1])<<8) def _accept(prefix): return ord(prefix[0]) == 10 and ord(prefix[1]) in [0, 2, 3, 5] class PcxImageFile(ImageFile.ImageFile): format = "PCX" format_description = "Paintbrush" def _open(self): # header s = self.fp.read(128) if not _accept(s): raise SyntaxError, "not a PCX file" # image bbox = i16(s[4:]), i16(s[6:]), i16(s[8:])+1, i16(s[10:])+1 if bbox[2] <= bbox[0] or bbox[3] <= bbox[1]: raise SyntaxError, "bad PCX image size" # format version = ord(s[1]) bits = ord(s[3]) planes = ord(s[65]) stride = i16(s[66:]) if bits == 1 and planes == 1: mode = rawmode = "1" elif bits == 1 and planes in (2, 4): mode = "P" rawmode = "P;%dL" % planes self.palette = ImagePalette.raw("RGB", s[16:64]) elif version == 5 and bits == 8 and planes == 1: mode = rawmode = "L" # FIXME: hey, this doesn't work with the incremental loader !!! self.fp.seek(-769, 2) s = self.fp.read(769) if len(s) == 769 and ord(s[0]) == 12: # check if the palette is linear greyscale for i in range(256): if s[i*3+1:i*3+4] != chr(i)*3: mode = rawmode = "P" break if mode == "P": self.palette = ImagePalette.raw("RGB", s[1:]) elif version == 5 and bits == 8 and planes == 3: mode = "RGB" rawmode = "RGB;L" else: raise IOError, "unknown PCX mode" self.mode = mode self.size = bbox[2]-bbox[0], bbox[3]-bbox[1] self.tile = [("pcx", bbox, 128, rawmode)] # -------------------------------------------------------------------- # save PCX files SAVE = { # mode: (version, bits, planes, raw mode) "1": (2, 1, 1, "1"), "L": (5, 8, 1, "L"), "P": (5, 8, 1, "P"), "RGB": (5, 8, 3, "RGB;L"), } def o16(i): return chr(i&255) + chr(i>>8&255) def _save(im, fp, filename, check=0): try: version, bits, planes, rawmode = SAVE[im.mode] except KeyError: raise ValueError, "Cannot save %s images as PCX" % im.mode if check: return check # bytes per plane stride = (im.size[0] * bits + 7) / 8 # under windows, we could determine the current screen size with # "Image.core.display_mode()[1]", but I think that's overkill... screen = im.size dpi = 100, 100 # PCX header fp.write( chr(10) + chr(version) + chr(1) + chr(bits) + o16(0) + o16(0) + o16(im.size[0]-1) + o16(im.size[1]-1) + o16(dpi[0]) + o16(dpi[1]) + chr(0)*24 + chr(255)*24 + chr(0) + chr(planes) + o16(stride) + o16(1) + o16(screen[0]) + o16(screen[1]) + chr(0)*54 ) assert fp.tell() == 128 ImageFile._save(im, fp, [("pcx", (0,0)+im.size, 0, (rawmode, bits*planes))]) if im.mode == "P": # colour palette fp.write(chr(12)) fp.write(im.im.getpalette("RGB", "RGB")) # 768 bytes elif im.mode == "L": # greyscale palette fp.write(chr(12)) for i in range(256): fp.write(chr(i)*3) # -------------------------------------------------------------------- # registry Image.register_open("PCX", PcxImageFile, _accept) Image.register_save("PCX", _save) Image.register_extension("PCX", ".pcx") Imaging-1.1.3/PIL/PdfImagePlugin.py0100444000076400007640000001042007442710203016561 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/PdfImagePlugin.py#3 $ # # PDF (Acrobat) file handling # # History: # 96-07-16 fl Created # 97-01-18 fl Fixed header # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996-97. # # See the README file for information on usage and redistribution. # __version__ = "0.2" import Image, ImageFile import StringIO # # -------------------------------------------------------------------- # object ids: # 1. catalogue # 2. pages # 3. image # 4. page # 5. page contents def _obj(fp, obj, **dict): fp.write("%d 0 obj\n" % obj) if dict: fp.write("<<\n") for k, v in dict.items(): if v is not None: fp.write("/%s %s\n" % (k, v)) fp.write(">>\n") def _endobj(fp): fp.write("endobj\n") def _save(im, fp, filename): # # make sure image data is available im.load() xref = [0]*(5+1) # placeholders fp.write("%PDF-1.2\n") fp.write("% created by PIL PDF driver " + __version__ + "\n") # # Get image characteristics width, height = im.size # FIXME: Should replace ASCIIHexDecode with RunLengthDecode (packbits) # or LZWDecode (tiff/lzw compression). Note that PDF 1.2 also supports # Flatedecode (zip compression). params = None if im.mode == "1": filter = "/ASCIIHexDecode" config = "/DeviceGray", "/ImageB", 1 elif im.mode == "L": filter = "/DctDecode" # params = "<< /Predictor 15 /Columns %d >>" % (width-2) config = "/DeviceGray", "/ImageB", 8 elif im.mode == "P": filter = "/ASCIIHexDecode" config = "/Indexed", "/ImageI", 8 elif im.mode == "RGB": filter = "/DCTDecode" config = "/DeviceRGB", "/ImageC", 8 elif im.mode == "CMYK": filter = "/DCTDecode" config = "/DeviceRGB", "/ImageC", 8 else: raise ValueError, "illegal mode" colorspace, proc, bits = config # # catalogue xref[1] = fp.tell() _obj(fp, 1, Type = "/Catalog", Pages = "2 0 R") _endobj(fp) # # pages xref[2] = fp.tell() _obj(fp, 2, Type = "/Pages", Count = 1, Kids = "[4 0 R]") _endobj(fp) # # image op = StringIO.StringIO() if filter == "/ASCIIHexDecode": ImageFile._save(im, op, [("hex", (0,0)+im.size, 0, None)]) elif filter == "/DCTDecode": ImageFile._save(im, op, [("jpeg", (0,0)+im.size, 0, im.mode)]) elif filter == "/FlateDecode": ImageFile._save(im, op, [("zip", (0,0)+im.size, 0, im.mode)]) elif filter == "/RunLengthDecode": ImageFile._save(im, op, [("packbits", (0,0)+im.size, 0, im.mode)]) else: raise ValueError, "unsupported PDF filter" xref[3] = fp.tell() _obj(fp, 3, Type = "/XObject", Subtype = "/Image", Width = width, Height = height, Length = len(op.getvalue()), Filter = filter, BitsPerComponent = bits, DecodeParams = params, ColorSpace = colorspace) fp.write("stream\n") fp.write(op.getvalue()) fp.write("\nendstream\n") _endobj(fp) # # page xref[4] = fp.tell() fp.write("4 0 obj\n<<\n/Type /Page\n/Parent 2 0 R\n"\ "/Resources <<\n/ProcSet [ /PDF %s ]\n"\ "/XObject << /image 3 0 R >>\n>>\n"\ "/MediaBox [ 0 0 %d %d ]\n/Contents 5 0 R\n>>\n" %\ (proc, width, height)) # # page contents op = StringIO.StringIO() op.write("q %d 0 0 %d 0 0 cm /image Do Q\n" % (width, height)) xref[5] = fp.tell() _obj(fp, 5, Length = len(op.getvalue())) fp.write("stream\n") fp.write(op.getvalue()) _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") Imaging-1.1.3/PIL/PixarImagePlugin.py0100444000076400007640000000334207442710203017140 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/PixarImagePlugin.py#3 $ # # PIXAR raster support for PIL # # history: # 97-01-29 fl Created # # notes: # This is incomplete; it is based on a few samples created with # Photoshop 2.5 and 3.0, and a summary description provided by # Greg Coats . Hopefully, "L" and # "RGBA" support will be added in future versions. # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import Image, ImageFile # # helpers def i16(c): return ord(c[0]) + (ord(c[1])<<8) def i32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) # # -------------------------------------------------------------------- class PixarImageFile(ImageFile.ImageFile): format = "PIXAR" format_description = "PIXAR raster image" def _open(self): # assuming a 4-byte magic label (FIXME: add "_accept" hook) s = self.fp.read(4) if s != "\200\350\000\000": raise SyntaxError, "not a PIXAR file" # read rest of header s = s + self.fp.read(508) self.size = i16(s[418:420]), i16(s[416:418]) # get channel/depth descriptions mode = i16(s[424:426]), i16(s[426:428]) if mode == (14, 2): self.mode = "RGB" # FIXME: to be continued... # create tile descriptor (assuming "dumped") self.tile = [("raw", (0,0)+self.size, 1024, (self.mode, 0, 1))] # # -------------------------------------------------------------------- Image.register_open("PIXAR", PixarImageFile) # # FIXME: what's the standard extension? Imaging-1.1.3/PIL/PngImagePlugin.py0100444000076400007640000003014207442710203016577 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/PngImagePlugin.py#2 $ # # PNG support code # # See "PNG (Portable Network Graphics) Specification, version 1.0; # W3C Recommendation", 1996-10-01, Thomas Boutell (ed.). # # history: # 2025-05-06 fl Created (couldn't resist it) # 2025-12-14 fl Upgraded, added read and verify support (0.2) # 2025-12-15 fl Separate PNG stream parser # 2024-12-29 fl Added write support, added getchunks # 2024-12-30 fl Eliminated circular references in decoder (0.3) # 2025-07-12 fl Read/write 16-bit images as mode I (0.4) # 2025-02-08 fl Added transparency support (from Zircon) (0.5) # 2025-04-16 fl Don't close data source in "open" method (0.6) # # Copyright (c) 1997-2001 by Secret Labs AB # Copyright (c) 1996 by Fredrik Lundh # # See the README file for information on usage and redistribution. # __version__ = "0.6" import string import Image, ImageFile, ImagePalette def i16(c): return ord(c[1]) + (ord(c[0])<<8) def i32(c): return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24) _MAGIC = "\211PNG\r\n\032\n" _MODES = { # supported bits/color combinations, and corresponding modes/rawmodes (1, 0): ("1", "1"), (2, 0): ("L", "L;2"), (4, 0): ("L", "L;4"), (8, 0): ("L", "L"), (16,0): ("I", "I;16B"), (8, 2): ("RGB", "RGB"), (16,2): ("RGB", "RGB;16B"), (1, 3): ("P", "P;1"), (2, 3): ("P", "P;2"), (4, 3): ("P", "P;4"), (8, 3): ("P", "P"), (8, 4): ("RGBA", "LA"), (16,4): ("RGBA", "LA;16B"), (8, 6): ("RGBA", "RGBA"), (16,6): ("RGBA", "RGBA;16B"), } # -------------------------------------------------------------------- # Support classes. Suitable for PNG and related formats like MNG etc. class ChunkStream: def __init__(self, fp): self.fp = fp self.queue = [] if not hasattr(Image.core, "crc32"): self.crc = self.crc_skip def read(self): "Fetch a new chunk. Returns header information." if self.queue: cid, pos, len = self.queue[-1] del self.queue[-1] self.fp.seek(pos) else: s = self.fp.read(8) cid = s[4:] pos = self.fp.tell() len = i32(s) return cid, pos, len def close(self): self.queue = self.crc = self.fp = None def push(self, cid, pos, len): self.queue.append((cid, pos, len)) def call(self, cid, pos, len): "Call the appropriate chunk handler" if Image.DEBUG: print "STREAM", cid, pos, len return getattr(self, "chunk_" + cid)(pos, len) def crc(self, cid, data): "Read and verify checksum" crc1 = Image.core.crc32(data, Image.core.crc32(cid)) crc2 = i16(self.fp.read(2)), i16(self.fp.read(2)) if crc1 != crc2: raise SyntaxError, "broken PNG file"\ "(bad header checksum in %s)" % cid def crc_skip(self, cid, data): "Read checksum. Used if the C module is not present" self.fp.read(4) def verify(self, endchunk = "IEND"): # Simple approach; just calculate checksum for all remaining # blocks. Must be called directly after open. cids = [] while 1: cid, pos, len = self.read() if cid == endchunk: break self.crc(cid, self.fp.read(len)) cids.append(cid) return cids # -------------------------------------------------------------------- # PNG image stream (IHDR/IEND) class PngStream(ChunkStream): def __init__(self, fp): ChunkStream.__init__(self, fp) # local copies of Image attributes self.im_info = {} self.im_size = (0,0) self.im_mode = None self.im_tile = None self.im_palette = None def chunk_IHDR(self, pos, len): # image header s = self.fp.read(len) self.im_size = i32(s), i32(s[4:]) try: self.im_mode, self.im_rawmode = _MODES[(ord(s[8]), ord(s[9]))] except: pass if ord(s[12]): self.im_info["interlace"] = 1 if ord(s[11]): raise SyntaxError, "unknown filter category" return s def chunk_IDAT(self, pos, len): # image data self.im_tile = [("zip", (0,0)+self.im_size, pos, self.im_rawmode)] self.im_idat = len raise EOFError def chunk_IEND(self, pos, len): # end of PNG image raise EOFError def chunk_PLTE(self, pos, len): # palette s = self.fp.read(len) if self.im_mode == "P": self.im_palette = "RGB", s return s def chunk_tRNS(self, pos, len): # transparency s = self.fp.read(len) if self.im_mode == "P": i = string.find(s, chr(0)) if i >= 0: self.im_info["transparency"] = i elif self.im_mode == "L": self.im_info["transparency"] = i16(s) return s def chunk_gAMA(self, pos, len): # gamma setting s = self.fp.read(len) self.im_info["gamma"] = i32(s) / 100000.0 return s def chunk_tEXt(self, pos, len): # text s = self.fp.read(len) [k, v] = string.split(s, "\0") self.im_info[k] = v return s # -------------------------------------------------------------------- # PNG reader def _accept(prefix): return prefix[:8] == _MAGIC class PngImageFile(ImageFile.ImageFile): format = "PNG" format_description = "Portable network graphics" def _open(self): if self.fp.read(8) != _MAGIC: raise SyntaxError, "not a PNG file" # # Parse headers up to the first IDAT chunk self.png = PngStream(self.fp) while 1: # # get next chunk cid, pos, len = self.png.read() try: s = self.png.call(cid, pos, len) except EOFError: break except AttributeError: if Image.DEBUG: print cid, pos, len, "(unknown)" s = self.fp.read(len) self.png.crc(cid, s) # # Copy relevant attributes from the PngStream. An alternative # would be to let the PngStream class modify these attributes # directly, but that introduces circular references which are # difficult to break if things go wrong in the decoder... # (believe me, I've tried ;-) self.mode = self.png.im_mode self.size = self.png.im_size self.info = self.png.im_info self.tile = self.png.im_tile if self.png.im_palette: rawmode, data = self.png.im_palette self.palette = ImagePalette.raw(rawmode, data) self.__idat = len # used by load_read() def verify(self): "Verify PNG file" # back up to beginning of IDAT block self.fp.seek(self.tile[0][2] - 8) self.png.verify() self.png.close() self.fp = None def load_read(self, bytes): "internal: read more image data" while self.__idat == 0: # end of chunk, skip forward to next one self.fp.read(4) # CRC cid, pos, len = self.png.read() if cid not in ["IDAT", "DDAT"]: self.png.push(cid, pos, len) return "" self.__idat = len # empty chunks are allowed # read more data from this chunk if bytes <= 0: bytes = self.__idat else: bytes = min(bytes, self.__idat) self.__idat = self.__idat - bytes return self.fp.read(bytes) def load_end(self): "internal: finished reading image data" self.png.close() self.png = None # -------------------------------------------------------------------- # PNG writer def o16(i): return chr(i>>8&255) + chr(i&255) def o32(i): return chr(i>>24&255) + chr(i>>16&255) + chr(i>>8&255) + chr(i&255) _OUTMODES = { # supported bits/color combinations, and corresponding modes/rawmodes "1": ("1", chr(1)+chr(0)), "L;1": ("L;1", chr(1)+chr(0)), "L;2": ("L;2", chr(2)+chr(0)), "L;4": ("L;4", chr(4)+chr(0)), "L": ("L", chr(8)+chr(0)), "I": ("I;16B", chr(16)+chr(0)), "P;1": ("P;1", chr(1)+chr(3)), "P;2": ("P;2", chr(2)+chr(3)), "P;4": ("P;4", chr(4)+chr(3)), "P": ("P", chr(8)+chr(3)), "RGB": ("RGB", chr(8)+chr(2)), "RGBA":("RGBA", chr(8)+chr(6)), } def putchunk(fp, cid, *data): "Write a PNG chunk (including CRC field)" data = string.join(data, "") fp.write(o32(len(data)) + cid) fp.write(data) hi, lo = Image.core.crc32(data, Image.core.crc32(cid)) fp.write(o16(hi) + o16(lo)) class _idat: # wrap output from the encoder in IDAT chunks def __init__(self, fp, chunk): self.fp = fp self.chunk = chunk def write(self, data): self.chunk(self.fp, "IDAT", data) def _save(im, fp, filename, chunk=putchunk, check=0): # save an image to disk (called by the save method) mode = im.mode if mode == "P": # # attempt to minimize storage requirements for palette images if im.encoderinfo.has_key("bits"): # number of bits specified by user n = 1 << im.encoderinfo["bits"] else: # check palette contents n = 256 # FIXME if n <= 2: bits = 1 elif n <= 4: bits = 2 elif n <= 16: bits = 4 else: bits = 8 if bits != 8: mode = "%s;%d" % (mode, bits) # encoder options if im.encoderinfo.has_key("dictionary"): dictionary = im.encoderinfo["dictionary"] else: dictionary = "" im.encoderconfig = (im.encoderinfo.has_key("optimize"), dictionary) # get the corresponding PNG mode try: rawmode, mode = _OUTMODES[mode] except KeyError: raise IOError, "cannot write mode %s as PNG" % mode if check: return check # # write minimal PNG file fp.write(_MAGIC) chunk(fp, "IHDR", o32(im.size[0]), o32(im.size[1]), # 0: size mode, # 8: depth/type chr(0), # 10: compression chr(0), # 11: filter category chr(0)) # 12: interlace flag if im.mode == "P": chunk(fp, "PLTE", im.im.getpalette("RGB")) if im.encoderinfo.has_key("transparency"): if im.mode == "P": transparency = max(0, min(255, im.encoderinfo["transparency"])) chunk(fp, "tRNS", chr(255) * transparency + chr(0)) elif im.mode == "L": transparency = max(0, min(65535, im.encoderinfo["transparency"])) chunk(fp, "tRNS", o16(transparency)) else: raise IOError, "cannot use transparency for this mode" if 0: # FIXME: to be supported some day chunk(fp, "gAMA", o32(int(gamma * 100000.0))) ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)]) chunk(fp, "IEND", "") try: fp.flush() except: pass # -------------------------------------------------------------------- # PNG chunk converter def getchunks(im, **params): """Return a list of PNG chunks representing this image.""" class collector: data = [] def write(self, data): pass 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") Imaging-1.1.3/PIL/PpmImagePlugin.py0100444000076400007640000000621507442710203016613 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/PpmImagePlugin.py#2 $ # # PPM support for PIL # # History: # 96-03-24 fl Created # 98-03-06 fl Write RGBA images (as RGB, that is) # # Copyright (c) Secret Labs AB 1997-98. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # __version__ = "0.2" import string import Image, ImageFile # # -------------------------------------------------------------------- MODES = { # standard "P4": "1", "P5": "L", "P6": "RGB", # extensions "P0CMYK": "CMYK", # PIL extensions (for test purposes only) "PyP": "P", "PyRGBA": "RGBA", "PyCMYK": "CMYK" } def _accept(prefix): return prefix[0] == "P" and prefix[1] in "0456y" class PpmImageFile(ImageFile.ImageFile): format = "PPM" format_description = "Pbmplus image" def _token(self, s = ""): while 1: # read until next whitespace c = self.fp.read(1) if not c or c in string.whitespace: break s = s + c return s def _open(self): # check magic s = self.fp.read(1) if s != "P": raise SyntaxError, "not a PPM file" mode = MODES[self._token(s)] if mode == "1": self.mode = "1" rawmode = "1;I" else: self.mode = rawmode = mode for ix in range(3): while 1: while 1: s = self.fp.read(1) if s not in string.whitespace: break if s != "#": break s = self.fp.readline() s = int(self._token(s)) if ix == 0: xsize = s elif ix == 1: ysize = s if mode == "1": break self.size = xsize, ysize self.tile = [("raw", (0, 0, xsize, ysize), self.fp.tell(), (rawmode, 0, 1))] # ALTERNATIVE: load via builtin debug function # self.im = Image.core.open_ppm(self.filename) # self.mode = self.im.mode # self.size = self.im.size # # -------------------------------------------------------------------- def _save(im, fp, filename): if im.mode == "1": rawmode, head = "1;I", "P4" elif im.mode == "L": rawmode, head = "L", "P5" elif im.mode == "RGB": rawmode, head = "RGB", "P6" elif im.mode == "RGBA": rawmode, head = "RGB", "P6" else: raise IOError, "cannot write mode %s as PPM" % im.mode fp.write(head + "\n%d %d\n" % im.size) if head != "P4": fp.write("255\n") ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, 0, 1))]) # ALTERNATIVE: save via builtin debug function # im._dump(filename) # # -------------------------------------------------------------------- Image.register_open("PPM", PpmImageFile, _accept) Image.register_save("PPM", _save) Image.register_extension("PPM", ".pbm") Image.register_extension("PPM", ".pgm") Image.register_extension("PPM", ".ppm") Imaging-1.1.3/PIL/PsdImagePlugin.py0100444000076400007640000001465107442710203016610 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/PIL/PsdImagePlugin.py#5 $ # # Adobe PSD 2.5/3.0 file handling # # History: # 2025-09-01 fl Created # 2025-01-03 fl Read most PSD images # 2025-01-18 fl Fixed P and CMYK support # 2025-10-21 fl Added seek/tell support (for layers) # # Copyright (c) 1997-2001 by Secret Labs AB. # Copyright (c) 1995-2001 by Fredrik Lundh # # See the README file for information on usage and redistribution. # __version__ = "0.4" import string import Image, ImageFile, ImagePalette MODES = { # (photoshop mode, bits) -> (pil mode, required channels) (0, 1): ("1", 1), (0, 8): ("L", 1), (1, 8): ("L", 1), (2, 8): ("P", 1), (3, 8): ("RGB", 3), (4, 8): ("CMYK", 4), (7, 8): ("L", 1), # FIXME: multilayer (8, 8): ("L", 1), # duotone (9, 8): ("LAB", 3) } # # helpers def i16(c): return ord(c[1]) + (ord(c[0])<<8) def i32(c): return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24) # --------------------------------------------------------------------. # read PSD images def _accept(prefix): return prefix[:4] == "8BPS" class PsdImageFile(ImageFile.ImageFile): format = "PSD" format_description = "Adobe Photoshop" def _open(self): read = self.fp.read # # header s = read(26) if s[:4] != "8BPS" or i16(s[4:]) != 1: raise SyntaxError, "not a PSD file" psd_bits = i16(s[22:]) psd_channels = i16(s[12:]) psd_mode = i16(s[24:]) mode, channels = MODES[(psd_mode, psd_bits)] if channels > psd_channels: raise IOError, "not enough channels" self.mode = mode self.size = i32(s[18:]), i32(s[14:]) # # color mode data size = i32(read(4)) if size: data = read(size) if mode == "P" and size == 768: self.palette = ImagePalette.raw("RGB;L", data) # # image resources self.resources = [] size = i32(read(4)) if size: # load resources end = self.fp.tell() + size while self.fp.tell() < end: signature = read(4) id = i16(read(2)) name = read(ord(read(1))) if not (len(name) & 1): read(1) # padding data = read(i32(read(4))) if (len(data) & 1): read(1) # padding self.resources.append((id, name, data)) # # layer and mask information self.layers = [] size = i32(read(4)) if size: end = self.fp.tell() + size size = i32(read(4)) if size: self.layers = _layerinfo(self.fp) self.fp.seek(end) # # image descriptor self.tile = _maketile(self.fp, mode, (0, 0) + self.size, channels) # keep the file open self._fp = self.fp self.frame = 0 def seek(self, layer): # seek to given layer (1..max) if layer == self.frame: return try: if layer <= 0: raise IndexError name, mode, bbox, tile = self.layers[layer-1] self.mode = mode self.tile = tile self.frame = layer self.fp = self._fp return name, bbox except IndexError: raise EOFError, "no such layer" def tell(self): # return layer number (0=image, 1..max=layers) return self.frame def load_prepare(self): # create image memory if necessary if not self.im or\ self.im.mode != self.mode or self.im.size != self.size: self.im = Image.core.fill(self.mode, self.size, 0) # create palette (optional) if self.mode == "P": Image.Image.load(self) def _layerinfo(file): # read layerinfo block layers = [] read = file.read for i in range(abs(i16(read(2)))): # bounding box y0 = i32(read(4)); x0 = i32(read(4)) y1 = i32(read(4)); x1 = i32(read(4)) # image info info = [] mode = [] for i in range(i16(read(2))): type = i16(read(2)) if type == 65535: m = "A" else: m = "RGB"[type] mode.append(m) size = i32(read(4)) info.append((m, size)) # figure out the image mode mode.sort() if mode == ["R"]: mode = "L" elif mode == ["B", "G", "R"]: mode = "RGB" elif mode == ["A", "B", "G", "R"]: mode = "RGBA" else: mode = None # unknown # skip over blend flags and extra information filler = read(12) name = None # FIXME file.seek(i32(read(4)), 1) layers.append((name, mode, (x0, y0, x1, y1))) # get tiles i = 0 for name, mode, bbox in layers: tile = [] for m in mode: t = _maketile(file, m, bbox, 1) if t: tile.extend(t) layers[i] = name, mode, bbox, tile i = i + 1 return layers def _maketile(file, mode, bbox, channels): tile = None read = file.read compression = i16(read(2)) xsize = bbox[2] - bbox[0] ysize = bbox[3] - bbox[1] offset = file.tell() if compression == 0: # # raw compression tile = [] for channel in range(channels): layer = mode[channel] if mode == "CMYK": layer = layer + ";I" tile.append(("raw", bbox, offset, layer)) offset = offset + xsize*ysize elif compression == 1: # # packbits compression i = 0 tile = [] bytecount = read(channels * ysize * 2) offset = file.tell() for channel in range(channels): layer = mode[channel] if mode == "CMYK": layer = layer + ";I" tile.append( ("packbits", bbox, offset, layer) ) for y in range(ysize): offset = offset + i16(bytecount[i:i+2]) i = i + 2 file.seek(offset) if offset & 1: read(1) # padding return tile # -------------------------------------------------------------------- # registry Image.register_open("PSD", PsdImageFile, _accept) Image.register_extension("PSD", ".psd") Imaging-1.1.3/PIL/PSDraw.py0100444000076400007640000001274307442710203015100 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/PIL/PSDraw.py#3 $ # # simple postscript graphics interface # # History: # 96-04-20 fl Created # 99-01-10 fl Added gsave/grestore to image method # # Copyright (c) Secret Labs AB 1997-99. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # import EpsImagePlugin import string class PSDraw: def __init__(self, fp = None): if not fp: import sys fp = sys.stdout self.fp = fp def begin_document(self, id = None): "Write Postscript DSC header" # FIXME: incomplete self.fp.write("%!PS-Adobe-3.0\n" "save\n" "/showpage { } def\n" "%%EndComments\n" "%%BeginDocument\n") #self.fp.write(ERROR_PS) # debugging! self.fp.write(EDROFF_PS) self.fp.write(VDI_PS) self.fp.write("%%EndProlog\n") self.isofont = {} def end_document(self): "Write Postscript DSC footer" self.fp.write("%%EndDocument\n" "restore showpage\n" "%%End\n") if hasattr(self.fp, "flush"): self.fp.flush() def setfont(self, font, size): if not self.isofont.has_key(font): # reencode font self.fp.write("/PSDraw-%s ISOLatin1Encoding /%s E\n" %\ (font, font)) self.isofont[font] = 1 # rough self.fp.write("/F0 %d /PSDraw-%s F\n" % (size, font)) def setink(self, ink): print "*** NOT YET IMPLEMENTED ***" def line(self, xy0, xy1): xy = xy0 + xy1 self.fp.write("%d %d %d %d Vl\n" % xy) def rectangle(self, box): self.fp.write("%d %d M %d %d 0 Vr\n" % box) def text(self, xy, text): text = string.joinfields(string.splitfields(text, "("), "\\(") text = string.joinfields(string.splitfields(text, ")"), "\\)") xy = xy + (text,) self.fp.write("%d %d M (%s) S\n" % xy) def image(self, box, im, dpi = None): "Write an PIL image" # default resolution depends on mode if not dpi: if im.mode == "1": dpi = 200 # fax else: dpi = 100 # greyscale # image size (on paper) x = float(im.size[0] * 72) / dpi y = float(im.size[1] * 72) / dpi # max allowed size xmax = box[2] - box[0] ymax = box[3] - box[1] if x > xmax: y = y * xmax / x; x = xmax if y > ymax: x = x * ymax / y; y = ymax dx = (xmax - x) / 2 + box[0] dy = (ymax - y) / 2 + box[1] self.fp.write("gsize\n%f %f translate\n" % (dx, dy)) if (x, y) != im.size: # EpsImagePlugin._save prints the image at (0,0,xsize,ysize) sx = x / im.size[0] sy = y / im.size[1] self.fp.write("%f %f scale\n" % (sx, sy)) EpsImagePlugin._save(im, self.fp, None, 0) self.fp.write("\ngrestore\n") # -------------------------------------------------------------------- # Postscript driver # # EDROFF.PS -- Postscript driver for Edroff 2 # # History: # 94-01-25 fl: created (edroff 2.04) # # Copyright (c) Fredrik Lundh 1994. # EDROFF_PS = """\ /S { show } bind def /P { moveto show } bind def /M { moveto } bind def /X { 0 rmoveto } bind def /Y { 0 exch rmoveto } bind def /E { findfont dup maxlength dict begin { 1 index /FID ne { def } { pop pop } ifelse } forall /Encoding exch def dup /FontName exch def currentdict end definefont pop } bind def /F { findfont exch scalefont dup setfont [ exch /setfont cvx ] cvx bind def } bind def """ # # VDI.PS -- Postscript driver for VDI meta commands # # History: # 94-01-25 fl: created (edroff 2.04) # # Copyright (c) Fredrik Lundh 1994. # VDI_PS = """\ /Vm { moveto } bind def /Va { newpath arcn stroke } bind def /Vl { moveto lineto stroke } bind def /Vc { newpath 0 360 arc closepath } bind def /Vr { exch dup 0 rlineto exch dup neg 0 exch rlineto exch neg 0 rlineto 0 exch rlineto 100 div setgray fill 0 setgray } bind def /Tm matrix def /Ve { Tm currentmatrix pop translate scale newpath 0 0 .5 0 360 arc closepath Tm setmatrix } bind def /Vf { currentgray exch setgray fill setgray } bind def """ # # ERROR.PS -- Error handler # # History: # 89-11-21 fl: created (pslist 1.10) # ERROR_PS = """\ /landscape false def /errorBUF 200 string def /errorNL { currentpoint 10 sub exch pop 72 exch moveto } def errordict begin /handleerror { initmatrix /Courier findfont 10 scalefont setfont newpath 72 720 moveto $error begin /newerror false def (PostScript Error) show errorNL errorNL (Error: ) show /errorname load errorBUF cvs show errorNL errorNL (Command: ) show /command load dup type /stringtype ne { errorBUF cvs } if show errorNL errorNL (VMstatus: ) show vmstatus errorBUF cvs show ( bytes available, ) show errorBUF cvs show ( bytes used at level ) show errorBUF cvs show errorNL errorNL (Operand stargck: ) show errorNL /ostargck load { dup type /stringtype ne { errorBUF cvs } if 72 0 rmoveto show errorNL } forall errorNL (Execution stargck: ) show errorNL /estargck load { dup type /stringtype ne { errorBUF cvs } if 72 0 rmoveto show errorNL } forall end showpage } def end """ Imaging-1.1.3/PIL/SgiImagePlugin.py0100444000076400007640000000427207442710203016602 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/SgiImagePlugin.py#2 $ # # SGI image file handling # # See "The SGI Image File Format (Draft version 0.97)", Paul Haeberli. # # # History: # 2025-09-10 fl Created # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1995. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import string import Image, ImageFile def i16(c): return ord(c[1]) + (ord(c[0])<<8) def i32(c): return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24) def _accept(prefix): return i16(prefix) == 474 class SgiImageFile(ImageFile.ImageFile): format = "SGI" format_description = "SGI Image File Format" def _open(self): # HEAD s = self.fp.read(512) if i16(s) != 474: raise SyntaxError, "not an SGI image file" # relevant header entries compression = ord(s[2]) # bytes, dimension, zsize layout = ord(s[3]), i16(s[4:]), i16(s[10:]) # determine mode from bytes/zsize if layout == (1, 2, 1): self.mode = "L" elif layout == (1, 3, 3): self.mode = "RGB" else: raise SyntaxError, "unsupported SGI image mode" # size self.size = i16(s[6:]), i16(s[8:]) # decoder info if compression == 0: if self.mode == "RGB": # RGB images are band interleaved size = self.size[0]*self.size[1] self.tile = [("raw", (0,0)+self.size, 512, ("R",0,1)), ("raw", (0,0)+self.size, 512+size, ("G",0,1)), ("raw", (0,0)+self.size, 512+2*size, ("B",0,1))] else: self.tile = [("raw", (0,0)+self.size, 512, (self.mode, 0, 1))] if compression == 1: self.tile = [("sgi_rle", (0,0)+self.size, 512, (self.mode, 0, 1))] # # registry Image.register_open("SGI", SgiImageFile, _accept) Image.register_extension("SGI", ".bw") Image.register_extension("SGI", ".rgb") Image.register_extension("SGI", ".rgba") Image.register_extension("SGI", ".sgi") # really? Imaging-1.1.3/PIL/SunImagePlugin.py0100444000076400007640000000376207442710203016630 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/SunImagePlugin.py#3 $ # # Sun image file handling # # History: # 2025-09-10 fl Created # 2025-05-28 fl Fixed 32-bit alignment # 2024-12-29 fl Import ImagePalette module # 2025-12-18 fl Fixed palette loading (from Jean-Claude Rimbault) # # Copyright (c) 1997-2001 by Secret Labs AB # Copyright (c) 1995-1996 by Fredrik Lundh # # See the README file for information on usage and redistribution. # __version__ = "0.3" import string import Image, ImageFile, ImagePalette def i16(c): return ord(c[1]) + (ord(c[0])<<8) def i32(c): return ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16) + (ord(c[0])<<24) def _accept(prefix): return i32(prefix) == 0x59a66a95 class SunImageFile(ImageFile.ImageFile): format = "SUN" format_description = "Sun Raster File" def _open(self): # HEAD s = self.fp.read(32) if i32(s) != 0x59a66a95: raise SyntaxError, "not an SUN raster file" offset = 32 self.size = i32(s[4:8]), i32(s[8:12]) depth = i32(s[12:16]) if depth == 1: self.mode, rawmode = "1", "1;I" elif depth == 8: self.mode = rawmode = "L" elif depth == 24: self.mode, rawmode = "RGB", "BGR" else: raise SyntaxError, "unsupported mode" compression = i32(s[20:24]) if i32(s[24:28]) != 0: length = i32(s[28:32]) offset = offset + length self.palette = ImagePalette.raw("RGB;L", self.fp.read(length)) if self.mode == "L": self.mode = rawmode = "P" stride = (((self.size[0] * depth + 7) / 8) + 3) & (~3) if compression == 1: self.tile = [("raw", (0,0)+self.size, offset, (rawmode, stride))] elif compression == 2: self.tile = [("sun_rle", (0,0)+self.size, offset, rawmode)] # # registry Image.register_open("SUN", SunImageFile, _accept) Image.register_extension("SUN", ".ras") Imaging-1.1.3/PIL/TarIO.py0100444000076400007640000000204207442710203014705 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/TarIO.py#3 $ # # read files from within a tar file # # History: # 95-06-18 fl Created # 96-05-28 fl Open files in binary mode # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1995-96. # # See the README file for information on usage and redistribution. # import ContainerIO import string class TarIO(ContainerIO.ContainerIO): def __init__(self, tarfile, file): fh = open(tarfile, "rb") while 1: s = fh.read(512) if len(s) != 512: raise IOError, "unexpected end of tar file" name = s[:100] i = string.find(name, chr(0)) if i == 0: raise IOError, "cannot find subfile" if i > 0: name = name[:i] size = string.atoi(s[124:136], 8) if file == name: break fh.seek((size + 511) & (~511), 1) # Open region ContainerIO.ContainerIO.__init__(self, fh, fh.tell(), size) Imaging-1.1.3/PIL/TgaImagePlugin.py0100444000076400007640000000651307442710203016573 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/TgaImagePlugin.py#3 $ # # TGA file handling # # History: # 95-09-01 fl created (reads 24-bit files only) # 97-01-04 fl support more TGA versions, including compressed images # 98-07-04 fl fixed orientation and alpha layer bugs # 98-09-11 fl fixed orientation for runlength decoder # # Copyright (c) Secret Labs AB 1997-98. # Copyright (c) Fredrik Lundh 1995-97. # # See the README file for information on usage and redistribution. # __version__ = "0.3" import Image, ImageFile, ImagePalette def i16(c): return ord(c[0]) + (ord(c[1])<<8) def i32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) MODES = { # map imagetype/depth to rawmode (1, 8): "P", (3, 1): "1", (3, 8): "L", (2, 16): "BGR;5", (2, 24): "BGR", (2, 32): "BGRA", } def _accept(prefix): return prefix[0] == "\0" class TgaImageFile(ImageFile.ImageFile): format = "TGA" format_description = "Targa" def _open(self): # process header s = self.fp.read(18) id = ord(s[0]) colormaptype = ord(s[1]) imagetype = ord(s[2]) depth = ord(s[16]) flags = ord(s[17]) self.size = i16(s[12:]), i16(s[14:]) # validate header fields if id != 0 or colormaptype not in (0, 1) or\ self.size[0] <= 0 or self.size[1] <= 0 or\ depth not in (8, 16, 24, 32): raise SyntaxError, "not a TGA file" # image mode if imagetype in (3, 11): self.mode = "L" if depth == 1: self.mode = "1" # ??? elif imagetype in (1, 9): self.mode = "P" elif imagetype in (2, 10): self.mode = "RGB" if depth == 32: self.mode = "RGBA" else: raise SyntaxError, "unknown TGA mode" # orientation orientation = flags & 0x30 if orientation == 0x20: orientation = 1 elif not orientation: orientation = -1 else: raise SyntaxError, "unknown TGA orientation" if imagetype & 8: self.info["compression"] = "tga_rle" if colormaptype: # read palette start, size, mapdepth = i16(s[3:]), i16(s[5:]), i16(s[7:]) if mapdepth == 16: self.palette = ImagePalette.raw("BGR;16", "\0"*2*start + self.fp.read(2*size)) elif mapdepth == 24: self.palette = ImagePalette.raw("BGR", "\0"*3*start + self.fp.read(3*size)) elif mapdepth == 32: self.palette = ImagePalette.raw("BGRA", "\0"*4*start + self.fp.read(4*size)) # setup tile descriptor try: rawmode = MODES[(imagetype&7, depth)] if imagetype & 8: # compressed self.tile = [("tga_rle", (0, 0)+self.size, self.fp.tell(), (rawmode, orientation, depth))] else: self.tile = [("raw", (0, 0)+self.size, self.fp.tell(), (rawmode, 0, orientation))] except KeyError: pass # cannot decode # # registry Image.register_open("TGA", TgaImageFile, _accept) Image.register_extension("TGA", ".tga") Imaging-1.1.3/PIL/TiffImagePlugin.py0100444000076400007640000005100707442710203016746 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/TiffImagePlugin.py#5 $ # # TIFF file handling # # TIFF is a flexible, if somewhat aged, image file format originally # defined by Aldus. Although TIFF supports a wide variety of pixel # layouts and compression methods, the name doesn't really stand for # "thousands of incompatible file formats," it just feels that way. # # To read TIFF data from a stream, the stream must be seekable. For # progressive decoding, make sure to use TIFF files where the tag # directory is placed first in the file. # # History: # 2025-09-01 fl Created # 2025-05-04 fl Handle JPEGTABLES tag # 2025-05-18 fl Fixed COLORMAP support # 2025-01-05 fl Fixed PREDICTOR support # 2025-08-27 fl Added support for rational tags (from Perry Stoll) # 2025-01-10 fl Fixed seek/tell (from Jan Blom) # 2025-07-15 fl Use private names for internal variables # 2025-06-13 fl Rewritten for PIL 1.0 (1.0) # 2025-10-11 fl Additional fixes for Python 2.0 (1.1) # 2025-04-17 fl Fixed rewind support (seek to frame 0) (1.2) # 2025-05-12 fl Added write support for more tags (from Greg Couch) (1.3) # 2025-12-18 fl Added workaround for broken Matrox library # 2025-01-18 fl Don't mess up if photometric tag is missing (D. Alan Stewart) # # Copyright (c) 1997-2002 by Secret Labs AB # Copyright (c) 1995-1997 by Fredrik Lundh # # See the README file for information on usage and redistribution. # __version__ = "1.3.2" import Image, ImageFile import ImagePalette import string # # -------------------------------------------------------------------- # Read TIFF files def il16(c,o=0): return ord(c[o]) + (ord(c[o+1])<<8) def il32(c,o=0): return ord(c[o]) + (ord(c[o+1])<<8) + (ord(c[o+2])<<16) + (ord(c[o+3])<<24) def ol16(i): return chr(i&255) + chr(i>>8&255) def ol32(i): return chr(i&255) + chr(i>>8&255) + chr(i>>16&255) + chr(i>>24&255) def ib16(c,o=0): return ord(c[o+1]) + (ord(c[o])<<8) def ib32(c,o=0): return ord(c[o+3]) + (ord(c[o+2])<<8) + (ord(c[o+1])<<16) + (ord(c[o])<<24) # a few tag names, just to make the code below a bit more readable IMAGEWIDTH = 256 IMAGELENGTH = 257 BITSPERSAMPLE = 258 COMPRESSION = 259 PHOTOMETRIC_INTERPRETATION = 262 IMAGEDESCRIPTION = 270 STRIPOFFSETS = 273 SAMPLESPERPIXEL = 277 ROWSPERSTRIP = 278 STRIPBYTECOUNTS = 279 X_RESOLUTION = 282 Y_RESOLUTION = 283 PLANAR_CONFIGURATION = 284 RESOLUTION_UNIT = 296 SOFTWARE = 305 DATE_TIME = 306 ARTIST = 315 PREDICTOR = 317 COLORMAP = 320 EXTRASAMPLES = 338 SAMPLEFORMAT = 339 JPEGTABLES = 347 COPYRIGHT = 33432 IPTC_NAA_CHUNK = 33723 # newsphoto properties PHOTOSHOP_CHUNK = 34377 # photoshop properties COMPRESSION_INFO = { # Compression => pil compression name 1: "raw", 2: "tiff_ccitt", 3: "group3", 4: "group4", 5: "tiff_lzw", 6: "tiff_jpeg", # obsolete 7: "jpeg", 32771: "tiff_raw_16", # 16-bit padding 32773: "packbits" } OPEN_INFO = { # Photometric Interpretation, SampleFormat, BitsPerSample, ExtraSamples => # mode, rawmode (0, 1, (1,), ()): ("1", "1;I"), (0, 1, (8,), ()): ("L", "L;I"), (1, 1, (1,), ()): ("1", "1"), (1, 1, (8,), ()): ("L", "L"), (1, 2, (16,), ()): ("I;16", "I;16"), (1, 2, (32,), ()): ("I", "I;32S"), (1, 3, (32,), ()): ("F", "F;32F"), (2, 1, (8,8,8), ()): ("RGB", "RGB"), (2, 1, (8,8,8,8), (0,)): ("RGBX", "RGBX"), (2, 1, (8,8,8,8), (2,)): ("RGBA", "RGBA"), (3, 1, (1,), ()): ("P", "P;1"), (3, 1, (2,), ()): ("P", "P;2"), (3, 1, (4,), ()): ("P", "P;4"), (3, 1, (8,), ()): ("P", "P"), (5, 1, (8,8,8,8), ()): ("CMYK", "CMYK"), (6, 1, (8,8,8), ()): ("YCbCr", "YCbCr"), (8, 1, (8,8,8), ()): ("LAB", "LAB"), } PREFIXES = ["MM\000\052", "II\052\000"] def _accept(prefix): return prefix[:4] in PREFIXES class ImageFileDirectory: # represents a TIFF tag directory. to speed things up, # we don't decode tags unless they're asked for. def __init__(self, prefix="II"): assert prefix in ("MM", "II") self.prefix = prefix if prefix == "MM": self.i16, self.i32 = ib16, ib32 # FIXME: save doesn't yet support big-endian mode... else: self.i16, self.i32 = il16, il32 self.o16, self.o32 = ol16, ol32 self.reset() def reset(self): self.tags = {} self.tagdata = {} self.next = None # dictionary API (sort of) def __len__(self): return max(len(self.tagdata), len(self.tags)) def __getitem__(self, tag): try: return self.tags[tag] except KeyError: type, data = self.tagdata[tag] # unpack on the fly size, handler = self.load_dispatch[type] self.tags[tag] = data = handler(self, data) del self.tagdata[tag] return data def get(self, tag, default=None): try: return self[tag] except KeyError: return default def getscalar(self, tag, default=None): try: value = self[tag] if len(value) != 1: if tag == SAMPLEFORMAT: # work around broken (?) matrox library # (from Ted Wright, via Bob Klimek) raise KeyError # use default raise ValueError, "not a scalar" return value[0] except KeyError: if default is None: raise return default def has_key(self, tag): return self.tags.has_key(tag) or self.tagdata.has_key(tag) def __setitem__(self, tag, value): if type(value) is not type(()): value = (value,) self.tags[tag] = value # load primitives load_dispatch = {} def load_byte(self, data): l = [] for i in range(len(data)): l.append(ord(data[i])) return tuple(l) load_dispatch[1] = (1, load_byte) def load_string(self, data): if data[-1:] == '\0': data = data[:-1] return data load_dispatch[2] = (1, load_string) def load_short(self, data): l = [] for i in range(0, len(data), 2): l.append(self.i16(data, i)) return tuple(l) load_dispatch[3] = (2, load_short) def load_long(self, data): l = [] for i in range(0, len(data), 4): l.append(self.i32(data, i)) return tuple(l) load_dispatch[4] = (4, load_long) def load_rational(self, data): l = [] for i in range(0, len(data), 8): l.append((self.i32(data, i), self.i32(data, i+4))) return tuple(l) load_dispatch[5] = (8, load_rational) def load_undefined(self, data): # Untyped data return data load_dispatch[7] = (1, load_undefined) def load(self, fp): # load tag dictionary self.reset() i16 = self.i16 i32 = self.i32 for i in range(i16(fp.read(2))): ifd = fp.read(12) tag, typ = i16(ifd), i16(ifd, 2) if Image.DEBUG: import TiffTags tagname = TiffTags.TAGS.get(tag, "unknown") typname = TiffTags.TYPES.get(typ, "unknown") print "tag: %s (%d)" % (tagname, tag), print "- type: %s (%d)" % (typname, typ), try: dispatch = self.load_dispatch[typ] except KeyError: if Image.DEBUG: print "- unsupported type", typ continue # ignore unsupported type size, handler = dispatch size = size * i32(ifd, 4) # Get and expand tag value if size > 4: here = fp.tell() fp.seek(i32(ifd, 8)) data = fp.read(size) fp.seek(here) else: data = ifd[8:8+size] if len(data) != size: raise IOError, "not enough data" self.tagdata[tag] = typ, data if Image.DEBUG: if tag in (COLORMAP, IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK): print "- value: " % size else: print "- value:", self[tag] self.next = i32(fp.read(4)) # save primitives def save(self, fp): o16 = self.o16 o32 = self.o32 fp.write(o16(len(self.tags))) # always write in ascending tag order tags = self.tags.items() tags.sort() directory = [] append = directory.append offset = fp.tell() + len(self.tags) * 12 + 4 stripoffsets = None # pass 1: convert tags to binary format for tag, value in tags: if Image.DEBUG: import TiffTags tagname = TiffTags.TAGS.get(tag, "unknown") print "save: %s (%d)" % (tagname, tag), print "- value:", value if type(value[0]) is type(""): # string data typ = 2 data = value = string.join(value, "\0") + "\0" else: # integer data if tag == STRIPOFFSETS: stripoffsets = len(directory) typ = 4 # to avoid catch-22 elif tag in (X_RESOLUTION, Y_RESOLUTION): # identify rational data fields typ = 5 else: typ = 3 for v in value: if v >= 65536: typ = 4 if typ == 3: data = string.join(map(o16, value), "") else: data = string.join(map(o32, value), "") # figure out if data fits into the directory if len(data) == 4: append((tag, typ, len(value), data, "")) elif len(data) < 4: append((tag, typ, len(value), data + (4-len(data))*"\0", "")) else: count = len(value) if typ == 5: count = count / 2 # adjust for rational data field append((tag, typ, count, o32(offset), data)) offset = offset + len(data) if offset & 1: offset = offset + 1 # word padding # update strip offset data to point beyond auxiliary data if stripoffsets is not None: tag, typ, count, value, data = directory[stripoffsets] assert not data, "multistrip support not yet implemented" value = o32(self.i32(value) + offset) directory[stripoffsets] = tag, typ, count, value, data # pass 2: write directory to file for tag, typ, count, value, data in directory: if Image.DEBUG > 1: print tag, typ, count, repr(value), repr(data) fp.write(o16(tag) + o16(typ) + o32(count) + value) fp.write("\0\0\0\0") # end of directory # pass 3: write auxiliary data to file for tag, typ, count, value, data in directory: fp.write(data) if len(data) & 1: fp.write("\0") return offset class TiffImageFile(ImageFile.ImageFile): format = "TIFF" format_description = "Adobe TIFF" def _open(self): "Open the first image in a TIFF file" # Header ifh = self.fp.read(8) if ifh[:4] not in PREFIXES: raise SyntaxError, "not a TIFF file" # image file directory (tag dictionary) self.tag = self.ifd = ImageFileDirectory(ifh[:2]) # setup frame pointers self.__first = self.__next = self.ifd.i32(ifh, 4) self.__frame = -1 self.__fp = self.fp # and load the first frame self._seek(0) def seek(self, frame): "Select a given frame as current image" if frame < 0: frame = 0 self._seek(frame) def tell(self): "Return the current frame number" return self._tell() def _seek(self, frame): self.fp = self.__fp if frame < self.__frame: # rewind file self.__frame = -1 self.__next = self.__first while self.__frame < frame: if not self.__next: raise EOFError, "no more images in TIFF file" self.fp.seek(self.__next) self.tag.load(self.fp) self.__next = self.tag.next self.__frame = self.__frame + 1 self._setup() def _tell(self): return self.__frame def _decoder(self, rawmode, layer): "Setup decoder contexts" args = None if rawmode == "RGB" and self._planar_configuration == 2: rawmode = rawmode[layer] if self._compression == "raw": args = (rawmode, 0, 1) if self._compression in ["packbits", "tiff_lzw", "jpeg"]: args = rawmode if self._compression == "jpeg" and self.tag.has_key(JPEGTABLES): # Hack to handle abbreviated JPEG headers self.tile_prefix = self.tag[JPEGTABLES] elif self._compression == "tiff_lzw" and self.tag.has_key(317): # Section 14: Differencing Predictor self.decoderconfig = (self.tag[PREDICTOR][0],) return args def _setup(self): "Setup this image object based on current tags" # extract relevant tags self._compression = COMPRESSION_INFO[self.tag.getscalar( COMPRESSION, 1 )] self._planar_configuration = self.tag.getscalar( PLANAR_CONFIGURATION, 1 ) # photometric is a required tag, but not everyone is reading # the specification photo = self.tag.getscalar(PHOTOMETRIC_INTERPRETATION, 0) if Image.DEBUG: print "*** Summary ***" print "- compression:", self._compression print "- photometric_interpretation:", photo print "- planar_configuration:", self._planar_configuration # size xsize = self.tag.getscalar(IMAGEWIDTH) ysize = self.tag.getscalar(IMAGELENGTH) self.size = xsize, ysize if Image.DEBUG: print "- size:", self.size format = self.tag.getscalar(SAMPLEFORMAT, 1) # mode: check photometric interpretation and bits per pixel key = ( photo, format, self.tag.get(BITSPERSAMPLE, (1,)), self.tag.get(EXTRASAMPLES, ()) ) if Image.DEBUG: print "format key:", key try: self.mode, rawmode = OPEN_INFO[key] except KeyError: if Image.DEBUG: print "- unsupported format" raise SyntaxError, "unknown pixel mode" if Image.DEBUG: print "- raw mode:", rawmode print "- pil mode:", self.mode self.info["compression"] = self._compression # build tile descriptors x = y = l = 0 self.tile = [] if self.tag.has_key(STRIPOFFSETS): # striped image h = self.tag.getscalar(ROWSPERSTRIP, ysize) w = self.size[0] a = None for o in self.tag[STRIPOFFSETS]: if not a: a = self._decoder(rawmode, l) self.tile.append( (self._compression, (0, min(y, ysize), w, min(y+h, ysize)), o, a)) y = y + h if y >= self.size[1]: x = y = 0 l = l + 1 a = None elif self.tag.has_key(324): # tiled image w = self.tag.getscalar(322) h = self.tag.getscalar(323) a = None for o in self.tag[324]: if not a: a = self._decoder(rawmode, l) # FIXME: this doesn't work if the image size # is not a multiple of the tile size... self.tile.append( (self._compression, (x, y, x+w, y+h), o, a)) x = x + w if x >= self.size[0]: x, y = 0, y + h if y >= self.size[1]: x = y = 0 l = l + 1 a = None else: if Image.DEBUG: print "- unsupported data organization" raise SyntaxError, "unknown data organization" # fixup palette descriptor if self.mode == "P": palette = map(lambda a: chr(a / 256), self.tag[COLORMAP]) self.palette = ImagePalette.raw("RGB;L", string.join(palette, "")) # # -------------------------------------------------------------------- # Write TIFF files # little endian is default SAVE_INFO = { # mode => rawmode, photometrics, sampleformat, bitspersample, extra "1": ("1", 1, 1, (1,), None), "L": ("L", 1, 1, (8,), None), "P": ("P", 3, 1, (8,), None), "I": ("I;32S", 1, 2, (32,), None), "I;16": ("I;16", 1, 2, (16,), None), "F": ("F;32F", 1, 3, (32,), None), "RGB": ("RGB", 2, 1, (8,8,8), None), "RGBX": ("RGBX", 2, 1, (8,8,8,8), 0), "RGBA": ("RGBA", 2, 1, (8,8,8,8), 2), "CMYK": ("CMYK", 5, 1, (8,8,8,8), None), "YCbCr": ("YCbCr", 6, 1, (8,8,8), None), "LAB": ("LAB", 8, 1, (8,8,8), None), } def _cvt_res(value): # convert value to TIFF rational number -- (numerator, denominator) if type(value) in (type([]), type(())): assert(len(value) % 2 == 0) return value if type(value) == type(1): return (value, 1) value = float(value) return (int(value * 65536), 65536) def _save(im, fp, filename): try: rawmode, photo, format, bits, extra = SAVE_INFO[im.mode] except KeyError: raise IOError, "cannot write mode %s as TIFF" % im.mode ifd = ImageFileDirectory() # tiff header (write via IFD to get everything right) fp.write(ifd.prefix + ifd.o16(42) + ifd.o32(8)) ifd[IMAGEWIDTH] = im.size[0] ifd[IMAGELENGTH] = im.size[1] # additions written by Greg Couch, gregc@cgl.ucsf.edu # inspired by image-sig posting from Kevin Cazabon, kcazabon@home.com if hasattr(im, 'tag'): # preserve tags from original TIFF image file for key in (RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION): if im.tag.tagdata.has_key(key): ifd[key] = im.tag.tagdata.get(key) if im.encoderinfo.has_key("description"): ifd[IMAGEDESCRIPTION] = im.encoderinfo["description"] if im.encoderinfo.has_key("resolution"): ifd[X_RESOLUTION] = ifd[Y_RESOLUTION] \ = _cvt_res(im.encoderinfo["resolution"]) if im.encoderinfo.has_key("x resolution"): ifd[X_RESOLUTION] = _cvt_res(im.encoderinfo["x resolution"]) if im.encoderinfo.has_key("y resolution"): ifd[Y_RESOLUTION] = _cvt_res(im.encoderinfo["y resolution"]) if im.encoderinfo.has_key("resolution unit"): unit = im.encoderinfo["resolution unit"] if unit == "inch": ifd[RESOLUTION_UNIT] = 2 elif unit == "cm" or unit == "centimeter": ifd[RESOLUTION_UNIT] = 3 else: ifd[RESOLUTION_UNIT] = 1 if im.encoderinfo.has_key("software"): ifd[SOFTWARE] = im.encoderinfo["software"] if im.encoderinfo.has_key("date time"): ifd[DATE_TIME] = im.encoderinfo["date time"] if im.encoderinfo.has_key("artist"): ifd[ARTIST] = im.encoderinfo["artist"] if im.encoderinfo.has_key("copyright"): ifd[COPYRIGHT] = im.encoderinfo["copyright"] if bits != (1,): ifd[BITSPERSAMPLE] = bits if len(bits) != 1: ifd[SAMPLESPERPIXEL] = len(bits) if extra is not None: ifd[EXTRASAMPLES] = extra if format != 1: ifd[SAMPLEFORMAT] = format ifd[PHOTOMETRIC_INTERPRETATION] = photo if im.mode == "P": lut = im.im.getpalette("RGB", "RGB;L") ifd[COLORMAP] = tuple(map(lambda v: ord(v) * 256, lut)) # 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 offset = ifd.save(fp) ImageFile._save(im, fp, [ ("raw", (0,0)+im.size, offset, (rawmode, stride, 1)) ]) # # -------------------------------------------------------------------- # 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") Imaging-1.1.3/PIL/TiffTags.py0100444000076400007640000000604307442710203015443 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/TiffTags.py#2 $ # # TIFF tags # # This module provides clear-text names for various well-known # TIFF tags. the TIFF codec works just fine without it. # # Copyright (c) Secret Labs AB 1999. # # See the README file for information on usage and redistribution. # TAGS = { 254: "NewSubfileType", 255: "SubfileType", 256: "ImageWidth", 257: "ImageLength", 258: "BitsPerSample", 259: "Compression", (259, 1): "uncompressed", (259, 2): "ccitt 1d", (259, 3): "group 3 fax", (259, 4): "group 4 fax", (259, 5): "lzw", (259, 6): "jpeg", (259, 32773): "packbits", 262: "PhotometricInterpretation", (262, 0): "whiteiszero", (262, 1): "blackiszero", (262, 2): "rgb", (262, 3): "rgb palette", (262, 4): "transparency mask", (262, 5): "cmyk", (262, 6): "ycbcr", (262, 8): "cielab", 263: "Thresholding", 264: "CellWidth", 265: "CellHeight", 266: "FillOrder", 269: "DocumentName", 270: "ImageDescription", 271: "Make", 272: "Model", 273: "StripOffsets", 274: "Orientation", 277: "SamplesPerPixel", 278: "RowsPerStrip", 279: "StripByteCounts", 280: "MinSampleValue", 281: "MaxSampleValue", 282: "XResolution", 283: "YResolution", 284: "PlanarConfiguration", (284, 1): "contigous", (284, 2): "separate", 285: "PageName", 286: "XPosition", 287: "YPosition", 288: "FreeOffsets", 289: "FreeByteCounts", 290: "GrayResponseUnit", 291: "GrayResponseCurve", 292: "T4Options", 293: "T6Options", 296: "ResolutionUnit", 297: "PageNumber", 301: "TransferFunction", 305: "Software", 306: "DateTime", 315: "Artist", 316: "HostComputer", 317: "Predictor", 318: "WhitePoint", 319: "PrimaryChromaticies", 320: "ColorMap", 321: "HalftoneHints", 322: "TileWidth", 323: "TileLength", 324: "TileOffsets", 325: "TileByteCounts", 332: "InkSet", 333: "InkNames", 334: "NumberOfInks", 336: "DotRange", 337: "TargetPrinter", 338: "ExtraSamples", 339: "SampleFormat", 340: "SMinSampleValue", 341: "SMaxSampleValue", 342: "TransferRange", 347: "JPEGTables", # obsolete JPEG tags 512: "JPEGProc", 513: "JPEGInterchangeFormat", 514: "JPEGInterchangeFormatLength", 515: "JPEGRestartInterval", 517: "JPEGLosslessPredictors", 518: "JPEGPointTransforms", 519: "JPEGQTables", 520: "JPEGDCTables", 521: "JPEGACTables", 529: "YCbCrCoefficients", 530: "YCbCrSubSampling", 531: "YCbCrPositioning", 532: "ReferenceBlackWhite", 33432: "Copyright", # various extensions (should check specs for "official" names) 33723: "IptcNaaInfo", 34377: "PhotoshopInfo", } TYPES = { 1: "byte", 2: "ascii", 3: "short", 4: "long", 5: "rational", 6: "signed byte", 7: "undefined", 8: "signed short", 9: "signed long", 10: "signed rational", 11: "float", 12: "double", } Imaging-1.1.3/PIL/WmfImagePlugin.py0100444000076400007640000001633607442710203016615 0ustar fredrikfredrik# # THIS IS WORK IN PROGRESS. # # The Python Imaging Library. # $Id: //modules/pil/PIL/WmfImagePlugin.py#3 $ # # WMF support for PIL # # history: # 96-12-14 fl Created # # notes: # This code currently supports placable metafiles only, and # just a few graphics operations are implemented. # # Copyright (c) Secret Labs AB 1997. # Copyright (c) Fredrik Lundh 1996. # # See the README file for information on usage and redistribution. # __version__ = "0.1" import Image, ImageDraw, ImageFile import string # # -------------------------------------------------------------------- def i16(c): return ord(c[0]) + (ord(c[1])<<8) def i32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) # -------------------------------------------------------------------- # The following codes are taken from the wingdi.h header file. # Copyright (c) 1985-1996, Microsoft Corp. All rights reserved. META_ANIMATEPALETTE = 0x0436 META_ARC = 0x0817 META_BITBLT = 0x0922 META_CHORD = 0x0830 META_CREATEBRUSHINDIRECT = 0x02FC META_CREATEFONTINDIRECT = 0x02FB META_CREATEPALETTE = 0x00f7 META_CREATEPATTERNBRUSH = 0x01F9 META_CREATEPENINDIRECT = 0x02FA META_CREATEREGION = 0x06FF META_DELETEOBJECT = 0x01f0 META_DIBBITBLT = 0x0940 META_DIBCREATEPATTERNBRUSH = 0x0142 META_DIBSTRETCHBLT = 0x0b41 META_ELLIPSE = 0x0418 META_ESCAPE = 0x0626 META_EXCLUDECLIPRECT = 0x0415 META_EXTFLOODFILL = 0x0548 META_EXTTEXTOUT = 0x0a32 META_FILLREGION = 0x0228 META_FLOODFILL = 0x0419 META_FRAMEREGION = 0x0429 META_INTERSECTCLIPRECT = 0x0416 META_INVERTREGION = 0x012A META_LINETO = 0x0213 META_MOVETO = 0x0214 META_OFFSETCLIPRGN = 0x0220 META_OFFSETVIEWPORTORG = 0x0211 META_OFFSETWINDOWORG = 0x020F META_PAINTREGION = 0x012B META_PATBLT = 0x061D META_PIE = 0x081A META_POLYGON = 0x0324 META_POLYLINE = 0x0325 META_POLYPOLYGON = 0x0538 META_REALIZEPALETTE = 0x0035 META_RECTANGLE = 0x041B META_RESIZEPALETTE = 0x0139 META_RESTOREDC = 0x0127 META_ROUNDRECT = 0x061C META_SAVEDC = 0x001E META_SCALEVIEWPORTEXT = 0x0412 META_SCALEWINDOWEXT = 0x0410 META_SELECTCLIPREGION = 0x012C META_SELECTOBJECT = 0x012D META_SELECTPALETTE = 0x0234 META_SETBKCOLOR = 0x0201 META_SETBKMODE = 0x0102 META_SETDIBTODEV = 0x0d33 META_SETMAPMODE = 0x0103 META_SETMAPPERFLAGS = 0x0231 META_SETPALENTRIES = 0x0037 META_SETPIXEL = 0x041F META_SETPOLYFILLMODE = 0x0106 META_SETRELABS = 0x0105 META_SETROP2 = 0x0104 META_SETSTRETCHBLTMODE = 0x0107 META_SETTEXTALIGN = 0x012E META_SETTEXTCHAREXTRA = 0x0108 META_SETTEXTCOLOR = 0x0209 META_SETTEXTJUSTIFICATION = 0x020A META_SETVIEWPORTEXT = 0x020E META_SETVIEWPORTORG = 0x020D META_SETWINDOWEXT = 0x020C META_SETWINDOWORG = 0x020B META_STRETCHBLT = 0x0B23 META_STRETCHDIB = 0x0f43 META_TEXTOUT = 0x0521 # create a code to name dictionary (for debugging) NAME = {} for k, v in vars().items(): if k[:5] == "META_": NAME[v] = k[5:] # # -------------------------------------------------------------------- # Read WMF file def _accept(prefix): return prefix[:6] == "\327\315\306\232\000\000" class WmfImageFile(ImageFile.ImageFile): format = "WMF" format_description = "Windows Metafile" def _open(self): # check placable header s = self.fp.read(22) if s[:6] != "\327\315\306\232\000\000": raise SyntaxError, "Not a placable WMF file" # position on output device bbox = i16(s[6:8]), i16(s[8:10]), i16(s[10:12]), i16(s[12:14]) # FIXME: should take the scale into account self.mode = "P" self.size = (bbox[2]-bbox[0]) / 20, (bbox[3]-bbox[1]) / 20 # FIXME: while hacking self.size = (bbox[2] + bbox[0])/10, (bbox[3] + bbox[1])/10 self.bbox = bbox # check standard header s = self.fp.read(18) if s[:6] != "\001\000\011\000\000\003": raise SyntaxError, "Not a WMF file" def _ink(self, rgb): # lookup colour in current palette try: return self.palette[rgb] except KeyError: # hmm. what if the palette becomes full? ink = len(self.palette) self.palette[rgb] = ink return ink def load(self): if self.im: return # # windows standard palette self.palette = { '\000\000\000': 0, '\200\000\000': 1, '\000\200\000': 2, '\200\200\000': 3, '\000\000\200': 4, '\200\000\200': 5, '\000\200\200': 6, '\300\300\300': 7, '\300\334\300': 8, '\246\312\360': 9, '\377\373\360': 246, '\240\240\244': 247, '\200\200\200': 248, '\377\000\000': 249, '\000\377\000': 250, '\377\377\000': 251, '\000\000\377': 252, '\377\000\377': 253, '\000\377\377': 254, '\377\377\377': 255, } fill = 0 pen = brush = self._ink("\000\000\000") paper = self._ink("\377\377\377") self.im = Image.core.fill(self.mode, self.size, paper) # # render metafile into image, using the standard palette id = ImageDraw.ImageDraw(self) while 1: s = self.fp.read(6) size = i32(s)*2 func = i16(s[4:]) if not func: break s = self.fp.read(size-6) if func == META_SETPOLYFILLMODE: fill = i16(s) id.setfill(fill) elif func == META_CREATEBRUSHINDIRECT: brush = self._ink(s[2:5]) elif func == META_CREATEPENINDIRECT: pen = self._ink(s[6:9]) elif func == META_POLYGON: xy = map(lambda i,s=s: i16(s[i:i+2])/10, range(2, len(s), 2)) if fill: id.setink(brush) id.polygon(xy) id.setink(pen) id.setfill(0) id.polygon(xy) id.setfill(1) else: id.setink(pen) id.polygon(xy) elif func == META_POLYLINE: xy = map(lambda i,s=s: i16(s[i:i+2])/10, range(2, len(s), 2)) id.setink(pen) id.line(xy) elif func == META_RECTANGLE: xy = (i16(s[2:4])/10, i16(s[0:2])/10, i16(s[6:8])/10, i16(s[4:6])/10) if fill: id.setink(brush) id.rectangle(xy) id.setink(pen) id.setfill(0) id.rectangle(xy) id.setfill(1) else: id.setink(pen) id.rectangle(xy) else: if Image.DEBUG: print size, hex(func), NAME[func] pass # # attach palette to image palette = ["\0\0\0"] * 256 for rgb, i in self.palette.items(): if i < 256: palette[i] = rgb self.im.putpalette("RGB", string.join(palette, "")) # # -------------------------------------------------------------------- # Registry stuff Image.register_open("WMF", WmfImageFile, _accept) Image.register_extension("WMF", ".wmf") Imaging-1.1.3/PIL/XbmImagePlugin.py0100444000076400007640000000437507442710203016612 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/XbmImagePlugin.py#3 $ # # XBM File handling # # History: # 2025-09-08 fl Created # 2025-11-01 fl Added save support # 2025-07-07 fl Made header parser more tolerant # 2025-07-22 fl Fixed yet another parser bug # 2025-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.4) # 2025-05-13 fl Added hotspot handling (based on code from Bernhard Herzog) # # Copyright (c) 1997-2001 by Secret Labs AB # Copyright (c) 1996-1997 by Fredrik Lundh # # See the README file for information on usage and redistribution. # __version__ = "0.4" import re, string import Image, ImageFile # XBM header xbm_head = re.compile( "#define[ \t]+[^_]*_width[ \t]+(?P[0-9]+)[\r\n]+" "#define[ \t]+[^_]*_height[ \t]+(?P[0-9]+)[\r\n]+" "(?P" "#define[ \t]+[^_]*_x_hot[ \t]+(?P[0-9]+)[\r\n]+" "#define[ \t]+[^_]*_y_hot[ \t]+(?P[0-9]+)[\r\n]+" ")?" "[\\000-\\377]*_bits\\[\\]" ) def _accept(prefix): return prefix[:7] == "#define" class XbmImageFile(ImageFile.ImageFile): format = "XBM" format_description = "X11 Bitmap" def _open(self): m = xbm_head.match(self.fp.read(512)) if m: xsize = int(m.group("width")) ysize = int(m.group("height")) if m.group("hotspot"): self.info["hotspot"] = ( int(m.group("xhot")), int(m.group("yhot")) ) self.mode = "1" self.size = xsize, ysize 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") Imaging-1.1.3/PIL/XpmImagePlugin.py0100444000076400007640000000601307442710203016617 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/XpmImagePlugin.py#2 $ # # XPM File handling # # History: # 2024-12-29 fl Created # 2025-02-17 fl Use 're' instead of 'regex' (Python 2.1) (0.7) # # Copyright (c) Secret Labs AB 1997-2001. # Copyright (c) Fredrik Lundh 1996-2001. # # See the README file for information on usage and redistribution. # __version__ = "0.2" import re, string import Image, ImageFile, ImagePalette # XPM header xpm_head = re.compile("\"([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*)") def _accept(prefix): return prefix[:9] == "/* XPM */" class XpmImageFile(ImageFile.ImageFile): format = "XPM" format_description = "X11 Pixel Map" def _open(self): if not _accept(self.fp.read(9)): raise SyntaxError, "not an XPM file" # skip forward to next string while 1: s = self.fp.readline() if not s: raise SyntaxError, "broken XPM file" m = xpm_head.match(s) if m: break self.size = int(m.group(1)), int(m.group(2)) pal = int(m.group(3)) bpp = int(m.group(4)) if pal > 256 or bpp != 1: raise ValueError, "cannot read this XPM file" # # load palette description palette = ["\0\0\0"] * 256 for i in range(pal): s = self.fp.readline() if s[-2:] == '\r\n': s = s[:-2] elif s[-1:] in '\r\n': s = s[:-1] c = ord(s[1]) s = string.split(s[2:-2]) for i in range(0, len(s), 2): if s[i] == "c": # process colour key rgb = s[i+1] if rgb == "None": self.info["transparency"] = c elif rgb[0] == "#": # FIXME: handle colour names (see ImagePalette.py) rgb = string.atoi(rgb[1:], 16) palette[c] = chr((rgb >> 16) & 255) +\ chr((rgb >> 8) & 255) +\ chr(rgb & 255) else: # unknown colour raise ValueError, "cannot read this XPM file" break else: # missing colour key raise ValueError, "cannot read this XPM file" 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") Imaging-1.1.3/PIL/XVThumbImagePlugin.py0100444000076400007640000000320607442710203017411 0ustar fredrikfredrik# # The Python Imaging Library. # $Id: //modules/pil/PIL/XVThumbImagePlugin.py#3 $ # # XV Thumbnail file handler by Charles E. "Gene" Cash # (gcash@magicnet.net) # # see xvcolor.c and xvbrowse.c in the sources to John Bradley's XV, # available from ftp://ftp.cis.upenn.edu/pub/xv/ # # history: # 98-08-15 cec created (b/w only) # 98-12-09 cec added color palette # 98-12-28 fl added to PIL (with only a few very minor modifications) # # To do: # FIXME: make save work (this requires quantization support) # __version__ = "0.1" import string import Image, ImageFile, ImagePalette # standard color palette for thumbnails (RGB332) PALETTE = "" for r in range(8): for g in range(8): for b in range(4): PALETTE = PALETTE + (chr((r*255)/7)+chr((g*255)/7)+chr((b*255)/3)) class XVThumbImageFile(ImageFile.ImageFile): format = "XVThumb" format_description = "XV thumbnail image" def _open(self): # check magic s = self.fp.read(6) if s != "P7 332": raise SyntaxError, "not an XV thumbnail file" # skip info comments while 1: s = string.strip(self.fp.readline()) if s == "#END_OF_COMMENTS": break # read header line s = string.split(self.fp.readline()) self.mode = "P" self.size = int(s[0]), int(s[1]) self.palette = ImagePalette.raw("RGB", PALETTE) self.tile = [ ("raw", (0, 0)+self.size, self.fp.tell(), (self.mode, 0, 1) )] # -------------------------------------------------------------------- Image.register_open("XVThumb", XVThumbImageFile) Imaging-1.1.3/Scripts/pilconvert.py0100444000076400007640000000435707442710203017132 0ustar fredrikfredrik#! /usr/local/bin/python # # The Python Imaging Library. # $Id: //modules/pil/Scripts/pilconvert.py#2 $ # # convert image files # # History: # 0.1 96-04-20 fl Created # 0.2 96-10-04 fl Use draft mode when converting images # 0.3 96-12-30 fl Optimize output (PNG, JPEG) # 0.4 97-01-18 fl Made optimize an option (PNG, JPEG) # 0.5 98-12-30 fl Fixed -f option (from Anthony Baxter) # import Image import getopt, string, sys def usage(): print "PIL Convert 0.5/98-12-30 -- convert image files" print "Usage: pilconvert [option] infile outfile" print print "Options:" print print " -c convert to format (default is given by extension)" print print " -g convert to greyscale" print " -p convert to palette image (using standard palette)" print " -r convert to rgb" print print " -o optimize output (trade speed for size)" print " -q set compression quality (0-100, JPEG only)" print print " -f list supported file formats" sys.exit(1) if len(sys.argv) == 1: usage() try: opt, argv = getopt.getopt(sys.argv[1:], "c:dfgopq:r") except getopt.error, v: print v sys.exit(1) format = None convert = None options = { } for o, a in opt: if o == "-f": Image.init() id = Image.ID[:] id.sort() print "Supported formats (* indicates output format):" for i in id: if Image.SAVE.has_key(i): print i+"*", else: print i, sys.exit(1) elif o == "-c": format = a if o == "-g": convert = "L" elif o == "-p": convert = "P" elif o == "-r": convert = "RGB" elif o == "-o": options["optimize"] = 1 elif o == "-q": options["quality"] = string.atoi(a) if len(argv) != 2: usage() try: im = Image.open(argv[0]) if convert and im.mode != convert: im.draft(convert, im.size) im = im.convert(convert) if format: apply(im.save, (argv[1], format), options) else: apply(im.save, (argv[1],), options) except: print "cannot convert image", print "(%s:%s)" % (sys.exc_type, sys.exc_value) Imaging-1.1.3/Scripts/pildriver.py0100444000076400007640000003575207442710203016750 0ustar fredrikfredrik#!/usr/bin/env python """PILdriver, an image-processing calculator using PIL. An instance of class PILDriver is essentially a software stack machine (Polish-notation interpreter) for sequencing PIL image transformations. The state of the instance is the interpreter stack. The only method one will normally invoke after initialization is the `execute' method. This takes an argument list of tokens, pushes them onto the instance's stack, and then tries to clear the stack by successive evaluation of PILdriver operators. Any part of the stack not cleaned off persists and is part of the evaluation context for the next call of the execute method. PILDriver doesn't catch any exceptions, on the theory that these are actually diagnostic information that should be interpreted by the calling code. When called as a script, the command-line arguments are passed to a PILDriver instance. If there are no command-line arguments, the module runs an interactive interpreter, each line of which is split into space-separated tokens and passed to the execute method. In the method descriptions below, a first line beginning with the string `usage:' means this method can be invoked with the token that follows it. Following <>-enclosed arguments describe how the method interprets the entries on the stack. Each argument specification begins with a type specification: either `int', `float', `string', or `image'. All operations consume their arguments off the stack (use `dup' to keep copies around). Use `verbose 1' to see the stack state displayed before each operation. Usage examples: `show crop 0 0 200 300 open test.png' loads test.png, crops out a portion of its upper-left-hand corner and displays the cropped portion. `save rotated.png rotate 30 open test.tiff' loads test.tiff, rotates it 30 degrees, and saves the result as rotated.png (in PNG format). """ # by Eric S. Raymond # $Id: //modules/pil/Scripts/pildriver.py#3 $ # TO DO: # 1. Add PILFont capabilities, once that's documented. # 2. Add PILDraw operations. # 3. Add support for composing and decomposing multiple-image files. # import Image, string class PILDriver: verbose = 0 def do_verbose(self): """usage: verbose Set verbosity flag from top of stack. """ self.verbose = self.do_pop() # The evaluation stack (internal only) stack = [] # Stack of pending operations def push(self, item): "Push an argument onto the evaluation stack." self.stack = [item] + self.stack def top(self): "Return the top-of-stack element." return self.stack[0] # Stack manipulation (callable) def do_clear(self): """usage: clear Clear the stack. """ self.stack = [] def do_pop(self): """usage: pop Discard the top element on the stack. """ top = self.stack[0] self.stack = self.stack[1:] return top def do_dup(self): """usage: dup Duplicate the top-of-stack item. """ if hasattr(self, 'format'): # If it's an image, do a real copy dup = self.stack[0].copy() else: dup = self.stack[0] self.stack = [dup] + self.stack def do_swap(self): """usage: swap Swap the top-of-stack item with the next one down. """ self.stack = [self.stack[1], self.stack[0]] + self.stack[2:] # Image module functions (callable) def do_new(self): """usage: new : Create and push a greyscale image of given size and color. """ xsize = int(self.do_pop()) ysize = int(self.do_pop()) color = int(self.do_pop()) self.push(Image.new("L", (xsize, ysize), color)) def do_open(self): """usage: open Open the indicated image, read it, push the image on the stack. """ self.push(Image.open(self.do_pop())) def do_blend(self): """usage: blend Replace two images and an alpha with the blended image. """ image1 = self.do_pop() image2 = self.do_pop() alpha = float(self.do_pop()) self.push(Image.blend(image1, image2, alpha)) def do_composite(self): """usage: composite Replace two images and a mask with their composite. """ image1 = self.do_pop() image2 = self.do_pop() mask = self.do_pop() self.push(Image.composite(image1, image2, mask)) def do_merge(self): """usage: merge [ [ []]] Merge top-of stack images in a way described by the mode. """ mode = self.do_pop() bandlist = [] for band in mode: bandlist.append(self.do_pop()) self.push(Image.merge(mode, bandlist)) # Image class methods def do_convert(self): """usage: convert Convert the top image to the given mode. """ mode = self.do_pop() image = self.do_pop() self.push(image.convert(mode)) def do_copy(self): """usage: copy Make and push a true copy of the top image. """ self.dup() def do_crop(self): """usage: crop Crop and push a rectangular region from the current image. """ left = int(self.do_pop()) upper = int(self.do_pop()) right = int(self.do_pop()) lower = int(self.do_pop()) image = self.do_pop() self.push(image.crop((left, upper, right, lower))) def do_draft(self): """usage: draft Configure the loader for a given mode and size. """ mode = self.do_pop() xsize = int(self.do_pop()) ysize = int(self.do_pop()) self.push(self.draft(mode, (xsize, ysize))) def do_filter(self): """usage: filter Process the top image with the given filter. """ import ImageFilter filter = eval("ImageFilter." + string.upper(self.do_pop())) image = self.do_pop() self.push(image.filter(filter)) def do_getbbox(self): """usage: getbbox Push left, upper, right, and lower pixel coordinates of the top image. """ bounding_box = self.do_pop().getbbox() self.push(bounding_box[3]) self.push(bounding_box[2]) self.push(bounding_box[1]) self.push(bounding_box[0]) def do_getextrema(self): """usage: extrema Push minimum and maximum pixel values of the top image. """ extrema = self.do_pop().extrema() self.push(extrema[1]) self.push(extrema[0]) def do_offset(self): """usage: offset Offset the pixels in the top image. """ xoff = int(self.do_pop()) yoff = int(self.do_pop()) image = self.do_pop() self.push(image.offset(xoff, yoff)) def do_paste(self): """usage: paste Paste figure image into ground with upper left at given offsets. """ figure = self.do_pop() xoff = int(self.do_pop()) yoff = int(self.do_pop()) ground = self.do_pop() if figure.mode == "RGBA": self.push(ground.paste(figure, (xoff, yoff), figure)) else: self.push(ground.paste(figure, (xoff, yoff))) def do_resize(self): """usage: resize Resize the top image. """ ysize = int(self.do_pop()) xsize = int(self.do_pop()) image = self.do_pop() self.push(image.resize(xsize, ysize)) def do_rotate(self): """usage: rotate Rotate image through a given angle """ angle = int(self.do_pop()) image = self.do_pop() self.push(image.rotate(angle)) def do_save(self): """usage: save Save image with default options. """ filename = self.do_pop() image = self.do_pop() image.save(filename) def do_save2(self): """usage: save2 Save image with specified options. """ filename = self.do_pop() options = self.do_pop() image = self.do_pop() image.save(filename, None, options) def do_show(self): """usage: show Display and pop the top image. """ self.do_pop().show() def do_thumbnail(self): """usage: thumbnail Modify the top image in the stack to contain a thumbnail of itself. """ ysize = int(self.do_pop()) xsize = int(self.do_pop()) self.top().thumbnail((xsize, ysize)) def do_transpose(self): """usage: transpose Transpose the top image. """ transpose = string.upper(self.do_pop()) image = self.do_pop() self.push(image.transpose(transpose)) # Image attributes def do_format(self): """usage: format Push the format of the top image onto the stack. """ self.push(self.pop().format) def do_mode(self): """usage: mode Push the mode of the top image onto the stack. """ self.push(self.pop().mode) def do_size(self): """usage: size Push the image size on the stack as (y, x). """ size = self.pop().size self.push(size[0]) self.push(size[1]) # ImageChops operations def do_invert(self): """usage: invert Invert the top image. """ import ImageChops self.push(ImageChops.invert(self.do_pop())) def do_lighter(self): """usage: lighter Pop the two top images, push an image of the lighter pixels of both. """ import ImageChops image1 = self.do_pop() image2 = self.do_pop() self.push(ImageChops.lighter(image1, image2)) def do_darker(self): """usage: darker Pop the two top images, push an image of the darker pixels of both. """ import ImageChops image1 = self.do_pop() image2 = self.do_pop() self.push(ImageChops.darker(image1, image2)) def do_difference(self): """usage: difference Pop the two top images, push the difference image """ import ImageChops image1 = self.do_pop() image2 = self.do_pop() self.push(ImageChops.difference(image1, image2)) def do_multiply(self): """usage: multiply Pop the two top images, push the multiplication image. """ import ImageChops image1 = self.do_pop() image2 = self.do_pop() self.push(ImageChops.multiply(image1, image2)) def do_screen(self): """usage: screen Pop the two top images, superimpose their inverted versions. """ import ImageChops image2 = self.do_pop() image1 = self.do_pop() self.push(ImageChops.screen(image1, image2)) def do_add(self): """usage: add Pop the two top images, produce the scaled sum with offset. """ import ImageChops image1 = self.do_pop() image2 = self.do_pop() scale = float(self.do_pop()) offset = int(self.do_pop()) self.push(ImageChops.add(image1, image2, scale, offset)) def do_subtract(self): """usage: subtract Pop the two top images, produce the scaled difference with offset. """ import ImageChops image1 = self.do_pop() image2 = self.do_pop() scale = float(self.do_pop()) offset = int(self.do_pop()) self.push(ImageChops.subtract(image1, image2, scale, offset)) # ImageEnhance classes def do_color(self): """usage: color Enhance color in the top image. """ import ImageEnhance factor = float(self.do_pop()) image = self.do_pop() enhancer = ImageEnhance.Color(image) self.push(enhancer.enhance(factor)) def do_contrast(self): """usage: contrast Enhance contrast in the top image. """ import ImageEnhance factor = float(self.do_pop()) image = self.do_pop() enhancer = ImageEnhance.Color(image) self.push(enhancer.enhance(factor)) def do_brightness(self): """usage: brightness Enhance brightness in the top image. """ import ImageEnhance factor = float(self.do_pop()) image = self.do_pop() enhancer = ImageEnhance.Color(image) self.push(enhancer.enhance(factor)) def do_sharpness(self): """usage: sharpness Enhance sharpness in the top image. """ import ImageEnhance factor = float(self.do_pop()) image = self.do_pop() enhancer = ImageEnhance.Color(image) self.push(enhancer.enhance(factor)) # The interpreter loop def execute(self, list): "Interpret a list of PILDriver commands." list.reverse() while len(list) > 0: self.push(list[0]) list = list[1:] if self.verbose: print "Stack: " + `self.stack` top = self.top() if type(top) != type(""): continue; funcname = "do_" + top if not hasattr(self, funcname): continue else: self.do_pop() func = getattr(self, funcname) func() if __name__ == '__main__': import sys try: import readline except ImportError: pass # not available on all platforms # If we see command-line arguments, interpret them as a stack state # and execute. Otherwise go interactive. driver = PILDriver() if len(sys.argv[1:]) > 0: driver.execute(sys.argv[1:]) else: print "PILDriver says hello." while 1: try: line = raw_input('pildriver> '); except EOFError: print "\nPILDriver says goodbye." break driver.execute(string.split(line)) print driver.stack # The following sets edit modes for GNU EMACS # Local Variables: # mode:python # End: Imaging-1.1.3/Scripts/pilfile.py0100444000076400007640000000366107442710203016366 0ustar fredrikfredrik#! /usr/local/bin/python # # The Python Imaging Library. # $Id: //modules/pil/Scripts/pilfile.py#2 $ # # a utility to identify image files # # this script identifies image files, extracting size and # pixel mode information for known file formats. Note that # you don't need the PIL C extension to use this module. # # History: # 0.0 2025-09-01 fl Created # 0.1 2025-05-18 fl Modified options, added debugging mode # 0.2 2024-12-29 fl Added verify mode # 0.3 2025-06-05 fl Don't mess up on class exceptions (1.5.2 and later) # import Image import getopt, sys if len(sys.argv) == 1: print "PIL File 0.3/99-06-05 -- identify image files" print "Usage: pilfile [option] files..." print "Options:" print " -f list supported file formats" print " -i show associated info and tile data" print " -v verify file headers" print " -q quiet, don't warn for unidentified/missing/broken files" sys.exit(1) try: opt, argv = getopt.getopt(sys.argv[1:], "fqivD") except getopt.error, v: print v sys.exit(1) verbose = quiet = verify = 0 for o, a in opt: if o == "-f": Image.init() id = Image.ID[:] id.sort() print "Supported formats:" for i in id: print i, sys.exit(1) elif o == "-i": verbose = 1 elif o == "-q": quiet = 1 elif o == "-v": verify = 1 elif o == "-D": Image.DEBUG = Image.DEBUG + 1 for file in argv: try: im = Image.open(file) print "%s:" % file, im.format, "%dx%d" % im.size, im.mode, if verbose: print im.info, im.tile, print if verify: try: im.verify() except: if not quiet: print "failed to verify image", print "(%s:%s)" % (sys.exc_type, sys.exc_value) except IOError, v: if not quiet: print file, "failed:", v Imaging-1.1.3/Scripts/pilfont.py0100444000076400007640000000173107442710203016411 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/Scripts/pilfont.py#3 $ # # PIL raster font compiler # # history: # 2025-08-25 fl created # 2025-03-10 fl use "from PIL import" # VERSION = "0.4" import glob, os, sys # drivers from PIL import BdfFontFile from PIL import PcfFontFile if len(sys.argv) <= 1: print "PILFONT", VERSION, "-- PIL font compiler." print print "Usage: pilfont fontfiles..." print print "Convert given font files to the PIL raster font format." print "This version of pilfont supports X BDF and PCF fonts." sys.exit(1) files = [] for f in sys.argv[1:]: files = files + glob.glob(f) for f in files: print f + "...", try: fp = open(f, "rb") try: p = PcfFontFile.PcfFontFile(fp) except SyntaxError: fp.seek(0) p = BdfFontFile.BdfFontFile(fp) p.save(f) except (SyntaxError, IOError): print "failed" else: print "OK" Imaging-1.1.3/Scripts/pilprint.py0100444000076400007640000000437307442710203016604 0ustar fredrikfredrik#! /usr/local/bin/python # # The Python Imaging Library. # $Id: //modules/pil/Scripts/pilprint.py#2 $ # # print image files to postscript printer # # History: # 0.1 96-04-20 fl Created # 0.2a1 96-10-04 fl Use draft mode when converting. # VERSION = "pilprint 0.2a1/96-10-04" import Image import PSDraw letter = ( 1.0*72, 1.0*72, 7.5*72, 10.0*72 ) def description(file, image): import os title = os.path.splitext(os.path.split(file)[1])[0] format = " (%dx%d " if image.format: format = " (" + image.format + " %dx%d " return title + format % image.size + image.mode + ")" import getopt, os, sys if len(sys.argv) == 1: print "PIL Print 0.2a1/96-10-04 -- print image files" print "Usage: pilprint files..." print "Options:" print " -c colour printer (default is monochrome)" print " -p print via lpr (default is stdout)" print " -P same as -p but use given printer" sys.exit(1) try: opt, argv = getopt.getopt(sys.argv[1:], "cdpP:") except getopt.error, v: print v sys.exit(1) printer = None # print to stdout monochrome = 1 # reduce file size for most common case for o, a in opt: if o == "-d": # debug: show available drivers Image.import_plugins() print Image.ID sys.exit(1) elif o == "-c": # colour printer monochrome = 0 elif o == "-p": # default printer channel printer = "lpr" elif o == "-P": # printer channel printer = "lpr -P%s" % v for file in argv: try: im = Image.open(file) title = description(file, im) if monochrome and im.mode not in ["1", "L"]: im.draft("L", im.size) im = im.convert("L") if printer: fp = os.popen(printer, "w") else: fp = sys.stdout ps = PSDraw.PSDraw(fp) ps.begin_document() ps.setfont("Helvetica-Narrow-Bold", 18) ps.text((letter[0], letter[3]+24), title) ps.setfont("Helvetica-Narrow-Bold", 8) ps.text((letter[0], letter[1]-30), VERSION) ps.image(letter, im) ps.end_document() except: print "cannot print image", print "(%s:%s)" % (sys.exc_type, sys.exc_value) Imaging-1.1.3/Images/lena.gif0100444000076400007640000003772007442710203015557 0ustar fredrikfredrikGIF87a€€÷C6©‡€´ºÜ”D<Ò‡[šg^zRQÓ£€ÅmOó×¥”f„m18»¥ Ñ¤‘ê¼€¤v\͉|š‡žÝ½¨‰n}qCMЙssSw\7I±hR娎™XLì¤j¸ˆrÊ}Z·Ž–÷Ë€oE`×sW(:â˳ä‰`°waÓ°š­ZE–x“ä×ÈzbˆÐ›™—¯õ»{¸ˆ~шi®if˜hr€dlÜX°xp¬v„ã°s•Y^†EBŠSNåšc[/<í¯jïϬä™~l9Oôټɀf–§á¼˜Ñ³®¦ˆœdCVä£i³oXÏ›˜ÑoЩ°ì¼¦„Ut~Ma¨¥Ã‡e±€rL*AÕuRoLD#?ëßÍU)E˜ˆ®¤‰¬¦™¹°ph—``}=>ĦšÎ‘~Œw”äa±€Š¤vl^lãο܂gL-Oì׿¼bGL$9|6,´¥¼Äš›•põÄ}…\{ĺ¼d8Ed*7œšÀŒdeá°ü¶dôÜÎÔeܶ¬d¼ª íªlÓ¶¡äžm>Rç¶“ºž¡L4Äs¤pb|Ziäˆm¬–ŒL&E¤~\ܶ˜Œ‚¤,€€þÉ”GÆ 4:øè±¡gšbW€ÁÀÉD$JtøR,A^tBò,“C‚L)’@H°XŠ S$H‘¶øŒ€>Ÿ™AóŒ¡:Ž>[z$Œ?a*H,VW1eÖ:t R¬£×cÅÈ áã#¡A¡ÏŽè£‡6IØ1Ã@—.$ÇŽmì0r¤K:* œÓåÍ }Iúõ¸’$±‘ˆs, I%i.]j4©™¤G†šòÍn’tÕZbu×®$‹ RCQ¢:tÕAF<=:¢Ó0¬.Œu5*öاK>¦4ÜÁ¥uÄÖG¾ 9q\ʸþ"/öâY…#h*èþ¬Û(3–¶r µÄñ׋iÕ¸ƒ2îì°Ã¹é€Ðg|ÏððñÂpÜps€Ôu .VñÕ,!MGÛSH'qø`tt@ÇGtŒHÒs|õÄwQ„6i¥•àG<³^R|Tp”) _M/îל%u™d’äµÌ JøðŒ<èeVZfô_JT46<€XZD 7"T)‚;Øìࣨ¥ ~Íi Sœ½öâuaÓsRítŒHõ_T®__7„ù°QÏÄ1’|5˜ýŒ–WÞ|¥nJô1Ž ¤©Ý `‰ë‘/¿œŠº½{”@ø¼iaZÁqN ‰WU @\1pÁËñe "²žœ&G5~a¨i$!IŠ€…cñ ,ÇøÃ2‚ K¬O}9Ò Ø”¢ H@Ú‘‹Ê áþ¸Ývpl¤B;ºÔмå ¹1ÒP/“ùÌ^ê—†JH"ì¨(&SäÄ·„%Ô¡UÑ"d¢Æ0ÍkÇ€AG^pŽs x¼’ ¤õAãІà1 h”Æ Rºª$*€ã|¾¤ƒqìˆG| ˜4ð³æEP6BCä@”"Ìñ 0–ÀB=ºÑ€˜ þ L€‡näEF"tä6rŒe a@ŸìȃŒí(fGäׇôH;üÀq”Á¿Ì-Ø”6D€ ltimÁD4¢¡ƒ ØìKã@½fE—â"EïÜ¥ˆ ¾¤ÑaÝþXA:ˆÑ€@T"¯\AZ9 Á ÀÚr¢¶8cvuz†jhÇ>r,)ÚˆF ÇáÌqÀ ³Ð!4P¨Ü½ Tع™»rÂa˜HÚ8Ê N/Í`ŠÉF'!x/ZႃôÕÁ`A K©´D,ÑnX‚®|e<Ø<Œ@¤¸¥d`Ñ4èÜù´qŽ=ÅؤYC%P#}ˆÎ¶Dæ‡bì UJ…±17*@ò€P$.þ@ΆxI˜@€Ö¡+PˆpH“Ðø5¹¡tJàÀ6‚P‚ Ð X`%-ÜT‚þÀC< ‡1´V0øþ¶ñ…ÚÚ¶—™³Òš­¥Àµ†À}Á8†« h#dqˆÃD¥®TÌC@C7õÀƒÜà"¸˜)<œt2Vyõ¢]žJ~arpøƒ5ÆU! Ó1êÀÊ:´2ñð0Œ­]FÖt ¬eï‡ÀøÃùx+Èsd+âLæ ÀÑöa"kr·¿nóeIì¦àE€bLjÆÕb¼? à»õâ0 è¼ zCTCX¾°õnc.@*1^0 ¸2Øïò+9ØB„(2;Ï=ä@´Á‡sôQ ñÃQ  \2’Ì:ø@þ ^&1`³›nÖk#E€—b¢9HÃfʃ†°Cò*T/P|«mÔâä”V ¬CÖø18@Œ XÃh,áÊÄ#¿cˆGkG0` W¸‚É´†e`à0è:ró ›ä$nÑ&ž m÷kÝ5¢޹P¯u‡#.0*à ÆÆ:Ò€‹hxiAÆÃÀ´5!@|‹pªÁEé°&¾h#/²X‚  ¸àÄ -ŠJ‹iø cð¯¨% þ¢‚¨E#4@}Ñ…äÀÀ ¨‘+iƒ—ÆÅD1A\àÖÖî0©ïôÚa11TþР‡Ä¦A8ÆL½tØãM»Š€Ð¡ÿ Õö‚y¡ÕŽ•ÁãžË÷ùl;†9Aþè· n‘N¤ Ÿ¨Ò0rÀ æ[ÓFYžámÐøÃ úh6@¢c­Ï*Ë:<î?9_ ¹»€~@…n”œÄÑvµûàD8y½^U}ɦѕû;]8¢•/HBG•ïHZH‹°C——Àò@Np¢ ž÷|>ÑpäB’¸¥Ü Ä0‚pŠO½Æ:ø€ Gˆ›vû_‡_v €àH­Àß“7Œ°£K¿!Ð þðònÓe"y‘ìš8þ8»?ȆFAØ ‚XÔÍZB©J€€+‹¾‚J8}œ€ü=Ÿ‚Fá 'Æ$ôìÏ 0à” vÚ úPf—I|ÅMww"RqÆvIpÄ0ÜÖ|{WS‡ebv€rƒó3:EóAå†n)ÔJRkò– Äð÷ÐB­à@7#ÐrÐtrÀƒNuÐ)€vpÄ7Bº/€|5 ¸@ ]Gq˜@ Ú0k|€ýóH¼ã)uÖÄæP÷Pİ­B/(GX:À7|ë@/‚SEíÔ$k²&:–_€’Û ~úñþÝpƒÄf` ­@ •Àƒ’ØdrMzõw °ŒÁD*»‡ Q¸¨p8fº–_`RØt7bH"pT`ÝPÛ`dy§<Ãp }À,'/Ès‡b/tAs;–=r!¿„ –,d Í:A€PÊÀoA(WuU0óGœ@zwP8@ES uN„€'ip € ½¦kèàèðaèp‡ `lbðp÷` Ipd@‚rÅ@N\Â7âT‡ŒÅ dsø3;r!Sð3ð¯†5’Ð÷Р𦠱 u² X ÞhþP”z•ò÷tõG8à‰Ô`®GÔ€°( 0 íXC–ibT°WŽð*Õ;bNÅÀpxxÍ‡Ñ ^B:|@ †rÝ&!"n²áƒ% Þ‡42Ö` ´a \c q­0@ôÀoðdòG#ÐtòGzÀ”@mVØpÏ”ÀRîtÐãD w–;àÐM©0+eDŽð u` Äp`ddÐ|y—p€ sH SÄ|„S!0ðPù¦`/p”Pk¢JPÝ` H@±0Ž|éZ”‹°Mª`T` Ÿð Óù Û47(…MÿÓH½“ 順ݕ+p+Àmfv¿È7Ö’@ëh–1WLj`õ+³#(¸° «à,Ù%€I {iZ & 1É P&•XŽ˜Ø„€ —7 ¡Q8”U2Ÿ×mÀR° ² bðHà‹ŽPÐ k˜•G°÷ÉIÜ0 õ A@|0}80m:ÕIh‰â~ í¤c#t@ äP'†d ôpZ eªy|É—M ¶<ø¡žõg@ »á> °¡ 2Ðþ#@ð W €WbÀ;hM°(V°–à+@õ™•à€0 É pqH@`R‡!ø@…ójVêj³€ Yq¤`Û %ðH@Y &@ 0  ì°ªy±§s„ÆêyLçyp '@dA*f{;£@åùyQ§b ]zÕM‚M0 çÇiFZ¤ÏpcRE0ŽÂŸ H°ŽÊ“p„cp¸ðja ' $ÇB±ö_°ŒYì°±@tZà&@ h0ü6§CࡊÈ:„£@Ÿ1-˜ 3@œà~ŸP§NW gÐf§þ£Y%’Py˜j¤Fz;•¤„• àEÇ“ÌW8Çð3â¦c°3€e¹ !iiÍ@bA©­YÐ Z0Z°µZ°&À—ÇI˃u „QV¨N‡—€õЯu–X˜§y® ‡ ¡ð 2Û hphPŸf°°WwE']å}@ Ç´%h/'`8x<À–Ç([åó›æƒÄ€©çPTÏ ^@Y ­Ð¨Û°[±QÖý`z MƃGq+À cð_) ‰BXŸ ž *•DàU+™z©…›°S€¸Ñþð ÂN@{z>s/¯Fsà GÐ4ä̰ÎX –€(JPÖ€ @& üe D·¡[›ºZðµx±²Ôd¶¨0&p€r¸ú»À+mÐw d¸™'å\“ Tï{©7K©ÛHx÷ÙÉ }ÇÀ‰ÝAÀpö ÃàÖ¯îôC@—¸@ƒx_ bÑ+÷k àejþà·*y“D`¬»_¶PPÏ™µ•Øs*?XÁ@ÀDD†»“ ?`Ó@© l³6[¸ê@^‡ð“ ¸0L½†ƒe~˜ 0þXFs fiÛ ’/ ¿Úp~Ip©K°º»*À½Êd@¨KÊ ŽG±´Dñ@•Ðy­pUÐi¬6É¡…y²¡ Rà°óàthðÁ Œ©‹(+@8Ÿg.µ0… œ8¥D8†GÐf°‚¿ÔËÀ’¾¦ %PVÏ ¥…à­ðÄd€Ä&»µù¥¿© ñ0ÀE ¤FgŽ…Z‰•˜¿<ø °hM¨£NP®+ %õù·§iŸÏ Ü ýjIp@b ‚ Hp‘À`hTèk pÐGãp €¾ƒÅB B _PuT¸ç0 B¬‹°h C\Òàþìຌ¡&` Ðñ0©%‰|e¤ÌÀ+`J Ÿ`lÈÖ;N@+ + Ä€+Ä!œª‘ÙÉ7}¶½È“<3V½UýWÑùØÀ ð*9,ÔBJ•dp~Y€GZ %BìYP¸D\¦yà«yP×±Ó <A(Ž19˜œ`yÛ…WÿS7¬< m ›ÏFJñQŸ…›¤¢S0=Ë7ð€ €7hSÊS>à ЭPk¸ °†:uB@ 1ƒÐBS{+ù›@ ’lÒºø›³M °—cÀƒ®UP{-§ŸG y0 Ë D¤.TÂWßþ”ºõÂö¹ÛXEƒ§¸ÔUÐ_²Âù*“!]= fðÕ¥îŠ  °p±ÁB˜õc5xY ÛÍkPå`2+`Öh@Û °+@ þ0ZeÞŽÈrзìÐŒ‹dHF4 eõ¾úL¸Œ}Ýù<¥ m¥˜p}öR™=Õ:Å yü*­ã ®PN¹!ˆÑˆ4` ¾¦Ö0d‡¼TV 0pÕÐÁI  Û€¿ê0 u]?X0 ràÈ ýF‰¤Œ±¡—´WàŸ©¼M÷QË7kŸ"žÝFf¤tQÕ Ð$ Ç<À:@}þÙI†ã3 D¦Ð®@I˜P`<¶ ðÓ ƒç` ’ÖP ½Ð I€ € p Þ0 àðéž ØžÆoCpUb e’ˆ²œpw% ŸÀaÛ$•“`¤FÌØŽ=âm|Ë1W/0˜N ± fpÇßUÕä3É ¦` …>S4ÒLø ÁùEÕ0 ™à Õ ‡ §² ? bÀ]à EP pU®E‰Æ áž7ÊWÐXHà=€5ZØè–ༀkŸn^¸FÊðµá@x1ã  ç%7E(W›2^/' ¦ðà S`¸Pþ±¦’ÄP 0dÒø00 Ûp‡°N  æeðe =Œàpt\>ŽýÆogK¨ø‡r±CÐIt¼œ)Vp~õ©«еìæl¼&Ï¿Á y–¤­S ãi ¯–`>&ó0 ëEd?L ƒ‡p ?à?ð À Âð§p * †À] ’ ž¡š'x Æå  ­¢H` G@r€DÿsDêÂb@ÔüDöÙJGÝõÛH µ÷ÒŸÁ7­Ðg:àËßuÐÙì<ò¦p GéGÖðè/pþÐ ² àÐÉË1àŽpøŽÀ*­° µœK üUùÆ-g`1àXÐdd0 6b@ç§­ÔJô»ú+Py±b-K´0`@ \˜6Àƒ£xðK‡d¸Á˜@&2 E8LQä™hŠYæ‹Ò¡þÁšLŒQÀ +zQ`ž øfžÀùA(æG!Ph@ ⎈‹H.õS¨#ŽúÃåc*óc–ƒŽ±f™ â‹D8eGĸÀR¦ _œ˜CF&‰"Ð9¦&¸,¼à×ßÚhà ìã›otÀ×9$qZ.“#q/‡6hÑ O¸€„-C*Ä!†*„‚ "¸€¦ãˆ ì€+ˆ‚G_g9üJxAäA r ãS‡0¡ÛÜl,ã0Øç Ü!4 Ö9ìfšŠ¸ ÎÃX]*€«¾T H¦…{…Ãâ8A$óÁÑA?`Fj9R™?HÂÚ@Ã3ôû…o PBQº|ðC ˄Հha #ȃø£EPaîX€5^@: Czx.50@‰þP80H„`”°:ØEh±»ñEWº"o_4VNCÖ îåFÂ_ŒaÏ™¤à¾·Ÿ4&e' G60ŽgèÀØø?,à!@¡ ¾@ ¾:(-ˆü1¸®ÞßV¼¤¼Úº{0‹cü×q7¿áÞoôè,Ót„7ˆS(•:oä\ÁÓÛ pÀ.Àaœ è“l3€4¨3e8Á0è`Š/hC×PBÈÅ! ðC§(…v i1ˆ€av`pœHÛëÀÆr`Ãs‚‹H,¾ Ld@@€À¹~`¸þmØ\Ð8½mb ‚ ^À¼÷Åßç f+€…®]Q ªö#ë¤J<ˆê ÐAÖA+xTÛq„0Ä Ž.th/¼̱# yb¥ÝŽ‹.E $âD¾@ úÐÃíÎ+  8P EÀ I$cÝŸØ'à:¾µ°*'T‚n¸‡ƒã½U €àˆ„»‚uH†çh’™”9À€X+È"h;¸€P6€wCé!è‚ ¡Žy@›Pè‚p 9† ƒ€€a8†ið9hz8 ƒ)€…å*©Øcøþ…X° „‡^Ð…$ø8 k*€Æ2'¾¸½(i‹:ÞÂ(ø´ðà H†uø¬I‚ƒäƒ h9† IXih†O‚|ȉ¡°€.0¹Ré ´ ]¸†1Щ\€ mxN°k‚e mhN =x…6È€s‚8E@1¶ñ +ÀsÈU˜)l˜‡( Pã‹HÀ\á %Fåé:,`‡Vp€ƒ¸ ¸ˆuÐ@‘É’¡ƒ4H†1A€? €:˜†øØ>w‰„Gàw!š2@!H A= ±‡—»20ÐP€jþ88€D8‡sHH: Xè„ À,XŸ ‚ÊJ0<°9˜ ˜4 ;0½i‹(I@ͺ Æ’›0\Fp5áë’Ð@çèÀÐ?ä†Äi?4„Öƒ‚D$Cp'ð„T°q0.†Gˆ6! VË =Xj°ਠð H4-&j †NpHÀ!àÊ0n°U˜;˜‡Xˆ^’ì(婺R3FÌ¢…HÉ7ŒvÈ…1€Éht€:¼FÀ\¤=„‡  ;$8†/8„%ø…_.Ci‚GàGèg0„þU¨"8ÓœÂë 9ˆ@¡Að/&aÒM/@ƒƒ,Ë)@ËWˆ…XHÍÀÈ?Äò‚r0¬J,€¡pòKKøŽ{¸bà=¹!LÃ̘üNk<™u L™çèà ‚fxLØqa(5s Yè‚ÑôÌR`~¨¦j’‚„¤H'ì„ð¯ÌzÈ€X &a:Èsè„N^ Î, í„Qò‘o-À‚_Üwèb5y¡ ¸Àü)®‹œ ‡ïOƒ1>H; J耿á@†³L '8…S`ƒ.8…”†.hþGð YXG¨`àëb‚!FÀ À:Ø ¸†9—v *e )€Pà$˜Š:ÐŽdÀ…)`E4E=xP8&y3m :˜s€W-¸Sjø ‡È»Ò’°. ظ%8ÛCÀè†%FŸšÑV°Q ‡0Jµ;†`pQè‡à¡ˆèCásŽ þè‚&0!p°C‚&è ¤‚Ѐ Èë ‚míÐ'¤VlÐ4íM`õ†7:Ð/xN‡;…:¨1p¸hZH¬PçéÖ¬kZÀÎä:¹!ƒï|TH×upÈÆÄx¥ÖšIêÔ ˆ&pc€‚Tè‚2X_PÍy”†äÄ®{  |ˆ«L˜H?ƒ… †ÕA&`%ƒ4Ë'¤ˆ;µ„s€…? „}K{HxX¯UFú79¤3°8¸8×\P׃ƒÉÃ7Çô¨¤Ú€)¸Cþ €cð€ š Q.P9ˆ:!ûÑ(*†P° €bè~˜ŽðPø‚¸P4ÝØ ð=ðt†„^•‡6x4HŸ#~ Àw…©Û¹(b º(5ZhÄZˆ\îôÙï¼\uÕÜý(Zv[€/øÕ¤jÚuXh‚S‡Ð1UxÜ#°®^¨nê²3Zx€¨w¨ØX‡u¨MdEtЇ͹•8EVlÈNð¨m8‡Qü! ;À{€$pìP¨3è pbQ<ƒ à€màxÔG]WuÍ” êÑÉÛþSy5ç™>rh*IH%Ý"VO(ƒK'`—^hÁ±`Ó±u`-ЂrÝņjD€)˜X mðÕ4Õcj@j¨ã” HK †cp´ð‘ Iƒ<€é°%ˆbtÑ(᩼‡<3b#¶\ùMÍíy²9Æ´ƒX^/Ý"rX†j`†Sˆqà‡ûô.0H`P8,ër„B`Zð‚!`€PUX1™ãŒ½c}Ðhfb}†s˜˜™‚aòBRql¸¹=ÍZÉ àÖèËæ ×”$å9‚#ZÍíäÈÜði×wë aþœü‚áSk`'•¥˜ ˜!P'@PH…-(Y¥F˜oXƒÀN`zl–d¾ÐÛ|SÜ$V>àƒƒ4ÞN° ‚ @Bþ‚h; ‚>ݸ‡T(%§Rk À¬€3ð¦ÈÝÊEbußÌM€Mƒu 1`³,ñ‚àjHåeHGhqàð„ ;!Hi@n8ä (0 (<ž­Ž+8rcHj@<æb%V4V`‚ à9¨[%€…+h0à†` „>Èeè]Ñ ÀNœÝ½›â€Ðä ÍÜ0H€xN€vM–w†þ5Êg8àƒhþ8$0 f†²€2†R@yø?ô€n´þH•Ù|XˆŒu[}Ð}Ðäåˆæs`#Xì&èÐxvA ø†Ã¶K8oP‚ÆÆº ìü¦{ði¨€\0…Ðl¢6êHN0Zwµƒ+€€gp§ˆh €Šk¨ J pp¨ d[+`¦^¸‚rHB¸‚+)ÀQ €oÀU(€ÀØâ†SHî7ÈhÆ¥€Èl@j  —æœósWÔ〄Æ&2ÜkÜÊ2oP†juídÍøN-ôQJ°n€6‚þSίЀ„køƒjPÛ2‚9@Ug‡RðO˜‡iÀƒ@€u¸"ð„à¶lxXU>P cã%¹&Kc EmÐ>ÐsˆD#B(¼ƒ½¢ †°ˆ‚؃>PÜ“l¬ä©Ûƒ#Èö–gyòÍîäL}7 xç@ªçØ€X‡ fH‡Ip„T`YX3Õ€‚Gä.¸sˆˆ…Àž’ <²(táMƒÁh[:¦L`f@€ØÕ)h?·€;‡bXëTXJÈ(€(EGC¹‡:8œQ¹±MN̽Üø„ø„ð‘þ  ÀÑF;}Ö€$X˜†&† ˜ë{Ä_€a(ÀsDІNh À€±èSÁ†VEX›c:ކ0nt脘‚‘Ÿf^ÅÍN€}Pv¹€Cþwø†À†3¶ƒf €qø·@T,×T÷3˜Qðq‡ï ÇôX悸‚x&2‚fÐiÀ€I‡y~0p,i˜ƒ«ELø‚Ѐn)¸€#‹êÀTo.Z ˜‚2²ì`t˜f‘ÿ`Ec“Ö `—³8 ÃþRÉR0ƒ>È:5̽6,ïÈ-†VÐìJçìN® XMwþk„€#pŽ=ÔM©ÆCð_1@w¸)íC˜g(.(ƒ$(Ü$x0XýiB ¸O…oØ p×…ØUX0~¼'K¾×A`~}8HX—už£Kƒ`¸‚T €·`ü('‚s¡ü&¹Ùƒ\ðK?úuwïÈãSk„…RþNƒEX-+«Í)ƒéaðCègx„¿°ÉêÂ…TØv,¸,U0*Ø ä– (_èÌèD휶N3fL)YÒÇ9%î‰Ñ; 8®PÈán^ž,fB„XQç ZÝh9ƒ…C”¹0eÚîS‚1aÂŒ˜*f6U80`þ¢íœ°pôÌÙlR“ÒÄ0šãÌ“ÎA™c¨œ´¤L)Û!f‡BÀØR¥rGå°lë†aøƒ‹,:Ô&SFéCž<_ìˆ %æ06w9F³³`»JBAkEÏ:!°=úàA¸í@eÆ·ï؆ç†Ö3=^Äòy!ó PdˆñÅ‘¬'¤­B1G²Læ¢T¸ áà„YwÀ„IÅQÃý¡Cç…6üèÐ<ó‘Á fçT gçID;WØaG0P!‚ dÐÒ-ÔÔlžå”4M%ð[=Œ8U.ù¥À pذYiàÀÌ þæ9‘ŠÂtáÌ/Ît!Ä*BÌáAÎÄ@büõ{"P!œaî¤BI0”ˆ²Î pôÂ9ç\–È“AçL#åž\0¥;;\‘Ã:vä #Zø4!-®Ý3TÝÐ@ýDÆn#6…"ŠáˆÊ;PÀÍ1˜ν³Á:¤ªg b~@Aâ@¢4,…_¼b0F WHñŒJ½†È‹‘Pc³žõ90ñŒ[㓾UÎ/xÑ˾¢½Ú**@ŒXÌÍž]öð€ÜÈðˆ>@ pƒEH '‹ªÁg1¨£ ÐD(ì C·`$Є õÝóˆ!§àÀAcYdC$P€1XÈbÈÁ>ª8`Ã@(DÀ ŽÀ"nŸþµ²Þˇ‰—É ôˆ¬L ßýŽÀdGC²‘=f£ÈnI!†ñ?0~6„ž¹qs H•œj\ÞñŽØƒ€GXZQtmDA ¡0¤EÀO ãR+èý‡¸”ÆõÀ¯°@$›˜9 ípÀJ ¸@µ}@@ƒù™A1ü’ÝÜ!8å€0Ú0€ÔÁ°ÐAXÙ@+ðÁ8¤´˜yœ‡Â(è8‰4'¨@A)Ô’Œ¥2¬AM)P, ƒ}Œ(VÃE:(ŸÛEþ­=Ã3È >ç0ýÚ'A€2Øh•VP©Y,^ÌB;Ì‚t€2` `œÀ…Õ–.ô‚=›(îCD|^¦œxƒ9‰ÇXÏÈ‚´#€#´•!\‚4TAgÄ €ôC¯¤Âãh,¸0tÀ Dà ÐÚ2†¤aÿðaPYd]ã î—àBà žÓ(¢&¬™9Iâ».Ã\A;‚À$Ü€.L@õŸÕP,ðAX˜ØhÃ4P@ì?t+\À°U¤HÁì@è@耀4lÁ„ÂɼÇBˆ@;Ã.`Ãq8þ£²`ÂdœC4€6 ƒ²è|á“p/ÈÁô ¢ tÀ=ÔAQˆ79 ‡pôËÁÙùíä‚“CÎ+%€À¸Á>0‰Má¼ô‚y B*@ZB¼Ív¸…¨ $ D¸Ã-A 6l…uÀ0ؼ@_þ%­C4¼€_* 4R´‚?Ð3 â [ì>”Àì ¢"*OØã™ á0p7d8éB„æ7PÚ7üÙiâ@l@XðÀXhC7L‚_ùÅ\€AP‡_8‚8˜‡!”,0‚tÁªÔH*ÔRhh<.þ¤‚ ÓÃM' ,ãJÜ~<ðCJ®$ ê×'èØ–8­Üdz_ô@80àPØAà7L‚.Àœd¨g¬0€¸覰æ8xƒ9ä‹-‰Aü_BLZZÀÞ0°UäÔ]ê•(àœB*ß ÌHè%&(c3jÃÍ]4„ P6ÈÁ¯µä=ä€.à€j›<@°F@„Aœ$ƒÐ`ê&þÌ$¨+èR(@*샼Ã.ðÁêA Àƒ6xC/„Âsu näñp’'xÂ)TÁÁB(ØR-m‰ðÑ¥„þòÁ`¢Cž¾]ÜiCÍ\ K ÁvNß mQSD†.ƒeZæ,øA®%¤A\>h€.h@ôB¸å{ì¸AP.€… üç ”Ã< ŽÇ Ä—ÏtÌ—zB<4äƒ0Ĥ@ÊàhÀiˆ6 AÛ1cs¦^‚$´Bã`P•± wêW¤Á&2iI„_;|€Ë¤(ØA¢ªëå !Ebƒ‚ôB¸A<¨ªúLa6ð¸@+ŠtÍytAG¥ÂÓ6ZöˆÂ®B)@Dja£ÉœâÂp•},k_b`ú¥òñ©å%|=Ö Œþ/pÂŒ40)> ˆS0èŠáä˜)ø ¤ÊØ 0Íhð‘é ˆ.肨Ã;˜&à‚ð€:< XA×hå´8‰,Wž[^€4W\‚®€Bˆ­=¤}€½@žÂ5 Ã8LÆ8(‹3ê€6ð>PdÅh¡ ¸+>l*¥ ÙÀ.h@hÜ”¶ÍélAXPAMlÁm<ìƒí‚$$„'èJê>‘Û˜ÈU]BsiÍZ’p(ØÃ¬ÚÀG:ãdø¥_b­a‚ÚÎZ˜AÈ*ïŒ@ɾBþØAä“–Ø™“)ôÁPB°(ªºêÂ7 jàC/0°P@°‚&Ü£.à‚ì+8€|AêÍff¹Ä—""è9HA>\,‘êë°K,&ÛnÐÁžF0c‚ñò©3FC𾵌?0 rBwÞ‰í+,©TÙÀ„™–à€pCô~ØA§ %“ôL>ôB!TnÀ1˜ÁÂA«*Á7¨‘K4˜Ç&ˆÁC±±…‚8 ÀÈÀˆÁ°«¾äcPìÍÀ}xHj 8ã9æðB'&@ðñò!ô1 ¦ŒÔçÀìÑÜ.ìþT5M“~Ã7ÐðxC èEaÀˆ¢©"„…´¼Àr5ÏhÏuˆAüŸ, ?H+˜ ÈX±¦Á08ÆcLA1–íÛõå8Ð2;kÜA°SœÈÂh¡~‚à€8ùQ£–ÀÍ!8y&êä@ß¶p Ó@9¨ADD~ÈŒ€ì<ƒXlŠPÀ_ÈêÍCÙÜø‚\ Áÿí# BÌX¤ÔìH…íc4pÄóiïô@kƒhƒñB#Kæ "&@Ã’rtxBôäh›lx°‡l´eÉ(D*°‚ŒÀ¸ñA1d®XÁ6üÀ—`)à;¿ó)ìHÂúƒA ÎpÉ8Fí&0LAQϸ Ì@žú%:æ_JœæÄñÁå¦?È-órB´ð’3(C”À1CíæYè‚,ˆÐ” „¯D ‡h@¤ì€9Œ4TB1$ÐC À.øtÇ\OÜÈt8À&N3B/ èB*$Ã{~¨ðÙ‡ÛÇHÌ@Rv^æ¥ñB08õ9‹fÁdA,oa£ D®8…'h.T&.l+6ѧ.HBDA/€Á®ƒO;Imaging-1.1.3/Images/lena.ppm0100444000076400007640000014001707442710203015600 0ustar fredrikfredrikP6 128 128 255 ߢ…ä£{ä¡~ߟxÞ¡yàšfß›lÜšyâ›jåŸhæ¦ué­yê§vé¡pÛš»ubž^Y¦f]©g[¯gZ±kX­m\±kY²jT²m]³iQ¶u\Ây\ÃxZÀyaÎ_Ê„`чeÊ‚fÌ„eË€_ËaÌ]Ì€]·nÒ‚]φeÖ‚[Ð…d̆iÌ‚aΈeÌ…cЄ_Ó…\Ì…nË„fσcÊ[΃^Í[ɇjÉ‚dЃ\у^Є_φc΄aÍ…gφbÈ€\Ê€_Ѓ]΃`ЇbÇ~[Ë…i΃eʃaÉ}^È~ZÁ|i¾yb²p[ªfR½tbЇ_Ö‘mÞ™mߣuÝ›hÜ™hß—iÚšyÝšqàšhÞ–dÞ™kݘeß—iݘbÝšjÞšjÝŸqÝœoàžlôΑøÕýÙž÷ҕϘt¥dV¬h[¹w]¸y^ÀwV¿yWº|d¼{iÀ{_¾yaÅfÂ|c¿{c½uXÂ~dÀ{[ÄdÀwZ¼sX¹xfå§Ý›nãqâžxãšjáœkß™kâ˜làšiÞ›eܘnç¡néªzî¯|í«~ëžcÜm¹n]Ÿ\T¤`W¦b\­jY±kT°gV¯jV°iT¶nV²oZ·mTÂvYÁvWÆzbÉ~_È}]˃gÊ_Èãb΀`Ì‚a΂`χkцhÓ‰gÕ„`ΈlÒ‰`ÎbÒƒ]Ó…^Í…a΃j͇f̓m͆gÊ`΀ZÏ]È~]É`È_Ì€\΃]φdÒ[͆gφhÍ„a̓^Ìb̃bÈ…lÈ|Zʃf̃gÉ~dÉ_Å}`¿y\¼w\¹vaªiY³mUË€WÖjÝ™uÞŸkÞŸoà˜fÚšvÝ›rÚ—kÞœqàšgÞ—há˜dá–_Ü›bà˜fÜ›gÞ›mÝšiÚuóȃúÖ˜ýÚ ùןۣv£aQ¬pf´sZ¼w\ÁyVÂzV½{eµv`ÁwVÃ{^Ã}]¿xZ¿{]½vXÂx\Ç_Åe¿y[¾rS¾}dØ•t¬gQàmà›lá›wàpß™iâ›dà˜kà›lâšcå¤uìªtë¨nï©tå›`׋^¼qYž[P£YO®dM°eO´iQ³iV°kR°gM±fM±hX°iS·t]È|^Ã~_Æ}aÉ}\Ê€fÕƒXËXʈi΀[Í[Ì[΂_΄_Ó†`Ö‡\Õ…^Ñ…fÏ„_шiÍ„`ÓƒbÌ„lЃ`Ë}^Ô†aʃiÍ‚bÌ€^ΆbÍ‚dÍ|YɃbÐ\Ñ„^Í€[Í`ЈgЄaÉ]È‚iË‚dÍ\Å~eÉzZË‚ZÉ}[ÆvYÄ}^Ã|b¾wc¶q[¯gR«eT¾v[Ò‹lÙ•oÜzÞ sÝžwÙšmàœeÞœrà™kà™dãœdÞšlàœoß™fßnÚ™iÙ™qܘfÙ›sç³|öÒ˜ûؘüÙšó̇¹z_«hSµoXºtX¾uX¸za¹w\¿zY¼zhÄzYÄ{Z¿{[Ä}cÇcÅ}\È}\Ã}\ʃdÅ~_±iOa5?\-=áoåœiâšiâ™dßžxâ–eà˜hãœgæžmå¦qæ§mì§hë¦cãžkÓ‰c´mQžVI¢\KªcR±jT´o^²mQ°fN³kO²fP´iSÀnOÂwWÅtSÄvYÈzYË\ÏzQÏ‚e΃eцhÓ„_Ò…iË€_φdÑ]ÎXÒ…bÓ„[Õ„ZÏ]Ђ`Ó†bÏ^χkÒ‚^͇kÒ‚`Ï…cÏ„iÑ€\ÎaÑ]ЀVÑ€XÔ†aÓ…fÏ]ЂaÍ„cЃbÏ€_Ç`ΆdËa˃bÌYÅ}aËbÌ\Ç|`Ç|bÄ|c¸p\³p\±kV«j[Í„d×nߘná¡ißžoàkãjà¡næ¡kåŸoâšháœgß›mà•`â™^Û—bÝšmÙ˜oÙ—kØ–kñĉøÕ›üÚœûØšã³~¤gX°s^½sT¹rZº{fÂvWÀxZ¾x]½vU¾yZÂ{ZÃ|\ÄyUÊbÈ‚^Ê}_Ó„^³mT_;PW(;[0Aá›oá–eãžkâ›mâ™]äœhÝšpá£}æ¦yå¥ké¦tê¤nè kâ˜i؇Z»lP \P¢^L«hW®dN´eHµkR¶kQ´n]²eJ¸gKÂpMÂpNÅuTÆybÉ}XÎ}XÐ\È„gÓW΃^Ò„`Òƒ]Ñ…a΂^ÏZÏ…dÒ„XÕ„]Ò†lÓ~VÕ„_Ï…bÔ‚^̃]Í‚[ІjІeЄbÏ`Ì„^σ\΂aÌ~UÔ‚XÒŠmÓ‰fЂ\σ]Ò[Óƒ^̓aÊ‚_Ñ‚]Î^Ì}_Ï|[Ï…iÎaÎaÈ€`¿}fÅz[ºqU±wg»s\«hY¾yf×—zÝ–nÞšmߣuá£zåžjå£rá såŸmã¡xáœgâžlâ›mßœfÝ•f×—tÙ—oÛ–kÖ”käªtøÏúØœüÚžøÑ•ÍŽa³oW³nU»t]·yd»{bÆ}^Á}]Ã`À}bÅa»gË}YÊaу`̓c§_N[,;U-?V.<\-;â›jâœjæ›eå›dážtã™eߘkߢwé¨oç£pç¤uå¡næ¡hå¡u؉Y¸oS¤bPŸ\N­eR³fL¸iT³iJ°nU°fN®cH²hP¸oTÃtQÀuUÆ}]Í}SÁ{d΃dÌ^ÏV΂d΃bÐ`ʃeÌ„cÐaÏUÑYÖ‡aÓ„ZÓƒ]Î}YÕƒZÍ\Ò…aЃ]Óƒ^Î`΂`у_Ç~^΂`Í\Î[Ì\Ò„bÒ‰hуdσaÑWÎ`Ë~WЃe΀`Ë}YÇ€gË~]Êz\΃cÐZË~YÂz^Á{dÃy^·q[³mW°jW°o\ЋiÚ“eÞ›nã¢yå¦väiä¡rã¢kæ¢iã lá›mâšoâ›qÝ uÞ™qܘgÚ˜pØ”pÙ–nÚdï½|úÔ˜ûÚüÚšòÄ‚¨hS¬jV²q[»tZÂz^Á~`ºs^½|c¸|iÀ†sȃiÉ‚dÓ‡cÕf¤_O[->W):V1EW/>e7EÞ˜käqã¢râœdâœpãœoæŸmæ§|é¤uæ§wå£pâhå¢pä—]Ý‹Y¿r[¢XF¦[L­`L¯hO²gO·hP²mU°gR±iQ¹mP¶oW½sRÃ{WÈxTÇxTÇ~^Ð[Ê[ÐWÏ]ÏZÓ„]Ë…nÑ~\ÔZÒVÒƒ]ØVÓƒ^Ô~VÐ[Ï‚aÒ†eÒ‚[Ö^Ñ}VÍyUÍ~WÌcÏ~YÓXÊ|\ÍZÈ|[Ì~^Ï…gÕ€YЂ^σ_΂aÐ\Ð}XЀ[ЂbÊ}ZÍ€cÐbÐ~WÍ}YÌ`Ç{ZÆ{b¿yb³nZ³lS®h\´wlψnÙ“qàžuá¡wä¡zä¦zà ~âŸnâŸdäŸhߘgÞjäšcá›oÞšpÛ›mÞ˜fÛ–iÙ—oÖ“kÞm÷ËùÙ¢ûÝŸüÖ•×¥j©dM®kX¼vW¾y[Å|T¼x`ÁzZ»t]ÀkÃ}_Ò€`Ô‹g¥^RgIYW'7X/DZ-8a1:f6=æžhåfãŸzæŸkâjâŸvæ£måªrè¥mä¥wä¡iájå¡oç`Ù_¾pMžYM¦\J­`L³jQ¸lQ³iM´eI¯eM¯fP¸jPµgNÀrQÆwPÅxTÆ{\Ç]ÌYÌyRÍ‚]ÎZЃYÌaÈ€gÌ‚dσaÓYÑ‚ZцfÖ†cÑ}XÒ{UÓ‚aуcÐ…lÊ{VÎ}TÊxSË|\Ê{^Ï^Ë}_Î|\Í|WÌ|XÑ€^Ì^Ô]Í`Ï]чeÈz]É€Z΄bÏ\Ð}YÌ}]ÌWÐ}\Í^Ð…`É}]Ãw`Æ{bºnW·pZ³lZ·sbσh×”yÝœ|àžwã£{âŸyàžsÞŸráœrã¡nâ¡fá›gàšnâškßvÛœvÚ˜lÚ•c×”fÙ‘lÖ”kñºyùÕ˜ùÙŸýÞ¤ôËŒ³nN¯kT¾uT¾uU¾z\»xdÅxV¹x]Æ|`ȃ`ÑŠgŸYIT/DW-D^3D\*7e5Bj5A^2<äŸpã rå›iã£væ¤zç¥xëªqèªuä©tæ aâ páfæ aæœd݉U¿oS¡]N¨_V«aI°dNµhO°hR´dJ³fM°fN¶jS»pVÃrQÇvVÁx]¾wXÇ|bÎZÍ{ZÉ|[Ì}YÍ~_Ï€\Ì€a΀bÓ‚ZЄ[Ï_Ï]ЄaÎaÓT΃m΂iÏ~[Ó|VÑ{SÌ|VÇuYÉyVÊ}aÌ~_Ì}WÌ€]Æ}aÉ|[Æ`ÌcËcу^Í\Ê‚fË€dÏ„cÈ~bÍ~aÍ€aÉ~aÊ}_Î}TÇjÊ~\Èz[Èy\µqb¼r\¹kX¸teЃdÖuÜ–màœtávâ uÜŸtÞœpá¡páußràšiášnßœkÜ™mß›oßkášnØ™nØ•pÔhבhõË‹úØžû߯ýݠ㸪k[±kS¹rV¿xZÃ|\ÂxVÂ~aÆcÈ„\¥^QW&6R':Y3D^*=f6;f1=^09i7<âŸnãœgá«å¡uç¤nê©rì§oí¦né¢häžkâžmâ oç¡pæ›lÚ‡U¼kN›RD¡[Jª[H­gX¯eN±gL¬fK±cM²iVµiP¸lN¸pW¿qVÃsQÇyWÇ{[È~[Í‚bËzZÎYÏ€ZË]Ë|^Ï€`Ð~\Ï}UÈ|^΀cÒ‡mÕˆhÒWÕ~[×XÒ€]Ï~YÏ|YÎ{YÈvYËwWÉ|VÍ~ZÆ{[Àz`Å|ZÌ|UÍcÈ~^ʃiɃfË‚bÊ~bÊeÒZÐ`È~`Ï[Ë|`Ð}YЀ\È~dÏ{WË~aÃu\À{eºoS´m_Àwb΀dÕŒpØ”oÜ™sÝštàžwÝ›pÞžwÞ xÞœuß™qàhà›räkà›gášhÝ™ràšlØ—nÕ‘kØ‘e׌[ç®xùÔ˜úÜ¡ûà±ùÔ•ÄŠ^®gQ»pT¿uW¾}bÀzZÊaÐ…f›[KW'8U,>Y-?Z,>e6Ba.:`3Bd4=Z,6å¡häŸgå£xä¦zçªyé§xê£oç¢iç ræ¡nèŸdçŸlèŸjæša؈\¼fKœSD¢ZG«YJ±pe´dL±eP°eQ¯eQ¯bP²cHÀkMÀrRÁx\Ãx[Ä}_ÄvWÊxWÍ{WÈ€fÆ{[ÌyUË|cÎ}\Ë|\Ò{WÑ~YÍ€^ÑcÏ|XÓ}WуbÑ^Ï…mÔcÑzWÐ}[ÍzTÏ~YÍzPÂtRÍySÃvVÇxQÅsTÈyVÌ~[Èa̓fÍdÏcÐ~YÊ~`Í€dÏdÎ|VËdÍzZÑUË]Í{WÉxVÇx_ÀuY»u^¼t^»lV½r^Ì‚iÔ‹lÔ“zÙ•sÜž{àxÞŸwÝšsážrâtßšháœgß™lÞšká ß™fß™mݘlÚ•kÙjÚ`׌]Ö_öˈùÚ¤úÞ§üÞ¥òÆ…¨dO­kR´qY»oSÃ|`ʃa¢aQ[.>W-AW*:\3C`3B`4@`7Ib,:_-:Z);äžlãjâ yé§té©|çgãœqåžfä wê¥eäŸfåkè¡kç˜]ÛˆY´jQ–RE¢`O­`L®cOµjU°bJ®bI®fM³fOµhR¼kSÄw^ÅxSÅvSËYÇ{ZÇcÏ|[Ê‚gÉ{WÎYÍeщsÑZÍhÊ}\Ð…gÍ~YÒ€bÔƒdÒ]Ó|VÑ„cÒ~UÎ~]ÒYË~bÅzfɃuÈ«§È¨©Àšš½†·yhÁvXÎ|UÈvTÈz\Èz]Íy[Ç€aËcÒ]Í‚bÌ|[Ô^ÎdÑ}PÊ‚dσaÍ€_Çy`Âw]»nT½oR²k\¼s_ÆkÓŠkÕ’tؘyÛ˜tÜ–mÞxßœ|Ü›sâšjßœqà™mãžhäœcßqß™hà•dÙ•oÖŒaÚdÚŽ]ÙcÔmå©múЋúݦûß«ù×™Õšb¯jS¯kSµo]À}[¢^OY+:U+;U)?`1D\1Bk>Jb3Ci7H_/;_/;]1?ã£rå¢né pçªrê£uç™aã“[Þ“bäœmè¢eæ¡mä sè£sæ›hß‹\ºoR£[PŸWG­_L­dP°eO±hQ­eOµjN±eM½kMÂsUÁpRÈvSÊxUÆxVÍ}WÌ}VÏVÈ~]Ï^Ò~ZÒ]Ò…hÓYÊyZÒbÈ{]Ï„dÖ[ЄbÕ„XÒ}VÌ}eË‘‚¼Ž¾œ–¾‘‰ÌŸ‹Î¡Õ²–Ñ´˜Ø¶ÙÆ´Ô¼¬Ô¯ŸÕ»§¿»s[¼sYÊgÆyYÉ{XǃlÅ~g΂aÎ}]Í{XÐiÊ~aÉ~_Î~`ÍxRÁw\Às\ºrc¶kWµpaÌ|^ØŠgבnÖ‘s×nÜ—rÛ–qÝ™sàšpÜ•hà™mÞ–iá›lå›eà—gÛ–lß–gÛ^Öa×fÚ\ÖŒ]ÔgÕ‘dôăùÙ¨úÞ¤üá©÷ˉ®kQ¶pW¾|`Ÿ\LT%8X1HX0D`0>c7Ab6@a8Gf>La-:[):c/b2;i;H_-8d3?^4F\+8c1:\*6],9åžgë£rí­uë¥qä•YÙNÓ{LÙŠZçœhê£dë¥mé§oì¨lçŸgÜ„V·kO›M@ UG¨[F«aM¬_H¯_I³dM¯bL³gO¶fO¹kRÅpQÇtUÑzTÍyRÊyZÐzVÎ~[Ì~]ÍzYÓXÐ|[Ò\Ð\Ñ}ZË{^Ñ„kÉ„qÍ•…Áx_ĉqÆzÀŽ~È”‹Ë”|Í”tÉ“ÅÊ‘vÍž…Ó¢{Õ²™×¯‹Òº¦Ò·¢Õ¬Ù¼›Õ»«ãÈ¥ßİÀž”¼oU¿sZÉ|cÊeÍ{_Çx_ЀcÈwXÈw]Çy[ÂoS¾rXÀpQ´iS±m]½oSÍ`׌iÙ“lÜ•wÖ’oÛ“oÚ”sÖ•wÙ˜uÜmÜ”hÜ”iÚ’hÜ—kÙ‘bÜŽ`Ý‘hÚ‘mØgØŒaÙŽ`ÙŽdÙ^Õ‹_Ñ…^î·uùÚ©ûÞ§ÿä®ÿÚ—¾xXX,AQ';U&8W0Ae9Ce1>h8G`3<[2E`/Ag9Fa8L[,=_.:çŸjí©hí©kègá‹YÈnB½lKÛ‡[åœfè©sí¦më£nî¥kè¡náŽXÀoOšYK•LH›VK¢\S­ng¯dJ¬aL²aI³fK±hTÃnUÂqPÉvRÃv[É|\ÇzZÎyPÐzQÏzVЀ_ÑiÑ_Í€aÑyWÓ‡kÖ•qÊu¾„j„nÂ~m³vh¿j¸|s»rÀŒ„ÆÌ¤—ǜǬ£Ñ¦’ұɧԩŠ×°‰ÙÀ©Ñ¶£Ü·…ÚÁ¦ãÁ•ÚįâÁ£Ûů¬jZ½lRÁpV¿zcÆy]ÄzaÃs[ÅzaÄv^Àt]¿sU¹p_²lY²fNºpZÇ}j׈gÜ’nÞ”mÙjÛ“jÛ”kÛ“uÛ“nÜ—oà•kÙaÛ`×fÜ’fÛfÜ‘aÚ‘h×eØŒeÚ]ÛŽZÜ]Ú_Ö‰_ØŽdùÉŠüÜ þä²ÿå­¾pLT-AY-EX/?a2@j8Gc4Ei=K`.?X+@d3Ac5Fb1A^-:g29è©rï­oêœaå•_ÏxI¢RAÄqKÛŒ\åžeë¨ré¤jé£mï¦méš_ÜŒ^¿lIJD—TI£VG¥]K¢]N­aJ±jN°fO°fP²jU´oZ½sZÉsLÃrSÇrRÇuRË{]È}`ÆvYÍ|\Ï}aÐzWÍz\î°y¹mR½ze¿vU¹zg½|h¸zfº…|Ä…l¸t‹wÅ‚eÅ„kÀ”‡Â€Í¥ŒÀŽÇŸ™Ô¡yÓ°—×·¥Ûº™Ô½¤Ú¹¥Þ¿™Ö´§ßŸٿ´ßÇ«ÞÁ¥·™Ž®lY·kT¿ubÄvWÀs]ÇuW¿s[ÆsVÂpT¹pW·jP¨h^¹lUÍ`ØŒmß”mÜ”nÝ“jÜmÚ’k×’qÛ’oÝ“lÞ™oÛdÙ‡Zà`ÞŒ\Û—lÞ]ÙŽ`ÚiÕŠ`ÛŽbÕŒdØ’jÙ‘jØŒ`Ø_è¤mÿÛ¥ÿä³ï»wK&=U*=W*:Z.?j;Gc5Ag4@\,:T(=^->^/:V+7_.;f6AW'4ì¨uèœhÚ„R­^E’JD¿qMÛ‰Vä¡mí¥mé£ié¥ué¤eèœl߇Y¹jO’F>”M?›[N¥ZK§bR«aN§aO«eR®eM³dIµjOºqZÀrS¿tZÃuSÃxWÇw_Æv[Ï€^ËbÐ}[Ð{ZÊyWÄrPÀoZ½v\½u\¾€p¾xm»zd¹}lÈvº‰½†tÌ‘xĉtɉkÇŠqË—~Ó£}Ó²˜Ò³¥Ô¦|Ó¸¤Ö¶©Ü¾žÙ·¥à½—Ú¿¦âãØÅºÝìÙǺáȰӽ®¬fT°jY¶iRºoU¼pX¾r\ºr_»p[±iY¹jN©aP¶oYÐ_ߎcá˜nݘtá”iÛmÖŽjÓŽiÖlÜiÚ”qß“fÚfÞdÞcÝaÛ‘iÙeÞcØŒcÙeÜhÝ_ÜŽ`ÜŽaÞ”jÞ•fÿˆó¸uU';V*@T,CZ.d3>f4>g6A_1>Q(;e;Ga1?U,?c5En@LkŒNH“UL™WK¤YJªfXÊ~bÜlæšlä™oä˜há˜má’jÓ‡j«i\f19^0EšaXÃwZÛ‹fá•nÞ‘lߎbßcàŽ_Ý`ߎhà‘få–mçŸxAET%9\3AY*Y,@n:BY.;X5D].<]4EmHY‚R`¬ytÈ‘wјu¾…nÔžy£[JWN¢YH¤^QœVCZP¼jNÚŠ[äšfì©tí¨xë§vë¨}ä–cÙˆj¹jP‘NJ’KF¢WI©aN§`Q¬dR¨cN­`H¬dO±iY´gR¸q[ÄsSÈsP¿t[ÃwZË{_ÃuZË{XÂsXºnTºnU¼pWÅrWÁoR³n`µ}t¼p½u¸yg¸yeÈ^ÒŠfÇ|ÇŽqÑ‘nŇlÏjË‘x΋tΑzݲĕ†Å¦‘æÊªåʰãÊ´áͼèϰãŨÛÁ¹Ûþà̼ç̯æÇ¦ÛıßÏÄàÏÀãÒÀæÓÃîÝÌÏÍÇšj\ŽJA“M?œYM¨_LÏ}[Ühå›zä™nä•lå˜nà“j؈f°dKk08R)²dQÔˆkÝ‘jã•dáaÙŽhÞŒ`Þhä•iç”hë™fÇtRX+j5\0Di9OšjeÈ‘wÆsÉ’uО†Ö¥ƒÙ£~œUG¤[H¡^N¢]L›VHŸ]U¼udÚˆUæšiè¢oç¦}ê¦zë£pç˜aÝ„U·hT’LF—KA\Q¦aKªe]¯hZ¸hM«cO¬bN³aM¸pW¶mT¾nPÂwTÃvW¼oXÃrPÏ|W¬^J®aMºkQÁsWºlU·jVÃtX¹mY´ulºx_Æ~dÈnÇ{ΆkʉkÒ”xȆlÇ€pÃ…hχg͉b¾r½ƒÜ²’Þ¿³ãÆ´ÞÀ«ßƵݺ¡ØÃ¹àİÙ®äпâÍÂçѽãŰâ̼äͶæÏ¸âʱäкâпçÙËæÕÃçÚÍðáÀt;<‰F@¦^LËyXÛŠcá–kæšqçšpâšqäšwÖˆc±kSt;BZ(6U%5m15§[GÍzVÛŽkà’eÜfÛ‹aßeä”kèœp’SOV+9a2?].;p:Cd2=e4Ac1@Y,@i;J]+8_1=b09Y2@W.J•fkÇ’ÆtÀŠxÉ•wר…×¥~Ò ~ŸXL¦_Jž`S¡]LžYL›UL¿oQÛŒcãŸwè¥kè¢qè£uå£räœr؆gµiRNP–ULYKŸ[I¨`P²dP©aM¬eS²hO¯fQ¸gL¸nUÆvW¿sWÁw\½oW캀ÊoH½jM·m[ºnW¿vaÂoO¿pUºr[Ì{ZÄd»yjÇzj͆jÒ–x¹zqÐ…fÕ“uË}Ä{_¿{g¹s]°paÜ­}ä¿–Þ¼­â³ŒßµàÀ¤Ù¶ÝÁ¬ØÁµâĪàË´ãÏÁâοàÉÁâοãÓÆãϹæÐ¾ãÐÀàË·ÝÊ¿âÐÀæÖÀëÚÁíâϵ¥­{8>—SIÆvXÜgã™râ™lçšoäœuÝ—uÕ†c³iUw:?]-=_.;[(7s45¯aJÐ{SÕŽkÚŠ\Þ†UÜŒ`å•iÎyLW)9V+<_0Aa2=f0=c6i5@c7AP(?}KUÁ’ƒÌ–ÄŠpÇ“{Ó¡zÓŸvÔ¢}Ø£y¡YH XIžZO [NžXFšQEµjOØ‘käšdë¢jë¢rê¦sè¥væ™iÜ‹\ºnV’OF’OK¡VH¤]N©aK­`G²eOªaPªgT²m]¸mS±mYÂoRÁtY»mP¹k^úÈ€°`T°iY³fUÁsY»nSÁsTµlTÁu^ÇvZÑ}WÃiÌ…lÏ…eÐŽiÆ‚h΀]щnÄy¹yh±n^µzpßµ¥ßÀ¡áÁ©â½™ß¼Ÿà¸œÝ¯‰Õ·¦âǰÞÅ·ßɽ۽´ÞʶâÐÁáÈ·ßʾá̹ãκֿ·âÌÀåθãÓÅãнâÓÅåÖÊéßÔðàÈšXPJFÂpL܈aä˜fã•kß—qå—gãœuÖ‡d°gRx>K`.C](4^,6S".p=EÏ¿¹éØÆîÕ¹Ù¾±æÓ¿Ø“ob/AU*<[.@^1=f1=h9Ff;Gh9K`8H^-8^0Gh8Hb1;[/=d7K»…yÑ—yŇpÃwÔ£„Ó xÓŸ|ÒŸƒÕžy™XK¡\LšYK[O¢]RšUFºkOÕŒhåšlé¥wæ¤w䦈é¡mæ—c؉^¸fHŒEB–PGžVFXGª^Jª^N§bL¨]I­eW°mV±eOºjO¸mSÀpO·eOÏŠ`î¥e´fU±iP´mU¸q]Î|UºmWÃsW¼{j´iZÊiÎ_ÏŽnÁ~nЈaÀƒp̆jÄxW´yf´rfÊ™‹Ü²£Ý¯ƒäº“جš×¯™àƱԯ¢âÅ£ßÀ¨ÝŰßÄ«àIJß˸â¦ÜÅ·á̻ܿ¨Ùòäнç϶Ýȼà̹àÎÀàÐÁãÒÆãÒÆåÕËèÞÖÑú‡GA·nWÔ‡lãšqå˜lå›häœsá•kÖˆh´kSr;A[)7Z'8U'8Q.AâγíÕ´Õ¶¤äпíßËíâÔéÔ±L&AQ,CZ-Ah3@d3?gAKa2?`1?d5Cb4Dc4Gja3>d1=V.A_0[2Dd5Cc0:_/9\.=d6Jm8Cf3^.8[,=d2Cf4?W*6Z-B¶uÓ›…ÈzЙƒ×£zÒ Õ|֞јzÓ€Ö›yјzÒ™v¬dM±`F®cO«dP¯aH«`IÉqHߌ]ߘiê¥pì¨sï®sí¬sé¢mߎ]¼nK˜OC“MCYK¦bTªbK±aG®`I²hP±`I°eL·kO½lL¹lR§YKûڥ᥄ËzTµhQ¸mV²bM®aP¾qQ¹qZ§_YÉyYÇ|c²fUÌ{[½ubДƒÖšÚšnÒ“qЗx¸xlÛ €Ø¦ØŸ‹Ø±Û¤‘Ӣפ—×¼·Þ¸™Ó”{Û»žÛ©Ò¯žà¿ªÚ²Œ×± Ü¼¬×®›ß¿¨Û¬‡×°¤×µŸß½žØ»£Ô·¦Ù¾­ÙĶ׼¯ÛÀ²ÞįØÄ¸ÓµŸÑ¼µÙƽرŸß“`à—ißïîÔ«ÖµŸ×±ŸäÔ¿åÏ´àÈ´ÞʸáDZßÊ·âιãͼæÑ¿ëÔÂñàÏñÞºL'@W2G\2Da2A^0>]+:Z-:d3@c8Io>N™^cÏ“|Д~Î’xÖž}Ö €Ö }Öž~ÓŸ~Ö {Ñš}̖јzÑ–x­gN®dP­gQ·gK°aH°`HÆqMÛŠ_ålì¤gî©kì®uî«uê¦sà”h»oQ“J<“NB¤bU¥[I­dN±cJ³cJ­cK®_G¬aK´fN·jKµeG¥XOýÖ—èžnÙ‹ZÃwT¸kT¸nR·gSÄvTµnZºhPÆzWÀzoÍeÀsTÌxÔ•{Û™sÏ„fÕ¡†Ãx_Ú’qÙ ‚Ûž„Р’Õ™…Ú¨ŽÕ²£Ù­†Í—Ó¡“Þ·šÝ¥ƒÜ¯”Ù¯•ݶ–ݵŽÞª„×·¬Û½®×©‡Ü²ŒÞ¼¥Ó·®Ó°˜Ø¾¬ÖÁ¾ÜÄ´Þ¿¦Ø¸¢Ùº¨×»­Õ¾®Ñ»¬ÖÁ¶Ó¸¬ÛƸٱ êӷ׳‘߸•ßÈ´èϵå̳ÞÊ·ßʶàȳãÊ·áÏ»âË¹ßÆ«æÑÀçÒÁðàÑïÞ¸E$AZ/@`5D^3J^/c3A^->k>Pj7?a3].Aa5Aa2?[)7a0;Y-=Pa­y|Ó—{Ò’rÍ—€Ôž‡Ö „Ó¢ˆÙŸ€Õ¡‹Òœ€ÒžÒ~Ñ€Ôž}Ô›sÖšqªbI¥_L¦WH§aL¦bM°bLÁpKÛŠXçfì¨vê©uè¬uê«ví¤iá’`»jM“ME™NG¦\F§dS«dT°bI«^IªbO®aM®`F·hM·fF¬`G­eMôÃ{é­{â’cÝ’jÙŒeË}X´k\§]N¸hQ»kMËŒqÕkÏ`ЇgÏ‹cÁ~fÖqÖnÌ‘ÏvÔœuʘ”Û¢xÖ•~Ó’wÙ¦™ÚžxÜš„Û­˜ÚŸ~Ø¥„Û Õ•}ݱ‘Û£‡ÕfÌž„׫ŒÖ®’Ù¨‡Ü¯šØ«™Û¸¡Ø¯’Õ§“Ò¬›Ô­™Õ´¥Ê ŽÑ§˜èʥб™Üº™ÜIJèαáȶÙñÜÀ¯Ü¾©àİÞűáȲàȵâ̺ãͼäͺåϻș†×¯»}kÒ¡‘Ü·šË¹«N%9W)5c8D^0:U+:f6>\-:n?R˜`hÕ•xÔ—‚˓؞‚Õ£€ÓŸ~ÖšwÓ‚ÒÕžzÒ™xÕœrМ~ÒŸ{Óœ~Ñš{§^G§]I¥]J¨^H¥[H«aOÅnLß[è¡fì©uí©pì©pñ©qí©kà‘e·kR™SK˜RN¢XK«`K«\L­^J¯^H¯cM±aD´gN³dH¬cM¨]IÆ}QòÀ€æ±}Þ›zÚ‘qÌyVчfÇv[¶cI²dN׋iÕŽpÔ‡hʃgǃdÉ‚fוxÖ‡aÍŽzÕ‘jÊ‹sÐxÔ–xÒuÓ”|Ü¡yÙ™~ÖÙ•t՞ћ„Ñ¢’Û¥œÛ«‰ÑŽpÅ•ˆ×¬ˆÛ¡Û­˜ÓŸ†Ù±šØ®¡Ó¤ž×§šÖ¢‘Ö¨”Óœ…Ç—ÊŸàÁ¤Ý­…⼋àèæÍµäǬâÁžÝîÚ­ßŰáŪßȵáʺã̸á˵ßʹãÑÁçҺʛ‡Ð¨Ä‰tÙ©•Í—‡çиS.@Y1K[1=a8@];MY*;c2@\/EyG\¼ƒvÖš|Î{Ζ„Óž}Ó €ÐžƒÒ›ÑšxÓžƒÓ¡ƒÕž‚Л}ÏwΚyΙvÕšw¥]F­cO«_J¨bNªaJ²fIÇvVߌ\ä mì§tí­së­xí¯{ê¡hâ—k¾qR•K@—J@žXG£_N­fR¬aK®]D³`H®cMªbM®cL«`F¡WGáš^õÄ~í¯sêœ]â“RÚ‚Sá”_ÌuO»bGÑiÖŠj˃hÇdÃ|`Â~kÙ“oÏ…c×–uÐ’vº|pĉ~Ó–yÑŒjØ”uÚ¡Ú™~Ô•ÉÏ›µ”˜©Š’£uvX^Ë–Š×š{Ý£Ù¢‚ؤ|Ñœ‰Ý¥ƒØ›…Ò •Ó¢”ТžÐ«¥Ñ˜{Ä—Ú¹žåÀ–Ù²›ÛÁ±å̳áãڻ¤Õ¸ Û¿©ßÀ©ÞůÝÇ²ÝÆ¯àË·ã̺ä˺âÊ´áͽæÓÂÝÇ´Î¥‘ÅŒzÏšj«l`بŽîßÀI$=V+?a8J]3AX.?iBPc1=d6J•aeÖ˜yÑ”€Ì“yÒ‚× €Ø yÕž€ÓšzÑštÔ›~Õž}Óœ€Ðš|П{Óœ}ЀԜs§]J«bN­cJ©dP±cL·hQÈuRàŒZæŸoì®sì«pê­xí©lð«uàZ½kK–KA—PG¢ZF§bS©_K°^F®_F®`L¶fN¯_GµbH¯]F¡TFØ’NòÇò¯nížTì Yç [ìœ^ÛˆV¸oaÎaÈx_̃iË‘†¸|nÌŒuÚŽkÑŠqÒl¹{fÇ„nÍŒvЊ`Ô–yÒ”}Ó–ƒŽSZ«}€©mgUYžjjž_aʋ̙ˆ\c½ƒt٠ة•°Ž‹Â‰~ר˜×¨•«xh7LÊ›’½ŽŒÆŽ‚áÁ®ÚªÚ»­âdzèÈªãÆ­Ú½ªÜÁ©ÛİÜÁ®ÛƲàÈ³ßÆ°âÈ´â͸ßɲä̹æÐ¹æÒ¿æÒ»Ò§ŒÆ™z‰QJžcW¼‡…ëÕ¿À˜oL"6Y-?`18[(7_0Cl9?\1Ei7L¹‚tÙœwÌ’†Ï—~ÔŸ{Ù¢|Ö ƒÓšzЂњ|ÔœzÒŸ|Óœ~Ôš|ЛwÑ|Ïœ‚Μ|©dT«cT¨dS«bL­aP¶eLÐwRáŒWéiì©sîªqì®wì®|í§nå—c¾qR”LCKA›TE¥bQ«^H°cL±dO²eL·hO¶aG²bJ°`BŸVDÐPöË÷»‚øµeì¤\éšYéžcâX¹o^Ãt\Æ{eÁ‚rº{oȉuЇcЇiÍuµ}n΂eɇtʆmÏt×”zÓ‘s«q€ÍŠq»xm¦jk‘]hZeoE\Ö¦›Ø£Ÿ€¤©†¢ ƒqE_‹\k rq”ai_2KlEb†^nR,I̜彙С…Ôµ¡ßÀ¤àŪܾ áƬÙñÛõÝÀ­ÝÅ­ÞɺáɸáʲâɶåηáÌ»à˵æÎ¸çϳΞƒ—XD•TH\N´xkâÁ­ìÚ¹T,AT)<_/=a.9X)7f3=^/:X0F”dgÒ–Е͔֢…ÓŸ†ÖÓžÕŸzКwÑœ|Óš{Ïœ|ÒœzΛЛ~Ì™ЙyÔšy¬^K±gQ§bQ©_M°eMÇmEÑtLä’[êžbê¬rê¬líªsì¬pî¥gã—i¾sOPH–K@TJ§]JªdP«_G®cM°fR¯aL±`J³bH°dM§XD´cEýÃxù¾jþÅjñ£VÙ‹\è˜[¿va¶q_½tYÀl®jaÈ‚j͉nÈ„nÒŽqÊ€dÈ„mÒˆiÈ…lȉwÓ‘zÊŽžemĉ¬~‡¢q{£di¯ty“eƒ‰g†žp†¥Š¨†YpmHed;\—€Ÿc;ZtNoX.?P'AS4VL,N ‰”Ô˜tÓ¥˜ÞȸæÈ«áèÞìÞÁ§âÅ«ÚįØÁ°ÜÁ§ÝDZáÈ´âȯáɺæÐ¼ãÍ»çÏ¿äÈ«Á|P’RF—`RšZI `P±q_Ý´œìѲD5R-@[0Bb3Ba3>V+8i9CY.V‚e‡^3Iƒd‹]5M?1E&Bͳ¦¾ƒu̱®äÅ©àÄ¦âÆªá©Þĩݾ§áÃ¥ßñ׿©Û¿­Ýī۰ã͸åɬëÒ»åÍ®›\M–RG—TE˜VHž\N¨iaÊ—ˆæ¹˜ê˨a03U'=X,=c3A`.=^-?c2_1?`4A`5Cd3>_,;[-SfA[€U_c@RZ-EqFYX+@oFjM\a1Ec8U’s‹‹g‹Q'Ata”@4†_lÙl¸€nÝ´åǦٷ•Ô±¢Õ»­×µ™Ñµ¤Ð¯–Õ´žØ¸¡àÁ¨ÞÁªÛ°áĤг~PSpBJ›v~Ÿx„¶•’Þ¦†å¥yè©vå¦ré·’òÍŸa.1U';\-8_.;l8Ab7?a1;^-7d4>`>O\7K£pmÒ“sÏ’xÓžƒ×£~Ö¥€Ô¤…Ó¦ŠÖ£‚Ô£…ÒžÒŸ‚шΟ͈Μ„Í˛ʙ}ΖtÍ–y°kV³iW²fR²dK¸dG²fGÈrNá‰Vé¡jë«rî«oê©tî¬uì©yâ’aÊuP–NF’GCžWH¤\IªcO°bJ«_K¬bM°aJ±eM®`K·fL¶eF¯`FŸZLöܱúÚ¥î½ä­„á›q¥YIÓŒoÌ…oʉ{£b^ÀzhÆ{b»znÆy`σkÕŠoÏŠv|h:Gc4Ad5D]+6f28X0Ae:N¸„|ÇxÊ‘|Ö¤|Ú§~×§€Ö¤„ب†×¡Ñ£‡Ò¢€Ó¡~Ñ ÍœÒΜ€ÍŸ‰Í„Í›‡Ì™ΘµjS±mW·iP¯gU®bL³\CÂoNÛŠ^èaê«wì­|ï®sí«oì¦nä•`ÇuRJ?”NGšNH¥[J©_N­aJ²gQ¯aK°bM¯^G¯cP¹iLµhN·iQ®bLžWKøÝµñ»}è°€íº}¾wSË{_͆p·rfÁ{c΀dÇ~jÀvc²rq̇w­|„·vp¥fgŽ[ii>XƒZlY.EQ&AoB`ŽhuP$8a2P^1=[.@a/Db5Nf>TW-NŠ€¢”p…†QW›n~⼒Ῡݪ׺£Ñµ¡Ï±™Ô· Ô®’Ѩ׷ Õº§Õ¹¢Ö»§×µ¦ëĪ竉’SRšoo„RT‘ez¦‚‹kvÇ“„å©ñ â·ƒV,<\.9U%4b3?h5@k9Ap?G^1;U)8\+>c6Bb8NŒXXÀ‡sµqКƒÖ¨‚Ù¨†×¢~Ô¥ˆÕ¢€Ö¢„Ô£„Ö¡‚ÑžÒ£Ò¢ˆÐ€Ñœ|Ïš€Í}ʘ{Ç•~Ë–|±jW·jVµiR­cM°gSª_N½iMÖŠ`è mîªyï©píªuð¯qñªkã˜gÊxY“KCF<—RA¡]K®gR¦aR¬_J²aL­bM¬bT¯eL´eNÀkQÁnP³gJ¢WHçµuöÆ{ð¼”Û™s݈[¿v_»rbÀxcÊ‚j½€|³umºup²€Š u‡•e{P_…OcŒ[lŽc|k?Ra9LO'A~Z{j?RrA][*=^/Ci[/CqH_§vk¹€m±€~Ó£†Ù¦Õ£×£‚×¥Õ¡Ô£…Ö£†Õ¡|Ó Ï›|ÑœyÑŸ~Í…ÐxÌ˘zÏ›|È•€»qX¶kV·kS®_J¬`K¥ZFµgJÚƒUã™gê«xì¬kë«xï°yïªvä”dÆwV“IDHD˜XJ¡UG°eOªbP¨_Lª_J¬^M¯bL±cLµjPÃqX½ye»oS¥_OЂPüÙ”öÄð«w¾wdÇ|d¥_TÁ{hÁzg¸}yȇpÏ„k³qr̃n°qusAVf;Qh9SŠaqCZ\2KZ3PpB^e†vK_X-?]/@`4FZ.>W1D\4M“h|}X†Œj’§‹“Òª”Õ­˜ÖµžÒ°šÌ©Ñ´ Ï®›Ó°”ײ›Ð°™Íª™êĥ뿩êÁ¯ëÄ­îÅ®ïÄ¡ãšw²aHHS–mv…P_¬ƒ†·ÃŠzœSBT$5S):^/@f;Ji8?m;Bi6Ba0W+AˆU]žpl±ј†o4AY,<[/i4;rDRe8Dj4@]-;_0>`/=e5D_.F¦tn¿ˆv±}q–„Ó¤դץ€Ô¤Õ¦}Π‚Õ €Ñ£ƒÖ¥€Ó£}Ò¡ˆÒŸzÓ£‡ÑŸƒÑ ƒÑzЃИqÍ—v±jV¬hR¬bO«fU­dQ¡]J·jOÙ‡_åšjê¨{í¬uì®zêªví§uå—hÆuQ–RJ”K=•OC¤]N«_J°bQ¶eN«fW«_K²iS´eN¸lR¾nTÆsR½mUºgI³cKÿÖšþͯgS¶gN¼oZ¹wm¼p]΄q¾mYÊ{gÆ{h—hnR%;[oZ.>W)@].B]5OwPlqHZb8SSo`9\¡°|Pi~W{O);F!7ª…ƒ¨e_Äž Ó¤‹¡†Ÿ×®’Ú¿¦ÞÁ§Òª“΢ɟ‹Ñµ Õ°™ß¢‰ç¬‰ì»žíǪëäíÈ©ïǨòË­ñ϶óͳì´ÊlJ‹JE\/APQwDQ»’ÍŠ]0HY3E]-:c1:f1>f6Ej8Bh3;g6F\'4f19X1?uHTµ†u¹†uÆxË›}Ä“v˘Ô¤ƒÖ©…Ó¥ƒÓ¤|Ò¢~Õ£Ò¤Õ¢…Ô Ñ›yРҠ~Ï{ÍŸ~ΙzÌ–wÊ”{­cN«lX±iV¬dN§bO¨[E®cN؆^á™hë¨rë«zì­|ë«sî­ræ“dÇzZ“PJQIœTD¢]M«eO®kU°l[¶cJ²hO±hY´fMµgTÄ{RÃrXÆvTºlN²`Pýàºè´ƒ¹jPÀwi½mQ­h^Í‚dÆw\PSxHQ„IQ“[_\.D‡[nU*Ea2>_0A`4Af69Z-E˜hiÄo²|iΘwÑž…Ê—yÄ—‚Ë“~˘}ÍœƒÏž†Ñ¢}ÓŸzÔ£СŠÒ£ƒÐ ƒÔ¤~М{Ñ›zÒœwÒ}Θ~Ì•}±lT­gQ®eOªgR©gT¥[E±fHÔ…aãjê«zë¬wì¯uí®sî§nä–e½pW•SM™SJ UE£^S°cO°fU±jW²gQ´bJ®aQ¶cNÔ†bÅrQÃqQÄtWÄsS·mZã™S伕ÇtPÄoP»r\Á}hÈ„y×…k³g[™Y[`4GT&:f9Wo@K[.Ik>QlAUa7KX)AqG_g7S‹f‡…X{[,?k@_C9ŠY]ЄlÌ’‚ܪ‡Û­‘׫—©Ñ¦‰Ø¾®Ó³šÑ¬šÌ¦‘Ø‘náœ訄䮑ëÀ¢ëÀ¥îĪíɹðʲñͱñÒ»õÑ·õÓºóɨã™z¦WBa.;Q":vJR¿¢Ï¤’]6IfI`i8Di:Fh=Fl>Gr^/X-;„RWÈ“€´‚rɘ~צ|ңѣ‡Ïœ}Éœ~Ìœ{É—}É›ƒÀs¿’~Å’uÇ‘uÇ“xÊš~ÍŸˆÏšyÊ™|Î~Λ֛{Ï”w°fP«cQ¯fQ¬cN©]H©[B´dKØŠaæ”gè¨}쫀ꮆï°tï«uâ›uÆvW•TL—OH YR¥_O°gS±gZ¯eS´mX±eS¸gR¸lS¾pZ½sWÁpTÀkIÁoL¼fGÓŒfÊQÂtQ×XÕŒx¯‘¡lmr8DXrO$Ck?TmIrf;VU(>l=VƒSgZ(;a7Mf?Td:L_1EoEl}RuH7†a}Ú p¹sbà¥zÛœzÛ¯•Ö¹¦Úº¦«Š×·ŸË§›ÎƒÜŠáŸ‚䥂鮑笄賙붛ïÁ îÅ®ìɵîÇ©ñ˪ðͯóÏ´÷Ò´öѮ︗ÉtT”PFU,BR(A†PZÙ­‘HO_,:d=Ok<@m?Ji?Ja5]3AnAS½‰sÁ†mÅ’}Ô£sئ‡Ô¢…ÐuΠ„Ô¤Ò¦„Ó¥‹Ï¡†Íž|ǘ€¿•¿‘€¿‘v¿w¾sÓÀz½Ž|Ä“‚ДqÉš|­dQ¯fP§_L°dP®eM°`Fª_KÕ‚Yâ›rç¨wï®{뱂ð±xí§pã˜lÆwU•PJ–RNžZO¥`S­hQ³fVª`O­cM©_Q²gY¿kQÄrPÉuWÄuYÊwYÙ–pÝ¥[S#4U&:ªmg´‰Æy]ÀqRb.FpFRN$@\4M”q•S&4h8H]0Ch?UV)=[,C`3Kf6IX/Bi8T[wQ(?¢yr¦_PáÅ·Û¥€Ü¹˜Ì™Ó¤ŠÛÁ´Ü¿«Í¯•‹G@­eQ·tcÉ|hØ“ä¥ëµ˜ëµ’걎벑췚îáëÁ¢ï¾¡ïšïȦñɨóͰó̪뮈ÃoRt7?Y&3P%9‘_tݹ©Ÿ^Zn>Gc8Ji=LrIRh[2JŽ]a¾‹|»€jÈ—zÑ¢‡ÒzÔžyÏ}Ïž|ÏzÓ …Ñž~С‚ÌšzÍž€Í›vÇ™ƒ½”¿•‰Ä•¿‘‚¼‹y¼‘…¹‹|À‹v‰q°iT³fP°fP­aF²`C¥^K¬\HÕ„[ãwé§vï®{ì­oî¯{ð©påœkÃv^“RNOHœRKª]L±eT°bK®bP¯eT¼jM¸fH»kRÁsXÇoUÃrSËz[é¡o¸oVo=G[(A´ŒŠÚƒP UISRb5L‘¤T.S}Yz’oˆS'=g;XmLZc:NW0AV'9P%8ŠlŠnMr‚[T)D`:EÄ€eÊ›ŒÝªƒÜ¹à½œÍš‚Ø»¬ÞíɑoÖˆkÞ–z×”xÄ}e’KB=;›XMÒté¯ç´˜ç®Œì¯Šíº—é¨íºí¼ŸòÄ™ðßé¹Ãfž^UŽH@‰C=X'6O*AsCUÙ¬›ÃŒwY-?}HLm;Cn>I\4C]0vKgS(?^7HyL_P!0\)6U*C‚lqX1=E 8Òž»€sà¨zß²’àÆ­Ò¨ŽÖ±ßÆ©¸lOÑ~_ÒŠnÓŠnÈ{^àœ„Ó‰l²dX£VG¤YNÌw]å£éªŠê®ì¹šíÁŸîº™ì¶™ê¶µmYŸ_[®h^¶lVÇrN¨ZCs:@Q(sHUÙ®p_yDLf;@me1;c0;S&>†RX¿•Џ„r̘|Ö¤}Õ ~Óœ‚ÏšvÕœrÍœzјvΞÎxÏ|ИrϘzʘwÊœxÉ™}Ê›ƒÊšƒÆ–~À’zÕ»}ºŽ³‡‚©`J§_P¤^Q¨\L¡ZL˜QCŸXIÑ‚\â›jê«zð²vì±nð²vì«{ä—eÌzT’ME’OG—TE¡TE¨^J¶cJ­_H¨_J¯aJ«\H­aZÓ¥ç¤fÞ[à˜uâ–i¾„zb2AIHH"CxY|Nm“€«…f‰‰eœ­A:|Wtg>R}^rV,EL#6U)B˜xšS&:]'7K);K#:É•gÛ¹¥Ü¤|ß·¢äÌ·Þ¿«Û½ŸŒJ<ˆB>h.5l29h5Ac-8rNažno[-9\(9¨V=ׇ`Õ‚cÜpâ”u꧄レô̰òÊ¥·uXf4A_2CƒGHv=@d/=kJQ(A£mdŠnÀ†vÕ ÒžvМ€Ï—xÏ—yΗtÓ™nÔ¢Óž„Ï›yÎ}ЙwÆ–xΜ|È–vË–{Èš„Ç™}À’|¿Žz¸Š{¿‰x³‹¶ˆ{¨dM¤\K¦]F§`L¡YG“PEŸS?ׂVâ˜gï­oî­lî±…ñ´ƒë¬~â“]ËyO‘HC•NF¨YI±eP°aI¯^H¯gP°dJ­\E¥WHÔ~IñćÅ~fÜ‘kã˜dŸ][Ìs€GOK*EoPtb=V}_…L&@nHl‰b†pŽQ)=Z->]7Mf>HW,AV(6d2C^.>Z,@b8WQ&E¸Œu®l`ܤtà·“Ú¸£àȶâÅ ŽPI–N?i6e19j7Ce1a-5h/7f6AW*‚RXÂ}¾†tÌ—€Ñ›}Óž€Òž}ΘoМ{Ï™xÍ–~Òœ}ÑšuÊ—xÏš|ΗyÌ—‚Ê”nÔyÃ’wÂyÀz¼|¶ˆr±†u¦~w²Š~É£‰°dLªdQ¨aK¥`O[M“M@–QFÓ|Oá—pï«tï³yì³zò²{ð®zã˜kÐyRVG YL¬aJ³hM³jS¾nTµhOC5n4B‰Ui¯„Ó¯¶ìºŽõã·^3JO&M`/:g6EM#4W8[Ì›„½‡{Ô–tÙ¹ ßƺÚÁ¤ªeOÏ{]Ñ}j׋oÊ…t¥ZO¼n`ÂŒ‰¼‘”áÁ¯íκ綋ܑmÇpXÓ}WÑx\ÕcÞs驈÷ÜÁéʰ¨YKÇ€t£y©Ž«×´¯ÒŒD<{>Eq5>Z/Bb3EˆW_Z`Ë¢•}JT‚SW`1>[-8[0>j9?\/B˜f_¿‡kÃŒwÔž€Î›|ÏœzÏ—wЛ{Ó˜sÏ—yÏ™wИvÑ›s̘v˘zΕwÌ’sÄ•Ô{»{¶‡q»´„q®xÁ’yÏ¢Ú­}à·Œ±hP®hU­fO¡XCŸVH™RG˜K<ÕUãžhêªvî²}î´ï¹‚ð´vå›oÓ€U¢VJ¢YI²dK·iL¾pT¿qSÓ›xV'9©niÖ™{ÆŠ†Æ““£tOa`/b4EtBG°|Á…hÄpÏ|Ñz͚ЗxÇ—{Ï–|Ï—uʃʗyÍ–tÌœƒÍ—wÊ“mÆŒv¿ŒvÀz¹‡u³…t³ˆx¹‚Ö§Ý´†ä¸„潄辉¯iV­bP¥aNžXK™UF“MA’H:Ñ|Sâ—jì©xî³vî¶|ð·…ð°wåžmÕOŸSC£S@¯`J¸dHÁnOÀiNÕŠT½”‰Æ‹ŒÈ¨xERmE[~RcT';[3OZ6\¤ÄœŠ¯‡p”Z5R`:NlEc[…†j‘’vŸš…¨a4?W-CX);`2@[-:^.?X+9G0J":Ó›sÅŒzÚ¦Ù±šáȱ\G½cHÓ„gÙŠtÝ’yá–{Ü‘qÝpÛ”yÝoÔ‰tØ”|Û•zÜŸÚ”ƒØœ‡Ó{b؉p×dÙ‚mç¥óÒ»îÒ¹Úª“Ú•{Ó‡pÏ‚oÊ}d¶gR«_J [D|?@W(9b2BOU€NXàÀ°˜bktAAl8?X&6pDEY)4KPËs²€uÏœzÑ¡€Ë”tΘyÍ–yÊ•|Ê–xË“rÍ—zÈ“wÍ–xÈ“rÊ“wÈ’wÇ‘t¹‰w½‡l´…u±vÏœyß³…ç¼…èÀ…亄齀鼀¬aM¨^HœWI”PG–RE‡C=ŒD;Í|Uã•cê§të°wð³†ð¶ƒô¶ƒæšaÖQŸVJ¡ZG§^EºiL½nQÀmPÃoW×™x³pgŸjgc8Q‹f…c>VP.Ni:Y‚\|’uœiF^uPoT+H`7TuRunNbwªŽpŸƒm†“‡·_0@X,Dܹ§—jv‹\__1;U%4e:?T(=›f\º‰{º‰uÍœ‚Ð}Ï›xÍ–pΘwË—|͘xÊ•wÌ•yÉ•wÇ”€Á•‚È•wÂvÄ}¹Ž²€oµ‚pج‚æÀˆìÅ’ëÁ‚鿄羇è»~꽂¦YE WJšTJ“OD“M?†A9ˆEBÎzNâ™nê©uð°wð²uñ¶{ó®rëžiÒ]VDœP?«YA¹cFºpY¿oXÀuf¥k„˪¸¤‘ºª‘¬iC]`9Qe9S{Mn‹h€X€œ…ªL"9Q+F^8Z–{•zW„gDg’{µ¿i@Xp@JY+>`3BX,9T,CU,CU(;Å|RÃŒ€ã´ŒÞÁªÑ»¥ŽD;¿jNÎxZÒ€hÜ‹rá–ã›}檋奇豖䫒嬒魑æ©â­”Þœ~Ü“~ÛŽoÚ‰jØb×z[ä—}îË·ñÜÍâ¸Ý¨—Ýš}ÝmÛ†jÓ~cÐz`°dMo/5f-6j06zBFm:C߯•¥ux{IIpAOW)8c1:_->°zi¾‡qÉtÓŸx·ϖvÌ•uËš„È•|È—|É’xÅ’xË”vÆ’uÃrÀŒu¼}»‹u´‡v¯‚uتêÀ†ëÄîŃìÀ}ê¿„é»}ëÁ…éÀ„›VH™WL”OI’RO‘K>~>;‡A?ÎzWá’cè«ì±}ðµwñ³ï³|çžmÓ€Y›PG›N?§YD°kf™щk´‡Å€otBK`Rh?Xc7OtQwvNmtQu—‚¤aT*D[6Ih?[‘rsLTK'F±…z§uh]4G\.>W/FT.DO*Cµ‰v°plÙ´’Þ¬ÞϱT%7–MAÇoKÐy`ׄgÙˆiá–råš{处讓벓笔簕簌鲗孌á¥Û“xÞ•yÜŒuÜ…a܃iß‘vîʶòÚÈ㸛ऎកÜyÚ†vÕ„kÍ}^¸gMt>Gm;Eh4Bm7Bc/Dâ´•³Ž‡f6Bg4:`5@`/9h4?ÂŽu½‡uјyÓ¡zÍžzÊ™zÉ—É“vÍ•sÈ”xÔwÄ’xÑz½wÄ‘tÑy»Štµ„p¸„qÕ¥zéÀ‰íʼnìćí€ïÁ|êÀ‹è¿…éÂ’éÆ˜™UJ‘OEŽID‘OI‰JCy;6>?Ê{Uä›pé©të°vï²yï³{ï°å—_Ñ|Q£XH–QG¦]H­na¼mVÀo`·ytxMaXvƒ^|rF\^6R‚`ƒ^6U–„±m„]8UY0HZ.E[/HV)@_4LyIWi:Me5>P'D§lc£ic\/BY4JS)AN&7[2GÃfÄtá½£ßÁ¢M'Cr=Cl9?k5?c-?Ú¬œË¨Œa/:[)7e5?_1=ŽVNÉ“n‡oÔ zРzΘtÉœŠÆ–wË—~É’vÄ–~Ç‘uÁ“‚É“‚Ãy¾‘„¼Žy¶…u³€sΞ纃ðÀ|îÁ„ìÁ}ìÄ„ë‚鿎ëÆëÉžéË©JGˆFBŽOKŽJDƒC`3B_3C[0DX5I\.C~C?p:E«qc¼X©zuN+DH 6M!9»…c¶sdâÄ©âÄ®¹—vP(;k17žUHÌtRÏx\Ú‚hÝ…aãqá–zã“mè¢€í©„ê²’é°„ç­‘ç­‹æ¤{㟃ݎhÞŒhÛ‰eÒ{YÝ€XÛ|麧òßÎ㻦ުŠßžÚrÙ‰oÛ„jÌvZTGg3>g1;m3R&6uADr9o3:o/3ÈvXà—jã£{í°„ë±xï±{ð¯wêžeÖ~O›QA“MC¡ZG©db§zµˆ–WisGhˆ\|„^‚d8Z€b…ˆuš€^‹{\„Ÿ•²Y5@J$8W-Ha2CV.Da2H‰^o[Z¬zn²uZt;^,|?=i.;i/6ÁwYá–lë§uí±„î°xð°…ò¬{ècÒ}W—PA‘KI²|‰´of¯lj»uluE`…[s€\vNizPoa:^’yX5Y€_Ž•†§^0Qi>SY0LkDRS*EBMDÎ}\á™rè¨té¯ë¯}ï°|ò°{ë oÕƒ`žTG”MC¡YG±cIºoa¤jq¡an†^u¬}xxMmI&N˜€”__yUzyW†}š}b‰ª¡µ“~ L#;f’`d§oj´—œ¯tY«smØÏÂJ$9S)¢dX«YCÆoRÓx[×~[Ú`Þ†kÞ‹qà‘pâ”rà”uä”wã˜|å ç{äŸtá˜tà•oÚŽzÜ€[߀ZÖfÕŽß¾®ç¼¡ä¦†Ý›Õ‘}Ó„mÇxXX,;X1GU-D]3A…IHs=Aj6Ò „¼ŒzŒTQ¿‚cÒ‘bÊ”rÔœù˜~͘}ÎÅwÔwÈ–È’oÊ“p¿’~ÀŽr¼x³‡zÌ—së¼ñÂzðÄ{ïÈòÑœòÑœðΘíÍšñÑðÓ§ìÒ§ìÒ­íÓ§îÔ±ˆLAI@ŒE?I@|>=†GC¤h`ÑŒsàœzè©ê©jî«xñ³~ð¯tè mÔƒ\¡VH”SF£TE®\KÓ——¨|‹mPk|Rl ˆl>M[0B[0Ra9Ng@awQs…eˆyVŠn™™yŠk>X‘`rˆRYL%5M'@¸”•Æ~Ï´¦Í¬ZN«uem?9W(<^+9h3>k:@mÆmLÏ|`Ø\Ü~]ß…gà‡fä‘mߊmã‡bâ‹láqÞ•wà’sá—vÜ“uÝ“oÚ–yࠃ宔íͳ婒ëξ绖ܜ†ÚŒpΉv®ofZ->V0FW.?a5Jj=KŽPIJB{DAe2>X'<¾Šr¬t`¬s_ÒfЕvÊ›Ο}̘yÌœuÈ•|ÈœˆÆ“~Ä”zÁ‘yÁ‘z¿‘vÆ‘v¾w¸‡p¹€f×¢wòÀ|óÅ€òΗñОòÒ¡òΘïÑ¡ïÏ›îÏšëÒ±ìÓ°ïÒªîÔ±îÓ®BD<9„KF‚AA}>>‹IH^VˈtÝœvç¨zë­뱄ð´~ñ²|ç¡o؃S›SFŽFE°sn¡^Z¶iR¡jyqDWˆkŽg:I_2JaAVw\…sQe„]yhGhuMr‘q–V2R•w‘ ”¦@)EqCRņyϼ¼È«§Ü¯“O=›\Pȵ¶T/FT)>¦k`e2?m9>f4>ŒUM]*3a*:—VKšSJ¼`CÖyQØ}WÚXÞƒ`á‡^àŠgàg܆eárÝo݈`Ü‹kÜoÙtÝ‘ràœtã™jä”læžyðÀ•砇夈Ջj΄rΉvY/FX.>a6DX/C_3@v>CŒPHF>}ABd/8X&<­z®ub¶|`Õ_Ì”lÏšuÏšuÌšxË›~Ç•}Æ“vɘxÓ|Á“wÆ‘tÆ“{Ât¿Œv¸‰o·ƒoÚ¦tðÂzóʈðÑ òÓ›óÑšòÓ¤ïЙíÏ îÒ¤íѪìÕ®ìÓ«îÔ¬íѪm5=q78x<<ƒCB~?@‰HAœZMшkÛ {é®ꬆí¯yï³…ð±të¤qÜ€N”NH•UZ±vx¦^V¼‚…—_kZ,G_5KtIa_9TsNiQ2TkHhˆd‹‡c€tOn`=aŽn˜ƒn‰w‘}Wi×®µu‘ؼ·åϼ¢eI¤fYµƒqU-=V+>V,?‰PH]*7b.:n=>{B=a+4_/>…FC‘NF¶`IÎwWØ]Ú„aÜ|R߃XÞ‡câŒháiâ”k²]=­YAÎqFÖ|MÐyOÕuNÏqGËjEËnOß|K؉g“C8»jN¼lTÛ’u½|fT/JW-AX,?W-;b8Fh3>x<:ROk2=zC@\&8›e`²̓ZÙ‘\ÍoÍšuΚuÍœ}É•yÇ•{Æ”vÂ’}À’yÅ”vÀŽuÀrÂ’t‘y¶‡sµiÞªsñÆ…óΔóÓ¤òÔ¢ðÑðÑ™ïÐðÑŸïÒ¥îÓ§íÕ±îÔ®íÔ¯ðÙªj:Eo:@z<;|A@z?D‘YT«fWÐŽoàž}ë«uì¬xî±{ñ¶{ò´†é¡jÒ…aŸTQË—‹™NG«e`ĉ‚†Sd}Tq]7LkCW\9RnF`{T`=[¡±ƒcŒ|XuŒjŠ‚^}•u’aB^|RnÝ‘eÛ„jîàÕÙ¼Ÿ©j^´thÀŸsW/=_-7V3Bi58_,9i39i68p>Cx=@d.Bw8:‘VQ¬[CÇpRÒwTÖzPÖ€W܃`݇`á…fânà’sÙbØ[ÖsWÓnLØvWß|XÝe×zZÚ}nå€å›‘Ý…vÔ‹uÜŠnÖŒj\0FV3I`7CV-Fa2=zFIk7?‚LLRIe0@Ža]X+;…PP¿ŠÔˆVÙŽ`Ì—|МvΘtÉ—uÇ•xÉ—|Á”}ÓÀ‘•¾‘~À’xÀ’|»v´„n³ƒvä±yôÌôÓ˜òÒ£ñјðÐñÑšñÓ¢ïÒ¤îÒ¦ðÔ¯ïÖ§îÕ¬ñÕ©ðÔªh8Dp7<{@@€A>x:?ŠSP¤bRΊnárꮌë±sì°rðµzï³pä¡}Ç}vÇ–ŽŽHD›QMÆ…±gX”cla1MnASO&8P'D|Piw]€`Ec…›V3T†l’Šk’€^z\7YƒbŒ¢ƒšç”cÌsYßÐÃ[NÉŒyÙ¼¤P-C[9Kc5CW,=\-8s<=a.;i58t?CHGd0;‚D?‡RI‹GA¶gKÍtUÌuQÔ|SØ~TÚ„fÛ‹jãkâ’sãmÜ‚ZØ€\Þ‚Xày]ç…kê†î¦‡ï±”قwÕxÜŒiš[JY.GX.?e4@Z):d5l9>h6A~LI_4F‘VS‰OH}EE±`D¾nNÇrPÐwPÐ`ÓdØeÞ‡bÞ‹kä“pÜ‹i܆aÔ]×|TÞƒaæ„bçŽ|ê“ëuä…pÔ•‚Ü—yʆmW*@U/FV-A_0C\,=b-4f17…E=w=C‘RL€DC’^Yh8CuFTΆ֡ؓfÊšvÌžyÊ›zÍ›xÈ–xË›|Èš}Ä•ƒÁ—yÀ‘yÀ“~»~Ás¾Œr°„r°{cí¿}öÖ£öÖ¢óÔ¡ñÑ›òÖ¨òÖ¨ðÕ¨ñÖ®ñÖ§ñОîÏ›îÍ”ðË‘ðΙc3?g5>p::o9=q69Ÿ]LšUKÏ„dܘsçª|í³‚î´ƒðµxò´|æžlÕT˜REEQѦ©¦`Y«nl_1N‘q|Y+?X2N‚g„[0NnOv±¶Ô}Vu›‘¸z™a>[cCh–ˆª©xp•w‰®¡¾’Þ§k穈m9FY5L\4Gf6Ag4:X-Bj58c4@r=Cf9CvBEq?B_/>„QRˆRMw@C T>¶eIºeEÃnLÊvZÔ{WØ‚`׃cÛ‡hÞrÞŽqÛ…hÛ‚]×VÒ~WËuVËv[ÍrXÐ{\à …Ú{Óor6:U+CQ%<\/Be6CyDEk7=o9>WIˆEB•]Qt>=‘UGl6Bj;IÒ«˜Ú¡„Õ”iÊ›tÅ™tÍœ€Ë™vÈ—uÇ–vÎvƘÁ”|Řy¼x»w¹{·‹y¬}l°wdìÃ…÷Ú©÷Ø£ôÕŸðÕ©ôÖ§ôÙ«òÙ´ðÒ£îΗîÍ”íÌ—ìМðРðÏš_2Bg1Ag1:e/9}?>°iP¨fZ΃iÛ“ié£nê²€í²zð³ð²xé¥yׂU—VO†?H¹–£abƒT^g:UrŒ]1DE"A|_~iA]O0\¶¸ß”vbHb™…§€`„€[wе¥qvŒoŠi‚––÷Äw¿{]S.DZ4HX->g7i7A\5Gg6?e0:`.=^,;k9i7@j;Bm6=†I>:2£WC²bG¾jPÐ{[Ô\Ö†eØ‹pÙ‰gÚŽlà‘qâœ{Ý–säž~䥌é­äžx䢄ޕ{Ó•sV&9„I@W0IY1E]6In[,BÕ®‘Ü¥zÌ›|Ë ~ÇœyÉœƒÈ–yÁ–|țŖ€Æ˜y¿”{Å”¼”ˆ½x²Š€´‰q¥{k¤ugîÇ‘õÛ¬÷Ú£óÖ¤óÕ¥òÔ¥ôÔŸòÓ¥ñÖ§óÔ¦ðÒ£ñÏ—ñΑòСó͘\2@d7C[-?U0D’XP¬gT©eUІcÞ“jê¦zë²zé°vì°…ð³|è£rÖ€STHIF¡dZ”[\`8IW0LzQ_e:LO1R€Wp\:TiCe ’´gAW_=Y”…³””|¢v[Œ±’ŸË••hD_ŸkktCRg7JW/E\3G\1El;Ek9AZ/Bk9BW(7m=@^.=`/>n8;v:9h7>l8D?u99u4.–K=±[=ÁnPÓ|WÖ~Y׉kÚwÛ“|â›zâ{穉壇穈奋樊अړyÇŠuS';r>FS3HT/J\4Ip>A\,;m7;`/:™aT‹NN„I@‡OHŽSCŽYUZ+F×®•ÙwÈ•|ˢ˛vÅšƒÅ–xÄ•|Ä“v“yĘ~Å•uÀ”z¹Žz´Ž|²‡x­…t¡{l¬rðÏœõܯ÷Ø óÔ¢òÓ óÖ§óÕ¢óÖ¢òÔ óÐðÍ—òΘï̘óÍ™ïÆŽ],?d5A^1B\->yCD¤aL¿rSÒ†`ß–mç§uê¯{í°wí²}ï­~é lÖ…X™NE|BF˜\Yb:Ic8JQ1Hesb8O[0Ki@[S.GD!J¢´‹i‹mGh…k–i‡š‡ª‰q™’s°Šš†Se–k`qERZ8L[0D[0CV/Dj;D{BDV-?€F@a2=`2@[,:]-7h6@c2:d2;md)1ƒ??§\HÅtTÉtUÐ}aÑ‚kÞŽlÜ’oÞ“táŸ~奊簗䥄妌àš}Õ“v¶mRW*>Y3M_Ÿh^‹MK…HC‹LA‘XJ’YV\,CÚ­˜Ú¢€Æ–ÕzƘ}Ä™€Á—ƒÄ™„Á—€¼”€Å˜x¿–w»w´{µŒ€´‰x©užvj¾}ôÕžõÝ®÷ÖžñÑ“òÔŸõצõئôÔŸòÑŸóÎóÊ‘îÇ꾌â¨{¶qFZ+?].@W+?v@>C=<3•QD¥`K«j`Æy`Ñ‹sÕuÜ”wâŸ|å¢~ݘ{Þ–uÖŽnÅ‚g£YDR-<\4EX3N];Q]4IsCGg8Dg5?i:E™`[’]X‡PM†NK–_SVG]1GÚ°™Ò•k³}f²}gµƒj¼Œx¾‘~¼‘}¾“€Å”z¿“}¼xµ}µ‹y¯‰x«ƒv§wŸqfد~õ×£÷Ú¨÷ÖœöÕ›õÓžöÔ—õЗóÏ“òÏ‘ïÄŒëµw͇Ku:8Y+9R+>f5@`3BV)W+@‘PMƒNLR)=}DAW-=]2Cb0>^0=[-=a.:m=Aj5:m9Dj5:s;;•NA›PB½mVÈzgÔ…h׆jÖuЉpÜ’uÙqßœ|Þ ßž€Û {ߥ‰âª‰ß°“Þ»Ÿ¼œ{QZU9NW1IY4H\5FoAM^4Bc7EJI—\QRIUO„LL™ZQ‡ICj:DÓ©“Á…c°z^©mWªsf±z]±i±t²ƒn²†vÅ’w½wµŽ{´Šu¬‡r©p¢zoŸtoçÂŒö×¢õÓ˜öÒ™îÏ—ôÒõÑ•ôÏ–ôʊ渇ΙtƒHCQ#7Q*=d2>u<He5@_-BY.?a.<„H@ŠIAÇaÚ‘jæ¤xì®éªtë®}ï¯wæ›iˉ}ྈzFO]0EwIRP-Hh?RsFRe:Ia8KrKX]7MX-Ke›©¢©^9TY8\œ‰° ¾„h”†kƒ’p‘’w”nIZµ—‰k‘O3Ha6DEIq>D^3D‰QK\-@Z+?c4B_/:a1Ae4Ad6Bu@Gu@Dg4Ai6C—TI¬`OÌxYσeÎ~_Í~_Ò„cÈ„mчiØoÛ“vÙ”pÖ–yבrוy× ‡ß¯‡çÀ›êâëɤáÅ«”uˆW?U_;LfI)?R+D}N^b9MV/HlHTQgnBXN(C—‡ª[}ˆoŸ¶¤¶b?[|]‹‰k“‹sŒvOx¬—¼­…Ž’ytZ=Q^0Ax@Fh;HV2GŒTNX.=Y+Dm8Bc3=h5>ŽUT·hMÊz_Ë|_Ì~aÏ{`΄lЊqÚ‰fÜŠaÙr׊j׉i×rÚ—yà£{ã³å¿çÄèÆŸêÈ¡ï̪êΪ•w†M-=M)>Q'9k:CIE~GIƒLITQ‹QI~ED†MPÖ•gµ~gÉq½…j½aµ€q³xc«tf£iZ fW™g[žj_¡sn™i_ob›iX—lcžj^ïÄŠöÑóȉõЖôÒ—ñИöÑ—ëÁ•Ù«|QFZ.Y0>_3H“v”G!;j9PiyK[L%>S)K£“³wšƒ\™Ž¬qTm‚f‹k—”«‹m“Žjˆ ~Ÿc4Ež’Œg7C‚CBa3CS&<‹OD\+9`/>U';f6?_3GX-Bg9Ci=GKJk6Aa0<…FC°gO½qSË{bÌz[Ð}^Ï}aÓƒcÙ‰pØŠmÚ‰mØŒnØŽlØ“yÞ™zܧŒå¹è¾›çÁœè˜êÇ¥ï̦ïÌ©òϰæÏ®iJQF 9a4:ŽVP€FGxGF„JG€EDLT‘_`Ö’h¼†w¼Žx¿s¿‹o¶„r¼„n±~o«ub«p] gZŸcV•aYYT—`UªqW”^QˆOO쿆öÏ’öËôÓœóÍ“òÌìËá©vSE`/<†OJ†JJHF•XNSJ“VI§‚¨Œ‹§ƒ‚žso‘_RƒEBc*5–UFÓˆeä£yç¦xê©tê­zî®~ê iÎ}a¹~t¨toR.IV/DL$:I#BŸ}œl‰L,KŽo“uFZ€Xo]5Oa;TyMghDd™†ž]8UsPvz_zu—uœ—¤¢†£’c\vJ^tMbŽdqw?C]3?Q+B…OJ^3Dh8DZ2DjEyDFc7@ŠPK¨fVÄtWÆvZÐ`ÏaÊ‚eÚŠhØlÜ“uÙnÙˆlÙ’tÛ•xÝŸ€á«„崌鿙徚èÁ—éžíÉ ðͪò̦òÒ®óÖµ‘ya6=e9G{GLyGHŒQG{CCk4:®zmЕuÍ’sÈ”y¿“wÀ‹mÂw¸Œ}¼‹{·„r¯{k¨xm¡na qd‘ZU®t`Æ‚Y™bRVPïĆ÷Ò˜öÐ’øÖœöÒ›òÍ–Ø›jszUgm?RlE[c<[‡i‘koM&F–Š­`9UkEbb@\yX}‡kˆš‚ ’|¡“¨K#C»§ŸP*Iµ˜‚d2GR.FN)BŠOJf3Bd9KR1Fb2@g=Ib1>]4Ii4At?F©cI`0>‹WR±o\ÅqWÑ„^Ì~]É{dÖ‹o܆aÙŽiØŒn؆dÙ‰gÚ‘lÜœ{à¢ä§ƒâ­‰åµæº˜å¼—澘ëÅŸðÉ¢ðÍ£óÏ«õÓ±ô×·ž‰_6MtAIsBC~JFw>@\(=ÈŽ{ΔuÏšyÄ—}Á‘z¿s¾Žwºx´‡xµ…p³…u¯|p§xp¤yqŸnf¸yVÈ„X¨j[ʈ\ôË“õÕž÷Ô ÷Ö óˉ뿃¥gOW*>ŽPG—YL–XK”RL¨gW_N˜\Sœ\I›ut¬Œ«——«•¬‡{”ZNa,9—PBÒ‰hç¦pì¬xì®wë«oåŸsã”tµuiÑÅËE E¸wgÈ{_Êz^Áx`׈kÜi׈lÛŽmÚŠfÝgÚlÝ•wàœxÝŸ}⩇ã¢~孂䱿¸Œë»‘ë¿‘ìÆï̦ñΤñÓ·óÖºôؽ‹fi}C>r;;~FA‚HHP(CÙª‡Ë‘pÅ“vÈ–t¼‘r¾tÀnÁz»Šw½‰u¾Šu±‚o´‚n¨o¨yiµzYȆY»uNÞ¨uôÓŸöÕš÷Ô—øÕœíňןiB?zDGŸ^Nž_S›ZL­jU´€z¡`M“QL¢`UsEQœ~„¬“—¸¡›º–…¡tna.9•SC׌`è¥zðµ‡ë±€í°~ï±wë jÝŒZ¤y~g6>P(@P&;b6AV,8W0Bk8FS.BQ*G‰c{sJbK(A\6@O&BY;X|VfQ.HnFalJpx—’u–˜}—¢”·¦š±¤‚†j<;a8[ͺÁM&8M$7w@Eh8Ab0@S)@^2E~MO_0Q1G^1C[/J“p…^:LX&3J!=‰aP-GoEe„a€nMd{XhDeˆoŽl‹‹p”­—¨™{‘D#@ ˆ©ÝÙÓH%q;@~DFa-h‡{W{sMpaŠlˆn‹uVx€a~¢”¹¬›¬c3K]3OŸszàÖÍN+EP&9}CA„OEc4AU.@Y3GvACb.:_2?l6>ª`N¾pI¡ZG`,;¦bSÉqOÙ\Ø€bÛ‡_Ü…_܇eÝ‘mÜ‹eÝkÝ’kà‘iÞ˜tà›uÝœyà¢}ä§㬄届沉溗ê½ìÄšïʨñдñÒ´óÖ¾õÜÄ÷ß»k:;e/9^,7a+7ÕšrËjÉ–xÊ‘lÇ”w¿lÀ{¼Šr¹‚³‰v¶‰t°„u®q«zh±yfËlä¬sî¾{õÏ—õÙ¥øÖšøÓ˜òÈ~ÍŠOšXQ¤`M›VO¬fT²oV²mZž^NšYN©gY£kdŸi_R):a3F¢Š‹Â«¤½¤—¦ƒ{O&;†G<ÙŒ`é¨xñ³ë±sî±}ñµví¦jß‹a©~{M)Ce7MX-Cc:Jb;HV.C]7LS-J€ZnˆbxH"=qJT]/DQ%;[7RaP%:iCO_6GY*ÔiÆ”yÈ“x¿r¼‹sÆ‘sÁp¾sºˆm»‰m²€n©|s©ye°zcÜ©vùÔ›øÕ õΑøÕœøÙ¡öÔ™òÈÙX¤]I¡\K _P°fO»sX¸u\œZNšZL«k[£dW›`X”_^G3U%:›z»§¢È­¡­Š}[)3z88Ù‡Wë§wí²|ì°|í±xîµ}í¦pÛ‰Y­rV.Ie>LN$9T*9[,?]3JR-H”yœl>Ie7IK'@S*@vJ\bf5@c05f2@o;Dj?Id09_-=v=BÁrQÏ^È|^®[DyCA«iX×zP׃g܈gÞˆiߊcÚ‰dÛ‡`ÝŒfß…^ÝŒhÝnÚ~à–rßœxàwß¡᧊㯎ä³å¸Žå½æÃ¥íɬðϱïÏ´ïÓ»ïÖÁöÚ¾öß¼­scF0¬kYÏ‹dÏŸzÈ•uÁrÃn½ŽqÁqÀp¶‰t²ƒn³„m­€r¬zhµw[꾆÷Ù¡ùÔ—÷Ñ•öÖ øØ¤ùÒè´}ÂuK¬_H XE¥_L²lW¹oP§cQŸ^PŸ`P¦g[škh•aZˆVVJ!4U(>™|…·¤¤Âª¡­…h4:|>BÚˆZê§rì®{é²yæ­pë±vâŸrØ‘lžs„g?PU-BQ-CU,9[)9V,JwReO1So†xSeZ/BW.?d:HP(ÕƒWí©xç¯~å¯~è±}çŸkÛŒb¶~xNXW)=\8IV*=_7FV1DQ/AZ4G„\muFYS,>mKY[6GV-A_8OU1?V-HŽq”d>WL*Ik™œ˜„Ÿ•n‘U(;V+0L':\39j;=¥€Œ®–® ’`.9f8DmÕƒZë¨mí±xî°uì²tì²zé¤pÖ…`¥mrk8EfpH^W,KnFVB!;g@]‚`…Œz Œv’‹p•ž…”U/GO&9m6m@LvLPq?E¦}bi7?c2€Y\¯˜™½©Ÿ±™wGI}>?Òƒ^è nì±~è®ê³ƒíµ‰ç¢fÚ’kÇ|vGRd=NW.BO)EY4Peq]5ET,CkCWc9M\0?X/AL(?{WxX->a=VzUq[6Sb†V;L|f“†r£“„¥kDhr’“m‰W-=L#8tBFc6>s>Ei4QkCVc:Qc?Te8LW3Hc8OY2Gy]xgCi^>Uz`x™‘±h<[hHoœ}˜¥–¶H$8j:@S(Y2DR+<\6IoJ_rGXZk;DR'5`09Z'5Z,:_05k7?–SGÂnKÌvSÌ}]ËxXi7IšWKÓ‚[ÚˆeÙ‡dÝuß‹gàgÝqßdáhàiÝŠ_Û‰`ÝŠ`Þbßeß•oß•qàœuÞ›qà¡~ᩃ᫆⮅縒佛èÀ ëÉ®éÉ­ñÔÀòÕ¼ðÕ¿ïÓ¼ôڹͅU–[G’VHWGcM¦p[­w`±†x¸ˆp·†n¸u¸‹pÇŽnÓœfÑ’^ˇV͈XîÑúÛ£ûÕ’ç¯aÅxN¶fJ•SG›UGªfOMB•TI¤lfŸ`W—bZYXœkh’^YˆVUu>?N(:N#5^1C±›™Æ±«¾¦˜—oju<=Ï}Oãmé­wê®yæ¯{ñ³wì§màa¢kk‚R]Q)@V*;[-=U+MV/Eg?SZ6Ke8F`6DX,AO$5Q(>X.?iR‚‰u ~[œˆ™\:T€bˆnF]c;Sƒj„€Xrl>G^0X)8V(8g26ŠKGµeFÈxVÆsRÉvN¨]Ae9MªeVÕWÚˆh؆_ÞqÝ‘nã’bÞŠjàdá‹ZáŒhÛˆ^Ú…[Þˆ^ÚŒgÞŠ]Ý“làšvÞšvÝšsßžpâ£xà©„á«~ß±Žå»˜åÀçÆ©ëÏ·îжðÓ¸ðÓ¸ñØÁ÷Û¾ÊwSIaXF@†GBŠQ@”]M“]Q–cTnb¢sf¸‡qÊ–}Ô¢rÉ’iŇ_Õ˜hõÑ’ýÞ¦öÉÛW¶jP›S@ŠMCŸZP˜SIŒMEaXž`Tš_[“_W•`\˜jfa]~JGm59N%9E0^4I®•ȯ¡¿¨˜£|mz=;ÊuRãnç¬~ê±yë®{ñ´í¨tÞ“`¢ps‹YcM%?f;LQ0JP(AU/Ci>KU4Kc9HW3Gj@Mg:Qg”NA’MF‹KCžbZ¥nc‘UP[T‘ZRžf``^‰WWk;@k7@_/:nS);V.@]2E]4G_8MW2Jd;T[4Hi=Qf=I^/CjBSR+?X1@`S'4X)7h.8ˆF?¶hKËxNÆvUÌ{U{6/g3>°mYÓƒZÝ‹_߆`ÚˆhÞaÞ‹_á‰aߎiânÞkàŽ_ß‹cÛ…Y݆[ÜŠ[Û…YÛeÜ’nÛ•oà™mÞ™nàŸwà¢zঃⴑ㳉世åĪéǬí̳ìϾîÔ¿ïÔÂõÙ¾ôدNC™`K¥hZ¡fU–^S‰QEƒIFp;Ae38Z+5U+6xBI߯€ïÆ‚à©]î½}úÓúωܖS—RAs9;‹JF’WLƒIG–YS¡lh™^N“[Y\S”YS li]ZxJIs>>g2<”\V‡PKŠ\`¦ˆ~Ƴ¨Í·§ª‹xBAÈsHãŸyë®}ê°}é²{ð¼„ë®qÀoX·‡‚zKYR%7W0GgAPX0FR(<\2@X7Oc`5GsL]S)>I(I„k‚ž“ºsšŠbƒ¡}ˆV0EW0?V+5R&6R%8U0?Z*?PE™YHÅrNÇtUÉwPC6W'9žXMÓ€YØ„WÙ†[ÝŠeÜ‹f݆]áŠ]áiãfß“oâ‹\áfÛŠ_ÝjÚh݈\ÞŠcÝŠ^ÚŽfß’eà”kܘqÝ›yáŸ|ߥyß©ƒå´ãº•çÀ¡çÆ­éɳêÍ»îÒ¾ñÔ»òÕ½öÙ¸ŸeX™^M¤k[¦o\ŸgZ”_U“]VGEtEM_/9O'=DDòÆ‹÷ÍÝ™[óÇyüÔé¶q”P?m57{@>‰LC†HH‹QP¥i_šcWˆPO‰TJŒTJ˜f`¢ttˆYWzIJr@Dk6>[VZR–ljª…­¡Æ·¥¯•‰€FAÂsSàœpê¬tî±tê°ñ¸wé­l¨cN¶{jƒQ_Z1EU,C[3BV-=X+=Y5IW1DV0DR*=pGYX0Be=RU-CW0He9JN$8j?MZ6MhCVn@U^:Sh}w˜T/E`1>T)r0P!3˜WEÎ~WÔ~Vׄ^Ù†c߉aÓ†eߎaÞ‹\á‹cÝdÝqÝ‹_Þ’oàŠ\ÞŠcß‹hÝ‹^ÝhØŒiÚ‰^àdà•aÛ”iátÞŸ|ߣ‡Þ§{ã±’ã¶—ã½ æÃ§éȳë͹ëѽòÔÀñѸöÙ¿Ôµ§’WM j`©m[ŸdUšaR˜\QŽUJyF@k:?`,9ˆILèµ|öÉ{ðÀuõÆ„é®g—YCg3;j5=LFz?CŠNJœbVš^R‹RO„OO‚LF’ZW qr•fa†UWSRo:BrBK…QMŸqnŸro©Š„Å® È¯ž±–††PFÀqRá›oç²xè¬që´‚î¸vî­v®cS®rm_3Eb9JT3GZ1C^6HV,@a8HQ)@X4LcF]iBQT,CrK[g=R\6GV/GŠf}^8TnB^a:UoOf’x’l?S[4@p?HV+=R);X-;O)7S%,a1:MA¶hK·iJ°eIO!,a-7¯cEÃtOÑxQØ„WØ„WÛ‰]܈WÛkÞ‹aÜŠeÞŒhÞcß‹aÞiáfÝ‘jߌeà‹cߌ\ÞbÞ‰^Ú‹gÝiÛ‘iÜ’eÜ™tÞŸwߤ}à¥|ᧀ௑⸖你æÅ­ìͰëϸîÒ½ïÔ»óÙÃïÕ®‹MB™f^¡hYŸeUg\—bU˜bWˆUU†NJ‰VOœ\Káµ}úÕ—ôÅ}×’Z›]Lw@?m5;ƒLGE@ˆI@™aV£lcŒZX}KP†NLŒ[W kg¡mj^^‹XXtDGwGIg6_3HoFXY/Dc;P`=QU0GyVrvP`O(~`hW3JjIhsNx£–º\6GfE\O*FX/6Q)9Z.:\*4}B;–Q=i29O&4j6>ŸT@²cGÇuSÍxWÔ~U؃ZÔZ؆_ÜŒ^Û…[ß’kÞŽoߊaáeãŽfß‘dà’já“jÝ’ißbÜŒgÞŠXÛeÝŒaÝ‹\ÝŒ]Ü“kà˜lÞ™rÞ¡|ृã©z⯋ඕ忢åìçÇ­êϸìѽðÒ¿ñÖÁðÕ°ŒRI’ZP›eYžl\—g\šg^–dYŽ^Y–a]™\S bZà«wñƈؖTRH‚LFz>C~F>…GB„LKžb^¤ph“_W€NMu>A‡LM˜`XŸoe›id’a`yDGp>Fb2:~W[†]dšz~¹¨¢Æ¯¢µ™„œi_ÀpJÞ›jæ¬vì²|îµ€ó·}îªlÎoNVN'@S+@T1?a9Mo?Q\6J`6F[1Ha3IW/HuZsR/G€]€‘u’sJ^I)@ƒaqM#2pLs•x_:X–€£‚buo~T2GQ*>V-?\1>Z)7X(6U'5l7>NC¤YDµeMÃqSÐwQÎyRÑ€UÒ~TÕ|QÔ‚\׆bÚŠgÛˆ[݈_Ý…YÝ‹dàŠbß`ÝŒgß’nâ•kÞgÝŽdÞaÞŒb܉[á`Þ‘iÜdÞ’ià™oàžàŸuà£â©„â±äº˜äº¥ä¿£çÅ«é̳ìлïÕÀñÖÀñؼ»†y‡RJ’b[–eUžgZ¢qc—cbœf\­t`¬lX³nVÂ{W¹xT”UKPG’UI–[PPF„FE—aZœga“^TJF{IMwBH™c^œpn¤rq“cc‰Z`vGLq=Aq>A_0;d:DiXb=W‘v”M(Fm‹ew@8tI]U.?gGb™y‹sRhiCSL$6Z7ER&5a,/t95–N<¦XA¹mOÂnLÈv[Ï|ZÑzTÑ|WÒUÕ‚VÖRÕ‚XÚƒV܈a݈]܈cÛˆ\àŒ_á`Þ‹aÜŽkÝ‘màgÝbÞ‘làeàcÛdàeá’iÜjÛ“dÞ•pà›vÜ›yà¡~ृ஑ఇⶕ⽡çĦåÈ­éεïÓ»îÕ¿ð׾߯¯‚HCŒ]T’bXšfZ¡r_lZ¤te­v^¯nS¹pX¬kX¨eQš^V¡eT¦dO–VJ‰JGSRœlo]XKL‡RN~JK‰RI§zv§{yŸnh’e`}EHq=Ag6>i8Aa3>`4:`1:g@H‡_hκ°âË°ÝÆ¯«r¶rYÞšsí°}î³xïµ}÷¹}ç¥wƒQZh?K]3IV*?O(6_4FjAOb8Pg?Ua@NO)@S+LnƒQ/DmF^sC_Œ­[>QhGd—‚¤V0FgCf39}A¹jDÂkHÉrHÊyWÉuMÏ{MÒZÓ}SÓ|Q؃SÙ€S؃XÚ‚X܆\Þˆ[Þ†[Û…^äWÝŠ^߉[Þoáná‘jà“jÝià’ià’hà•já–kâ“mß`ß—lä›uáštãvÞŸqà¦yߦ~ⱈà³ä»¥ã¾¡äÅ®èÉ´ëϸëмìÒ»ïÔ³†LG†UQŒYK—f^™g\¥sg±t\¿~_Â~b¸uYºqS½oQË~WÇwP¯iS`^œg]Š[[SV…MPƒNI…MF—bY±zk¬ysh`†W[r??c1iÖÚ5,FXà{ÔWàý‚cêµó÷Ôú4ŽBû¾OãWíIÛY01uïÉ­+`6u®©‚EñƒÏz\ð3ëQ¯®iø#ïqŸZËVV‹pb:´)óSEh³¸Ì˜\ŽTf­±&ùìxÏÔ…iìädêÁ;Äõ¨.tgžµfâm%òîa?töo¡ÿ=j¼¬`I4ËV’º/é2m¶7ðœf¯2Y:[|ŒG­j9¨¨µbÊèÙÝ£Ÿºxo¥QñFöKñ}L7GŸfÇõÖ–I20:VÆžcÖ4©´»ƒ† òÔzô51vfs\¾ñÈ Üvç­sú׈šÚo³é²5rqÈ^Äñ¦xT¸±¸›Hˆât%&‘‡‡ø×,T*ásÁÁ¯B ûÒ"u:Dô‹ëó{¯@ªuà{šßÔŽ4éOûÆXñ}nqÆúìõùÉž›k‚¤i œ= ÄCŸÆ´íúrx¬»C˜¾ï«h,‰c.ìGNIÀ®‰Š%–—ÊRwÿ#Þ›!€Æ}½*;¢îuV;Ê©$tfUn§±ì}j# åª-Á•c‘·ÿ¥oÚ¶èÔ]€;@ÿ<aÚC%ë«©Ù8.GSþÏ­tV¡!M±ð;±ëøÖ±×s޵‹eÌF+”V¿ƒÿ¯Øý+‹ñ–úèÊÒIg6r>2º’;÷?JîQ”ûúš{ÅÜosË Œ:0È5«Šg<*Ê›¿C‚ÐØ<.zóIs©-®¯œ¼$Àí'ÔTú~.‘}y§ÈKˆß1¹Þ‡¡þŸPk˜ñœsÏ«ØÅgÉtÄùi剮xÚ«ƒ=5ÉÌŽÀ‘Yÿˆ_ÃöÈmmü ˆÎ3±zÇè=þ•Òé ôúe»ÝË]‘~eϦìóøqîkÇ5ÙõR{»¥).â¢3ÿ,Àãoáþ5T0íËÞÙ:ðjÑz•YÞGf•Éiœ’O'“ÔÖÆ‡áöÕeF”¶zãû£ÜÕ-/N—T¾ŽÞ"@'s?e^æ½JÂÎ++tŽ4ÚŠ0ªzý~µÙZ¯"²ÜÂ*ç7hÞCþýu÷Ëÿ¹3ýÊä¬#ÿM؃]}ðΙ7û‡ùW•WâGwcƒ´ùb¶ô>­j¬œgÕT‘úXV¹1xæ·|6CkÐ&3½/±ÚOò¶©¥Éû$WIotá˜bH>äÕÈ#VË9%88níSêðÅ ãpÜc†ÏN”Å|r~ùö¨ƒæÇ#NÚB­†î©à(tHx$ãôÏøV·ße„±` à–~‹ü¹þ_Ï6/n2ï”f2¡V5áŽyž‡Ó­uS¥9/tå©kêwÜc*¸ëÐúT¢ãfIl“ÏÒ¸ñ„ÆT·³Ó畊 ÎBü ’Ý:3Èž{×gc ’B²Ý(YAh÷giô÷úŸÈU8J„”Y<Ñ‹ìq†Sò¾ÜœwJ}®›io)™aF™†CÉ#¸Ï§Nw©ÔHÏ—{âk+G6ö¡®îqò¬#+œdeºcéš›+ó=ÉNMr-s¨ZÚ‰æžP«oHç® “a_:—’y7ÈI’F,DZ'Ÿç]ïŠu§µÒ.,&p5+ÌŽ3þ¢,î;›»0ㄞüóžÓö¯HŸº„yÇ^p¢º)»EÉ•YèuÞцcæ8>tøwÏaÙk}³K´ªc½4žkŠrrwgB²9heì8îÀWax3¦Éþåqq]Þ›Åv—C:dŸîVV¨é¾ÇŸZsã¿jѵ’KyRê,y°u88ìqØÿZ¥gÄdã¿5©g— 'üçÚ·¨ÕÞ ž6¸¶™1™c*zèÎ+òú=>6FÉlàrÇðéý1ÛÙµxÞyQ÷Ù“l¡‡.W‘ŸBéØWw,ÓJ'›n$wV F8 ãƒËqì{æ¶ÃÐo}‘Ï9¨«"ÅÅûßI4$'åbä‚#P9oCUìâº[ß±”v•Š¡‹p8ÜFþݪ »y‘©/¼§—€I=qÉÉÉ;~^•á4»d»œ/Ÿ( +“žƒ““Ðu?Ž{àvÔ¨©ÅXçÝêIá.n¤ŒïvÈ,AlñÔý@ü²ry®Ž óI…ÎZÇ›R·¶ Ž$o'ÍTÈ99íȲEnXMŒ4.®„d<á©SšM•ìŸ-ÙÏøÔÍkc æw[]Ø– >VôÎ9#Ú°oüNú>…nm"W¸¸Ü±ÈÀb01Î1†#8çŒúô®¯ÆW–ø~âÍäß9^#A–\tükËŸ}Ç„ôב²a¸–1ÊŒ)ô5tÒš´»ŽÖI£Vv,òÈÒK+nyä±<’O­zƒ¬~Ëb®ë†˜ ñÑùsø×eköíRoáfÃöG'ôÍz¬¢[ ÛŒóÚ«+G”#Ü²Õ ŒÔ¹HØÇèj'œ§úÁÁî+•'Ыœ€}—¶ãvOš¿Î½àgKrðW–¤Ì5PÜ2ÿ:õ)‰þÌ÷+,Dmc¥;œ»4$Gó>ÕÎ7Ãñ«GW‹HÓ儺> í¶!¨Ä¾ýÀ8Qí߈-¤i²ËŸáÈy'8À'ùóô5@F.µUfß |ÎXäƒÀç>ùþX9ô(aÕK¹W«Ë¢*Ê÷’êïö‰Aºld‚$,x\“À÷çôÅ cÌ‹P’'P©")ù@ëµG¿*?*dmq6¯ˆeód™ŠoÁÀéòã‘ÀÀÇ¥^Ô­¾Ñ§šdÕüð ÏÌØèHJë”㢎d›Õš^ ÑßQÔ_Rœ.,áxn0Xþ¼sós‘šë5“7ˆ,ͽ¤Ï ²ýÒ §=Op3Ð~'œcÖ5(´«+/é®CÈ«%Û©pò>¤rÝ?‘]>—&Õ\tÀ¯6¼ß2—sª4Ó}Œ» [CÓÉöµW†`vùXê2NAÁÈÇÒº=Îû=ØŒ¯ž°±#ݳRÜÜ ·fà sšf‚åµ)#Û62åY9óÉ\¾[S‘ÀkšDÂòÉ-ÅÅá“yžCÀ^r:÷$vªª¯á †Ü˜¦×X7éòŠê¼[rés¿¸Ú®k”Ó–FÐ5Ø~ñV €,Oéšë¥7(ݙԊV±gÁvbkÙ.Xd"ìÜòAú×z[šÀð¢Ûh©!\4¹“óéúùÖÔ™:VeÍ6Jѳ5,ZmÍÖCå!õš~“h.g3¸Ìqœ{µtkp[¯¥bê4ùc¸¤ûž/§´sê¶Ù0Ö½>Qÿù8ãeyO‡ I©)ݘ8õäW«Ês¦¿ºUb•¤‘¼õ<ð°M.Gy6–uÚ[¦7wÏãùgë›o>oüÀ»ãGgÝѲ~RÄ}1Œ zæ§¿»Y,’0ùŽßܨ`ÇA€¿‘¨ôU…­¥W‘Áß d6p,Ùã¦å~žõëa•¢rW–£ï4Ùõ[ŒZú[ …v«\)ú.9Îx­7K_ Ü ˜ Í©bo0í‰@ñÐ2 [ÒæM*E¹¸á„^eäŒ|À¨ôãó®?WÔäÕïZL‰"LòzŸV=Iî}€Ssk ¡ðµ•æÕã¼¹”Ë,Å˹êÇý|zW£Ù0©‚2+ÌmåDe$gkg…uÚ.®åÛÈûd ŒõÅŠ‹vhíÃÉ+£¬k˜eÝ™Iéš’Óû>Ô¦»o˜(óxÏlz÷üª²Ãö­¬¥sëQëWgHÒ¤šC+€¡cæ'Ÿ^¿¡®h&Ù¤ímÎ/Æ:‡ÚuHìƒáœtùøçQ訇QÔ-Gú»›7O|–\~•‹yîVI™šIeäžäžtšñQY|¹F2)'þ¹ÿö5èIrG•t9/ÍvvpD–ö‘ƒŠ@ìÅ1ØàÔÄ€J«rû¾•ÇØI>‰|Mëó©­E\ŠƒJMºM˜a‚bRGáSK*D¥¤‘Q@É$à ÁhÛfR|ÏCÄ$ÒeЮ⻉÷Âî ~$W¦Ÿ›O9˜úÖ¼þ9žãáÌS1Üé*.O\Ò½ #û4×:èÆhÑÑBWG”jóÍýµö9ÊÅ*ClO•ü  ãHÎrrsóf›§Êï·b¬—J«2« «ƒò•Î3É#ÐuéÖ†¨Äë¿"«<¬0ñô=?É4]ˆÀ«ó,Q)9$“ùçŽ‡ŽÆ½hh‘É-NºÆëí`Ço#†Ð —ÇRsÁÎOlsÈë\íôÚÝŠ3W©XUÿ/äCá5{Däž ¨Ù·¤É’ ÏÔ}yúÔšÁÇ-¼Ü“ß-ÃÈó"•Û´süGŽ£SUSUra£9¨Õ©®ŸÃö¨òL·¤›#xÎèk gžø@ŠP¼ •#”Á®ÆÂßn¹pÝBÄ‹œwþ„W"i+´bïsvÕD*6"'°P+Sû6ÇS´0j$ÊÄæ9¬ä;H­;Y9×dïtkV:ˆ<.–£QÒ$iíb;åÆ]¨?Ä=¸#Þ²ô×¼A8ÞB Ÿû0¯c³~'½yÃè¿Øþ<ÔÒ ©hÐ !QŽFÜF`ÈÀLWg´rƒæ8àììM$Ä“)ôëU[É·'–¬Ü`â$ã§+`+SÃzlw[îæÉÛ T_qÎk>XÜÓN¦Þ©©E£iR^\gˉ8Uê}÷¯&ÕAxno‹‹pp–áŽÕôÏbk²ñ½á¸¸†Å>â6çÇ÷»W'#ª¸œ(õ=êh+j·*0²»¡ÛÊÞ¿ŠDe1H[kzpk¿·i!ÊÉ?…rž/«è:”#h(Xg© ÿ…té´xuËŒ³œŒãŒ{Õc.Ú&ƒµÏ!Õ\m]mEAæ‘Èû¹ëüê´˜T Ƕ)Ï!»¼Ÿ–g,ãSÛÅeINÔrÃ'Œ)*cœ÷ü«ÕŠÐÁîhiÌV–ÚEQüå$_¿àãpyÏO´5YÀ\\Ä6¼‡¬œ wö<j±ŠÖâ?5Tá°éÐìonnÎGSßUôÙî5Wˆ üùóîzäu§RIGQB7–†·‡¢òÒMJñö¢(œž‚ºâ’îd*÷ ¿iê0 ûãŸi¤)XþÓ#J±É0€ý_Ç5¿ÀÅxµj©7cÔ§ $LÃâ¬A æ¡^E*) {Ö •%uc£°— Çñ²½µ½µý¼qùÌþC9‘‚Ê>™ÝùÕ«96‘V5ø~Ûá›Ø×;Ö?1vŒ’WæñÆ?맪±çMrÌó™|H¶À Ëv_WNEw}šxÒ³û?Ÿ†8È#‚}8®-£¿\:†îE]Õîo.´˜l™ÄV‘ Œ"ñæcÔÒ«+EÆ7M•/µSª_Í4|#1!aëTn¦òm|ÅÏ ¤‚+%´+…È.øê?«jS‰®Î׿*1]0¦£¢¦ÙÿÙImaging-1.1.3/Images/courB08.bdf0100444000076400007640000005302407442710203016043 0ustar fredrikfredrikSTARTFONT 2.1 COMMENT $XConsortium: courB08.bdf,v 1.5 94/04/10 21:46:11 gildea Exp $ COMMENT COMMENT Copyright 1984, 1987 Adobe Systems, Inc. COMMENT Portions Copyright 1988 Digital Equipment Corporation COMMENT COMMENT Adobe is a registered trademark of Adobe Systems, Inc. Permission COMMENT to use these trademarks is hereby granted only in association with the COMMENT images described in this file. COMMENT COMMENT Permission to use, copy, modify, and distribute this software and COMMENT its documentation for any purpose and without fee is hereby granted, COMMENT provided that the above copyright notices appear in all copies and COMMENT that both those copyright notices and this permission notice appear COMMENT in supporting documentation, and that the names of Adobe Systems and COMMENT Digital Equipment Corporation not be used in advertising or COMMENT publicity pertaining to distribution of the software without COMMENT specific, written prior permission. Adobe Systems and Digital COMMENT Equipment Corporation make no representations about the suitability COMMENT of this software for any purpose. It is provided "as is" without COMMENT express or implied warranty. COMMENT COMMENT ADOBE SYSTEMS AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL COMMENT WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED COMMENT WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ADOBE COMMENT SYSTEMS AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY SPECIAL, COMMENT INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER COMMENT RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF COMMENT CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN COMMENT CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. COMMENT COMMENT FONT -Adobe-Courier-Bold-R-Normal--11-80-100-100-M-60-ISO8859-1 SIZE 8 100 100 FONTBOUNDINGBOX 8 11 -1 -2 STARTPROPERTIES 22 COMMENT Begin LogicalFontDescription FONTNAME_REGISTRY "" FAMILY_NAME "Courier" FOUNDRY "Adobe" WEIGHT_NAME "Bold" SLANT "R" SETWIDTH_NAME "Normal" ADD_STYLE_NAME "" PIXEL_SIZE 11 POINT_SIZE 80 RESOLUTION_X 100 RESOLUTION_Y 100 SPACING "M" AVERAGE_WIDTH 60 CHARSET_REGISTRY "ISO8859" CHARSET_ENCODING "1" COMMENT END LogicalFontDescription CHARSET_COLLECTIONS "ASCII ISO8859-1 ADOBE-STANDARD" FACE_NAME "Courier Bold" COPYRIGHT "Copyright (c) 1987 Adobe Systems, Inc., Portions Copyright 1988 Digital Equipment Corp." COMMENT ***** end of inserted font properties FONT_ASCENT 8 FONT_DESCENT 2 CAP_HEIGHT 6 X_HEIGHT 5 ENDPROPERTIES CHARS 194 STARTCHAR space ENCODING 32 SWIDTH 600 0 DWIDTH 6 0 BBX 1 1 0 0 BITMAP 00 ENDCHAR STARTCHAR exclam ENCODING 33 SWIDTH 600 0 DWIDTH 6 0 BBX 2 6 1 0 BITMAP C0 C0 C0 C0 00 C0 ENDCHAR STARTCHAR quotedbl ENCODING 34 SWIDTH 600 0 DWIDTH 6 0 BBX 3 3 1 3 BITMAP A0 A0 A0 ENDCHAR STARTCHAR numbersign ENCODING 35 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 -1 BITMAP 50 50 F8 50 50 F8 50 50 ENDCHAR STARTCHAR dollar ENCODING 36 SWIDTH 600 0 DWIDTH 6 0 BBX 5 9 0 -1 BITMAP 20 78 C8 F0 78 18 D8 F0 20 ENDCHAR STARTCHAR percent ENCODING 37 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP E0 A8 F0 20 78 A8 38 ENDCHAR STARTCHAR ampersand ENCODING 38 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP 38 60 30 7C D8 7C ENDCHAR STARTCHAR quoteright ENCODING 39 SWIDTH 600 0 DWIDTH 6 0 BBX 3 3 1 4 BITMAP 60 40 80 ENDCHAR STARTCHAR parenleft ENCODING 40 SWIDTH 600 0 DWIDTH 6 0 BBX 3 8 1 -1 BITMAP 20 40 C0 C0 C0 C0 40 20 ENDCHAR STARTCHAR parenright ENCODING 41 SWIDTH 600 0 DWIDTH 6 0 BBX 3 8 1 -1 BITMAP 80 40 60 60 60 60 40 80 ENDCHAR STARTCHAR asterisk ENCODING 42 SWIDTH 600 0 DWIDTH 6 0 BBX 4 4 0 3 BITMAP 20 F0 60 90 ENDCHAR STARTCHAR plus ENCODING 43 SWIDTH 600 0 DWIDTH 6 0 BBX 5 5 0 1 BITMAP 20 20 F8 20 20 ENDCHAR STARTCHAR comma ENCODING 44 SWIDTH 600 0 DWIDTH 6 0 BBX 3 3 1 -2 BITMAP 60 40 80 ENDCHAR STARTCHAR minus ENCODING 45 SWIDTH 600 0 DWIDTH 6 0 BBX 5 1 0 3 BITMAP F8 ENDCHAR STARTCHAR period ENCODING 46 SWIDTH 600 0 DWIDTH 6 0 BBX 2 1 1 0 BITMAP C0 ENDCHAR STARTCHAR slash ENCODING 47 SWIDTH 600 0 DWIDTH 6 0 BBX 4 8 1 -1 BITMAP 10 10 20 20 40 40 80 80 ENDCHAR STARTCHAR zero ENCODING 48 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP 70 D8 D8 D8 D8 D8 70 ENDCHAR STARTCHAR one ENCODING 49 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 30 F0 30 30 30 30 FC ENDCHAR STARTCHAR two ENCODING 50 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP 70 D8 18 30 60 D8 F8 ENDCHAR STARTCHAR three ENCODING 51 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP 70 D8 18 70 18 D8 70 ENDCHAR STARTCHAR four ENCODING 52 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 18 38 58 D8 FC 18 18 ENDCHAR STARTCHAR five ENCODING 53 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP F8 C0 F0 D8 18 98 F0 ENDCHAR STARTCHAR six ENCODING 54 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP 70 D8 C0 F0 D8 D8 70 ENDCHAR STARTCHAR seven ENCODING 55 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP F8 D8 18 30 30 60 60 ENDCHAR STARTCHAR eight ENCODING 56 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP 70 D8 D8 70 D8 D8 70 ENDCHAR STARTCHAR nine ENCODING 57 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP 70 D8 D8 78 18 D8 70 ENDCHAR STARTCHAR colon ENCODING 58 SWIDTH 600 0 DWIDTH 6 0 BBX 2 4 1 0 BITMAP C0 00 00 C0 ENDCHAR STARTCHAR semicolon ENCODING 59 SWIDTH 600 0 DWIDTH 6 0 BBX 3 6 0 -2 BITMAP 60 00 00 60 40 80 ENDCHAR STARTCHAR less ENCODING 60 SWIDTH 600 0 DWIDTH 6 0 BBX 4 5 0 1 BITMAP 30 60 C0 60 30 ENDCHAR STARTCHAR equal ENCODING 61 SWIDTH 600 0 DWIDTH 6 0 BBX 4 3 0 2 BITMAP F0 00 F0 ENDCHAR STARTCHAR greater ENCODING 62 SWIDTH 600 0 DWIDTH 6 0 BBX 4 5 1 1 BITMAP C0 60 30 60 C0 ENDCHAR STARTCHAR question ENCODING 63 SWIDTH 600 0 DWIDTH 6 0 BBX 5 6 0 0 BITMAP 70 98 30 60 00 60 ENDCHAR STARTCHAR at ENCODING 64 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 0 -1 BITMAP 70 C8 98 A8 A8 9C C0 70 ENDCHAR STARTCHAR A ENCODING 65 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP 78 38 28 7C 6C EE ENDCHAR STARTCHAR B ENCODING 66 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP F8 6C 78 6C 6C F8 ENDCHAR STARTCHAR C ENCODING 67 SWIDTH 600 0 DWIDTH 6 0 BBX 5 6 0 0 BITMAP 78 D8 C0 C0 D8 70 ENDCHAR STARTCHAR D ENCODING 68 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP F8 6C 6C 6C 6C F8 ENDCHAR STARTCHAR E ENCODING 69 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP FC 60 78 60 6C FC ENDCHAR STARTCHAR F ENCODING 70 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP FC 60 78 60 60 F0 ENDCHAR STARTCHAR G ENCODING 71 SWIDTH 600 0 DWIDTH 6 0 BBX 5 6 0 0 BITMAP 70 D8 C0 F8 D8 78 ENDCHAR STARTCHAR H ENCODING 72 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP EE 6C 7C 6C 6C EE ENDCHAR STARTCHAR I ENCODING 73 SWIDTH 600 0 DWIDTH 6 0 BBX 4 6 0 0 BITMAP F0 60 60 60 60 F0 ENDCHAR STARTCHAR J ENCODING 74 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP 3C 18 18 D8 D8 70 ENDCHAR STARTCHAR K ENCODING 75 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP EC 68 70 78 6C F6 ENDCHAR STARTCHAR L ENCODING 76 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP F0 60 60 60 6C FC ENDCHAR STARTCHAR M ENCODING 77 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP C4 6C 6C 7C 54 D4 ENDCHAR STARTCHAR N ENCODING 78 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP EE 74 74 6C 6C E4 ENDCHAR STARTCHAR O ENCODING 79 SWIDTH 600 0 DWIDTH 6 0 BBX 5 6 0 0 BITMAP 70 D8 D8 D8 D8 70 ENDCHAR STARTCHAR P ENCODING 80 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP F8 6C 6C 78 60 F0 ENDCHAR STARTCHAR Q ENCODING 81 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 -1 BITMAP 70 D8 D8 D8 D8 70 18 ENDCHAR STARTCHAR R ENCODING 82 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP F8 6C 6C 78 6C F6 ENDCHAR STARTCHAR S ENCODING 83 SWIDTH 600 0 DWIDTH 6 0 BBX 5 6 0 0 BITMAP 78 C8 F0 38 98 F0 ENDCHAR STARTCHAR T ENCODING 84 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP FC B4 30 30 30 78 ENDCHAR STARTCHAR U ENCODING 85 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP EE 6C 6C 6C 6C 38 ENDCHAR STARTCHAR V ENCODING 86 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP EE 6C 28 38 38 10 ENDCHAR STARTCHAR W ENCODING 87 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP D6 54 54 7C 38 28 ENDCHAR STARTCHAR X ENCODING 88 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 0 0 BITMAP CC 78 30 30 78 CC ENDCHAR STARTCHAR Y ENCODING 89 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP E6 66 3C 18 18 3C ENDCHAR STARTCHAR Z ENCODING 90 SWIDTH 600 0 DWIDTH 6 0 BBX 5 6 0 0 BITMAP F8 D8 30 60 D8 F8 ENDCHAR STARTCHAR bracketleft ENCODING 91 SWIDTH 600 0 DWIDTH 6 0 BBX 3 8 1 -1 BITMAP E0 C0 C0 C0 C0 C0 C0 E0 ENDCHAR STARTCHAR backslash ENCODING 92 SWIDTH 600 0 DWIDTH 6 0 BBX 4 8 0 -1 BITMAP 80 80 40 40 20 20 10 10 ENDCHAR STARTCHAR bracketright ENCODING 93 SWIDTH 600 0 DWIDTH 6 0 BBX 3 8 1 -1 BITMAP E0 60 60 60 60 60 60 E0 ENDCHAR STARTCHAR asciicircum ENCODING 94 SWIDTH 600 0 DWIDTH 6 0 BBX 5 3 0 4 BITMAP 20 70 D8 ENDCHAR STARTCHAR underscore ENCODING 95 SWIDTH 600 0 DWIDTH 6 0 BBX 6 1 0 -2 BITMAP FC ENDCHAR STARTCHAR quoteleft ENCODING 96 SWIDTH 600 0 DWIDTH 6 0 BBX 3 3 1 4 BITMAP C0 40 20 ENDCHAR STARTCHAR a ENCODING 97 SWIDTH 600 0 DWIDTH 6 0 BBX 6 5 0 0 BITMAP 70 D8 78 D8 FC ENDCHAR STARTCHAR b ENCODING 98 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 -1 0 BITMAP E0 60 78 6C 6C 6C F8 ENDCHAR STARTCHAR c ENCODING 99 SWIDTH 600 0 DWIDTH 6 0 BBX 5 5 0 0 BITMAP 70 D8 C0 D8 70 ENDCHAR STARTCHAR d ENCODING 100 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 38 18 78 D8 D8 D8 7C ENDCHAR STARTCHAR e ENCODING 101 SWIDTH 600 0 DWIDTH 6 0 BBX 5 5 0 0 BITMAP 70 D8 F8 C0 78 ENDCHAR STARTCHAR f ENCODING 102 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP 38 60 F8 60 60 60 F8 ENDCHAR STARTCHAR g ENCODING 103 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 -2 BITMAP 6C D8 D8 D8 78 18 F0 ENDCHAR STARTCHAR h ENCODING 104 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 -1 0 BITMAP E0 60 78 6C 6C 6C 6C ENDCHAR STARTCHAR i ENCODING 105 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 30 00 F0 30 30 30 FC ENDCHAR STARTCHAR j ENCODING 106 SWIDTH 600 0 DWIDTH 6 0 BBX 4 9 0 -2 BITMAP 30 00 F0 30 30 30 30 30 E0 ENDCHAR STARTCHAR k ENCODING 107 SWIDTH 600 0 DWIDTH 6 0 BBX 7 7 -1 0 BITMAP E0 60 6C 78 70 78 6E ENDCHAR STARTCHAR l ENCODING 108 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP F0 30 30 30 30 30 FC ENDCHAR STARTCHAR m ENCODING 109 SWIDTH 600 0 DWIDTH 6 0 BBX 6 5 -1 0 BITMAP F8 7C 54 54 54 ENDCHAR STARTCHAR n ENCODING 110 SWIDTH 600 0 DWIDTH 6 0 BBX 6 5 -1 0 BITMAP D8 6C 6C 6C 6C ENDCHAR STARTCHAR o ENCODING 111 SWIDTH 600 0 DWIDTH 6 0 BBX 5 5 0 0 BITMAP 70 D8 D8 D8 70 ENDCHAR STARTCHAR p ENCODING 112 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 -1 -2 BITMAP F8 6C 6C 6C 78 60 F0 ENDCHAR STARTCHAR q ENCODING 113 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 -2 BITMAP 6C D8 D8 D8 78 18 3C ENDCHAR STARTCHAR r ENCODING 114 SWIDTH 600 0 DWIDTH 6 0 BBX 6 5 0 0 BITMAP DC 74 60 60 F0 ENDCHAR STARTCHAR s ENCODING 115 SWIDTH 600 0 DWIDTH 6 0 BBX 6 5 0 0 BITMAP 78 E0 78 1C F8 ENDCHAR STARTCHAR t ENCODING 116 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 60 60 F8 60 60 6C 38 ENDCHAR STARTCHAR u ENCODING 117 SWIDTH 600 0 DWIDTH 6 0 BBX 7 5 -1 0 BITMAP EC 6C 6C 6C 3E ENDCHAR STARTCHAR v ENCODING 118 SWIDTH 600 0 DWIDTH 6 0 BBX 6 5 -1 0 BITMAP EC 6C 38 38 10 ENDCHAR STARTCHAR w ENCODING 119 SWIDTH 600 0 DWIDTH 6 0 BBX 7 5 -1 0 BITMAP D6 54 7C 3C 28 ENDCHAR STARTCHAR x ENCODING 120 SWIDTH 600 0 DWIDTH 6 0 BBX 6 5 0 0 BITMAP EC 78 30 78 DC ENDCHAR STARTCHAR y ENCODING 121 SWIDTH 600 0 DWIDTH 6 0 BBX 7 7 -1 -2 BITMAP EE 6C 6C 28 38 30 E0 ENDCHAR STARTCHAR z ENCODING 122 SWIDTH 600 0 DWIDTH 6 0 BBX 5 5 0 0 BITMAP F8 B0 60 D8 F8 ENDCHAR STARTCHAR braceleft ENCODING 123 SWIDTH 600 0 DWIDTH 6 0 BBX 4 8 1 -1 BITMAP 30 60 60 C0 60 60 60 30 ENDCHAR STARTCHAR bar ENCODING 124 SWIDTH 600 0 DWIDTH 6 0 BBX 1 7 2 -1 BITMAP 80 80 80 80 80 80 80 ENDCHAR STARTCHAR braceright ENCODING 125 SWIDTH 600 0 DWIDTH 6 0 BBX 4 8 0 -1 BITMAP C0 60 60 30 60 60 60 C0 ENDCHAR STARTCHAR asciitilde ENCODING 126 SWIDTH 600 0 DWIDTH 6 0 BBX 5 2 0 3 BITMAP 68 B0 ENDCHAR STARTCHAR exclamdown ENCODING 161 SWIDTH 600 0 DWIDTH 6 0 BBX 2 7 1 -2 BITMAP C0 00 C0 C0 C0 C0 C0 ENDCHAR STARTCHAR cent ENCODING 162 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 -1 BITMAP 20 20 78 C8 C0 78 20 20 ENDCHAR STARTCHAR sterling ENCODING 163 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 38 68 20 F8 20 64 F8 ENDCHAR STARTCHAR currency ENCODING 164 SWIDTH 600 0 DWIDTH 6 0 BBX 5 5 0 1 BITMAP 88 70 50 70 88 ENDCHAR STARTCHAR yen ENCODING 165 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP CC 48 FC 30 FC 30 78 ENDCHAR STARTCHAR brokenbar ENCODING 166 SWIDTH 600 0 DWIDTH 6 0 BBX 1 9 2 -2 BITMAP 80 80 80 80 00 80 80 80 80 ENDCHAR STARTCHAR section ENCODING 167 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 -1 BITMAP 78 48 60 90 48 30 90 F0 ENDCHAR STARTCHAR dieresis ENCODING 168 SWIDTH 600 0 DWIDTH 6 0 BBX 3 1 1 5 BITMAP A0 ENDCHAR STARTCHAR copyright ENCODING 169 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 30 48 B4 A4 B4 48 30 ENDCHAR STARTCHAR ordfeminine ENCODING 170 SWIDTH 600 0 DWIDTH 6 0 BBX 4 5 1 2 BITMAP E0 10 D0 00 F0 ENDCHAR STARTCHAR guillemotleft ENCODING 171 SWIDTH 600 0 DWIDTH 6 0 BBX 7 5 -1 0 BITMAP 36 6C D8 6C 36 ENDCHAR STARTCHAR logicalnot ENCODING 172 SWIDTH 600 0 DWIDTH 6 0 BBX 5 3 0 2 BITMAP F8 08 08 ENDCHAR STARTCHAR hyphen ENCODING 173 SWIDTH 600 0 DWIDTH 6 0 BBX 5 1 0 3 BITMAP F8 ENDCHAR STARTCHAR registered ENCODING 174 SWIDTH 600 0 DWIDTH 6 0 BBX 7 7 0 0 BITMAP 38 44 BA B2 AA 44 38 ENDCHAR STARTCHAR macron ENCODING 175 SWIDTH 600 0 DWIDTH 6 0 BBX 4 1 0 5 BITMAP F0 ENDCHAR STARTCHAR degree ENCODING 176 SWIDTH 600 0 DWIDTH 6 0 BBX 4 3 0 4 BITMAP 60 90 60 ENDCHAR STARTCHAR plusminus ENCODING 177 SWIDTH 600 0 DWIDTH 6 0 BBX 5 6 0 0 BITMAP 20 20 F8 20 00 F8 ENDCHAR STARTCHAR twosuperior ENCODING 178 SWIDTH 600 0 DWIDTH 6 0 BBX 3 4 1 3 BITMAP 60 A0 40 E0 ENDCHAR STARTCHAR threesuperior ENCODING 179 SWIDTH 600 0 DWIDTH 6 0 BBX 3 4 1 3 BITMAP E0 40 20 C0 ENDCHAR STARTCHAR acute ENCODING 180 SWIDTH 600 0 DWIDTH 6 0 BBX 2 2 2 5 BITMAP 40 80 ENDCHAR STARTCHAR mu ENCODING 181 SWIDTH 600 0 DWIDTH 6 0 BBX 7 7 -1 -2 BITMAP EC 6C 6C 6C 7E 40 40 ENDCHAR STARTCHAR paragraph ENCODING 182 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 0 -1 BITMAP 7C A8 A8 68 28 28 28 6C ENDCHAR STARTCHAR periodcentered ENCODING 183 SWIDTH 600 0 DWIDTH 6 0 BBX 2 1 1 3 BITMAP C0 ENDCHAR STARTCHAR cedilla ENCODING 184 SWIDTH 600 0 DWIDTH 6 0 BBX 3 3 1 -2 BITMAP 40 20 C0 ENDCHAR STARTCHAR onesuperior ENCODING 185 SWIDTH 600 0 DWIDTH 6 0 BBX 3 4 1 3 BITMAP C0 40 40 E0 ENDCHAR STARTCHAR ordmasculine ENCODING 186 SWIDTH 600 0 DWIDTH 6 0 BBX 4 5 1 2 BITMAP 60 90 60 00 F0 ENDCHAR STARTCHAR guillemotright ENCODING 187 SWIDTH 600 0 DWIDTH 6 0 BBX 7 5 -1 0 BITMAP D8 6C 36 6C D8 ENDCHAR STARTCHAR onequarter ENCODING 188 SWIDTH 600 0 DWIDTH 6 0 BBX 7 7 -1 0 BITMAP C0 44 48 F4 2C 5E 04 ENDCHAR STARTCHAR onehalf ENCODING 189 SWIDTH 600 0 DWIDTH 6 0 BBX 7 7 -1 0 BITMAP C0 44 48 F6 2A 44 0E ENDCHAR STARTCHAR threequarters ENCODING 190 SWIDTH 600 0 DWIDTH 6 0 BBX 7 7 -1 0 BITMAP E0 44 28 D4 2C 5E 04 ENDCHAR STARTCHAR questiondown ENCODING 191 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 -2 BITMAP 30 00 30 30 60 C8 70 ENDCHAR STARTCHAR Agrave ENCODING 192 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 20 10 00 78 38 28 7C 6C EE ENDCHAR STARTCHAR Aacute ENCODING 193 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 10 20 00 78 38 28 7C 6C EE ENDCHAR STARTCHAR Acircumflex ENCODING 194 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 10 28 00 78 38 28 7C 6C EE ENDCHAR STARTCHAR Atilde ENCODING 195 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 34 48 00 78 38 28 7C 6C EE ENDCHAR STARTCHAR Adieresis ENCODING 196 SWIDTH 600 0 DWIDTH 6 0 BBX 7 8 -1 0 BITMAP 28 00 78 38 28 7C 6C EE ENDCHAR STARTCHAR Aring ENCODING 197 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 30 48 30 78 38 28 7C 6C EE ENDCHAR STARTCHAR AE ENCODING 198 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP 7E 3A 6C 78 DA DE ENDCHAR STARTCHAR Ccedilla ENCODING 199 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 -2 BITMAP 78 D8 C0 C0 D8 70 10 60 ENDCHAR STARTCHAR Egrave ENCODING 200 SWIDTH 600 0 DWIDTH 6 0 BBX 6 9 -1 0 BITMAP 20 10 00 FC 64 78 60 6C FC ENDCHAR STARTCHAR Eacute ENCODING 201 SWIDTH 600 0 DWIDTH 6 0 BBX 6 9 -1 0 BITMAP 10 20 00 FC 64 78 60 6C FC ENDCHAR STARTCHAR Ecircumflex ENCODING 202 SWIDTH 600 0 DWIDTH 6 0 BBX 6 9 -1 0 BITMAP 20 50 00 FC 64 78 60 6C FC ENDCHAR STARTCHAR Edieresis ENCODING 203 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 -1 0 BITMAP 50 00 FC 64 78 60 6C FC ENDCHAR STARTCHAR Igrave ENCODING 204 SWIDTH 600 0 DWIDTH 6 0 BBX 4 9 0 0 BITMAP 40 20 00 F0 60 60 60 60 F0 ENDCHAR STARTCHAR Iacute ENCODING 205 SWIDTH 600 0 DWIDTH 6 0 BBX 4 9 0 0 BITMAP 20 40 00 F0 60 60 60 60 F0 ENDCHAR STARTCHAR Icircumflex ENCODING 206 SWIDTH 600 0 DWIDTH 6 0 BBX 4 9 0 0 BITMAP 40 A0 00 F0 60 60 60 60 F0 ENDCHAR STARTCHAR Idieresis ENCODING 207 SWIDTH 600 0 DWIDTH 6 0 BBX 4 8 0 0 BITMAP A0 00 F0 60 60 60 60 F0 ENDCHAR STARTCHAR Eth ENCODING 208 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP F8 6C F4 64 6C F8 ENDCHAR STARTCHAR Ntilde ENCODING 209 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 34 48 00 EE 64 74 7C 6C EC ENDCHAR STARTCHAR Ograve ENCODING 210 SWIDTH 600 0 DWIDTH 6 0 BBX 5 9 0 0 BITMAP 40 20 00 70 D8 D8 D8 D8 70 ENDCHAR STARTCHAR Oacute ENCODING 211 SWIDTH 600 0 DWIDTH 6 0 BBX 5 9 0 0 BITMAP 20 40 00 70 D8 D8 D8 D8 70 ENDCHAR STARTCHAR Ocircumflex ENCODING 212 SWIDTH 600 0 DWIDTH 6 0 BBX 5 9 0 0 BITMAP 20 50 00 70 D8 D8 D8 D8 70 ENDCHAR STARTCHAR Otilde ENCODING 213 SWIDTH 600 0 DWIDTH 6 0 BBX 5 9 0 0 BITMAP 68 90 00 70 D8 D8 D8 D8 70 ENDCHAR STARTCHAR Odieresis ENCODING 214 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 0 BITMAP 50 00 70 D8 D8 D8 D8 70 ENDCHAR STARTCHAR multiply ENCODING 215 SWIDTH 600 0 DWIDTH 6 0 BBX 5 5 0 1 BITMAP 88 50 20 50 88 ENDCHAR STARTCHAR Oslash ENCODING 216 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP 3A 6C 7C 6C 6C B8 ENDCHAR STARTCHAR Ugrave ENCODING 217 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 20 10 00 EE 6C 6C 6C 6C 38 ENDCHAR STARTCHAR Uacute ENCODING 218 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 08 10 00 EE 6C 6C 6C 6C 38 ENDCHAR STARTCHAR Ucircumflex ENCODING 219 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 10 28 00 EE 6C 6C 6C 6C 38 ENDCHAR STARTCHAR Udieresis ENCODING 220 SWIDTH 600 0 DWIDTH 6 0 BBX 7 8 -1 0 BITMAP 28 00 EE 6C 6C 6C 6C 38 ENDCHAR STARTCHAR Yacute ENCODING 221 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 0 BITMAP 04 08 00 E6 66 3C 18 18 3C ENDCHAR STARTCHAR Thorn ENCODING 222 SWIDTH 600 0 DWIDTH 6 0 BBX 6 6 -1 0 BITMAP E0 78 6C 6C 78 E0 ENDCHAR STARTCHAR germandbls ENCODING 223 SWIDTH 600 0 DWIDTH 6 0 BBX 7 6 -1 0 BITMAP 38 68 7C 66 66 EC ENDCHAR STARTCHAR agrave ENCODING 224 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 0 0 BITMAP 20 10 00 70 98 78 D8 FC ENDCHAR STARTCHAR aacute ENCODING 225 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 0 0 BITMAP 10 20 00 70 98 78 D8 FC ENDCHAR STARTCHAR acircumflex ENCODING 226 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 0 0 BITMAP 20 50 00 70 98 78 D8 FC ENDCHAR STARTCHAR atilde ENCODING 227 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 0 0 BITMAP 68 90 00 70 98 78 D8 FC ENDCHAR STARTCHAR adieresis ENCODING 228 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 50 00 70 98 78 D8 FC ENDCHAR STARTCHAR aring ENCODING 229 SWIDTH 600 0 DWIDTH 6 0 BBX 6 9 0 0 BITMAP 30 48 30 00 70 98 78 D8 FC ENDCHAR STARTCHAR ae ENCODING 230 SWIDTH 600 0 DWIDTH 6 0 BBX 6 5 -1 0 BITMAP 6C B4 7C B0 DC ENDCHAR STARTCHAR ccedilla ENCODING 231 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 -2 BITMAP 70 D8 C0 D8 70 10 60 ENDCHAR STARTCHAR egrave ENCODING 232 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 0 BITMAP 40 20 00 70 D8 F8 C0 78 ENDCHAR STARTCHAR eacute ENCODING 233 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 0 BITMAP 20 40 00 70 D8 F8 C0 78 ENDCHAR STARTCHAR ecircumflex ENCODING 234 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 0 BITMAP 20 50 00 70 D8 F8 C0 78 ENDCHAR STARTCHAR edieresis ENCODING 235 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP 50 00 70 D8 F8 C0 78 ENDCHAR STARTCHAR igrave ENCODING 236 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 0 0 BITMAP 20 10 00 70 30 30 30 FC ENDCHAR STARTCHAR iacute ENCODING 237 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 0 0 BITMAP 10 20 00 70 30 30 30 FC ENDCHAR STARTCHAR icircumflex ENCODING 238 SWIDTH 600 0 DWIDTH 6 0 BBX 6 8 0 0 BITMAP 20 50 00 70 30 30 30 FC ENDCHAR STARTCHAR idieresis ENCODING 239 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 50 00 70 30 30 30 FC ENDCHAR STARTCHAR eth ENCODING 240 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 0 BITMAP D0 60 B0 78 D8 D8 D8 70 ENDCHAR STARTCHAR ntilde ENCODING 241 SWIDTH 600 0 DWIDTH 6 0 BBX 7 8 -1 0 BITMAP 34 48 00 D8 6C 6C 6C 6E ENDCHAR STARTCHAR ograve ENCODING 242 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 0 BITMAP 40 20 00 70 D8 D8 D8 70 ENDCHAR STARTCHAR oacute ENCODING 243 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 0 BITMAP 20 40 00 70 D8 D8 D8 70 ENDCHAR STARTCHAR ocircumflex ENCODING 244 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 0 BITMAP 20 50 00 70 D8 D8 D8 70 ENDCHAR STARTCHAR otilde ENCODING 245 SWIDTH 600 0 DWIDTH 6 0 BBX 5 8 0 0 BITMAP 68 90 00 70 D8 D8 D8 70 ENDCHAR STARTCHAR odieresis ENCODING 246 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 0 BITMAP 50 00 70 D8 D8 D8 70 ENDCHAR STARTCHAR divide ENCODING 247 SWIDTH 600 0 DWIDTH 6 0 BBX 5 5 0 1 BITMAP 20 00 F8 00 20 ENDCHAR STARTCHAR oslash ENCODING 248 SWIDTH 600 0 DWIDTH 6 0 BBX 5 7 0 -1 BITMAP 08 70 D8 F8 D8 70 80 ENDCHAR STARTCHAR ugrave ENCODING 249 SWIDTH 600 0 DWIDTH 6 0 BBX 7 8 -1 0 BITMAP 20 10 00 EC 6C 6C 6C 3E ENDCHAR STARTCHAR uacute ENCODING 250 SWIDTH 600 0 DWIDTH 6 0 BBX 7 8 -1 0 BITMAP 10 20 00 EC 6C 6C 6C 3E ENDCHAR STARTCHAR ucircumflex ENCODING 251 SWIDTH 600 0 DWIDTH 6 0 BBX 7 8 -1 0 BITMAP 10 28 00 EC 6C 6C 6C 3E ENDCHAR STARTCHAR udieresis ENCODING 252 SWIDTH 600 0 DWIDTH 6 0 BBX 7 7 -1 0 BITMAP 28 00 EC 6C 6C 6C 3E ENDCHAR STARTCHAR yacute ENCODING 253 SWIDTH 600 0 DWIDTH 6 0 BBX 7 10 -1 -2 BITMAP 08 10 00 EE 6C 6C 28 38 30 F0 ENDCHAR STARTCHAR thorn ENCODING 254 SWIDTH 600 0 DWIDTH 6 0 BBX 6 9 -1 -2 BITMAP E0 60 78 6C 6C 6C 78 60 F0 ENDCHAR STARTCHAR ydieresis ENCODING 255 SWIDTH 600 0 DWIDTH 6 0 BBX 7 9 -1 -2 BITMAP 28 00 EE 6C 6C 28 38 30 F0 ENDCHAR STARTCHAR trademark ENCODING -1 SWIDTH 600 0 DWIDTH 6 0 BBX 7 4 -1 3 BITMAP F6 5E 5A 5A ENDCHAR STARTCHAR perthousand ENCODING -1 SWIDTH 600 0 DWIDTH 6 0 BBX 6 7 0 0 BITMAP 60 A8 D0 60 6C B4 D8 ENDCHAR STARTCHAR oe ENCODING -1 SWIDTH 600 0 DWIDTH 6 0 BBX 6 5 0 0 BITMAP 6C B4 BC B0 6C ENDCHAR STARTCHAR fl ENCODING -1 SWIDTH 600 0 DWIDTH 6 0 BBX 7 7 -1 0 BITMAP 3C 6C FC 6C 6C 6C FE ENDCHAR ENDFONT Imaging-1.1.3/Images/courB08.pbm0100444000076400007640000000237107442710203016065 0ustar fredrikfredrik‰PNG  IHDR+2ÖhÀIDATxœešÿuDáÌÂ#þ.1Îîû³üs>ßþîþo1îïñÿ÷ï¯>ñÉþs‡ã·Á‡Ã϶wÍîó»×ߟèç}3ÿç=ˆûÙýfÙƒ ÑCÞ@„(„•ñ¤TN ÿÿešÿ Ê=mÿ ­ -ãYS +¸Ý\3Èδ×ê‡ÇYê7¿}ú¨üßfqÓµÿyýø%d®MÐðà}ì–‘¿>ËÎ!EÁY£C“ ø1OÁx˜á†ØÅ«éžÅ®Mx0ÿÿešÿªFŠÚ =è ½@í–~è Ñ@€¼ÿÝKøÿ _°I€7žþ€õ4Àó(pûÕ«ÞZo¿u4}Ê#øà¯ã¿†:ßö~·ß¾ß®o„øð°ÿÿešÿêe2P$k€¦©ª1Š}ýôo€@øÀ PþÆÊÿ`Ѱ‡€âèD@ÀŽç¯@+bš0í¥üÿÿKhÿýJ7Z½`€f+ƒ4ƒã(‡qƒYÎÍíe$nçþ;s9÷}uƒYÎ ÿÿb``Áb(N ƒ.ÀˆÆ/߯ÿÿÿ?`O·<ÇÀ cQÿÿ"ŲÿÿbÔx\ÁØbÍ~îðÖMÏ"Û½?{múÌô#ǯ;¨e ÿÿb`|Ö$°¤A5ïD+ƒ“c'G«CA+­ÿÿbxǸýŸÄ? †¢ Œ÷o00X3Tï šÿÿbª?óÅãÖ—wž›—Ùo-óܪQ=ïnBù§T³ÿÿbúÏ`À*hczûZÿŸLE³¯ma¹óãÃ~ªYÁÀÿÿbbX·"æý~aW§'P±?3þ š%ÿÿbbØZäcx˜¥€¹¨7†á ÿ†/q<T³ÿÿb°0`ÿÿÿAƒÜ÷æÿÿÏÞynÁÀøùù™„T³ÿÿb`¨`````¨C–øL=Kÿÿ"`7uÿÿÑò$¼áUIEND®B`‚Imaging-1.1.3/Images/courB08.pil0100444000076400007640000001202707442710203016072 0ustar fredrikfredrikPILfont ;;;;;;10; DATA ÿÿÿúÿúÿýÿù ÿø  ÿùÿÿÿúÿùÿüÿù!ÿù!$ÿùÿý$(ÿúÿÿ(-ÿÿ-0ÿüÿý05ÿÿ57ÿù7;ÿù;@ÿù@FÿùFKÿùKPÿùPVÿùV[ÿù[`ÿù`eÿùejÿùjoÿüoqÿüqtÿúÿÿtxÿûÿþx|ÿúÿÿ|€ÿú€…ÿù…‹ÿÿÿú‹’ÿÿÿú’˜ÿú˜ÿÿÿú£ÿÿÿú£©ÿÿÿú©¯ÿú¯´ÿÿÿú´»ÿú»¿ÿÿÿú¿ÅÿÿÿúÅÌÿÿÿúÌÒÿÿÿúÒØÿÿÿúØßÿúßäÿÿÿúäêÿúêïÿÿÿúïöÿúöûÿÿÿúûÿÿÿúÿÿÿúÿÿÿúÿúÿÿÿú#ÿú#(ÿù(+ÿù+/ÿù/2ÿùÿü277=ÿùÿü=@ÿû@FÿÿÿùFLÿûLQÿùQWÿûW\ÿù\aÿûagÿÿÿùgmÿùmsÿùsw ÿÿÿùw~ÿù~„ÿÿÿû„ŠÿÿÿûŠÿû•ÿÿÿû•›ÿû›¡ÿû¡§ÿû§­ÿù­³ÿÿÿû³ºÿÿÿûºÀÿÿÿûÀÇÿûÇÍÿÿÿûÍÔÿûÔÙÿùÙÝÿúÝÞÿùÞâÿûÿýâçÿûçéÿùéîÿùîôÿúÿÿôùÿùùÿÿùÿ ÿùÿúÿûÿùÿùÿþÿÿÿûÿûÿþÿüÿý#ÿù#*ÿúÿû*.ÿùÿü.2ÿú27ÿùÿý7:ÿùÿý:=ÿùÿû=?ÿÿÿû?FÿùFLÿüÿýLNÿÿNQÿùÿýQTÿùÿþTXÿÿÿûX_ÿÿÿù_fÿÿÿùfmÿÿÿùmtÿûtyÿÿÿ÷y€ ÿÿÿ÷€‡ ÿÿÿ÷‡Ž ÿÿÿ÷Ž• ÿÿÿø•œÿÿÿ÷œ£ ÿÿÿú£ªÿúª¯ÿÿÿ÷¯µ ÿÿÿ÷µ» ÿÿÿ÷»Á ÿÿÿøÁÇÿ÷ÇË ÿ÷ËÏ ÿ÷ÏÓ ÿøÓ×ÿÿÿú×Ýÿÿÿ÷Ýä ÿ÷äé ÿ÷éî ÿ÷îó ÿ÷óø ÿøøýÿúÿÿýÿÿÿú ÿÿÿ÷  ÿÿÿ÷ ÿÿÿ÷ ÿÿÿø ÿÿÿ÷ ÿÿÿú ÿÿÿú ÿø !ÿø! 'ÿø' -ÿø- 3ÿù3 9ÿ÷9 ?ÿÿÿû? EÿûE JÿøJ OÿøO TÿøT YÿùY ^ÿø^ dÿød jÿøj pÿùp vÿøv {ÿÿÿø{ ‚ÿø‚ ‡ÿø‡ ŒÿøŒ ‘ÿø‘ –ÿù– ›ÿúÿÿ›  ÿú  ¥ÿÿÿø¥ ¬ÿÿÿø¬ ³ÿÿÿø³ ºÿÿÿùº ÁÿÿÿøÁ ÈÿÿÿùÈ ÎÿÿÿùÎ ÕImaging-1.1.3/Sane/README0100444000076400007640000000055707442710203014510 0ustar fredrikfredrik The SANE module provides an interface to the SANE scanner and frame grabber interface for Linux. This module was contributed by Andrew Kuchling. The most recent release can be found at: ftp://starship.skyport.net/pub/crew/amk/sane/ To build this module, add the following line to Setup.in: _sane Sane/_sanemodule.c -IlibImaging -L/usr/local/lib/sane/ -lsane-dll Imaging-1.1.3/Sane/sanedoc.txt0100444000076400007640000001466507442710203016012 0ustar fredrikfredrikThe _sane_ module is an Python interface to the SANE (Scanning is Now Easy) library, which provides access to various raster scanning devices such as flatbed scanners and digital cameras. For more information about SANE, consult the SANE Web site at http://www.mostang.com/sane/ . Note that this documentation doesn't duplicate all the information in the SANE documentation, which you must also consult to get a complete understanding. Send comments, questions, and bug reports concerning this module to amk1@erols.com, or possibly to image-sig@python.org . The module exports two object types, a bunch of constants, and two functions. get_devices() Return a list of 4-tuples containing the available scanning devices. Each tuple contains 4 strings: the device name, suitable for passing to _open()_; the device's vendor; the model; and the type of device, such as 'virtual device' or 'video camera'. >>> import sane ; sane.get_devices() [('qcam:0x378', 'Connectix', 'B&W QuickCam', 'video camera'), ('pnm:0', 'Noname', 'PNM file reader', 'virtual device')] open(devicename) Open a device, given a string containing its name. SANE devices have names like _"qcam:0x378"_ or _"pnm:0"_. If the attempt to open the device fails, a _sane.error_ exception will be raised. If there are no problems, a SaneDev object will be returned. SaneDev objects =============== The basic process of scanning an image consists of getting a SaneDev object for the device, setting various parameters, starting the scan, and then reading the image data. Images are composed of one or more frames; greyscale and one-pass colour scanners return a single frame containing all the image data, but 3-pass scanners will usually return 3 frames, one for each of the red, green, blue channels. Methods: fileno() Returns a file descriptor for the scanning device. This method's existence means that SaneDev objects can be used by the select module. get_parameters() Return a tuple containing information about the current settings of the device and the current frame: (format, last_frame, pixels_per_line, lines, depth, bytes_per_line). format -- 'L' for greyscale image, 'RGB' for RGB image, or one of 'R', 'G', 'B' if the image is a single channel of an RGB image (from PIL's point of view, this is equivalent to 'L'). last_frame -- A Boolean value, which is true if this is the last frame of the image, and false otherwise. pixels_per_line -- Width of the frame. lines -- Height of the frame. depth -- Depth of the image, measured in bits. SANE will only allow using 8, 16, or 24-bit depths. bytes_per_line -- Bytes required to store a single line of data, as computed from pixels_per_line and depth. start() Start a scan. This function must be called before the _snap()_ method can be used. cancel() Cancel a scan already in progress. snap() Snap a single frame of data, returning a PIL Image object containing the data. If the scanner is one that requires several frames to return all the image data, it's the caller's responsibility to call the _start()_ and _snap()_ methods again for the next frame, and to combine the frames into a single image afterwards. close() Closes the object. Attributes: SaneDev objects have a few fixed attributes which are always available, and a larger collection of attributes which vary depending on the device. For example, the _pnm:0_ device takes a PNM file and simulates a scanner using the image data; a SaneDev object representing the _pnm:0_ device therefore has a _filename_ attribute which can be changed to specify the filename, _contrast_ and _brightness_ attributes to modify the returned image, and so forth. For an option like _filename_ and a SaneDev object _obj_, _obj.opt_filename_ returns the SaneOption object for the option, and _obj.filename_ returns the option's current value. The current value may be an integer, floating-point value, or string, depending on the nature of the option. optlist A list containing the _py_name_ values for all the options supported by this device. >>> import sane ; s=sane.open('pnm:0') ; s.optlist ['filename', 'brightness', 'contrast', 'grayify', 'three_pass', 'hand_scanner', 'default_enhancements'] SaneOption objects ================== SANE's option handling is its most elaborate subsystem, intended to allow automatically generating dialog boxes and prompts for user configuration of the scanning device. The SaneOption object can be used to get a human-readable name and description for an option, the units to use, and what the legal values are. No information about the current value of the option is available; for that, read the corresponding attribute of a SaneDev object. This documentation does not explain all the details of SANE's option handling; consult the SANE documentation for all the details. Methods: is_active() Returns true if the option is active. is_settable() Returns true if the option can be set under software control. Attributes: cap An integer containing various flags about the object's capabilities; whether it's active, whether it's settable, etc. Also available as the _capability_ attribute. constraint The constraint placed on the value of this option. If it's _None_, there are essentially no constraint of the value. It may also be a list of integers or strings, in which case the value *must* be one of the possibilities in the list. Numeric values may have a 3-tuple as the constraint; this 3-tuple contains _(minimum, maximum, increment)_, and the value must be in the defined range. desc A lengthy description of what the option does; it may be shown to the user for clarification. index An integer giving the option's index in the option list. name A short name for the option. py_name The option's name, as a legal Python identifier. The name attribute may contain the '-' character, so it will be converted to '_' for the py_name attribute. size For a string-valued option, this is the maximum length allowed. title A single-line string that can be used as a title string. type A constant giving the type of this option: will be one of the following constants found in the SANE module: TYPE_BOOL TYPE_INT TYPE_FIXED TYPE_STRING TYPE_BUTTON TYPE_GROUP unit For numeric-valued options, this is a constant representing the unit used for this option. It will be one of the following constants found in the SANE module: UNIT_NONE UNIT_PIXEL UNIT_BIT UNIT_MM UNIT_DPI UNIT_PERCENT Imaging-1.1.3/Sane/_sanemodule.c0100444000076400007640000003621107442710203016263 0ustar fredrikfredrik/*********************************************************** Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the names of Stichting Mathematisch Centrum or CWI or Corporation for National Research Initiatives or CNRI not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. While CWI is the initial source for this software, a modified version is made available by the Corporation for National Research Initiatives (CNRI) at the Internet address ftp://ftp.python.org. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ /* SaneDev objects */ #include "Python.h" #include "Imaging.h" #include static PyObject *ErrorObject; typedef struct { PyObject_HEAD SANE_Handle h; } SaneDevObject; /* Raise a SANE exception */ PyObject * PySane_Error(st) SANE_Status st; { char *string; if (st==SANE_STATUS_GOOD) {Py_INCREF(Py_None); return (Py_None);} string=sane_strstatus(st); PyErr_SetString(ErrorObject, string); return NULL; } staticforward PyTypeObject SaneDev_Type; #define SaneDevObject_Check(v) ((v)->ob_type == &SaneDev_Type) static SaneDevObject * newSaneDevObject(arg) PyObject *arg; { SaneDevObject *self; self = PyObject_NEW(SaneDevObject, &SaneDev_Type); if (self == NULL) return NULL; self->h=NULL; return self; } /* SaneDev methods */ static void SaneDev_dealloc(self) SaneDevObject *self; { if (self->h) sane_close(self->h); self->h=NULL; PyMem_DEL(self); } static PyObject * SaneDev_get_parameters(self, args) SaneDevObject *self; PyObject *args; { SANE_Status st; SANE_Parameters p; char *format="unknown format"; if (!PyArg_ParseTuple(args, "")) return NULL; st=sane_get_parameters(self->h, &p); if (st) return PySane_Error(st); switch (p.format) { case(SANE_FRAME_GRAY): format="L"; break; case(SANE_FRAME_RGB): format="RGB"; break; case(SANE_FRAME_RED): format="R"; break; case(SANE_FRAME_GREEN): format="G"; break; case(SANE_FRAME_BLUE): format="B"; break; } return Py_BuildValue("si(ii)ii", format, p.last_frame, p.pixels_per_line, p.lines, p.depth, p.bytes_per_line); } static PyObject * SaneDev_fileno(self, args) SaneDevObject *self; PyObject *args; { SANE_Status st; SANE_Int fd; if (!PyArg_ParseTuple(args, "")) return NULL; st=sane_get_select_fd(self->h, &fd); if (st) return PySane_Error(st); return PyInt_FromLong(fd); } static PyObject * SaneDev_start(self, args) SaneDevObject *self; PyObject *args; { SANE_Status st; if (!PyArg_ParseTuple(args, "")) return NULL; st=sane_start(self->h); if (st) return PySane_Error(st); Py_INCREF(Py_None); return Py_None; } static PyObject * SaneDev_cancel(self, args) SaneDevObject *self; PyObject *args; { if (!PyArg_ParseTuple(args, "")) return NULL; sane_cancel(self->h); Py_INCREF(Py_None); return Py_None; } static PyObject * SaneDev_get_options(self, args) SaneDevObject *self; PyObject *args; { SANE_Option_Descriptor *d; PyObject *list, *value; int i=1; if (!PyArg_ParseTuple(args, "")) return NULL; if (!(list = PyList_New(0))) return NULL; do { d=sane_get_option_descriptor(self->h, i); if (d!=NULL) { PyObject *constraint; int j; switch (d->constraint_type) { case(SANE_CONSTRAINT_NONE): Py_INCREF(Py_None); constraint=Py_None; break; case(SANE_CONSTRAINT_RANGE): constraint=Py_BuildValue("iii", d->constraint.range->min, d->constraint.range->max, d->constraint.range->quant); break; case(SANE_CONSTRAINT_WORD_LIST): constraint=PyList_New(d->constraint.word_list[0]); for (j=1; j<=d->constraint.word_list[0]; j++) PyList_SetItem(constraint, j-1, PyInt_FromLong(d->constraint.word_list[j])); break; case(SANE_CONSTRAINT_STRING_LIST): constraint=PyList_New(0); for(j=0; d->constraint.string_list[j]!=NULL; j++) PyList_Append(constraint, PyString_FromString(d->constraint.string_list[j]) ); break; } value=Py_BuildValue("isssiiiiO", i, d->name, d->title, d->desc, d->type, d->unit, d->size, d->cap, constraint); PyList_Append(list, value); } i++; } while (d!=NULL); return list; } static PyObject * SaneDev_get_option(self, args) SaneDevObject *self; PyObject *args; { SANE_Status st; SANE_Option_Descriptor *d; SANE_Int i; PyObject *value; int n; void *v; if (!PyArg_ParseTuple(args, "i", &n)) return NULL; d=sane_get_option_descriptor(self->h, n); v=malloc(d->size+1); st=sane_control_option(self->h, n, SANE_ACTION_GET_VALUE, v, &i); if (st) {free(v); return PySane_Error(st);} switch(d->type) { case(SANE_TYPE_BOOL): case(SANE_TYPE_INT): value=Py_BuildValue("ii", i, *( (SANE_Int*)v) ); break; case(SANE_TYPE_FIXED): value=Py_BuildValue("id", i, SANE_UNFIX((*((SANE_Fixed*)v))) ); break; case(SANE_TYPE_STRING): value=Py_BuildValue("is", i, v); break; case(SANE_TYPE_BUTTON): case(SANE_TYPE_GROUP): value=Py_BuildValue("iO", i, Py_None); break; } free(v); return value; } static PyObject * SaneDev_set_option(self, args) SaneDevObject *self; PyObject *args; { SANE_Status st; SANE_Option_Descriptor *d; SANE_Int i; PyObject *value; int n; void *v; if (!PyArg_ParseTuple(args, "iO", &n, &value)) return NULL; d=sane_get_option_descriptor(self->h, n); v=malloc(d->size+1); switch(d->type) { case(SANE_TYPE_BOOL): if (!PyInt_Check(value)) { PyErr_SetString(PyExc_TypeError, "SANE_BOOL requires an integer"); free(v); return NULL; } /* fall through */ case(SANE_TYPE_INT): if (!PyInt_Check(value)) { PyErr_SetString(PyExc_TypeError, "SANE_INT requires an integer"); free(v); return NULL; } *( (SANE_Int*)v) = PyInt_AsLong(value); break; case(SANE_TYPE_FIXED): if (!PyFloat_Check(value)) { PyErr_SetString(PyExc_TypeError, "SANE_FIXED requires a floating point number"); free(v); return NULL; } *( (SANE_Fixed*)v) = SANE_FIX(PyFloat_AsDouble(value)); break; case(SANE_TYPE_STRING): if (!PyString_Check(value)) { PyErr_SetString(PyExc_TypeError, "SANE_STRING requires a string"); free(v); return NULL; } memcpy(v, PyString_AsString(value), PyString_Size(value)); break; case(SANE_TYPE_BUTTON): case(SANE_TYPE_GROUP): break; } st=sane_control_option(self->h, n, SANE_ACTION_SET_VALUE, v, &i); if (st) {free(v); return PySane_Error(st);} free(v); return Py_BuildValue("i", i); } static PyObject * SaneDev_set_auto_option(self, args) SaneDevObject *self; PyObject *args; { SANE_Status st; SANE_Option_Descriptor *d; SANE_Int i; int n; if (!PyArg_ParseTuple(args, "i", &n)) return NULL; d=sane_get_option_descriptor(self->h, n); st=sane_control_option(self->h, n, SANE_ACTION_SET_AUTO, NULL, &i); if (st) {return PySane_Error(st);} return Py_BuildValue("i", i); } static PyObject * SaneDev_snap(self, args) SaneDevObject *self; PyObject *args; { SANE_Status st; SANE_Byte buffer[8192]; /* XXX how big should the buffer be? */ SANE_Int len; Imaging im; SANE_Parameters p; char *format="unknown format"; int px, py; long L; if (!PyArg_ParseTuple(args, "i", &L)) return NULL; im=(Imaging)L; st=SANE_STATUS_GOOD; px=py=0; while (st!=SANE_STATUS_EOF) { st=sane_read(self->h, buffer, 8192, &len); if (st && (st!=SANE_STATUS_EOF)) return PySane_Error(st); if (st==SANE_STATUS_GOOD) { if (p.format==SANE_FRAME_RGB) { } else { /* Handle some sort of 8-bit code */ /* XXX Optimize */ int i; for (i=0; iysize; i++) { im->image8[py][px]=buffer[i]; if (++px >= (int) im->xsize) px = 0, py++; } } } } Py_INCREF(Py_None); return Py_None; } static PyMethodDef SaneDev_methods[] = { {"get_parameters", (PyCFunction)SaneDev_get_parameters, 1}, {"get_options", (PyCFunction)SaneDev_get_options, 1}, {"get_option", (PyCFunction)SaneDev_get_option, 1}, {"set_option", (PyCFunction)SaneDev_set_option, 1}, {"set_auto_option", (PyCFunction)SaneDev_set_auto_option, 1}, {"start", (PyCFunction)SaneDev_start, 1}, {"cancel", (PyCFunction)SaneDev_cancel, 1}, {"snap", (PyCFunction)SaneDev_snap, 1}, {"fileno", (PyCFunction)SaneDev_fileno, 1}, {NULL, NULL} /* sentinel */ }; static PyObject * SaneDev_getattr(self, name) SaneDevObject *self; char *name; { #if 0 if (self->x_attr != NULL) { PyObject *v = PyDict_GetItemString(self->x_attr, name); if (v != NULL) { Py_INCREF(v); return v; } } #endif return Py_FindMethod(SaneDev_methods, (PyObject *)self, name); } static int SaneDev_setattr(self, name, v) SaneDevObject *self; char *name; PyObject *v; { #if 0 if (self->x_attr == NULL) { self->x_attr = PyDict_New(); if (self->x_attr == NULL) return -1; } if (v == NULL) { int rv = PyDict_DelItemString(self->x_attr, name); if (rv < 0) PyErr_SetString(PyExc_AttributeError, "delete non-existing SaneDev attribute"); return rv; } else return PyDict_SetItemString(self->x_attr, name, v); #endif } staticforward PyTypeObject SaneDev_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ "SaneDev", /*tp_name*/ sizeof(SaneDevObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ /* methods */ (destructor)SaneDev_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)SaneDev_getattr, /*tp_getattr*/ (setattrfunc)SaneDev_setattr, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ }; /* --------------------------------------------------------------------- */ static PyObject * PySane_init(self, args) PyObject *self; /* Not used */ PyObject *args; { SANE_Status st; SANE_Int version; if (!PyArg_ParseTuple(args, "")) return NULL; /* XXX Authorization is not yet supported */ st=sane_init(&version, NULL); if (st) return PySane_Error(st); return Py_BuildValue("iiii", version, SANE_VERSION_MAJOR(version), SANE_VERSION_MINOR(version), SANE_VERSION_BUILD(version)); } static PyObject * PySane_exit(self, args) PyObject *self; /* Not used */ PyObject *args; { if (!PyArg_ParseTuple(args, "")) return NULL; sane_exit(); Py_INCREF(Py_None); return Py_None; } static PyObject * PySane_get_devices(self, args) PyObject *self; /* Not used */ PyObject *args; { const SANE_Device **devlist; SANE_Device *dev; SANE_Status st; PyObject *list; int local_only, i; if (!PyArg_ParseTuple(args, "|i", &local_only)) { return NULL; } st=sane_get_devices(&devlist, local_only); if (st) return PySane_Error(st); if (!(list = PyList_New(0))) return NULL; for(i=0; devlist[i]!=NULL; i++) { dev=devlist[i]; PyList_Append(list, Py_BuildValue("ssss", dev->name, dev->vendor, dev->model, dev->type)); } return list; } /* Function returning new SaneDev object */ static PyObject * PySane_open(self, args) PyObject *self; PyObject *args; { SaneDevObject *rv; SANE_Status st; char *name; if (!PyArg_ParseTuple(args, "s", &name)) return NULL; rv = newSaneDevObject(); if ( rv == NULL ) return NULL; st = sane_open(name, &(rv->h)); if (st) { Py_DECREF(rv); return PySane_Error(st); } return (PyObject *)rv; } static PyObject * PySane_OPTION_IS_ACTIVE(self, args) PyObject *self; PyObject *args; { SANE_Int cap; long lg; if (!PyArg_ParseTuple(args, "i", &lg)) return NULL; cap=lg; return PyInt_FromLong( SANE_OPTION_IS_ACTIVE(cap)); } static PyObject * PySane_OPTION_IS_SETTABLE(self, args) PyObject *self; PyObject *args; { SANE_Int cap; long lg; if (!PyArg_ParseTuple(args, "i", &lg)) return NULL; cap=lg; return PyInt_FromLong( SANE_OPTION_IS_SETTABLE(cap)); } /* List of functions defined in the module */ static PyMethodDef PySane_methods[] = { {"init", PySane_init, 1}, {"exit", PySane_exit, 1}, {"get_devices", PySane_get_devices, 1}, {"_open", PySane_open, 1}, {"OPTION_IS_ACTIVE", PySane_OPTION_IS_ACTIVE, 1}, {"OPTION_IS_SETTABLE", PySane_OPTION_IS_SETTABLE, 1}, {NULL, NULL} /* sentinel */ }; static void insint(d, name, value) PyObject *d; char *name; int value; { PyObject *v = PyInt_FromLong((long) value); if (!v || PyDict_SetItemString(d, name, v)) Py_FatalError("can't initialize sane module"); Py_DECREF(v); } void init_sane() { PyObject *m, *d; /* Create the module and add the functions */ m = Py_InitModule("_sane", PySane_methods); /* Add some symbolic constants to the module */ d = PyModule_GetDict(m); ErrorObject = PyString_FromString("_sane.error"); PyDict_SetItemString(d, "error", ErrorObject); insint(d, "INFO_INEXACT", SANE_INFO_INEXACT); insint(d, "INFO_RELOAD_OPTIONS", SANE_INFO_RELOAD_OPTIONS); insint(d, "RELOAD_PARAMS", SANE_INFO_RELOAD_PARAMS); insint(d, "FRAME_GRAY", SANE_FRAME_GRAY); insint(d, "FRAME_RGB", SANE_FRAME_RGB); insint(d, "FRAME_RED", SANE_FRAME_RED); insint(d, "FRAME_GREEN", SANE_FRAME_GREEN); insint(d, "FRAME_BLUE", SANE_FRAME_BLUE); insint(d, "CONSTRAINT_NONE", SANE_CONSTRAINT_NONE); insint(d, "CONSTRAINT_RANGE", SANE_CONSTRAINT_RANGE); insint(d, "CONSTRAINT_WORD_LIST", SANE_CONSTRAINT_WORD_LIST); insint(d, "CONSTRAINT_STRING_LIST", SANE_CONSTRAINT_STRING_LIST); insint(d, "TYPE_BOOL", SANE_TYPE_BOOL); insint(d, "TYPE_INT", SANE_TYPE_INT); insint(d, "TYPE_FIXED", SANE_TYPE_FIXED); insint(d, "TYPE_STRING", SANE_TYPE_STRING); insint(d, "TYPE_BUTTON", SANE_TYPE_BUTTON); insint(d, "TYPE_GROUP", SANE_TYPE_GROUP); insint(d, "UNIT_NONE", SANE_UNIT_NONE); insint(d, "UNIT_PIXEL", SANE_UNIT_PIXEL); insint(d, "UNIT_BIT", SANE_UNIT_BIT); insint(d, "UNIT_MM", SANE_UNIT_MM); insint(d, "UNIT_DPI", SANE_UNIT_DPI); insint(d, "UNIT_PERCENT", SANE_UNIT_PERCENT); insint(d, "CAP_SOFT_SELECT", SANE_CAP_SOFT_SELECT); insint(d, "CAP_HARD_SELECT", SANE_CAP_HARD_SELECT); insint(d, "CAP_SOFT_DETECT", SANE_CAP_SOFT_DETECT); insint(d, "CAP_EMULATED", SANE_CAP_EMULATED); insint(d, "CAP_AUTOMATIC", SANE_CAP_AUTOMATIC); insint(d, "CAP_INACTIVE", SANE_CAP_INACTIVE); insint(d, "CAP_ADVANCED", SANE_CAP_ADVANCED); /* Check for errors */ if (PyErr_Occurred()) Py_FatalError("can't initialize module _sane"); } Imaging-1.1.3/Sane/sane.py0100444000076400007640000000430607442710203015124 0ustar fredrikfredrik import Image import _sane from _sane import * class Option: def __init__(self, args): import string self.index, self.name = args[0], args[1] self.title, self.desc = args[2], args[3] self.type, self.unit = args[4], args[5] self.size, self.cap = args[6], args[7] self.constraint = args[8] def f(x): if x=='-': return '_' else: return x if type(self.name)!=type(''): self.py_name=str(self.name) else: self.py_name=string.join(map(f, self.name), '') class SaneDev: def __init__(self, devname): d=self.__dict__ d['dev']=_sane._open(devname) d['opt']={} optlist=d['dev'].get_options() for t in optlist: o=Option(t) if o.type!=TYPE_GROUP: d['opt'][o.py_name]=o def __setattr__(self, key, value): dev=self.__dict__['dev'] optdict=self.__dict__['opt'] if not optdict.has_key(key): self.__dict__[key]=value ; return opt=optdict[key] if opt.type==TYPE_GROUP: raise AttributeError, "Groups can't be set: "+key if not _sane.OPTION_IS_ACTIVE(opt.cap): raise AttributeError, 'Inactive option: '+key if not _sane.OPTION_IS_SETTABLE(opt.cap): raise AttributeError, "Option can't be set by software: "+key self.last_opt = dev.set_option(opt.index, value) def __getattr__(self, key): dev=self.__dict__['dev'] optdict=self.__dict__['opt'] if not optdict.has_key(key): raise AttributeError, 'No such attribute: '+key opt=optdict[key] if opt.type==TYPE_BUTTON: raise AttributeError, "Buttons don't have values: "+key if opt.type==TYPE_GROUP: raise AttributeError, "Groups don't have values: "+key if not _sane.OPTION_IS_ACTIVE(opt.cap): raise AttributeError, 'Inactive option: '+key self.last_opt, value = dev.get_option(opt.index) return value def get_parameters(self): return self.dev.get_parameters() def get_options(self): return self.dev.get_options() def start(self): return self.dev.start() def cancel(self): return self.dev.cancel() def fileno(self): return self.dev.fileno() def snap(self): format, last_frame, (xsize, ysize), depth, bytes_per_line = self.get_parameters() im=Image.new(format, (xsize,ysize)) self.dev.snap( im.im.id ) return im def open(devname): new=SaneDev(devname) return new Imaging-1.1.3/Sane/demo.py0100444000076400007640000000135207442710203015120 0ustar fredrikfredrik # Get the path set up properly import sys ; sys.path.append('.') import sane print 'SANE version:', sane.init() print 'Available devices=', sane.get_devices() scanner=sane.open('qcam:0x378') print 'SaneDev object=', scanner print 'Device parameters:', scanner.get_parameters() # Set scan parameters scanner.contrast=170 ; scanner.brightness=150 ; scanner.white_level=190 scanner.depth=6 scanner.br_x=320 ; scanner.br_y=240 # Initiate the scan scanner.start() # Get an Image object # (For my B&W QuickCam, this is a grey-scale image. Other scanning devices # may return a im=scanner.snap() # Write the image out as a GIF file im.save('foo.gif') # The show method() simply saves the image to a temporary file and calls "xv". #im.show() Imaging-1.1.3/Scripts/README0100444000076400007640000000531407442710203015245 0ustar fredrikfredrik------- Scripts ------- This directory contains a number of more or less trivial utilities and demo programs. Comments and contributions are welcome. -------------------------------------------------------------------- pildriver.py (by Eric S. Raymond) A class implementing an image-processing calculator for scripts. Parses lists of commnds (or, called interactively, command-line arguments) into image loads, transformations, and saves. -------------------------------------------------------------------- viewer.py A simple image viewer. Can display all file formats handled by PIL. Transparent images are properly handled. -------------------------------------------------------------------- thresholder.py A simple utility that demonstrates how a transparent 1-bit overlay can be used to show the current thresholding of an 8-bit image. -------------------------------------------------------------------- enhancer.py Illustrates the ImageEnhance module. Drag the sliders to modify the images. This might be very slow on some platforms, depending on the Tk version. -------------------------------------------------------------------- painter.py Illustrates how a painting program could be based on PIL and Tk. Press the left mouse button and drag over the image to remove the colour. Some clever tricks have been used to get decent performance when updating the screen; see the sources for details. -------------------------------------------------------------------- player.py A simple image sequence player. You can use either a sequence format like FLI/FLC, GIF, or ARG, or give a number of images which are interpreted as frames in a sequence. All frames must have the same size. -------------------------------------------------------------------- gifmaker.py Convert a sequence file to a GIF animation. Note that the GIF encoder provided with this release of PIL writes uncompressed GIF files only, so the resulting animations are rather large compared with these created by other tools. -------------------------------------------------------------------- explode.py Split a sequence file into individual frames. -------------------------------------------------------------------- image2py.py Convert an image to a Python module containing an IMAGE variable. Note that the module using the module must include JPEG and ZIP decoders, unless the -u option is used. -------------------------------------------------------------------- olesummary.py Uses the OleFileIO module to dump the summary information from an OLE structured storage file. This works with most OLE files, including Word documents, FlashPix images, etc. Note that datetime fields currently show the number of seconds since January 1st, 1601. Imaging-1.1.3/Scripts/bdf2pil.py0100444000076400007640000001371607442710203016266 0ustar fredrikfredrik#! /usr/local/bin/python # # $Id: //modules/pil/Scripts/bdf2pil.py#2 $ # # File: # bdf2pil.py -- font compiler for X bitmap distribution files # # Description: # This utility converts a BDF font to an image file with an # associated font metrics file. # # History: # 96-05-16 fl: Created (after an idea from David Ascher) # 96-08-07 fl: Font metrics file uses network byte order # # Copyright (c) Fredrik Lundh 1996. All rights reserved. # VERSION = "1.0" # HACK try: import Image except: import sys sys.path.insert(0, ".") import Image # -------------------------------------------------------------------- # Parse X Bitmap Distribution Format (BDF) # -------------------------------------------------------------------- import string bdf_slant = { "R": "Roman", "I": "Italic", "O": "Oblique", "RI": "Reverse Italic", "RO": "Reverse Oblique", "OT": "Other" } bdf_spacing = { "P": "Proportional", "M": "Monospaced", "C": "Cell" } def bdf_char(f): # skip to STARTCHAR while 1: s = f.readline() if not s: return None if s[:9] == "STARTCHAR": break id = string.strip(s[9:]) # load symbol properties props = {} while 1: s = f.readline() if not s or s[:6] == "BITMAP": break i = string.find(s, " ") props[s[:i]] = s[i+1:-1] # load bitmap bitmap = [] while 1: s = f.readline() if not s or s[:7] == "ENDCHAR": break bitmap.append(s[:-1]) bitmap = string.join(bitmap, "") [w, h, x, y] = map(string.atoi, string.split(props["BBX"])) [dx, dy] = map(string.atoi, string.split(props["DWIDTH"])) bbox = (dx, dy, x, y, x+w, y+h) return id, string.atoi(props["ENCODING"]), bbox, bitmap def bdf2font(filename): f = open(filename) s = f.readline() if s[:13] != "STARTFONT 2.1": print filename, "is not a valid BDF file (ignoring)" return None print filename props = {} comments = [] while 1: s = f.readline() if not s or s[:13] == "ENDPROPERTIES": break i = string.find(s, " ") props[s[:i]] = s[i+1:-1] if s[:i] in ["COMMENT", "COPYRIGHT"]: if string.find(s, "LogicalFontDescription") < 0: comments.append(s[i+1:-1]) font = string.split(props["FONT"], "-") font[4] = bdf_slant[font[4]] font[11] = bdf_spacing[font[11]] ascent = string.atoi(props["FONT_ASCENT"]) descent = string.atoi(props["FONT_DESCENT"]) fontname = string.join(font[1:], ";") print "#", fontname #for i in comments: # print "#", i font = [] while 1: c = bdf_char(f) if not c: break id, code, bbox, bits = c if code >= 0: font.append((code, bbox, bits)) return font, fontname, ascent, descent # -------------------------------------------------------------------- # Translate font to image # -------------------------------------------------------------------- def font2image(font, ascent, descent): metrics = [None] * 256 # create glyph images for all characters in this font width = height = 0 glyph = [None]*256 for id, (dx, dy, b0, b1, b2, b3), bits in font: w, h = b2-b0, b3-b1 if w > 0 and h > 0: i = Image.core.new("L", (w, h)) height = max(height, h) d = Image.core.hex_decoder("1") d.setimage(i) d.decode(bits) glyph[id] = i width = width + w # pack the glyphs into a large image x = 0 bboxes = {} i = Image.core.fill("L", (width, height), 0) for id, (dx, dy, b0, b1, b2, b3), bits in font: w, h = b2-b0, b3-b1 if w > 0 and h > 0: bbox = (x, 0, x+w, h) metrics[id] = (dx, dy), (b0, b1, b2, b3), bbox i.paste(glyph[id], bbox) x = x + w bboxes[id] = bbox return i, bboxes def puti16(fp, values): # write network order (big-endian) 16-bit sequence for v in values: fp.write(chr(v>>8&255) + chr(v&255)) # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- import glob, os, sys print "BDF2PIL", VERSION, "-- Font compiler for X BDF fonts." print "Copyright (c) Fredrik Lundh 1996. All rights reserved." if len(sys.argv) <= 1: print print "Usage: bdf2pil files..." print print "BDF files are converted to a bitmap file (currently" print "using PBM format) and a font metrics file (PIL)." sys.exit(1) files = [] for f in sys.argv[1:]: files = files + glob.glob(f) for file in files: font, fontname, ascent, descent = bdf2font(file) if font: image, srcbbox = font2image(font, ascent, descent) # to be changed to PCX or something... image.save_ppm(os.path.splitext(file)[0] + ".pbm") # create font metrics file metrics = {} for id, xy_bbox, bits in font: x, y, x0, y0, x1, y1 = xy_bbox metrics[id] = (x, y, x0, ascent-y1, x1, ascent-y0) + srcbbox[id] fp = open(os.path.splitext(file)[0] + ".pil", "wb") fp.write("PILfont\n") fp.write("%s\n" % fontname) fp.write("DATA\n") for id in range(256): try: puti16(fp, metrics[id]) except KeyError: puti16(fp, (0,) * 10) fp.close() # -------------------------------------------------------------------- # Font metrics format: # "PILfont" LF # fontdescriptor LF # (optional) key=value... LF # "DATA" LF # binary data: 256*10*2 bytes (dx, dy, dstbox, srcbox) # # To place a character, cut out srcbox and paste at dstbox, # relative to the character position. Then move the character # position according to dx, dy. # -------------------------------------------------------------------- Imaging-1.1.3/Scripts/enhancer.py0100444000076400007640000000253307442710203016522 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/Scripts/enhancer.py#2 $ # # this demo script creates four windows containing an image and a slider. # drag the slider to modify the image. # from Tkinter import * import Image, ImageTk, ImageEnhance import sys # # enhancer widget class Enhance(Frame): def __init__(self, master, image, name, enhancer, lo, hi): Frame.__init__(self, master) # set up the image self.tkim = ImageTk.PhotoImage(image.mode, image.size) self.enhancer = enhancer(image) self.update("1.0") # normalize # image window Label(self, image=self.tkim).pack() # scale s = Scale(self, label=name, orient=HORIZONTAL, from_=lo, to=hi, resolution=0.01, command=self.update) s.set(self.value) s.pack() def update(self, value): self.value = eval(value) self.tkim.paste(self.enhancer.enhance(self.value)) # # main root = Tk() im = Image.open(sys.argv[1]) im.thumbnail((200, 200)) Enhance(root, im, "Color", ImageEnhance.Color, 0.0, 4.0).pack() Enhance(Toplevel(), im, "Sharpness", ImageEnhance.Sharpness, -2.0, 2.0).pack() Enhance(Toplevel(), im, "Brightness", ImageEnhance.Brightness, -1.0, 3.0).pack() Enhance(Toplevel(), im, "Contrast", ImageEnhance.Contrast, -1.0, 3.0).pack() root.mainloop() Imaging-1.1.3/Scripts/explode.py0100444000076400007640000000461207442710203016377 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/Scripts/explode.py#2 $ # # split an animation into a number of frame files # import Image import os, string, sys class Interval: def __init__(self, interval = "0"): self.setinterval(interval) def setinterval(self, interval): self.hilo = [] for s in string.split(interval, ","): if not string.strip(s): continue try: v = string.atoi(s) if v < 0: lo, hi = 0, -v else: lo = hi = v except ValueError: i = string.find(s, "-") lo, hi = string.atoi(s[:i]), string.atoi(s[i+1:]) self.hilo.append((hi, lo)) if not self.hilo: self.hilo = [(sys.maxint, 0)] def __getitem__(self, index): for hi, lo in self.hilo: if hi >= index >= lo: return 1 return 0 # -------------------------------------------------------------------- # main program html = 0 if sys.argv[1:2] == ["-h"]: html = 1 del sys.argv[1] if not sys.argv[2:]: print print "Syntax: python explode.py infile template [range]" print print "The template argument is used to construct the names of the" print "individual frame files. The frames are numbered file001.ext," print "file002.ext, etc. You can insert %d to control the placement" print "and syntax of the frame number." print print "The optional range argument specifies which frames to extract." print "You can give one or more ranges like 1-10, 5, -15 etc. If" print "omitted, all frames are extracted." sys.exit(1) infile = sys.argv[1] outfile = sys.argv[2] frames = Interval(string.join(sys.argv[3:], ",")) try: # check if outfile contains a placeholder outfile % 1 except TypeError: file, ext = os.path.splitext(outfile) outfile = file + "%03d" + ext ix = 1 im = Image.open(infile) if html: file, ext = os.path.splitext(outfile) html = open(file+".html", "w") html.write("\n\n") while 1: if frames[ix]: im.save(outfile % ix) print outfile % ix if html: html.write("
\n" % outfile % ix) try: im.seek(ix) except EOFError: break ix = ix + 1 if html: html.write("\n\n") Imaging-1.1.3/Scripts/gifmaker.py0100444000076400007640000000572607442710203016533 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/Scripts/gifmaker.py#2 $ # # convert sequence format to GIF animation # # history: # 97-01-03 fl created # # Copyright (c) Secret Labs AB 1997. All rights reserved. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # # # For special purposes, you can import this module and call # the makedelta or compress functions yourself. For example, # if you have an application that generates a sequence of # images, you can convert it to a GIF animation using some- # thing like the following code: # # import Image # import gifmaker # # sequence = [] # # # generate sequence # for i in range(100): # im = # sequence.append(im) # # # write GIF animation # fp = open("out.gif", "wb") # gifmaker.makedelta(fp, sequence) # fp.close() # # Alternatively, use an iterator to generate the sequence, and # write data directly to a socket. Or something... # import Image, ImageChops import string from GifImagePlugin import getheader, getdata # -------------------------------------------------------------------- # sequence iterator class image_sequence: def __init__(self, im): self.im = im def __getitem__(self, ix): try: if ix: self.im.seek(ix) return self.im except EOFError: raise IndexError # end of sequence # -------------------------------------------------------------------- # straightforward delta encoding def makedelta(fp, sequence): """Convert list of image frames to a GIF animation file""" frames = 0 previous = None for im in sequence: # # FIXME: write graphics control block before each frame if not previous: # global header for s in getheader(im) + getdata(im): fp.write(s) else: # delta frame delta = ImageChops.subtract_modulo(im, previous) bbox = delta.getbbox() if bbox: # compress difference for s in getdata(im.crop(bbox), offset = bbox[:2]): fp.write(s) else: # FIXME: what should we do in this case? pass previous = im.copy() frames = frames + 1 fp.write(";") return frames # -------------------------------------------------------------------- # main hack def compress(infile, outfile): # open input image, and force loading of first frame im = Image.open(infile) im.load() # open output file fp = open(outfile, "wb") seq = image_sequence(im) makedelta(fp, seq) fp.close() if __name__ == "__main__": import sys if len(sys.argv) < 3: print "GIFMAKER -- create GIF animations" print "Usage: gifmaker infile outfile" sys.exit(1) compress(sys.argv[1], sys.argv[2]) Imaging-1.1.3/Scripts/image2py.py0100444000076400007640000000546707442710203016465 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/Scripts/image2py.py#2 $ # # convert an image to a Python module # # to use the module, import it and access the "IMAGE" variable # # import img1 # im = img1.IMAGE # # the variable name can be changed with the -n option # # note that the application using this module must include JPEG # and/or ZIP decoders, unless the -u option is used. # # Copyright (c) Secret Labs AB 1997. All rights reserved. # Copyright (c) Fredrik Lundh 1997. # # See the README file for information on usage and redistribution. # import Image import getopt, string, StringIO, sys octdigits = "01234567" def usage(): print "image2py 0.1/97-01-03 -- convert image to python module" print print "Usage: image2py [options] imagefile pyfile" print print "Options:" print " -n set variable name (default is 'IMAGE')" print " -l use lossy compression (JPEG) if suitable" print " -u disable compression" print print "Provided you use distinct variable names, the output" print "files can be concatenated into one large module file." sys.exit(1) try: opt, argv = getopt.getopt(sys.argv[1:], "n:lu") except getopt.error, v: usage() name = "IMAGE" lossy = 0 compress = 1 for o, a in opt: if o == "-n": name = a elif o == "-l": lossy = 1 elif o == "-u": compress = 0 if len(argv) != 2: usage() # -------------------------------------------------------------------- # convert image to string im = Image.open(argv[0]) if im.format == "JPEG" and compress: # store as is data = open(argv[0], "rb").read() else: # load and store as PNG fp = StringIO.StringIO() if compress: if lossy and im.mode in ["L", "RGB"]: im.save(fp, "JPEG") else: im.convert("RGB").save(fp, "PNG") else: im.save(fp, "PPM") # FIXME: won't work with "P" images data = fp.getvalue() # -------------------------------------------------------------------- # convert string to python module (this is not very fast...) fp = open(argv[1], "w") data = repr(data) fp.write("# generated by image2py %s\n" % argv[0]) fp.write("import Image, StringIO\n") word = "%s = Image.open(StringIO.StringIO('" % name fp.write(word) c = len(word) i = 1 while i < len(data)-1: if data[i] != "\\": word = data[i] i = i + 1 else: if data[i+1] in octdigits: for n in range(2, 5): if data[i+n] not in octdigits: break word = data[i:i+n] i = i + n else: word = data[i:i+2] i = i + 2 l = len(word) if c + l >= 78-1: # fp.write("'\n'") fp.write("\\\n") c = 0 fp.write(word) c = c + l fp.write("'))\n") Imaging-1.1.3/Scripts/painter.py0100444000076400007640000000364607442710203016407 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/Scripts/painter.py#2 $ # # this demo script illustrates pasting into an already displayed # photoimage. note that the current version of Tk updates the whole # image everytime we paste, so to get decent performance, we split # the image into a set of tiles. # from Tkinter import * import Image, ImageTk import sys # # painter widget class PaintCanvas(Canvas): def __init__(self, master, image): Canvas.__init__(self, master, width=image.size[0], height=image.size[1]) # fill the canvas self.tile = {} self.tilesize = tilesize = 32 xsize, ysize = image.size for x in range(0, xsize, tilesize): for y in range(0, ysize, tilesize): box = x, y, min(xsize, x+tilesize), min(ysize, y+tilesize) tile = ImageTk.PhotoImage(image.crop(box)) self.create_image(x, y, image=tile, anchor=NW) self.tile[(x,y)] = box, tile self.image = image self.bind("", self.paint) def paint(self, event): xy = event.x - 10, event.y - 10, event.x + 10, event.y + 10 im = self.image.crop(xy) # process the image in some fashion im = im.convert("L") self.image.paste(im, xy) self.repair(xy) def repair(self, box): # update canvas dx = box[0] % self.tilesize dy = box[1] % self.tilesize for x in range(box[0]-dx, box[2]+1, self.tilesize): for y in range(box[1]-dy, box[3]+1, self.tilesize): try: xy, tile = self.tile[(x, y)] tile.paste(self.image.crop(xy)) except KeyError: pass # outside the image self.update_idletasks() # # main root = Tk() im = Image.open(sys.argv[1]) if im.mode != "RGB": im = im.convert("RGB") PaintCanvas(root, im).pack() root.mainloop() Imaging-1.1.3/Scripts/player.py0100444000076400007640000000524307442710203016234 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/Scripts/player.py#2 $ # from Tkinter import * import Image, ImageTk import sys Image.DEBUG = 0 # -------------------------------------------------------------------- # experimental: support ARG animation scripts import ArgImagePlugin def applet_hook(animation, images): app = animation(animation_display, images) app.run() ArgImagePlugin.APPLET_HOOK = applet_hook class AppletDisplay: def __init__(self, ui): self.__ui = ui def paste(self, im, bbox): self.__ui.image.paste(im, bbox) def update(self): self.__ui.update_idletasks() # -------------------------------------------------------------------- # an image animation player class UI(Label): def __init__(self, master, im): if type(im) == type([]): # list of images self.im = im[1:] im = self.im[0] else: # sequence self.im = im if im.mode == "1": self.image = ImageTk.BitmapImage(im, foreground="white") else: self.image = ImageTk.PhotoImage(im) # APPLET SUPPORT (very crude, and not 100% safe) global animation_display animation_display = AppletDisplay(self) Label.__init__(self, master, image=self.image, bg="black", bd=0) self.update() try: duration = im.info["duration"] except KeyError: duration = 100 self.after(duration, self.next) def next(self): if type(self.im) == type([]): try: im = self.im[0] del self.im[0] self.image.paste(im) except IndexError: return # end of list else: try: im = self.im im.seek(im.tell() + 1) self.image.paste(im) except EOFError: return # end of file try: duration = im.info["duration"] except KeyError: duration = 100 self.after(duration, self.next) self.update_idletasks() # -------------------------------------------------------------------- # script interface if __name__ == "__main__": if not sys.argv[1:]: print "Syntax: python player.py imagefile(s)" sys.exit(1) filename = sys.argv[1] root = Tk() root.title(filename) if len(sys.argv) > 2: # list of images print "loading..." im = [] for filename in sys.argv[1:]: im.append(Image.open(filename)) else: # sequence im = Image.open(filename) UI(root, im).pack() root.mainloop() Imaging-1.1.3/Scripts/viewer.py0100444000076400007640000000153607442710204016243 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/Scripts/viewer.py#2 $ # from Tkinter import * import Image, ImageTk # # an image viewer class UI(Label): def __init__(self, master, im): if im.mode == "1": # bitmap image self.image = ImageTk.BitmapImage(im, foreground="white") Label.__init__(self, master, image=self.image, bg="black", bd=0) else: # photo image self.image = ImageTk.PhotoImage(im) Label.__init__(self, master, image=self.image, bd=0) # # script interface if __name__ == "__main__": import sys if not sys.argv[1:]: print "Syntax: python viewer.py imagefile" sys.exit(1) filename = sys.argv[1] root = Tk() root.title(filename) im = Image.open(filename) UI(root, im).pack() root.mainloop() Imaging-1.1.3/Scripts/thresholder.py0100444000076400007640000000327207442710204017264 0ustar fredrikfredrik# # The Python Imaging Library # $Id: //modules/pil/Scripts/thresholder.py#2 $ # # this demo script illustrates how a 1-bit BitmapImage can be used # as a dynamically updated overlay # from Tkinter import * import Image, ImageTk import sys # # an image viewer class UI(Frame): def __init__(self, master, im, value = 128): Frame.__init__(self, master) self.image = im self.value = value self.canvas = Canvas(self, width=im.size[0], height=im.size[1]) self.backdrop = ImageTk.PhotoImage(im) self.canvas.create_image(0, 0, image=self.backdrop, anchor=NW) self.canvas.pack() scale = Scale(self, orient=HORIZONTAL, from_=0, to=255, resolution=1, command=self.update, length=256) scale.set(value) scale.bind("", self.redraw) scale.pack() # uncomment the following line for instant feedback (might # be too slow on some platforms) # self.redraw() def update(self, value): self.value = eval(value) self.redraw() def redraw(self, event = None): # create overlay (note the explicit conversion to mode "1") im = self.image.point(lambda v,t=self.value: v>=t, "1") self.overlay = ImageTk.BitmapImage(im, foreground="green") # update canvas self.canvas.delete("overlay") self.canvas.create_image(0, 0, image=self.overlay, anchor=NW, tags="overlay") # -------------------------------------------------------------------- # main root = Tk() im = Image.open(sys.argv[1]) if im.mode != "L": im = im.convert("L") # im.thumbnail((320,200)) UI(root, im).pack() root.mainloop() Imaging-1.1.3/Tk/tkImaging.c0100444000076400007640000001236607442710204015400 0ustar fredrikfredrik/* * The Python Imaging Library. * $Id: tkImaging.c,v 1.1 2025/05/09 22:11:39 fredrik Exp $ * * TK interface for Python Imaging objects * * Copies (parts of) a named display memory to a photo image object. * Also contains code to create an display memory. Under Tk, a * display memory is simply an "L" or "RGB" image memory that is * allocated in a single block. * * To use this module, add the following lines to your Tcl_AppInit * function (in tkappinit.c). Put them after the calls to Tcl_Init * and Tk_Init: * * { * extern void TkImaging_Init(Tcl_Interp* interp); * TkImaging_Init(interp); * } * * This registers a Tcl command called "PyImagingPhoto", which * is use to communicate between PIL and Tk's PhotoImage handler. * * Compile and link tkImaging.c with tkappinit.c and _tkinter * (see the Setup file for details on how to use tkappinit.c). * Note that _tkinter.c must be compiled with WITH_APPINIT. * * History: * 2025-09-12 fl Created * 2025-04-08 fl Ready for release * 2025-05-09 fl Use command instead of image type * 2025-03-18 fl Initialize alpha layer pointer (struct changed in 8.3) * * Copyright (c) 1997-2001 by Secret Labs AB * Copyright (c) 1995-2001 by Fredrik Lundh * * See the README file for information on usage and redistribution. */ #include #include "tk.h" #include "Imaging.h" static Imaging ImagingFind(const char* name) { long id; /* FIXME: use CObject instead? */ id = atol(name); if (!id) return NULL; return (Imaging) id; } static int PyImagingPhoto(ClientData clientdata, Tcl_Interp* interp, int argc, char **argv) { Imaging im; Tk_PhotoHandle photo; Tk_PhotoImageBlock block; if (argc != 3) { Tcl_AppendResult(interp, "usage: ", argv[0], " destPhoto srcImage", (char *) NULL); return TCL_ERROR; } /* get Tcl PhotoImage handle */ photo = Tk_FindPhoto(interp, argv[1]); if (photo == NULL) { Tcl_AppendResult(interp, "destination photo must exist", (char *) NULL); return TCL_ERROR; } /* get PIL Image handle */ im = ImagingFind(argv[2]); if (!im) { Tcl_AppendResult(interp, "bad name", (char*) NULL); return TCL_ERROR; } if (!im->block) { Tcl_AppendResult(interp, "bad display memory", (char*) NULL); return TCL_ERROR; } /* Active region */ #if 0 if (src_xoffset + xsize > im->xsize) xsize = im->xsize - src_xoffset; if (src_yoffset + ysize > im->ysize) ysize = im->ysize - src_yoffset; if (xsize < 0 || ysize < 0 || src_xoffset >= im->xsize || src_yoffset >= im->ysize) return TCL_OK; #endif /* Mode */ if (strcmp(im->mode, "1") == 0 || strcmp(im->mode, "L") == 0) { block.pixelSize = 1; block.offset[0] = block.offset[1] = block.offset[2] = 0; } else if (strncmp(im->mode, "RGB", 3) == 0) { block.pixelSize = 4; block.offset[0] = 0; block.offset[1] = 1; block.offset[2] = 2; block.offset[3] = 0; /* no alpha (or reserved, under 8.2) */ } else { Tcl_AppendResult(interp, "Bad mode", (char*) NULL); return TCL_ERROR; } block.width = im->xsize; block.height = im->ysize; block.pitch = im->linesize; block.pixelPtr = (unsigned char*) im->block; #if 0 block.pixelPtr = (unsigned char*) im->block + src_yoffset * im->linesize + src_xoffset * im->pixelsize; #endif if (strcmp(im->mode, "RGBA") == 0) { /* Copy non-transparent pixels to photo image */ int x, y; Tk_PhotoImageBlock run; /* Clear current contents */ Tk_PhotoBlank(photo); /* Setup run descriptor */ run.height = 1; run.pitch = block.pitch; run.pixelSize = block.pixelSize; run.offset[0] = 0; run.offset[1] = 1; run.offset[2] = 2; run.offset[3] = 0; /* no alpha (or reserved, under 8.2) */ /* Copy opaque runs to photo image */ for (y = 0; y < block.height; y++) { unsigned char* p = block.pixelPtr + y*block.pitch; unsigned char* s = p; int w = 0; for (x = 0; x < block.width; x++) { if (p[3]) { /* opaque: add pixel to current run */ if (w == 0) s = p; w = w + 1; } else if (s) { /* copy run to photo image */ if (w > 0) { run.width = w; run.pixelPtr = s; Tk_PhotoPutBlock(photo, &run, x-w, y, run.width, 1); } w = 0; } p += block.pixelSize; } if (w > 0) { /* copy final run, if any */ run.width = w; run.pixelPtr = s; Tk_PhotoPutBlock(photo, &run, x-w, y, run.width, 1); } } } else /* Copy opaque block to photo image, and leave the rest to TK */ Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height); return TCL_OK; } void TkImaging_Init(Tcl_Interp* interp) { Tcl_CreateCommand(interp, "PyImagingPhoto", PyImagingPhoto, (ClientData) 0, (Tcl_CmdDeleteProc*) NULL); } Imaging-1.1.3/Tk/install.txt0100444000076400007640000000261207442710204015522 0ustar fredrikfredrik==================================================================== Using PIL With Tkinter ==================================================================== Starting with 1.0 final (release candidate 2 and later, to be precise), PIL can attach itself to Tkinter in flight. As a result, you no longer need to rebuild the Tkinter extension to be able to use PIL. However, if you cannot get the this to work on your platform, you can do it in the old way: * Adding Tkinter support 1. Compile Python's _tkinter.c with the WITH_APPINIT and WITH_PIL flags set, and link it with tkImaging.c and tkappinit.c. To do this, copy the former to the Modules directory, and edit the _tkinter line in Setup (or Setup.in) according to the instructions in that file. NOTE: if you have an old Python version, the tkappinit.c file is not included by default. If this is the case, you will have to add the following lines to tkappinit.c, after the MOREBUTTONS stuff: { extern void TkImaging_Init(Tcl_Interp* interp); TkImaging_Init(interp); } This registers a Tcl command called "PyImagingPhoto", which is use to communicate between PIL and Tk's PhotoImage handler. You must also change the _tkinter line in Setup (or Setup.in) to something like: _tkinter _tkinter.c tkImaging.c tkappinit.c -DWITH_APPINIT -I/usr/local/include -L/usr/local/lib -ltk8.0 -ltcl8.0 -lX11 Imaging-1.1.3/Tk/booster.txt0100444000076400007640000000750607442710204015540 0ustar fredrikfredrik==================================================================== The Photoimage Booster Patch (for Windows 95/NT) ==================================================================== This patch kit boosts performance for 16/24-bit displays. The first patch is required on Tk 4.2 (where it fixes the problems for 16-bit displays) and later versions, with the exception for Tk 8.0b1 where Sun added something similar themselves, only to remove it in 8.0b2. By installing both patches, Tk's PhotoImage handling becomes much faster on both 16-bit and 24-bit displays. The patch has been tested with Tk 4.2 and 8.0. Here's a benchmark, made with a sample program which loads two 512x512 greyscale PGM's, and two 512x512 colour PPM's, and displays each of them in a separate toplevel windows. Tcl/Tk was compiled with Visual C 4.0, and run on a P100 under Win95. Image load times are not included in the timings: 8-bit 16-bit 24-bit -------------------------------------------------------------------- 1. original 4.2 code 5.52 s 8.57 s 3.79 s 2. booster patch 5.49 s 1.87 s 1.82 s speedup None 4.6x 2.1x ==================================================================== Here's the patches: 1. For portability and speed, the best thing under Windows is to treat 16-bit displays as if they were 24-bit. The Windows device drivers take care of the rest. ---------------------------------------------------------------- If you have Tk 4.1 or Tk 8.0b1, you don't have to apply this patch! It only applies to Tk 4.2, Tk 8.0a[12] and Tk 8.0b2. ---------------------------------------------------------------- In win/tkWinImage.c, change the following line in XCreateImage: imagePtr->bits_per_pixel = depth; to /* ==================================================================== */ /* The tk photo image booster patch -- patch section 1 */ /* ==================================================================== */ if (visual->class == TrueColor) /* true colour is stored as 3 bytes: (blue, green, red) */ imagePtr->bits_per_pixel = 24; else imagePtr->bits_per_pixel = depth; /* ==================================================================== */ 2. The DitherInstance implementation is not good. It's especially bad on highend truecolour displays. IMO, it should be rewritten from scratch (some other day...). Anyway, the following band-aid makes the situation a little bit better under Windows. This hack trades some marginal quality (no dithering on 16-bit displays) for a dramatic performance boost. Requires patch 1, unless you're using Tk 4.1 or Tk 8.0b1. In generic/tkImgPhoto.c, add the #ifdef section to the DitherInstance function: for (; height > 0; height -= nLines) { if (nLines > height) { nLines = height; } dstLinePtr = (unsigned char *) imagePtr->data; yEnd = yStart + nLines; /* ==================================================================== */ /* The tk photo image booster patch -- patch section 2 */ /* ==================================================================== */ #ifdef __WIN32__ if (colorPtr->visualInfo.class == TrueColor && instancePtr->gamma == 1.0) { /* Windows hicolor/truecolor booster */ for (y = yStart; y < yEnd; ++y) { destBytePtr = dstLinePtr; srcPtr = srcLinePtr; for (x = xStart; x < xEnd; ++x) { destBytePtr[0] = srcPtr[2]; destBytePtr[1] = srcPtr[1]; destBytePtr[2] = srcPtr[0]; destBytePtr += 3; srcPtr += 3; } srcLinePtr += lineLength; dstLinePtr += bytesPerLine; } } else #endif /* ==================================================================== */ for (y = yStart; y < yEnd; ++y) { srcPtr = srcLinePtr; errPtr = errLinePtr; destBytePtr = dstLinePtr; ==================================================================== last updated: 97-07-03/fl Imaging-1.1.3/Tk/pilbitmap.txt0100444000076400007640000001076107442710204016041 0ustar fredrikfredrik==================================================================== The PIL Bitmap Booster Patch ==================================================================== The pilbitmap booster patch greatly improves performance of the ImageTk.BitmapImage constructor. Unfortunately, the design of Tk doesn't allow us to do this from the tkImaging interface module, so you have to patch the Tk sources. Once installed, the ImageTk module will automatically detect this patch. (Note: this patch has been tested with Tk 8.0 on Win32 only, but it should work just fine on other platforms as well). 1. To the beginning of TkGetBitmapData (in generic/tkImgBmap.c), add the following stuff: ------------------------------------------------------------------------ int width, height, numBytes, hotX, hotY; char *p, *end, *expandedFileName; ParseInfo pi; char *data = NULL; Tcl_DString buffer; /* ==================================================================== */ /* The pilbitmap booster patch -- patch section */ /* ==================================================================== */ char *PILGetBitmapData(); if (string) { /* Is this a PIL bitmap reference? */ data = PILGetBitmapData(string, widthPtr, heightPtr, hotXPtr, hotYPtr); if (data) return data; } /* ==================================================================== */ pi.string = string; if (string == NULL) { if (Tcl_IsSafe(interp)) { ------------------------------------------------------------------------ 2. Append the following to the same file (you may wish to include Imaging.h instead of copying the struct declaration...) ------------------------------------------------------------------------ /* ==================================================================== */ /* The pilbitmap booster patch -- code section */ /* ==================================================================== */ /* Imaging declaration boldly copied from Imaging.h (!) */ typedef struct ImagingInstance *Imaging; /* a.k.a. ImagingImage :-) */ typedef unsigned char UINT8; typedef int INT32; struct ImagingInstance { /* Format */ char mode[4+1]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK") */ int type; /* Always 0 in this version */ int depth; /* Always 8 in this version */ int bands; /* Number of bands (1, 3, or 4) */ int xsize; /* Image dimension. */ int ysize; /* Colour palette (for "P" images only) */ void* palette; /* Data pointers */ UINT8 **image8; /* Set for 8-bit image (pixelsize=1). */ INT32 **image32; /* Set for 32-bit image (pixelsize=4). */ /* Internals */ char **image; /* Actual raster data. */ char *block; /* Set if data is allocated in a single block. */ int pixelsize; /* Size of a pixel, in bytes (1 or 4) */ int linesize; /* Size of a line, in bytes (xsize * pixelsize) */ /* Virtual methods */ void (*im_delete)(Imaging *); }; /* The pilbitmap booster patch allows you to pass PIL images to the Tk bitmap decoder. Passing images this way is much more efficient than using the "tobitmap" method. */ char * PILGetBitmapData(string, widthPtr, heightPtr, hotXPtr, hotYPtr) char *string; int *widthPtr, *heightPtr; int *hotXPtr, *hotYPtr; { char* data; char* p; int y; Imaging im; if (strncmp(string, "PIL:", 4) != 0) return NULL; im = (Imaging) atol(string + 4); if (strcmp(im->mode, "1") != 0 && strcmp(im->mode, "L") != 0) return NULL; data = p = (char *) ckalloc((unsigned) ((im->xsize+7)/8) * im->ysize); for (y = 0; y < im->ysize; y++) { char* in = im->image8[y]; int i, m, b; b = 0; m = 1; for (i = 0; i < im->xsize; i++) { if (in[i] != 0) b |= m; m <<= 1; if (m == 256){ *p++ = b; b = 0; m = 1; } } if (m != 1) *p++ = b; } *widthPtr = im->xsize; *heightPtr = im->ysize; *hotXPtr = -1; *hotYPtr = -1; return data; } /* ==================================================================== */ ------------------------------------------------------------------------ 3. Recompile Tk and relink the _tkinter module (where necessary). ==================================================================== Last updated: 97-05-17/fl Imaging-1.1.3/MiniTest/test.py0100444000076400007640000000653507442710203016031 0ustar fredrikfredrik# minimal sanity check import sys sys.path.insert(0, "PIL") sys.path.insert(1, "MiniTest") import Image import ImageDraw import ImageFilter def _info(im): im.load() return im.format, im.mode, im.size def testimage(): """ PIL lets you create in-memory images with various pixel types: >>> im = Image.new("1", (128, 128)) # monochrome >>> _info(im) (None, '1', (128, 128)) >>> _info(Image.new("L", (128, 128))) # grayscale (luminance) (None, 'L', (128, 128)) >>> _info(Image.new("P", (128, 128))) # palette (None, 'P', (128, 128)) >>> _info(Image.new("RGB", (128, 128))) # truecolor (None, 'RGB', (128, 128)) >>> _info(Image.new("I", (128, 128))) # 32-bit integer (None, 'I', (128, 128)) >>> _info(Image.new("F", (128, 128))) # 32-bit floating point (None, 'F', (128, 128)) Or open existing files: >>> im = Image.open("Images/lena.gif") >>> _info(im) ('GIF', 'P', (128, 128)) >>> _info(Image.open("Images/lena.ppm")) ('PPM', 'RGB', (128, 128)) >>> _info(Image.open("Images/lena.jpg")) ('JPEG', 'RGB', (128, 128)) PIL doesn't actually load the image data until it's needed, or you call the "load" method: >>> im = Image.open("Images/lena.ppm") >>> type(im.im) # internal image attribute >>> im.load() >>> type(im.im) You can apply many different operations on images. Most operations return a new image: >>> im = Image.open("Images/lena.ppm") >>> _info(im.convert("L")) (None, 'L', (128, 128)) >>> _info(im.copy()) (None, 'RGB', (128, 128)) >>> _info(im.crop((32, 32, 96, 96))) (None, 'RGB', (64, 64)) >>> _info(im.filter(ImageFilter.BLUR)) (None, 'RGB', (128, 128)) >>> im.getbands() ('R', 'G', 'B') >>> im.getbbox() (0, 0, 128, 128) >>> len(im.getdata()) 16384 >>> im.getextrema() ((61, 255), (26, 234), (44, 223)) >>> im.getpixel((0, 0)) (223, 162, 133) >>> len(im.getprojection()) 2 >>> len(im.histogram()) 768 >>> _info(im.point(range(256)*3)) (None, 'RGB', (128, 128)) >>> _info(im.resize((64, 64))) (None, 'RGB', (64, 64)) >>> _info(im.rotate(45)) (None, 'RGB', (128, 128)) >>> map(_info, im.split()) [(None, 'L', (128, 128)), (None, 'L', (128, 128)), (None, 'L', (128, 128))] >>> len(im.convert("1").tobitmap()) 10456 >>> len(im.tostring()) 49152 >>> _info(im.transform((512, 512), Image.AFFINE, (1,0,0,0,1,0))) (None, 'RGB', (512, 512)) >>> _info(im.transform((512, 512), Image.EXTENT, (32,32,96,96))) (None, 'RGB', (512, 512)) The ImageDraw module lets you draw stuff in raster images: >>> im = Image.new("L", (128, 128), 64) >>> d = ImageDraw.ImageDraw(im) >>> d.line((0, 0, 128, 128), fill=128) >>> d.line((0, 128, 128, 0), fill=128) >>> im.getextrema() (64, 128) PIL can do many other things, but I'll leave that for another day. If you're curious, check the handbook, available from: http://www.pythonware.com Cheers /F """ if __name__ == "__main__": # use doctest to make sure the test program behaves as documented! import doctest, test status = doctest.testmod(test) if status[0]: print "*** %s tests of %d failed." % status else: print "%s tests passed." % status[1] Imaging-1.1.3/MiniTest/doctest.py0100444000076400007640000010622407442710203016513 0ustar fredrikfredrik# Module doctest version 0.9.6 # Released to the public domain 16-Jan-2001, # by Tim Peters (tim.one@home.com). # local modifications: # 2025-02-13 fl: minor tweaks to make it run under both 1.5.2 and 2.0 # Provided as-is; use at your own risk; no warranty; no promises; enjoy! """Module doctest -- a framework for running examples in docstrings. NORMAL USAGE In normal use, end each module M with: def _test(): import doctest, M # replace M with your module's name return doctest.testmod(M) # ditto if __name__ == "__main__": _test() Then running the module as a script will cause the examples in the docstrings to get executed and verified: python M.py This won't display anything unless an example fails, in which case the failing example(s) and the cause(s) of the failure(s) are printed to stdout (why not stderr? because stderr is a lame hack <0.2 wink>), and the final line of output is "Test failed.". Run it with the -v switch instead: python M.py -v and a detailed report of all examples tried is printed to stdout, along with assorted summaries at the end. You can force verbose mode by passing "verbose=1" to testmod, or prohibit it by passing "verbose=0". In either of those cases, sys.argv is not examined by testmod. In any case, testmod returns a 2-tuple of ints (f, t), where f is the number of docstring examples that failed and t is the total number of docstring examples attempted. WHICH DOCSTRINGS ARE EXAMINED? + M.__doc__. + f.__doc__ for all functions f in M.__dict__.values(), except those with private names. + C.__doc__ for all classes C in M.__dict__.values(), except those with private names. + If M.__test__ exists and "is true", it must be a dict, and each entry maps a (string) name to a function object, class object, or string. Function and class object docstrings found from M.__test__ are searched even if the name is private, and strings are searched directly as if they were docstrings. In output, a key K in M.__test__ appears with name .__test__.K Any classes found are recursively searched similarly, to test docstrings in their contained methods and nested classes. Private names reached from M's globals are skipped, but all names reached from M.__test__ are searched. By default, a name is considered to be private if it begins with an underscore (like "_my_func") but doesn't both begin and end with (at least) two underscores (like "__init__"). You can change the default by passing your own "isprivate" function to testmod. If you want to test docstrings in objects with private names too, stuff them into an M.__test__ dict, or see ADVANCED USAGE below (e.g., pass your own isprivate function to Tester's constructor, or call the rundoc method of a Tester instance). Warning: imports can cause trouble; e.g., if you do from XYZ import XYZclass then XYZclass is a name in M.__dict__ too, and doctest has no way to know that XYZclass wasn't *defined* in M. So it may try to execute the examples in XYZclass's docstring, and those in turn may require a different set of globals to work correctly. I prefer to do "import *"- friendly imports, a la import XYY _XYZclass = XYZ.XYZclass del XYZ or (Python 2.0) from XYZ import XYZclass as _XYZclass and then the leading underscore stops testmod from going nuts. You may prefer the method in the next section. WHAT'S THE EXECUTION CONTEXT? By default, each time testmod finds a docstring to test, it uses a *copy* of M's globals (so that running tests on a module doesn't change the module's real globals, and so that one test in M can't leave behind crumbs that accidentally allow another test to work). This means examples can freely use any names defined at top-level in M. It also means that sloppy imports (see above) can cause examples in external docstrings to use globals inappropriate for them. You can force use of your own dict as the execution context by passing "globs=your_dict" to testmod instead. Presumably this would be a copy of M.__dict__ merged with the globals from other imported modules. WHAT IF I WANT TO TEST A WHOLE PACKAGE? Piece o' cake, provided the modules do their testing from docstrings. Here's the test.py I use for the world's most elaborate Rational/ floating-base-conversion pkg (which I'll distribute some day): from Rational import Cvt from Rational import Format from Rational import machprec from Rational import Rat from Rational import Round from Rational import utils modules = (Cvt, Format, machprec, Rat, Round, utils) def _test(): import doctest import sys verbose = "-v" in sys.argv for mod in modules: doctest.testmod(mod, verbose=verbose, report=0) doctest.master.summarize() if __name__ == "__main__": _test() IOW, it just runs testmod on all the pkg modules. testmod remembers the names and outcomes (# of failures, # of tries) for each item it's seen, and passing "report=0" prevents it from printing a summary in verbose mode. Instead, the summary is delayed until all modules have been tested, and then "doctest.master.summarize()" forces the summary at the end. So this is very nice in practice: each module can be tested individually with almost no work beyond writing up docstring examples, and collections of modules can be tested too as a unit with no more work than the above. WHAT ABOUT EXCEPTIONS? No problem, as long as the only output generated by the example is the traceback itself. For example: >>> a = [None] >>> a[1] Traceback (innermost last): File "", line 1, in ? IndexError: list index out of range >>> Note that only the exception type and value are compared (specifically, only the last line in the traceback). ADVANCED USAGE doctest.testmod() captures the testing policy I find most useful most often. You may want other policies. testmod() actually creates a local instance of class doctest.Tester, runs appropriate methods of that class, and merges the results into global Tester instance doctest.master. You can create your own instances of doctest.Tester, and so build your own policies, or even run methods of doctest.master directly. See doctest.Tester.__doc__ for details. SO WHAT DOES A DOCSTRING EXAMPLE LOOK LIKE ALREADY!? Oh ya. It's easy! In most cases a copy-and-paste of an interactive console session works fine -- just make sure the leading whitespace is rigidly consistent (you can mix tabs and spaces if you're too lazy to do it right, but doctest is not in the business of guessing what you think a tab means). >>> # comments are ignored >>> x = 12 >>> x 12 >>> if x == 13: ... print "yes" ... else: ... print "no" ... print "NO" ... print "NO!!!" ... no NO NO!!! >>> Any expected output must immediately follow the final ">>>" or "..." line containing the code, and the expected output (if any) extends to the next ">>>" or all-whitespace line. That's it. Bummers: + Expected output cannot contain an all-whitespace line, since such a line is taken to signal the end of expected output. + Output to stdout is captured, but not output to stderr (exception tracebacks are captured via a different means). + If you continue a line via backslashing in an interactive session, or for any other reason use a backslash, you need to double the backslash in the docstring version. This is simply because you're in a string, and so the backslash must be escaped for it to survive intact. Like: >>> if "yes" == \\ ... "y" + \\ ... "es": # in the source code you'll see the doubled backslashes ... print 'yes' yes The starting column doesn't matter: >>> assert "Easy!" >>> import math >>> math.floor(1.9) 1.0 and as many leading whitespace characters are stripped from the expected output as appeared in the initial ">>>" line that triggered it. If you execute this very file, the examples above will be found and executed, leading to this output in verbose mode: Running doctest.__doc__ Trying: a = [None] Expecting: nothing ok Trying: a[1] Expecting: Traceback (innermost last): File "", line 1, in ? IndexError: list index out of range ok Trying: x = 12 Expecting: nothing ok Trying: x Expecting: 12 ok Trying: if x == 13: print "yes" else: print "no" print "NO" print "NO!!!" Expecting: no NO NO!!! ok ... and a bunch more like that, with this summary at the end: 5 items had no tests: doctest.Tester.__init__ doctest.Tester.run__test__ doctest.Tester.summarize doctest.run_docstring_examples doctest.testmod 12 items passed all tests: 9 tests in doctest 6 tests in doctest.Tester 10 tests in doctest.Tester.merge 7 tests in doctest.Tester.rundict 3 tests in doctest.Tester.rundoc 3 tests in doctest.Tester.runstring 2 tests in doctest.__test__._TestClass 2 tests in doctest.__test__._TestClass.__init__ 2 tests in doctest.__test__._TestClass.get 1 tests in doctest.__test__._TestClass.square 2 tests in doctest.__test__.string 7 tests in doctest.is_private 54 tests in 17 items. 54 passed and 0 failed. Test passed. """ # 0,0,1 06-Mar-1999 # initial version posted # 0,0,2 06-Mar-1999 # loosened parsing: # cater to stinkin' tabs # don't insist on a blank after PS2 prefix # so trailing "... " line from a compound stmt no longer # breaks if the file gets whitespace-trimmed # better error msgs for inconsistent leading whitespace # 0,9,1 08-Mar-1999 # exposed the Tester class and added client methods # plus docstring examples of their use (eww - head-twisting!) # fixed logic error in reporting total # of tests & failures # added __test__ support to testmod (a pale reflection of Christian # Tismer's vision ...) # removed the "deep" argument; fiddle __test__ instead # simplified endcase logic for extracting tests, and running them. # before, if no output was expected but some was produced # anyway via an eval'ed result, the discrepancy wasn't caught # made TestClass private and used __test__ to get at it # many doc updates # speed _SpoofOut for long expected outputs # 0,9,2 09-Mar-1999 # throw out comments from examples, enabling use of the much simpler # exec compile(... "single") ... # for simulating the runtime; that barfs on comment-only lines # used the traceback module to do a much better job of reporting # exceptions # run __doc__ values thru str(), "just in case" # privateness of names now determined by an overridable "isprivate" # function # by default a name now considered to be private iff it begins with # an underscore but doesn't both begin & end with two of 'em; so # e.g. Class.__init__ etc are searched now -- as they always # should have been # 0,9,3 18-Mar-1999 # added .flush stub to _SpoofOut (JPython buglet diagnosed by # Hugh Emberson) # repaired ridiculous docs about backslashes in examples # minor internal changes # changed source to Unix line-end conventions # moved __test__ logic into new Tester.run__test__ method # 0,9,4 27-Mar-1999 # report item name and line # in failing examples # 0,9,5 29-Jun-1999 # allow straightforward exceptions in examples - thanks to Mark Hammond! # 0,9,6 16-Jan-2001 # fiddling for changes in Python 2.0: some of the embedded docstring # examples no longer worked *exactly* as advertised, due to minor # language changes, and running doctest on itself pointed that out. # Hard to think of a better example of why this is useful . __version__ = 0, 9, 6 import types _FunctionType = types.FunctionType _ClassType = types.ClassType _ModuleType = types.ModuleType _StringType = types.StringType del types import string _string_find = string.find _string_join = string.join _string_split = string.split _string_rindex = string.rindex del string import re PS1 = ">>>" PS2 = "..." _isPS1 = re.compile(r"(\s*)" + re.escape(PS1)).match _isPS2 = re.compile(r"(\s*)" + re.escape(PS2)).match _isEmpty = re.compile(r"\s*$").match _isComment = re.compile(r"\s*#").match del re __all__ = [] # Extract interactive examples from a string. Return a list of triples, # (source, outcome, lineno). "source" is the source code, and ends # with a newline iff the source spans more than one line. "outcome" is # the expected output if any, else an empty string. When not empty, # outcome always ends with a newline. "lineno" is the line number, # 0-based wrt the start of the string, of the first source line. def _extract_examples(s): isPS1, isPS2 = _isPS1, _isPS2 isEmpty, isComment = _isEmpty, _isComment examples = [] lines = _string_split(s, "\n") i, n = 0, len(lines) while i < n: line = lines[i] i = i + 1 m = isPS1(line) if m is None: continue j = m.end(0) # beyond the prompt if isEmpty(line, j) or isComment(line, j): # a bare prompt or comment -- not interesting continue lineno = i - 1 if line[j] != " ": raise ValueError("line " + `lineno` + " of docstring lacks " "blank after " + PS1 + ": " + line) j = j + 1 blanks = m.group(1) nblanks = len(blanks) # suck up this and following PS2 lines source = [] while 1: source.append(line[j:]) line = lines[i] m = isPS2(line) if m: if m.group(1) != blanks: raise ValueError("inconsistent leading whitespace " "in line " + `i` + " of docstring: " + line) i = i + 1 else: break if len(source) == 1: source = source[0] else: # get rid of useless null line from trailing empty "..." if source[-1] == "": del source[-1] source = _string_join(source, "\n") + "\n" # suck up response if isPS1(line) or isEmpty(line): expect = "" else: expect = [] while 1: if line[:nblanks] != blanks: raise ValueError("inconsistent leading whitespace " "in line " + `i` + " of docstring: " + line) expect.append(line[nblanks:]) i = i + 1 line = lines[i] if isPS1(line) or isEmpty(line): break expect = _string_join(expect, "\n") + "\n" examples.append( (source, expect, lineno) ) return examples # Capture stdout when running examples. class _SpoofOut: def __init__(self): self.clear() def write(self, s): self.buf.append(s) def get(self): return _string_join(self.buf, "") def clear(self): self.buf = [] def flush(self): # JPython calls flush pass # Display some tag-and-msg pairs nicely, keeping the tag and its msg # on the same line when that makes sense. def _tag_out(printer, *tag_msg_pairs): for tag, msg in tag_msg_pairs: printer(tag + ":") msg_has_nl = msg[-1:] == "\n" msg_has_two_nl = msg_has_nl and \ _string_find(msg, "\n") < len(msg) - 1 if len(tag) + len(msg) < 76 and not msg_has_two_nl: printer(" ") else: printer("\n") printer(msg) if not msg_has_nl: printer("\n") # Run list of examples, in context globs. "out" can be used to display # stuff to "the real" stdout, and fakeout is an instance of _SpoofOut # that captures the examples' std output. Return (#failures, #tries). def _run_examples_inner(out, fakeout, examples, globs, verbose, name): import sys, traceback OK, BOOM, FAIL = range(3) NADA = "nothing" stderr = _SpoofOut() failures = 0 for source, want, lineno in examples: if verbose: _tag_out(out, ("Trying", source), ("Expecting", want or NADA)) fakeout.clear() try: exec compile(source, "", "single") in globs got = fakeout.get() state = OK except: # See whether the exception was expected. if _string_find(want, "Traceback (innermost last):\n") == 0 or\ _string_find(want, "Traceback (most recent call last):\n") == 0: # Only compare exception type and value - the rest of # the traceback isn't necessary. want = _string_split(want, '\n')[-2] + '\n' exc_type, exc_val, exc_tb = sys.exc_info() got = traceback.format_exception_only(exc_type, exc_val)[0] state = OK else: # unexpected exception stderr.clear() traceback.print_exc(file=stderr) state = BOOM if state == OK: if got == want: if verbose: out("ok\n") continue state = FAIL assert state in (FAIL, BOOM) failures = failures + 1 out("*" * 65 + "\n") _tag_out(out, ("Failure in example", source)) out("from line #" + `lineno` + " of " + name + "\n") if state == FAIL: _tag_out(out, ("Expected", want or NADA), ("Got", got)) else: assert state == BOOM _tag_out(out, ("Exception raised", stderr.get())) return failures, len(examples) # Run list of examples, in context globs. Return (#failures, #tries). def _run_examples(examples, globs, verbose, name): import sys saveout = sys.stdout try: sys.stdout = fakeout = _SpoofOut() x = _run_examples_inner(saveout.write, fakeout, examples, globs, verbose, name) finally: sys.stdout = saveout return x def run_docstring_examples(f, globs, verbose=0, name="NoName"): """f, globs, verbose=0, name="NoName" -> run examples from f.__doc__. Use dict globs as the globals for execution. Return (#failures, #tries). If optional arg verbose is true, print stuff even if there are no failures. Use string name in failure msgs. """ try: doc = f.__doc__ if not doc: # docstring empty or None return 0, 0 # just in case CT invents a doc object that has to be forced # to look like a string <0.9 wink> doc = str(doc) except: return 0, 0 e = _extract_examples(doc) if not e: return 0, 0 return _run_examples(e, globs, verbose, name) def is_private(prefix, base): """prefix, base -> true iff name prefix + "." + base is "private". Prefix may be an empty string, and base does not contain a period. Prefix is ignored (although functions you write conforming to this protocol may make use of it). Return true iff base begins with an (at least one) underscore, but does not both begin and end with (at least) two underscores. >>> is_private("a.b", "my_func") 0 >>> is_private("____", "_my_func") 1 >>> is_private("someclass", "__init__") 0 >>> is_private("sometypo", "__init_") 1 >>> is_private("x.y.z", "_") 1 >>> is_private("_x.y.z", "__") 0 >>> is_private("", "") # senseless but consistent 0 """ return base[:1] == "_" and not base[:2] == "__" == base[-2:] class Tester: """Class Tester -- runs docstring examples and accumulates stats. In normal use, function doctest.testmod() hides all this from you, so use that if you can. Create your own instances of Tester to do fancier things. Methods: runstring(s, name) Search string s for examples to run; use name for logging. Return (#failures, #tries). rundoc(object, name=None) Search object.__doc__ for examples to run; use name (or object.__name__) for logging. Return (#failures, #tries). rundict(d, name) Search for examples in docstrings in all of d.values(); use name for logging. Return (#failures, #tries). run__test__(d, name) Treat dict d like module.__test__. Return (#failures, #tries). summarize(verbose=None) Display summary of testing results, to stdout. Return (#failures, #tries). merge(other) Merge in the test results from Tester instance "other". >>> from doctest import Tester >>> t = Tester(globs={'x': 42}, verbose=0) >>> t.runstring(r''' ... >>> x = x * 2 ... >>> print x ... 42 ... ''', 'XYZ') ***************************************************************** Failure in example: print x from line #2 of XYZ Expected: 42 Got: 84 (1, 2) >>> t.runstring(">>> x = x * 2\\n>>> print x\\n84\\n", 'example2') (0, 2) >>> t.summarize() 1 items had failures: 1 of 2 in XYZ ***Test Failed*** 1 failures. (1, 4) >>> t.summarize(verbose=1) 1 items passed all tests: 2 tests in example2 1 items had failures: 1 of 2 in XYZ 4 tests in 2 items. 3 passed and 1 failed. ***Test Failed*** 1 failures. (1, 4) >>> """ def __init__(self, mod=None, globs=None, verbose=None, isprivate=None): """mod=None, globs=None, verbose=None, isprivate=None See doctest.__doc__ for an overview. Optional keyword arg "mod" is a module, whose globals are used for executing examples. If not specified, globs must be specified. Optional keyword arg "globs" gives a dict to be used as the globals when executing examples; if not specified, use the globals from module mod. In either case, a copy of the dict is used for each docstring examined. Optional keyword arg "verbose" prints lots of stuff if true, only failures if false; by default, it's true iff "-v" is in sys.argv. Optional keyword arg "isprivate" specifies a function used to determine whether a name is private. The default function is doctest.is_private; see its docs for details. """ if mod is None and globs is None: raise TypeError("Tester.__init__: must specify mod or globs") if mod is not None and type(mod) is not _ModuleType: raise TypeError("Tester.__init__: mod must be a module; " + `mod`) if globs is None: globs = mod.__dict__ self.globs = globs if verbose is None: import sys verbose = "-v" in sys.argv self.verbose = verbose if isprivate is None: isprivate = is_private self.isprivate = isprivate self.name2ft = {} # map name to (#failures, #trials) pair def runstring(self, s, name): """ s, name -> search string s for examples to run, logging as name. Use string name as the key for logging the outcome. Return (#failures, #examples). >>> t = Tester(globs={}, verbose=1) >>> test = r''' ... # just an example ... >>> x = 1 + 2 ... >>> x ... 3 ... ''' >>> t.runstring(test, "Example") Running string Example Trying: x = 1 + 2 Expecting: nothing ok Trying: x Expecting: 3 ok 0 of 2 examples failed in string Example (0, 2) """ if self.verbose: print "Running string", name f = t = 0 e = _extract_examples(s) if e: f, t = _run_examples(e, self.globs.copy(), self.verbose, name) if self.verbose: print f, "of", t, "examples failed in string", name self.__record_outcome(name, f, t) return f, t def rundoc(self, object, name=None): """ object, name=None -> search object.__doc__ for examples to run. Use optional string name as the key for logging the outcome; by default use object.__name__. Return (#failures, #examples). If object is a class object, search recursively for method docstrings too. object.__doc__ is examined regardless of name, but if object is a class, whether private names reached from object are searched depends on the constructor's "isprivate" argument. >>> t = Tester(globs={}, verbose=0) >>> def _f(): ... '''Trivial docstring example. ... >>> assert 2 == 2 ... ''' ... return 32 ... >>> t.rundoc(_f) # expect 0 failures in 1 example (0, 1) """ if name is None: try: name = object.__name__ except AttributeError: raise ValueError("Tester.rundoc: name must be given " "when object.__name__ doesn't exist; " + `object`) if self.verbose: print "Running", name + ".__doc__" f, t = run_docstring_examples(object, self.globs.copy(), self.verbose, name) if self.verbose: print f, "of", t, "examples failed in", name + ".__doc__" self.__record_outcome(name, f, t) if type(object) is _ClassType: f2, t2 = self.rundict(object.__dict__, name) f = f + f2 t = t + t2 return f, t def rundict(self, d, name): """ d. name -> search for docstring examples in all of d.values(). For k, v in d.items() such that v is a function or class, do self.rundoc(v, name + "." + k). Whether this includes objects with private names depends on the constructor's "isprivate" argument. Return aggregate (#failures, #examples). >>> def _f(): ... '''>>> assert 1 == 1 ... ''' >>> def g(): ... '''>>> assert 2 != 1 ... ''' >>> d = {"_f": _f, "g": g} >>> t = Tester(globs={}, verbose=0) >>> t.rundict(d, "rundict_test") # _f is skipped (0, 1) >>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0) >>> t.rundict(d, "rundict_test_pvt") # both are searched (0, 2) """ if not hasattr(d, "items"): raise TypeError("Tester.rundict: d must support .items(); " + `d`) f = t = 0 for thisname, value in d.items(): if type(value) in (_FunctionType, _ClassType): f2, t2 = self.__runone(value, name + "." + thisname) f = f + f2 t = t + t2 return f, t def run__test__(self, d, name): """d, name -> Treat dict d like module.__test__. Return (#failures, #tries). See testmod.__doc__ for details. """ failures = tries = 0 prefix = name + "." savepvt = self.isprivate try: self.isprivate = lambda *args: 0 for k, v in d.items(): thisname = prefix + k if type(v) is _StringType: f, t = self.runstring(v, thisname) elif type(v) in (_FunctionType, _ClassType): f, t = self.rundoc(v, thisname) else: raise TypeError("Tester.run__test__: values in " "dict must be strings, functions " "or classes; " + `v`) failures = failures + f tries = tries + t finally: self.isprivate = savepvt return failures, tries def summarize(self, verbose=None): """ verbose=None -> summarize results, return (#failures, #tests). Print summary of test results to stdout. Optional arg 'verbose' controls how wordy this is. By default, use the verbose setting established by the constructor. """ if verbose is None: verbose = self.verbose notests = [] passed = [] failed = [] totalt = totalf = 0 for x in self.name2ft.items(): name, (f, t) = x assert f <= t totalt = totalt + t totalf = totalf + f if t == 0: notests.append(name) elif f == 0: passed.append( (name, t) ) else: failed.append(x) if verbose: if notests: print len(notests), "items had no tests:" notests.sort() for thing in notests: print " ", thing if passed: print len(passed), "items passed all tests:" passed.sort() for thing, count in passed: print " %3d tests in %s" % (count, thing) if failed: print len(failed), "items had failures:" failed.sort() for thing, (f, t) in failed: print " %3d of %3d in %s" % (f, t, thing) if verbose: print totalt, "tests in", len(self.name2ft), "items." print totalt - totalf, "passed and", totalf, "failed." if totalf: print "***Test Failed***", totalf, "failures." elif verbose: print "Test passed." return totalf, totalt def merge(self, other): """ other -> merge in test results from the other Tester instance. If self and other both have a test result for something with the same name, the (#failures, #tests) results are summed, and a warning is printed to stdout. >>> from doctest import Tester >>> t1 = Tester(globs={}, verbose=0) >>> t1.runstring(''' ... >>> x = 12 ... >>> print x ... 12 ... ''', "t1example") (0, 2) >>> >>> t2 = Tester(globs={}, verbose=0) >>> t2.runstring(''' ... >>> x = 13 ... >>> print x ... 13 ... ''', "t2example") (0, 2) >>> common = ">>> assert 1 + 2 == 3\\n" >>> t1.runstring(common, "common") (0, 1) >>> t2.runstring(common, "common") (0, 1) >>> t1.merge(t2) *** Tester.merge: 'common' in both testers; summing outcomes. >>> t1.summarize(1) 3 items passed all tests: 2 tests in common 2 tests in t1example 2 tests in t2example 6 tests in 3 items. 6 passed and 0 failed. Test passed. (0, 6) >>> """ d = self.name2ft for name, (f, t) in other.name2ft.items(): if d.has_key(name): print "*** Tester.merge: '" + name + "' in both" \ " testers; summing outcomes." f2, t2 = d[name] f = f + f2 t = t + t2 d[name] = f, t def __record_outcome(self, name, f, t): if self.name2ft.has_key(name): print "*** Warning: '" + name + "' was tested before;", \ "summing outcomes." f2, t2 = self.name2ft[name] f = f + f2 t = t + t2 self.name2ft[name] = f, t def __runone(self, target, name): if "." in name: i = _string_rindex(name, ".") prefix, base = name[:i], name[i+1:] else: prefix, base = "", base if self.isprivate(prefix, base): return 0, 0 return self.rundoc(target, name) master = None def testmod(m, name=None, globs=None, verbose=None, isprivate=None, report=1): """m, name=None, globs=None, verbose=None, isprivate=None, report=1 Test examples in docstrings in functions and classes reachable from module m, starting with m.__doc__. Private names are skipped. Also test examples reachable from dict m.__test__ if it exists and is not None. m.__dict__ maps names to functions, classes and strings; function and class docstrings are tested even if the name is private; strings are tested directly, as if they were docstrings. Return (#failures, #tests). See doctest.__doc__ for an overview. Optional keyword arg "name" gives the name of the module; by default use m.__name__. Optional keyword arg "globs" gives a dict to be used as the globals when executing examples; by default, use m.__dict__. A copy of this dict is actually used for each docstring, so that each docstring's examples start with a clean slate. Optional keyword arg "verbose" prints lots of stuff if true, prints only failures if false; by default, it's true iff "-v" is in sys.argv. Optional keyword arg "isprivate" specifies a function used to determine whether a name is private. The default function is doctest.is_private; see its docs for details. Optional keyword arg "report" prints a summary at the end when true, else prints nothing at the end. In verbose mode, the summary is detailed, else very brief (in fact, empty if all tests passed). Advanced tomfoolery: testmod runs methods of a local instance of class doctest.Tester, then merges the results into (or creates) global Tester instance doctest.master. Methods of doctest.master can be called directly too, if you want to do something unusual. Passing report=0 to testmod is especially useful then, to delay displaying a summary. Invoke doctest.master.summarize(verbose) when you're done fiddling. """ global master if type(m) is not _ModuleType: raise TypeError("testmod: module required; " + `m`) if name is None: name = m.__name__ tester = Tester(m, globs=globs, verbose=verbose, isprivate=isprivate) failures, tries = tester.rundoc(m, name) f, t = tester.rundict(m.__dict__, name) failures = failures + f tries = tries + t if hasattr(m, "__test__"): testdict = m.__test__ if testdict: if not hasattr(testdict, "items"): raise TypeError("testmod: module.__test__ must support " ".items(); " + `testdict`) f, t = tester.run__test__(testdict, name + ".__test__") failures = failures + f tries = tries + t if report: tester.summarize() if master is None: master = tester else: master.merge(tester) return failures, tries class _TestClass: """ A pointless class, for sanity-checking of docstring testing. Methods: square() get() >>> _TestClass(13).get() + _TestClass(-12).get() 1 >>> hex(_TestClass(13).square().get()) '0xa9' """ def __init__(self, val): """val -> _TestClass object with associated value val. >>> t = _TestClass(123) >>> print t.get() 123 """ self.val = val def square(self): """square() -> square TestClass's associated value >>> _TestClass(13).square().get() 169 """ self.val = self.val ** 2 return self def get(self): """get() -> return TestClass's associated value. >>> x = _TestClass(-42) >>> print x.get() -42 """ return self.val __test__ = {"_TestClass": _TestClass, "string": r""" Example of a string object, searched as-is. >>> x = 1; y = 2 >>> x + y, x * y (3, 2) """ } def _test(): import doctest return doctest.testmod(doctest) if __name__ == "__main__": _test()