Previous Section  < Day Day Up >  Next Section

10.8. Jump to the Web

Now that we have found which GIMP functions are used for much of the time, we have to figure out exactly what these functions are and possibly optimize their use.

First, we search the Web for pixel_rgn_get_pixel and try to determine what it does. After a few false starts, the following link and information revealed in Listing 10.11 confirm our suspicions about what pixel_rgn_get_pixel does.

Listing 10.11.

"There are calls for pixel_rgn_get_ pixel, row, col, and rect, which grab

data from the image and dump it into a buffer that you've pre-allocated.

And there are set calls to match. Look for "Pixel Regions" in gimp.h."


image.html )

In addition, the information in Listing 10.12 suggests that it is a good idea to avoid using pixel_rgn_get_ calls.

Listing 10.12.

"Note that these calls are relatively slow, they can easily be the

slowest thing in your plug-in. Do not get (or set) pixels one at a time

using pixel_rgn_[get|set]_pixel if there is any other way. " (from


In addition, the Web search yields information about the gimp_rgb_set_uchar function by simply turning up the source for the function. As shown in Listing 10.13, this call just packs the red, green, and blue values into a GimpRGB structure that represents a single color.

Listing 10.13.


gimp_rgb_set_uchar (GimpRGB *rgb,

                    guchar r,

                    guchar g,

                    guchar b)


  g_return_if_fail (rgb != NULL);

  rgb->r = (gdouble) r / 255.0;

  rgb->g = (gdouble) g / 255.0;

  rgb->b = (gdouble) b / 255.0;


Information gleaned from the Web confirms our suspicion: The pixel_rgn_get_ pixel function is a way to extract image data from the image, and gimp_rgba_set_uchar is just a way to take the color data returned by pixel_rgn_get_pixel and put it into the GimpRGB data structure.

Not only do we see how these functions are used, other pages also hint that they may not be the best functions to use if we want the filter to perform at its peak. One Web page ( suggests that it may be possible to increase performance by using the GIMP image cache. Another Web site ( suggests that it might be possible to increase performance by rewriting the filter to access the image data more efficiently.

    Previous Section  < Day Day Up >  Next Section