blob: 1c0124174e053194752bedb0c81c3e054d9212ad [file] [log] [blame]
Fred Drakefc576191998-04-04 07:15:02 +00001\section{Built-in Module \module{imageop}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{builtin}{imageop}
3
4\modulesynopsis{Manipulate raw image data.}
5
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006
Fred Drakefc576191998-04-04 07:15:02 +00007The \module{imageop} module contains some useful operations on images.
8It operates on images consisting of 8 or 32 bit pixels stored in
9Python strings. This is the same format as used by
10\function{gl.lrectwrite()} and the \module{imgfile} module.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000011
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 unknown number of bits
16per pixel, etc.
17\end{excdesc}
18
19
Fred Drakecce10901998-03-17 06:33:25 +000020\begin{funcdesc}{crop}{image, psize, width, height, x0, y0, x1, y1}
Guido van Rossum470be141995-03-17 16:07:09 +000021Return the selected part of \var{image}, which should by
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000022\var{width} by \var{height} in size and consist of pixels of
Guido van Rossum470be141995-03-17 16:07:09 +000023\var{psize} bytes. \var{x0}, \var{y0}, \var{x1} and \var{y1} are like
Fred Drakefc576191998-04-04 07:15:02 +000024the \function{gl.lrectread()} parameters, i.e.\ the boundary is
25included in the new image. The new boundaries need not be inside the
26picture. Pixels that fall outside the old image will have their value
27set to zero. If \var{x0} is bigger than \var{x1} the new image is
28mirrored. The same holds for the y coordinates.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029\end{funcdesc}
30
Fred Drakecce10901998-03-17 06:33:25 +000031\begin{funcdesc}{scale}{image, psize, width, height, newwidth, newheight}
Guido van Rossum470be141995-03-17 16:07:09 +000032Return \var{image} scaled to size \var{newwidth} by \var{newheight}.
33No interpolation is done, scaling is done by simple-minded pixel
34duplication or removal. Therefore, computer-generated images or
35dithered images will not look nice after scaling.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000036\end{funcdesc}
37
Fred Drakecce10901998-03-17 06:33:25 +000038\begin{funcdesc}{tovideo}{image, psize, width, height}
Guido van Rossum470be141995-03-17 16:07:09 +000039Run a vertical low-pass filter over an image. It does so by computing
40each destination pixel as the average of two vertically-aligned source
41pixels. The main use of this routine is to forestall excessive
42flicker if the image is displayed on a video device that uses
43interlacing, hence the name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000044\end{funcdesc}
45
Fred Drakecce10901998-03-17 06:33:25 +000046\begin{funcdesc}{grey2mono}{image, width, height, threshold}
Guido van Rossum470be141995-03-17 16:07:09 +000047Convert a 8-bit deep greyscale image to a 1-bit deep image by
48tresholding all the pixels. The resulting image is tightly packed and
Fred Drakefc576191998-04-04 07:15:02 +000049is probably only useful as an argument to \function{mono2grey()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000050\end{funcdesc}
51
Fred Drakecce10901998-03-17 06:33:25 +000052\begin{funcdesc}{dither2mono}{image, width, height}
Guido van Rossum470be141995-03-17 16:07:09 +000053Convert an 8-bit greyscale image to a 1-bit monochrome image using a
54(simple-minded) dithering algorithm.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000055\end{funcdesc}
56
Fred Drakecce10901998-03-17 06:33:25 +000057\begin{funcdesc}{mono2grey}{image, width, height, p0, p1}
Guido van Rossum470be141995-03-17 16:07:09 +000058Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
59All pixels that are zero-valued on input get value \var{p0} on output
60and all one-value input pixels get value \var{p1} on output. To
61convert a monochrome black-and-white image to greyscale pass the
62values \code{0} and \code{255} respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000063\end{funcdesc}
64
Fred Drakecce10901998-03-17 06:33:25 +000065\begin{funcdesc}{grey2grey4}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000066Convert an 8-bit greyscale image to a 4-bit greyscale image without
67dithering.
68\end{funcdesc}
69
Fred Drakecce10901998-03-17 06:33:25 +000070\begin{funcdesc}{grey2grey2}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000071Convert an 8-bit greyscale image to a 2-bit greyscale image without
72dithering.
73\end{funcdesc}
74
Fred Drakecce10901998-03-17 06:33:25 +000075\begin{funcdesc}{dither2grey2}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000076Convert an 8-bit greyscale image to a 2-bit greyscale image with
Fred Drakefc576191998-04-04 07:15:02 +000077dithering. As for \function{dither2mono()}, the dithering algorithm
78is currently very simple.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000079\end{funcdesc}
80
Fred Drakecce10901998-03-17 06:33:25 +000081\begin{funcdesc}{grey42grey}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000082Convert a 4-bit greyscale image to an 8-bit greyscale image.
83\end{funcdesc}
84
Fred Drakecce10901998-03-17 06:33:25 +000085\begin{funcdesc}{grey22grey}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000086Convert a 2-bit greyscale image to an 8-bit greyscale image.
87\end{funcdesc}