[gimp] app: move the XCF version logic to gimpimage.[ch]



commit 4fdfe10b2932d202bfccd49bee9b76026c306570
Author: Michael Natterer <mitch gimp org>
Date:   Sat Sep 27 20:38:43 2014 +0200

    app: move the XCF version logic to gimpimage.[ch]
    
    Add gimp_image_get_xcf_version() and use it when saving XCFs. The
    function also returns GIMP versions in integer (comparable) and string
    form to be used by GUI logic that allows to save compatible files.

 app/core/gimpimage.c |   77 ++++++++++++++++++++++++++++++++++++++++++++++++++
 app/core/gimpimage.h |    5 +++
 app/xcf/xcf-save.c   |   53 +---------------------------------
 app/xcf/xcf-save.h   |    8 ++---
 app/xcf/xcf.c        |   16 ++++++----
 5 files changed, 95 insertions(+), 64 deletions(-)
---
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 38e0511..3a45bb0 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -2284,6 +2284,83 @@ gimp_image_get_export_proc (const GimpImage *image)
   return GIMP_IMAGE_GET_PRIVATE (image)->export_proc;
 }
 
+gint
+gimp_image_get_xcf_version (GimpImage    *image,
+                            gboolean      zlib_compression,
+                            gint         *gimp_version,
+                            const gchar **version_string)
+{
+  GList *list;
+  gint   version = 0;  /* default to oldest */
+
+  /* need version 1 for colormaps */
+  if (gimp_image_get_colormap (image))
+    version = 1;
+
+  for (list = gimp_image_get_layer_iter (image);
+       list && version < 3;
+       list = g_list_next (list))
+    {
+      GimpLayer *layer = GIMP_LAYER (list->data);
+
+      switch (gimp_layer_get_mode (layer))
+        {
+          /* new layer modes not supported by gimp-1.2 */
+        case GIMP_SOFTLIGHT_MODE:
+        case GIMP_GRAIN_EXTRACT_MODE:
+        case GIMP_GRAIN_MERGE_MODE:
+        case GIMP_COLOR_ERASE_MODE:
+          version = MAX (2, version);
+          break;
+
+        default:
+          break;
+        }
+
+      /* need version 3 for layer trees */
+      if (gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
+        version = MAX (3, version);
+    }
+
+  /* need version 6 for new metadata */
+  if (gimp_image_get_metadata (image))
+    version = MAX (6, version);
+
+  /* need version 7 for high bit depth images */
+  if (gimp_image_get_precision (image) != GIMP_PRECISION_U8_GAMMA)
+    version = MAX (7, version);
+
+  /* need version 8 for zlib compression */
+  if (zlib_compression)
+    version = MAX (8, version);
+
+  switch (version)
+    {
+    case 0:
+    case 1:
+    case 2:
+      if (gimp_version)   *gimp_version   = 206;
+      if (version_string) *version_string = "GIMP 2.6";
+      break;
+
+    case 3:
+      if (gimp_version)   *gimp_version   = 208;
+      if (version_string) *version_string = "GIMP 2.8";
+      break;
+
+    case 4:
+    case 5:
+    case 6:
+    case 7:
+    case 8:
+      if (gimp_version)   *gimp_version   = 210;
+      if (version_string) *version_string = "GIMP 2.10";
+      break;
+    }
+
+  return version;
+}
+
 void
 gimp_image_set_resolution (GimpImage *image,
                            gdouble    xresolution,
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index af58882..9b9716c 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -170,6 +170,11 @@ GimpPlugInProcedure * gimp_image_get_export_proc (const GimpImage    *image);
 void            gimp_image_exported              (GimpImage          *image,
                                                   GFile              *file);
 
+gint            gimp_image_get_xcf_version       (GimpImage          *image,
+                                                  gboolean            zlib_compression,
+                                                  gint               *gimp_version,
+                                                  const gchar       **version_string);
+
 void            gimp_image_set_resolution        (GimpImage          *image,
                                                   gdouble             xres,
                                                   gdouble             yres);
diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c
index d972054..1ceb521 100644
--- a/app/xcf/xcf-save.c
+++ b/app/xcf/xcf-save.c
@@ -185,58 +185,7 @@ static gboolean xcf_save_vectors       (XcfInfo           *info,
   } G_STMT_END
 
 
-void
-xcf_save_choose_format (XcfInfo   *info,
-                        GimpImage *image)
-{
-  GList *list;
-  gint   save_version = 0;  /* default to oldest */
-
-  /* need version 1 for colormaps */
-  if (gimp_image_get_colormap (image))
-    save_version = 1;
-
-  for (list = gimp_image_get_layer_iter (image);
-       list && save_version < 3;
-       list = g_list_next (list))
-    {
-      GimpLayer *layer = GIMP_LAYER (list->data);
-
-      switch (gimp_layer_get_mode (layer))
-        {
-          /* new layer modes not supported by gimp-1.2 */
-        case GIMP_SOFTLIGHT_MODE:
-        case GIMP_GRAIN_EXTRACT_MODE:
-        case GIMP_GRAIN_MERGE_MODE:
-        case GIMP_COLOR_ERASE_MODE:
-          save_version = MAX (2, save_version);
-          break;
-
-        default:
-          break;
-        }
-
-      /* need version 3 for layer trees */
-      if (gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
-        save_version = MAX (3, save_version);
-    }
-
-  /* need version 6 for new metadata */
-  if (gimp_image_get_metadata (image))
-    save_version = MAX (6, save_version);
-
-  /* need version 7 for high bit depth images */
-  if (gimp_image_get_precision (image) != GIMP_PRECISION_U8_GAMMA)
-    save_version = MAX (7, save_version);
-
-  /* need version 8 for zlib compression */
-  if (info->compression == COMPRESS_ZLIB)
-    save_version = MAX (8, save_version);
-
-  info->file_version = save_version;
-}
-
-gint
+gboolean
 xcf_save_image (XcfInfo    *info,
                 GimpImage  *image,
                 GError    **error)
diff --git a/app/xcf/xcf-save.h b/app/xcf/xcf-save.h
index a7dba92..5278539 100644
--- a/app/xcf/xcf-save.h
+++ b/app/xcf/xcf-save.h
@@ -19,11 +19,9 @@
 #define __XCF_SAVE_H__
 
 
-void   xcf_save_choose_format (XcfInfo    *info,
-                               GimpImage  *image);
-gint   xcf_save_image         (XcfInfo    *info,
-                               GimpImage  *image,
-                               GError    **error);
+gboolean   xcf_save_image (XcfInfo    *info,
+                           GimpImage  *image,
+                           GError    **error);
 
 
 #endif  /* __XCF_SAVE_H__ */
diff --git a/app/xcf/xcf.c b/app/xcf/xcf.c
index 110be91..157536a 100644
--- a/app/xcf/xcf.c
+++ b/app/xcf/xcf.c
@@ -387,17 +387,19 @@ xcf_save_invoker (GimpProcedure         *procedure,
 
   if (info.output)
     {
-      info.gimp        = gimp;
-      info.seekable    = G_SEEKABLE (info.output);
-      info.progress    = progress;
-      info.filename    = filename;
-      info.compression = COMPRESS_ZLIB;
+      info.gimp         = gimp;
+      info.seekable     = G_SEEKABLE (info.output);
+      info.progress     = progress;
+      info.filename     = filename;
+      info.compression  = COMPRESS_ZLIB;
+      info.file_version = gimp_image_get_xcf_version (image,
+                                                      info.compression ==
+                                                      COMPRESS_ZLIB,
+                                                      NULL, NULL);
 
       if (progress)
         gimp_progress_start (progress, FALSE, _("Saving '%s'"), filename);
 
-      xcf_save_choose_format (&info, image);
-
       success = xcf_save_image (&info, image, &my_error);
 
       if (success)


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