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