[gimp/goat-invasion] app: add gimp_gegl_apply_mask() and use it in GimpPaintCore



commit c995a76e1d8d6fad18a59fce78ba38ef3d136b9c
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 23 11:28:16 2012 +0200

    app: add gimp_gegl_apply_mask() and use it in GimpPaintCore

 app/gegl/gimp-gegl-loops.c |   32 +++++++++++++++
 app/gegl/gimp-gegl-loops.h |    6 +++
 app/paint/gimppaintcore.c  |   96 +++++++++++++++-----------------------------
 3 files changed, 70 insertions(+), 64 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-loops.c b/app/gegl/gimp-gegl-loops.c
index 7c8243b..9fab06a 100644
--- a/app/gegl/gimp-gegl-loops.c
+++ b/app/gegl/gimp-gegl-loops.c
@@ -391,3 +391,35 @@ gimp_gegl_smudge_blend (GeglBuffer          *top_buffer,
         }
     }
 }
+
+void
+gimp_gegl_apply_mask (GeglBuffer          *mask_buffer,
+                      const GeglRectangle *mask_rect,
+                      GeglBuffer          *dest_buffer,
+                      const GeglRectangle *dest_rect,
+                      gdouble              opacity)
+{
+  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 ("RGBA float"),
+                            GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE);
+
+  while (gegl_buffer_iterator_next (iter))
+    {
+      const gfloat *mask = iter->data[0];
+      gfloat       *dest = iter->data[1];
+
+      while (iter->length--)
+        {
+          dest[3] *= *mask * opacity;
+
+          mask += 1;
+          dest += 4;
+        }
+    }
+}
diff --git a/app/gegl/gimp-gegl-loops.h b/app/gegl/gimp-gegl-loops.h
index a85bb5b..75dc0e9 100644
--- a/app/gegl/gimp-gegl-loops.h
+++ b/app/gegl/gimp-gegl-loops.h
@@ -51,5 +51,11 @@ void   gimp_gegl_smudge_blend (GeglBuffer          *top_buffer,
                                const GeglRectangle *dest_rect,
                                guchar               blend);
 
+void   gimp_gegl_apply_mask   (GeglBuffer          *mask_buffer,
+                               const GeglRectangle *mask_rect,
+                               GeglBuffer          *dest_buffer,
+                               const GeglRectangle *dest_rect,
+                               gdouble              opacity);
+
 
 #endif /* __GIMP_GEGL_LOOPS_H__ */
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index 9642c4a..55854f7 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -30,9 +30,11 @@
 
 #include "paint-funcs/paint-funcs.h"
 
+#include "gegl/gimp-gegl-loops.h"
 #include "gegl/gimp-gegl-utils.h"
 
 #include "core/gimp.h"
+#include "core/gimp-apply-operation.h"
 #include "core/gimp-utils.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpimage.h"
@@ -110,11 +112,11 @@ static void      paint_mask_to_canvas_buffer         (GimpPaintCore       *core,
                                                       GeglBuffer          *paint_mask,
                                                       const GeglRectangle *paint_mask_rect,
                                                       gdouble              paint_opacity);
-static void      paint_mask_to_paint_area            (GimpPaintCore       *core,
+static void      paint_mask_to_paint_buffer          (GimpPaintCore       *core,
                                                       GeglBuffer          *paint_mask,
                                                       const GeglRectangle *paint_mask_rect,
                                                       gdouble              paint_opacity);
-static void      canvas_buffer_to_paint_area         (GimpPaintCore       *core);
+static void      canvas_buffer_to_paint_buffer       (GimpPaintCore       *core);
 
 
 G_DEFINE_TYPE (GimpPaintCore, gimp_paint_core, GIMP_TYPE_OBJECT)
@@ -736,7 +738,7 @@ gimp_paint_core_paste (GimpPaintCore            *core,
                                        paint_opacity);
         }
 
-      canvas_buffer_to_paint_area (core);
+      canvas_buffer_to_paint_buffer (core);
 
       base_buffer = core->undo_buffer;
     }
@@ -745,8 +747,8 @@ gimp_paint_core_paste (GimpPaintCore            *core,
    */
   else
     {
-      paint_mask_to_paint_area (core, paint_mask, paint_mask_rect,
-                                paint_opacity);
+      paint_mask_to_paint_buffer (core, paint_mask, paint_mask_rect,
+                                  paint_opacity);
     }
 
   width  = gegl_buffer_get_width  (core->paint_buffer);
@@ -924,30 +926,19 @@ gimp_paint_core_smooth_coords (GimpPaintCore    *core,
 
 }
 
-
 static void
-canvas_buffer_to_paint_area (GimpPaintCore *core)
+canvas_buffer_to_paint_buffer (GimpPaintCore *core)
 {
-  PixelRegion srcPR;
-  PixelRegion maskPR;
-
-  /*  combine the canvas buffer and the paint area  */
-  pixel_region_init_temp_buf (&srcPR,
-                              gimp_gegl_buffer_get_temp_buf (core->paint_buffer),
-                              0, 0,
-                              gegl_buffer_get_width  (core->paint_buffer),
-                              gegl_buffer_get_height (core->paint_buffer));
-
-  pixel_region_init (&maskPR,
-                     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),
-                     FALSE);
-
-  /*  apply the canvas buffer to the paint area  */
-  apply_mask_to_region (&srcPR, &maskPR, OPAQUE_OPACITY);
+  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)),
+                        core->paint_buffer,
+                        GEGL_RECTANGLE (0, 0,
+                                        gegl_buffer_get_width  (core->paint_buffer),
+                                        gegl_buffer_get_height (core->paint_buffer)),
+                        1.0);
 }
 
 static void
@@ -991,44 +982,21 @@ paint_mask_to_canvas_buffer (GimpPaintCore       *core,
   /*  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);
 }
 
 static void
-paint_mask_to_paint_area (GimpPaintCore       *core,
-                          GeglBuffer          *paint_mask,
-                          const GeglRectangle *paint_mask_rect,
-                          gdouble              paint_opacity)
-{
-  PixelRegion srcPR;
-  PixelRegion paint_maskPR;
-
-  /*  combine the canvas buf and the paint mask to the canvas buf  */
-  pixel_region_init_temp_buf (&srcPR,
-                              gimp_gegl_buffer_get_temp_buf (core->paint_buffer),
-                              0, 0,
-                              gegl_buffer_get_width  (core->paint_buffer),
-                              gegl_buffer_get_height (core->paint_buffer));
-
-  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);
-    }
-
-  /*  apply the mask  */
-  apply_mask_to_region (&srcPR, &paint_maskPR, paint_opacity * 255.999);
+paint_mask_to_paint_buffer (GimpPaintCore       *core,
+                            GeglBuffer          *paint_mask,
+                            const GeglRectangle *paint_mask_rect,
+                            gdouble              paint_opacity)
+{
+  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)),
+                        paint_opacity);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]