cinap_lenrekadd hg and python4bb9e2215 years agoHistory
100 lines · 4.0 KB · TeX
RawDownload
\section{\module{imageop} ---         Manipulate raw image data} \declaremodule{builtin}{imageop}\modulesynopsis{Manipulate raw image data.}  The \module{imageop} module contains some useful operations on images.It operates on images consisting of 8 or 32 bit pixels stored inPython strings.  This is the same format as used by\function{gl.lrectwrite()} and the \refmodule{imgfile} module. The module defines the following variables and functions: \begin{excdesc}{error}This exception is raised on all errors, such as unknown number of bitsper pixel, etc.\end{excdesc}  \begin{funcdesc}{crop}{image, psize, width, height, x0, y0, x1, y1}Return the selected part of \var{image}, which should be\var{width} by \var{height} in size and consist of pixels of\var{psize} bytes. \var{x0}, \var{y0}, \var{x1} and \var{y1} are likethe \function{gl.lrectread()} parameters, i.e.\ the boundary isincluded in the new image.  The new boundaries need not be inside thepicture.  Pixels that fall outside the old image will have their valueset to zero.  If \var{x0} is bigger than \var{x1} the new image ismirrored.  The same holds for the y coordinates.\end{funcdesc} \begin{funcdesc}{scale}{image, psize, width, height, newwidth, newheight}Return \var{image} scaled to size \var{newwidth} by \var{newheight}.No interpolation is done, scaling is done by simple-minded pixelduplication or removal.  Therefore, computer-generated images ordithered images will not look nice after scaling.\end{funcdesc} \begin{funcdesc}{tovideo}{image, psize, width, height}Run a vertical low-pass filter over an image.  It does so by computingeach destination pixel as the average of two vertically-aligned sourcepixels.  The main use of this routine is to forestall excessiveflicker if the image is displayed on a video device that usesinterlacing, hence the name.\end{funcdesc} \begin{funcdesc}{grey2mono}{image, width, height, threshold}Convert a 8-bit deep greyscale image to a 1-bit deep image bythresholding all the pixels.  The resulting image is tightly packed andis probably only useful as an argument to \function{mono2grey()}.\end{funcdesc} \begin{funcdesc}{dither2mono}{image, width, height}Convert an 8-bit greyscale image to a 1-bit monochrome image using a(simple-minded) dithering algorithm.\end{funcdesc} \begin{funcdesc}{mono2grey}{image, width, height, p0, p1}Convert a 1-bit monochrome image to an 8 bit greyscale or color image.All pixels that are zero-valued on input get value \var{p0} on outputand all one-value input pixels get value \var{p1} on output.  Toconvert a monochrome black-and-white image to greyscale pass thevalues \code{0} and \code{255} respectively.\end{funcdesc} \begin{funcdesc}{grey2grey4}{image, width, height}Convert an 8-bit greyscale image to a 4-bit greyscale image withoutdithering.\end{funcdesc} \begin{funcdesc}{grey2grey2}{image, width, height}Convert an 8-bit greyscale image to a 2-bit greyscale image withoutdithering.\end{funcdesc} \begin{funcdesc}{dither2grey2}{image, width, height}Convert an 8-bit greyscale image to a 2-bit greyscale image withdithering.  As for \function{dither2mono()}, the dithering algorithmis currently very simple.\end{funcdesc} \begin{funcdesc}{grey42grey}{image, width, height}Convert a 4-bit greyscale image to an 8-bit greyscale image.\end{funcdesc} \begin{funcdesc}{grey22grey}{image, width, height}Convert a 2-bit greyscale image to an 8-bit greyscale image.\end{funcdesc} \begin{datadesc}{backward_compatible}If set to 0, the functions in this module use a non-backwardcompatible way of representing multi-byte pixels on little-endiansystems.  The SGI for which this module was originally written is abig-endian system, so setting this variable will have no effect.However, the code wasn't originally intended to run on anything else,so it made assumptions about byte order which are not universal.Setting this variable to 0 will cause the byte order to be reversed onlittle-endian systems, so that it then is the same as on big-endiansystems.\end{datadesc}