blob: 0f732bf671f48c3b93f3b867c3f6953942a122f9 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{imageop} ---
Fred Drakeffbe6871999-04-22 21:23:22 +00002 Manipulate raw image data}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakeffbe6871999-04-22 21:23:22 +00004\declaremodule{builtin}{imageop}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Manipulate raw image data.}
6
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007
Fred Drakefc576191998-04-04 07:15:02 +00008The \module{imageop} module contains some useful operations on images.
9It operates on images consisting of 8 or 32 bit pixels stored in
10Python strings. This is the same format as used by
Fred Drakeffbe6871999-04-22 21:23:22 +000011\function{gl.lrectwrite()} and the \refmodule{imgfile} module.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000012
13The module defines the following variables and functions:
14
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000015\begin{excdesc}{error}
16This exception is raised on all errors, such as unknown number of bits
17per pixel, etc.
18\end{excdesc}
19
20
Fred Drakecce10901998-03-17 06:33:25 +000021\begin{funcdesc}{crop}{image, psize, width, height, x0, y0, x1, y1}
Georg Brandld13eeb72007-01-30 20:21:35 +000022Return the selected part of \var{image}, which should be
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000023\var{width} by \var{height} in size and consist of pixels of
Guido van Rossum470be141995-03-17 16:07:09 +000024\var{psize} bytes. \var{x0}, \var{y0}, \var{x1} and \var{y1} are like
Fred Drakefc576191998-04-04 07:15:02 +000025the \function{gl.lrectread()} parameters, i.e.\ the boundary is
26included in the new image. The new boundaries need not be inside the
27picture. Pixels that fall outside the old image will have their value
28set to zero. If \var{x0} is bigger than \var{x1} the new image is
29mirrored. The same holds for the y coordinates.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000030\end{funcdesc}
31
Fred Drakecce10901998-03-17 06:33:25 +000032\begin{funcdesc}{scale}{image, psize, width, height, newwidth, newheight}
Guido van Rossum470be141995-03-17 16:07:09 +000033Return \var{image} scaled to size \var{newwidth} by \var{newheight}.
34No interpolation is done, scaling is done by simple-minded pixel
35duplication or removal. Therefore, computer-generated images or
36dithered images will not look nice after scaling.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000037\end{funcdesc}
38
Fred Drakecce10901998-03-17 06:33:25 +000039\begin{funcdesc}{tovideo}{image, psize, width, height}
Guido van Rossum470be141995-03-17 16:07:09 +000040Run a vertical low-pass filter over an image. It does so by computing
41each destination pixel as the average of two vertically-aligned source
42pixels. The main use of this routine is to forestall excessive
43flicker if the image is displayed on a video device that uses
44interlacing, hence the name.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000045\end{funcdesc}
46
Fred Drakecce10901998-03-17 06:33:25 +000047\begin{funcdesc}{grey2mono}{image, width, height, threshold}
Guido van Rossum470be141995-03-17 16:07:09 +000048Convert a 8-bit deep greyscale image to a 1-bit deep image by
Thomas Woutersf8316632000-07-16 19:01:10 +000049thresholding all the pixels. The resulting image is tightly packed and
Fred Drakefc576191998-04-04 07:15:02 +000050is probably only useful as an argument to \function{mono2grey()}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000051\end{funcdesc}
52
Fred Drakecce10901998-03-17 06:33:25 +000053\begin{funcdesc}{dither2mono}{image, width, height}
Guido van Rossum470be141995-03-17 16:07:09 +000054Convert an 8-bit greyscale image to a 1-bit monochrome image using a
55(simple-minded) dithering algorithm.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000056\end{funcdesc}
57
Fred Drakecce10901998-03-17 06:33:25 +000058\begin{funcdesc}{mono2grey}{image, width, height, p0, p1}
Guido van Rossum470be141995-03-17 16:07:09 +000059Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
60All pixels that are zero-valued on input get value \var{p0} on output
61and all one-value input pixels get value \var{p1} on output. To
62convert a monochrome black-and-white image to greyscale pass the
63values \code{0} and \code{255} respectively.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000064\end{funcdesc}
65
Fred Drakecce10901998-03-17 06:33:25 +000066\begin{funcdesc}{grey2grey4}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000067Convert an 8-bit greyscale image to a 4-bit greyscale image without
68dithering.
69\end{funcdesc}
70
Fred Drakecce10901998-03-17 06:33:25 +000071\begin{funcdesc}{grey2grey2}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000072Convert an 8-bit greyscale image to a 2-bit greyscale image without
73dithering.
74\end{funcdesc}
75
Fred Drakecce10901998-03-17 06:33:25 +000076\begin{funcdesc}{dither2grey2}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000077Convert an 8-bit greyscale image to a 2-bit greyscale image with
Fred Drakefc576191998-04-04 07:15:02 +000078dithering. As for \function{dither2mono()}, the dithering algorithm
79is currently very simple.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000080\end{funcdesc}
81
Fred Drakecce10901998-03-17 06:33:25 +000082\begin{funcdesc}{grey42grey}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000083Convert a 4-bit greyscale image to an 8-bit greyscale image.
84\end{funcdesc}
85
Fred Drakecce10901998-03-17 06:33:25 +000086\begin{funcdesc}{grey22grey}{image, width, height}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000087Convert a 2-bit greyscale image to an 8-bit greyscale image.
88\end{funcdesc}
Sjoerd Mullender7e6bbe12004-01-10 20:43:43 +000089
90\begin{datadesc}{backward_compatible}
91If set to 0, the functions in this module use a non-backward
92compatible way of representing multi-byte pixels on little-endian
93systems. The SGI for which this module was originally written is a
94big-endian system, so setting this variable will have no effect.
95However, the code wasn't originally intended to run on anything else,
96so it made assumptions about byte order which are not universal.
97Setting this variable to 0 will cause the byte order to be reversed on
98little-endian systems, so that it then is the same as on big-endian
99systems.
100\end{datadesc}