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