General Pixel Transformation (XForms (Forms Library) - Version 1.2 (Rev. 4) A Graphical User Interface Toolkit for X)

Next: Image Annotation, Previous: Warping, Up: Simple Image Processing [Contents][Index]

#### 37.7.8 General Pixel Transformation

Many image processing tasks can be implemented as seperate RGB transformations. These transformations can be done very efficiently through the use of lookup tables. For this reason the following routine exists:

    int flimage_transform_pixels(FL_IMAGE *im, int *red,
                                 int *green, int *blue);

where `red`, `green` and `blue` are the lookup tables of a length of at least `FL_PCMAX + 1` (typically 256). The function returns a postive number on success and the image will be replaced. Note that this routine notices the settings of the subimage, i.e., you can transform a portion of the image.

To illustrate the use of this routine let’s look at how a simple contrast adjustment may be implemented:

    #include <forms.h>
    #include <math.h>

    int AdjustContrast(FL_IMAGE *im) {
        int r[FL_PCMAX+1],
            g[FL_PCMAX+1],
            b[FL_PCMAX+1];
        int i,
            scale = 10;

        /* in this example rgb are adjusted the same way */
        for ( i = 0; i <= FL_PCMAX; i++)
            r[i] = g[i] = b[i] = i * log10(1 + i * scale / FL_PCMAX )
                                 / log10( 1 + scale );

        return flimage_transform_pixels(im, r, g, b);
    }