blob: a10e06c2cc4dd1e968e9f6e693fadd686310a3bf [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 Drakef6863c11999-03-02 16:37:17 +00005 \platform{IRIX}
Fred Drakeb91e9341998-07-23 17:59:49 +00006\modulesynopsis{Read and write image files in compressed JPEG format.}
7
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008
Fred Drake434493b1998-03-14 19:47:23 +00009The module \module{jpeg} provides access to the jpeg compressor and
Fred Drakebe110c11999-03-12 15:27:35 +000010decompressor written by the Independent JPEG Group
11\index{Independent JPEG Group}(IJG). JPEG is a standard for
12compressing pictures; it is defined in ISO 10918. For details on JPEG
13or the Independent JPEG Group software refer to the JPEG standard or
14the documentation provided with the software.
15
16A portable interface to JPEG image files is available with the Python
17Imaging Library (PIL) by Fredrik Lundh. Information on PIL is
18available at \url{http://www.pythonware.com/products/pil/}.
19\index{Python Imaging Library}
20\index{PIL (the Python Imaging Library)}
21\index{Lundh, Fredrik}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000022
Fred Drake434493b1998-03-14 19:47:23 +000023The \module{jpeg} module defines an exception and some functions.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024
Fred Drake434493b1998-03-14 19:47:23 +000025\begin{excdesc}{error}
26Exception raised by \function{compress()} and \function{decompress()}
27in case of errors.
28\end{excdesc}
29
30\begin{funcdesc}{compress}{data, w, h, b}
31Treat data as a pixmap of width \var{w} and height \var{h}, with
32\var{b} bytes per pixel. The data is in SGI GL order, so the first
Fred Drakefc576191998-04-04 07:15:02 +000033pixel is in the lower-left corner. This means that \function{gl.lrectread()}
Fred Drake434493b1998-03-14 19:47:23 +000034return data can immediately be passed to \function{compress()}.
35Currently only 1 byte and 4 byte pixels are allowed, the former being
36treated as greyscale and the latter as RGB color.
37\function{compress()} returns a string that contains the compressed
Fred Drakefc576191998-04-04 07:15:02 +000038picture, in JFIF\index{JFIF} format.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000039\end{funcdesc}
40
41\begin{funcdesc}{decompress}{data}
Fred Drakefc576191998-04-04 07:15:02 +000042Data is a string containing a picture in JFIF\index{JFIF} format. It
43returns a tuple \code{(\var{data}, \var{width}, \var{height},
Fred Drake434493b1998-03-14 19:47:23 +000044\var{bytesperpixel})}. Again, the data is suitable to pass to
Fred Drakefc576191998-04-04 07:15:02 +000045\function{gl.lrectwrite()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000046\end{funcdesc}
47
Fred Drake434493b1998-03-14 19:47:23 +000048\begin{funcdesc}{setoption}{name, value}
49Set various options. Subsequent \function{compress()} and
50\function{decompress()} calls will use these options. The following
51options are available:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000052
Fred Drakeee601911998-04-11 20:53:03 +000053\begin{tableii}{l|p{3in}}{code}{Option}{Effect}
Fred Drake434493b1998-03-14 19:47:23 +000054 \lineii{'forcegray'}{%
55 Force output to be grayscale, even if input is RGB.}
56 \lineii{'quality'}{%
57 Set the quality of the compressed image to a value between
Fred Drakefab2f341998-04-11 18:46:56 +000058 \code{0} and \code{100} (default is \code{75}). This only affects
59 compression.}
Fred Drake434493b1998-03-14 19:47:23 +000060 \lineii{'optimize'}{%
61 Perform Huffman table optimization. Takes longer, but results in
Fred Drakefab2f341998-04-11 18:46:56 +000062 smaller compressed image. This only affects compression.}
Fred Drake434493b1998-03-14 19:47:23 +000063 \lineii{'smooth'}{%
64 Perform inter-block smoothing on uncompressed image. Only useful
Fred Drakefab2f341998-04-11 18:46:56 +000065 for low-quality images. This only affects decompression.}
Fred Drake434493b1998-03-14 19:47:23 +000066\end{tableii}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000067\end{funcdesc}
Fred Drakebe110c11999-03-12 15:27:35 +000068
69
70\begin{seealso}
Fred Drakee20bd192001-04-12 16:47:17 +000071 \seetitle{JPEG Still Image Data Compression Standard}{The
72 canonical reference for the JPEG image format, by
73 Pennebaker and Mitchell.}
Fred Drakebe110c11999-03-12 15:27:35 +000074
Fred Drakee20bd192001-04-12 16:47:17 +000075 \seetitle[http://www.w3.org/Graphics/JPEG/itu-t81.pdf]{Information
76 Technology - Digital Compression and Coding of
77 Continuous-tone Still Images - Requirements and
78 Guidelines}{The ISO standard for JPEG is also published as
79 ITU T.81. This is available online in PDF form.}
Fred Drakebe110c11999-03-12 15:27:35 +000080\end{seealso}