LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Functions
Directory creation and navigation

Create, release, select, query, and unlink directories. More...

Collaboration diagram for Directory creation and navigation:

Functions

tdir_t TIFFCurrentDirectory (TIFF *tif)
 Read the cached index of the current directory.
 
tdir_t TIFFNumberOfDirectories (TIFF *tif)
 Count reachable main-chain directories from the cached file header.
 
uint64_t TIFFCurrentDirOffset (TIFF *tif)
 Read the cached file offset of the current directory.
 
void TIFFFreeDirectory (TIFF *tif)
 Release the current directory's owned values and codec state.
 
int TIFFCreateDirectory (TIFF *tif)
 Replace current values with a fresh in-memory image directory.
 
int TIFFCreateCustomDirectory (TIFF *tif, const TIFFFieldArray *infoarray)
 Replace current values with a fresh custom metadata directory.
 
int TIFFCreateEXIFDirectory (TIFF *tif)
 Create a fresh in-memory EXIF metadata directory.
 
int TIFFCreateGPSDirectory (TIFF *tif)
 Create a fresh in-memory EXIF GPS metadata directory.
 
int TIFFLastDirectory (TIFF *tif)
 Test whether the cached next-directory link is zero.
 
int TIFFSetDirectory (TIFF *tif, tdir_t dirn)
 Select and read an image directory by its main-chain index.
 
int TIFFSetSubDirectory (TIFF *tif, uint64_t diroff)
 Select and read an image directory at a file offset.
 
int TIFFUnlinkDirectory (TIFF *tif, tdir_t dirn)
 Remove an image directory from the on-file main chain.
 

Detailed Description

Create, release, select, query, and unlink directories.

See Directory creation and navigation for numbering, failure states, and side effects.

Function Documentation

◆ TIFFCreateCustomDirectory()

int TIFFCreateCustomDirectory ( TIFF *  tif,
const TIFFFieldArray *  infoarray 
)
extern

Replace current values with a fresh custom metadata directory.

Discards current directory values and codec state through TIFFFreeDirectory(), then installs defaults and the image schema through TIFFDefaultDirectory(). Invalidates borrowed values and replaceable descriptors. Does not save dirty values or write an IFD; use this only when discarding them is intended. No new TIFF handle is allocated. Setup may allocate and invoke the process-wide tag extender and codec setup, with diagnostics but no reliable status propagation. Subsequently replaces the image field table with the supplied custom schema; the extender does not extend the final custom table. A NULL infoarray is diagnosed and leaves the image schema from TIFFDefaultDirectory() in place; the remaining resets still occur. Clears current/next/data offsets, sets the index to (tdir_t)UINT_MAX, destroys directory maps, and forces the next indexed selection to start from the main-chain header. Descriptors/names remain borrowed and must outlive their use. The schema record itself is only read during setup. The new metadata must later be written with TIFFWriteCustomDirectory() and linked by the appropriate parent tag; creation does not link it.

Parameters
[in,out]tifNon-NULL live handle; caller must serialise access.
[in]infoarrayValid private schema with long-lived descriptors and names, or NULL (rejected as described above); TIFFFieldArray is opaque in the public header.
Returns
One when infoarray is NULL, otherwise zero, even after other reported setup failures; inspect diagnostics rather than interpreting zero as success.

Definition at line 2258 of file tif_dir.c.

References _TIFFCleanupIFDOffsetAndNumberMaps(), _TIFFSetupFields(), tiff::tif_curdir, tiff::tif_curoff, tiff::tif_diroff, tiff::tif_nextdiroff, tiff::tif_setdirectory_force_absolute, TIFF_NON_EXISTENT_DIR_NUMBER, TIFFDefaultDirectory(), TIFFErrorExtR(), TIFFFreeDirectory(), and TRUE.

Referenced by TIFFCreateEXIFDirectory(), and TIFFCreateGPSDirectory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIFFCreateDirectory()

int TIFFCreateDirectory ( TIFF *  tif)
extern

Replace current values with a fresh in-memory image directory.

Discards current directory values and codec state through TIFFFreeDirectory(), then installs defaults and the image schema through TIFFDefaultDirectory(). Invalidates borrowed values and replaceable descriptors. Does not save dirty values or write an IFD; use this only when discarding them is intended. No new TIFF handle is allocated. Setup may allocate and invoke the process-wide tag extender and codec setup, with diagnostics but no reliable status propagation. Clears current/next directory and image-data offsets and marks the directory unwritten. The cached directory index, directory maps, and other write state are not comprehensively reset; this is not equivalent to reopening a handle.

Parameters
[in,out]tifNon-NULL live handle; caller must serialise access.
Returns
Zero unconditionally, including when internal setup reports a failure; not a Boolean success indication.

Definition at line 2246 of file tif_dir.c.

References FALSE, TIFFDirectory::td_iswrittentofile, tiff::tif_curoff, tiff::tif_dir, tiff::tif_diroff, tiff::tif_nextdiroff, TIFFDefaultDirectory(), and TIFFFreeDirectory().

Referenced by TIFFWriteDirectorySec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIFFCreateEXIFDirectory()

int TIFFCreateEXIFDirectory ( TIFF *  tif)
extern

Create a fresh in-memory EXIF metadata directory.

Delegates to TIFFCreateCustomDirectory() with the built-in EXIF schema and all its discard, pointer-invalidation, index/map reset, callback, and failure rules. The caller needs no private schema definition. Does not persist or link the metadata directory; write/link it separately.

Parameters
[in,out]tifNon-NULL live handle; caller must serialise access.
Returns
Zero unconditionally; internal setup failures can report diagnostics without changing this return value.

Definition at line 2296 of file tif_dir.c.

References _TIFFGetExifFields(), exifFieldArray, and TIFFCreateCustomDirectory().

Here is the call graph for this function:

◆ TIFFCreateGPSDirectory()

int TIFFCreateGPSDirectory ( TIFF *  tif)
extern

Create a fresh in-memory EXIF GPS metadata directory.

Delegates to TIFFCreateCustomDirectory() with the built-in EXIF GPS schema and all its discard, pointer-invalidation, index/map reset, callback, and failure rules. The caller needs no private schema definition. Does not persist or link the metadata directory; write/link it separately.

Parameters
[in,out]tifNon-NULL live handle; caller must serialise access.
Returns
Zero unconditionally; internal setup failures can report diagnostics without changing this return value.

Definition at line 2306 of file tif_dir.c.

References _TIFFGetGpsFields(), gpsFieldArray, and TIFFCreateCustomDirectory().

Here is the call graph for this function:

◆ TIFFCurrentDirectory()

tdir_t TIFFCurrentDirectory ( TIFF *  tif)
extern

Read the cached index of the current directory.

Reads state without I/O, allocation, diagnostics, or ownership transfer. A main-chain read uses zero-based numbering; a newly entered unrecognised SubIFD chain starts at zero. After writing an image directory the index can describe the last written IFD while the in-memory directory is fresh. Creation of an ordinary directory preserves the old index. A failed read can leave an index without a fully valid directory. See Directory creation and navigation for these distinctions.

Parameters
[in]tifNon-NULL live handle; caller must serialise access.
Returns
Cached index, or (tdir_t)UINT_MAX for an absent/unknown index; not an independent validity test.

Definition at line 906 of file tif_open.c.

References tiff::tif_curdir.

◆ TIFFCurrentDirOffset()

uint64_t TIFFCurrentDirOffset ( TIFF *  tif)
extern

Read the cached file offset of the current directory.

Reads state without I/O, allocation, diagnostics, or ownership transfer. A nonzero result can identify a directory whose read later failed; zero can mean a fresh directory or stepping beyond the chain. It is not proof that current tag values came from that offset. See Directory creation and navigation.

Parameters
[in]tifNon-NULL live handle; caller must serialise access.
Returns
Directory offset in file bytes, or zero when no current file offset is recorded.

Definition at line 2814 of file tif_dir.c.

References tiff::tif_diroff.

◆ TIFFFreeDirectory()

void TIFFFreeDirectory ( TIFF *  tif)
extern

Release the current directory's owned values and codec state.

Invokes codec cleanup, clears presence bits, and releases directory-owned arrays, strings, custom-value storage, deferred strile entries, and IFD-size bookkeeping. Borrowed pointers into this storage become invalid. Does not free/close the handle or its client I/O, persist dirty values, dispose the field schema, or fully reset scalar values, offsets, and indices. Initialise a new directory before using it for normal tag/image operations. Core cleanup returns no status; codec callbacks may have their own diagnostics/side effects.

Parameters
[in,out]tifNon-NULL live handle; caller must serialise access.

Definition at line 2165 of file tif_dir.c.

References _TIFFfreeExt(), _TIFFmemset(), CleanupField, FALSE, FIELD_YCBCRPOSITIONING, FIELD_YCBCRSUBSAMPLING, TIFFDirectory::td_colormap_alloc, TIFFDirectory::td_colormap_count, TIFFDirectory::td_customValueCount, TIFFDirectory::td_customValues, TIFFDirectory::td_dirdatasize_Noffsets, TIFFDirectory::td_dirdatasize_offsets, TIFFDirectory::td_dirdatasize_read, TIFFDirectory::td_dirdatasize_write, TIFFDirectory::td_fieldsset, TIFFDirectory::td_iswrittentofile, TIFFDirectory::td_stripbytecount_entry, TIFFDirectory::td_stripoffset_entry, TIFFDirectory::td_stripoffsetbyteallocsize, TIFFDirectory::td_transferfunction_count, tiff::tif_cleanup, tiff::tif_dir, TIFFClrFieldBit, and TIFFTagValue::value.

Referenced by TIFFCleanup(), TIFFCreateCustomDirectory(), TIFFCreateDirectory(), TIFFReadCustomDirectory(), TIFFReadDirectory(), TIFFUnlinkDirectory(), and TIFFWriteDirectorySec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIFFLastDirectory()

int TIFFLastDirectory ( TIFF *  tif)
extern

Test whether the cached next-directory link is zero.

Does not scan or validate the file. A fresh unwritten directory also satisfies this test, and a loop-truncated chain can appear finished. No allocation, I/O, mutation, diagnostic, or ownership transfer occurs.

Parameters
[in]tifNon-NULL live handle; caller must serialise access.
Returns
Nonzero if the cached next offset is zero; zero otherwise.

Definition at line 2820 of file tif_dir.c.

References tiff::tif_nextdiroff.

◆ TIFFNumberOfDirectories()

tdir_t TIFFNumberOfDirectories ( TIFF *  tif)
extern

Count reachable main-chain directories from the cached file header.

Walks directory links without loading their tag values, starting from the cached header rather than the current SubIFD. Does not count unwritten directories or traverse SubIFD arrays/custom metadata. Updates index/offset maps and the cached directory count; leaves current tag storage/index unchanged but can move client I/O position and allocate map storage. Read errors dispatch diagnostics and return the prefix counted so far. A detected next-link loop warns and is treated as the chain end. Map-creation exhaustion can be diagnosed while traversal continues without full loop tracking. A zero or partial count is not a separate error status. No ownership transfers.

Parameters
[in,out]tifNon-NULL live handle; caller must serialise access.
Returns
Number successfully traversed, possibly zero/partial on error; also stored in the cached count.

Definition at line 2623 of file tif_dir.c.

References TIFFHeaderUnion::big, TIFFHeaderUnion::classic, tiff::tif_curdircount, tiff::tif_flags, tiff::tif_header, TIFF_BIGTIFF, TIFFHeaderClassic::tiff_diroff, TIFFHeaderBig::tiff_diroff, and TIFFAdvanceDirectory().

Referenced by _TIFFGetDirNumberFromOffset(), and TIFFWriteDirectorySec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIFFSetDirectory()

int TIFFSetDirectory ( TIFF *  tif,
tdir_t  dirn 
)
extern

Select and read an image directory by its main-chain index.

Uses a cached offset, relative stepping, or traversal from the cached header as appropriate. After leaving a custom/SubIFD context it clears those maps and starts from the main-chain header. It does not select a SubIFD by array position. Does not save dirty values first. Successful reading replaces directory/codec state and invalidates borrowed values and replaceable descriptors. Once reading starts, failure can leave changed offsets, index, next-link, schema, flags, and partially loaded values; there is no rollback to the old directory. Unreachable indices can fail earlier with old values still present but altered maps, traversal flags, or I/O position. Diagnostics follow traversal/reader failures; absence can return zero silently. No ownership transfers and no errno guarantee is provided.

Parameters
[in,out]tifNon-NULL live handle; caller must serialise access.
[in]dirnZero-based main-chain directory index.
Returns
One when TIFFReadDirectory() succeeds, zero if unreachable, looping, or a traversal/read failure occurs; zero does not preserve the old state.

Definition at line 2648 of file tif_dir.c.

References _TIFFCleanupIFDOffsetAndNumberMaps(), _TIFFGetOffsetFromDirNumber(), TIFFHeaderUnion::big, TIFFHeaderUnion::classic, FALSE, tiff::tif_curdir, tiff::tif_diroff, tiff::tif_flags, tiff::tif_header, tiff::tif_nextdiroff, tiff::tif_setdirectory_force_absolute, TIFF_BIGTIFF, TIFFHeaderClassic::tiff_diroff, TIFFHeaderBig::tiff_diroff, TIFF_NON_EXISTENT_DIR_NUMBER, TIFFAdvanceDirectory(), and TIFFReadDirectory().

Here is the call graph for this function:

◆ TIFFSetSubDirectory()

int TIFFSetSubDirectory ( TIFF *  tif,
uint64_t  diroff 
)
extern

Select and read an image directory at a file offset.

Use this for image SubIFDs; EXIF/GPS/custom metadata requires the matching custom reader/schema. An offset known to the maps retains its mapped index. An unrecognised successful offset starts a new chain indexed at zero, clears/reseeds maps, and forces a later TIFFSetDirectory() to restart at the main-chain header. The lookup may first scan main-chain links. Failures may still change traversal state, and a final map-registration failure can follow a successful directory read. A zero offset is a special state operation: clears current/next offsets, sets the index unknown and unwritten flag, keeps old tag values, performs no directory read, and returns zero. Does not save dirty values first. Successful reading replaces directory/codec state and invalidates borrowed values and replaceable descriptors. Once reading starts, failure can leave changed offsets, index, next-link, schema, flags, and partially loaded values; there is no rollback to the old directory. An unreadable or loop-detected offset can fail before old values are replaced, but after the map lookup has scanned the main chain and changed maps, flags, or I/O position. Diagnostics follow traversal/reader failures. No ownership transfers and no errno guarantee is provided.

Parameters
[in,out]tifNon-NULL live handle; caller must serialise access.
[in]diroffImage-IFD offset in file bytes, or zero for the special no-current-offset operation.
Returns
One on read/map-registration success, zero for zero offset, read/traversal failure, or detected map-registration failure; no rollback is promised.

Definition at line 2744 of file tif_dir.c.

References _TIFFCheckDirNumberAndOffset(), _TIFFCleanupIFDOffsetAndNumberMaps(), _TIFFGetDirNumberFromOffset(), FALSE, TIFFDirectory::td_iswrittentofile, tiff::tif_curdir, tiff::tif_dir, tiff::tif_nextdiroff, tiff::tif_setdirectory_force_absolute, TIFF_NON_EXISTENT_DIR_NUMBER, TIFFReadDirectory(), and TRUE.

Here is the call graph for this function:

◆ TIFFUnlinkDirectory()

int TIFFUnlinkDirectory ( TIFF *  tif,
tdir_t  dirn 
)
extern

Remove an image directory from the on-file main chain.

Requires a writable handle and a reachable main-chain entry. Patches the preceding link (or header) to the following directory; does not reclaim the removed IFD or image-data bytes, truncate the file, or update references such as SubIFD arrays. Does not flush current dirty values/data first. After a successful link write, releases owned raw-buffer/directory storage and codec state, installs defaults, clears write/current/next/last offsets and maps, and leaves a fresh directory intended for appending. Borrowed storage is invalidated and cached counts/index change. Seek/write/chain failures dispatch diagnostics but can leave changed maps, position, or file bytes; no rollback is attempted. The patch seek result is not independently checked, and post-write default-setup errors do not change the success result. No handle ownership transfers.

Parameters
[in,out]tifNon-NULL live handle; caller must serialise access.
[in]dirnOne-based main-chain position: the first directory is 1, unlike TIFFSetDirectory(). Zero is rejected.
Returns
One after a successful link write/reset attempt; zero for read-only mode, zero index, a nonexistent directory (diagnosed either as nonexistent or as a possible IFD loop), or a detected traversal/write failure.

Definition at line 2828 of file tif_dir.c.

References _TIFFCleanupIFDOffsetAndNumberMaps(), _TIFFfreeExt(), TIFFHeaderUnion::big, TIFFHeaderUnion::classic, tiff::tif_curdir, tiff::tif_curdircount, tiff::tif_curoff, tiff::tif_diroff, tiff::tif_flags, tiff::tif_header, tiff::tif_lastdiroff, tiff::tif_mode, tiff::tif_nextdiroff, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdata, tiff::tif_rawdataloaded, tiff::tif_rawdataoff, tiff::tif_rawdatasize, TIFF_BEENWRITING, TIFF_BIGTIFF, TIFF_BUF4WRITE, TIFF_BUFFERSETUP, TIFFHeaderClassic::tiff_diroff, TIFFHeaderBig::tiff_diroff, TIFF_MYBUFFER, TIFF_NON_EXISTENT_DIR_NUMBER, TIFF_POSTENCODE, TIFF_SWAB, TIFFAdvanceDirectory(), TIFFDefaultDirectory(), TIFFErrorExtR(), TIFFFreeDirectory(), TIFFSeekFile, TIFFSwabLong(), TIFFSwabLong8(), and WriteOK.

Here is the call graph for this function: