[gegl] add gegl_operation_get_source_format



commit 12bcf52d30bc6051261e1ae5937933fab2cfd397
Author: Ãyvind KolÃs <pippin gimp org>
Date:   Sat Dec 29 12:58:40 2012 +1100

    add gegl_operation_get_source_format
    
    This provides a way of checking the BablFormat of a given pad in the final
    "prepare" of the operation and after, making it possible to rejig properties
    or similar to achieve format/precision/etc dependent processing.

 gegl/operation/gegl-operation.c |   16 ++++++++++++++++
 gegl/operation/gegl-operation.h |    8 +++++++-
 operations/common/opacity.c     |   28 +++++++++-------------------
 3 files changed, 32 insertions(+), 20 deletions(-)
---
diff --git a/gegl/operation/gegl-operation.c b/gegl/operation/gegl-operation.c
index 5075011..97604bc 100644
--- a/gegl/operation/gegl-operation.c
+++ b/gegl/operation/gegl-operation.c
@@ -720,3 +720,19 @@ gegl_operation_get_key (const gchar *operation_name,
   g_type_class_unref (klass);
   return ret;
 }
+
+const Babl *
+gegl_operation_get_source_format (GeglOperation *operation,
+                                  const gchar   *padname)
+{
+  GeglNode *src_node = gegl_operation_get_source_node (operation, padname);
+
+  if (src_node)
+    {
+      GeglOperation *op = src_node->operation;
+      if (op)
+        return gegl_operation_get_format (op, "output");
+            /* XXX: could be a different pad than "output" */
+    }
+  return NULL;
+}
diff --git a/gegl/operation/gegl-operation.h b/gegl/operation/gegl-operation.h
index fc7abfe..d86d1fa 100644
--- a/gegl/operation/gegl-operation.h
+++ b/gegl/operation/gegl-operation.h
@@ -211,8 +211,14 @@ const Babl *    gegl_operation_get_format    (GeglOperation *operation,
 const gchar *   gegl_operation_get_name      (GeglOperation *operation);
 
 
+/* checks the incoming Babl format on a given pad, can be used in the prepare
+ * stage to make format dependent decisions
+ */
+const Babl  * gegl_operation_get_source_format (GeglOperation *operation,
+                                                const gchar   *padname);
+
 /* retrieves the node providing data to a named input pad */
-GeglNode      * gegl_operation_get_source_node (GeglOperation *operation,
+GeglNode    * gegl_operation_get_source_node   (GeglOperation *operation,
                                                 const gchar   *pad_name);
 
 GParamSpec ** gegl_operation_list_properties   (const gchar *operation_type,
diff --git a/operations/common/opacity.c b/operations/common/opacity.c
index 5c50cbb..4df4867 100644
--- a/operations/common/opacity.c
+++ b/operations/common/opacity.c
@@ -30,33 +30,23 @@ gegl_chant_double (value, _("Opacity"), -10.0, 10.0, 1.0,
 #define GEGL_CHANT_C_FILE       "opacity.c"
 
 #include "gegl-chant.h"
-#include "graph/gegl-node.h"
 
 #include <stdio.h>
 
+
 static void prepare (GeglOperation *self)
 {
-  GeglNode *src_node = gegl_operation_get_source_node (self, "input");
+  const Babl *fmt = gegl_operation_get_source_format (self, "input");
   GeglChantO *o = GEGL_CHANT_PROPERTIES (self);
 
-  if (src_node)
+  if (fmt == babl_format ("RGBA float"))
     {
-      GeglOperation *op = src_node->operation;
-      if (op)
-        {
-          const Babl *fmt = gegl_operation_get_format (op, "output"); /* XXX: could
-                                                         be a different pad */
-
-          if (fmt == babl_format ("RGBA float"))
-            {
-              /* ugly way of communicating that we want the RGBA version */
-              o->chant_data = (void*)0xabc;
-              gegl_operation_set_format (self, "input", babl_format ("RGBA float"));
-              gegl_operation_set_format (self, "output", babl_format ("RGBA float"));
-              gegl_operation_set_format (self, "aux", babl_format ("Y float"));
-              return;
-            }
-        }
+      gegl_operation_set_format (self, "input", babl_format ("RGBA float"));
+      gegl_operation_set_format (self, "output", babl_format ("RGBA float"));
+      gegl_operation_set_format (self, "aux", babl_format ("Y float"));
+      /* ugly way of communicating that we want the RGBA version */
+      o->chant_data = (void*)0xabc;
+      return;
     }
   o->chant_data = NULL;
   gegl_operation_set_format (self, "input", babl_format ("RaGaBaA float"));



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