app: improve gimp_channel_clear()

When clearing a channel, do nothing if the channel is already
empty; otherwise, align the cleared rectangle to the channel
buffer's tile grid, so that all affected tiles are dropped, rather
than zeroed.  Furthermore, only update the affected region of the
channel.
This commit is contained in:
Ell 2019-01-17 15:05:37 -05:00
parent de4e7b4770
commit ac5e4f4c33
1 changed files with 25 additions and 8 deletions

View File

@ -37,6 +37,7 @@
#include "gegl/gimp-gegl-loops.h"
#include "gegl/gimp-gegl-mask.h"
#include "gegl/gimp-gegl-nodes.h"
#include "gegl/gimp-gegl-utils.h"
#include "gimp.h"
#include "gimp-utils.h"
@ -1258,6 +1259,13 @@ gimp_channel_real_clear (GimpChannel *channel,
const gchar *undo_desc,
gboolean push_undo)
{
GeglBuffer *buffer;
GeglRectangle rect;
GeglRectangle aligned_rect;
if (channel->bounds_known && channel->empty)
return;
if (push_undo)
{
if (! undo_desc)
@ -1266,19 +1274,27 @@ gimp_channel_real_clear (GimpChannel *channel,
gimp_channel_push_undo (channel, undo_desc);
}
if (channel->bounds_known && ! channel->empty)
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (channel));
if (channel->bounds_known)
{
gegl_buffer_clear (gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
GEGL_RECTANGLE (channel->x1, channel->y1,
channel->x2 - channel->x1,
channel->y2 - channel->y1));
rect.x = channel->x1;
rect.y = channel->y1;
rect.width = channel->x2 - channel->x1;
rect.height = channel->y2 - channel->y1;
}
else
{
gegl_buffer_clear (gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
NULL);
rect.x = 0;
rect.y = 0;
rect.width = gimp_item_get_width (GIMP_ITEM (channel));
rect.height = gimp_item_get_height (GIMP_ITEM (channel));
}
gimp_gegl_rectangle_align_to_tile_grid (&aligned_rect, &rect, buffer);
gegl_buffer_clear (buffer, &aligned_rect);
/* we know the bounds */
channel->bounds_known = TRUE;
channel->empty = TRUE;
@ -1287,7 +1303,8 @@ gimp_channel_real_clear (GimpChannel *channel,
channel->x2 = gimp_item_get_width (GIMP_ITEM (channel));
channel->y2 = gimp_item_get_height (GIMP_ITEM (channel));
gimp_drawable_update (GIMP_DRAWABLE (channel), 0, 0, -1, -1);
gimp_drawable_update (GIMP_DRAWABLE (channel),
rect.x, rect.y, rect.width, rect.height);
}
static void