gimp r27216 - in trunk: . app/core



Author: mitch
Date: Fri Oct 10 21:18:24 2008
New Revision: 27216
URL: http://svn.gnome.org/viewvc/gimp?rev=27216&view=rev

Log:
2008-10-10  Michael Natterer  <mitch gimp org>

	* app/core/gimpdrawablestack.[ch]: move all the code that creates
	a graph of drawables and all adding/removing/reordering code from
	GimpImage to this file.

	* app/core/gimpimage.c: remove the code here and use the layer
	stack's subgraph instead. Add #if 0'ed code that blends the
	channels on top of that but that doesn't work because channels
	don't provide nodes yet.



Modified:
   trunk/ChangeLog
   trunk/app/core/gimpdrawablestack.c
   trunk/app/core/gimpdrawablestack.h
   trunk/app/core/gimpimage.c

Modified: trunk/app/core/gimpdrawablestack.c
==============================================================================
--- trunk/app/core/gimpdrawablestack.c	(original)
+++ trunk/app/core/gimpdrawablestack.c	Fri Oct 10 21:18:24 2008
@@ -29,17 +29,33 @@
 #include "gimpdrawablestack.h"
 
 
+#ifdef __GNUC__
+#warning FIXME: gegl_node_add_child() needs to be public
+#endif
+GeglNode * gegl_node_add_child (GeglNode *self,
+                                GeglNode *child);
+
+#ifdef __GNUC__
+#warning FIXME: gegl_node_remove_child() needs to be public
+#endif
+GeglNode * gegl_node_remove_child (GeglNode *self,
+                                   GeglNode *child);
+
+
 /*  local function prototypes  */
 
-static void   gimp_drawable_stack_finalize (GObject       *object);
+static void   gimp_drawable_stack_finalize    (GObject           *object);
 
-static void   gimp_drawable_stack_add      (GimpContainer *container,
-                                            GimpObject    *object);
-static void   gimp_drawable_stack_remove   (GimpContainer *container,
-                                            GimpObject    *object);
-static void   gimp_drawable_stack_reorder  (GimpContainer *container,
-                                            GimpObject    *object,
-                                            gint           new_index);
+static void   gimp_drawable_stack_remove      (GimpContainer     *container,
+                                               GimpObject        *object);
+static void   gimp_drawable_stack_reorder     (GimpContainer     *container,
+                                               GimpObject        *object,
+                                               gint               new_index);
+
+static void   gimp_drawable_stack_add_node    (GimpDrawableStack *stack,
+                                               GimpDrawable      *drawable);
+static void   gimp_drawable_stack_remove_node (GimpDrawableStack *stack,
+                                               GimpDrawable      *drawable);
 
 
 G_DEFINE_TYPE (GimpDrawableStack, gimp_drawable_stack, GIMP_TYPE_LIST)
@@ -55,7 +71,6 @@
 
   object_class->finalize   = gimp_drawable_stack_finalize;
 
-  container_class->add     = gimp_drawable_stack_add;
   container_class->remove  = gimp_drawable_stack_remove;
   container_class->reorder = gimp_drawable_stack_reorder;
 }
@@ -68,20 +83,31 @@
 static void
 gimp_drawable_stack_finalize (GObject *object)
 {
-  G_OBJECT_CLASS (parent_class)->finalize (object);
-}
+  GimpDrawableStack *stack = GIMP_DRAWABLE_STACK (object);
 
-static void
-gimp_drawable_stack_add (GimpContainer *container,
-                         GimpObject    *object)
-{
-  GIMP_CONTAINER_CLASS (parent_class)->add (container, object);
+  if (stack->graph)
+    {
+      g_object_unref (stack->graph);
+      stack->graph = NULL;
+    }
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
 gimp_drawable_stack_remove (GimpContainer *container,
                             GimpObject    *object)
 {
+  GimpDrawableStack *stack = GIMP_DRAWABLE_STACK (container);
+
+  if (stack->graph)
+    {
+      gimp_drawable_stack_remove_node (stack, GIMP_DRAWABLE (object));
+
+      gegl_node_remove_child (stack->graph,
+                              gimp_drawable_get_node (GIMP_DRAWABLE (object)));
+    }
+
   GIMP_CONTAINER_CLASS (parent_class)->remove (container, object);
 }
 
@@ -90,9 +116,20 @@
                              GimpObject    *object,
                              gint           new_index)
 {
+  GimpDrawableStack *stack = GIMP_DRAWABLE_STACK (container);
+
+  if (stack->graph)
+    gimp_drawable_stack_remove_node (stack, GIMP_DRAWABLE (object));
+
   GIMP_CONTAINER_CLASS (parent_class)->reorder (container, object, new_index);
+
+  if (stack->graph)
+    gimp_drawable_stack_add_node (stack, GIMP_DRAWABLE (object));
 }
 
+
+/*  public functions  */
+
 GimpContainer *
 gimp_drawable_stack_new (GType drawable_type)
 {
@@ -105,3 +142,164 @@
                        "unique-names",  TRUE,
                        NULL);
 }
+
+GeglNode *
+gimp_drawable_stack_get_graph (GimpDrawableStack *stack)
+{
+  GList    *list;
+  GList    *reverse_list = NULL;
+  GeglNode *previous     = NULL;
+  GeglNode *output;
+
+  g_return_val_if_fail (GIMP_IS_DRAWABLE_STACK (stack), NULL);
+
+  if (stack->graph)
+    return stack->graph;
+
+  for (list = GIMP_LIST (stack)->list;
+       list;
+       list = g_list_next (list))
+    {
+      GimpDrawable *drawable = list->data;
+
+      reverse_list = g_list_prepend (reverse_list, drawable);
+    }
+
+  stack->graph = gegl_node_new ();
+
+  for (list = reverse_list; list; list = g_list_next (list))
+    {
+      GimpDrawable *drawable = list->data;
+      GeglNode     *node     = gimp_drawable_get_node (drawable);
+
+      gegl_node_add_child (stack->graph, node);
+
+      if (previous)
+        gegl_node_connect_to (previous, "output",
+                              node,     "input");
+
+      previous = node;
+    }
+
+  output = gegl_node_get_output_proxy (stack->graph, "output");
+
+  if (previous)
+    gegl_node_connect_to (previous, "output",
+                          output,   "input");
+
+  return stack->graph;
+}
+
+
+/*  private functions  */
+
+static void
+gimp_drawable_stack_add_node (GimpDrawableStack *stack,
+                              GimpDrawable      *drawable)
+{
+  GimpDrawable *drawable_below;
+  GeglNode     *node;
+  gint          index;
+
+  node = gimp_drawable_get_node (drawable);
+
+  index = gimp_container_get_child_index (GIMP_CONTAINER (stack),
+                                          GIMP_OBJECT (drawable));
+
+  if (index == 0)
+    {
+      GeglNode *output;
+
+      output = gegl_node_get_output_proxy (stack->graph, "output");
+
+      gegl_node_connect_to (node,   "output",
+                            output, "input");
+    }
+  else
+    {
+      GimpDrawable *drawable_above;
+      GeglNode     *node_above;
+
+      drawable_above = (GimpDrawable *)
+        gimp_container_get_child_by_index (GIMP_CONTAINER (stack), index - 1);
+
+      node_above = gimp_drawable_get_node (drawable_above);
+
+      gegl_node_connect_to (node,       "output",
+                            node_above, "input");
+    }
+
+  drawable_below = (GimpDrawable *)
+    gimp_container_get_child_by_index (GIMP_CONTAINER (stack), index + 1);
+
+  if (drawable_below)
+    {
+      GeglNode *node_below = gimp_drawable_get_node (drawable_below);
+
+      gegl_node_connect_to (node_below, "output",
+                            node,       "input");
+    }
+}
+
+static void
+gimp_drawable_stack_remove_node (GimpDrawableStack *stack,
+                                 GimpDrawable      *drawable)
+{
+  GimpDrawable *drawable_below;
+  GeglNode     *node;
+  gint          index;
+
+  node = gimp_drawable_get_node (GIMP_DRAWABLE (drawable));
+
+  /*  bail out if the layer was newly added  */
+  if (! gegl_node_get_consumers (node, "output", NULL, NULL))
+    return;
+
+  index = gimp_container_get_child_index (GIMP_CONTAINER (stack),
+                                          GIMP_OBJECT (drawable));
+
+  drawable_below = (GimpDrawable *)
+    gimp_container_get_child_by_index (GIMP_CONTAINER (stack), index + 1);
+
+  if (index == 0)
+    {
+      if (drawable_below)
+        {
+          GeglNode *node_below;
+          GeglNode *output;
+
+          node_below = gimp_drawable_get_node (drawable_below);
+
+          output = gegl_node_get_output_proxy (stack->graph, "output");
+
+          gegl_node_disconnect (node,       "input");
+          gegl_node_connect_to (node_below, "output",
+                                output,     "input");
+        }
+    }
+  else
+    {
+      GimpDrawable *drawable_above;
+      GeglNode     *node_above;
+
+      drawable_above = (GimpDrawable *)
+        gimp_container_get_child_by_index (GIMP_CONTAINER (stack), index - 1);
+
+      node_above = gimp_drawable_get_node (drawable_above);
+
+      if (drawable_below)
+        {
+          GeglNode *node_below;
+
+          node_below = gimp_drawable_get_node (drawable_below);
+
+          gegl_node_disconnect (node,       "input");
+          gegl_node_connect_to (node_below, "output",
+                                node_above, "input");
+        }
+      else
+        {
+          gegl_node_disconnect (node_above, "input");
+        }
+    }
+}

Modified: trunk/app/core/gimpdrawablestack.h
==============================================================================
--- trunk/app/core/gimpdrawablestack.h	(original)
+++ trunk/app/core/gimpdrawablestack.h	Fri Oct 10 21:18:24 2008
@@ -37,6 +37,8 @@
 struct _GimpDrawableStack
 {
   GimpList  parent_instance;
+
+  GeglNode *graph;
 };
 
 struct _GimpDrawableStackClass
@@ -45,8 +47,10 @@
 };
 
 
-GType           gimp_drawable_stack_get_type (void) G_GNUC_CONST;
-GimpContainer * gimp_drawable_stack_new      (GType  drawable_type);
+GType           gimp_drawable_stack_get_type  (void) G_GNUC_CONST;
+GimpContainer * gimp_drawable_stack_new       (GType              drawable_type);
+
+GeglNode      * gimp_drawable_stack_get_graph (GimpDrawableStack *stack);
 
 
 #endif  /*  __GIMP_DRAWABLE_STACK_H__  */

Modified: trunk/app/core/gimpimage.c
==============================================================================
--- trunk/app/core/gimpimage.c	(original)
+++ trunk/app/core/gimpimage.c	Fri Oct 10 21:18:24 2008
@@ -126,12 +126,6 @@
 GeglNode * gegl_node_add_child (GeglNode *self,
                                 GeglNode *child);
 
-#ifdef __GNUC__
-#warning FIXME: gegl_node_remove_child() needs to be public
-#endif
-GeglNode * gegl_node_remove_child (GeglNode *self,
-                                   GeglNode *child);
-
 
 /*  local function prototypes  */
 
@@ -2554,155 +2548,52 @@
 GeglNode *
 gimp_image_get_graph (GimpImage *image)
 {
-  GList    *list;
-  GList    *reverse_list = NULL;
-  GeglNode *previous     = NULL;
+  GeglNode *layers_node;
+#if 0
+  GeglNode *channels_node;
+  GeglNode *blend_node;
+#endif
+  GeglNode *output;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
   if (image->graph)
     return image->graph;
 
-  for (list = GIMP_LIST (image->layers)->list;
-       list;
-       list = g_list_next (list))
-    {
-      GimpLayer *layer = list->data;
-
-      if (! gimp_layer_is_floating_sel (layer))
-        reverse_list = g_list_prepend (reverse_list, layer);
-    }
-
   image->graph = gegl_node_new ();
 
-  for (list = reverse_list; list; list = g_list_next (list))
-    {
-      GimpDrawable *layer = list->data;
-      GeglNode     *node  = gimp_drawable_get_node (layer);
-
-      gegl_node_add_child (image->graph, node);
-
-      if (previous)
-        gegl_node_connect_to (previous, "output",
-                              node,     "input");
-
-      previous = node;
-    }
-
-  if (previous)
-    {
-      GeglNode *output;
-
-      output = gegl_node_get_output_proxy (image->graph, "output");
-
-      gegl_node_connect_to (previous, "output",
-                            output,   "input");
-    }
-
-  return image->graph;
-}
-
-/*  layer must be part of image->layers !!!  */
-static void
-gimp_image_add_layer_node (GimpImage *image,
-                           GimpLayer *layer)
-{
-  GimpLayer *layer_below;
-  GeglNode  *node;
-  gint       index;
-
-  index = gimp_image_get_layer_index (image, layer);
-
-  node = gimp_drawable_get_node (GIMP_DRAWABLE (layer));
+  layers_node =
+    gimp_drawable_stack_get_graph (GIMP_DRAWABLE_STACK (image->layers));
 
-  if (index == 0)
-    {
-      GeglNode *output;
-
-      output = gegl_node_get_output_proxy (image->graph, "output");
-
-      gegl_node_connect_to (node,   "output",
-                            output, "input");
-    }
-  else
-    {
-      GimpLayer *layer_above;
-      GeglNode  *node_above;
+  gegl_node_add_child (image->graph, layers_node);
 
-      layer_above = gimp_image_get_layer_by_index (image, index - 1);
+#if 0
+  channels_node =
+    gimp_drawable_stack_get_graph (GIMP_DRAWABLE_STACK (image->channels));
 
-      node_above = gimp_drawable_get_node (GIMP_DRAWABLE (layer_above));
+  gegl_node_add_child (image->graph, channels_node);
 
-      gegl_node_connect_to (node,       "output",
-                            node_above, "input");
-    }
+  blend_node = gegl_node_new_child (image->graph,
+                                    "operation", "normal",
+                                    NULL);
 
-  layer_below = gimp_image_get_layer_by_index (image, index + 1);
-
-  if (layer_below)
-    {
-      GeglNode *node_below = gimp_drawable_get_node (GIMP_DRAWABLE (layer_below));
-
-      gegl_node_connect_to (node_below, "output",
-                            node,       "input");
-    }
-}
-
-/*  layer must be part of image->layers !!!  */
-static void
-gimp_image_remove_layer_node (GimpImage *image,
-                              GimpLayer *layer)
-{
-  GimpLayer *layer_below;
-  GeglNode  *node;
-  gint       index;
-
-  index = gimp_image_get_layer_index (image, layer);
-
-  node = gimp_drawable_get_node (GIMP_DRAWABLE (layer));
-
-  layer_below = gimp_image_get_layer_by_index (image, index + 1);
-
-  if (index == 0)
-    {
-      if (layer_below)
-        {
-          GeglNode *node_below;
-          GeglNode *output;
-
-          node_below = gimp_drawable_get_node (GIMP_DRAWABLE (layer_below));
-
-          output = gegl_node_get_output_proxy (image->graph, "output");
-
-          gegl_node_disconnect (node,       "input");
-          gegl_node_connect_to (node_below, "output",
-                                output,     "input");
-        }
-    }
-  else
-    {
-      GimpLayer *layer_above;
-      GeglNode  *node_above;
-
-      layer_above = gimp_image_get_layer_by_index (image, index - 1);
-
-      node_above = gimp_drawable_get_node (GIMP_DRAWABLE (layer_above));
+  gegl_node_connect_to (layers_node,   "output",
+                        blend_node,    "input");
+  gegl_node_connect_to (channels_node, "output",
+                        blend_node,    "aux");
+#endif
 
-      if (layer_below)
-        {
-          GeglNode *node_below;
+  output = gegl_node_get_output_proxy (image->graph, "output");
 
-          node_below = gimp_drawable_get_node (GIMP_DRAWABLE (layer_below));
+#if 0
+  gegl_node_connect_to (blend_node, "output",
+                        output,     "input");
+#else
+  gegl_node_connect_to (layers_node, "output",
+                        output,      "input");
+#endif
 
-          gegl_node_disconnect (node,       "input");
-          gegl_node_connect_to (node_below, "output",
-                                node_above, "input");
-        }
-      else
-        {
-          gegl_node_disconnect (node_above, "input");
-        }
-    }
+  return image->graph;
 }
 
 
@@ -3109,9 +3000,6 @@
   gimp_container_insert (image->layers, GIMP_OBJECT (layer), position);
   g_object_unref (layer);
 
-  if (! gimp_layer_is_floating_sel (layer) && image->graph)
-    gimp_image_add_layer_node (image, layer);
-
   /*  notify the layers dialog of the currently active layer  */
   gimp_image_set_active_layer (image, layer);
 
@@ -3174,14 +3062,6 @@
   if (layer == active_layer)
     gimp_drawable_invalidate_boundary (GIMP_DRAWABLE (layer));
 
-  if (! gimp_layer_is_floating_sel (layer) && image->graph)
-    {
-      gimp_image_remove_layer_node (image, layer);
-
-      gegl_node_remove_child (image->graph,
-                              gimp_drawable_get_node (GIMP_DRAWABLE (layer)));
-    }
-
   gimp_container_remove (image->layers, GIMP_OBJECT (layer));
   image->layer_stack = g_slist_remove (image->layer_stack, layer);
 
@@ -3405,14 +3285,8 @@
   if (push_undo)
     gimp_image_undo_push_layer_reposition (image, undo_desc, layer);
 
-  if (! gimp_layer_is_floating_sel (layer) && image->graph)
-    gimp_image_remove_layer_node (image, layer);
-
   gimp_container_reorder (image->layers, GIMP_OBJECT (layer), new_index);
 
-  if (! gimp_layer_is_floating_sel (layer) && image->graph)
-    gimp_image_add_layer_node (image, layer);
-
   if (gimp_item_get_visible (GIMP_ITEM (layer)))
     {
       gint off_x, off_y;



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