CHAPTER 11 PLUG-INS AND SCRIPTING 457 Instead (Web hosting e commerce)

CHAPTER 11 PLUG-INS AND SCRIPTING 457 Instead of widthand heightof the drawable, you ll need the width and height of the image (which you can get with gimp_image_width(image_id) and gimp_image_height(image_id)). Inside the loop over the layers, you ll need the width and height of each drawable. To keep from getting confused about which is which, I ve used iwidthand iheightfor the image dimensions, and dwidth and dheight (declared inside the layers loop) for the drawable dimensions. layers is an array of integers, which represent layer IDs. You can get the drawable for each of these layers with gimp_drawable_get(layer_id). Then you can do all the operations that Zealous Crop did on its drawable, including the pixel-region operations. Handling the Edges One at a Time Once everything is set up, rather than looping over the whole width and height of each layer s drawable, you need only explore inward from each of the four image edges. Keep track of the maximum extent of the crop rectangle so far, in image coordinates, using xmin, xmax, ymin, and ymax. Since you aren t looping over the whole drawable, this is very fast; most of the time you ll only need to check a few lines before you find something that can t be cropped. Then you can move on to the next edge. Since the plug-in will no longer loop over the entire image, there s no point in keeping track of area to update the progress bar. It should be sufficient to update the progress bar once after each layer. Update it to the current layer number divided by the total number of layers. That means you can remove areaand total_area from the program. Here is how to find ymax, the bottom edge from the current layer. The other three edges are similar: start = dheight - 1; if (layerOffsetY + dheight > iheight) start = iheight - layerOffsetY - 1; Find the starting point for the loop. The loop should start at the bottom edge of the image, or the bottom edge of the layer, whichever is higher. (Remember, a layer can run off the edge of the image containing it.) dheight is the height of the drawable (the current layer). Since coordinates start at 0, dheight - 1 is the coordinate of the bottom-most pixels in the layer. layerOffsetY + dheight represents the image coordinates of the bottom edge of the layer. If that is greater than the image height, then the image s bottom edge lies off the bottom of the image, and start is adjusted accordingly, to the last visible pixel in the layer. for (y = start; y > 0 && layerOffsetY + y > ymax; y ) Loop backwards (with y in layer coordinates) from the bottom visible pixel in the layer until we either reach the top of the image, or until the image coordinates of the current row (layerOffsetY + y) crosses the ymax we ve already found from some other layer. gimp_pixel_rgn_get_row (&srcPR, buffer, 0, y, dwidth); for (x = 0; x < dwidth * bytes; x += bytes) Get the row at this position, and loop horizontally over the pixels in it. Notice that this isn t checking to see if the pixels are really inside the image boundaries. That s something that should probably be added. if (!colours_equal (buffer, &buffer[x], bytes))
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Leave a Reply