Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 1 | \section{Built-in Module \sectcode{jpeg}} |
| 2 | \bimodindex{jpeg} |
| 3 | |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 4 | The module \code{jpeg} provides access to the jpeg compressor and |
| 5 | decompressor written by the Independent JPEG Group. JPEG is a (draft?)\ |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 6 | standard for compressing pictures. For details on jpeg or the |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 7 | Independent JPEG Group software refer to the JPEG standard or the |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 8 | documentation provided with the software. |
| 9 | |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 10 | The \code{jpeg} module defines these functions: |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 11 | |
| 12 | \renewcommand{\indexsubitem}{(in module jpeg)} |
| 13 | \begin{funcdesc}{compress}{data\, w\, h\, b} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 14 | Treat data as a pixmap of width \var{w} and height \var{h}, with \var{b} bytes per |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 15 | pixel. The data is in SGI GL order, so the first pixel is in the |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 16 | lower-left corner. This means that \code{lrectread} return data can |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 17 | immediately be passed to compress. Currently only 1 byte and 4 byte |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 18 | pixels are allowed, the former being treated as greyscale and the |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 19 | latter as RGB color. Compress returns a string that contains the |
| 20 | compressed picture, in JFIF format. |
| 21 | \end{funcdesc} |
| 22 | |
| 23 | \begin{funcdesc}{decompress}{data} |
| 24 | Data is a string containing a picture in JFIF format. It returns a |
| 25 | tuple |
| 26 | \code{(\var{data}, \var{width}, \var{height}, \var{bytesperpixel})}. |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 27 | Again, the data is suitable to pass to \code{lrectwrite}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 28 | \end{funcdesc} |
| 29 | |
| 30 | \begin{funcdesc}{setoption}{name\, value} |
| 31 | Set various options. Subsequent compress and decompress calls |
| 32 | will use these options. The following options are available: |
| 33 | \begin{description} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 34 | \item[\code{'forcegray' }] |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 35 | Force output to be grayscale, even if input is RGB. |
| 36 | |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 37 | \item[\code{'quality' }] |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 38 | Set the quality of the compressed image to a |
| 39 | value between \code{0} and \code{100} (default is \code{75}). Compress only. |
| 40 | |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 41 | \item[\code{'optimize' }] |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 42 | Perform Huffman table optimization. Takes longer, but results in |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 43 | smaller compressed image. Compress only. |
| 44 | |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 45 | \item[\code{'smooth' }] |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 46 | Perform inter-block smoothing on uncompressed image. Only useful for |
| 47 | low-quality images. Decompress only. |
| 48 | \end{description} |
| 49 | \end{funcdesc} |
| 50 | |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 51 | Compress and uncompress raise the error \code{jpeg.error} in case of errors. |