[gimp] app: add dedicated op for pass through mode, with shortcuts



commit 5effdd03b4dd018fdf5469cd2e9a97301969b694
Author: Ell <ell_se yahoo com>
Date:   Thu Aug 31 11:20:37 2017 -0400

    app: add dedicated op for pass through mode, with shortcuts
    
    Pass through mode uses the same compositing logic as REPLACE mode,
    however, it's a special case of REPLACE, where the layer is already
    composited against the backdrop.  This allows us to take a few
    shortcuts that aren't generally applicable to REPLACE mode.
    
    Add a dedicated op class for pass through mode, derived from the
    REPLACE mode op, implementing these shortcuts.

 app/operations/gimp-operations.c                   |    2 +
 app/operations/layer-modes/Makefile.am             |    2 +
 app/operations/layer-modes/gimp-layer-modes.c      |    2 +-
 .../layer-modes/gimpoperationpassthrough.c         |  106 ++++++++++++++++++++
 .../layer-modes/gimpoperationpassthrough.h         |   54 ++++++++++
 5 files changed, 165 insertions(+), 1 deletions(-)
---
diff --git a/app/operations/gimp-operations.c b/app/operations/gimp-operations.c
index 513794a..aba46c4 100644
--- a/app/operations/gimp-operations.c
+++ b/app/operations/gimp-operations.c
@@ -92,6 +92,7 @@
 #include "layer-modes/gimpoperationerase.h"
 #include "layer-modes/gimpoperationmerge.h"
 #include "layer-modes/gimpoperationnormal.h"
+#include "layer-modes/gimpoperationpassthrough.h"
 #include "layer-modes/gimpoperationreplace.h"
 #include "layer-modes/gimpoperationsplit.h"
 
@@ -175,6 +176,7 @@ gimp_operations_init (Gimp *gimp)
   g_type_class_ref (GIMP_TYPE_OPERATION_ERASE);
   g_type_class_ref (GIMP_TYPE_OPERATION_MERGE);
   g_type_class_ref (GIMP_TYPE_OPERATION_SPLIT);
+  g_type_class_ref (GIMP_TYPE_OPERATION_PASS_THROUGH);
   g_type_class_ref (GIMP_TYPE_OPERATION_REPLACE);
   g_type_class_ref (GIMP_TYPE_OPERATION_ANTI_ERASE);
 
diff --git a/app/operations/layer-modes/Makefile.am b/app/operations/layer-modes/Makefile.am
index 9bd64b9..24af8fe 100644
--- a/app/operations/layer-modes/Makefile.am
+++ b/app/operations/layer-modes/Makefile.am
@@ -40,6 +40,8 @@ libapplayermodes_generic_a_sources = \
        gimpoperationmerge.h                    \
        gimpoperationnormal.c                   \
        gimpoperationnormal.h                   \
+       gimpoperationpassthrough.c              \
+       gimpoperationpassthrough.h              \
        gimpoperationreplace.c                  \
        gimpoperationreplace.h                  \
        gimpoperationsplit.c                    \
diff --git a/app/operations/layer-modes/gimp-layer-modes.c b/app/operations/layer-modes/gimp-layer-modes.c
index cc29dc6..528102d 100644
--- a/app/operations/layer-modes/gimp-layer-modes.c
+++ b/app/operations/layer-modes/gimp-layer-modes.c
@@ -800,7 +800,7 @@ static const GimpLayerModeInfo layer_mode_infos[] =
 
   { GIMP_LAYER_MODE_PASS_THROUGH,
 
-    .op_name              = "gimp:replace",
+    .op_name              = "gimp:pass-through",
     .flags                = GIMP_LAYER_MODE_FLAG_BLEND_SPACE_IMMUTABLE |
                             GIMP_LAYER_MODE_FLAG_COMPOSITE_MODE_IMMUTABLE,
     .context              = GIMP_LAYER_MODE_CONTEXT_GROUP,
diff --git a/app/operations/layer-modes/gimpoperationpassthrough.c 
b/app/operations/layer-modes/gimpoperationpassthrough.c
new file mode 100644
index 0000000..ce33bac
--- /dev/null
+++ b/app/operations/layer-modes/gimpoperationpassthrough.c
@@ -0,0 +1,106 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpoperationpassthrough.c
+ * Copyright (C) 2008 Michael Natterer <mitch gimp org>
+ *               2017 Ell
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl-plugin.h>
+
+#include "../operations-types.h"
+
+#include "gimp-layer-modes.h"
+#include "gimpoperationpassthrough.h"
+
+
+static gboolean   gimp_operation_pass_through_parent_process (GeglOperation        *operation,
+                                                              GeglOperationContext *context,
+                                                              const gchar          *output_prop,
+                                                              const GeglRectangle  *result,
+                                                              gint                  level);
+
+
+G_DEFINE_TYPE (GimpOperationPassThrough, gimp_operation_pass_through,
+               GIMP_TYPE_OPERATION_REPLACE)
+
+#define parent_class gimp_operation_pass_through_parent_class
+
+
+static void
+gimp_operation_pass_through_class_init (GimpOperationPassThroughClass *klass)
+{
+  GeglOperationClass          *operation_class  = GEGL_OPERATION_CLASS (klass);
+  GimpOperationLayerModeClass *layer_mode_class = GIMP_OPERATION_LAYER_MODE_CLASS (klass);
+
+  gegl_operation_class_set_keys (operation_class,
+                                 "name",        "gimp:pass-through",
+                                 "description", "GIMP pass through mode operation",
+                                 NULL);
+
+  operation_class->process              = gimp_operation_pass_through_parent_process;
+
+  /* don't use REPLACE mode's specialized get_affected_region(); PASS_THROUGH
+   * behaves like an ordinary layer mode here.
+   */
+  layer_mode_class->get_affected_region = NULL;
+}
+
+static void
+gimp_operation_pass_through_init (GimpOperationPassThrough *self)
+{
+}
+
+static gboolean
+gimp_operation_pass_through_parent_process (GeglOperation        *operation,
+                                            GeglOperationContext *context,
+                                            const gchar          *output_prop,
+                                            const GeglRectangle  *result,
+                                            gint                  level)
+{
+  GimpOperationLayerMode *layer_mode = (gpointer) operation;
+
+  /* if the layer's opacity is 100%, it has no mask, and its composite mode
+   * contains "aux" (the latter should always be the case for pass through
+   * mode,) we can just pass "aux" directly as output.  note that the same
+   * optimization would more generally apply to REPLACE mode, save for the fact
+   * that when both the backdrop and the layer have a pixel with 0% alpha, we
+   * want to maintain the color value of the backdrop, not the layer; since,
+   * for pass through groups, the layer is already composited against the
+   * backdrop, such pixels will have the same color value for both the backdrop
+   * and the layer.
+   */
+  if (layer_mode->opacity == 1.0                            &&
+      ! gegl_operation_context_get_object (context, "aux2") &&
+      (gimp_layer_mode_get_included_region (layer_mode->layer_mode,
+                                            layer_mode->real_composite_mode) &
+       GIMP_LAYER_COMPOSITE_REGION_SOURCE))
+    {
+      GObject *aux;
+
+      aux = gegl_operation_context_get_object (context, "aux");
+
+      gegl_operation_context_set_object (context, "output", aux);
+
+      return TRUE;
+    }
+
+  return GEGL_OPERATION_CLASS (parent_class)->process (operation, context,
+                                                       output_prop, result,
+                                                       level);
+}
diff --git a/app/operations/layer-modes/gimpoperationpassthrough.h 
b/app/operations/layer-modes/gimpoperationpassthrough.h
new file mode 100644
index 0000000..8bf1fa6
--- /dev/null
+++ b/app/operations/layer-modes/gimpoperationpassthrough.h
@@ -0,0 +1,54 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpoperationpassthrough.h
+ * Copyright (C) 2008 Michael Natterer <mitch gimp org>
+ *               2017 Ell
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_OPERATION_PASS_THROUGH_H__
+#define __GIMP_OPERATION_PASS_THROUGH_H__
+
+
+#include "gimpoperationreplace.h"
+
+
+#define GIMP_TYPE_OPERATION_PASS_THROUGH            (gimp_operation_pass_through_get_type ())
+#define GIMP_OPERATION_PASS_THROUGH(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GIMP_TYPE_OPERATION_PASS_THROUGH, GimpOperationPassThrough))
+#define GIMP_OPERATION_PASS_THROUGH_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
GIMP_TYPE_OPERATION_PASS_THROUGH, GimpOperationPassThroughClass))
+#define GIMP_IS_OPERATION_PASS_THROUGH(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GIMP_TYPE_OPERATION_PASS_THROUGH))
+#define GIMP_IS_OPERATION_PASS_THROUGH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
GIMP_TYPE_OPERATION_PASS_THROUGH))
+#define GIMP_OPERATION_PASS_THROUGH_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
GIMP_TYPE_OPERATION_PASS_THROUGH, GimpOperationPassThroughClass))
+
+
+typedef struct _GimpOperationPassThrough      GimpOperationPassThrough;
+typedef struct _GimpOperationPassThroughClass GimpOperationPassThroughClass;
+
+struct _GimpOperationPassThrough
+{
+  GimpOperationReplace parent_instance;
+};
+
+struct _GimpOperationPassThroughClass
+{
+  GimpOperationReplaceClass parent_class;
+};
+
+
+GType   gimp_operation_pass_through_get_type (void) G_GNUC_CONST;
+
+
+#endif /* __GIMP_OPERATION_PASS_THROUGH_H__ */


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