blob: e74fe9e74387a97081524c2d8f970cf6960c4b0d [file] [log] [blame]
Fred Drake7932a6b1998-04-03 07:09:38 +00001\section{Built-in Module \module{imgfile}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-imgfile}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003\bimodindex{imgfile}
4
Fred Drake7932a6b1998-04-03 07:09:38 +00005The \module{imgfile} module allows Python programs to access SGI imglib image
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006files (also known as \file{.rgb} files). The module is far from
7complete, but is provided anyway since the functionality that there is
8is enough in some cases. Currently, colormap files are not supported.
9
10The module defines the following variables and functions:
11
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000012\begin{excdesc}{error}
13This exception is raised on all errors, such as unsupported file type, etc.
14\end{excdesc}
15
16\begin{funcdesc}{getsizes}{file}
17This 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
20bytes per pixel. Only 3 byte RGB pixels and 1 byte greyscale pixels
21are currently supported.
22\end{funcdesc}
23
24\begin{funcdesc}{read}{file}
25This function reads and decodes the image on the specified file, and
Fred Drake7932a6b1998-04-03 07:09:38 +000026returns it as a Python string. The string has either 1 byte greyscale
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000027pixels or 4 byte RGBA pixels. The bottom left pixel is the first in
Fred Drake7932a6b1998-04-03 07:09:38 +000028the string. This format is suitable to pass to \function{gl.lrectwrite()},
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029for instance.
30\end{funcdesc}
31
Fred Drakecce10901998-03-17 06:33:25 +000032\begin{funcdesc}{readscaled}{file, x, y, filter\optional{, blur}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000033This function is identical to read but it returns an image that is
34scaled to the given \var{x} and \var{y} sizes. If the \var{filter} and
35\var{blur} parameters are omitted scaling is done by
36simply dropping or duplicating pixels, so the result will be less than
37perfect, especially for computer-generated images.
38
39Alternatively, you can specify a filter to use to smoothen the image
40after 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
43parameter specifying the blurriness of the filter. It defaults to \code{1.0}.
44
Fred Drakea38a2861998-04-11 16:57:05 +000045\function{readscaled()} makes no attempt to keep the aspect ratio
46correct, so that is the users' responsibility.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000047\end{funcdesc}
48
49\begin{funcdesc}{ttob}{flag}
50This function sets a global flag which defines whether the scan lines
51of the image are read or written from bottom to top (flag is zero,
52compatible with SGI GL) or from top to bottom(flag is one,
53compatible with X). The default is zero.
54\end{funcdesc}
55
Fred Drakecce10901998-03-17 06:33:25 +000056\begin{funcdesc}{write}{file, data, x, y, z}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000057This function writes the RGB or greyscale data in \var{data} to image
58file \var{file}. \var{x} and \var{y} give the size of the image,
59\var{z} is 1 for 1 byte greyscale images or 3 for RGB images (which are
60stored as 4 byte values of which only the lower three bytes are used).
Fred Drakea38a2861998-04-11 16:57:05 +000061These are the formats returned by \function{gl.lrectread()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000062\end{funcdesc}