LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Functions
Transfer buffers and preparation

Attach borrowed buffers, allocate owned buffers, and prepare strile arrays. More...

Collaboration diagram for Transfer buffers and preparation:

Functions

int TIFFReadBufferSetup (TIFF *tif, void *bp, tmsize_t size)
 Replace the handle's raw reading buffer.
 
int TIFFWriteBufferSetup (TIFF *tif, void *bp, tmsize_t size)
 Replace the handle's encoding buffer.
 
int TIFFSetupStrips (TIFF *tif)
 Replace strile offset/count arrays from current geometry.
 
int TIFFWriteCheck (TIFF *tif, int tiles, const char *module)
 Validate and prepare geometry for image writing.
 
uint64_t TIFFGetMaxCompressionRatio (TIFF *tif)
 Query the codec's allocation-recovery compression-ratio heuristic.
 

Detailed Description

Attach borrowed buffers, allocate owned buffers, and prepare strile arrays.

Function Documentation

◆ TIFFGetMaxCompressionRatio()

uint64_t TIFFGetMaxCompressionRatio ( TIFF *  tif)
extern

Query the codec's allocation-recovery compression-ratio heuristic.

Invokes the installed optional ratio callback; absent callback returns zero. Used by selected large-allocation sanity checks, not a mathematically guaranteed compression bound or output-buffer capacity. Callback effects/diagnostics depend on the codec; no ownership transfers and dispatch imposes no other validation.

Parameters
[in]tifNon-NULL live handle with matching current geometry and codec methods; the built-in callbacks only read it. Serialise access externally.
Returns
Codec heuristic ratio, or zero when absent/disabled; not an error indicator.

Definition at line 272 of file tif_compress.c.

References tiff::tif_getmaxcompressionratio.

Referenced by _TIFFReadEncodedStripAndAllocBuffer(), _TIFFReadEncodedTileAndAllocBuffer(), TIFFFillStrip(), and TIFFFillTile().

Here is the caller graph for this function:

◆ TIFFReadBufferSetup()

int TIFFReadBufferSetup ( TIFF *  tif,
void *  bp,
tmsize_t  size 
)
extern

Replace the handle's raw reading buffer.

Detaches old raw storage, freeing it only when TIFF_MYBUFFER marks ownership. A non-NULL bp is borrowed: keep it live, writable, and large enough until detached/handle cleanup; the library does not free it. NULL requests matching Ext allocation owned/released by the handle. Never pass the old owned allocation back as bp: it is freed first. Replacement is destructive, with no rollback on allocation failure. Requires a raw-capable codec; owned capacity is rounded to 1024 bytes and zero-filled. Explicit borrowed capacity is stored as supplied, so the caller must provide a valid positive size. Clears the raw cursor, count and loaded extent and forgets the current strip/tile, so the next read reloads its strile into the new buffer; with a codec that cannot seek within a strile, scanline reading must then restart at the strile's first row. Does not otherwise restart codec state. Allocation/policy failures dispatch diagnostics. After a failed owned allocation the handle has no raw buffer and a zero capacity but keeps TIFF_MYBUFFER, so a later strip or tile read allocates its own buffer again. No caller allocation ownership transfers merely by attaching bp.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]bpBorrowed writable buffer that later raw reads fill, or NULL to allocate owned storage; not dereferenced here and must not alias an allocation being released.
[in]sizePositive buffer capacity in bytes; with bp NULL it is rounded up to a multiple of 1024, and a size that rounds to zero is rejected.
Returns
One on attachment/allocation success, zero on unsupported raw reading or detected size/allocation failure; old storage may already be gone.

Definition at line 1802 of file tif_read.c.

References _TIFFcallocExt(), _TIFFfreeExt(), NOSTRIP, NOTILE, TIFFDirectory::td_curstrip, TIFFDirectory::td_curtile, TIFFDirectory::td_row, tiff::tif_dir, tiff::tif_flags, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdata, tiff::tif_rawdataloaded, tiff::tif_rawdataoff, tiff::tif_rawdatasize, TIFF_MYBUFFER, TIFF_NOREADRAW, TIFFErrorExtR(), and TIFFroundup_64.

Referenced by TIFFFillStrip(), and TIFFFillTile().

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

◆ TIFFSetupStrips()

int TIFFSetupStrips ( TIFF *  tif)
extern

Replace strile offset/count arrays from current geometry.

Computes counts, enforces directory array-size limits, frees old arrays and allocates zeroed replacements with the handle allocator. Requires consistent nonzero sample/row/tile geometry, particularly separate-plane divisor. Updates cached counts before allocations; failure can leave one array allocated and the other NULL, with old values lost. Sets offset/count presence bits only on success. Does not write payloads or the IFD. Diagnostics follow geometry/size/allocation helpers; borrowed array views are invalidated.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
Returns
One after both arrays are initialised, zero on count/size/allocation failure; not transactional.

Definition at line 729 of file tif_write.c.

References _TIFFCheckMalloc(), _TIFFfreeExt(), _TIFFmemset(), FIELD_ROWSPERSTRIP, FIELD_STRIPBYTECOUNTS, FIELD_STRIPOFFSETS, FIELD_TILEDIMENSIONS, isTiled, isUnspecified, PLANARCONFIG_SEPARATE, TIFFDirectory::td_nstrips, TIFFDirectory::td_planarconfig, TIFFDirectory::td_samplesperpixel, TIFFDirectory::td_stripbytecount_p, TIFFDirectory::td_stripoffset_p, TIFFDirectory::td_stripsperimage, tiff::tif_dir, tiff::tif_flags, TIFF_BIGTIFF, TIFFErrorExtR(), TIFFNumberOfStrips(), TIFFNumberOfTiles(), and TIFFSetFieldBit.

Referenced by TIFFCheckpointDirectory(), TIFFForceStrileArrayWriting(), TIFFReadDirectory(), and TIFFWriteCheck().

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

◆ TIFFWriteBufferSetup()

int TIFFWriteBufferSetup ( TIFF *  tif,
void *  bp,
tmsize_t  size 
)
extern

Replace the handle's encoding buffer.

Detaches old raw storage, freeing it only when TIFF_MYBUFFER marks ownership. A non-NULL bp is borrowed: keep it live, writable, and large enough until detached/handle cleanup; the library does not free it. NULL requests matching Ext allocation owned/released by the handle. Never pass the old owned allocation back as bp: it is freed first. A size other than minus one must be positive; any other value is diagnosed and rejected before the old buffer is touched. Replacement is otherwise destructive, with no rollback on allocation failure. Minus one forces owned allocation, ignoring bp, using a geometry estimate plus margin and at least 8192 bytes. Initialises raw cursor/count and buffer-setup flag on success; does not flush pending encoded bytes before replacement. Allocation failure dispatches a diagnostic. No caller allocation ownership transfers merely by attaching bp.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]bpBorrowed writable buffer that later encoding fills, or NULL to allocate owned storage; not dereferenced here and must not alias an allocation being released.
[in]sizeBuffer capacity in bytes, or minus one to allocate owned storage sized from the current geometry (bp is then ignored).
Returns
One when the buffer is attached or allocated; zero for an invalid size, with the old buffer kept, or if allocating owned storage fails, by which time any previously owned buffer has been freed.

Definition at line 860 of file tif_write.c.

References _TIFFfreeExt(), _TIFFmallocExt(), isTiled, TIFFDirectory::td_tilesize, tiff::tif_dir, tiff::tif_flags, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdata, tiff::tif_rawdatasize, TIFF_BUFFERSETUP, TIFF_MYBUFFER, TIFF_SSIZE_FORMAT, TIFF_TMSIZE_T_MAX, TIFFErrorExtR(), and TIFFStripSize().

Referenced by _TIFFReserveLargeEnoughWriteBuffer().

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

◆ TIFFWriteCheck()

int TIFFWriteCheck ( TIFF *  tif,
int  tiles,
const char *  module 
)
extern

Validate and prepare geometry for image writing.

Checks writable mode and organisation, attempts deferred-array fill without propagating its result, validates image-width presence, allocates missing strile arrays, computes cached tile/scanline sizes, and sets TIFF_BEENWRITING to freeze most format tags. Can force deferred strile-array writing; if that fails, clears TIFF_BEENWRITING again and fails. Does not validate every tag, input buffer, or codec operation. Reads deferred strile arrays when present and, in update mode with placeholder strile entries, rewrites them in the file through TIFFForceStrileArrayWriting(). Invokes tag/diagnostic callbacks but no codec callbacks, and encodes no image data. Failure can leave new arrays/counts/caches and flags; no rollback. No ownership transfers. No errno or durability guarantee. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]tilesExactly one for tiled operations, zero for strips/scanlines.
[in]moduleBorrowed diagnostic context string, or NULL.
Returns
One after required preparation, zero on detected mode/organisation/required geometry/allocation or forced strile-array write failure; nested errors can coexist with one.

Definition at line 783 of file tif_write.c.

References _TIFFFillStriles(), FIELD_IMAGEDIMENSIONS, isTiled, TIFFDirectory::td_nstrips, TIFFDirectory::td_scanlinesize, TIFFDirectory::td_stripbytecount_entry, TIFFDirectory::td_stripoffset_entry, TIFFDirectory::td_stripoffset_p, TIFFDirectory::td_tilesize, TIFFDirEntry::tdir_count, TIFFDirEntry::tdir_offset, TIFFDirEntry::tdir_tag, TIFFDirEntry::tdir_type, tiff::tif_dir, tiff::tif_flags, tiff::tif_mode, TIFF_BEENWRITING, TIFF_DIRTYDIRECT, TIFFErrorExtR(), TIFFFieldSet, TIFFForceStrileArrayWriting(), TIFFScanlineSize(), TIFFSetupStrips(), TIFFTileSize(), and TIFFDirEntry::toff_long8.

Here is the call graph for this function: