Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{imageop} --- |
Fred Drake | ffbe687 | 1999-04-22 21:23:22 +0000 | [diff] [blame] | 2 | Manipulate raw image data} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | |
Fred Drake | ffbe687 | 1999-04-22 21:23:22 +0000 | [diff] [blame] | 4 | \declaremodule{builtin}{imageop} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 5 | \modulesynopsis{Manipulate raw image data.} |
| 6 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 7 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 8 | The \module{imageop} module contains some useful operations on images. |
| 9 | It operates on images consisting of 8 or 32 bit pixels stored in |
| 10 | Python strings. This is the same format as used by |
Fred Drake | ffbe687 | 1999-04-22 21:23:22 +0000 | [diff] [blame] | 11 | \function{gl.lrectwrite()} and the \refmodule{imgfile} module. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 12 | |
| 13 | The module defines the following variables and functions: |
| 14 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 15 | \begin{excdesc}{error} |
| 16 | This exception is raised on all errors, such as unknown number of bits |
| 17 | per pixel, etc. |
| 18 | \end{excdesc} |
| 19 | |
| 20 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 21 | \begin{funcdesc}{crop}{image, psize, width, height, x0, y0, x1, y1} |
Georg Brandl | d13eeb7 | 2007-01-30 20:21:35 +0000 | [diff] [blame] | 22 | Return the selected part of \var{image}, which should be |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 23 | \var{width} by \var{height} in size and consist of pixels of |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 24 | \var{psize} bytes. \var{x0}, \var{y0}, \var{x1} and \var{y1} are like |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 25 | the \function{gl.lrectread()} parameters, i.e.\ the boundary is |
| 26 | included in the new image. The new boundaries need not be inside the |
| 27 | picture. Pixels that fall outside the old image will have their value |
| 28 | set to zero. If \var{x0} is bigger than \var{x1} the new image is |
| 29 | mirrored. The same holds for the y coordinates. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 30 | \end{funcdesc} |
| 31 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 32 | \begin{funcdesc}{scale}{image, psize, width, height, newwidth, newheight} |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 33 | Return \var{image} scaled to size \var{newwidth} by \var{newheight}. |
| 34 | No interpolation is done, scaling is done by simple-minded pixel |
| 35 | duplication or removal. Therefore, computer-generated images or |
| 36 | dithered images will not look nice after scaling. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 37 | \end{funcdesc} |
| 38 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 39 | \begin{funcdesc}{tovideo}{image, psize, width, height} |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 40 | Run a vertical low-pass filter over an image. It does so by computing |
| 41 | each destination pixel as the average of two vertically-aligned source |
| 42 | pixels. The main use of this routine is to forestall excessive |
| 43 | flicker if the image is displayed on a video device that uses |
| 44 | interlacing, hence the name. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 45 | \end{funcdesc} |
| 46 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 47 | \begin{funcdesc}{grey2mono}{image, width, height, threshold} |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 48 | Convert a 8-bit deep greyscale image to a 1-bit deep image by |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 49 | thresholding all the pixels. The resulting image is tightly packed and |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 50 | is probably only useful as an argument to \function{mono2grey()}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 51 | \end{funcdesc} |
| 52 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 53 | \begin{funcdesc}{dither2mono}{image, width, height} |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 54 | Convert an 8-bit greyscale image to a 1-bit monochrome image using a |
| 55 | (simple-minded) dithering algorithm. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 56 | \end{funcdesc} |
| 57 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 58 | \begin{funcdesc}{mono2grey}{image, width, height, p0, p1} |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 59 | Convert a 1-bit monochrome image to an 8 bit greyscale or color image. |
| 60 | All pixels that are zero-valued on input get value \var{p0} on output |
| 61 | and all one-value input pixels get value \var{p1} on output. To |
| 62 | convert a monochrome black-and-white image to greyscale pass the |
| 63 | values \code{0} and \code{255} respectively. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 64 | \end{funcdesc} |
| 65 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 66 | \begin{funcdesc}{grey2grey4}{image, width, height} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 67 | Convert an 8-bit greyscale image to a 4-bit greyscale image without |
| 68 | dithering. |
| 69 | \end{funcdesc} |
| 70 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 71 | \begin{funcdesc}{grey2grey2}{image, width, height} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 72 | Convert an 8-bit greyscale image to a 2-bit greyscale image without |
| 73 | dithering. |
| 74 | \end{funcdesc} |
| 75 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 76 | \begin{funcdesc}{dither2grey2}{image, width, height} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 77 | Convert an 8-bit greyscale image to a 2-bit greyscale image with |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 78 | dithering. As for \function{dither2mono()}, the dithering algorithm |
| 79 | is currently very simple. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 80 | \end{funcdesc} |
| 81 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 82 | \begin{funcdesc}{grey42grey}{image, width, height} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 83 | Convert a 4-bit greyscale image to an 8-bit greyscale image. |
| 84 | \end{funcdesc} |
| 85 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 86 | \begin{funcdesc}{grey22grey}{image, width, height} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 87 | Convert a 2-bit greyscale image to an 8-bit greyscale image. |
| 88 | \end{funcdesc} |
Sjoerd Mullender | 7e6bbe1 | 2004-01-10 20:43:43 +0000 | [diff] [blame] | 89 | |
| 90 | \begin{datadesc}{backward_compatible} |
| 91 | If set to 0, the functions in this module use a non-backward |
| 92 | compatible way of representing multi-byte pixels on little-endian |
| 93 | systems. The SGI for which this module was originally written is a |
| 94 | big-endian system, so setting this variable will have no effect. |
| 95 | However, the code wasn't originally intended to run on anything else, |
| 96 | so it made assumptions about byte order which are not universal. |
| 97 | Setting this variable to 0 will cause the byte order to be reversed on |
| 98 | little-endian systems, so that it then is the same as on big-endian |
| 99 | systems. |
| 100 | \end{datadesc} |