Fred Drake | 7932a6b | 1998-04-03 07:09:38 +0000 | [diff] [blame] | 1 | \section{Built-in Module \module{imgfile}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-imgfile} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 3 | \bimodindex{imgfile} |
| 4 | |
Fred Drake | 7932a6b | 1998-04-03 07:09:38 +0000 | [diff] [blame] | 5 | The \module{imgfile} module allows Python programs to access SGI imglib image |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 6 | files (also known as \file{.rgb} files). The module is far from |
| 7 | complete, but is provided anyway since the functionality that there is |
| 8 | is enough in some cases. Currently, colormap files are not supported. |
| 9 | |
| 10 | The module defines the following variables and functions: |
| 11 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 12 | \begin{excdesc}{error} |
| 13 | This exception is raised on all errors, such as unsupported file type, etc. |
| 14 | \end{excdesc} |
| 15 | |
| 16 | \begin{funcdesc}{getsizes}{file} |
| 17 | This function returns a tuple \code{(\var{x}, \var{y}, \var{z})} where |
| 18 | \var{x} and \var{y} are the size of the image in pixels and |
| 19 | \var{z} is the number of |
| 20 | bytes per pixel. Only 3 byte RGB pixels and 1 byte greyscale pixels |
| 21 | are currently supported. |
| 22 | \end{funcdesc} |
| 23 | |
| 24 | \begin{funcdesc}{read}{file} |
| 25 | This function reads and decodes the image on the specified file, and |
Fred Drake | 7932a6b | 1998-04-03 07:09:38 +0000 | [diff] [blame] | 26 | returns it as a Python string. The string has either 1 byte greyscale |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 27 | pixels or 4 byte RGBA pixels. The bottom left pixel is the first in |
Fred Drake | 7932a6b | 1998-04-03 07:09:38 +0000 | [diff] [blame] | 28 | the string. This format is suitable to pass to \function{gl.lrectwrite()}, |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 29 | for instance. |
| 30 | \end{funcdesc} |
| 31 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 32 | \begin{funcdesc}{readscaled}{file, x, y, filter\optional{, blur}} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 33 | This function is identical to read but it returns an image that is |
| 34 | scaled to the given \var{x} and \var{y} sizes. If the \var{filter} and |
| 35 | \var{blur} parameters are omitted scaling is done by |
| 36 | simply dropping or duplicating pixels, so the result will be less than |
| 37 | perfect, especially for computer-generated images. |
| 38 | |
| 39 | Alternatively, you can specify a filter to use to smoothen the image |
| 40 | after scaling. The filter forms supported are \code{'impulse'}, |
| 41 | \code{'box'}, \code{'triangle'}, \code{'quadratic'} and |
| 42 | \code{'gaussian'}. If a filter is specified \var{blur} is an optional |
| 43 | parameter specifying the blurriness of the filter. It defaults to \code{1.0}. |
| 44 | |
Guido van Rossum | 16d6e71 | 1994-08-08 12:30:22 +0000 | [diff] [blame] | 45 | \code{readscaled} makes no |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 46 | attempt to keep the aspect ratio correct, so that is the users' |
| 47 | responsibility. |
| 48 | \end{funcdesc} |
| 49 | |
| 50 | \begin{funcdesc}{ttob}{flag} |
| 51 | This function sets a global flag which defines whether the scan lines |
| 52 | of the image are read or written from bottom to top (flag is zero, |
| 53 | compatible with SGI GL) or from top to bottom(flag is one, |
| 54 | compatible with X). The default is zero. |
| 55 | \end{funcdesc} |
| 56 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 57 | \begin{funcdesc}{write}{file, data, x, y, z} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 58 | This function writes the RGB or greyscale data in \var{data} to image |
| 59 | file \var{file}. \var{x} and \var{y} give the size of the image, |
| 60 | \var{z} is 1 for 1 byte greyscale images or 3 for RGB images (which are |
| 61 | stored as 4 byte values of which only the lower three bytes are used). |
| 62 | These are the formats returned by \code{gl.lrectread}. |
| 63 | \end{funcdesc} |