[gimp] app: use MASK_COMPONENTS algorithm in gimp_paint_core_{paste, replace}()



commit c7d8d9ba2ee7e1ecd47d3220b0951ebb7189609b
Author: Ell <ell_se yahoo com>
Date:   Sat Feb 16 09:43:34 2019 -0500

    app: use MASK_COMPONENTS algorithm in gimp_paint_core_{paste,replace}()
    
    Remove the mask_components_onto() gimppaintcore-loops function, and
    the GimpPaintCore::comp_buffer member.  Instead, in
    gimp_paint_core_paste() and gimp_paint_core_replace(), use the
    MASK_COMPONENTS algorithm, added in the previous commit.

 app/paint/gimppaintcore-loops.cc | 74 -------------------------------
 app/paint/gimppaintcore-loops.h  |  8 ----
 app/paint/gimppaintcore.c        | 96 ++++++++++++----------------------------
 app/paint/gimppaintcore.h        |  1 -
 4 files changed, 29 insertions(+), 150 deletions(-)
---
diff --git a/app/paint/gimppaintcore-loops.cc b/app/paint/gimppaintcore-loops.cc
index f6e95d0ac4..1cabc501e6 100644
--- a/app/paint/gimppaintcore-loops.cc
+++ b/app/paint/gimppaintcore-loops.cc
@@ -2256,77 +2256,3 @@ gimp_paint_core_loops_process (const GimpPaintCoreLoopsParams *params,
     dispatch_do_layer_blend,
     dispatch_mask_components);
 }
-
-
-/* mask_components_onto():
- *
- * Copies the contents of 'src_buffer' and 'aux_buffer' into 'dst_buffer', over
- * 'roi'.  Components set in 'mask' are copied from 'aux_buffer', while those
- * not set in 'mask' are copied from 'src_buffer'.  'linear_mode' specifies
- * whether to iterate over the buffers use a linear format.  It should match
- * the linear mode of the painted-to drawable, to avoid modifying masked-out
- * components.
- *
- * Note that we don't integrate this function into the rest of the algorithm
- * framework, since it uses a (potentially) different format when iterating
- * over the buffers than the rest of the algorithms.
- */
-
-void
-mask_components_onto (GeglBuffer          *src_buffer,
-                      GeglBuffer          *aux_buffer,
-                      GeglBuffer          *dst_buffer,
-                      const GeglRectangle *roi,
-                      GimpComponentMask    mask,
-                      GimpTRCType          trc,
-                      const Babl          *space)
-{
-  const Babl *iterator_format;
-
-  if (! roi)
-    roi = gegl_buffer_get_extent (dst_buffer);
-
-  iterator_format =
-    gimp_babl_format (GIMP_RGB,
-                      gimp_babl_precision (GIMP_COMPONENT_TYPE_FLOAT, trc),
-                      TRUE, space);
-
-  gegl_parallel_distribute_area (
-    roi, PIXELS_PER_THREAD,
-    [=] (const GeglRectangle *area)
-    {
-      GeglBufferIterator *iter;
-
-      iter = gegl_buffer_iterator_new (dst_buffer, area, 0,
-                                       iterator_format,
-                                       GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE, 3);
-
-      gegl_buffer_iterator_add (iter, src_buffer, area, 0,
-                                iterator_format,
-                                GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
-
-      gegl_buffer_iterator_add (iter, aux_buffer, area, 0,
-                                iterator_format,
-                                GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
-
-      while (gegl_buffer_iterator_next (iter))
-        {
-          gfloat *dest    = (gfloat *)iter->items[0].data;
-          gfloat *src     = (gfloat *)iter->items[1].data;
-          gfloat *aux     = (gfloat *)iter->items[2].data;
-          glong   samples = iter->length;
-
-          while (samples--)
-            {
-              dest[RED]   = (mask & GIMP_COMPONENT_MASK_RED)   ? aux[RED]   : src[RED];
-              dest[GREEN] = (mask & GIMP_COMPONENT_MASK_GREEN) ? aux[GREEN] : src[GREEN];
-              dest[BLUE]  = (mask & GIMP_COMPONENT_MASK_BLUE)  ? aux[BLUE]  : src[BLUE];
-              dest[ALPHA] = (mask & GIMP_COMPONENT_MASK_ALPHA) ? aux[ALPHA] : src[ALPHA];
-
-              src  += 4;
-              aux  += 4;
-              dest += 4;
-            }
-        }
-    });
-}
diff --git a/app/paint/gimppaintcore-loops.h b/app/paint/gimppaintcore-loops.h
index afc888c926..1d7e1fd361 100644
--- a/app/paint/gimppaintcore-loops.h
+++ b/app/paint/gimppaintcore-loops.h
@@ -66,13 +66,5 @@ typedef struct
 void   gimp_paint_core_loops_process (const GimpPaintCoreLoopsParams *params,
                                       GimpPaintCoreLoopsAlgorithm     algorithms);
 
-void   mask_components_onto          (GeglBuffer                     *src_buffer,
-                                      GeglBuffer                     *aux_buffer,
-                                      GeglBuffer                     *dst_buffer,
-                                      const GeglRectangle            *roi,
-                                      GimpComponentMask               mask,
-                                      GimpTRCType                     trc,
-                                      const Babl                     *space);
-
 
 #endif /* __GIMP_PAINT_CORE_LOOPS_H__ */
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index e2f0737dec..4ff3ebca9a 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -461,27 +461,6 @@ gimp_paint_core_start (GimpPaintCore     *core,
       gimp_applicator_set_dest_buffer (core->applicator,
                                        gimp_drawable_get_buffer (drawable));
     }
-  else
-    {
-      g_clear_object (&core->comp_buffer);
-
-      /* Allocate the scratch buffer if there's a component mask */
-      if (gimp_drawable_get_active_mask (drawable) != GIMP_COMPONENT_MASK_ALL)
-        {
-          const Babl *format =
-            gimp_babl_format (GIMP_RGB,
-                              gimp_babl_precision (GIMP_COMPONENT_TYPE_FLOAT,
-                                                   gimp_drawable_get_trc (drawable)),
-                              TRUE,
-                              gimp_drawable_get_space (drawable));
-
-          core->comp_buffer =
-            gegl_buffer_new (GEGL_RECTANGLE (0, 0,
-                                             gimp_item_get_width  (item),
-                                             gimp_item_get_height (item)),
-                             format);
-        }
-    }
 
   /*  Freeze the drawable preview so that it isn't constantly updated.  */
   gimp_viewable_preview_freeze (GIMP_VIEWABLE (drawable));
@@ -509,7 +488,6 @@ gimp_paint_core_finish (GimpPaintCore *core,
     }
 
   g_clear_object (&core->mask_buffer);
-  g_clear_object (&core->comp_buffer);
 
   image = gimp_item_get_image (GIMP_ITEM (drawable));
 
@@ -787,8 +765,12 @@ gimp_paint_core_paste (GimpPaintCore            *core,
                        GimpLayerMode             paint_mode,
                        GimpPaintApplicationMode  mode)
 {
-  gint width  = gegl_buffer_get_width  (core->paint_buffer);
-  gint height = gegl_buffer_get_height (core->paint_buffer);
+  gint              width  = gegl_buffer_get_width  (core->paint_buffer);
+  gint              height = gegl_buffer_get_height (core->paint_buffer);
+  GimpComponentMask affect = gimp_drawable_get_active_mask (drawable);
+
+  if (! affect)
+    return;
 
   if (core->applicator)
     {
@@ -882,10 +864,7 @@ gimp_paint_core_paste (GimpPaintCore            *core,
       if (! params.paint_buf)
         return;
 
-      if (core->comp_buffer)
-        params.dest_buffer = core->comp_buffer;
-      else
-        params.dest_buffer = gimp_drawable_get_buffer (drawable);
+      params.dest_buffer = gimp_drawable_get_buffer (drawable);
 
       if (mode == GIMP_PAINT_CONSTANT)
         {
@@ -925,10 +904,7 @@ gimp_paint_core_paste (GimpPaintCore            *core,
           algorithms |= GIMP_PAINT_CORE_LOOPS_ALGORITHM_PAINT_MASK_TO_PAINT_BUF_ALPHA;
 
           /* dest_buffer -> paint_buf -> dest_buffer */
-          if (core->comp_buffer)
-            params.src_buffer = gimp_drawable_get_buffer (drawable);
-          else
-            params.src_buffer = params.dest_buffer;
+          params.src_buffer = params.dest_buffer;
         }
 
       params.mask_buffer   = core->mask_buffer;
@@ -939,21 +915,14 @@ gimp_paint_core_paste (GimpPaintCore            *core,
 
       algorithms |= GIMP_PAINT_CORE_LOOPS_ALGORITHM_DO_LAYER_BLEND;
 
-      gimp_paint_core_loops_process (&params, algorithms);
-
-      if (core->comp_buffer)
+      if (affect != GIMP_COMPONENT_MASK_ALL)
         {
-          mask_components_onto (params.src_buffer,
-                                core->comp_buffer,
-                                gimp_drawable_get_buffer (drawable),
-                                GEGL_RECTANGLE (core->paint_buffer_x,
-                                                core->paint_buffer_y,
-                                                width,
-                                                height),
-                                gimp_drawable_get_active_mask (drawable),
-                                gimp_drawable_get_trc (drawable),
-                                gimp_drawable_get_space (drawable));
+          params.affect = affect;
+
+          algorithms |= GIMP_PAINT_CORE_LOOPS_ALGORITHM_MASK_COMPONENTS;
         }
+
+      gimp_paint_core_loops_process (&params, algorithms);
     }
 
   /*  Update the undo extents  */
@@ -987,7 +956,8 @@ gimp_paint_core_replace (GimpPaintCore            *core,
                          gdouble                   image_opacity,
                          GimpPaintApplicationMode  mode)
 {
-  gint width, height;
+  gint              width, height;
+  GimpComponentMask affect;
 
   if (! gimp_drawable_has_alpha (drawable))
     {
@@ -1005,6 +975,11 @@ gimp_paint_core_replace (GimpPaintCore            *core,
   width  = gegl_buffer_get_width  (core->paint_buffer);
   height = gegl_buffer_get_height (core->paint_buffer);
 
+  affect = gimp_drawable_get_active_mask (drawable);
+
+  if (! affect)
+    return;
+
   if (core->applicator)
     {
       GeglRectangle  mask_rect;
@@ -1141,10 +1116,7 @@ gimp_paint_core_replace (GimpPaintCore            *core,
       if (! params.paint_buf)
         return;
 
-      if (core->comp_buffer)
-        params.dest_buffer = core->comp_buffer;
-      else
-        params.dest_buffer = gimp_drawable_get_buffer (drawable);
+      params.dest_buffer = gimp_drawable_get_buffer (drawable);
 
       if (mode == GIMP_PAINT_CONSTANT)
         {
@@ -1186,10 +1158,7 @@ gimp_paint_core_replace (GimpPaintCore            *core,
           algorithms |= GIMP_PAINT_CORE_LOOPS_ALGORITHM_PAINT_MASK_TO_COMP_MASK;
 
           /* dest_buffer -> paint_buf -> dest_buffer */
-          if (core->comp_buffer)
-            params.src_buffer = gimp_drawable_get_buffer (drawable);
-          else
-            params.src_buffer = params.dest_buffer;
+          params.src_buffer = params.dest_buffer;
         }
 
       params.mask_buffer   = core->mask_buffer;
@@ -1200,21 +1169,14 @@ gimp_paint_core_replace (GimpPaintCore            *core,
 
       algorithms |= GIMP_PAINT_CORE_LOOPS_ALGORITHM_DO_LAYER_BLEND;
 
-      gimp_paint_core_loops_process (&params, algorithms);
-
-      if (core->comp_buffer)
+      if (affect != GIMP_COMPONENT_MASK_ALL)
         {
-          mask_components_onto (params.src_buffer,
-                                core->comp_buffer,
-                                gimp_drawable_get_buffer (drawable),
-                                GEGL_RECTANGLE (core->paint_buffer_x,
-                                                core->paint_buffer_y,
-                                                width,
-                                                height),
-                                gimp_drawable_get_active_mask (drawable),
-                                gimp_drawable_get_trc (drawable),
-                                gimp_drawable_get_space (drawable));
+          params.affect = affect;
+
+          algorithms |= GIMP_PAINT_CORE_LOOPS_ALGORITHM_MASK_COMPONENTS;
         }
+
+      gimp_paint_core_loops_process (&params, algorithms);
     }
 
   /*  Update the undo extents  */
diff --git a/app/paint/gimppaintcore.h b/app/paint/gimppaintcore.h
index 350c7b0d8b..7f3eee1893 100644
--- a/app/paint/gimppaintcore.h
+++ b/app/paint/gimppaintcore.h
@@ -58,7 +58,6 @@ struct _GimpPaintCore
   GeglBuffer  *undo_buffer;       /*  pixels which have been modified     */
   GeglBuffer  *saved_proj_buffer; /*  proj tiles which have been modified */
   GeglBuffer  *canvas_buffer;     /*  the buffer to paint the mask to     */
-  GeglBuffer  *comp_buffer;       /*  scratch buffer used when masking components */
   GeglBuffer  *paint_buffer;      /*  the buffer to paint pixels to       */
   gint         paint_buffer_x;
   gint         paint_buffer_y;


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