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