From 0e6fc28518b636cb4ff4f774455d3a36117db95c Mon Sep 17 00:00:00 2001 From: Victor Forsiuk Date: Sat, 11 Jan 2025 16:37:57 +0200 Subject: [PATCH 1/2] Actually we can read TIFF files with arbitrary number of samples per pixel --- src/imageio/imageio_tiff.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/imageio/imageio_tiff.c b/src/imageio/imageio_tiff.c index 5a986008dfd5..4c0b5c4e3419 100644 --- a/src/imageio/imageio_tiff.c +++ b/src/imageio/imageio_tiff.c @@ -411,13 +411,6 @@ dt_imageio_retval_t dt_imageio_open_tiff(dt_image_t *img, const char *filename, return DT_IMAGEIO_UNSUPPORTED_FEATURE; } - /* we only support 1, 3 or 4 samples per pixel */ - if(t.spp != 1 && t.spp != 3 && t.spp != 4) - { - TIFFClose(t.tiff); - return DT_IMAGEIO_UNSUPPORTED_FEATURE; - } - /* don't depend on planar config if spp == 1 */ if(t.spp > 1 && config != PLANARCONFIG_CONTIG) { From 2e333c572ad02d15d841d9794a666d63c7f6617d Mon Sep 17 00:00:00 2001 From: Victor Forsiuk Date: Sat, 11 Jan 2025 17:14:25 +0200 Subject: [PATCH 2/2] Treat data with 2 samples per pixel as monochrome --- src/imageio/imageio_tiff.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/imageio/imageio_tiff.c b/src/imageio/imageio_tiff.c index 4c0b5c4e3419..da54afe21619 100644 --- a/src/imageio/imageio_tiff.c +++ b/src/imageio/imageio_tiff.c @@ -99,7 +99,7 @@ static inline int _read_chunky_8(tiff_t *t) /* set rgb to first sample from scanline */ out[0] = ((float)in[0]) * (1.0f / 255.0f); - if(t->spp == 1) + if(t->spp < 3) // mono, maybe plus alpha channel { out[1] = out[2] = out[0]; } @@ -130,7 +130,7 @@ static inline int _read_chunky_16(tiff_t *t) { out[0] = ((float)in[0]) * (1.0f / 65535.0f); - if(t->spp == 1) + if(t->spp < 3) // mono, maybe plus alpha channel { out[1] = out[2] = out[0]; } @@ -165,7 +165,7 @@ static inline int _read_chunky_h(tiff_t *t) out[0] = _half_to_float(in[0]); #endif - if(t->spp == 1) + if(t->spp < 3) // mono, maybe plus alpha channel { out[1] = out[2] = out[0]; } @@ -201,7 +201,7 @@ static inline int _read_chunky_f(tiff_t *t) { out[0] = in[0]; - if(t->spp == 1) + if(t->spp < 3) // mono, maybe plus alpha channel { out[1] = out[2] = out[0]; } @@ -237,7 +237,7 @@ static inline int _read_chunky_8_Lab(tiff_t *t, uint16_t photometric) { out[0] = ((float)in[0]) * (100.0f/255.0f); - if(t->spp == 1) + if(t->spp < 3) // mono, maybe plus alpha channel { out[1] = out[2] = 0; } @@ -293,7 +293,7 @@ static inline int _read_chunky_16_Lab(tiff_t *t, uint16_t photometric) { out[0] = ((float)in[0]) * (100.0f/range); - if(t->spp == 1) + if(t->spp < 3) // mono, maybe plus alpha channel { out[1] = out[2] = 0; }