当前位置: 首页>>代码示例>>C++>>正文


C++ TIFFSeekFile函数代码示例

本文整理汇总了C++中TIFFSeekFile函数的典型用法代码示例。如果您正苦于以下问题:C++ TIFFSeekFile函数的具体用法?C++ TIFFSeekFile怎么用?C++ TIFFSeekFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TIFFSeekFile函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TIFFClientOpen


//.........这里部分代码省略.........
    /*
     * Read in TIFF header.
     */
    if (tif->tif_mode & O_TRUNC ||
        !ReadOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
        if (tif->tif_mode == O_RDONLY) {
            TIFFErrorExt(tif->tif_clientdata, name,
                     "Cannot read TIFF header");
            goto bad;
        }
        /*
         * Setup header and write.
         */
#ifdef WORDS_BIGENDIAN
        tif->tif_header.tiff_magic = tif->tif_flags & TIFF_SWAB
            ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN;
#else
        tif->tif_header.tiff_magic = tif->tif_flags & TIFF_SWAB
            ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN;
#endif
        tif->tif_header.tiff_version = TIFF_VERSION;
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabShort(&tif->tif_header.tiff_version);
        tif->tif_header.tiff_diroff = 0;	/* filled in later */


                /*
                 * The doc for "fopen" for some STD_C_LIBs says that if you 
                 * open a file for modify ("+"), then you must fseek (or 
                 * fflush?) between any freads and fwrites.  This is not
                 * necessary on most systems, but has been shown to be needed
                 * on Solaris. 
                 */
                TIFFSeekFile( tif, 0, SEEK_SET );
               
        if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
            TIFFErrorExt(tif->tif_clientdata, name,
                     "Error writing TIFF header");
            goto bad;
        }
        /*
         * Setup the byte order handling.
         */
        TIFFInitOrder(tif, tif->tif_header.tiff_magic);
        /*
         * Setup default directory.
         */
        if (!TIFFDefaultDirectory(tif))
            goto bad;
        tif->tif_diroff = 0;
        tif->tif_dirlist = NULL;
        tif->tif_dirlistsize = 0;
        tif->tif_dirnumber = 0;
        return (tif);
    }
    /*
     * Setup the byte order handling.
     */
    if (tif->tif_header.tiff_magic != TIFF_BIGENDIAN &&
        tif->tif_header.tiff_magic != TIFF_LITTLEENDIAN
#if MDI_SUPPORT
        &&
#if HOST_BIGENDIAN
        tif->tif_header.tiff_magic != MDI_BIGENDIAN
#else
        tif->tif_header.tiff_magic != MDI_LITTLEENDIAN
开发者ID:BlueFireworks,项目名称:rtems-graphics-toolkit,代码行数:67,代码来源:tif_open.c

示例2: TIFFAppendToStrip

/*
 * Append the data to the specified strip.
 */
static int
TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc)
{
    static const char module[] = "TIFFAppendToStrip";
    TIFFDirectory *td = &tif->tif_dir;
    uint64 m;
        int64 old_byte_count = -1;

    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] >= (uint64) cc )
            {
                /* 
                 * There is already tile data on disk, and the new tile
                 * data we have 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_flags |= TIFF_DIRTYSTRIP;
            }

            tif->tif_curoff = td->td_stripoffset[strip];

            /*
             * We are starting a fresh strip/tile, so set the size to zero.
             */
            old_byte_count = td->td_stripbytecount[strip];
            td->td_stripbytecount[strip] = 0;
    }

    m = tif->tif_curoff+cc;
    if (!(tif->tif_flags&TIFF_BIGTIFF))
        m = (uint32)m;
    if ((m<tif->tif_curoff)||(m<(uint64)cc))
    {
        TIFFErrorExt(tif->tif_clientdata, module, "Maximum TIFF file size exceeded");
        return (0);
    }
    if (!WriteOK(tif, data, cc)) {
        TIFFErrorExt(tif->tif_clientdata, module, "Write error at scanline %lu",
            (unsigned long) tif->tif_row);
            return (0);
    }
    tif->tif_curoff = m;
    td->td_stripbytecount[strip] += cc;

        if( (int64) td->td_stripbytecount[strip] != old_byte_count )
            tif->tif_flags |= TIFF_DIRTYSTRIP;
            
    return (1);
}
开发者ID:hoangduit,项目名称:reactos,代码行数:72,代码来源:tif_write.c

示例3: TIFFLinkDirectory

/*
 * Link the current directory into the
 * directory chain for the file.
 */
static int
TIFFLinkDirectory(TIFF* tif)
{
    static const char module[] = "TIFFLinkDirectory";
    uint32 nextdir;
    uint32 diroff;

    tif->tif_diroff = (TIFFSeekFile(tif, (toff_t) 0, SEEK_END)+1) &~ 1;
    diroff = (uint32) tif->tif_diroff;
    if (tif->tif_flags & TIFF_SWAB)
        TIFFSwabLong(&diroff);
#if SUBIFD_SUPPORT
    if (tif->tif_flags & TIFF_INSUBIFD) {
        (void) TIFFSeekFile(tif, tif->tif_subifdoff, SEEK_SET);
        if (!WriteOK(tif, &diroff, sizeof (diroff))) {
            TIFFError(module,
                "%s: Error writing SubIFD directory link",
                tif->tif_name);
            return (0);
        }
        /*
         * Advance to the next SubIFD or, if this is
         * the last one configured, revert back to the
         * normal directory linkage.
         */
        if (--tif->tif_nsubifd)
            tif->tif_subifdoff += sizeof (diroff);
        else
            tif->tif_flags &= ~TIFF_INSUBIFD;
        return (1);
    }
#endif
    if (tif->tif_header.tiff_diroff == 0) {
        /*
         * First directory, overwrite offset in header.
         */
        tif->tif_header.tiff_diroff = (uint32) tif->tif_diroff;
#define	HDROFF(f)	((toff_t) &(((TIFFHeader*) 0)->f))
        (void) TIFFSeekFile(tif, HDROFF(tiff_diroff), SEEK_SET);
        if (!WriteOK(tif, &diroff, sizeof (diroff))) {
            TIFFError(tif->tif_name, "Error writing TIFF header");
            return (0);
        }
        return (1);
    }
    /*
     * Not the first directory, search to the last and append.
     */
    nextdir = tif->tif_header.tiff_diroff;
    do {
        uint16 dircount;

        if (!SeekOK(tif, nextdir) ||
            !ReadOK(tif, &dircount, sizeof (dircount))) {
            TIFFError(module, "Error fetching directory count");
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabShort(&dircount);
        (void) TIFFSeekFile(tif,
            dircount * sizeof (TIFFDirEntry), SEEK_CUR);
        if (!ReadOK(tif, &nextdir, sizeof (nextdir))) {
            TIFFError(module, "Error fetching directory link");
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabLong(&nextdir);
    } while (nextdir != 0);
    (void) TIFFSeekFile(tif, -(toff_t) sizeof (nextdir), SEEK_CUR);
    if (!WriteOK(tif, &diroff, sizeof (diroff))) {
        TIFFError(module, "Error writing directory link");
        return (0);
    }
    return (1);
}
开发者ID:BoxianLai,项目名称:moxiedev,代码行数:79,代码来源:tif_dirwrite.c

示例4: TIFFAppendToStrip

/*
 * Append the data to the specified strip.
 */
static int
TIFFAppendToStrip(TIFF* tif, tstrip_t strip, tidata_t data, tsize_t cc) {
    TIFFDirectory* td = &tif->tif_dir;
    static const char module[] = "TIFFAppendToStrip";

    if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 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])) {
                TIFFError(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)) {
        TIFFError(module, "%s: Write error at scanline %lu",
                  tif->tif_name, (unsigned long) tif->tif_row);
        return (0);
    }
    tif->tif_curoff += cc;
    td->td_stripbytecount[strip] += cc;
    return (1);
}
开发者ID:353,项目名称:viewercv,代码行数:66,代码来源:tif_write.c

示例5: _TIFFWriteCustomDirectory

static int
_TIFFWriteCustomDirectory(TIFF* tif, toff_t *pdiroff)
{
    uint16 dircount;
    uint32 nfields;
    tsize_t dirsize;
    char* data;
    TIFFDirEntry* dir;
    TIFFDirectory* td;
    unsigned long b, fields[FIELD_SETLONGS];
    int fi, nfi;

    if (tif->tif_mode == O_RDONLY)
        return (1);

    td = &tif->tif_dir;
    /*
     * Size the directory so that we can calculate
     * offsets for the data items that aren't kept
     * in-place in each field.
     */
    nfields = 0;
    for (b = 0; b <= FIELD_LAST; b++)
        if (TIFFFieldSet(tif, b) && b != FIELD_CUSTOM)
            nfields += (b < FIELD_SUBFILETYPE ? 2 : 1);
    nfields += td->td_customValueCount;
    dirsize = nfields * sizeof (TIFFDirEntry);
    data = (char*) _TIFFmalloc(dirsize);
    if (data == NULL) {
        TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
                 "Cannot write directory, out of space");
        return (0);
    }
    /*
     * Put the directory  at the end of the file.
     */
    tif->tif_diroff = (TIFFSeekFile(tif, (toff_t) 0, SEEK_END)+1) &~ 1;
    tif->tif_dataoff = (toff_t)(
        tif->tif_diroff + sizeof (uint16) + dirsize + sizeof (toff_t));
    if (tif->tif_dataoff & 1)
        tif->tif_dataoff++;
    (void) TIFFSeekFile(tif, tif->tif_dataoff, SEEK_SET);
    dir = (TIFFDirEntry*) data;
    /*
     * Setup external form of directory
     * entries and write data items.
     */
    _TIFFmemcpy(fields, td->td_fieldsset, sizeof (fields));

    for (fi = 0, nfi = tif->tif_nfields; nfi > 0; nfi--, fi++) {
        const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi];

        /*
         * For custom fields, we test to see if the custom field
         * is set or not.  For normal fields, we just use the
         * FieldSet test.
        */
        if( fip->field_bit == FIELD_CUSTOM )
        {
            int ci, is_set = FALSE;

            for( ci = 0; ci < td->td_customValueCount; ci++ )
                is_set |= (td->td_customValues[ci].info == fip);

            if( !is_set )
                continue;
        }
        else if (!FieldSet(fields, fip->field_bit))
            continue;
                
        if( fip->field_bit != FIELD_CUSTOM )
            ResetFieldBit(fields, fip->field_bit);
    }

    /*
     * Write directory.
     */
    dircount = (uint16) nfields;
    *pdiroff = (uint32) tif->tif_nextdiroff;
    if (tif->tif_flags & TIFF_SWAB) {
        /*
         * The file's byte order is opposite to the
         * native machine architecture.  We overwrite
         * the directory information with impunity
         * because it'll be released below after we
         * write it to the file.  Note that all the
         * other tag construction routines assume that
         * we do this byte-swapping; i.e. they only
         * byte-swap indirect data.
         */
        for (dir = (TIFFDirEntry*) data; dircount; dir++, dircount--) {
            TIFFSwabArrayOfShort(&dir->tdir_tag, 2);
            TIFFSwabArrayOfLong(&dir->tdir_count, 2);
        }
        dircount = (uint16) nfields;
        TIFFSwabShort(&dircount);
        TIFFSwabLong(pdiroff);
    }
    (void) TIFFSeekFile(tif, tif->tif_diroff, SEEK_SET);
    if (!WriteOK(tif, &dircount, sizeof (dircount))) {
//.........这里部分代码省略.........
开发者ID:louisfeng,项目名称:FreeImage,代码行数:101,代码来源:tif_dirwrite.c

示例6: TIFFWriteDirectory

/*
 * Write the contents of the current directory
 * to the specified file.  This routine doesn't
 * handle overwriting a directory with auxiliary
 * storage that's been changed.
 */
int
TIFFWriteDirectory(TIFF* tif)
{
    uint16 dircount;
    uint32 diroff;
    ttag_t tag;
    uint32 nfields;
    tsize_t dirsize;
    char* data;
    TIFFDirEntry* dir;
    TIFFDirectory* td;
    u_long b, fields[FIELD_SETLONGS];
    int fi, nfi;

    if (tif->tif_mode == O_RDONLY)
        return (1);
    /*
     * Clear write state so that subsequent images with
     * different characteristics get the right buffers
     * setup for them.
     */
    if (tif->tif_flags & TIFF_POSTENCODE) {
        tif->tif_flags &= ~TIFF_POSTENCODE;
        if (!(*tif->tif_postencode)(tif)) {
            TIFFError(tif->tif_name,
                "Error post-encoding before directory write");
            return (0);
        }
    }
    (*tif->tif_close)(tif);			/* shutdown encoder */
    /*
     * Flush any data that might have been written
     * by the compression close+cleanup routines.
     */
    if (tif->tif_rawcc > 0 && !TIFFFlushData1(tif)) {
        TIFFError(tif->tif_name,
            "Error flushing data before directory write");
        return (0);
    }
    if ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {
        _TIFFfree(tif->tif_rawdata);
        tif->tif_rawdata = NULL;
        tif->tif_rawcc = 0;
    }
    tif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP);

    td = &tif->tif_dir;
    /*
     * Size the directory so that we can calculate
     * offsets for the data items that aren't kept
     * in-place in each field.
     */
    nfields = 0;
    for (b = 0; b <= FIELD_LAST; b++)
        if (TIFFFieldSet(tif, b))
            nfields += (b < FIELD_SUBFILETYPE ? 2 : 1);
    dirsize = nfields * sizeof (TIFFDirEntry);
    data = (char*) _TIFFmalloc(dirsize);
    if (data == NULL) {
        TIFFError(tif->tif_name,
            "Cannot write directory, out of space");
        return (0);
    }
    /*
     * Directory hasn't been placed yet, put
     * it at the end of the file and link it
     * into the existing directory structure.
     */
    if (tif->tif_diroff == 0 && !TIFFLinkDirectory(tif))
        goto bad;
    tif->tif_dataoff = (toff_t)(
        tif->tif_diroff + sizeof (uint16) + dirsize + sizeof (toff_t));
    if (tif->tif_dataoff & 1)
        tif->tif_dataoff++;
    (void) TIFFSeekFile(tif, tif->tif_dataoff, SEEK_SET);
    tif->tif_curdir++;
    dir = (TIFFDirEntry*) data;
    /*
     * Setup external form of directory
     * entries and write data items.
     */
    _TIFFmemcpy(fields, td->td_fieldsset, sizeof (fields));
    /*
     * Write out ExtraSamples tag only if
     * extra samples are present in the data.
     */
    if (FieldSet(fields, FIELD_EXTRASAMPLES) && !td->td_extrasamples) {
        ResetFieldBit(fields, FIELD_EXTRASAMPLES);
        nfields--;
        dirsize -= sizeof (TIFFDirEntry);
    }								/*XXX*/
    for (fi = 0, nfi = tif->tif_nfields; nfi > 0; nfi--, fi++) {
        const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi];
        if (!FieldSet(fields, fip->field_bit))
//.........这里部分代码省略.........
开发者ID:BoxianLai,项目名称:moxiedev,代码行数:101,代码来源:tif_dirwrite.c

示例7: TIFFRewriteDirectory

int 
TIFFRewriteDirectory( TIFF *tif )
{
    static const char module[] = "TIFFRewriteDirectory";

    /* We don't need to do anything special if it hasn't been written. */
    if( tif->tif_diroff == 0 )
        return TIFFWriteDirectory( tif );

    /*
    ** Find and zero the pointer to this directory, so that TIFFLinkDirectory
    ** will cause it to be added after this directories current pre-link.
    */
    
    /* Is it the first directory in the file? */
    if (tif->tif_header.tiff_diroff == tif->tif_diroff) 
    {
        tif->tif_header.tiff_diroff = 0;
        tif->tif_diroff = 0;

        TIFFSeekFile(tif, (toff_t)(TIFF_MAGIC_SIZE+TIFF_VERSION_SIZE),
             SEEK_SET);
        if (!WriteOK(tif, &(tif->tif_header.tiff_diroff), 
                     sizeof (tif->tif_diroff))) 
        {
            TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
                     "Error updating TIFF header");
            return (0);
        }
    }
    else
    {
        toff_t  nextdir, off;

    nextdir = tif->tif_header.tiff_diroff;
    do {
        uint16 dircount;

        if (!SeekOK(tif, nextdir) ||
            !ReadOK(tif, &dircount, sizeof (dircount))) {
            TIFFErrorExt(tif->tif_clientdata, module,
                     "Error fetching directory count");
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabShort(&dircount);
        (void) TIFFSeekFile(tif,
            dircount * sizeof (TIFFDirEntry), SEEK_CUR);
        if (!ReadOK(tif, &nextdir, sizeof (nextdir))) {
            TIFFErrorExt(tif->tif_clientdata, module,
                     "Error fetching directory link");
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabLong(&nextdir);
    } while (nextdir != tif->tif_diroff && nextdir != 0);
        off = TIFFSeekFile(tif, 0, SEEK_CUR); /* get current offset */
        (void) TIFFSeekFile(tif, off - (toff_t)sizeof(nextdir), SEEK_SET);
        tif->tif_diroff = 0;
    if (!WriteOK(tif, &(tif->tif_diroff), sizeof (nextdir))) {
        TIFFErrorExt(tif->tif_clientdata, module,
                 "Error writing directory link");
        return (0);
    }
    }

    /*
    ** Now use TIFFWriteDirectory() normally.
    */

    return TIFFWriteDirectory( tif );
}
开发者ID:louisfeng,项目名称:FreeImage,代码行数:72,代码来源:tif_dirwrite.c

示例8: TIFFLinkDirectory

/*
 * Link the current directory into the directory chain for the file.
 */
static int
TIFFLinkDirectory(TIFF* tif)
{
    static const char module[] = "TIFFLinkDirectory";
    toff_t nextdir;
    toff_t diroff, off;

    tif->tif_diroff = (TIFFSeekFile(tif, (toff_t) 0, SEEK_END)+1) &~ 1;
    diroff = tif->tif_diroff;
    if (tif->tif_flags & TIFF_SWAB)
        TIFFSwabLong(&diroff);

    /*
     * Handle SubIFDs
     */
        if (tif->tif_flags & TIFF_INSUBIFD) {
        (void) TIFFSeekFile(tif, tif->tif_subifdoff, SEEK_SET);
        if (!WriteOK(tif, &diroff, sizeof (diroff))) {
            TIFFErrorExt(tif->tif_clientdata, module,
                     "%s: Error writing SubIFD directory link",
                     tif->tif_name);
            return (0);
        }
        /*
         * Advance to the next SubIFD or, if this is
         * the last one configured, revert back to the
         * normal directory linkage.
         */
        if (--tif->tif_nsubifd)
            tif->tif_subifdoff += sizeof (diroff);
        else
            tif->tif_flags &= ~TIFF_INSUBIFD;
        return (1);
    }

    if (tif->tif_header.tiff_diroff == 0) {
        /*
         * First directory, overwrite offset in header.
         */
        tif->tif_header.tiff_diroff = tif->tif_diroff;
        (void) TIFFSeekFile(tif,
                    (toff_t)(TIFF_MAGIC_SIZE+TIFF_VERSION_SIZE),
                                    SEEK_SET);
        if (!WriteOK(tif, &diroff, sizeof (diroff))) {
            TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
                     "Error writing TIFF header");
            return (0);
        }
        return (1);
    }
    /*
     * Not the first directory, search to the last and append.
     */
    nextdir = tif->tif_header.tiff_diroff;
    do {
        uint16 dircount;

        if (!SeekOK(tif, nextdir) ||
            !ReadOK(tif, &dircount, sizeof (dircount))) {
            TIFFErrorExt(tif->tif_clientdata, module,
                     "Error fetching directory count");
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabShort(&dircount);
        (void) TIFFSeekFile(tif,
            dircount * sizeof (TIFFDirEntry), SEEK_CUR);
        if (!ReadOK(tif, &nextdir, sizeof (nextdir))) {
            TIFFErrorExt(tif->tif_clientdata, module,
                     "Error fetching directory link");
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabLong(&nextdir);
    } while (nextdir != 0);
        off = TIFFSeekFile(tif, 0, SEEK_CUR); /* get current offset */
        (void) TIFFSeekFile(tif, off - (toff_t)sizeof(nextdir), SEEK_SET);
    if (!WriteOK(tif, &diroff, sizeof (diroff))) {
        TIFFErrorExt(tif->tif_clientdata, module,
                 "Error writing directory link");
        return (0);
    }
    return (1);
}
开发者ID:louisfeng,项目名称:FreeImage,代码行数:87,代码来源:tif_dirwrite.c

示例9: TIFFAppendToStrip

/*
 * Append the data to the specified strip.
 */
static int
TIFFAppendToStrip(TIFF* tif, tstrip_t strip, tidata_t data, tsize_t cc)
{
    TIFFDirectory *td = &tif->tif_dir;
    static const char module[] = "TIFFAppendToStrip";

    if (_TIFFGetOffset(tif, strip) == 0 || tif->tif_curoff == 0) {
        /*
         * No current offset, set the current strip.
         */
        assert(td->td_nstrips > 0);
        if (_TIFFGetOffset(tif, 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 || 
                    _TIFFGetOffset(tif, strip + 1) < _TIFFGetOffset(tif, strip) + cc) {
                    _TIFFSetOffset(tif, strip, TIFFSeekFile(tif, (toff_t)0, SEEK_END));
                }
            } else {
                tstrip_t i;
                for (i = 0; i < td->td_nstrips; i++) {
                    if (_TIFFGetOffset(tif, i) > _TIFFGetOffset(tif, strip) && 
                        _TIFFGetOffset(tif, i) < _TIFFGetOffset(tif, strip) + cc) {
                        _TIFFSetOffset(tif, strip, TIFFSeekFile(tif, (toff_t)0, SEEK_END));
                        break;
                    }
                }
            }
            /* check if block will overlap offsets or bytes counts arrays */
            if ((td->td_stripoffsoff &&
                _TIFFGetOffset(tif, strip) < td->td_stripoffsoff &&
                _TIFFGetOffset(tif, strip) + cc > td->td_stripoffsoff) ||
                (td->td_stripbcsoff &&
                _TIFFGetOffset(tif, strip) < td->td_stripbcsoff &&
                _TIFFGetOffset(tif, strip) + cc > td->td_stripbcsoff))
                _TIFFSetOffset(tif, strip, TIFFSeekFile(tif, (toff_t)0, SEEK_END));

            if (!SeekOK(tif, _TIFFGetOffset(tif, strip))) {
                TIFFErrorExt(tif->tif_clientdata, module,
                      "%s: Seek error at scanline %lu",
                      tif->tif_name,
                      (unsigned long)tif->tif_row);
                return (0);
            }
        } else
            _TIFFSetOffset(tif, strip,
                TIFFSeekFile(tif, (toff_t) 0, SEEK_END));
        tif->tif_curoff = _TIFFGetOffset(tif, strip);
    }

    if (!WriteOK(tif, data, cc)) {
        TIFFErrorExt(tif->tif_clientdata, module, 
            "%s: Write error at scanline %lu (%d)",
            tif->tif_name, (unsigned long) tif->tif_row, TIFFGetErrno(tif));
        return (0);
    }
    tif->tif_curoff += cc;
    _TIFFSetByteCount(tif, strip, _TIFFGetByteCount(tif, strip) + cc);
    return (1);
}
开发者ID:GaryShearer,项目名称:BasicOCR,代码行数:69,代码来源:tif_write.c

示例10: _TIFFWriteDirectory


//.........这里部分代码省略.........
     * Size the directory so that we can calculate
     * offsets for the data items that aren't kept
     * in-place in each field.
     */
    nfields = 0;
    for (b = 0; b <= FIELD_LAST; b++)
        if (TIFFFieldSet(tif, b) && b != FIELD_CUSTOM)
            nfields += (b < FIELD_SUBFILETYPE ? 2 : 1);
        nfields += td->td_customValueCount;
    dirsize = nfields * TDIREntryLen(tif);
    data = (char*) _TIFFmalloc(dirsize);
    if (data == NULL) {
        TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
            "Cannot write directory, out of space");
        goto bad2;
    }
    _TIFFmemset(data, 0, dirsize);
    /*
     * Setup external form of directory
     * entries and write data items.
     */
    _TIFFmemcpy(fields, td->td_fieldsset, sizeof (fields));
    /*
     * Write out ExtraSamples tag only if
     * extra samples are present in the data.
     */
    if (FieldSet(fields, FIELD_EXTRASAMPLES) && !td->td_extrasamples) {
        ResetFieldBit(fields, FIELD_EXTRASAMPLES);
        nfields--;
        dirsize -= TDIREntryLen(tif);
    }								/*XXX*/

    tif->tif_dataoff = tif->tif_diroff + TIFFDirCntLen(tif) + dirsize + TIFFDirOffLen(tif);
    (void) TIFFSeekFile(tif, tif->tif_dataoff, SEEK_SET);
    dir = (TIFFDirEntry*) data;
    for (fi = 0, nfi = tif->tif_nfields; nfi > 0; nfi--, fi++) {
        const TIFFFieldInfo* fip = tif->tif_fieldinfo[fi];

                /*
                ** For custom fields, we test to see if the custom field
                ** is set or not.  For normal fields, we just use the
                ** FieldSet test. 
                */
                if( fip->field_bit == FIELD_CUSTOM )
                {
                    int ci, is_set = FALSE;

                    for( ci = 0; ci < td->td_customValueCount; ci++ )
                        is_set |= (td->td_customValues[ci].info == fip);

                    if( !is_set )
                        continue;
                }
        else if (!FieldSet(fields, fip->field_bit))
                    continue;

                /*
                ** Handle other fields.
                */
        switch (fip->field_bit)
                {
        case FIELD_STRIPOFFSETS:
            /*
             * We use one field bit for both strip and tile
             * offsets, and so must be careful in selecting
             * the appropriate field descriptor (so that tags
开发者ID:rajvikram,项目名称:weaver,代码行数:67,代码来源:tif_dirwrite.c

示例11: TIFFMakeBigTIFF


//.........这里部分代码省略.........
                "Error reading TIFF directory (%d)", TIFFGetErrno(tif));
            goto error;
        }
        diroffB = tif->tif_dataoff;
        tif->tif_dataoff += sizeof(dircountB) + dirsizeB + sizeof(toff_t);

        for (dirindex = 0; dirindex < dircount; dirindex++) {
            dir = (TIFFDirEntry*) (data + dirindex * TIFFDirEntryLenS);
            dirB = (TIFFDirEntry*) (dataB + dirindex * TIFFDirEntryLenB);
            if (tif->tif_flags & TIFF_SWAB) {
                TIFFSwabShort(&dir->s.tdir_tag);
                TIFFSwabShort(&dir->s.tdir_type);
                TIFFSwabLong(&dir->s.tdir_count);
                TIFFSwabLong(&dir->s.tdir_offset);
            }
            dirB->b.tdir_tag = dir->s.tdir_tag;
            dirB->b.tdir_type = dir->s.tdir_type;
            dirB->b.tdir_count = dir->s.tdir_count;
            dirB->b.tdir_offset = 0;
            /*
             * If data are in directory entry itself, copy data, else (data are pointed
             * to by directory entry) copy pointer.  This is complicated by the fact that
             * the old entry had 32-bits of space, and the new has 64-bits, so may have
             * to read data pointed at by the old entry directly into the new entry.
             */
            switch (dir->s.tdir_type) {
            case TIFF_UNDEFINED:
            case TIFF_BYTE:
            case TIFF_SBYTE:
            case TIFF_ASCII:
                if (dir->s.tdir_count <= sizeof(dir->s.tdir_offset))
                    _TIFFmemcpy(&dirB->b.tdir_offset, &dir->s.tdir_offset, dir->s.tdir_count);
                else if (dir->s.tdir_count <= sizeof(dirB->b.tdir_count)) {
                    TIFFSeekFile(tif, dir->s.tdir_offset, SEEK_SET);
                    TIFFReadFile(tif, &dirB->b.tdir_offset, dir->s.tdir_count);
                } else
                    dirB->b.tdir_offset = dir->s.tdir_offset;
                break;
            case TIFF_SHORT:
            case TIFF_SSHORT:
                if (dir->s.tdir_count <= sizeof(dir->s.tdir_offset) / sizeof(uint16))
                    _TIFFmemcpy(&dirB->b.tdir_offset, &dir->s.tdir_offset, dir->s.tdir_count * sizeof(uint16));
                else if (dir->s.tdir_count <= sizeof(dirB->b.tdir_count) / sizeof(uint16)) {
                    TIFFSeekFile(tif, dir->s.tdir_offset, SEEK_SET);
                    TIFFReadFile(tif, &dirB->b.tdir_offset, dir->s.tdir_count * sizeof(uint16));
                    if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabArrayOfShort((uint16*) &dirB->b.tdir_offset, dir->s.tdir_count);
                } else
                    dirB->b.tdir_offset = dir->s.tdir_offset;
                break;
            case TIFF_LONG:
            case TIFF_FLOAT:
            case TIFF_IFD:
                if (dir->s.tdir_count <= sizeof(dir->s.tdir_offset) / sizeof(uint32))
                    _TIFFmemcpy(&dirB->b.tdir_offset, &dir->s.tdir_offset, dir->s.tdir_count * sizeof(uint32));
                else if (dir->s.tdir_count <= sizeof(dirB->b.tdir_count) / sizeof(uint32)) {
                    TIFFSeekFile(tif, dir->s.tdir_offset, SEEK_SET);
                    TIFFReadFile(tif, &dirB->b.tdir_offset, dir->s.tdir_count * sizeof(uint32));
                    if (tif->tif_flags & TIFF_SWAB)
                        TIFFSwabArrayOfLong((uint32*) &dirB->b.tdir_offset, dir->s.tdir_count);
                } else
                    dirB->b.tdir_offset = dir->s.tdir_offset;
                break;
            case TIFF_RATIONAL:
            case TIFF_SRATIONAL:
                if (dir->s.tdir_count * 2 <= sizeof(dirB->b.tdir_offset) / sizeof(uint32)) {
开发者ID:rajvikram,项目名称:weaver,代码行数:67,代码来源:tif_dirwrite.c

示例12: TIFFLinkDirectory

/*
 * Link the current directory into the
 * directory chain for the file.
 */
static int
TIFFLinkDirectory(TIFF* tif)
{
    static const char module[] = "TIFFLinkDirectory";
    toff_t currdir, nextdir;
    toff_t diroff, nextdiroff;	/* 32-bit or 64-bit dir offsets */

    /*
     * New directory will go at end of file; if file not BigTIFF and
     * size is beyond 2^32, convert to BigTIFF now.
     */
    tif->tif_diroff = ((TIFFSeekFile(tif, 0, SEEK_END) + 1) & ~(toff_t) 1);
    if (!isBigTIFF(tif) && isBigOff(tif->tif_diroff)) {
        if (!TIFFMakeBigTIFF(tif))
            return (0);
        tif->tif_diroff = ((TIFFSeekFile(tif, 0, SEEK_END) + 1) & ~(toff_t) 1);
    }

    TIFFSetDirOff(tif,diroff,tif->tif_diroff);
    if (tif->tif_flags & TIFF_SWAB)
        TIFFSwabDirOff(tif,&diroff);

    /*
     * Handle SubIFDs
     */
        if (tif->tif_flags & TIFF_INSUBIFD) {
        (void) TIFFSeekFile(tif, tif->tif_subifdoff, SEEK_SET);
        if (!WriteOK(tif, &diroff, TIFFDirOffLen(tif))) {
            TIFFErrorExt(tif->tif_clientdata, module,
                "%s: Error writing SubIFD directory link (%d)",
                tif->tif_name, TIFFGetErrno(tif));
            return (0);
        }
        /*
         * Advance to the next SubIFD or, if this is
         * the last one configured, revert back to the
         * normal directory linkage.
         */
        if (--tif->tif_nsubifd)
            tif->tif_subifdoff += TIFFDirOffLen(tif);
        else
            tif->tif_flags &= ~TIFF_INSUBIFD;
        return (1);
    }

    /*
     * First directory, overwrite offset in header.
     */
    nextdir = TIFFGetHdrDirOff(tif,tif->tif_header);
    if (nextdir == 0) {
        TIFFSetHdrDirOff(tif,tif->tif_header, tif->tif_diroff);
        if (!SeekOK(tif, 0) ||
            !WriteOK(tif, &tif->tif_header, sizeof(TIFFHeader)) ) {
            TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 
                "Error writing TIFF header (%d)", TIFFGetErrno(tif));
            return (0);
        }
        return (1);
    }
    /*
     * Not the first directory, search to the last and append.
     */
    do {
        uint64 dircount;	/* 16-bit or 64-bit directory count */

        if (!SeekOK(tif, nextdir) ||
            !ReadOK(tif, &dircount, TIFFDirCntLen(tif))) {
            TIFFErrorExt(tif->tif_clientdata, module, 
                "Error fetching directory count (%d)", TIFFGetErrno(tif));
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabDirCnt(tif,&dircount);
        currdir = nextdir + TIFFDirCntLen(tif) + TIFFGetDirCnt(tif,dircount) * TDIREntryLen(tif);
        TIFFSeekFile(tif, currdir, SEEK_SET);
        if (!ReadOK(tif, &nextdiroff, TIFFDirOffLen(tif)) ) {
            TIFFErrorExt(tif->tif_clientdata, module, 
                "Error fetching directory link (%d)", TIFFGetErrno(tif));
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabDirOff(tif,&nextdiroff);
        nextdir = TIFFGetDirOff(tif,nextdiroff);
    } while (nextdir != 0);

        TIFFSeekFile(tif, currdir, SEEK_SET);
    if (!WriteOK(tif, &diroff, TIFFDirOffLen(tif)) ) {
        TIFFErrorExt(tif->tif_clientdata, module, 
            "Error writing directory link (%d)", TIFFGetErrno(tif));
        return (0);
    }
    return (1);
}
开发者ID:rajvikram,项目名称:weaver,代码行数:97,代码来源:tif_dirwrite.c

示例13: TIFFRewriteDirectory

/*
 * Similar to TIFFWriteDirectory(), but if the directory has already
 * been written once, it is relocated to the end of the file, in case it
 * has changed in size.  Note that this will result in the loss of the 
 * previously used directory space. 
 */ 
int 
TIFFRewriteDirectory( TIFF *tif )
{
    static const char module[] = "TIFFRewriteDirectory";

    /* We don't need to do anything special if it hasn't been written. */
    if( tif->tif_diroff == 0 )
        return TIFFWriteDirectory( tif );

    /*
    ** Find and zero the pointer to this directory, so that TIFFLinkDirectory
    ** will cause it to be added after this directories current pre-link.
    */
    
    /* Is it the first directory in the file? */
    if (TIFFGetHdrDirOff(tif,tif->tif_header) == tif->tif_diroff) 
    {
        TIFFSetHdrDirOff(tif,tif->tif_header,0);
        tif->tif_diroff = 0;

        if (!SeekOK(tif, 0) ||
        !WriteOK(tif, &tif->tif_header, sizeof(TIFFHeader))) {
        TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 
        "Error updating TIFF header (%d)", TIFFGetErrno(tif));
            return (0);
        }
    }
    else
    {
        toff_t	nextdir, off;
    toff_t	nextdiroff;		/* 32-bit or 64-bit directory offset */

    nextdir = TIFFGetHdrDirOff(tif,tif->tif_header);
    do {
        uint16 dircount;

        if (!SeekOK(tif, nextdir) ||
            !ReadOK(tif, &dircount, sizeof (dircount))) {
            TIFFErrorExt(tif->tif_clientdata, module, 
                "Error fetching directory count (%d)", TIFFGetErrno(tif));
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabShort(&dircount);
        (void) TIFFSeekFile(tif, TIFFGetDirCnt(tif,dircount) * TDIREntryLen(tif), SEEK_CUR);
        if (!ReadOK(tif, &nextdiroff, TIFFDirOffLen(tif))) {
            TIFFErrorExt(tif->tif_clientdata, module, 
                "Error fetching directory link (%d)", TIFFGetErrno(tif));
            return (0);
        }
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabDirOff(tif,&nextdiroff);
        nextdir = TIFFGetDirOff(tif,nextdiroff);
    } while (nextdir != tif->tif_diroff && nextdir != 0);

        off = TIFFSeekFile(tif, 0, SEEK_CUR); /* get current offset */
        (void) TIFFSeekFile(tif, off - TIFFDirOffLen(tif), SEEK_SET);
        tif->tif_diroff = 0;
    if (!WriteOK(tif, &(tif->tif_diroff), TIFFDirOffLen(tif))) {
        TIFFErrorExt(tif->tif_clientdata, module, 
            "Error writing directory link (%d)", TIFFGetErrno(tif));
        return (0);
    }
    }

    /*
    ** Now use TIFFWriteDirectory() normally.
    */
    return TIFFWriteDirectory( tif );
}
开发者ID:rajvikram,项目名称:weaver,代码行数:76,代码来源:tif_dirwrite.c

示例14: TIFFClientOpen


//.........这里部分代码省略.........
                tif->tif_flags |= TIFF_STRIPCHOP;
            break;
        case 'c':
            if (m == O_RDONLY)
                tif->tif_flags &= ~TIFF_STRIPCHOP;
            break;
        }
    /*
     * Read in TIFF header.
     */
    tif->tif_flags &= ~TIFF_MAPPED;
    if (!ReadOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
        if (tif->tif_mode == O_RDONLY) {
            TIFFError(name, "Cannot read TIFF header");
            goto bad;
        }
        /*
         * Setup header and write.
         */
        tif->tif_header.tiff_magic = tif->tif_flags & TIFF_SWAB
            ? (bigendian ? TIFF_LITTLEENDIAN : TIFF_BIGENDIAN)
            : (bigendian ? TIFF_BIGENDIAN : TIFF_LITTLEENDIAN);
        tif->tif_header.tiff_version = TIFF_VERSION;
        if (tif->tif_flags & TIFF_SWAB)
            TIFFSwabShort(&tif->tif_header.tiff_version);
        tif->tif_header.tiff_diroff = 0;	/* filled in later */

                /*
                 * This seek shouldn't be necessary, but I have had some
                 * crazy problems with a failed fseek() on Solaris leaving
                 * the current file pointer out of whack when an fwrite()
                 * is done. 
                 */
                TIFFSeekFile( tif, 0, SEEK_SET );

        if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
            TIFFError(name, "Error writing TIFF header");
            goto bad;
        }
        /*
         * Setup the byte order handling.
         */
        TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
        /*
         * Setup default directory.
         */
        if (!TIFFDefaultDirectory(tif))
            goto bad;
        tif->tif_diroff = 0;
        return (tif);
    }
    /*
     * Setup the byte order handling.
     */
    if (tif->tif_header.tiff_magic != TIFF_BIGENDIAN &&
        tif->tif_header.tiff_magic != TIFF_LITTLEENDIAN) {
        TIFFError(name,  "Not a TIFF file, bad magic number %d (0x%x)",
            tif->tif_header.tiff_magic,
            tif->tif_header.tiff_magic);
        goto bad;
    }
    TIFFInitOrder(tif, tif->tif_header.tiff_magic, bigendian);
    /*
     * Swap header if required.
     */
    if (tif->tif_flags & TIFF_SWAB) {
开发者ID:gzwplato,项目名称:VersyPDF,代码行数:67,代码来源:tif_open.c


注:本文中的TIFFSeekFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。