[gimp/wip/wormnest/tiff-issue-4176] plug-ins: fix #4176 color displayed wrong in multi page tiffs with linear TRC.




commit 7eba589c1532edfdff682b7b8a9d632d6deaea08
Author: Jacob Boerema <jgboerema gmail com>
Date:   Sat Oct 31 14:48:06 2020 -0400

    plug-ins: fix #4176 color displayed wrong in multi page tiffs with linear TRC.
    
    If we were loading multi page tif images as layers then only the tif pages
    that had a color profile attached would get set as linear (and each tiff page
    can have a color profile). Since most of the time only the first page has a
    color profile this caused us to load linear tiff pages incorrectly.
    
    Also we were overwriting the color profile if there was more than one since
    GIMP can only load one per image. Instead of using the last one we see
    use the first one and notify if we encounter more than one.

 plug-ins/file-tiff/file-tiff-load.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/plug-ins/file-tiff/file-tiff-load.c b/plug-ins/file-tiff/file-tiff-load.c
index 56c504af91..26f9618771 100644
--- a/plug-ins/file-tiff/file-tiff-load.c
+++ b/plug-ins/file-tiff/file-tiff-load.c
@@ -161,6 +161,7 @@ load_image (GFile        *file,
   gint               max_row            = 0;
   gint               max_col            = 0;
   gboolean           save_transp_pixels = FALSE;
+  GimpColorProfile  *first_profile      = NULL;
   gint               li;
 
   *image = NULL;
@@ -344,8 +345,20 @@ load_image (GFile        *file,
       TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLEFORMAT, &sampleformat);
 
       profile = load_profile (tif);
+      if (! profile)
+        {
+          profile = first_profile;
+        }
+
       if (profile)
         {
+          if (! first_profile)
+            first_profile = profile;
+          else if (pages.target != GIMP_PAGE_SELECTOR_TARGET_IMAGES && first_profile != profile)
+            {
+              g_message (_("This image has multiple color profiles. Using the first one."));
+            }
+
           if (! *image)
             *profile_loaded = TRUE;
 
@@ -836,11 +849,13 @@ load_image (GFile        *file,
         }
 
       /* attach color profile */
-
       if (profile)
         {
-          gimp_image_set_color_profile (*image, profile);
-          g_object_unref (profile);
+          if (pages.target == GIMP_PAGE_SELECTOR_TARGET_IMAGES || profile == first_profile)
+            gimp_image_set_color_profile (*image, profile);
+
+          if (profile != first_profile)
+            g_object_unref (profile);
         }
 
       /* attach parasites */
@@ -1218,6 +1233,7 @@ load_image (GFile        *file,
 
       gimp_progress_update (1.0);
     }
+    g_object_unref (first_profile);
 
   if (pages.target == GIMP_PAGE_SELECTOR_TARGET_IMAGES)
     {


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