Hi,
> Thanks for the feedback ! I'll write the remaining part and submit it to
> upstream.
You can find a first draft in attachment.
While it's already a working solution (at least, I think), there's
still place for improvements.
* I'm not sure that the check it well positioned in the source code
* I still fear some redundancy with some other similar (but irrelevant in our
case) code at libtiff/tif_getimage.c:326
Also, I've double checked and RGB is the only case to handle. Palette
should have SamplePerPixel = 1, AFAIK BlackIsZero/WhiteIsZero should not
specify this field and YCbCr should always have SamplePerPixel = 3.
Feedback welcome.
Cheers,
Hugo
--
Hugo Lefeuvre (hle) | www.owl.eu.com
4096/ 9C4F C8BF A4B0 8FC5 48EB 56B8 1962 765B B9A8 BACA
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 6baa7b31..d9295800 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -4024,6 +4024,26 @@ TIFFReadDirectory(TIFF* tif)
}
}
}
+
+ /*
+ * Make sure all non-color channels are extrasamples.
+ * If it's not the case, define them as such.
+ */
+ if (tif->tif_dir.td_photometric == PHOTOMETRIC_RGB &&
+ tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples > 3) {
+ TIFFWarningExt(tif->tif_clientdata,module, "More than 3 color channels in "
+ "RGB image, defining non-standard channels as extrasamples");
+
+ int old_extrasamples = tif->tif_dir.td_extrasamples;
+ tif->tif_dir.td_extrasamples += ((tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples) - 3);
+
+ // sampleinfo should contain information relative to these new extra samples
+ uint16 new_sampleinfo[tif->tif_dir.td_extrasamples];
+ memset(new_sampleinfo, 0, tif->tif_dir.td_extrasamples);
+ memcpy(new_sampleinfo, tif->tif_dir.td_sampleinfo, old_extrasamples * sizeof(uint16));
+ _TIFFsetShortArray(&tif->tif_dir.td_sampleinfo, new_sampleinfo, tif->tif_dir.td_extrasamples);
+ }
+
/*
* Verify Palette image has a Colormap.
*/
diff --git a/libtiff/tif_print.c b/libtiff/tif_print.c
index 8deceb2b..5f9a676e 100644
--- a/libtiff/tif_print.c
+++ b/libtiff/tif_print.c
@@ -544,7 +544,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
uint16 i;
fprintf(fd, " %2ld: %5u",
l, td->td_transferfunction[0][l]);
- for (i = 1; i < td->td_samplesperpixel; i++)
+ for (i = 1; i < td->td_samplesperpixel - td->td_extrasamples; i++)
fprintf(fd, " %5u",
td->td_transferfunction[i][l]);
fputc('\n', fd);
Attachment:
signature.asc
Description: PGP signature