blob: 96afc9bb0797ed71c8885ba0c04bc18943fd1542 [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Built-in Module \sectcode{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
5The imgfile module allows python programs to access SGI imglib image
6files (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
12\renewcommand{\indexsubitem}{(in module imgfile)}
13\begin{excdesc}{error}
14This exception is raised on all errors, such as unsupported file type, etc.
15\end{excdesc}
16
17\begin{funcdesc}{getsizes}{file}
18This function returns a tuple \code{(\var{x}, \var{y}, \var{z})} where
19\var{x} and \var{y} are the size of the image in pixels and
20\var{z} is the number of
21bytes per pixel. Only 3 byte RGB pixels and 1 byte greyscale pixels
22are currently supported.
23\end{funcdesc}
24
25\begin{funcdesc}{read}{file}
26This function reads and decodes the image on the specified file, and
27returns it as a python string. The string has either 1 byte greyscale
28pixels or 4 byte RGBA pixels. The bottom left pixel is the first in
29the string. This format is suitable to pass to \code{gl.lrectwrite},
30for instance.
31\end{funcdesc}
32
Guido van Rossum16d6e711994-08-08 12:30:22 +000033\begin{funcdesc}{readscaled}{file\, x\, y\, filter\optional{\, blur}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000034This function is identical to read but it returns an image that is
35scaled to the given \var{x} and \var{y} sizes. If the \var{filter} and
36\var{blur} parameters are omitted scaling is done by
37simply dropping or duplicating pixels, so the result will be less than
38perfect, especially for computer-generated images.
39
40Alternatively, you can specify a filter to use to smoothen the image
41after scaling. The filter forms supported are \code{'impulse'},
42\code{'box'}, \code{'triangle'}, \code{'quadratic'} and
43\code{'gaussian'}. If a filter is specified \var{blur} is an optional
44parameter specifying the blurriness of the filter. It defaults to \code{1.0}.
45
Guido van Rossum16d6e711994-08-08 12:30:22 +000046\code{readscaled} makes no
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000047attempt to keep the aspect ratio correct, so that is the users'
48responsibility.
49\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
58\begin{funcdesc}{write}{file\, data\, x\, y\, z}
59This 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).
63These are the formats returned by \code{gl.lrectread}.
64\end{funcdesc}