From 89cf48606e002b5be8454438ce4439e2897e2ff7 Mon Sep 17 00:00:00 2001 From: Andrey Kiselev Date: Wed, 10 Nov 2004 21:08:11 +0000 Subject: [PATCH] Set the appropriate ReferenceBlackWhite array for YCbCr image which lacks that tag (noted by Hans Petter Selasky). --- libtiff/tif_aux.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/libtiff/tif_aux.c b/libtiff/tif_aux.c index ffc7946c..1260edff 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.7 2004-10-02 13:29:41 dron Exp $ */ +/* $Id: tif_aux.c,v 1.8 2004-11-10 21:08:11 dron Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -81,9 +81,24 @@ TIFFDefaultRefBlackWhite(TIFFDirectory* td) if (!(td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float)))) return 0; - for (i = 0; i < 3; i++) { - td->td_refblackwhite[2*i+0] = 0; - td->td_refblackwhite[2*i+1] = (float)((1L<td_bitspersample)-1L); + if (td->td_photometric == PHOTOMETRIC_YCBCR) { + /* + * YCbCr (Class Y) images must have the ReferenceBlackWhite + * tag set. Fix the broken images, which lacks that tag. + */ + td->td_refblackwhite[0] = 0.0F; + td->td_refblackwhite[1] = td->td_refblackwhite[3] = + td->td_refblackwhite[5] = 255.0F; + td->td_refblackwhite[2] = td->td_refblackwhite[4] = 128.0F; + } else { + /* + * Assume RGB (Class R) + */ + for (i = 0; i < 3; i++) { + td->td_refblackwhite[2*i+0] = 0; + td->td_refblackwhite[2*i+1] = + (float)((1L<td_bitspersample)-1L); + } } return 1; } @@ -246,3 +261,5 @@ TIFFGetFieldDefaulted(TIFF* tif, ttag_t tag, ...) va_end(ap); return (ok); } + +/* vim: set ts=8 sts=8 sw=8 noet: */