From c05abcefc6514c70bea0fbde9e180931e30c56ca Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Wed, 16 Dec 2020 17:56:18 -0500 Subject: [PATCH] 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 | 37 +++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/plug-ins/file-tiff/file-tiff-load.c b/plug-ins/file-tiff/file-tiff-load.c index ab1520bd6f..414789b9cd 100644 --- a/plug-ins/file-tiff/file-tiff-load.c +++ b/plug-ins/file-tiff/file-tiff-load.c @@ -171,6 +171,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; @@ -381,12 +382,38 @@ load_image (GFile *file, TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLEFORMAT, &sampleformat); profile = load_profile (tif); + if (! profile && first_profile) + { + profile = first_profile; + g_object_ref (profile); + } + if (profile) { + profile_linear = gimp_color_profile_is_linear (profile); + + if (! first_profile) + { + first_profile = profile; + g_object_ref (first_profile); + + if (profile_linear && li > 0 && pages.target != GIMP_PAGE_SELECTOR_TARGET_IMAGES) + g_message (_("This image has a linear color profile but " + "it was not set on the first layer. " + "The layers below layer # %d will be " + "interpreted as non linear."), li+1); + } + else if (pages.target != GIMP_PAGE_SELECTOR_TARGET_IMAGES && + ! gimp_color_profile_is_equal (first_profile, profile)) + { + g_message (_("This image has multiple color profiles. " + "We will use the first one. If this leads " + "to incorrect results you should consider " + "loading each layer as a separate image.")); + } + if (! *image) *profile_loaded = TRUE; - - profile_linear = gimp_color_profile_is_linear (profile); } if (bps > 8 && bps != 8 && bps != 16 && bps != 32 && bps != 64) @@ -888,10 +915,11 @@ load_image (GFile *file, } /* attach color profile */ - if (profile) { - gimp_image_set_color_profile (*image, profile); + if (pages.target == GIMP_PAGE_SELECTOR_TARGET_IMAGES || profile == first_profile) + gimp_image_set_color_profile (*image, profile); + g_object_unref (profile); } @@ -1396,6 +1424,7 @@ load_image (GFile *file, gimp_progress_update (1.0); } + g_clear_object (&first_profile); if (pages.target == GIMP_PAGE_SELECTOR_TARGET_IMAGES) {