blob: b5c14a4bf24622363bfd2d04ee08b49bc158e2be [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in Module \sectcode{jpeg}}
2\bimodindex{jpeg}
3
Guido van Rossum6bb1adc1995-03-13 10:03:32 +00004The module \code{jpeg} provides access to the jpeg compressor and
5decompressor written by the Independent JPEG Group. JPEG is a (draft?)\
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006standard for compressing pictures. For details on jpeg or the
Guido van Rossum16d6e711994-08-08 12:30:22 +00007Independent JPEG Group software refer to the JPEG standard or the
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008documentation provided with the software.
9
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000010The \code{jpeg} module defines these functions:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000011
12\renewcommand{\indexsubitem}{(in module jpeg)}
13\begin{funcdesc}{compress}{data\, w\, h\, b}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000014Treat 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 +000015pixel. The data is in SGI GL order, so the first pixel is in the
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000016lower-left corner. This means that \code{lrectread} return data can
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000017immedeately be passed to compress. Currently only 1 byte and 4 byte
Guido van Rossum16d6e711994-08-08 12:30:22 +000018pixels are allowed, the former being treated as greyscale and the
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000019latter as RGB color. Compress returns a string that contains the
20compressed picture, in JFIF format.
21\end{funcdesc}
22
23\begin{funcdesc}{decompress}{data}
24Data is a string containing a picture in JFIF format. It returns a
25tuple
26\code{(\var{data}, \var{width}, \var{height}, \var{bytesperpixel})}.
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000027Again, the data is suitable to pass to \code{lrectwrite}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000028\end{funcdesc}
29
30\begin{funcdesc}{setoption}{name\, value}
31Set various options. Subsequent compress and decompress calls
32will use these options. The following options are available:
33\begin{description}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000034\item[\code{'forcegray' }]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000035Force output to be grayscale, even if input is RGB.
36
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000037\item[\code{'quality' }]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000038Set the quality of the compressed image to a
39value between \code{0} and \code{100} (default is \code{75}). Compress only.
40
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000041\item[\code{'optimize' }]
Guido van Rossum16d6e711994-08-08 12:30:22 +000042Perform Huffman table optimization. Takes longer, but results in
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000043smaller compressed image. Compress only.
44
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000045\item[\code{'smooth' }]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000046Perform inter-block smoothing on uncompressed image. Only useful for
47low-quality images. Decompress only.
48\end{description}
49\end{funcdesc}
50
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000051Compress and uncompress raise the error \code{jpeg.error} in case of errors.