libjpeg.tex 3.14 KB
Newer Older
Fred Drake's avatar
Fred Drake committed
1
\section{\module{jpeg} ---
Fred Drake's avatar
Fred Drake committed
2
         Read and write JPEG files}
3

Fred Drake's avatar
Fred Drake committed
4
\declaremodule{builtin}{jpeg}
5
  \platform{IRIX}
6 7
\modulesynopsis{Read and write image files in compressed JPEG format.}

8

Fred Drake's avatar
Fred Drake committed
9
The module \module{jpeg} provides access to the jpeg compressor and
10 11 12 13 14 15 16 17 18 19 20 21
decompressor written by the Independent JPEG Group
\index{Independent JPEG Group}(IJG). JPEG is a standard for
compressing pictures; it is defined in ISO 10918.  For details on JPEG
or the Independent JPEG Group software refer to the JPEG standard or
the documentation provided with the software.

A portable interface to JPEG image files is available with the Python
Imaging Library (PIL) by Fredrik Lundh.  Information on PIL is
available at \url{http://www.pythonware.com/products/pil/}.
\index{Python Imaging Library}
\index{PIL (the Python Imaging Library)}
\index{Lundh, Fredrik}
22

Fred Drake's avatar
Fred Drake committed
23 24 25 26 27 28 29 30 31 32
The \module{jpeg} module defines an exception and some functions.

\begin{excdesc}{error}
Exception raised by \function{compress()} and \function{decompress()}
in case of errors.
\end{excdesc}

\begin{funcdesc}{compress}{data, w, h, b}
Treat data as a pixmap of width \var{w} and height \var{h}, with
\var{b} bytes per pixel.  The data is in SGI GL order, so the first
33
pixel is in the lower-left corner. This means that \function{gl.lrectread()}
Fred Drake's avatar
Fred Drake committed
34 35 36 37
return data can immediately be passed to \function{compress()}.
Currently only 1 byte and 4 byte pixels are allowed, the former being
treated as greyscale and the latter as RGB color.
\function{compress()} returns a string that contains the compressed
38
picture, in JFIF\index{JFIF} format.
39 40 41
\end{funcdesc}

\begin{funcdesc}{decompress}{data}
42 43
Data is a string containing a picture in JFIF\index{JFIF} format. It
returns a tuple \code{(\var{data}, \var{width}, \var{height},
Fred Drake's avatar
Fred Drake committed
44
\var{bytesperpixel})}.  Again, the data is suitable to pass to
45
\function{gl.lrectwrite()}.
46 47
\end{funcdesc}

Fred Drake's avatar
Fred Drake committed
48 49 50 51 52
\begin{funcdesc}{setoption}{name, value}
Set various options.  Subsequent \function{compress()} and
\function{decompress()} calls will use these options.  The following
options are available:

Fred Drake's avatar
Fred Drake committed
53
\begin{tableii}{l|p{3in}}{code}{Option}{Effect}
Fred Drake's avatar
Fred Drake committed
54 55 56 57
  \lineii{'forcegray'}{%
    Force output to be grayscale, even if input is RGB.}
  \lineii{'quality'}{%
    Set the quality of the compressed image to a value between
58 59
    \code{0} and \code{100} (default is \code{75}).  This only affects
    compression.}
Fred Drake's avatar
Fred Drake committed
60 61
  \lineii{'optimize'}{%
    Perform Huffman table optimization.  Takes longer, but results in
62
    smaller compressed image.  This only affects compression.}
Fred Drake's avatar
Fred Drake committed
63 64
  \lineii{'smooth'}{%
    Perform inter-block smoothing on uncompressed image.  Only useful
65
    for low-quality images.  This only affects decompression.}
Fred Drake's avatar
Fred Drake committed
66
\end{tableii}
67
\end{funcdesc}
68 69 70


\begin{seealso}
71 72 73
  \seetitle{JPEG Still Image Data Compression Standard}{The 
            canonical reference for the JPEG image format, by
            Pennebaker and Mitchell.}
74

75 76 77 78 79
  \seetitle[http://www.w3.org/Graphics/JPEG/itu-t81.pdf]{Information
            Technology - Digital Compression and Coding of
            Continuous-tone Still Images - Requirements and
            Guidelines}{The ISO standard for JPEG is also published as
            ITU T.81.  This is available online in PDF form.}
80
\end{seealso}