From a5f8345609c5146d0fe754361e8ea1911adde35a Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Mon, 1 Sep 2008 20:44:00 +0000 Subject: [PATCH] added clear_region(). 2008-09-01 Sven Neumann * app/paint-funcs/paint-funcs.[ch]: added clear_region(). * app/base/tile-manager-crop.c * app/core/gimpchannel.c * app/core/gimpimage-merge.c * app/core/gimpmaskundo.c * app/core/gimpprojection-construct.c: use it instead of calling color_region() with a zero color. svn path=/trunk/; revision=26826 --- ChangeLog | 11 +++++++++ app/base/tile-manager-crop.c | 37 ++++++++++++++--------------- app/core/gimpchannel.c | 11 ++++----- app/core/gimpimage-merge.c | 9 ++++--- app/core/gimpmaskundo.c | 4 +--- app/core/gimpprojection-construct.c | 9 ++++--- app/paint-funcs/paint-funcs.c | 29 ++++++++++++++++++++++ app/paint-funcs/paint-funcs.h | 3 +++ 8 files changed, 74 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd96c867d8..c344b8d1fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-09-01 Sven Neumann + + * app/paint-funcs/paint-funcs.[ch]: added clear_region(). + + * app/base/tile-manager-crop.c + * app/core/gimpchannel.c + * app/core/gimpimage-merge.c + * app/core/gimpmaskundo.c + * app/core/gimpprojection-construct.c: use it instead of calling + color_region() with a zero color. + 2008-09-01 Sven Neumann * app/core/gimpprojection-construct.c (gimp_projection_initialize): diff --git a/app/base/tile-manager-crop.c b/app/base/tile-manager-crop.c index f011745929..ce9a2aa185 100644 --- a/app/base/tile-manager-crop.c +++ b/app/base/tile-manager-crop.c @@ -35,14 +35,13 @@ TileManager * tile_manager_crop (TileManager *tiles, gint border) { - PixelRegion PR; - TileManager *new_tiles; - gint bytes, alpha; - gint x1, y1, x2, y2; - gboolean found; - gboolean empty; - gpointer pr; - const guchar black[MAX_CHANNELS] = { 0, 0, 0, 0 }; + PixelRegion region; + TileManager *new_tiles; + gint bytes, alpha; + gint x1, y1, x2, y2; + gboolean found; + gboolean empty; + gpointer pr; g_return_val_if_fail (tiles != NULL, NULL); @@ -55,22 +54,22 @@ tile_manager_crop (TileManager *tiles, x2 = 0; y2 = 0; - pixel_region_init (&PR, tiles, 0, 0, x1, y1, FALSE); + pixel_region_init (®ion, tiles, 0, 0, x1, y1, FALSE); - for (pr = pixel_regions_register (1, &PR); + for (pr = pixel_regions_register (1, ®ion); pr != NULL; pr = pixel_regions_process (pr)) { - const guchar *data = PR.data + alpha; - gint ex = PR.x + PR.w; - gint ey = PR.y + PR.h; + const guchar *data = region.data + alpha; + gint ex = region.x + region.w; + gint ey = region.y + region.h; gint x, y; - for (y = PR.y; y < ey; y++) + for (y = region.y; y < ey; y++) { found = FALSE; - for (x = PR.x; x < ex; x++, data += bytes) + for (x = region.x; x < ex; x++, data += bytes) if (*data) { if (x < x1) @@ -129,22 +128,22 @@ tile_manager_crop (TileManager *tiles, pixel_region_init (&destPR, new_tiles, 0, 0, new_width, border, TRUE); - color_region (&destPR, black); + clear_region (&destPR); pixel_region_init (&destPR, new_tiles, 0, border, border, (y2 - y1), TRUE); - color_region (&destPR, black); + clear_region (&destPR); pixel_region_init (&destPR, new_tiles, new_width - border, border, border, (y2 - y1), TRUE); - color_region (&destPR, black); + clear_region (&destPR); pixel_region_init (&destPR, new_tiles, 0, new_height - border, new_width, border, TRUE); - color_region (&destPR, black); + clear_region (&destPR); } pixel_region_init (&srcPR, tiles, diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c index 65d51e658e..d806b592ef 100644 --- a/app/core/gimpchannel.c +++ b/app/core/gimpchannel.c @@ -494,7 +494,6 @@ gimp_channel_translate (GimpItem *item, GimpChannel *tmp_mask = NULL; gint width, height; PixelRegion srcPR, destPR; - guchar empty = TRANSPARENT_OPACITY; gint x1, y1, x2, y2; gimp_channel_bounds (channel, &x1, &y1, &x2, &y2); @@ -539,7 +538,7 @@ gimp_channel_translate (GimpItem *item, 0, 0, gimp_item_width (GIMP_ITEM (channel)), gimp_item_height (GIMP_ITEM (channel)), TRUE); - color_region (&srcPR, &empty); + clear_region (&srcPR); if (width != 0 && height != 0) { @@ -1195,7 +1194,6 @@ gimp_channel_real_clear (GimpChannel *channel, gboolean push_undo) { PixelRegion maskPR; - guchar bg = TRANSPARENT_OPACITY; if (push_undo) { @@ -1216,7 +1214,7 @@ gimp_channel_real_clear (GimpChannel *channel, channel->x1, channel->y1, channel->x2 - channel->x1, channel->y2 - channel->y1, TRUE); - color_region (&maskPR, &bg); + clear_region (&maskPR); } else { @@ -1226,7 +1224,7 @@ gimp_channel_real_clear (GimpChannel *channel, 0, 0, gimp_item_width (GIMP_ITEM (channel)), gimp_item_height (GIMP_ITEM (channel)), TRUE); - color_region (&maskPR, &bg); + clear_region (&maskPR); } /* we know the bounds */ @@ -1247,7 +1245,6 @@ gimp_channel_real_all (GimpChannel *channel, gboolean push_undo) { PixelRegion maskPR; - guchar bg = OPAQUE_OPACITY; if (push_undo) gimp_channel_push_undo (channel, @@ -1261,7 +1258,7 @@ gimp_channel_real_all (GimpChannel *channel, 0, 0, gimp_item_width (GIMP_ITEM (channel)), gimp_item_height (GIMP_ITEM (channel)), TRUE); - color_region (&maskPR, &bg); + clear_region (&maskPR); /* we know the bounds */ channel->bounds_known = TRUE; diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c index 80661f6f3b..94c1f5ca56 100644 --- a/app/core/gimpimage-merge.c +++ b/app/core/gimpimage-merge.c @@ -319,7 +319,6 @@ gimp_image_merge_layers (GimpImage *image, GimpLayer *merge_layer; GimpLayer *layer; GimpLayer *bottom_layer; - guchar bg[4] = {0, 0, 0, 0}; GimpImageType type; gint count; gint x1, y1, x2, y2; @@ -418,6 +417,8 @@ gimp_image_merge_layers (GimpImage *image, if (merge_type == GIMP_FLATTEN_IMAGE || gimp_drawable_type (GIMP_DRAWABLE (layer)) == GIMP_INDEXED_IMAGE) { + guchar bg[4] = { 0, 0, 0, 0 }; + type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (gimp_image_base_type (image)); merge_layer = gimp_layer_new (image, (x2 - x1), (y2 - y1), @@ -471,15 +472,13 @@ gimp_image_merge_layers (GimpImage *image, GIMP_ITEM (merge_layer)->offset_x = x1; GIMP_ITEM (merge_layer)->offset_y = y1; - /* Set the layer to transparent */ + /* clear the layer */ pixel_region_init (&src1PR, gimp_drawable_get_tiles (GIMP_DRAWABLE (merge_layer)), 0, 0, (x2 - x1), (y2 - y1), TRUE); - - /* set the region to 0's */ - color_region (&src1PR, bg); + clear_region (&src1PR); /* Find the index in the layer list of the bottom layer--we need this * in order to add the final, merged layer to the layer list correctly diff --git a/app/core/gimpmaskundo.c b/app/core/gimpmaskundo.c index 46321e1930..5517296df6 100644 --- a/app/core/gimpmaskundo.c +++ b/app/core/gimpmaskundo.c @@ -139,8 +139,6 @@ gimp_mask_undo_pop (GimpUndo *undo, if (gimp_channel_bounds (channel, &x1, &y1, &x2, &y2)) { - guchar empty = 0; - new_tiles = tile_manager_new (x2 - x1, y2 - y1, 1); pixel_region_init (&srcPR, @@ -155,7 +153,7 @@ gimp_mask_undo_pop (GimpUndo *undo, gimp_drawable_get_tiles (GIMP_DRAWABLE (channel)), x1, y1, x2 - x1, y2 - y1, TRUE); - color_region (&srcPR, &empty); + clear_region (&srcPR); } else { diff --git a/app/core/gimpprojection-construct.c b/app/core/gimpprojection-construct.c index 3afef9a497..c1519aa939 100644 --- a/app/core/gimpprojection-construct.c +++ b/app/core/gimpprojection-construct.c @@ -377,12 +377,11 @@ gimp_projection_initialize (GimpProjection *proj, if (! coverage) { - PixelRegion PR; - guchar clear[4] = { 0, 0, 0, 0 }; + PixelRegion region; - pixel_region_init (&PR, gimp_projection_get_tiles (proj), - x, y, w, h, TRUE); - color_region (&PR, clear); + pixel_region_init (®ion, + gimp_projection_get_tiles (proj), x, y, w, h, TRUE); + clear_region (®ion); } } diff --git a/app/paint-funcs/paint-funcs.c b/app/paint-funcs/paint-funcs.c index 697fdb3191..fec8724e31 100644 --- a/app/paint-funcs/paint-funcs.c +++ b/app/paint-funcs/paint-funcs.c @@ -1885,6 +1885,35 @@ extract_from_indexed_pixels (guchar *src, /* REGION FUNCTIONS */ /**************************************************/ +void +clear_region (PixelRegion *dest) +{ + gpointer pr; + + for (pr = pixel_regions_register (1, dest); + pr != NULL; + pr = pixel_regions_process (pr)) + { + if (dest->w * dest->bytes == dest->rowstride) + { + memset (dest->data, 0, dest->w * dest->h * dest->bytes); + } + else + { + guchar *d = dest->data; + gint h = dest->h; + + while (h--) + { + memset (d, 0, dest->w * dest->bytes); + + d += dest->rowstride; + } + } + } +} + + void color_region (PixelRegion *dest, const guchar *col) diff --git a/app/paint-funcs/paint-funcs.h b/app/paint-funcs/paint-funcs.h index 6f5ab7fa13..92ea44aeaa 100644 --- a/app/paint-funcs/paint-funcs.h +++ b/app/paint-funcs/paint-funcs.h @@ -339,6 +339,9 @@ void extract_from_indexed_pixels (guchar *src, /* Region functions */ + +void clear_region (PixelRegion *dest); + void color_region (PixelRegion *dest, const guchar *color); void color_region_mask (PixelRegion *dest,