[gimp/goat-invasion: 571/608] app: special case REPLACE_MODE in gimp_gegl_create_apply_buffer_node()



commit c6de5b46f6b7c437a1360e864eb3844197294d56
Author: Michael Natterer <mitch gimp org>
Date:   Tue Apr 24 16:42:06 2012 +0200

    app: special case REPLACE_MODE in gimp_gegl_create_apply_buffer_node()
    
    it needs the mask/opacity on a separate input.

 app/gegl/gimp-gegl-nodes.c |   75 ++++++++++++++++++++++++++++++++-----------
 1 files changed, 56 insertions(+), 19 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-nodes.c b/app/gegl/gimp-gegl-nodes.c
index a750634..63e63ee 100644
--- a/app/gegl/gimp-gegl-nodes.c
+++ b/app/gegl/gimp-gegl-nodes.c
@@ -124,7 +124,6 @@ gimp_gegl_create_apply_buffer_node (GeglBuffer           *buffer,
   GeglNode *output;
   GeglNode *buffer_source;
   GeglNode *mask_source;
-  GeglNode *opacity_node;
   GeglNode *mode_node;
 
   g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
@@ -177,29 +176,67 @@ gimp_gegl_create_apply_buffer_node (GeglBuffer           *buffer,
   else
     mask_source = NULL;
 
-  opacity_node = gegl_node_new_child (node,
-                                      "operation", "gegl:opacity",
-                                      "value",     opacity,
-                                      NULL);
-
-  gegl_node_connect_to (buffer_source, "output",
-                        opacity_node,  "input");
-
-  if (mask_source)
-    gegl_node_connect_to (mask_source,   "output",
-                          opacity_node,  "aux");
-
   mode_node = gegl_node_new_child (node,
                                    "operation", "gegl:over",
                                    NULL);
   gimp_gegl_node_set_layer_mode (mode_node, mode, FALSE);
 
-  gegl_node_connect_to (opacity_node, "output",
-                        mode_node,    "aux");
-  gegl_node_connect_to (input,        "output",
-                        mode_node,    "input");
-  gegl_node_connect_to (mode_node,    "output",
-                        output,       "input");
+  if (mode == GIMP_REPLACE_MODE)
+    {
+      /*  modes that need access to the buffer's alpha channel are
+       *  implemented using GeglOperationPointComposer3 subclasses,
+       *  and have an "opacity" property, so they have access to all
+       *  sources of transparency independently
+       */
+
+      gegl_node_set (mode_node,
+                     "opacity", opacity,
+                     NULL);
+
+      gegl_node_connect_to (buffer_source, "output",
+                            mode_node,     "aux");
+
+      if (mask_source)
+        gegl_node_connect_to (mask_source, "output",
+                              mode_node,   "aux2");
+    }
+  else if (mask_source || opacity < 1.0)
+    {
+      /*  normal case: put the buffer through an opacity node that
+       *  applies mask and opacity before doing the actual mode
+       */
+
+      GeglNode *opacity_node;
+
+      opacity_node = gegl_node_new_child (node,
+                                          "operation", "gegl:opacity",
+                                          "value",     opacity,
+                                          NULL);
+
+      gegl_node_connect_to (buffer_source, "output",
+                            opacity_node,  "input");
+
+      if (mask_source)
+        gegl_node_connect_to (mask_source,   "output",
+                              opacity_node,  "aux");
+
+      gegl_node_connect_to (opacity_node, "output",
+                            mode_node,    "aux");
+    }
+  else
+    {
+      /*  shortcut for the case where the opacity node wouldn't do
+       *  anything
+       */
+
+      gegl_node_connect_to (buffer_source, "output",
+                            mode_node,     "aux");
+    }
+
+  gegl_node_connect_to (input,     "output",
+                        mode_node, "input");
+  gegl_node_connect_to (mode_node, "output",
+                        output,    "input");
 
   return node;
 }



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