[gimp] Issue #3532 - Wrong color profile on nikon taken photos, it's...



commit a08293dc74c8c8d6aeb26683b31d24d02cb59e3a
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jun 20 18:08:59 2019 +0200

    Issue #3532 - Wrong color profile on nikon taken photos, it's...
    
    ...always AdobeRGB!
    
    Change all file plug-ins to never call gimp_image_metadata_load_finish()
    with the GIMP_METADATA_LOAD_COLORSPACE when they loaded a color profile.
    
    This keeps gimp_image_metadata_load_finish() from assigning a profile
    from DCT even if the loaded profile was GIMP's built-in sRGB.

 plug-ins/common/file-heif.c            | 16 +++++----
 plug-ins/common/file-jp2-load.c        | 23 ++++++++++---
 plug-ins/common/file-png.c             | 13 +++++++-
 plug-ins/file-psd/psd-image-res-load.c |  4 ++-
 plug-ins/file-psd/psd-image-res-load.h |  1 +
 plug-ins/file-psd/psd-load.c           | 10 ++++--
 plug-ins/file-psd/psd-load.h           |  1 +
 plug-ins/file-psd/psd.c                |  8 ++++-
 plug-ins/file-tiff/file-tiff-load.c    |  9 ++++-
 plug-ins/file-tiff/file-tiff-load.h    | 11 +++---
 plug-ins/file-tiff/file-tiff.c         |  5 +++
 plug-ins/file-webp/file-webp-load.c    | 61 ++++++++++++++++++----------------
 12 files changed, 113 insertions(+), 49 deletions(-)
---
diff --git a/plug-ins/common/file-heif.c b/plug-ins/common/file-heif.c
index 6617ff3865..0ccb3e2551 100644
--- a/plug-ins/common/file-heif.c
+++ b/plug-ins/common/file-heif.c
@@ -528,10 +528,7 @@ load_image (GFile     *file,
   gimp_image_set_filename (image_ID, g_file_get_uri (file));
 
   if (profile)
-    {
-      gimp_image_set_color_profile (image_ID, profile);
-      g_object_unref (profile);
-    }
+    gimp_image_set_color_profile (image_ID, profile);
 
   layer_ID = gimp_layer_new (image_ID,
                              _("image content"),
@@ -604,7 +601,8 @@ load_image (GFile     *file,
 
     if (exif_data || xmp_data)
       {
-        GimpMetadata *metadata = gimp_metadata_new ();
+        GimpMetadata          *metadata = gimp_metadata_new ();
+        GimpMetadataLoadFlags  flags    = GIMP_METADATA_LOAD_ALL;
 
         if (exif_data)
           gimp_metadata_set_from_exif (metadata,
@@ -614,12 +612,18 @@ load_image (GFile     *file,
           gimp_metadata_set_from_xmp (metadata,
                                       xmp_data, xmp_data_size, NULL);
 
+        if (profile)
+          flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
+
         gimp_image_metadata_load_finish (image_ID, "image/heif",
-                                         metadata, GIMP_METADATA_LOAD_ALL,
+                                         metadata, flags,
                                          interactive);
       }
   }
 
+  if (profile)
+    g_object_unref (profile);
+
   heif_image_handle_release (handle);
   heif_context_free (ctx);
   heif_image_release (img);
diff --git a/plug-ins/common/file-jp2-load.c b/plug-ins/common/file-jp2-load.c
index 5c6c6e21b3..f0be18f10b 100644
--- a/plug-ins/common/file-jp2-load.c
+++ b/plug-ins/common/file-jp2-load.c
@@ -104,6 +104,7 @@ static gint32         load_image   (const gchar       *filename,
                                     OPJ_CODEC_FORMAT   format,
                                     OPJ_COLOR_SPACE    color_space,
                                     gboolean           interactive,
+                                    gboolean          *profile_loaded,
                                     GError           **error);
 
 static OPJ_COLOR_SPACE open_dialog (const gchar      *filename,
@@ -206,6 +207,7 @@ run (const gchar      *name,
   GimpRunMode        run_mode;
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
   gint               image_ID;
+  gboolean           profile_loaded = FALSE;
   GError            *error = NULL;
 
   run_mode = param[0].data.d_int32;
@@ -232,6 +234,7 @@ run (const gchar      *name,
           gimp_ui_init (PLUG_IN_BINARY, FALSE);
           interactive = TRUE;
           break;
+
         default:
           if (strcmp (name, LOAD_J2K_PROC) == 0)
             {
@@ -266,11 +269,17 @@ run (const gchar      *name,
         }
 
       if (strcmp (name, LOAD_JP2_PROC) == 0)
-        image_ID = load_image (param[1].data.d_string, OPJ_CODEC_JP2,
-                               color_space, interactive, &error);
+        {
+          image_ID = load_image (param[1].data.d_string, OPJ_CODEC_JP2,
+                                 color_space, interactive, &profile_loaded,
+                                 &error);
+        }
       else /* strcmp (name, LOAD_J2K_PROC) == 0 */
-        image_ID = load_image (param[1].data.d_string, OPJ_CODEC_J2K,
-                               color_space, interactive, &error);
+        {
+          image_ID = load_image (param[1].data.d_string, OPJ_CODEC_J2K,
+                                 color_space, interactive, &profile_loaded,
+                                 &error);
+        }
 
       if (image_ID != -1)
         {
@@ -284,6 +293,9 @@ run (const gchar      *name,
             {
               GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
 
+              if (profile_loaded)
+                flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
+
               gimp_image_metadata_load_finish (image_ID, "image/jp2",
                                                metadata, flags,
                                                interactive);
@@ -1028,6 +1040,7 @@ load_image (const gchar       *filename,
             OPJ_CODEC_FORMAT   format,
             OPJ_COLOR_SPACE    color_space,
             gboolean           interactive,
+            gboolean          *profile_loaded,
             GError           **error)
 {
   opj_stream_t      *stream;
@@ -1118,6 +1131,8 @@ load_image (const gchar       *filename,
           if (! profile)
             goto out;
 
+          *profile_loaded = TRUE;
+
           if (image->color_space == OPJ_CLRSPC_UNSPECIFIED ||
               image->color_space == OPJ_CLRSPC_UNKNOWN)
             {
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 1dabd09c04..13e14dd6d7 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -158,6 +158,7 @@ static void      run                       (const gchar      *name,
 static gint32    load_image                (const gchar      *filename,
                                             gboolean          interactive,
                                             gboolean         *resolution_loaded,
+                                            gboolean         *profile_loaded,
                                             GError          **error);
 static gboolean  save_image                (const gchar      *filename,
                                             gint32            image_ID,
@@ -453,6 +454,7 @@ run (const gchar      *name,
     {
       gboolean interactive;
       gboolean resolution_loaded = FALSE;
+      gboolean profile_loaded    = FALSE;
 
       switch (run_mode)
         {
@@ -469,6 +471,7 @@ run (const gchar      *name,
       image_ID = load_image (param[1].data.d_string,
                              interactive,
                              &resolution_loaded,
+                             &profile_loaded,
                              &error);
 
       if (image_ID != -1)
@@ -486,6 +489,9 @@ run (const gchar      *name,
               if (resolution_loaded)
                 flags &= ~GIMP_METADATA_LOAD_RESOLUTION;
 
+              if (profile_loaded)
+                flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
+
               gimp_image_metadata_load_finish (image_ID, "image/png",
                                                metadata, flags,
                                                interactive);
@@ -856,6 +862,7 @@ static gint32
 load_image (const gchar  *filename,
             gboolean      interactive,
             gboolean     *resolution_loaded,
+            gboolean     *profile_loaded,
             GError      **error)
 {
   gint              i;                    /* Looping var */
@@ -962,7 +969,11 @@ load_image (const gchar  *filename,
   profile = load_color_profile (pp, info, &profile_name);
 
   if (profile)
-    linear = gimp_color_profile_is_linear (profile);
+    {
+      *profile_loaded = TRUE;
+
+      linear = gimp_color_profile_is_linear (profile);
+    }
 
   /*
    * Get image precision and color model
diff --git a/plug-ins/file-psd/psd-image-res-load.c b/plug-ins/file-psd/psd-image-res-load.c
index ee6149c103..7949c6ca52 100644
--- a/plug-ins/file-psd/psd-image-res-load.c
+++ b/plug-ins/file-psd/psd-image-res-load.c
@@ -278,6 +278,7 @@ load_image_resource (PSDimageres  *res_a,
                      PSDimage     *img_a,
                      FILE         *f,
                      gboolean     *resolution_loaded,
+                     gboolean     *profile_loaded,
                      GError      **error)
 {
   gint  pad;
@@ -367,7 +368,8 @@ load_image_resource (PSDimageres  *res_a,
             break;
 
           case PSD_ICC_PROFILE:
-            load_resource_1039 (res_a, image_id, f, error);
+            if (! load_resource_1039 (res_a, image_id, f, error))
+              *profile_loaded = TRUE;
             break;
 
           case PSD_ALPHA_NAMES_UNI:
diff --git a/plug-ins/file-psd/psd-image-res-load.h b/plug-ins/file-psd/psd-image-res-load.h
index 8ccf6d556e..c981a6b79f 100644
--- a/plug-ins/file-psd/psd-image-res-load.h
+++ b/plug-ins/file-psd/psd-image-res-load.h
@@ -31,6 +31,7 @@ gint  load_image_resource       (PSDimageres  *res_a,
                                  PSDimage     *img_a,
                                  FILE         *f,
                                  gboolean     *resolution_loaded,
+                                 gboolean     *profile_loaded,
                                  GError      **error);
 
 gint  load_thumbnail_resource   (PSDimageres  *res_a,
diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c
index 962cc1a132..d973eba29a 100644
--- a/plug-ins/file-psd/psd-load.c
+++ b/plug-ins/file-psd/psd-load.c
@@ -70,6 +70,7 @@ static gint             add_image_resources        (gint32        image_id,
                                                     PSDimage     *img_a,
                                                     FILE         *f,
                                                     gboolean     *resolution_loaded,
+                                                    gboolean     *profile_loaded,
                                                     GError      **error);
 
 static gint             add_layers                 (gint32        image_id,
@@ -115,6 +116,7 @@ gint32
 load_image (const gchar  *filename,
             gboolean      merged_image_only,
             gboolean     *resolution_loaded,
+            gboolean     *profile_loaded,
             GError      **load_error)
 {
   FILE         *f;
@@ -189,7 +191,9 @@ load_image (const gchar  *filename,
 
   /* ----- Add image resources ----- */
   IFDBG(2) g_debug ("Add image resources");
-  if (add_image_resources (image_id, &img_a, f, resolution_loaded, &error) < 0)
+  if (add_image_resources (image_id, &img_a, f,
+                           resolution_loaded, profile_loaded,
+                           &error) < 0)
     goto load_error;
   gimp_progress_update (0.8);
 
@@ -1064,6 +1068,7 @@ add_image_resources (gint32     image_id,
                      PSDimage  *img_a,
                      FILE      *f,
                      gboolean  *resolution_loaded,
+                     gboolean  *profile_loaded,
                      GError   **error)
 {
   PSDimageres  res_a;
@@ -1097,7 +1102,8 @@ add_image_resources (gint32     image_id,
         }
 
       if (load_image_resource (&res_a, image_id, img_a, f,
-                               resolution_loaded, error) < 0)
+                               resolution_loaded, profile_loaded,
+                               error) < 0)
         return -1;
     }
 
diff --git a/plug-ins/file-psd/psd-load.h b/plug-ins/file-psd/psd-load.h
index fb83c01613..42eb516315 100644
--- a/plug-ins/file-psd/psd-load.h
+++ b/plug-ins/file-psd/psd-load.h
@@ -25,6 +25,7 @@
 gint32  load_image (const gchar  *filename,
                     gboolean      merged_image_only,
                     gboolean     *resolution_loaded,
+                    gboolean     *profile_loaded,
                     GError      **error);
 
 
diff --git a/plug-ins/file-psd/psd.c b/plug-ins/file-psd/psd.c
index 075544e042..083a5a9444 100644
--- a/plug-ins/file-psd/psd.c
+++ b/plug-ins/file-psd/psd.c
@@ -202,6 +202,7 @@ run (const gchar      *name,
       strcmp (name, LOAD_MERGED_PROC) == 0)
     {
       gboolean resolution_loaded = FALSE;
+      gboolean profile_loaded    = FALSE;
       gboolean interactive;
 
       switch (run_mode)
@@ -218,7 +219,9 @@ run (const gchar      *name,
 
       image_ID = load_image (param[1].data.d_string,
                              strcmp (name, LOAD_MERGED_PROC) == 0,
-                             &resolution_loaded, &error);
+                             &resolution_loaded,
+                             &profile_loaded,
+                             &error);
 
       if (image_ID != -1)
         {
@@ -235,6 +238,9 @@ run (const gchar      *name,
               if (resolution_loaded)
                 flags &= ~GIMP_METADATA_LOAD_RESOLUTION;
 
+              if (profile_loaded)
+                flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
+
               gimp_image_metadata_load_finish (image_ID, "image/x-psd",
                                                metadata, flags,
                                                interactive);
diff --git a/plug-ins/file-tiff/file-tiff-load.c b/plug-ins/file-tiff/file-tiff-load.c
index eda3a8e563..38c40aa771 100644
--- a/plug-ins/file-tiff/file-tiff-load.c
+++ b/plug-ins/file-tiff/file-tiff-load.c
@@ -151,6 +151,7 @@ load_image (GFile        *file,
             GimpRunMode   run_mode,
             gint32       *image,
             gboolean     *resolution_loaded,
+            gboolean     *profile_loaded,
             GError      **error)
 {
   TIFF              *tif;
@@ -341,7 +342,12 @@ load_image (GFile        *file,
 
       profile = load_profile (tif);
       if (profile)
-        profile_linear = gimp_color_profile_is_linear (profile);
+        {
+          if (! *image)
+            *profile_loaded = TRUE;
+
+          profile_linear = gimp_color_profile_is_linear (profile);
+        }
 
       if (bps > 8 && bps != 8 && bps != 16 && bps != 32 && bps != 64)
         worst_case = TRUE; /* Wrong sample width => RGBA */
@@ -1216,6 +1222,7 @@ load_image (GFile        *file,
           min_col = 0;
           min_row = 0;
         }
+
       /* resize image to bounding box of all layers */
       gimp_image_resize (*image,
                          max_col - min_col, max_row - min_row,
diff --git a/plug-ins/file-tiff/file-tiff-load.h b/plug-ins/file-tiff/file-tiff-load.h
index b0435676b6..19dc0c7d64 100644
--- a/plug-ins/file-tiff/file-tiff-load.h
+++ b/plug-ins/file-tiff/file-tiff-load.h
@@ -34,11 +34,12 @@ typedef struct
 } TiffSelectedPages;
 
 
-GimpPDBStatusType load_image  (GFile              *file,
-                               GimpRunMode         run_mode,
-                               gint32             *image,
-                               gboolean           *resolution_loaded,
-                               GError            **error);
+GimpPDBStatusType load_image  (GFile        *file,
+                               GimpRunMode   run_mode,
+                               gint32       *image,
+                               gboolean     *resolution_loaded,
+                               gboolean     *profile_loaded,
+                               GError      **error);
 
 
 #endif /* __FILE_TIFF_LOAD_H__ */
diff --git a/plug-ins/file-tiff/file-tiff.c b/plug-ins/file-tiff/file-tiff.c
index deca8c8118..6ca94e3c17 100644
--- a/plug-ins/file-tiff/file-tiff.c
+++ b/plug-ins/file-tiff/file-tiff.c
@@ -211,12 +211,14 @@ run (const gchar      *name,
       GFile    *file  = g_file_new_for_uri (param[1].data.d_string);
       gint32    image = 0;
       gboolean  resolution_loaded = FALSE;
+      gboolean  profile_loaded    = FALSE;
 
       if (run_mode == GIMP_RUN_INTERACTIVE)
         gimp_ui_init (PLUG_IN_BINARY, FALSE);
 
       status = load_image (file, run_mode, &image,
                            &resolution_loaded,
+                           &profile_loaded,
                            &error);
 
       if (image > 0)
@@ -234,6 +236,9 @@ run (const gchar      *name,
               if (resolution_loaded)
                 flags &= ~GIMP_METADATA_LOAD_RESOLUTION;
 
+              if (profile_loaded)
+                flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
+
               gimp_image_metadata_load_finish (image, "image/tiff",
                                                metadata, flags,
                                                run_mode == GIMP_RUN_INTERACTIVE);
diff --git a/plug-ins/file-webp/file-webp-load.c b/plug-ins/file-webp/file-webp-load.c
index ac6832eb95..1f49784226 100644
--- a/plug-ins/file-webp/file-webp-load.c
+++ b/plug-ins/file-webp/file-webp-load.c
@@ -77,18 +77,19 @@ load_image (const gchar *filename,
             gboolean     interactive,
             GError      **error)
 {
-  uint8_t  *indata = NULL;
-  gsize     indatalen;
-  gint      width;
-  gint      height;
-  gint32    image_ID;
-  WebPMux  *mux;
-  WebPData  wp_data;
-  uint32_t  flags;
-  gboolean  animation = FALSE;
-  gboolean  icc       = FALSE;
-  gboolean  exif      = FALSE;
-  gboolean  xmp       = FALSE;
+  uint8_t          *indata = NULL;
+  gsize             indatalen;
+  gint              width;
+  gint              height;
+  gint32            image_ID;
+  WebPMux          *mux;
+  WebPData          wp_data;
+  GimpColorProfile *profile   = NULL;
+  uint32_t          flags;
+  gboolean          animation = FALSE;
+  gboolean          icc       = FALSE;
+  gboolean          exif      = FALSE;
+  gboolean          xmp       = FALSE;
 
   /* Attempt to read the file contents from disk */
   if (! g_file_get_contents (filename,
@@ -135,6 +136,17 @@ load_image (const gchar *filename,
   /* Create the new image and associated layer */
   image_ID = gimp_image_new (width, height, GIMP_RGB);
 
+  if (icc)
+    {
+      WebPData icc_profile;
+
+      WebPMuxGetChunk (mux, "ICCP", &icc_profile);
+      profile = gimp_color_profile_new_from_icc_profile (icc_profile.bytes,
+                                                         icc_profile.size, NULL);
+      if (profile)
+        gimp_image_set_color_profile (image_ID, profile);
+    }
+
   if (! animation)
     {
       uint8_t *outdata;
@@ -233,21 +245,6 @@ load_image (const gchar *filename,
   /* Free the original compressed data */
   g_free (indata);
 
-  if (icc)
-    {
-      WebPData          icc_profile;
-      GimpColorProfile *profile;
-
-      WebPMuxGetChunk (mux, "ICCP", &icc_profile);
-      profile = gimp_color_profile_new_from_icc_profile (icc_profile.bytes,
-                                                         icc_profile.size, NULL);
-      if (profile)
-        {
-          gimp_image_set_color_profile (image_ID, profile);
-          g_object_unref (profile);
-        }
-    }
-
   if (exif || xmp)
     {
       GimpMetadata *metadata;
@@ -272,8 +269,13 @@ load_image (const gchar *filename,
                                                    file, NULL);
       if (metadata)
         {
+          GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
+
+          if (profile)
+            flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
+
           gimp_image_metadata_load_finish (image_ID, "image/webp",
-                                           metadata, GIMP_METADATA_LOAD_ALL,
+                                           metadata, flags,
                                            interactive);
           g_object_unref (metadata);
         }
@@ -285,5 +287,8 @@ load_image (const gchar *filename,
 
   gimp_image_set_filename (image_ID, filename);
 
+  if (profile)
+    g_object_unref (profile);
+
   return image_ID;
 }


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