[gimp] Bug 492048 - Detect color space in Exif 2.21/DCF 2.0 option files



commit 7e9957851e6197a77bc8149488135897ce8530c4
Author: Michael Natterer <mitch gimp org>
Date:   Mon Sep 28 19:54:18 2015 +0200

    Bug 492048 - Detect color space in Exif 2.21/DCF 2.0 option files
    
    Copy a ton of logic from darktable and libkexiv2 and parse more
    metadata tags which contain colorspace information, namely:
    
    Exif.Photo.ColorSpace
    Xmp.exif.ColorSpace
    Exif.Nikon3.ColorSpace
    Exif.Canon.ColorSpace

 libgimp/gimpimagemetadata.c |   91 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 78 insertions(+), 13 deletions(-)
---
diff --git a/libgimp/gimpimagemetadata.c b/libgimp/gimpimagemetadata.c
index 2b109ce..1b77435 100644
--- a/libgimp/gimpimagemetadata.c
+++ b/libgimp/gimpimagemetadata.c
@@ -177,28 +177,93 @@ gimp_image_metadata_load_finish (gint32                 image_ID,
 
   if (flags & GIMP_METADATA_LOAD_COLORSPACE)
     {
-      gchar *value;
+      GimpColorProfile *profile = gimp_image_get_color_profile (image_ID);
+
+      /* only look for colorspace information from metadata if the
+       * image didn't contain an embedded color profile
+       *
+       * the logic here was mostly taken from darktable and libkexiv2
+       */
+      if (! profile)
+        {
+          glong colorspace = -1;
+
+          if (gexiv2_metadata_has_tag (metadata,
+                                       "Exif.Photo.ColorSpace"))
+            {
+              colorspace = gexiv2_metadata_get_tag_long (metadata,
+                                                         "Exif.Photo.ColorSpace");
+            }
+          else if (gexiv2_metadata_has_tag (metadata,
+                                            "Xmp.exif.ColorSpace"))
+            {
+              colorspace = gexiv2_metadata_get_tag_long (metadata,
+                                                         "Xmp.exif.ColorSpace");
+            }
+
+          if (colorspace == 0x01)
+            {
+              /* sRGB, a NULL profile will do the right thing  */
+            }
+          else if (colorspace == 0x02)
+            {
+              profile = gimp_color_profile_new_adobe_rgb ();
+            }
+          else if (colorspace == 0xffff)
+            {
+              gchar *iop_index;
 
-      value = gexiv2_metadata_get_tag_interpreted_string (metadata,
+              iop_index = gexiv2_metadata_get_tag_string (metadata,
                                                           "Exif.Iop.InteroperabilityIndex");
 
-      if (! g_strcmp0 (value, "R03"))
-        {
-          GimpColorProfile *profile = gimp_image_get_color_profile (image_ID);
+              if (! g_strcmp0 (iop_index, "R03"))
+                {
+                  profile = gimp_color_profile_new_adobe_rgb ();
+                }
+              else if (! g_strcmp0 (iop_index, "R98"))
+                {
+                  /* sRGB, a NULL profile will do the right thing  */
+                }
 
-          if (! profile)
+              g_free (iop_index);
+            }
+          else if (gexiv2_metadata_has_tag (metadata,
+                                            "Exif.Nikon3.ColorSpace"))
             {
-              /* honor the R03 InteroperabilityIndex only if the
-               * image didn't contain an ICC profile
-               */
-              profile = gimp_color_profile_new_adobe_rgb ();
-              gimp_image_set_color_profile (image_ID, profile);
+              colorspace = gexiv2_metadata_get_tag_long (metadata,
+                                                         "Exif.Nikon3.ColorSpace");
+
+              if (colorspace == 0x01)
+                {
+                  /* sRGB, a NULL profile will do the right thing  */
+                }
+              else if (colorspace == 0x02)
+                {
+                  profile = gimp_color_profile_new_adobe_rgb ();
+                }
+            }
+          else if (gexiv2_metadata_has_tag (metadata,
+                                            "Exif.Canon.ColorSpace"))
+            {
+              colorspace = gexiv2_metadata_get_tag_long (metadata,
+                                                         "Exif.Canon.ColorSpace");
+
+              if (colorspace == 0x01)
+                {
+                  /* sRGB, a NULL profile will do the right thing  */
+                }
+              else if (colorspace == 0x02)
+                {
+                  profile = gimp_color_profile_new_adobe_rgb ();
+                }
             }
 
-          g_object_unref (profile);
+          if (profile)
+            gimp_image_set_color_profile (image_ID, profile);
         }
 
-      g_free (value);
+      if (profile)
+        g_object_unref (profile);
     }
 
   gimp_image_set_metadata (image_ID, metadata);


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