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