Commit 57985cd2 authored by Michael Natterer's avatar Michael Natterer 😴

app: create a meta-op to apply mask and opacity

and use it to apply the layer mask.
parent 15957cb3
......@@ -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,
/* 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),
pixel_region_init (&maskPR,
gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
0, 0,
gimp_item_get_width (item),
gimp_item_get_height (item),
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,
......@@ -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,
mask_source = gegl_node_new_child (node,
"operation", "gegl:buffer-source",
"buffer", mask,
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;
......@@ -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__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment