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