[gimp] app: add gimp_gegl_combine_mask() and use it in GimpPaintCore
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add gimp_gegl_combine_mask() and use it in GimpPaintCore
- Date: Wed, 2 May 2012 16:43:08 +0000 (UTC)
commit 4772d3e832d0e580105a9a524af08d40a59b61ad
Author: Michael Natterer <mitch gimp org>
Date: Mon Apr 23 12:51:11 2012 +0200
app: add gimp_gegl_combine_mask() and use it in GimpPaintCore
app/gegl/gimp-gegl-loops.c | 47 +++++++++++++++++++++++++++++
app/gegl/gimp-gegl-loops.h | 7 ++++
app/paint/gimppaintcore.c | 70 ++++++++++++-------------------------------
3 files changed, 74 insertions(+), 50 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-loops.c b/app/gegl/gimp-gegl-loops.c
index 9fab06a..badf5f8 100644
--- a/app/gegl/gimp-gegl-loops.c
+++ b/app/gegl/gimp-gegl-loops.c
@@ -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;
+ }
+ }
+ }
+}
diff --git a/app/gegl/gimp-gegl-loops.h b/app/gegl/gimp-gegl-loops.h
index 75dc0e9..76e6fe7 100644
--- a/app/gegl/gimp-gegl-loops.h
+++ b/app/gegl/gimp-gegl-loops.h
@@ -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__ */
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index 55854f7..068b9c7 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]