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