[gimp] Fix loading of layer masks of group layers



commit c1f3872141b04b7f1dd9c00303ccf269b434cbea
Author: Michael Natterer <mitch gimp org>
Date:   Thu Sep 3 19:11:02 2009 +0200

    Fix loading of layer masks of group layers
    
    Don't add layer masks to their layers while loading because a newly
    loaded group layer's size doesn't match its mask's size. Instead,
    attach all layer masks to their layers using g_object_set_data(), and
    add them after all layers have been loaded.

 app/xcf/xcf-load.c |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 86b6887..a9cc447 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -71,6 +71,7 @@
 
 /* #define GIMP_XCF_PATH_DEBUG */
 
+static void            xcf_load_add_masks     (GimpImage    *image);
 static gboolean        xcf_load_image_props   (XcfInfo      *info,
                                                GimpImage    *image);
 static gboolean        xcf_load_layer_props   (XcfInfo      *info,
@@ -297,6 +298,8 @@ xcf_load_image (Gimp     *gimp,
         goto error;
     }
 
+  xcf_load_add_masks (image);
+
   if (info->floating_sel && info->floating_sel_drawable)
     floating_sel_attach (info->floating_sel, info->floating_sel_drawable);
 
@@ -323,6 +326,8 @@ xcf_load_image (Gimp     *gimp,
 			_("This XCF file is corrupt!  I have loaded as much "
 			  "of it as I can, but it is incomplete."));
 
+  xcf_load_add_masks (image);
+
   gimp_image_undo_enable (image);
 
   return image;
@@ -337,6 +342,32 @@ xcf_load_image (Gimp     *gimp,
   return NULL;
 }
 
+static void
+xcf_load_add_masks (GimpImage *image)
+{
+  GList *layers;
+  GList *list;
+
+  layers = gimp_image_get_layer_list (image);
+
+  for (list = layers; list; list = g_list_next (list))
+    {
+      GimpLayer     *layer = list->data;
+      GimpLayerMask *mask;
+
+      mask = g_object_get_data (G_OBJECT (layer), "gimp-layer-mask");
+
+      if (mask)
+        {
+          gimp_layer_add_mask (layer, mask, FALSE, NULL);
+
+          g_object_set_data (G_OBJECT (layer), "gimp-layer-mask", NULL);
+        }
+    }
+
+  g_list_free (layers);
+}
+
 static gboolean
 xcf_load_image_props (XcfInfo   *info,
                       GimpImage *image)
@@ -1136,7 +1167,14 @@ xcf_load_layer (XcfInfo    *info,
       gimp_layer_mask_set_edit  (layer_mask, edit_mask);
       gimp_layer_mask_set_show  (layer_mask, show_mask, FALSE);
 
-      gimp_layer_add_mask (layer, layer_mask, FALSE, NULL);
+      /* don't add the layer mask yet, that won't work for group
+       * layers which update their size automatically; instead
+       * attach it so it can be added when all layers are loaded
+       */
+      g_object_set_data_full (G_OBJECT (layer), "gimp-layer-mask",
+                              g_object_ref (layer_mask),
+                              (GDestroyNotify) g_object_unref);
+      g_object_ref_sink (layer_mask);
     }
 
   /* attach the floating selection... */



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