diff options
Diffstat (limited to 'src/libtiff/tif_write.c')
-rw-r--r-- | src/libtiff/tif_write.c | 108 |
1 files changed, 61 insertions, 47 deletions
diff --git a/src/libtiff/tif_write.c b/src/libtiff/tif_write.c index 8a90fc7..9650a07 100644 --- a/src/libtiff/tif_write.c +++ b/src/libtiff/tif_write.c @@ -1,4 +1,4 @@ -/* $Id: tif_write.c,v 1.4 2009/12/11 15:17:41 scuri Exp $ */ +/* $Id: tif_write.c,v 1.5 2010/01/26 15:56:36 scuri Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -227,8 +227,10 @@ TIFFWriteEncodedStrip(TIFF* tif, tstrip_t strip, tdata_t data, tsize_t cc) if( td->td_stripbytecount[strip] > 0 ) { - /* Force TIFFAppendToStrip() to consider placing data at end - of file. */ + /* if we are writing over existing tiles, zero length. */ + td->td_stripbytecount[strip] = 0; + + /* this forces TIFFAppendToStrip() to do a seek */ tif->tif_curoff = 0; } @@ -361,8 +363,10 @@ TIFFWriteEncodedTile(TIFF* tif, ttile_t tile, tdata_t data, tsize_t cc) if( td->td_stripbytecount[tile] > 0 ) { - /* Force TIFFAppendToStrip() to consider placing data at end - of file. */ + /* if we are writing over existing tiles, zero length. */ + td->td_stripbytecount[tile] = 0; + + /* this forces TIFFAppendToStrip() to do a seek */ tif->tif_curoff = 0; } @@ -517,8 +521,7 @@ TIFFWriteCheck(TIFF* tif, int tiles, const char* module) * because this field is used in other parts of library even * in the single band case. */ - if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) - tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG; + tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG; } else { if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) { TIFFErrorExt(tif->tif_clientdata, module, @@ -622,53 +625,64 @@ TIFFGrowStrips(TIFF* tif, int delta, const char* module) static int TIFFAppendToStrip(TIFF* tif, tstrip_t strip, tidata_t data, tsize_t cc) { - static const char module[] = "TIFFAppendToStrip"; TIFFDirectory *td = &tif->tif_dir; + static const char module[] = "TIFFAppendToStrip"; if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) { - assert(td->td_nstrips > 0); - - if( td->td_stripbytecount[strip] != 0 - && td->td_stripoffset[strip] != 0 - && td->td_stripbytecount[strip] >= cc ) - { - /* - * There is already tile data on disk, and the new tile - * data we have to will fit in the same space. The only - * aspect of this that is risky is that there could be - * more data to append to this strip before we are done - * depending on how we are getting called. - */ - if (!SeekOK(tif, td->td_stripoffset[strip])) { - TIFFErrorExt(tif->tif_clientdata, module, - "Seek error at scanline %lu", - (unsigned long)tif->tif_row); - return (0); - } - } - else - { - /* - * Seek to end of file, and set that as our location to - * write this strip. - */ - td->td_stripoffset[strip] = TIFFSeekFile(tif, 0, SEEK_END); - } - - tif->tif_curoff = td->td_stripoffset[strip]; - - /* - * We are starting a fresh strip/tile, so set the size to zero. - */ - td->td_stripbytecount[strip] = 0; + /* + * No current offset, set the current strip. + */ + assert(td->td_nstrips > 0); + if (td->td_stripoffset[strip] != 0) { + /* + * Prevent overlapping of the data chunks. We need + * this to enable in place updating of the compressed + * images. Larger blocks will be moved at the end of + * the file without any optimization of the spare + * space, so such scheme is not too much effective. + */ + if (td->td_stripbytecountsorted) { + if (strip == td->td_nstrips - 1 + || td->td_stripoffset[strip + 1] < + td->td_stripoffset[strip] + cc) { + td->td_stripoffset[strip] = + TIFFSeekFile(tif, (toff_t)0, + SEEK_END); + } + } else { + tstrip_t i; + for (i = 0; i < td->td_nstrips; i++) { + if (td->td_stripoffset[i] > + td->td_stripoffset[strip] + && td->td_stripoffset[i] < + td->td_stripoffset[strip] + cc) { + td->td_stripoffset[strip] = + TIFFSeekFile(tif, + (toff_t)0, + SEEK_END); + } + } + } + + if (!SeekOK(tif, td->td_stripoffset[strip])) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Seek error at scanline %lu", + tif->tif_name, + (unsigned long)tif->tif_row); + return (0); + } + } else + td->td_stripoffset[strip] = + TIFFSeekFile(tif, (toff_t) 0, SEEK_END); + tif->tif_curoff = td->td_stripoffset[strip]; } if (!WriteOK(tif, data, cc)) { - TIFFErrorExt(tif->tif_clientdata, module, "Write error at scanline %lu", - (unsigned long) tif->tif_row); - return (0); + TIFFErrorExt(tif->tif_clientdata, module, "%s: Write error at scanline %lu", + tif->tif_name, (unsigned long) tif->tif_row); + return (0); } - tif->tif_curoff = tif->tif_curoff+cc; + tif->tif_curoff += cc; td->td_stripbytecount[strip] += cc; return (1); } |