626
623
TIFFAppendToStrip(TIFF* tif, tstrip_t strip, tidata_t data, tsize_t cc)
628
TIFFDirectory *td = &tif->tif_dir;
629
static const char module[] = "TIFFAppendToStrip";
631
if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) {
633
* No current offset, set the current strip.
635
assert(td->td_nstrips > 0);
636
if (td->td_stripoffset[strip] != 0) {
625
static const char module[] = "TIFFAppendToStrip";
626
TIFFDirectory *td = &tif->tif_dir;
628
if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) {
629
assert(td->td_nstrips > 0);
631
if( td->td_stripbytecount[strip] != 0
632
&& td->td_stripoffset[strip] != 0
633
&& td->td_stripbytecount[strip] >= cc )
636
* There is already tile data on disk, and the new tile
637
* data we have to will fit in the same space. The only
638
* aspect of this that is risky is that there could be
639
* more data to append to this strip before we are done
640
* depending on how we are getting called.
642
if (!SeekOK(tif, td->td_stripoffset[strip])) {
643
TIFFErrorExt(tif->tif_clientdata, module,
644
"Seek error at scanline %lu",
645
(unsigned long)tif->tif_row);
652
* Seek to end of file, and set that as our location to
655
td->td_stripoffset[strip] = TIFFSeekFile(tif, 0, SEEK_END);
658
tif->tif_curoff = td->td_stripoffset[strip];
638
* Prevent overlapping of the data chunks. We need
639
* this to enable in place updating of the compressed
640
* images. Larger blocks will be moved at the end of
641
* the file without any optimization of the spare
642
* space, so such scheme is not too much effective.
661
* We are starting a fresh strip/tile, so set the size to zero.
644
if (td->td_stripbytecountsorted) {
645
if (strip == td->td_nstrips - 1
646
|| td->td_stripoffset[strip + 1] <
647
td->td_stripoffset[strip] + cc) {
648
td->td_stripoffset[strip] =
649
TIFFSeekFile(tif, (toff_t)0,
651
td->td_stripbytecountsorted = 0;
655
for (i = 0; i < td->td_nstrips; i++) {
656
if (td->td_stripoffset[i] >
657
td->td_stripoffset[strip]
658
&& td->td_stripoffset[i] <
659
td->td_stripoffset[strip] + cc) {
660
td->td_stripoffset[strip] =
668
if (!SeekOK(tif, td->td_stripoffset[strip])) {
669
TIFFErrorExt(tif->tif_clientdata, module,
670
"%s: Seek error at scanline %lu",
672
(unsigned long)tif->tif_row);
676
td->td_stripoffset[strip] =
677
TIFFSeekFile(tif, (toff_t) 0, SEEK_END);
678
tif->tif_curoff = td->td_stripoffset[strip];
681
if (!WriteOK(tif, data, cc)) {
682
TIFFErrorExt(tif->tif_clientdata, module, "%s: Write error at scanline %lu",
683
tif->tif_name, (unsigned long) tif->tif_row);
686
tif->tif_curoff += cc;
687
td->td_stripbytecount[strip] += cc;
663
td->td_stripbytecount[strip] = 0;
666
if (!WriteOK(tif, data, cc)) {
667
TIFFErrorExt(tif->tif_clientdata, module, "Write error at scanline %lu",
668
(unsigned long) tif->tif_row);
671
tif->tif_curoff = tif->tif_curoff+cc;
672
td->td_stripbytecount[strip] += cc;