From 62d3736392611f6b21ad20719f8bd52096f1cca3 Mon Sep 17 00:00:00 2001 From: Frank Warmerdam Date: Sat, 15 Dec 2001 15:11:22 +0000 Subject: [PATCH] bug 93: default unmarked 4th sample as alpha --- ChangeLog | 12 ++++++++++++ libtiff/tif_getimage.c | 18 +++++++++++++++++- libtiff/tiffconf.h | 11 ++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 404aad8d..b0e99640 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2001-12-15 Frank Warmerdam + + * libtiff/tif_getimage.c: If DEFAULT_EXTRASAMPLE_AS_ALPHA is 1 + (defined in tiffconf.h - 1 by default) then the RGBA interface + will assume that a fourth extra sample is ASSOCALPHA if the + EXTRASAMPLE value isn't set for it. This changes the behaviour of + the library, but makes it work better with RGBA files produced by + lots of applications that don't mark the alpha values properly. + + http://bugzilla.remotesensing.org/show_bug.cgi?id=93 + http://bugzilla.remotesensing.org/show_bug.cgi?id=65 + 2001-12-12 Frank Warmerdam * libtiff/tif_jpeg.c: allow jpeg data stream sampling values to diff --git a/libtiff/tif_getimage.c b/libtiff/tif_getimage.c index 89c621e5..ed270765 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.15 2001-09-24 19:40:37 warmerda Exp $ */ +/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_getimage.c,v 1.16 2001-12-15 15:11:22 warmerda Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -220,12 +220,28 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, &extrasamples, &sampleinfo); if (extrasamples == 1) + { switch (sampleinfo[0]) { case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */ case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */ img->alpha = sampleinfo[0]; break; } + } + +#if DEFAULT_EXTRASAMPLE_AS_ALPHA == 1 + if( !TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) + img->photometric = PHOTOMETRIC_MINISWHITE; + + if( extrasamples == 0 + && img->samplesperpixel == 4 + && img->photometric == PHOTOMETRIC_RGB ) + { + img->alpha = EXTRASAMPLE_ASSOCALPHA; + extrasamples = 1; + } +#endif + colorchannels = img->samplesperpixel - extrasamples; TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress); TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig); diff --git a/libtiff/tiffconf.h b/libtiff/tiffconf.h index ef1e6cf0..c6e33d73 100644 --- a/libtiff/tiffconf.h +++ b/libtiff/tiffconf.h @@ -1,4 +1,4 @@ -/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/Attic/tiffconf.h,v 1.3 2001-05-12 03:59:50 warmerda Exp $ */ +/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/Attic/tiffconf.h,v 1.4 2001-12-15 15:11:22 warmerda Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1991-1997 Silicon Graphics, Inc. @@ -133,6 +133,11 @@ * or not to convert single-strip uncompressed images * to mutiple strips of ~8Kb--to reduce memory use) * SUBIFD_SUPPORT enable support for SubIFD tag (thumbnails and such) + * DEFAULT_EXTRASAMPLE_AS_ALPHA + * The RGBA interface will treat a fourth sample with + * no EXTRASAMPLE_ value as being ASSOCALPHA. Many + * packages produce RGBA files but don't mark the alpha + * properly. */ #ifndef STRIPCHOP_DEFAULT #define STRIPCHOP_DEFAULT TIFF_STRIPCHOP /* default is to enable */ @@ -140,4 +145,8 @@ #ifndef SUBIFD_SUPPORT #define SUBIFD_SUPPORT 1 /* enable SubIFD tag (330) support */ #endif +#ifndef DEFAULT_EXTRASAMPLE_AS_ALPHA +#define DEFAULT_EXTRASAMPLE_AS_ALPHA 1 +#endif + #endif /* _TIFFCONF_ */