blob: a4e931fc04f60295b7fbb3c03de2ce9e5da6acaf [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in Module \sectcode{jpeg}}
2\bimodindex{jpeg}
3
4The module jpeg provides access to the jpeg compressor and
5decompressor written by the Independent JPEG Group. JPEG is a (draft?)
6standard 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
10The jpeg module defines these functions:
11
12\renewcommand{\indexsubitem}{(in module jpeg)}
13\begin{funcdesc}{compress}{data\, w\, h\, b}
14Treat data as a pixmap of width w and height h, with 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 Rossum5fdeeea1994-01-02 01:22:07 +000016lower-left corner. This means that lrectread return data can
17immedeately 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})}.
27Again, the data is suitable to pass to lrectwrite.
28\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}
34\item[\code{'forcegray'}]
35Force output to be grayscale, even if input is RGB.
36
37\item[\code{'quality'}]
38Set the quality of the compressed image to a
39value between \code{0} and \code{100} (default is \code{75}). Compress only.
40
41\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
45\item[\code{'smooth'}]
46Perform inter-block smoothing on uncompressed image. Only useful for
47low-quality images. Decompress only.
48\end{description}
49\end{funcdesc}
50
51Compress and uncompress raise the error jpeg.error in case of errors.