[gimp/gimp-2-10] app: in gimppaintcore-loops, add MASK_COMPONENTS algorithm
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] app: in gimppaintcore-loops, add MASK_COMPONENTS algorithm
- Date: Sat, 16 Feb 2019 15:04:45 +0000 (UTC)
commit c4430b3debe36d1bdce612b329a8d7c7818e579a
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.
(cherry picked from commit 08fa46ea41d3af367c215fdde9271358834ea7e9)
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 4529c18fec..ba7944f15c 100644
--- a/app/paint/gimppaintcore-loops.cc
+++ b/app/paint/gimppaintcore-loops.cc
@@ -28,6 +28,8 @@ extern "C"
#include "core/gimptempbuf.h"
+#include "operations/gimpoperationmaskcomponents.h"
+
#include "operations/layer-modes/gimpoperationlayermode.h"
#include "gimppaintcore-loops.h"
@@ -2019,6 +2021,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
@@ -2119,7 +2251,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 a2d5c2efcd..ec95571774 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]