[gimp] app: add gimp_gegl_node_set_color() and use it in GimpChannel



commit 41c92af49b2b31a88a8823c43e815c32104a9a04
Author: Michael Natterer <mitch gimp org>
Date:   Sat Oct 19 17:31:32 2013 +0200

    app: add gimp_gegl_node_set_color() and use it in GimpChannel

 app/core/gimpchannel.c     |   26 ++++++--------------------
 app/gegl/gimp-gegl-nodes.c |   21 +++++++++++++++++++++
 app/gegl/gimp-gegl-nodes.h |    2 ++
 3 files changed, 29 insertions(+), 20 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index f8517eb..fa24fb1 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -401,7 +401,6 @@ gimp_channel_get_node (GimpFilter *filter)
   GeglNode     *node;
   GeglNode     *source;
   GeglNode     *mode_node;
-  GeglColor    *color;
   const Babl   *color_format;
 
   node = GIMP_FILTER_CLASS (parent_class)->get_node (filter);
@@ -409,8 +408,6 @@ gimp_channel_get_node (GimpFilter *filter)
   source = gimp_drawable_get_source_node (drawable);
   gegl_node_add_child (node, source);
 
-  color = gimp_gegl_color_new (&channel->color);
-
   g_warn_if_fail (channel->color_node == NULL);
 
   if (gimp_drawable_get_linear (drawable))
@@ -420,11 +417,10 @@ gimp_channel_get_node (GimpFilter *filter)
 
   channel->color_node = gegl_node_new_child (node,
                                              "operation", "gegl:color",
-                                             "value",     color,
                                              "format",    color_format,
                                              NULL);
-
-  g_object_unref (color);
+  gimp_gegl_node_set_color (channel->color_node,
+                            &channel->color);
 
   g_warn_if_fail (channel->mask_node == NULL);
 
@@ -1699,13 +1695,8 @@ gimp_channel_set_color (GimpChannel   *channel,
 
       if (gimp_filter_peek_node (GIMP_FILTER (channel)))
         {
-          GeglColor *gegl_color = gimp_gegl_color_new (&channel->color);
-
-          gegl_node_set (channel->color_node,
-                         "value", gegl_color,
-                         NULL);
-
-          g_object_unref (gegl_color);
+          gimp_gegl_node_set_color (channel->color_node,
+                                    &channel->color);
         }
 
       gimp_drawable_update (GIMP_DRAWABLE (channel),
@@ -1758,13 +1749,8 @@ gimp_channel_set_opacity (GimpChannel *channel,
 
       if (gimp_filter_peek_node (GIMP_FILTER (channel)))
         {
-          GeglColor *gegl_color = gimp_gegl_color_new (&channel->color);
-
-          gegl_node_set (channel->color_node,
-                         "value", gegl_color,
-                         NULL);
-
-          g_object_unref (gegl_color);
+          gimp_gegl_node_set_color (channel->color_node,
+                                    &channel->color);
         }
 
       gimp_drawable_update (GIMP_DRAWABLE (channel),
diff --git a/app/gegl/gimp-gegl-nodes.c b/app/gegl/gimp-gegl-nodes.c
index 592a8a1..42ff698 100644
--- a/app/gegl/gimp-gegl-nodes.c
+++ b/app/gegl/gimp-gegl-nodes.c
@@ -184,6 +184,9 @@ gimp_gegl_mode_node_set_mode (GeglNode             *node,
                  "opacity", &opacity,
                  NULL);
 
+  /* setting the operation creates a new instance, so we have to set
+   * all its properties
+   */
   gegl_node_set (node,
                  "operation", operation,
                  "linear",    linear,
@@ -219,3 +222,21 @@ gimp_gegl_node_set_matrix (GeglNode          *node,
 
   g_free (matrix_string);
 }
+
+void
+gimp_gegl_node_set_color (GeglNode      *node,
+                          const GimpRGB *color)
+{
+  GeglColor *gegl_color;
+
+  g_return_if_fail (GEGL_IS_NODE (node));
+  g_return_if_fail (color != NULL);
+
+  gegl_color = gimp_gegl_color_new (color);
+
+  gegl_node_set (node,
+                 "value", gegl_color,
+                 NULL);
+
+  g_object_unref (gegl_color);
+}
diff --git a/app/gegl/gimp-gegl-nodes.h b/app/gegl/gimp-gegl-nodes.h
index ba7ae70..619c023 100644
--- a/app/gegl/gimp-gegl-nodes.h
+++ b/app/gegl/gimp-gegl-nodes.h
@@ -39,6 +39,8 @@ void       gimp_gegl_mode_node_set_opacity     (GeglNode             *node,
                                                 gdouble               opacity);
 void       gimp_gegl_node_set_matrix           (GeglNode             *node,
                                                 const GimpMatrix3    *matrix);
+void       gimp_gegl_node_set_color            (GeglNode             *node,
+                                                const GimpRGB        *color);
 
 
 #endif /* __GIMP_GEGL_NODES_H__ */


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