/* do nothing */
}
-static i_img *read_one_tiff(TIFF *tif) {
+static i_img *read_one_tiff(TIFF *tif, int allow_incomplete) {
i_img *im;
uint32 width, height;
uint16 channels;
mm_log((1, "i_readtiff_wiol: %stiled\n", tiled?"":"not "));
mm_log((1, "i_readtiff_wiol: %sbyte swapped\n", TIFFIsByteSwapped(tif)?"":"not "));
+ /* separated defaults to CMYK, but if the user is using some strange
+ ink system we can't work out the color anyway */
+ if (photometric == PHOTOMETRIC_SEPARATED && channels >= 4) {
+ /* TIFF can have more than one alpha channel on an image,
+ but Imager can't, only store the first one */
+
+ channels = channels == 4 ? 3 : 4;
+
+ /* unfortunately the RGBA functions don't try to deal with the alpha
+ channel on CMYK images, at some point I'm planning on expanding
+ TIFF support to handle 16-bit/sample images and I'll deal with
+ it then */
+ }
+
+ /* TIFF images can have more than one alpha channel, but Imager can't
+ this ignores the possibility of 2 channel images with 2 alpha,
+ but there's not much I can do about that */
+ if (channels > 4)
+ channels = 4;
+
if (photometric == PHOTOMETRIC_PALETTE && bits_per_sample <= 8) {
channels = 3;
im = i_img_pal_new(width, height, channels, 256);
++row;
}
if (row < height) {
+ if (allow_incomplete) {
+ i_tags_setn(&im->tags, "i_lines_read", row);
+ }
+ else {
+ i_img_destroy(im);
+ _TIFFfree(buffer);
+ return NULL;
+ }
error = 1;
}
/* Ideally we'd optimize the palette, but that could be expensive
uint32 newrows, i_row;
if (!TIFFReadRGBAStrip(tif, row, raster)) {
- error++;
- break;
+ if (allow_incomplete) {
+ i_tags_setn(&im->tags, "i_lines_read", row);
+ error++;
+ break;
+ }
+ else {
+ i_push_error(0, "could not read TIFF image strip");
+ _TIFFfree(raster);
+ i_img_destroy(im);
+ return NULL;
+ }
}
newrows = (row+rowsperstrip > height) ? height-row : rowsperstrip;
}
if (error) {
mm_log((1, "i_readtiff_wiol: error during reading\n"));
- i_tags_addn(&im->tags, "i_incomplete", 0, 1);
+ i_tags_setn(&im->tags, "i_incomplete", 1);
}
if (raster)
_TIFFfree( raster );
=cut
*/
i_img*
-i_readtiff_wiol(io_glue *ig, int length, int page) {
+i_readtiff_wiol(io_glue *ig, int allow_incomplete, int page) {
TIFF* tif;
TIFFErrorHandler old_handler;
TIFFErrorHandler old_warn_handler;
/* Also add code to check for mmapped code */
io_glue_commit_types(ig);
- mm_log((1, "i_readtiff_wiol(ig %p, length %d)\n", ig, length));
+ mm_log((1, "i_readtiff_wiol(ig %p, allow_incomplete %d, page %d)\n", ig, allow_incomplete, page));
tif = TIFFClientOpen("(Iolayer)",
"rm",
}
}
- im = read_one_tiff(tif);
+ im = read_one_tiff(tif, allow_incomplete);
if (TIFFLastDirectory(tif)) mm_log((1, "Last directory of tiff file\n"));
TIFFSetErrorHandler(old_handler);
*count = 0;
do {
- i_img *im = read_one_tiff(tif);
+ i_img *im = read_one_tiff(tif, 0);
if (!im)
break;
if (++*count > result_alloc) {