blob: 745fe32560bb58995d441d46de10b9e924aaadd3 [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
Fred Drake434493b1998-03-14 19:47:23 +00005The module \module{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
Fred Drake434493b1998-03-14 19:47:23 +000011The \module{jpeg} module defines an exception and some functions.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000012
Fred Drake434493b1998-03-14 19:47:23 +000013\begin{excdesc}{error}
14Exception raised by \function{compress()} and \function{decompress()}
15in case of errors.
16\end{excdesc}
17
18\begin{funcdesc}{compress}{data, w, h, b}
19Treat data as a pixmap of width \var{w} and height \var{h}, with
20\var{b} bytes per pixel. The data is in SGI GL order, so the first
21pixel is in the lower-left corner. This means that \code{gl.lrectread}
22return data can immediately be passed to \function{compress()}.
23Currently only 1 byte and 4 byte pixels are allowed, the former being
24treated as greyscale and the latter as RGB color.
25\function{compress()} returns a string that contains the compressed
26picture, in JFIF format.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000027\end{funcdesc}
28
29\begin{funcdesc}{decompress}{data}
30Data is a string containing a picture in JFIF format. It returns a
Fred Drake434493b1998-03-14 19:47:23 +000031tuple \code{(\var{data}, \var{width}, \var{height},
32\var{bytesperpixel})}. Again, the data is suitable to pass to
33\code{gl.lrectwrite}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000034\end{funcdesc}
35
Fred Drake434493b1998-03-14 19:47:23 +000036\begin{funcdesc}{setoption}{name, value}
37Set various options. Subsequent \function{compress()} and
38\function{decompress()} calls will use these options. The following
39options are available:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000040
Fred Drake434493b1998-03-14 19:47:23 +000041\begin{tableii}{|l|l|}{code}{Option}{Effect}
42 \lineii{'forcegray'}{%
43 Force output to be grayscale, even if input is RGB.}
44 \lineii{'quality'}{%
45 Set the quality of the compressed image to a value between
46 \code{0} and \code{100} (default is \code{75}). \\
47 &This only affects compression.}
48 \lineii{'optimize'}{%
49 Perform Huffman table optimization. Takes longer, but results in
50 smaller compressed \\
51 &image. This only affects compression.}
52 \lineii{'smooth'}{%
53 Perform inter-block smoothing on uncompressed image. Only useful
54 for low-quality \\
55 &images. This only affects decompression.}
56\end{tableii}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000057\end{funcdesc}