Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / module-imageop.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-aifc.html" />
<link rel="prev" href="module-audioop.html" />
<link rel="parent" href="mmedia.html" />
<link rel="next" href="module-aifc.html" />
<meta name='aesop' content='information' />
<title>14.2 imageop -- Manipulate raw image data</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.1 audioop "
href="module-audioop.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="14. Multimedia Services"
href="mmedia.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="14.3 aifc "
href="module-aifc.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-audioop.html">14.1 audioop </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="mmedia.html">14. Multimedia Services</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-aifc.html">14.3 aifc </A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0016200000000000000000">
14.2 <tt class="module">imageop</tt> --
Manipulate raw image data</A>
</H1>
<P>
<A NAME="module-imageop"></A>
<P>
The <tt class="module">imageop</tt> module contains some useful operations on images.
It operates on images consisting of 8 or 32 bit pixels stored in
Python strings. This is the same format as used by
<tt class="function">gl.lrectwrite()</tt> and the <tt class="module"><a href="module-imgfile.html">imgfile</a></tt> module.
<P>
The module defines the following variables and functions:
<P>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-4622' xml:id='l2h-4622' class="exception">error</tt></b></dt>
<dd>
This exception is raised on all errors, such as unknown number of bits
per pixel, etc.
</dd></dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4623' xml:id='l2h-4623' class="function">crop</tt></b>(</nobr></td>
<td><var>image, psize, width, height, x0, y0, x1, y1</var>)</td></tr></table></dt>
<dd>
Return the selected part of <var>image</var>, which should by
<var>width</var> by <var>height</var> in size and consist of pixels of
<var>psize</var> bytes. <var>x0</var>, <var>y0</var>, <var>x1</var> and <var>y1</var> are like
the <tt class="function">gl.lrectread()</tt> parameters, i.e. the boundary is
included in the new image. The new boundaries need not be inside the
picture. Pixels that fall outside the old image will have their value
set to zero. If <var>x0</var> is bigger than <var>x1</var> the new image is
mirrored. The same holds for the y coordinates.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4624' xml:id='l2h-4624' class="function">scale</tt></b>(</nobr></td>
<td><var>image, psize, width, height, newwidth, newheight</var>)</td></tr></table></dt>
<dd>
Return <var>image</var> scaled to size <var>newwidth</var> by <var>newheight</var>.
No interpolation is done, scaling is done by simple-minded pixel
duplication or removal. Therefore, computer-generated images or
dithered images will not look nice after scaling.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4625' xml:id='l2h-4625' class="function">tovideo</tt></b>(</nobr></td>
<td><var>image, psize, width, height</var>)</td></tr></table></dt>
<dd>
Run a vertical low-pass filter over an image. It does so by computing
each destination pixel as the average of two vertically-aligned source
pixels. The main use of this routine is to forestall excessive
flicker if the image is displayed on a video device that uses
interlacing, hence the name.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4626' xml:id='l2h-4626' class="function">grey2mono</tt></b>(</nobr></td>
<td><var>image, width, height, threshold</var>)</td></tr></table></dt>
<dd>
Convert a 8-bit deep greyscale image to a 1-bit deep image by
thresholding all the pixels. The resulting image is tightly packed and
is probably only useful as an argument to <tt class="function">mono2grey()</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4627' xml:id='l2h-4627' class="function">dither2mono</tt></b>(</nobr></td>
<td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert an 8-bit greyscale image to a 1-bit monochrome image using a
(simple-minded) dithering algorithm.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4628' xml:id='l2h-4628' class="function">mono2grey</tt></b>(</nobr></td>
<td><var>image, width, height, p0, p1</var>)</td></tr></table></dt>
<dd>
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</var> on output
and all one-value input pixels get value <var>p1</var> on output. To
convert a monochrome black-and-white image to greyscale pass the
values <code>0</code> and <code>255</code> respectively.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4629' xml:id='l2h-4629' class="function">grey2grey4</tt></b>(</nobr></td>
<td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert an 8-bit greyscale image to a 4-bit greyscale image without
dithering.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4630' xml:id='l2h-4630' class="function">grey2grey2</tt></b>(</nobr></td>
<td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert an 8-bit greyscale image to a 2-bit greyscale image without
dithering.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4631' xml:id='l2h-4631' class="function">dither2grey2</tt></b>(</nobr></td>
<td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert an 8-bit greyscale image to a 2-bit greyscale image with
dithering. As for <tt class="function">dither2mono()</tt>, the dithering algorithm
is currently very simple.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4632' xml:id='l2h-4632' class="function">grey42grey</tt></b>(</nobr></td>
<td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert a 4-bit greyscale image to an 8-bit greyscale image.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-4633' xml:id='l2h-4633' class="function">grey22grey</tt></b>(</nobr></td>
<td><var>image, width, height</var>)</td></tr></table></dt>
<dd>
Convert a 2-bit greyscale image to an 8-bit greyscale image.
</dl>
<P>
<dl><dt><b><tt id='l2h-4634' xml:id='l2h-4634'>backward_compatible</tt></b></dt>
<dd>
If set to 0, the functions in this module use a non-backward
compatible way of representing multi-byte pixels on little-endian
systems. The SGI for which this module was originally written is a
big-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 on
little-endian systems, so that it then is the same as on big-endian
systems.
</dd></dl>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.1 audioop "
href="module-audioop.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="14. Multimedia Services"
href="mmedia.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="14.3 aifc "
href="module-aifc.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-audioop.html">14.1 audioop </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="mmedia.html">14. Multimedia Services</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-aifc.html">14.3 aifc </A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>