next up previous contents
Next: 3. Programming PIO functions Up: 2. Programming WIO operations Previous: 2.3 Output to an   Contents


2.4 Polymorphism

Most image processing operations in the VIPS library can operate on images of any type (IM_BANDFMT_UCHAR, as in our examples above, also IM_BANDFMT_UINT etc.). This is usually implemented with code replication: the operation contains loops for processing every kind of image, and when called, invokes the appropriate loop for the image it is given.

As an example, figure 2.3 calculates exp() for every pel in an image. If the input image is double, we write double output. If it is any other non-complex type, we write float. If it is complex, we flag an error (exp() of a complex number is fiddly). The example uses an image type predicate, im_iscomplex(). There are a number of these predicate functions, see the manual page.

Figure 2.3: Calculate exp() for an image
\begin{figure}\begin{quote}
\begin{verbatim}...

Figure 2.4: Calculate exp() for an image (cont)
\begin{figure}\begin{quote}
\begin{verbatim}/* Allocate a line buffer.
*/
i...
...-1 );
}/* Success.
*/
return( 0 );
}\end{verbatim}
\end{quote}\end{figure}



John Cupitt 2005-04-11