blob: e716695a7d611d0a1d9fd0f1cf1862de08f009d5 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{jpeg} ---
Fred Drake67d229e1999-02-20 04:51:16 +00002 Read and write JPEG files}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drake67d229e1999-02-20 04:51:16 +00004\declaremodule{builtin}{jpeg}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Read and write image files in compressed JPEG format.}
6
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007
Fred Drake434493b1998-03-14 19:47:23 +00008The module \module{jpeg} provides access to the jpeg compressor and
Fred Drakefc576191998-04-04 07:15:02 +00009decompressor written by the Independent JPEG Group%
10\index{Independent JPEG Group}%
11. JPEG is a (draft?)
12standard for compressing pictures. For details on JPEG or the
Guido van Rossum16d6e711994-08-08 12:30:22 +000013Independent JPEG Group software refer to the JPEG standard or the
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000014documentation provided with the software.
15
Fred Drake434493b1998-03-14 19:47:23 +000016The \module{jpeg} module defines an exception and some functions.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000017
Fred Drake434493b1998-03-14 19:47:23 +000018\begin{excdesc}{error}
19Exception raised by \function{compress()} and \function{decompress()}
20in case of errors.
21\end{excdesc}
22
23\begin{funcdesc}{compress}{data, w, h, b}
24Treat data as a pixmap of width \var{w} and height \var{h}, with
25\var{b} bytes per pixel. The data is in SGI GL order, so the first
Fred Drakefc576191998-04-04 07:15:02 +000026pixel is in the lower-left corner. This means that \function{gl.lrectread()}
Fred Drake434493b1998-03-14 19:47:23 +000027return data can immediately be passed to \function{compress()}.
28Currently only 1 byte and 4 byte pixels are allowed, the former being
29treated as greyscale and the latter as RGB color.
30\function{compress()} returns a string that contains the compressed
Fred Drakefc576191998-04-04 07:15:02 +000031picture, in JFIF\index{JFIF} format.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000032\end{funcdesc}
33
34\begin{funcdesc}{decompress}{data}
Fred Drakefc576191998-04-04 07:15:02 +000035Data is a string containing a picture in JFIF\index{JFIF} format. It
36returns a tuple \code{(\var{data}, \var{width}, \var{height},
Fred Drake434493b1998-03-14 19:47:23 +000037\var{bytesperpixel})}. Again, the data is suitable to pass to
Fred Drakefc576191998-04-04 07:15:02 +000038\function{gl.lrectwrite()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000039\end{funcdesc}
40
Fred Drake434493b1998-03-14 19:47:23 +000041\begin{funcdesc}{setoption}{name, value}
42Set various options. Subsequent \function{compress()} and
43\function{decompress()} calls will use these options. The following
44options are available:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000045
Fred Drakeee601911998-04-11 20:53:03 +000046\begin{tableii}{l|p{3in}}{code}{Option}{Effect}
Fred Drake434493b1998-03-14 19:47:23 +000047 \lineii{'forcegray'}{%
48 Force output to be grayscale, even if input is RGB.}
49 \lineii{'quality'}{%
50 Set the quality of the compressed image to a value between
Fred Drakefab2f341998-04-11 18:46:56 +000051 \code{0} and \code{100} (default is \code{75}). This only affects
52 compression.}
Fred Drake434493b1998-03-14 19:47:23 +000053 \lineii{'optimize'}{%
54 Perform Huffman table optimization. Takes longer, but results in
Fred Drakefab2f341998-04-11 18:46:56 +000055 smaller compressed image. This only affects compression.}
Fred Drake434493b1998-03-14 19:47:23 +000056 \lineii{'smooth'}{%
57 Perform inter-block smoothing on uncompressed image. Only useful
Fred Drakefab2f341998-04-11 18:46:56 +000058 for low-quality images. This only affects decompression.}
Fred Drake434493b1998-03-14 19:47:23 +000059\end{tableii}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000060\end{funcdesc}