[gimp/goat-invasion: 81/608] app: create a meta-op to apply mask and opacity



commit a8773f9af3d7bc2f8bfb76a8c3235837d3792b5b
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 16 17:29:28 2012 +0100

    app: create a meta-op to apply mask and opacity
    
    and use it to apply the layer mask.

 app/core/gimplayer.c       |   28 +++++++++++++---------------
 app/gegl/gimp-gegl-nodes.c |   36 ++++++++++++++++++++++++++++++++++++
 app/gegl/gimp-gegl-nodes.h |    4 +++-
 3 files changed, 52 insertions(+), 16 deletions(-)
---
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 79b0a38..24350fa 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -1789,7 +1789,6 @@ gimp_layer_apply_mask (GimpLayer         *layer,
   GimpItem      *item;
   GimpImage     *image;
   GimpLayerMask *mask;
-  PixelRegion    srcPR, maskPR;
   gboolean       view_changed = FALSE;
 
   g_return_if_fail (GIMP_IS_LAYER (layer));
@@ -1835,6 +1834,10 @@ gimp_layer_apply_mask (GimpLayer         *layer,
 
   if (mode == GIMP_MASK_APPLY)
     {
+      GeglBuffer *mask_buffer;
+      GeglBuffer *dest_buffer;
+      GeglNode   *apply_opacity;
+
       if (push_undo)
         gimp_drawable_push_undo (GIMP_DRAWABLE (layer), NULL,
                                  0, 0,
@@ -1843,20 +1846,15 @@ gimp_layer_apply_mask (GimpLayer         *layer,
                                  NULL, FALSE);
 
       /*  Combine the current layer's alpha channel and the mask  */
-      pixel_region_init (&srcPR,
-                         gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
-                         0, 0,
-                         gimp_item_get_width  (item),
-                         gimp_item_get_height (item),
-                         TRUE);
-      pixel_region_init (&maskPR,
-                         gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
-                         0, 0,
-                         gimp_item_get_width  (item),
-                         gimp_item_get_height (item),
-                         FALSE);
-
-      apply_mask_to_region (&srcPR, &maskPR, OPAQUE_OPACITY);
+      mask_buffer = gimp_drawable_get_read_buffer (GIMP_DRAWABLE (mask));
+      dest_buffer = gimp_drawable_get_write_buffer (GIMP_DRAWABLE (layer));
+
+      apply_opacity = gimp_gegl_create_apply_opacity_node (mask_buffer, 1.0);
+
+      gimp_drawable_apply_operation_to_buffer (GIMP_DRAWABLE (layer), NULL, NULL,
+                                               apply_opacity, TRUE, dest_buffer);
+
+      g_object_unref (apply_opacity);
     }
 
   g_signal_handlers_disconnect_by_func (mask,
diff --git a/app/gegl/gimp-gegl-nodes.c b/app/gegl/gimp-gegl-nodes.c
index 9440667..739a7ca 100644
--- a/app/gegl/gimp-gegl-nodes.c
+++ b/app/gegl/gimp-gegl-nodes.c
@@ -67,3 +67,39 @@ gimp_gegl_create_flatten_node (const GimpRGB *background)
 
   return node;
 }
+
+GeglNode *
+gimp_gegl_create_apply_opacity_node (GeglBuffer *mask,
+                                     gdouble     opacity)
+{
+  GeglNode  *node;
+  GeglNode  *input;
+  GeglNode  *output;
+  GeglNode  *opacity_node;
+  GeglNode  *mask_source;
+
+  g_return_val_if_fail (GEGL_IS_BUFFER (mask), NULL);
+
+  node = gegl_node_new ();
+
+  input  = gegl_node_get_input_proxy  (node, "input");
+  output = gegl_node_get_output_proxy (node, "output");
+
+  opacity_node = gegl_node_new_child (node,
+                                      "operation", "gegl:opacity",
+                                      "value",     opacity,
+                                      NULL);
+  mask_source = gegl_node_new_child (node,
+                                     "operation", "gegl:buffer-source",
+                                     "buffer",    mask,
+                                     NULL);
+
+  gegl_node_connect_to (input,        "output",
+                        opacity_node, "input");
+  gegl_node_connect_to (mask_source,  "output",
+                        opacity_node, "aux");
+  gegl_node_connect_to (opacity_node, "output",
+                        output,       "input");
+
+  return node;
+}
diff --git a/app/gegl/gimp-gegl-nodes.h b/app/gegl/gimp-gegl-nodes.h
index 792c9dd..8e341db 100644
--- a/app/gegl/gimp-gegl-nodes.h
+++ b/app/gegl/gimp-gegl-nodes.h
@@ -22,7 +22,9 @@
 #define __GIMP_GEGL_NODES_H__
 
 
-GeglNode * gimp_gegl_create_flatten_node (const GimpRGB *background);
+GeglNode * gimp_gegl_create_flatten_node       (const GimpRGB *background);
+GeglNode * gimp_gegl_create_apply_opacity_node (GeglBuffer    *mask,
+                                                gdouble        opacity);
 
 
 #endif /* __GIMP_GEGL_NODES_H__ */



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