blob: 4481e614c1cb6bfaaab15aaea3c6ecded5522be4 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in module \sectcode{imageop}}
2\bimodindex{imageop}
3
4The imageop module contains some useful operations on images.
5It operates on images consisting of 8 or 32 bit pixels
6stored in python strings. This is the same format as used
7by \code{gl.lrectwrite} and the \code{imgfile} module.
8
9The module defines the following variables and functions:
10
11\renewcommand{\indexsubitem}{(in module imageop)}
12
13\begin{excdesc}{error}
14This exception is raised on all errors, such as unknown number of bits
15per pixel, etc.
16\end{excdesc}
17
18
19\begin{funcdesc}{crop}{image\, psize\, width\, height\, x0\, y0\, x1\, y1}
20This function takes the image in \code{image}, which should by
21\code{width} by \code{height} in size and consist of pixels of
Guido van Rossum16d6e711994-08-08 12:30:22 +000022\code{psize} bytes, and returns the selected part of that image. \code{x0},
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000023\code{y0}, \code{x1} and \code{y1} are like the \code{lrectread}
24parameters, i.e. the boundary is included in the new image.
25The new boundaries need not be inside the picture. Pixels that fall
26outside the old image will have their value set to zero.
27If \code{x0} is bigger than \code{x1} the new image is mirrored. The
28same holds for the y coordinates.
29\end{funcdesc}
30
31\begin{funcdesc}{scale}{image\, psize\, width\, height\, newwidth\, newheight}
32This function returns a \code{image} scaled to size \code{newwidth} by
33\code{newheight}. No interpolation is done, scaling is done by
34simple-minded pixel duplication or removal. Therefore, computer-generated
35images or dithered images will not look nice after scaling.
36\end{funcdesc}
37
38\begin{funcdesc}{tovideo}{image\, psize\, width\, height}
39This function runs a vertical low-pass filter over an image. It does
40so by computing each destination pixel as the average of two
41vertically-aligned source pixels. The main use of this routine is to
42forestall excessive flicker if the image is displayed on a video
43device that uses interlacing, hence the name.
44\end{funcdesc}
45
46\begin{funcdesc}{grey2mono}{image\, width\, height\, threshold}
47This function converts a 8-bit deep greyscale image to a 1-bit deep
48image by tresholding all the pixels. The resulting image is tightly
49packed and is probably only useful as an argument to \code{mono2grey}.
50\end{funcdesc}
51
52\begin{funcdesc}{dither2mono}{image\, width\, height}
53This function also converts an 8-bit greyscale image to a 1-bit
54monochrome image but it uses a (simple-minded) dithering algorithm.
55\end{funcdesc}
56
57\begin{funcdesc}{mono2grey}{image\, width\, height\, p0\, p1}
58This function converts a 1-bit monochrome image to an 8 bit greyscale
59or color image. All pixels that are zero-valued on input get value
60\code{p0} on output and all one-value input pixels get value \code{p1}
61on output. To convert a monochrome black-and-white image to greyscale
62pass the values \code{0} and \code{255} respectively.
63\end{funcdesc}
64
65\begin{funcdesc}{grey2grey4}{image\, width\, height}
66Convert an 8-bit greyscale image to a 4-bit greyscale image without
67dithering.
68\end{funcdesc}
69
70\begin{funcdesc}{grey2grey2}{image\, width\, height}
71Convert an 8-bit greyscale image to a 2-bit greyscale image without
72dithering.
73\end{funcdesc}
74
75\begin{funcdesc}{dither2grey2}{image\, width\, height}
76Convert an 8-bit greyscale image to a 2-bit greyscale image with
77dithering. As for \code{dither2mono}, the dithering algorithm is
78currently very simple.
79\end{funcdesc}
80
81\begin{funcdesc}{grey42grey}{image\, width\, height}
82Convert a 4-bit greyscale image to an 8-bit greyscale image.
83\end{funcdesc}
84
85\begin{funcdesc}{grey22grey}{image\, width\, height}
86Convert a 2-bit greyscale image to an 8-bit greyscale image.
87\end{funcdesc}