summaryrefslogtreecommitdiff
path: root/thirdparty/libtiff/tif_flush.c
diff options
context:
space:
mode:
authorMathieu Malaterre <mathieu.malaterre@gmail.com>2012-03-12 11:35:35 +0000
committerMathieu Malaterre <mathieu.malaterre@gmail.com>2012-03-12 11:35:35 +0000
commitecd5c523dcd8a416771cb89b1cdef69c94d0aca4 (patch)
treed1c75280e1c3777f46b2e55ecbfd6487809532d8 /thirdparty/libtiff/tif_flush.c
parent3de14fc63ecddf490637117ea650e0f559e7f9fe (diff)
[trunk] Update libtiff to 4.0.1 to support BigTIFF. openjpeg/tiff 4.0.1 currently builds on linux/x86_64 and linux/mingw32.
Diffstat (limited to 'thirdparty/libtiff/tif_flush.c')
-rw-r--r--thirdparty/libtiff/tif_flush.c64
1 files changed, 54 insertions, 10 deletions
diff --git a/thirdparty/libtiff/tif_flush.c b/thirdparty/libtiff/tif_flush.c
index 7ecc4d83..fd14e4cd 100644
--- a/thirdparty/libtiff/tif_flush.c
+++ b/thirdparty/libtiff/tif_flush.c
@@ -1,4 +1,4 @@
-/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_flush.c,v 1.3.2.1 2010-06-08 18:50:42 bfriesen Exp $ */
+/* $Id: tif_flush.c,v 1.9 2010-03-31 06:40:10 fwarmerdam Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@@ -32,15 +32,58 @@
int
TIFFFlush(TIFF* tif)
{
+ if( tif->tif_mode == O_RDONLY )
+ return 1;
- if (tif->tif_mode != O_RDONLY) {
- if (!TIFFFlushData(tif))
- return (0);
- if ((tif->tif_flags & TIFF_DIRTYDIRECT) &&
- !TIFFWriteDirectory(tif))
- return (0);
- }
- return (1);
+ if (!TIFFFlushData(tif))
+ return (0);
+
+ /* In update (r+) mode we try to detect the case where
+ only the strip/tile map has been altered, and we try to
+ rewrite only that portion of the directory without
+ making any other changes */
+
+ if( (tif->tif_flags & TIFF_DIRTYSTRIP)
+ && !(tif->tif_flags & TIFF_DIRTYDIRECT)
+ && tif->tif_mode == O_RDWR )
+ {
+ uint64 *offsets=NULL, *sizes=NULL;
+
+ if( TIFFIsTiled(tif) )
+ {
+ if( TIFFGetField( tif, TIFFTAG_TILEOFFSETS, &offsets )
+ && TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &sizes )
+ && _TIFFRewriteField( tif, TIFFTAG_TILEOFFSETS, TIFF_LONG8,
+ tif->tif_dir.td_nstrips, offsets )
+ && _TIFFRewriteField( tif, TIFFTAG_TILEBYTECOUNTS, TIFF_LONG8,
+ tif->tif_dir.td_nstrips, sizes ) )
+ {
+ tif->tif_flags &= ~TIFF_DIRTYSTRIP;
+ tif->tif_flags &= ~TIFF_BEENWRITING;
+ return 1;
+ }
+ }
+ else
+ {
+ if( TIFFGetField( tif, TIFFTAG_STRIPOFFSETS, &offsets )
+ && TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &sizes )
+ && _TIFFRewriteField( tif, TIFFTAG_STRIPOFFSETS, TIFF_LONG8,
+ tif->tif_dir.td_nstrips, offsets )
+ && _TIFFRewriteField( tif, TIFFTAG_STRIPBYTECOUNTS, TIFF_LONG8,
+ tif->tif_dir.td_nstrips, sizes ) )
+ {
+ tif->tif_flags &= ~TIFF_DIRTYSTRIP;
+ tif->tif_flags &= ~TIFF_BEENWRITING;
+ return 1;
+ }
+ }
+ }
+
+ if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP))
+ && !TIFFRewriteDirectory(tif))
+ return (0);
+
+ return (1);
}
/*
@@ -56,7 +99,7 @@ int
TIFFFlushData(TIFF* tif)
{
if ((tif->tif_flags & TIFF_BEENWRITING) == 0)
- return (0);
+ return (1);
if (tif->tif_flags & TIFF_POSTENCODE) {
tif->tif_flags &= ~TIFF_POSTENCODE;
if (!(*tif->tif_postencode)(tif))
@@ -65,6 +108,7 @@ TIFFFlushData(TIFF* tif)
return (TIFFFlushData1(tif));
}
+/* vim: set ts=8 sts=8 sw=8 noet: */
/*
* Local Variables:
* mode: c