[gimp] app: in gimppaintcore-loops, add MASK_COMPONENTS algorithm



commit 08fa46ea41d3af367c215fdde9271358834ea7e9
Author: Ell <ell_se yahoo com>
Date:   Sat Feb 16 09:37:45 2019 -0500

    app: in gimppaintcore-loops, add MASK_COMPONENTS algorithm
    
    In gimppaintcore-loops, add a new MASK_COMPONENTS algorithm, which
    masks the output of compositing into the destination buffer,
    according to a component mask.  The algorithm uses the same code as
    gimp:mask-comopnents, and can be used as part of a
    gimp_paint_core_loops_process() pipeline, instead of using a
    separate function.

 app/paint/gimppaintcore-loops.cc | 135 ++++++++++++++++++++++++++++++++++++++-
 app/paint/gimppaintcore-loops.h  |   5 +-
 2 files changed, 138 insertions(+), 2 deletions(-)
---
diff --git a/app/paint/gimppaintcore-loops.cc b/app/paint/gimppaintcore-loops.cc
index 06a39fefd1..f6e95d0ac4 100644
--- a/app/paint/gimppaintcore-loops.cc
+++ b/app/paint/gimppaintcore-loops.cc
@@ -30,6 +30,8 @@ extern "C"
 
 #include "core/gimptempbuf.h"
 
+#include "operations/gimpoperationmaskcomponents.h"
+
 #include "operations/layer-modes/gimpoperationlayermode.h"
 
 #include "gimppaintcore-loops.h"
@@ -2021,6 +2023,136 @@ static MandatoryAlgorithmDispatch<
 dispatch_do_layer_blend;
 
 
+/* MaskComponents, dispatch_mask_components():
+ *
+ * An algorithm class, implementing the MASK_COMPONENTS algorithm.
+ */
+
+template <class Base>
+struct MaskComponents : Base
+{
+  static constexpr guint filter =
+    Base::filter |
+    GIMP_PAINT_CORE_LOOPS_ALGORITHM_MASK_COMPONENTS;
+
+  static constexpr gint max_n_iterators = Base::max_n_iterators + 1;
+
+  const Babl *format;
+  const Babl *comp_fish = NULL;
+
+  explicit
+  MaskComponents (const GimpPaintCoreLoopsParams *params) :
+    Base (params)
+  {
+    format = gimp_operation_mask_components_get_format (
+      gegl_buffer_get_format (params->dest_buffer));
+
+    if (format != this->iterator_format)
+      comp_fish = babl_fish (this->iterator_format, format);
+  }
+
+  template <class Derived>
+  struct State : Base::template State<Derived>
+  {
+    gint    dest_buffer_iterator;
+
+    guint8 *dest_pixel;
+    guint8 *comp_pixel;
+  };
+
+  template <class Derived>
+  void
+  init (const GimpPaintCoreLoopsParams *params,
+        State<Derived>                 *state,
+        GeglBufferIterator             *iter,
+        const GeglRectangle            *roi,
+        const GeglRectangle            *area) const
+  {
+    state->dest_buffer_iterator = gegl_buffer_iterator_add (
+      iter, params->dest_buffer, area, 0, format,
+      GEGL_ACCESS_READWRITE, GEGL_ABYSS_NONE);
+
+    /* initialize the base class *after* initializing the iterator, to make
+     * sure that dest_buffer is the primary buffer of the iterator, if no
+     * subclass added an iterator first.
+     */
+    Base::init (params, state, iter, roi, area);
+  }
+
+  template <class Derived>
+  void
+  init_step (const GimpPaintCoreLoopsParams *params,
+             State<Derived>                 *state,
+             GeglBufferIterator             *iter,
+             const GeglRectangle            *roi,
+             const GeglRectangle            *area,
+             const GeglRectangle            *rect) const
+  {
+    Base::init_step (params, state, iter, roi, area, rect);
+
+    state->dest_pixel =
+      (guint8 *) iter->items[state->dest_buffer_iterator].data;
+
+    if (comp_fish)
+      {
+        state->comp_pixel = (guint8 *) gegl_scratch_alloc (
+          rect->width * babl_format_get_bytes_per_pixel (format));
+      }
+  }
+
+  template <class Derived>
+  void
+  process_row (const GimpPaintCoreLoopsParams *params,
+               State<Derived>                 *state,
+               GeglBufferIterator             *iter,
+               const GeglRectangle            *roi,
+               const GeglRectangle            *area,
+               const GeglRectangle            *rect,
+               gint                            y) const
+  {
+    Base::process_row (params, state, iter, roi, area, rect, y);
+
+    gpointer comp_pixel;
+
+    if (comp_fish)
+      {
+        babl_process (comp_fish,
+                      state->comp_buffer_data, state->comp_pixel,
+                      rect->width);
+
+        comp_pixel = state->comp_pixel;
+      }
+    else
+      {
+        comp_pixel = state->comp_buffer_data;
+      }
+
+    gimp_operation_mask_components_process (format,
+                                            state->dest_pixel, comp_pixel,
+                                            state->dest_pixel,
+                                            rect->width, params->affect);
+
+    state->dest_pixel += rect->width * babl_format_get_bytes_per_pixel (format);
+  }
+
+  template <class Derived>
+  void
+  finalize_step (const GimpPaintCoreLoopsParams *params,
+                 State<Derived>                 *state) const
+  {
+    if (comp_fish)
+      gegl_scratch_free (state->comp_pixel);
+  }
+};
+
+static AlgorithmDispatch<
+  MaskComponents,
+  GIMP_PAINT_CORE_LOOPS_ALGORITHM_MASK_COMPONENTS,
+  decltype (dispatch_temp_comp_buffer)
+>
+dispatch_mask_components;
+
+
 /* gimp_paint_core_loops_process():
  *
  * Performs the set of algorithms requested in 'algorithms', specified as a
@@ -2121,7 +2253,8 @@ gimp_paint_core_loops_process (const GimpPaintCoreLoopsParams *params,
     dispatch_paint_mask_to_paint_buf_alpha,
     dispatch_canvas_buffer_to_comp_mask,
     dispatch_paint_mask_to_comp_mask,
-    dispatch_do_layer_blend);
+    dispatch_do_layer_blend,
+    dispatch_mask_components);
 }
 
 
diff --git a/app/paint/gimppaintcore-loops.h b/app/paint/gimppaintcore-loops.h
index 36974d5e27..afc888c926 100644
--- a/app/paint/gimppaintcore-loops.h
+++ b/app/paint/gimppaintcore-loops.h
@@ -28,7 +28,8 @@ typedef enum
   GIMP_PAINT_CORE_LOOPS_ALGORITHM_PAINT_MASK_TO_PAINT_BUF_ALPHA       = 1 << 2,
   GIMP_PAINT_CORE_LOOPS_ALGORITHM_CANVAS_BUFFER_TO_COMP_MASK          = 1 << 3,
   GIMP_PAINT_CORE_LOOPS_ALGORITHM_PAINT_MASK_TO_COMP_MASK             = 1 << 4,
-  GIMP_PAINT_CORE_LOOPS_ALGORITHM_DO_LAYER_BLEND                      = 1 << 5
+  GIMP_PAINT_CORE_LOOPS_ALGORITHM_DO_LAYER_BLEND                      = 1 << 5,
+  GIMP_PAINT_CORE_LOOPS_ALGORITHM_MASK_COMPONENTS                     = 1 << 6
 } GimpPaintCoreLoopsAlgorithm;
 
 
@@ -57,6 +58,8 @@ typedef struct
   gdouble            image_opacity;
 
   GimpLayerMode      paint_mode;
+
+  GimpComponentMask  affect;
 } GimpPaintCoreLoopsParams;
 
 


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