~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Source/LibTIFF/tif_write.c

  • Committer: Stefano Rivera
  • Date: 2010-07-24 15:35:51 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: stefanor@ubuntu.com-20100724153551-6s3fth1653huk31a
Tags: upstream-3.13.1
ImportĀ upstreamĀ versionĀ 3.31.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: tif_write.c,v 1.20 2007/11/10 18:41:43 drolon Exp $ */
 
1
/* $Id: tif_write.c,v 1.28 2009/11/07 19:18:27 drolon Exp $ */
2
2
 
3
3
/*
4
4
 * Copyright (c) 1988-1997 Sam Leffler
227
227
 
228
228
        if( td->td_stripbytecount[strip] > 0 )
229
229
        {
230
 
            /* if we are writing over existing tiles, zero length. */
231
 
            td->td_stripbytecount[strip] = 0;
232
 
 
233
 
            /* this forces TIFFAppendToStrip() to do a seek */
 
230
            /* Force TIFFAppendToStrip() to consider placing data at end
 
231
               of file. */
234
232
            tif->tif_curoff = 0;
235
233
        }
236
234
        
363
361
 
364
362
        if( td->td_stripbytecount[tile] > 0 )
365
363
        {
366
 
            /* if we are writing over existing tiles, zero length. */
367
 
            td->td_stripbytecount[tile] = 0;
368
 
 
369
 
            /* this forces TIFFAppendToStrip() to do a seek */
 
364
            /* Force TIFFAppendToStrip() to consider placing data at end
 
365
               of file. */
370
366
            tif->tif_curoff = 0;
371
367
        }
372
368
        
521
517
                 * because this field is used in other parts of library even
522
518
                 * in the single band case.
523
519
                 */
524
 
                tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG;
 
520
                if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG))
 
521
                    tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG;
525
522
        } else {
526
523
                if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) {
527
524
                        TIFFErrorExt(tif->tif_clientdata, module,
625
622
static int
626
623
TIFFAppendToStrip(TIFF* tif, tstrip_t strip, tidata_t data, tsize_t cc)
627
624
{
628
 
    TIFFDirectory *td = &tif->tif_dir;
629
 
    static const char module[] = "TIFFAppendToStrip";
630
 
 
631
 
    if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) {
632
 
        /*
633
 
         * No current offset, set the current strip.
634
 
         */
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;
 
627
 
 
628
        if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) {
 
629
            assert(td->td_nstrips > 0);
 
630
 
 
631
            if( td->td_stripbytecount[strip] != 0 
 
632
                && td->td_stripoffset[strip] != 0 
 
633
                && td->td_stripbytecount[strip] >= cc )
 
634
            {
 
635
                /* 
 
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.
 
641
                 */
 
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);
 
646
                    return (0);
 
647
                }
 
648
            }
 
649
            else
 
650
            {
 
651
                /* 
 
652
                 * Seek to end of file, and set that as our location to 
 
653
                 * write this strip.
 
654
                 */
 
655
                td->td_stripoffset[strip] = TIFFSeekFile(tif, 0, SEEK_END);
 
656
            }
 
657
 
 
658
            tif->tif_curoff = td->td_stripoffset[strip];
 
659
 
637
660
            /*
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.
643
662
             */
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,
650
 
                                     SEEK_END);
651
 
                    td->td_stripbytecountsorted = 0;
652
 
                }
653
 
            } else {
654
 
                tstrip_t i;
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] =
661
 
                            TIFFSeekFile(tif,
662
 
                                         (toff_t)0,
663
 
                                         SEEK_END);
664
 
                    }
665
 
                }
666
 
            }
667
 
 
668
 
            if (!SeekOK(tif, td->td_stripoffset[strip])) {
669
 
                TIFFErrorExt(tif->tif_clientdata, module,
670
 
                             "%s: Seek error at scanline %lu",
671
 
                             tif->tif_name,
672
 
                             (unsigned long)tif->tif_row);
673
 
                return (0);
674
 
            }
675
 
        } else
676
 
            td->td_stripoffset[strip] =
677
 
                TIFFSeekFile(tif, (toff_t) 0, SEEK_END);
678
 
        tif->tif_curoff = td->td_stripoffset[strip];
679
 
    }
680
 
 
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);
684
 
        return (0);
685
 
    }
686
 
    tif->tif_curoff += cc;
687
 
    td->td_stripbytecount[strip] += cc;
688
 
    return (1);
 
663
            td->td_stripbytecount[strip] = 0;
 
664
        }
 
665
 
 
666
        if (!WriteOK(tif, data, cc)) {
 
667
                TIFFErrorExt(tif->tif_clientdata, module, "Write error at scanline %lu",
 
668
                    (unsigned long) tif->tif_row);
 
669
                    return (0);
 
670
        }
 
671
        tif->tif_curoff =  tif->tif_curoff+cc;
 
672
        td->td_stripbytecount[strip] += cc;
 
673
        return (1);
689
674
}
690
675
 
691
676
/*