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