blob: 0d1dc1ce4c20d3f8d97c6ea27ea706e104199581 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in Module \sectcode{jpeg}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-jpeg}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003\bimodindex{jpeg}
4
Guido van Rossum6bb1adc1995-03-13 10:03:32 +00005The module \code{jpeg} provides access to the jpeg compressor and
6decompressor written by the Independent JPEG Group. JPEG is a (draft?)\
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007standard for compressing pictures. For details on jpeg or the
Guido van Rossum16d6e711994-08-08 12:30:22 +00008Independent JPEG Group software refer to the JPEG standard or the
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00009documentation provided with the software.
10
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000011The \code{jpeg} module defines these functions:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000012
13\renewcommand{\indexsubitem}{(in module jpeg)}
14\begin{funcdesc}{compress}{data\, w\, h\, b}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000015Treat data as a pixmap of width \var{w} and height \var{h}, with \var{b} bytes per
Guido van Rossum16d6e711994-08-08 12:30:22 +000016pixel. The data is in SGI GL order, so the first pixel is in the
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000017lower-left corner. This means that \code{lrectread} return data can
Guido van Rossum96628a91995-04-10 11:34:00 +000018immediately be passed to compress. Currently only 1 byte and 4 byte
Guido van Rossum16d6e711994-08-08 12:30:22 +000019pixels are allowed, the former being treated as greyscale and the
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000020latter as RGB color. Compress returns a string that contains the
21compressed picture, in JFIF format.
22\end{funcdesc}
23
24\begin{funcdesc}{decompress}{data}
25Data is a string containing a picture in JFIF format. It returns a
26tuple
27\code{(\var{data}, \var{width}, \var{height}, \var{bytesperpixel})}.
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000028Again, the data is suitable to pass to \code{lrectwrite}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029\end{funcdesc}
30
31\begin{funcdesc}{setoption}{name\, value}
32Set various options. Subsequent compress and decompress calls
33will use these options. The following options are available:
34\begin{description}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000035\item[\code{'forcegray' }]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000036Force output to be grayscale, even if input is RGB.
37
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000038\item[\code{'quality' }]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000039Set the quality of the compressed image to a
40value between \code{0} and \code{100} (default is \code{75}). Compress only.
41
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000042\item[\code{'optimize' }]
Guido van Rossum16d6e711994-08-08 12:30:22 +000043Perform Huffman table optimization. Takes longer, but results in
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000044smaller compressed image. Compress only.
45
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000046\item[\code{'smooth' }]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000047Perform inter-block smoothing on uncompressed image. Only useful for
48low-quality images. Decompress only.
49\end{description}
50\end{funcdesc}
51
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000052Compress and uncompress raise the error \code{jpeg.error} in case of errors.