[gimp] app: add gimp_layer_get_real_{blend,composite}_{space,mode}()



commit 96efde0f227045e446b18289a2f04bd0d90f3139
Author: Ell <ell_se yahoo com>
Date:   Sat Oct 21 11:10:29 2017 -0400

    app: add gimp_layer_get_real_{blend,composite}_{space,mode}()
    
    ... which return the layer's blend/composite space/mode.  However,
    unlike the non-"_real" versions, these functions never return AUTO
    -- instead, they return the actual space/mode that AUTO maps to for
    the current layer mode.
    
    When changing a layer's blend/composite space/mode, avoid
    updating the drawable if the real space/mode didn't change (i.e.,
    if changing from AUTO to the concrete value, or vice versa.)

 app/core/gimplayer.c |   85 +++++++++++++++++++++++++++++++++++++++++---------
 app/core/gimplayer.h |    6 +++
 2 files changed, 76 insertions(+), 15 deletions(-)
---
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 0f9db02..31c0acc 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -663,7 +663,7 @@ gimp_layer_update_mode_node (GimpLayer *layer)
     {
       visible_mode            = GIMP_LAYER_MODE_NORMAL;
       visible_blend_space     = GIMP_LAYER_COLOR_SPACE_AUTO;
-      visible_composite_space = layer->composite_space;
+      visible_composite_space = GIMP_LAYER_COLOR_SPACE_AUTO;
       visible_composite_mode  = GIMP_LAYER_COMPOSITE_AUTO;
 
       /* This makes sure that masks of LEGACY-mode layers are
@@ -671,8 +671,7 @@ gimp_layer_update_mode_node (GimpLayer *layer)
        * LINEAR space, or whatever composite space was chosen in the
        * layer attributes dialog
        */
-      if (visible_composite_space == GIMP_LAYER_COLOR_SPACE_AUTO)
-        visible_composite_space = gimp_layer_mode_get_composite_space (layer->mode);
+      visible_composite_space = gimp_layer_get_real_composite_space (layer);
     }
   else
     {
@@ -1862,7 +1861,8 @@ gimp_layer_create_mask (GimpLayer       *layer,
             gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0);
 
             gimp_gegl_apply_flatten (src_buffer, NULL, NULL,
-                                     dest_buffer, &background);
+                                     dest_buffer, &background,
+                                     GIMP_LAYER_COLOR_SPACE_RGB_LINEAR);
           }
         else
           {
@@ -2192,7 +2192,8 @@ gimp_layer_remove_alpha (GimpLayer   *layer,
 
   gimp_gegl_apply_flatten (gimp_drawable_get_buffer (GIMP_DRAWABLE (layer)),
                            NULL, NULL,
-                           new_buffer, &background);
+                           new_buffer, &background,
+                           gimp_layer_get_real_composite_space (layer));
 
   gimp_drawable_set_buffer (GIMP_DRAWABLE (layer),
                             gimp_item_is_attached (GIMP_ITEM (layer)),
@@ -2409,6 +2410,10 @@ gimp_layer_set_blend_space (GimpLayer           *layer,
 
   if (layer->blend_space != blend_space)
     {
+      GimpLayerColorSpace prev_real_blend_space;
+
+      prev_real_blend_space = gimp_layer_get_real_blend_space (layer);
+
       if (push_undo && gimp_item_is_attached (GIMP_ITEM (layer)))
         {
           GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
@@ -2421,10 +2426,13 @@ gimp_layer_set_blend_space (GimpLayer           *layer,
       g_signal_emit (layer, layer_signals[BLEND_SPACE_CHANGED], 0);
       g_object_notify (G_OBJECT (layer), "blend-space");
 
-      if (gimp_filter_peek_node (GIMP_FILTER (layer)))
-        gimp_layer_update_mode_node (layer);
+      if (gimp_layer_get_real_blend_space (layer) != prev_real_blend_space)
+        {
+          if (gimp_filter_peek_node (GIMP_FILTER (layer)))
+            gimp_layer_update_mode_node (layer);
 
-      gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, -1, -1);
+          gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, -1, -1);
+        }
     }
 }
 
@@ -2436,6 +2444,17 @@ gimp_layer_get_blend_space (GimpLayer *layer)
   return layer->blend_space;
 }
 
+GimpLayerColorSpace
+gimp_layer_get_real_blend_space (GimpLayer *layer)
+{
+  g_return_val_if_fail (GIMP_IS_LAYER (layer), GIMP_LAYER_COLOR_SPACE_RGB_LINEAR);
+
+  if (layer->blend_space == GIMP_LAYER_COLOR_SPACE_AUTO)
+    return gimp_layer_mode_get_blend_space (layer->mode);
+  else
+    return layer->blend_space;
+}
+
 void
 gimp_layer_set_composite_space (GimpLayer           *layer,
                                 GimpLayerColorSpace  composite_space,
@@ -2448,6 +2467,10 @@ gimp_layer_set_composite_space (GimpLayer           *layer,
 
   if (layer->composite_space != composite_space)
     {
+      GimpLayerColorSpace prev_real_composite_space;
+
+      prev_real_composite_space = gimp_layer_get_real_composite_space (layer);
+
       if (push_undo && gimp_item_is_attached (GIMP_ITEM (layer)))
         {
           GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
@@ -2460,10 +2483,13 @@ gimp_layer_set_composite_space (GimpLayer           *layer,
       g_signal_emit (layer, layer_signals[COMPOSITE_SPACE_CHANGED], 0);
       g_object_notify (G_OBJECT (layer), "composite-space");
 
-      if (gimp_filter_peek_node (GIMP_FILTER (layer)))
-        gimp_layer_update_mode_node (layer);
+      if (gimp_layer_get_real_composite_space (layer) != prev_real_composite_space)
+        {
+          if (gimp_filter_peek_node (GIMP_FILTER (layer)))
+            gimp_layer_update_mode_node (layer);
 
-      gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, -1, -1);
+          gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, -1, -1);
+        }
     }
 }
 
@@ -2475,6 +2501,17 @@ gimp_layer_get_composite_space (GimpLayer *layer)
   return layer->composite_space;
 }
 
+GimpLayerColorSpace
+gimp_layer_get_real_composite_space (GimpLayer *layer)
+{
+  g_return_val_if_fail (GIMP_IS_LAYER (layer), GIMP_LAYER_COLOR_SPACE_RGB_LINEAR);
+
+  if (layer->composite_space == GIMP_LAYER_COLOR_SPACE_AUTO)
+    return gimp_layer_mode_get_composite_space (layer->mode);
+  else
+    return layer->composite_space;
+}
+
 void
 gimp_layer_set_composite_mode (GimpLayer              *layer,
                                GimpLayerCompositeMode  composite_mode,
@@ -2487,6 +2524,10 @@ gimp_layer_set_composite_mode (GimpLayer              *layer,
 
   if (layer->composite_mode != composite_mode)
     {
+      GimpLayerCompositeMode prev_real_composite_mode;
+
+      prev_real_composite_mode = gimp_layer_get_real_composite_mode (layer);
+
       if (push_undo && gimp_item_is_attached (GIMP_ITEM (layer)))
         {
           GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
@@ -2499,12 +2540,15 @@ gimp_layer_set_composite_mode (GimpLayer              *layer,
       g_signal_emit (layer, layer_signals[COMPOSITE_MODE_CHANGED], 0);
       g_object_notify (G_OBJECT (layer), "composite-mode");
 
-      if (gimp_filter_peek_node (GIMP_FILTER (layer)))
-        gimp_layer_update_mode_node (layer);
+      if (gimp_layer_get_real_composite_mode (layer) != prev_real_composite_mode)
+        {
+          if (gimp_filter_peek_node (GIMP_FILTER (layer)))
+            gimp_layer_update_mode_node (layer);
 
-      gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, -1, -1);
+          gimp_drawable_update (GIMP_DRAWABLE (layer), 0, 0, -1, -1);
 
-      gimp_layer_update_excludes_backdrop (layer);
+          gimp_layer_update_excludes_backdrop (layer);
+        }
     }
 }
 
@@ -2516,6 +2560,17 @@ gimp_layer_get_composite_mode (GimpLayer *layer)
   return layer->composite_mode;
 }
 
+GimpLayerCompositeMode
+gimp_layer_get_real_composite_mode (GimpLayer *layer)
+{
+  g_return_val_if_fail (GIMP_IS_LAYER (layer), GIMP_LAYER_COMPOSITE_SRC_OVER);
+
+  if (layer->composite_mode == GIMP_LAYER_COMPOSITE_AUTO)
+    return gimp_layer_mode_get_composite_mode (layer->mode);
+  else
+    return layer->composite_mode;
+}
+
 gboolean
 gimp_layer_get_excludes_backdrop (GimpLayer *layer)
 {
diff --git a/app/core/gimplayer.h b/app/core/gimplayer.h
index 42a1246..b607688 100644
--- a/app/core/gimplayer.h
+++ b/app/core/gimplayer.h
@@ -187,18 +187,24 @@ void            gimp_layer_set_blend_space     (GimpLayer            *layer,
                                                 gboolean              push_undo);
 GimpLayerColorSpace
                 gimp_layer_get_blend_space     (GimpLayer            *layer);
+GimpLayerColorSpace
+               gimp_layer_get_real_blend_space (GimpLayer            *layer);
 
 void            gimp_layer_set_composite_space (GimpLayer            *layer,
                                                 GimpLayerColorSpace   composite_space,
                                                 gboolean              push_undo);
 GimpLayerColorSpace
                 gimp_layer_get_composite_space (GimpLayer            *layer);
+GimpLayerColorSpace
+           gimp_layer_get_real_composite_space (GimpLayer            *layer);
 
 void            gimp_layer_set_composite_mode  (GimpLayer            *layer,
                                                 GimpLayerCompositeMode  composite_mode,
                                                 gboolean              push_undo);
 GimpLayerCompositeMode
                 gimp_layer_get_composite_mode  (GimpLayer            *layer);
+GimpLayerCompositeMode
+           gimp_layer_get_real_composite_mode  (GimpLayer            *layer);
 
 gboolean      gimp_layer_get_excludes_backdrop (GimpLayer            *layer);
 


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