app: add gimp_gegl_combine_mask() and use it in GimpPaintCore

This commit is contained in:
Michael Natterer 2012-04-23 12:51:11 +02:00
parent c07790fa54
commit 4772d3e832
3 changed files with 74 additions and 50 deletions

View file

@ -423,3 +423,50 @@ gimp_gegl_apply_mask (GeglBuffer *mask_buffer,
}
}
}
void
gimp_gegl_combine_mask (GeglBuffer *mask_buffer,
const GeglRectangle *mask_rect,
GeglBuffer *dest_buffer,
const GeglRectangle *dest_rect,
gdouble opacity,
gboolean stipple)
{
GeglBufferIterator *iter;
iter = gegl_buffer_iterator_new (mask_buffer, mask_rect, 0,
babl_format ("Y float"),
GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
gegl_buffer_iterator_add (iter, dest_buffer, dest_rect, 0,
babl_format ("Y float"),
GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE);
while (gegl_buffer_iterator_next (iter))
{
const gfloat *mask = iter->data[0];
gfloat *dest = iter->data[1];
if (stipple)
{
while (iter->length--)
{
dest[0] += (1.0 - dest[0]) * *mask * opacity;
mask += 1;
dest += 1;
}
}
else
{
while (iter->length--)
{
if (opacity > dest[0])
dest[0] += (opacity - dest[0]) * *mask * opacity;
mask += 1;
dest += 1;
}
}
}
}

View file

@ -57,5 +57,12 @@ void gimp_gegl_apply_mask (GeglBuffer *mask_buffer,
const GeglRectangle *dest_rect,
gdouble opacity);
void gimp_gegl_combine_mask (GeglBuffer *mask_buffer,
const GeglRectangle *mask_rect,
GeglBuffer *dest_buffer,
const GeglRectangle *dest_rect,
gdouble opacity,
gboolean stipple);
#endif /* __GIMP_GEGL_LOOPS_H__ */

View file

@ -26,10 +26,6 @@
#include "paint-types.h"
#include "base/pixel-region.h"
#include "paint-funcs/paint-funcs.h"
#include "gegl/gimp-gegl-loops.h"
#include "gegl/gimp-gegl-utils.h"
@ -51,7 +47,8 @@
#include "gimp-intl.h"
#define STROKE_BUFFER_INIT_SIZE 2000
#define STROKE_BUFFER_INIT_SIZE 2000
enum
{
@ -929,15 +926,15 @@ gimp_paint_core_smooth_coords (GimpPaintCore *core,
static void
canvas_buffer_to_paint_buffer (GimpPaintCore *core)
{
gint width = gegl_buffer_get_width (core->paint_buffer);
gint height = gegl_buffer_get_height (core->paint_buffer);
gimp_gegl_apply_mask (core->canvas_buffer,
GEGL_RECTANGLE (core->paint_buffer_x,
core->paint_buffer_y,
gegl_buffer_get_width (core->paint_buffer),
gegl_buffer_get_height (core->paint_buffer)),
width, height),
core->paint_buffer,
GEGL_RECTANGLE (0, 0,
gegl_buffer_get_width (core->paint_buffer),
gegl_buffer_get_height (core->paint_buffer)),
GEGL_RECTANGLE (0, 0, width, height),
1.0);
}
@ -947,44 +944,16 @@ paint_mask_to_canvas_buffer (GimpPaintCore *core,
const GeglRectangle *paint_mask_rect,
gdouble paint_opacity)
{
PixelRegion srcPR;
PixelRegion paint_maskPR;
gint width = gegl_buffer_get_width (core->paint_buffer);
gint height = gegl_buffer_get_height (core->paint_buffer);
/* combine the paint mask and the canvas buffer */
pixel_region_init (&srcPR,
gimp_gegl_buffer_get_tiles (core->canvas_buffer),
core->paint_buffer_x,
core->paint_buffer_y,
gegl_buffer_get_width (core->paint_buffer),
gegl_buffer_get_height (core->paint_buffer),
TRUE);
if (gimp_gegl_buffer_get_temp_buf (paint_mask))
{
pixel_region_init_temp_buf (&paint_maskPR,
gimp_gegl_buffer_get_temp_buf (paint_mask),
paint_mask_rect->x,
paint_mask_rect->y,
paint_mask_rect->width,
paint_mask_rect->height);
}
else
{
pixel_region_init (&paint_maskPR,
gimp_gegl_buffer_get_tiles (paint_mask),
paint_mask_rect->x,
paint_mask_rect->y,
paint_mask_rect->width,
paint_mask_rect->height,
FALSE);
}
/* combine the mask to the canvas tiles */
combine_mask_and_region (&srcPR, &paint_maskPR,
paint_opacity * 255.999, GIMP_IS_AIRBRUSH (core));
/* temp EEK */
gimp_gegl_buffer_refetch_tiles (core->canvas_buffer);
gimp_gegl_combine_mask (paint_mask, paint_mask_rect,
core->canvas_buffer,
GEGL_RECTANGLE (core->paint_buffer_x,
core->paint_buffer_y,
width, height),
paint_opacity,
GIMP_IS_AIRBRUSH (core));
}
static void
@ -993,10 +962,11 @@ paint_mask_to_paint_buffer (GimpPaintCore *core,
const GeglRectangle *paint_mask_rect,
gdouble paint_opacity)
{
gint width = gegl_buffer_get_width (core->paint_buffer);
gint height = gegl_buffer_get_height (core->paint_buffer);
gimp_gegl_apply_mask (paint_mask, paint_mask_rect,
core->paint_buffer,
GEGL_RECTANGLE (0, 0,
gegl_buffer_get_width (core->paint_buffer),
gegl_buffer_get_height (core->paint_buffer)),
GEGL_RECTANGLE (0, 0, width, height),
paint_opacity);
}