From 11cb75681b1b13813dae6d60214ca6904c5a0d36 Mon Sep 17 00:00:00 2001 From: Andrey Kiselev Date: Sat, 6 Dec 2003 15:55:41 +0000 Subject: [PATCH] Read WhitePoint tag from the file and properly use it for CIE Lab->RGB transform. --- libtiff/tif_aux.c | 25 +++++++++++++++---------- libtiff/tif_getimage.c | 13 +++++++++---- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/libtiff/tif_aux.c b/libtiff/tif_aux.c index 81d51011..79d0b198 100644 --- a/libtiff/tif_aux.c +++ b/libtiff/tif_aux.c @@ -1,4 +1,4 @@ -/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_aux.c,v 1.5 2003-07-08 15:51:57 warmerda Exp $ */ +/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_aux.c,v 1.6 2003-12-06 15:55:41 dron Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -31,8 +31,6 @@ */ #include "tiffiop.h" #include "tif_predict.h" - -#ifdef COLORIMETRY_SUPPORT #include static void @@ -66,7 +64,6 @@ TIFFDefaultRefBlackWhite(TIFFDirectory* td) td->td_refblackwhite[2*i+1] = (float)((1L<td_bitspersample)-1L); } } -#endif /* * Like TIFFGetField, but return any default @@ -123,7 +120,6 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap) *va_arg(ap, uint16*) = (uint16) sp->predictor; return (1); } -#ifdef CMYK_SUPPORT case TIFFTAG_DOTRANGE: *va_arg(ap, uint16 *) = 0; *va_arg(ap, uint16 *) = (1<td_bitspersample)-1; @@ -134,7 +130,6 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap) case TIFFTAG_NUMBEROFINKS: *va_arg(ap, uint16 *) = td->td_ninks; return (1); -#endif case TIFFTAG_EXTRASAMPLES: *va_arg(ap, uint16 *) = td->td_extrasamples; *va_arg(ap, uint16 **) = td->td_sampleinfo; @@ -156,7 +151,6 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap) case TIFFTAG_IMAGEDEPTH: *va_arg(ap, uint32 *) = td->td_imagedepth; return (1); -#ifdef YCBCR_SUPPORT case TIFFTAG_YCBCRCOEFFICIENTS: if (!td->td_ycbcrcoeffs) { td->td_ycbcrcoeffs = (float *) @@ -175,8 +169,20 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap) case TIFFTAG_YCBCRPOSITIONING: *va_arg(ap, uint16 *) = td->td_ycbcrpositioning; return (1); -#endif -#ifdef COLORIMETRY_SUPPORT + case TIFFTAG_WHITEPOINT: + if (!td->td_whitepoint) { + td->td_whitepoint = (float *) + _TIFFmalloc(2 * sizeof (float)); + /* TIFF 6.0 specification says that it is no default + value for the WhitePoint, but AdobePhotoshop TIFF + Technical Note tells that it should be CIE D50. */ + td->td_whitepoint[0] = + D50_X0 / (D50_X0 + D50_Y0 + D50_Z0); + td->td_whitepoint[1] = + D50_Y0 / (D50_X0 + D50_Y0 + D50_Z0); + } + *va_arg(ap, float **) = td->td_whitepoint; + return (1); case TIFFTAG_TRANSFERFUNCTION: if (!td->td_transferfunction[0]) TIFFDefaultTransferFunction(td); @@ -191,7 +197,6 @@ TIFFVGetFieldDefaulted(TIFF* tif, ttag_t tag, va_list ap) TIFFDefaultRefBlackWhite(td); *va_arg(ap, float **) = td->td_refblackwhite; return (1); -#endif } return (0); } diff --git a/libtiff/tif_getimage.c b/libtiff/tif_getimage.c index 4ccded4b..0fdcbbc4 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.32 2003-12-04 10:31:54 dron Exp $ */ +/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_getimage.c,v 1.33 2003-12-06 15:55:41 dron Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -2050,6 +2050,8 @@ initCIELabConversion(TIFFRGBAImage* img) { static char module[] = "initCIELabConversion"; + float *coeffs, X0, Y0, Z0; + if (!img->cielab) { img->cielab = (TIFFCIELabToRGB *) _TIFFmalloc(sizeof(TIFFCIELabToRGB)); @@ -2059,9 +2061,12 @@ initCIELabConversion(TIFFRGBAImage* img) return NULL; } } - - if (TIFFCIELabToRGBInit(img->cielab, &display_sRGB, - D50_X0, D50_Y0, D50_Z0) < 0) { + + TIFFGetFieldDefaulted(img->tif, TIFFTAG_WHITEPOINT, &coeffs); + Y0 = 100.0; + X0 = coeffs[0] / coeffs[1] * Y0; + Z0 = (1.0 - coeffs[0] - coeffs[1]) / coeffs[1] * Y0; + if (TIFFCIELabToRGBInit(img->cielab, &display_sRGB, X0, Y0, Z0) < 0) { TIFFError(module, "Failed to initialize CIE L*a*b*->RGB conversion state."); _TIFFfree(img->cielab);