app: add gimp_gegl_clear()
... which clears the alpha component of a given buffer region, i.e., it makes the region transparent, while preserving color information. This corresponds to the "edit-clear" action.
This commit is contained in:
parent
861f356b63
commit
2e3eab7fbd
2 changed files with 55 additions and 0 deletions
|
|
@ -93,6 +93,58 @@ gimp_gegl_buffer_copy (GeglBuffer *src_buffer,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_gegl_clear (GeglBuffer *buffer,
|
||||
const GeglRectangle *rect)
|
||||
{
|
||||
const Babl *format;
|
||||
gint bpp;
|
||||
gint n_components;
|
||||
gint bpc;
|
||||
gint alpha_offset;
|
||||
|
||||
g_return_if_fail (GEGL_IS_BUFFER (buffer));
|
||||
|
||||
if (! rect)
|
||||
rect = gegl_buffer_get_extent (buffer);
|
||||
|
||||
format = gegl_buffer_get_format (buffer);
|
||||
|
||||
if (! babl_format_has_alpha (format))
|
||||
return;
|
||||
|
||||
bpp = babl_format_get_bytes_per_pixel (format);
|
||||
n_components = babl_format_get_n_components (format);
|
||||
bpc = bpp / n_components;
|
||||
alpha_offset = (n_components - 1) * bpc;
|
||||
|
||||
gegl_parallel_distribute_area (
|
||||
rect, PIXELS_PER_THREAD,
|
||||
[=] (const GeglRectangle *area)
|
||||
{
|
||||
GeglBufferIterator *iter;
|
||||
|
||||
iter = gegl_buffer_iterator_new (buffer, rect, 0, format,
|
||||
GEGL_ACCESS_READWRITE, GEGL_ABYSS_NONE,
|
||||
1);
|
||||
|
||||
while (gegl_buffer_iterator_next (iter))
|
||||
{
|
||||
guint8 *data = (guint8 *) iter->items[0].data;
|
||||
gint i;
|
||||
|
||||
data += alpha_offset;
|
||||
|
||||
for (i = 0; i < iter->length; i++)
|
||||
{
|
||||
memset (data, 0, bpc);
|
||||
|
||||
data += bpp;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
gimp_gegl_convolve (GeglBuffer *src_buffer,
|
||||
const GeglRectangle *src_rect,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ void gimp_gegl_buffer_copy (GeglBuffer *src_buffer,
|
|||
GeglBuffer *dest_buffer,
|
||||
const GeglRectangle *dest_rect);
|
||||
|
||||
void gimp_gegl_clear (GeglBuffer *buffer,
|
||||
const GeglRectangle *rect);
|
||||
|
||||
/* this is a pretty stupid port of concolve_region() that only works
|
||||
* on a linear source buffer
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue