blob: d0c1604bcf1d3794849bc6bdf59022aa0a9a73bc [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
7Indepent JPEG Group software refer to the JPEG standard or the
8documentation 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
15pixel. The data is in sgi gl order, so the first pixel is in the
16lower-left corner. This means that lrectread return data can
17immedeately be passed to compress. Currently only 1 byte and 4 byte
18pixels are allowed, the former being treaded as greyscale and the
19latter 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'}]
42Perform huffman table optimization. Takes longer, but results in
43smaller 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.