blob: 76e70af7147a0315109caa02b6a05455e71c188e [file] [log] [blame]
Fred Drakefc576191998-04-04 07:15:02 +00001\section{Built-in Module \module{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
Fred Drakefc576191998-04-04 07:15:02 +00006decompressor written by the Independent JPEG Group%
7\index{Independent JPEG Group}%
8. JPEG is a (draft?)
9standard for compressing pictures. For details on JPEG or the
Guido van Rossum16d6e711994-08-08 12:30:22 +000010Independent JPEG Group software refer to the JPEG standard or the
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000011documentation provided with the software.
12
Fred Drake434493b1998-03-14 19:47:23 +000013The \module{jpeg} module defines an exception and some functions.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000014
Fred Drake434493b1998-03-14 19:47:23 +000015\begin{excdesc}{error}
16Exception raised by \function{compress()} and \function{decompress()}
17in case of errors.
18\end{excdesc}
19
20\begin{funcdesc}{compress}{data, w, h, b}
21Treat data as a pixmap of width \var{w} and height \var{h}, with
22\var{b} bytes per pixel. The data is in SGI GL order, so the first
Fred Drakefc576191998-04-04 07:15:02 +000023pixel is in the lower-left corner. This means that \function{gl.lrectread()}
Fred Drake434493b1998-03-14 19:47:23 +000024return data can immediately be passed to \function{compress()}.
25Currently only 1 byte and 4 byte pixels are allowed, the former being
26treated as greyscale and the latter as RGB color.
27\function{compress()} returns a string that contains the compressed
Fred Drakefc576191998-04-04 07:15:02 +000028picture, in JFIF\index{JFIF} format.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029\end{funcdesc}
30
31\begin{funcdesc}{decompress}{data}
Fred Drakefc576191998-04-04 07:15:02 +000032Data is a string containing a picture in JFIF\index{JFIF} format. It
33returns a tuple \code{(\var{data}, \var{width}, \var{height},
Fred Drake434493b1998-03-14 19:47:23 +000034\var{bytesperpixel})}. Again, the data is suitable to pass to
Fred Drakefc576191998-04-04 07:15:02 +000035\function{gl.lrectwrite()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000036\end{funcdesc}
37
Fred Drake434493b1998-03-14 19:47:23 +000038\begin{funcdesc}{setoption}{name, value}
39Set various options. Subsequent \function{compress()} and
40\function{decompress()} calls will use these options. The following
41options are available:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000042
Fred Drakeee601911998-04-11 20:53:03 +000043\begin{tableii}{l|p{3in}}{code}{Option}{Effect}
Fred Drake434493b1998-03-14 19:47:23 +000044 \lineii{'forcegray'}{%
45 Force output to be grayscale, even if input is RGB.}
46 \lineii{'quality'}{%
47 Set the quality of the compressed image to a value between
Fred Drakefab2f341998-04-11 18:46:56 +000048 \code{0} and \code{100} (default is \code{75}). This only affects
49 compression.}
Fred Drake434493b1998-03-14 19:47:23 +000050 \lineii{'optimize'}{%
51 Perform Huffman table optimization. Takes longer, but results in
Fred Drakefab2f341998-04-11 18:46:56 +000052 smaller compressed image. This only affects compression.}
Fred Drake434493b1998-03-14 19:47:23 +000053 \lineii{'smooth'}{%
54 Perform inter-block smoothing on uncompressed image. Only useful
Fred Drakefab2f341998-04-11 18:46:56 +000055 for low-quality images. This only affects decompression.}
Fred Drake434493b1998-03-14 19:47:23 +000056\end{tableii}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000057\end{funcdesc}