From d15abe6676ce80b7093309118f0c7d702cf07106 Mon Sep 17 00:00:00 2001 From: Frank Warmerdam Date: Fri, 31 Aug 2001 13:53:08 +0000 Subject: [PATCH] Allow handling of images with extra samples that are to be ignored for contiguous 8bit greyscale and paletted images. See bug http://bugzilla.remotesensing.org/show_bug.cgi?id=75 --- ChangeLog | 8 +++++++ libtiff/tif_getimage.c | 52 ++++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index e39e3fd3..f222d75a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-08-31 Frank Warmerdam + + * libtiff/tif_getimage.c: relax handling of contig case where + there are extra samples that are supposed to be ignored. This + should now work for 8bit greyscale or palletted images. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=75 + 2001-08-28 Frank Warmerdam * libtiff/tif_getimage.c: Don't complain for CMYK (separated) diff --git a/libtiff/tif_getimage.c b/libtiff/tif_getimage.c index a1be1b2c..1abf231e 100644 --- a/libtiff/tif_getimage.c +++ b/libtiff/tif_getimage.c @@ -1,4 +1,4 @@ -/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_getimage.c,v 1.12 2001-08-28 13:11:38 warmerda Exp $ */ +/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_getimage.c,v 1.13 2001-08-31 13:53:08 warmerda Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -82,13 +82,22 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024]) case PHOTOMETRIC_MINISWHITE: case PHOTOMETRIC_MINISBLACK: case PHOTOMETRIC_PALETTE: - if (td->td_planarconfig == PLANARCONFIG_CONTIG && td->td_samplesperpixel != 1) { + if (td->td_planarconfig == PLANARCONFIG_CONTIG + && td->td_samplesperpixel != 1 + && td->td_bitspersample < 8 ) { sprintf(emsg, - "Sorry, can not handle contiguous data with %s=%d, and %s=%d", - photoTag, photometric, - "Samples/pixel", td->td_samplesperpixel); + "Sorry, can not handle contiguous data with %s=%d, " + "and %s=%d and Bits/Sample=%d", + photoTag, photometric, + "Samples/pixel", td->td_samplesperpixel, + td->td_bitspersample); return (0); } + /* + ** We should likely validate that any extra samples are either + ** to be ignored, or are alpha, and if alpha we should try to use + ** them. But for now we won't bother with this. + */ break; case PHOTOMETRIC_YCBCR: if (td->td_planarconfig != PLANARCONFIG_CONTIG) { @@ -261,11 +270,15 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) /* fall thru... */ case PHOTOMETRIC_MINISWHITE: case PHOTOMETRIC_MINISBLACK: - if (planarconfig == PLANARCONFIG_CONTIG && img->samplesperpixel != 1) { + if (planarconfig == PLANARCONFIG_CONTIG + && img->samplesperpixel != 1 + && img->bitspersample < 8 ) { sprintf(emsg, - "Sorry, can not handle contiguous data with %s=%d, and %s=%d", - photoTag, img->photometric, - "Samples/pixel", img->samplesperpixel); + "Sorry, can not handle contiguous data with %s=%d, " + "and %s=%d and Bits/Sample=%d", + photoTag, img->photometric, + "Samples/pixel", img->samplesperpixel, + img->bitspersample); return (0); } break; @@ -789,10 +802,15 @@ static void name(\ DECLAREContigPutFunc(put8bitcmaptile) { uint32** PALmap = img->PALmap; + int samplesperpixel = img->samplesperpixel; - (void) x; (void) y; + (void) y; while (h-- > 0) { - UNROLL8(w, NOP, *cp++ = PALmap[*pp++][0]); + for (x = w; x-- > 0;) + { + *cp++ = PALmap[*pp][0]; + pp += samplesperpixel; + } cp += toskew; pp += fromskew; } @@ -854,12 +872,16 @@ DECLAREContigPutFunc(put1bitcmaptile) */ DECLAREContigPutFunc(putgreytile) { + int samplesperpixel = img->samplesperpixel; uint32** BWmap = img->BWmap; (void) y; while (h-- > 0) { for (x = w; x-- > 0;) - *cp++ = BWmap[*pp++][0]; + { + *cp++ = BWmap[*pp][0]; + pp += samplesperpixel; + } cp += toskew; pp += fromskew; } @@ -870,6 +892,7 @@ DECLAREContigPutFunc(putgreytile) */ DECLAREContigPutFunc(put16bitbwtile) { + int samplesperpixel = img->samplesperpixel; uint32** BWmap = img->BWmap; (void) y; @@ -880,8 +903,9 @@ DECLAREContigPutFunc(put16bitbwtile) { /* use high order byte of 16bit value */ - *cp++ = BWmap[*(wp++) >> 8][0]; - pp += 2; + *cp++ = BWmap[*wp >> 8][0]; + pp += 2 * samplesperpixel; + wp += samplesperpixel; } cp += toskew; pp += fromskew;