[gimp] app: reimplement image component visibility using gimp:mask-components



commit 6ddb977542ba4e5bcaa75ded9a4b89c6a9fa8db2
Author: Michael Natterer <mitch gimp org>
Date:   Sat Oct 6 23:58:46 2012 +0200

    app: reimplement image component visibility using gimp:mask-components

 app/core/gimpimage-private.h |    1 +
 app/core/gimpimage.c         |   71 +++++++++++++++++++++++++++++++++++++-----
 app/core/gimpimage.h         |    1 +
 3 files changed, 65 insertions(+), 8 deletions(-)
---
diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h
index 12d7f5e..3f721a0 100644
--- a/app/core/gimpimage-private.h
+++ b/app/core/gimpimage-private.h
@@ -68,6 +68,7 @@ struct _GimpImagePrivate
 
   GimpProjection    *projection;            /*  projection layers & channels */
   GeglNode          *graph;                 /*  GEGL projection graph        */
+  GeglNode          *visible_mask;          /*  component visibility node    */
 
   GList             *guides;                /*  guides                       */
   GimpGrid          *grid;                  /*  grid                         */
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index bddb338..86f52c4 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -910,6 +910,7 @@ gimp_image_finalize (GObject *object)
     {
       g_object_unref (private->graph);
       private->graph = NULL;
+      private->visible_mask = NULL;
     }
 
   if (private->colormap)
@@ -1286,12 +1287,13 @@ gimp_image_get_proj_format (GimpProjectable *projectable)
 static GeglNode *
 gimp_image_get_graph (GimpProjectable *projectable)
 {
-  GimpImage        *image   = GIMP_IMAGE (projectable);
-  GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
-  GeglNode         *layers_node;
-  GeglNode         *channels_node;
-  GeglNode         *blend_node;
-  GeglNode         *output;
+  GimpImage         *image   = GIMP_IMAGE (projectable);
+  GimpImagePrivate  *private = GIMP_IMAGE_GET_PRIVATE (image);
+  GeglNode          *layers_node;
+  GeglNode          *channels_node;
+  GeglNode          *blend_node;
+  GeglNode          *output;
+  GimpComponentMask  mask;
 
   if (private->graph)
     return private->graph;
@@ -1317,10 +1319,21 @@ gimp_image_get_graph (GimpProjectable *projectable)
   gegl_node_connect_to (channels_node, "output",
                         blend_node,    "aux");
 
+  mask = ~gimp_image_get_visible_mask (image) & GIMP_COMPONENT_ALL;
+
+  private->visible_mask =
+    gegl_node_new_child (private->graph,
+                         "operation", "gimp:mask-components",
+                         "mask",      mask,
+                         NULL);
+
+  gegl_node_connect_to (blend_node,            "output",
+                        private->visible_mask, "input");
+
   output = gegl_node_get_output_proxy (private->graph, "output");
 
-  gegl_node_connect_to (blend_node, "output",
-                        output,     "input");
+  gegl_node_connect_to (private->visible_mask, "output",
+                        output,                "input");
 
   return private->graph;
 }
@@ -2347,6 +2360,17 @@ gimp_image_set_component_visible (GimpImage       *image,
     {
       private->visible[index] = visible ? TRUE : FALSE;
 
+      if (private->visible_mask)
+        {
+          GimpComponentMask mask;
+
+          mask = ~gimp_image_get_visible_mask (image) & GIMP_COMPONENT_ALL;
+
+          gegl_node_set (private->visible_mask,
+                         "mask", mask,
+                         NULL);
+        }
+
       g_signal_emit (image,
                      gimp_image_signals[COMPONENT_VISIBILITY_CHANGED], 0,
                      channel);
@@ -2390,6 +2414,37 @@ gimp_image_get_visible_array (const GimpImage *image,
     components[i] = private->visible[i];
 }
 
+GimpComponentMask
+gimp_image_get_visible_mask (const GimpImage *image)
+{
+  GimpImagePrivate  *private;
+  GimpComponentMask  mask = 0;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), 0);
+
+  private = GIMP_IMAGE_GET_PRIVATE (image);
+
+  switch (gimp_image_get_base_type (image))
+    {
+    case GIMP_RGB:
+      mask |= (private->visible[RED])   ? GIMP_COMPONENT_RED   : 0;
+      mask |= (private->visible[GREEN]) ? GIMP_COMPONENT_GREEN : 0;
+      mask |= (private->visible[BLUE])  ? GIMP_COMPONENT_BLUE  : 0;
+      mask |= (private->visible[ALPHA]) ? GIMP_COMPONENT_ALPHA : 0;
+      break;
+
+    case GIMP_GRAY:
+    case GIMP_INDEXED:
+      mask |= (private->visible[GRAY])  ? GIMP_COMPONENT_RED   : 0;
+      mask |= (private->visible[GRAY])  ? GIMP_COMPONENT_GREEN : 0;
+      mask |= (private->visible[GRAY])  ? GIMP_COMPONENT_BLUE  : 0;
+      mask |= (private->visible[ALPHA]) ? GIMP_COMPONENT_ALPHA : 0;
+      break;
+    }
+
+  return mask;
+}
+
 
 /*  emitting image signals  */
 
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index cf0190e..cac48cf 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -211,6 +211,7 @@ gboolean        gimp_image_get_component_visible (const GimpImage    *image,
                                                   GimpChannelType     type);
 void            gimp_image_get_visible_array     (const GimpImage    *image,
                                                   gboolean           *components);
+GimpComponentMask gimp_image_get_visible_mask    (const GimpImage    *image);
 
 
 /*  emitting image signals  */



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