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