added clear_region().

2008-09-01  Sven Neumann  <sven@gimp.org>

	* 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
This commit is contained in:
Sven Neumann 2008-09-01 20:44:00 +00:00 committed by Sven Neumann
parent 88955a3118
commit a5f8345609
8 changed files with 74 additions and 39 deletions

View file

@ -1,3 +1,14 @@
2008-09-01 Sven Neumann <sven@gimp.org>
* 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 <sven@gimp.org>
* app/core/gimpprojection-construct.c (gimp_projection_initialize):

View file

@ -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 (&region, tiles, 0, 0, x1, y1, FALSE);
for (pr = pixel_regions_register (1, &PR);
for (pr = pixel_regions_register (1, &region);
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,

View file

@ -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;

View file

@ -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

View file

@ -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
{

View file

@ -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 (&region,
gimp_projection_get_tiles (proj), x, y, w, h, TRUE);
clear_region (&region);
}
}

View file

@ -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)

View file

@ -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,