From 6c7bf882d0cbec811f4e35e7fa74668ae088cd3f Mon Sep 17 00:00:00 2001 From: Andrey Kiselev Date: Sat, 24 Feb 2007 17:09:31 +0000 Subject: [PATCH] Added special function to handle SubjectDistance EXIF tag as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1362 --- libtiff/tif_dirread.c | 53 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 035efd3d..84516f72 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirread.c,v 1.90 2007-02-22 11:33:44 dron Exp $ */ +/* $Id: tif_dirread.c,v 1.91 2007-02-24 17:09:31 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -58,6 +58,7 @@ static int TIFFFetchPerSampleAnys(TIFF*, TIFFDirEntry*, double*); static int TIFFFetchShortArray(TIFF*, TIFFDirEntry*, uint16*); static int TIFFFetchStripThing(TIFF*, TIFFDirEntry*, long, uint32**); static int TIFFFetchRefBlackWhite(TIFF*, TIFFDirEntry*); +static int TIFFFetchSubjectDistance(TIFF*, TIFFDirEntry*); static float TIFFFetchFloat(TIFF*, TIFFDirEntry*); static int TIFFFetchFloatArray(TIFF*, TIFFDirEntry*, float*); static int TIFFFetchDoubleArray(TIFF*, TIFFDirEntry*, double*); @@ -509,7 +510,7 @@ TIFFReadDirectory(TIFF* tif) } } /* - * Joris: OJPEG hack: + * OJPEG hack: * - If a) compression is OJPEG, and b) photometric tag is missing, * then we consistently find that photometric should be YCbCr * - If a) compression is OJPEG, and b) photometric tag says it's RGB, @@ -580,7 +581,7 @@ TIFFReadDirectory(TIFF* tif) goto bad; } /* - * Joris: OJPEG hack: + * OJPEG hack: * We do no further messing with strip/tile offsets/bytecounts in OJPEG * TIFFs */ @@ -860,7 +861,17 @@ TIFFReadCustomDirectory(TIFF* tif, toff_t diroff, goto ignore; } - (void) TIFFFetchNormalTag(tif, dp); + /* + * EXIF tags which need to be specifically processed. + */ + switch (dp->tdir_tag) { + case EXIFTAG_SUBJECTDISTANCE: + (void) TIFFFetchSubjectDistance(tif, dp); + break; + default: + (void) TIFFFetchNormalTag(tif, dp); + break; + } } if (dir) @@ -1226,9 +1237,8 @@ cvtRational(TIFF* tif, TIFFDirEntry* dir, uint32 num, uint32 denom, float* rv) } /* - * Fetch a rational item from the file - * at offset off and return the value - * as a floating point number. + * Fetch a rational item from the file at offset off and return the value as a + * floating point number. */ static float TIFFFetchRational(TIFF* tif, TIFFDirEntry* dir) @@ -1241,9 +1251,8 @@ TIFFFetchRational(TIFF* tif, TIFFDirEntry* dir) } /* - * Fetch a single floating point value - * from the offset field and return it - * as a native float. + * Fetch a single floating point value from the offset field and return it as + * a native float. */ static float TIFFFetchFloat(TIFF* tif, TIFFDirEntry* dir) @@ -1887,6 +1896,30 @@ TIFFFetchRefBlackWhite(TIFF* tif, TIFFDirEntry* dir) return (ok); } +/* + * Fetch and set the SubjectDistance EXIF tag. + */ +static int +TIFFFetchSubjectDistance(TIFF* tif, TIFFDirEntry* dir) +{ + uint32 l[2]; + float v; + int ok = 0; + + if (TIFFFetchData(tif, dir, (char *)l) + && cvtRational(tif, dir, l[0], l[1], &v)) { + /* + * XXX: Numerator 0xFFFFFFFF means that we have infinite + * distance. Indicate that with a negative floating point + * SubjectDistance value. + */ + ok = TIFFSetField(tif, dir->tdir_tag, + (l[0] != 0xFFFFFFFF) ? v : -v); + } + + return ok; +} + /* * Replace a single strip (tile) of uncompressed data by multiple strips * (tiles), each approximately STRIP_SIZE_DEFAULT bytes. This is useful for