Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{jpeg} --- |
Fred Drake | 67d229e | 1999-02-20 04:51:16 +0000 | [diff] [blame] | 2 | Read and write JPEG files} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | |
Fred Drake | 67d229e | 1999-02-20 04:51:16 +0000 | [diff] [blame] | 4 | \declaremodule{builtin}{jpeg} |
Fred Drake | f6863c1 | 1999-03-02 16:37:17 +0000 | [diff] [blame] | 5 | \platform{IRIX} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 6 | \modulesynopsis{Read and write image files in compressed JPEG format.} |
| 7 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 8 | |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 9 | The module \module{jpeg} provides access to the jpeg compressor and |
Fred Drake | be110c1 | 1999-03-12 15:27:35 +0000 | [diff] [blame] | 10 | decompressor written by the Independent JPEG Group |
| 11 | \index{Independent JPEG Group}(IJG). JPEG is a standard for |
| 12 | compressing pictures; it is defined in ISO 10918. For details on JPEG |
| 13 | or the Independent JPEG Group software refer to the JPEG standard or |
| 14 | the documentation provided with the software. |
| 15 | |
| 16 | A portable interface to JPEG image files is available with the Python |
| 17 | Imaging Library (PIL) by Fredrik Lundh. Information on PIL is |
| 18 | available at \url{http://www.pythonware.com/products/pil/}. |
| 19 | \index{Python Imaging Library} |
| 20 | \index{PIL (the Python Imaging Library)} |
| 21 | \index{Lundh, Fredrik} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 22 | |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 23 | The \module{jpeg} module defines an exception and some functions. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 24 | |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 25 | \begin{excdesc}{error} |
| 26 | Exception raised by \function{compress()} and \function{decompress()} |
| 27 | in case of errors. |
| 28 | \end{excdesc} |
| 29 | |
| 30 | \begin{funcdesc}{compress}{data, w, h, b} |
| 31 | Treat data as a pixmap of width \var{w} and height \var{h}, with |
| 32 | \var{b} bytes per pixel. The data is in SGI GL order, so the first |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 33 | pixel is in the lower-left corner. This means that \function{gl.lrectread()} |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 34 | return data can immediately be passed to \function{compress()}. |
| 35 | Currently only 1 byte and 4 byte pixels are allowed, the former being |
| 36 | treated as greyscale and the latter as RGB color. |
| 37 | \function{compress()} returns a string that contains the compressed |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 38 | picture, in JFIF\index{JFIF} format. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 39 | \end{funcdesc} |
| 40 | |
| 41 | \begin{funcdesc}{decompress}{data} |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 42 | Data is a string containing a picture in JFIF\index{JFIF} format. It |
| 43 | returns a tuple \code{(\var{data}, \var{width}, \var{height}, |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 44 | \var{bytesperpixel})}. Again, the data is suitable to pass to |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 45 | \function{gl.lrectwrite()}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 46 | \end{funcdesc} |
| 47 | |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 48 | \begin{funcdesc}{setoption}{name, value} |
| 49 | Set various options. Subsequent \function{compress()} and |
| 50 | \function{decompress()} calls will use these options. The following |
| 51 | options are available: |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 52 | |
Fred Drake | ee60191 | 1998-04-11 20:53:03 +0000 | [diff] [blame] | 53 | \begin{tableii}{l|p{3in}}{code}{Option}{Effect} |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 54 | \lineii{'forcegray'}{% |
| 55 | Force output to be grayscale, even if input is RGB.} |
| 56 | \lineii{'quality'}{% |
| 57 | Set the quality of the compressed image to a value between |
Fred Drake | fab2f34 | 1998-04-11 18:46:56 +0000 | [diff] [blame] | 58 | \code{0} and \code{100} (default is \code{75}). This only affects |
| 59 | compression.} |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 60 | \lineii{'optimize'}{% |
| 61 | Perform Huffman table optimization. Takes longer, but results in |
Fred Drake | fab2f34 | 1998-04-11 18:46:56 +0000 | [diff] [blame] | 62 | smaller compressed image. This only affects compression.} |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 63 | \lineii{'smooth'}{% |
| 64 | Perform inter-block smoothing on uncompressed image. Only useful |
Fred Drake | fab2f34 | 1998-04-11 18:46:56 +0000 | [diff] [blame] | 65 | for low-quality images. This only affects decompression.} |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 66 | \end{tableii} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 67 | \end{funcdesc} |
Fred Drake | be110c1 | 1999-03-12 15:27:35 +0000 | [diff] [blame] | 68 | |
| 69 | |
| 70 | \begin{seealso} |
Fred Drake | e20bd19 | 2001-04-12 16:47:17 +0000 | [diff] [blame] | 71 | \seetitle{JPEG Still Image Data Compression Standard}{The |
| 72 | canonical reference for the JPEG image format, by |
| 73 | Pennebaker and Mitchell.} |
Fred Drake | be110c1 | 1999-03-12 15:27:35 +0000 | [diff] [blame] | 74 | |
Fred Drake | e20bd19 | 2001-04-12 16:47:17 +0000 | [diff] [blame] | 75 | \seetitle[http://www.w3.org/Graphics/JPEG/itu-t81.pdf]{Information |
| 76 | Technology - Digital Compression and Coding of |
| 77 | Continuous-tone Still Images - Requirements and |
| 78 | Guidelines}{The ISO standard for JPEG is also published as |
| 79 | ITU T.81. This is available online in PDF form.} |
Fred Drake | be110c1 | 1999-03-12 15:27:35 +0000 | [diff] [blame] | 80 | \end{seealso} |