From 40c424104de1f12de0132a7dfc9ea46d110c364f Mon Sep 17 00:00:00 2001 From: Andrey Kiselev Date: Fri, 1 Jul 2005 12:35:18 +0000 Subject: [PATCH] Added open option 'h' to avoid reading the first IFD when needed. As per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=875 --- libtiff/tif_open.c | 16 +++++++++++++++- libtiff/tiffiop.h | 4 +++- man/TIFFOpen.3tiff | 9 +++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/libtiff/tif_open.c b/libtiff/tif_open.c index ea517d09..83cfd11e 100644 --- a/libtiff/tif_open.c +++ b/libtiff/tif_open.c @@ -1,4 +1,4 @@ -/* $Id: tif_open.c,v 1.25 2005-06-03 13:41:13 dron Exp $ */ +/* $Id: tif_open.c,v 1.26 2005-07-01 12:35:18 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -222,6 +222,7 @@ TIFFClientOpen( * 'm' disable use of memory-mapped files * 'C' enable strip chopping support when reading * 'c' disable strip chopping support + * 'h' read TIFF header only, do not load the first IFD * * The use of the 'l' and 'b' flags is strongly discouraged. * These flags are provided solely because numerous vendors, @@ -296,6 +297,9 @@ TIFFClientOpen( if (m == O_RDONLY) tif->tif_flags &= ~TIFF_STRIPCHOP; break; + case 'h': + tif->tif_flags |= TIFF_HEADERONLY; + break; } /* * Read in TIFF header. @@ -378,6 +382,16 @@ TIFFClientOpen( tif->tif_flags |= TIFF_MYBUFFER; tif->tif_rawcp = tif->tif_rawdata = 0; tif->tif_rawdatasize = 0; + + /* + * Sometimes we do not want to read the first directory (for example, + * it may be broken) and want to proceed to other directories. I this + * case we use the TIFF_HEADERONLY flag to open file and return + * immediately after reading TIFF header. + */ + if (tif->tif_flags & TIFF_HEADERONLY) + return (tif); + /* * Setup initial directory. */ diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h index 4435c72d..103dc88b 100644 --- a/libtiff/tiffiop.h +++ b/libtiff/tiffiop.h @@ -1,4 +1,4 @@ -/* $Id: tiffiop.h,v 1.35 2005-06-29 10:21:35 dron Exp $ */ +/* $Id: tiffiop.h,v 1.36 2005-07-01 12:35:18 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -109,6 +109,8 @@ struct tiff { #define TIFF_INSUBIFD 0x2000 /* currently writing a subifd */ #define TIFF_UPSAMPLED 0x4000 /* library is doing data up-sampling */ #define TIFF_STRIPCHOP 0x8000 /* enable strip chopping support */ +#define TIFF_HEADERONLY 0x10000 /* read header only, do not process */ + /* the first directory */ toff_t tif_diroff; /* file offset of current directory */ toff_t tif_nextdiroff; /* file offset of following directory */ toff_t* tif_dirlist; /* list of offsets to already seen */ diff --git a/man/TIFFOpen.3tiff b/man/TIFFOpen.3tiff index e30cb09b..f4209313 100644 --- a/man/TIFFOpen.3tiff +++ b/man/TIFFOpen.3tiff @@ -1,4 +1,4 @@ -.\" $Id: TIFFOpen.3tiff,v 1.1 2004-11-11 14:39:16 dron Exp $ +.\" $Id: TIFFOpen.3tiff,v 1.2 2005-07-01 12:36:22 dron Exp $ .\" .\" Copyright (c) 1988-1997 Sam Leffler .\" Copyright (c) 1991-1997 Silicon Graphics, Inc. @@ -23,7 +23,7 @@ .\" OF THIS SOFTWARE. .\" .if n .po 0 -.TH TIFFOpen 3TIFF "January 9, 1996" "libtiff" +.TH TIFFOpen 3TIFF "July 1, 2005" "libtiff" .SH NAME TIFFOpen, TIFFFdOpen, TIFFClientOpen \- open a .SM TIFF @@ -203,6 +203,11 @@ strip chopping. .TP .B c Disable the use of strip chopping when reading images. +.TP +.B h +Read TIFF header only, do not load the first image directory. That could be +useful in case of the broken first directory. We can open the file and proceed +to the other directories. .SH "BYTE ORDER" The .SM TIFF