From c377583233d7b1e54c6992add0dd18e346696fd3 Mon Sep 17 00:00:00 2001 From: olivier Date: Fri, 31 Dec 2010 16:12:40 +0000 Subject: * libtiff/tif_dirread.c: Allow reading directories where TIFFTAG_SMINSAMPLEVALUE and TIFFTAG_SMAXSAMPLEVALUE values differ for each channel. The min/max of all channels is used as appropriate. --- ChangeLog | 6 ++++++ libtiff/tif_dirread.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f443998..4ddb920c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-12-31 Olivier Paquet + + * libtiff/tif_dirread.c: Allow reading directories where + TIFFTAG_SMINSAMPLEVALUE and TIFFTAG_SMAXSAMPLEVALUE values differ for each + channel. The min/max of all channels is used as appropriate. + 2010-12-14 Lee Howard * libtiff/tif_dirread.c: tolerate some cases where diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 9e8b9c5c..667a5d96 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirread.c,v 1.92.2.14 2010-12-15 01:04:34 faxguy Exp $ */ +/* $Id: tif_dirread.c,v 1.92.2.15 2010-12-31 16:12:40 olivier Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -54,7 +54,7 @@ static float TIFFFetchRational(TIFF*, TIFFDirEntry*); static int TIFFFetchNormalTag(TIFF*, TIFFDirEntry*); static int TIFFFetchPerSampleShorts(TIFF*, TIFFDirEntry*, uint16*); static int TIFFFetchPerSampleLongs(TIFF*, TIFFDirEntry*, uint32*); -static int TIFFFetchPerSampleAnys(TIFF*, TIFFDirEntry*, double*); +static int TIFFFetchPerSampleAnys(TIFF*, TIFFDirEntry*, double*, double*); static int TIFFFetchShortArray(TIFF*, TIFFDirEntry*, uint16*); static int TIFFFetchStripThing(TIFF*, TIFFDirEntry*, long, uint32**); static int TIFFFetchRefBlackWhite(TIFF*, TIFFDirEntry*); @@ -480,11 +480,18 @@ TIFFReadDirectory(TIFF* tif) } break; case TIFFTAG_SMINSAMPLEVALUE: + { + double minv = 0.0, maxv = 0.0; + if (!TIFFFetchPerSampleAnys(tif, dp, &minv, &maxv) || + !TIFFSetField(tif, dp->tdir_tag, minv)) + goto bad; + } + break; case TIFFTAG_SMAXSAMPLEVALUE: { - double dv = 0.0; - if (!TIFFFetchPerSampleAnys(tif, dp, &dv) || - !TIFFSetField(tif, dp->tdir_tag, dv)) + double minv = 0.0, maxv = 0.0; + if (!TIFFFetchPerSampleAnys(tif, dp, &minv, &maxv) || + !TIFFSetField(tif, dp->tdir_tag, maxv)) goto bad; } break; @@ -1852,11 +1859,11 @@ TIFFFetchPerSampleLongs(TIFF* tif, TIFFDirEntry* dir, uint32* pl) } /* - * Fetch samples/pixel ANY values for the specified tag and verify that all - * values are the same. + * Fetch samples/pixel ANY values for the specified tag and returns their min + * and max. */ static int -TIFFFetchPerSampleAnys(TIFF* tif, TIFFDirEntry* dir, double* pl) +TIFFFetchPerSampleAnys(TIFF* tif, TIFFDirEntry* dir, double* minv, double* maxv) { uint16 samples = tif->tif_dir.td_samplesperpixel; int status = 0; @@ -1874,17 +1881,16 @@ TIFFFetchPerSampleAnys(TIFF* tif, TIFFDirEntry* dir, double* pl) if( samples < check_count ) check_count = samples; + *minv = *maxv = v[0]; for (i = 1; i < check_count; i++) - if (v[i] != v[0]) { - TIFFErrorExt(tif->tif_clientdata, tif->tif_name, - "Cannot handle different per-sample values for field \"%s\"", - _TIFFFieldWithTag(tif, dir->tdir_tag)->field_name); - goto bad; - } - *pl = v[0]; + { + if (v[i] < *minv) + *minv = v[i]; + if (v[i] > *maxv) + *maxv = v[i]; + } status = 1; } - bad: if (v && v != buf) _TIFFfree(v); } -- cgit v1.2.1