From 371336daa888321de62cf52461c6dc5287e12d05 Mon Sep 17 00:00:00 2001 From: fwarmerdam Date: Fri, 2 Nov 2007 19:53:04 +0000 Subject: [PATCH] avoid extra tile info write in TIFFWriteDirectory() --- ChangeLog | 7 +++++++ libtiff/tif_dirwrite.c | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 084969f04..067d3493a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2007-11-02 Frank Warmerdam + * tif_dirwrite.c: Try to avoid writing out a full readbuffer of tile + data when writing the directory just because we have BEENWRITING at + some point in the past. This was causing odd junk to be written out + in a tile of data when a single tile had an interleaving of reading + and writing with reading last. (highlighted by gdal + autotest/gcore/tif_write.py test 7. + * tif_predict.c: use working buffer in PredictorEncodeTile to avoid modifying callers buffer. http://trac.osgeo.org/gdal/ticket/1965 diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c index a404c1821..30ebe6940 100644 --- a/libtiff/tif_dirwrite.c +++ b/libtiff/tif_dirwrite.c @@ -323,6 +323,8 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) */ if (imagedone) { + tmsize_t orig_rawcc = tif->tif_rawcc; + if (tif->tif_flags & TIFF_POSTENCODE) { tif->tif_flags &= ~TIFF_POSTENCODE; @@ -336,9 +338,12 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) (*tif->tif_close)(tif); /* shutdown encoder */ /* * Flush any data that might have been written - * by the compression close+cleanup routines. + * by the compression close+cleanup routines. But + * be careful not to write stuff if we didn't add data + * in the previous steps as the "rawcc" data may well be + * a previously read tile/strip in mixed read/write mode. */ - if (tif->tif_rawcc > 0 + if (tif->tif_rawcc > 0 && tif->tif_rawcc != orig_rawcc && (tif->tif_flags & TIFF_BEENWRITING) != 0 && !TIFFFlushData1(tif)) {