Skip to content

Commit

Permalink
Merge branch 'fix-18187'
Browse files Browse the repository at this point in the history
* fix-18187:
  Treat data with 2 samples per pixel as monochrome
  Actually we can read TIFF files with arbitrary number of samples per pixel
  • Loading branch information
TurboGit committed Jan 12, 2025
2 parents cadda1c + 2e333c5 commit 57d7f14
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/imageio/imageio_tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 57d7f14

Please sign in to comment.