blob: c21be4848ea4ac246d5d36c37878249bf8704d12 [file] [log] [blame]
Fred Drakefc576191998-04-04 07:15:02 +00001\section{Built-in Module \module{imageop}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-imageop}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003\bimodindex{imageop}
4
Fred Drakefc576191998-04-04 07:15:02 +00005The \module{imageop} module contains some useful operations on images.
6It operates on images consisting of 8 or 32 bit pixels stored in
7Python strings. This is the same format as used by
8\function{gl.lrectwrite()} and the \module{imgfile} module.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00009
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 unknown number of bits
14per pixel, etc.
15\end{excdesc}
16
17
Fred Drakecce10901998-03-17 06:33:25 +000018\begin{funcdesc}{crop}{image, psize, width, height, x0, y0, x1, y1}
Guido van Rossum470be141995-03-17 16:07:09 +000019Return the selected part of \var{image}, which should by
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000020\var{width} by \var{height} in size and consist of pixels of
Guido van Rossum470be141995-03-17 16:07:09 +000021\var{psize} bytes. \var{x0}, \var{y0}, \var{x1} and \var{y1} are like
Fred Drakefc576191998-04-04 07:15:02 +000022the \function{gl.lrectread()} parameters, i.e.\ the boundary is
23included in the new image. The new boundaries need not be inside the
24picture. Pixels that fall outside the old image will have their value
25set to zero. If \var{x0} is bigger than \var{x1} the new image is
26mirrored. The same holds for the y coordinates.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000027\end{funcdesc}
28
Fred Drakecce10901998-03-17 06:33:25 +000029\begin{funcdesc}{scale}{image, psize, width, height, newwidth, newheight}
Guido van Rossum470be141995-03-17 16:07:09 +000030Return \var{image} scaled to size \var{newwidth} by \var{newheight}.
31No interpolation is done, scaling is done by simple-minded pixel
32duplication or removal. Therefore, computer-generated images or
33dithered images will not look nice after scaling.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000034\end{funcdesc}
35
Fred Drakecce10901998-03-17 06:33:25 +000036\begin{funcdesc}{tovideo}{image, psize, width, height}
Guido van Rossum470be141995-03-17 16:07:09 +000037Run a vertical low-pass filter over an image. It does so by computing
38each destination pixel as the average of two vertically-aligned source
39pixels. The main use of this routine is to forestall excessive
40flicker if the image is displayed on a video device that uses
41interlacing, hence the name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000042\end{funcdesc}
43
Fred Drakecce10901998-03-17 06:33:25 +000044\begin{funcdesc}{grey2mono}{image, width, height, threshold}
Guido van Rossum470be141995-03-17 16:07:09 +000045Convert a 8-bit deep greyscale image to a 1-bit deep image by
46tresholding all the pixels. The resulting image is tightly packed and
Fred Drakefc576191998-04-04 07:15:02 +000047is probably only useful as an argument to \function{mono2grey()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000048\end{funcdesc}
49
Fred Drakecce10901998-03-17 06:33:25 +000050\begin{funcdesc}{dither2mono}{image, width, height}
Guido van Rossum470be141995-03-17 16:07:09 +000051Convert an 8-bit greyscale image to a 1-bit monochrome image using a
52(simple-minded) dithering algorithm.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000053\end{funcdesc}
54
Fred Drakecce10901998-03-17 06:33:25 +000055\begin{funcdesc}{mono2grey}{image, width, height, p0, p1}
Guido van Rossum470be141995-03-17 16:07:09 +000056Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
57All pixels that are zero-valued on input get value \var{p0} on output
58and all one-value input pixels get value \var{p1} on output. To
59convert a monochrome black-and-white image to greyscale pass the
60values \code{0} and \code{255} respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000061\end{funcdesc}
62
Fred Drakecce10901998-03-17 06:33:25 +000063\begin{funcdesc}{grey2grey4}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000064Convert an 8-bit greyscale image to a 4-bit greyscale image without
65dithering.
66\end{funcdesc}
67
Fred Drakecce10901998-03-17 06:33:25 +000068\begin{funcdesc}{grey2grey2}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000069Convert an 8-bit greyscale image to a 2-bit greyscale image without
70dithering.
71\end{funcdesc}
72
Fred Drakecce10901998-03-17 06:33:25 +000073\begin{funcdesc}{dither2grey2}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000074Convert an 8-bit greyscale image to a 2-bit greyscale image with
Fred Drakefc576191998-04-04 07:15:02 +000075dithering. As for \function{dither2mono()}, the dithering algorithm
76is currently very simple.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000077\end{funcdesc}
78
Fred Drakecce10901998-03-17 06:33:25 +000079\begin{funcdesc}{grey42grey}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000080Convert a 4-bit greyscale image to an 8-bit greyscale image.
81\end{funcdesc}
82
Fred Drakecce10901998-03-17 06:33:25 +000083\begin{funcdesc}{grey22grey}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000084Convert a 2-bit greyscale image to an 8-bit greyscale image.
85\end{funcdesc}