[gimp] app: save image symmetries in the XCF file.



commit 65717041edc22ba8bec33d8b1c98ee65d69f57cf
Author: Jehan <jehan girinstud io>
Date:   Wed Jan 27 19:18:53 2016 +0100

    app: save image symmetries in the XCF file.
    
    Symmetries are saved in a parasite, which is backward compatible.

 app/xcf/xcf-load.c |   37 +++++++++++++++++++++++++++++++++++++
 app/xcf/xcf-save.c |   31 +++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index f5d6930..cdab55e 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -45,6 +45,7 @@
 #include "core/gimpimage-metadata.h"
 #include "core/gimpimage-private.h"
 #include "core/gimpimage-sample-points.h"
+#include "core/gimpimage-symmetry.h"
 #include "core/gimpimage-undo.h"
 #include "core/gimpitemstack.h"
 #include "core/gimplayer-floating-selection.h"
@@ -53,6 +54,7 @@
 #include "core/gimpparasitelist.h"
 #include "core/gimpprogress.h"
 #include "core/gimpselection.h"
+#include "core/gimpsymmetry.h"
 #include "core/gimptemplate.h"
 
 #include "operations/layer-modes/gimp-layer-modes.h"
@@ -160,6 +162,8 @@ xcf_load_image (Gimp     *gimp,
   gint                image_type;
   GimpPrecision       precision = GIMP_PRECISION_U8_GAMMA;
   gint                num_successful_elements = 0;
+  GList              *syms;
+  GList              *iter;
 
   /* read in the image width, height and type */
   xcf_read_int32 (info, (guint32 *) &width, 1);
@@ -272,6 +276,39 @@ xcf_load_image (Gimp     *gimp,
                                  gimp_parasite_name (parasite));
     }
 
+  /* check for symmetry parasites */
+  syms = gimp_image_symmetry_list ();
+  for (iter = syms; iter; iter = g_list_next (iter))
+    {
+      GType  type = (GType) iter->data;
+      gchar *parasite_name = gimp_symmetry_parasite_name (type);
+
+      parasite = gimp_image_parasite_find (image,
+                                           parasite_name);
+      g_free (parasite_name);
+      if (parasite)
+        {
+          GimpSymmetry *sym = gimp_symmetry_from_parasite (parasite,
+                                                           image,
+                                                           type);
+
+          if (sym)
+            {
+              GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
+
+              gimp_parasite_list_remove (private->parasites,
+                                         gimp_parasite_name (parasite));
+
+              gimp_image_symmetry_add (image, sym);
+
+              g_signal_emit_by_name (sym, "active-changed", NULL);
+              if (sym->active)
+                gimp_image_set_active_symmetry (image, type);
+            }
+        }
+    }
+  g_list_free (syms);
+
   /* migrate the old "exif-data" parasite */
   parasite = gimp_image_parasite_find (GIMP_IMAGE (image),
                                        "exif-data");
diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c
index b0e034c..6c193dd 100644
--- a/app/xcf/xcf-save.c
+++ b/app/xcf/xcf-save.c
@@ -45,11 +45,13 @@
 #include "core/gimpimage-metadata.h"
 #include "core/gimpimage-private.h"
 #include "core/gimpimage-sample-points.h"
+#include "core/gimpimage-symmetry.h"
 #include "core/gimplayer.h"
 #include "core/gimplayermask.h"
 #include "core/gimpparasitelist.h"
 #include "core/gimpprogress.h"
 #include "core/gimpsamplepoint.h"
+#include "core/gimpsymmetry.h"
 
 #include "operations/layer-modes/gimp-layer-modes.h"
 
@@ -358,6 +360,8 @@ xcf_save_image_props (XcfInfo    *info,
   GimpImagePrivate *private       = GIMP_IMAGE_GET_PRIVATE (image);
   GimpParasite     *grid_parasite = NULL;
   GimpParasite     *meta_parasite = NULL;
+  GList            *symmetry_parasites = NULL;
+  GList            *iter;
   GimpUnit          unit          = gimp_image_get_unit (image);
   gdouble           xres;
   gdouble           yres;
@@ -428,6 +432,23 @@ xcf_save_image_props (XcfInfo    *info,
         }
     }
 
+  if (g_list_length (gimp_image_symmetry_get (image)))
+    {
+      GimpParasite *parasite  = NULL;
+      GimpSymmetry *symmetry;
+
+      for (iter = gimp_image_symmetry_get (image); iter; iter = g_list_next (iter))
+        {
+          symmetry = GIMP_SYMMETRY (iter->data);
+          if (G_TYPE_FROM_INSTANCE (symmetry) == GIMP_TYPE_SYMMETRY)
+            /* Do not save the identity symmetry. */
+            continue;
+          parasite = gimp_symmetry_to_parasite (GIMP_SYMMETRY (iter->data));
+          gimp_parasite_list_add (private->parasites, parasite);
+          symmetry_parasites = g_list_prepend (symmetry_parasites, parasite);
+        }
+    }
+
   if (gimp_parasite_list_length (private->parasites) > 0)
     {
       xcf_check_error (xcf_save_prop (info, image, PROP_PARASITES, error,
@@ -448,6 +469,16 @@ xcf_save_image_props (XcfInfo    *info,
       gimp_parasite_free (meta_parasite);
     }
 
+  for (iter = symmetry_parasites; iter; iter = g_list_next (iter))
+    {
+      GimpParasite *parasite = iter->data;
+
+      gimp_parasite_list_remove (private->parasites,
+                                 gimp_parasite_name (parasite));
+    }
+  g_list_free_full (symmetry_parasites,
+                    (GDestroyNotify) gimp_parasite_free);
+
   xcf_check_error (xcf_save_prop (info, image, PROP_END, error));
 
   return TRUE;


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