[gimp/symmetry] app: save image symmetries in the XCF file.
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/symmetry] app: save image symmetries in the XCF file.
- Date: Fri, 12 Feb 2016 00:37:47 +0000 (UTC)
commit cafc616da5ffea79e0b3457ea0fcde8a0eaf66ed
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 | 42 +++++++++++++++++++++++++++++++++++++-----
2 files changed, 74 insertions(+), 5 deletions(-)
---
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 72e45ed..51cf01d 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-sel.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 "text/gimptextlayer.h"
@@ -157,6 +159,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 */
info->cp += xcf_read_int32 (info->input, (guint32 *) &width, 1);
@@ -269,6 +273,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 8f33568..ea55a3b 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 "text/gimptextlayer.h"
#include "text/gimptextlayer-xcf.h"
@@ -337,11 +339,13 @@ xcf_save_image_props (XcfInfo *info,
GimpImage *image,
GError **error)
{
- GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
- GimpParasite *grid_parasite = NULL;
- GimpParasite *meta_parasite = NULL;
- GimpParasite *compat_parasite = NULL;
- GimpUnit unit = gimp_image_get_unit (image);
+ GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
+ GimpParasite *grid_parasite = NULL;
+ GimpParasite *meta_parasite = NULL;
+ GimpParasite *compat_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,
gimp_parasite_list_add (private->parasites, compat_parasite);
}
+ 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,
@@ -454,6 +475,17 @@ xcf_save_image_props (XcfInfo *info,
gimp_parasite_name (compat_parasite));
gimp_parasite_free (compat_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]