From 0634bf3da9c077648f3ff7bf18f1418eadf21b89 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Mon, 6 Jun 2022 10:08:04 +0000 Subject: [PATCH] plug-ins: fix #1106 Add CMYK/A loading for TIFFs Adds support for loading 8 and 16 bit CMYK/A TIFF files with attached color profiles. --- plug-ins/file-tiff/file-tiff-load.c | 50 ++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/plug-ins/file-tiff/file-tiff-load.c b/plug-ins/file-tiff/file-tiff-load.c index 8855efc663..ea574d4f7a 100644 --- a/plug-ins/file-tiff/file-tiff-load.c +++ b/plug-ins/file-tiff/file-tiff-load.c @@ -495,6 +495,7 @@ load_image (GFile *file, GimpPrecision image_precision; const Babl *type; const Babl *base_format = NULL; + const Babl *space = NULL; guint16 orientation; gint cols; gint rows; @@ -961,6 +962,47 @@ load_image (GFile *file, fill_4bit2byte (tiff_mode); break; + case PHOTOMETRIC_SEPARATED: + layer_type = alpha ? GIMP_RGBA_IMAGE : GIMP_RGB_IMAGE; + /* It's possible that a CMYK image might not have an + * attached profile, so we'll check for it and set up + * space accordingly + */ + if (profile && gimp_color_profile_is_cmyk (profile)) + { + space = gimp_color_profile_get_space (profile, + GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC, + error); + g_clear_object (&profile); + } + else + { + space = NULL; + } + + if (alpha) + base_format = babl_format_new (babl_model ("CMYKA"), + type, + babl_component ("Cyan"), + babl_component ("Magenta"), + babl_component ("Yellow"), + babl_component ("Key"), + babl_component ("A"), + NULL); + else + base_format = babl_format_new (babl_model ("CMYK"), + type, + babl_component ("Cyan"), + babl_component ("Magenta"), + babl_component ("Yellow"), + babl_component ("Key"), + NULL); + + base_format = + babl_format_with_space (babl_format_get_encoding (base_format), + space); + break; + default: g_printerr ("photomet: %d (%d)\n", photomet, PHOTOMETRIC_PALETTE); worst_case = TRUE; @@ -1082,7 +1124,7 @@ load_image (GFile *file, } } - /* attach color profile */ + /* attach non-CMYK color profile */ if (profile) { if (pages.target == GIMP_PAGE_SELECTOR_TARGET_IMAGES || profile == first_profile) @@ -1350,6 +1392,12 @@ load_image (GFile *file, */ base_format = gimp_drawable_get_format (layer); } + else if (! space) + { + base_format = + babl_format_with_space (babl_format_get_encoding (base_format), + gimp_drawable_get_format (layer)); + } channel[0].ID = layer; channel[0].buffer = gimp_drawable_get_buffer (layer);