Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 1 | \section{Built-in Module \sectcode{jpeg}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-jpeg} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 3 | \bimodindex{jpeg} |
| 4 | |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 5 | The module \module{jpeg} provides access to the jpeg compressor and |
| 6 | decompressor written by the Independent JPEG Group. JPEG is a (draft?) |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 7 | standard for compressing pictures. For details on jpeg or the |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 8 | Independent JPEG Group software refer to the JPEG standard or the |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 9 | documentation provided with the software. |
| 10 | |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 11 | The \module{jpeg} module defines an exception and some functions. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 12 | |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 13 | \begin{excdesc}{error} |
| 14 | Exception raised by \function{compress()} and \function{decompress()} |
| 15 | in case of errors. |
| 16 | \end{excdesc} |
| 17 | |
| 18 | \begin{funcdesc}{compress}{data, w, h, b} |
| 19 | Treat data as a pixmap of width \var{w} and height \var{h}, with |
| 20 | \var{b} bytes per pixel. The data is in SGI GL order, so the first |
| 21 | pixel is in the lower-left corner. This means that \code{gl.lrectread} |
| 22 | return data can immediately be passed to \function{compress()}. |
| 23 | Currently only 1 byte and 4 byte pixels are allowed, the former being |
| 24 | treated as greyscale and the latter as RGB color. |
| 25 | \function{compress()} returns a string that contains the compressed |
| 26 | picture, in JFIF format. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 27 | \end{funcdesc} |
| 28 | |
| 29 | \begin{funcdesc}{decompress}{data} |
| 30 | Data is a string containing a picture in JFIF format. It returns a |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 31 | tuple \code{(\var{data}, \var{width}, \var{height}, |
| 32 | \var{bytesperpixel})}. Again, the data is suitable to pass to |
| 33 | \code{gl.lrectwrite}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 34 | \end{funcdesc} |
| 35 | |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 36 | \begin{funcdesc}{setoption}{name, value} |
| 37 | Set various options. Subsequent \function{compress()} and |
| 38 | \function{decompress()} calls will use these options. The following |
| 39 | options are available: |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 40 | |
Fred Drake | 434493b | 1998-03-14 19:47:23 +0000 | [diff] [blame] | 41 | \begin{tableii}{|l|l|}{code}{Option}{Effect} |
| 42 | \lineii{'forcegray'}{% |
| 43 | Force output to be grayscale, even if input is RGB.} |
| 44 | \lineii{'quality'}{% |
| 45 | Set the quality of the compressed image to a value between |
| 46 | \code{0} and \code{100} (default is \code{75}). \\ |
| 47 | &This only affects compression.} |
| 48 | \lineii{'optimize'}{% |
| 49 | Perform Huffman table optimization. Takes longer, but results in |
| 50 | smaller compressed \\ |
| 51 | &image. This only affects compression.} |
| 52 | \lineii{'smooth'}{% |
| 53 | Perform inter-block smoothing on uncompressed image. Only useful |
| 54 | for low-quality \\ |
| 55 | &images. This only affects decompression.} |
| 56 | \end{tableii} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 57 | \end{funcdesc} |