[gimp/gimp-2-10] Integrate the logic of profile saving with metadata saving



commit 9baae75c5ceb0b7166f662abda03ac29c06f15ae
Author: Michael Natterer <mitch gimp org>
Date:   Tue Dec 4 17:28:24 2018 +0100

    Integrate the logic of profile saving with metadata saving
    
    Add flag GIMP_METADATA_SAVE_COLOR_PROFILE to GimpMetadataSaveFlags and
    initialize it from gimp_export_color_profile() in
    gimp_image_metadata_save_prepare().
    
    Adapt all plug-ins to use the bit from the suggested export flags and
    pass the actually used value back to
    gimp_image_metadata_save_finish().
    
    This changes no behavior at all but creates hooks on the libgimp side
    that are called with the context of an image before and after the
    actual export, which might become useful later. Also, consistency
    is good even though the color profile is not strictly "metadata".
    
    (cherry picked from commit c667fdc5c0b0d4e55cf814439e9865ce60a6677e)

 libgimp/gimpimagemetadata.c    | 22 ++++++++++++++++++----
 libgimpbase/gimpmetadata.h     | 21 ++++++++++++---------
 plug-ins/common/file-png.c     |  7 ++++++-
 plug-ins/file-jpeg/jpeg.c      |  7 ++++++-
 plug-ins/file-tiff/file-tiff.c |  7 ++++++-
 5 files changed, 48 insertions(+), 16 deletions(-)
---
diff --git a/libgimp/gimpimagemetadata.c b/libgimp/gimpimagemetadata.c
index fdb16bd2cd..c41efd03e7 100644
--- a/libgimp/gimpimagemetadata.c
+++ b/libgimp/gimpimagemetadata.c
@@ -364,12 +364,18 @@ gimp_image_metadata_save_prepare (gint32                 image_ID,
 
       g_date_time_unref (datetime);
 
-      /* Thumbnail */
-
-      if (FALSE /* FIXME if (original image had a thumbnail) */)
-        *suggested_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
     }
 
+  /* Thumbnail */
+
+  if (FALSE /* FIXME if (original image had a thumbnail) */)
+    *suggested_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
+
+  /* Color profile */
+
+  if (! gimp_export_color_profile ())
+    *suggested_flags &= ~GIMP_METADATA_SAVE_COLOR_PROFILE;
+
   return metadata;
 }
 
@@ -620,6 +626,14 @@ gimp_image_metadata_save_finish (gint32                  image_ID,
       g_object_unref (thumb_pixbuf);
     }
 
+  if (flags & GIMP_METADATA_SAVE_COLOR_PROFILE)
+    {
+      /* nothing to do, but if we ever need to modify metadata based
+       * on the exported color profile, this is probably the place to
+       * add it
+       */
+    }
+
   success = gimp_metadata_save_to_file (new_metadata, file, error);
 
   g_object_unref (new_metadata);
diff --git a/libgimpbase/gimpmetadata.h b/libgimpbase/gimpmetadata.h
index a9ce389ff3..30a6f39fc3 100644
--- a/libgimpbase/gimpmetadata.h
+++ b/libgimpbase/gimpmetadata.h
@@ -55,20 +55,23 @@ typedef enum
 
 /**
  * GimpMetadataSaveFlags:
- * @GIMP_METADATA_SAVE_EXIF:      Save EXIF
- * @GIMP_METADATA_SAVE_XMP:       Save XMP
- * @GIMP_METADATA_SAVE_IPTC:      Save IPTC
- * @GIMP_METADATA_SAVE_THUMBNAIL: Save a thumbnail of the image
- * @GIMP_METADATA_SAVE_ALL:       Save all of the above
+ * @GIMP_METADATA_SAVE_EXIF:          Save EXIF
+ * @GIMP_METADATA_SAVE_XMP:           Save XMP
+ * @GIMP_METADATA_SAVE_IPTC:          Save IPTC
+ * @GIMP_METADATA_SAVE_THUMBNAIL:     Save a thumbnail of the image
+ * @GIMP_METADATA_SAVE_COLOR_PROFILE: Save the image's color profile
+ *                                    Since: 2.10.10
+ * @GIMP_METADATA_SAVE_ALL:           Save all of the above
  *
  * What kinds of metadata to save when exporting images.
  **/
 typedef enum
 {
-  GIMP_METADATA_SAVE_EXIF      = 1 << 0,
-  GIMP_METADATA_SAVE_XMP       = 1 << 1,
-  GIMP_METADATA_SAVE_IPTC      = 1 << 2,
-  GIMP_METADATA_SAVE_THUMBNAIL = 1 << 3,
+  GIMP_METADATA_SAVE_EXIF          = 1 << 0,
+  GIMP_METADATA_SAVE_XMP           = 1 << 1,
+  GIMP_METADATA_SAVE_IPTC          = 1 << 2,
+  GIMP_METADATA_SAVE_THUMBNAIL     = 1 << 3,
+  GIMP_METADATA_SAVE_COLOR_PROFILE = 1 << 4,
 
   GIMP_METADATA_SAVE_ALL       = 0xffffffff
 } GimpMetadataSaveFlags;
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 05601c3e0f..b7cc9dba25 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -553,7 +553,7 @@ run (const gchar      *name,
       pngvals.save_xmp       = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
       pngvals.save_iptc      = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
       pngvals.save_thumbnail = (metadata_flags & GIMP_METADATA_SAVE_THUMBNAIL) != 0;
-      pngvals.save_profile   = gimp_export_color_profile ();
+      pngvals.save_profile   = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
 
       /* Override preferences from PNG export defaults (if saved). */
       load_parasite ();
@@ -659,6 +659,11 @@ run (const gchar      *name,
                   else
                     metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
 
+                  if (pngvals.save_profile)
+                    metadata_flags |= GIMP_METADATA_SAVE_COLOR_PROFILE;
+                  else
+                    metadata_flags &= ~GIMP_METADATA_SAVE_COLOR_PROFILE;
+
                   file = g_file_new_for_path (param[3].data.d_string);
                   gimp_image_metadata_save_finish (orig_image_ID,
                                                    "image/png",
diff --git a/plug-ins/file-jpeg/jpeg.c b/plug-ins/file-jpeg/jpeg.c
index b23e89842e..b1e77ff6e7 100644
--- a/plug-ins/file-jpeg/jpeg.c
+++ b/plug-ins/file-jpeg/jpeg.c
@@ -347,7 +347,7 @@ run (const gchar      *name,
       jsvals.save_xmp       = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
       jsvals.save_iptc      = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
       jsvals.save_thumbnail = (metadata_flags & GIMP_METADATA_SAVE_THUMBNAIL) != 0;
-      jsvals.save_profile   = gimp_export_color_profile ();
+      jsvals.save_profile   = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
 
       parasite = gimp_image_get_parasite (orig_image_ID, "gimp-comment");
       if (parasite)
@@ -570,6 +570,11 @@ run (const gchar      *name,
               else
                 metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
 
+              if (jsvals.save_profile)
+                metadata_flags |= GIMP_METADATA_SAVE_COLOR_PROFILE;
+              else
+                metadata_flags &= ~GIMP_METADATA_SAVE_COLOR_PROFILE;
+
               file = g_file_new_for_path (param[3].data.d_string);
               gimp_image_metadata_save_finish (orig_image_ID,
                                                "image/jpeg",
diff --git a/plug-ins/file-tiff/file-tiff.c b/plug-ins/file-tiff/file-tiff.c
index 11c6873b1e..ef5994386c 100644
--- a/plug-ins/file-tiff/file-tiff.c
+++ b/plug-ins/file-tiff/file-tiff.c
@@ -367,7 +367,7 @@ run (const gchar      *name,
       tsvals.save_xmp       = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
       tsvals.save_iptc      = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
       tsvals.save_thumbnail = (metadata_flags & GIMP_METADATA_SAVE_THUMBNAIL) != 0;
-      tsvals.save_profile   = gimp_export_color_profile ();
+      tsvals.save_profile   = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
 
       parasite = gimp_image_get_parasite (orig_image, "gimp-comment");
       if (parasite)
@@ -500,6 +500,11 @@ run (const gchar      *name,
                   /* never save metadata thumbnails for TIFF, see bug #729952 */
                   metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
 
+                  if (tsvals.save_profile)
+                    metadata_flags |= GIMP_METADATA_SAVE_COLOR_PROFILE;
+                  else
+                    metadata_flags &= ~GIMP_METADATA_SAVE_COLOR_PROFILE;
+
                   gimp_image_metadata_save_finish (image,
                                                    "image/tiff",
                                                    metadata, metadata_flags,


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