LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Macros | Typedefs | Functions
Transfer helpers and codec methods

Manage raw caches, codec progress, strile appends, and postdecode conversion. More...

Collaboration diagram for Transfer helpers and codec methods:

Macros

#define INITIAL_THRESHOLD   (1024 * 1024)
 Start progressive raw-buffer reads at one MiB.
 
#define THRESHOLD_MULTIPLIER   10
 Grow raw-buffer read allocation stages by a factor of ten.
 
#define MAX_THRESHOLD
 Set the allocation-growth cutoff to 1000 MiB.
 
#define TIFF_INT64_MAX   ((((int64_t)0x7FFFFFFF) << 32) | 0xFFFFFFFF)
 Bound accepted raw strile byte counts to INT64_MAX.
 
#define NOSTRIP   ((uint32_t)(-1)) /* undefined state */
 Local repeat of the NOSTRIP sentinel defined in tif_dir.h.
 
#define WRITECHECKSTRIPS(tif, module)    (((tif)->tif_flags & TIFF_BEENWRITING) || TIFFWriteCheck((tif), 0, module))
 Reuse write preparation or check strip organisation.
 
#define WRITECHECKTILES(tif, module)    (((tif)->tif_flags & TIFF_BEENWRITING) || TIFFWriteCheck((tif), 1, module))
 Reuse write preparation or check tile organisation.
 
#define BUFFERCHECK(tif)
 Reuse an output buffer or allocate default encoding storage.
 
#define isUnspecified(tif, f)    (TIFFFieldSet(tif, f) && (tif)->tif_dir.td_imagelength == 0)
 Test the zero-image-length provisional strile case.
 

Typedefs

typedef void(* TIFFVoidMethod) (TIFF *tif)
 Run a codec close or cleanup operation.
 
typedef int(* TIFFBoolMethod) (TIFF *tif)
 Run a codec setup or completion operation.
 
typedef int(* TIFFPreMethod) (TIFF *tif, uint16_t sample)
 Prepare a codec for one sample plane.
 
typedef int(* TIFFCodeMethod) (TIFF *tif, uint8_t *buf, tmsize_t size, uint16_t sample)
 Encode or decode a requested image-data extent.
 
typedef int(* TIFFSeekMethod) (TIFF *tif, uint32_t nrows)
 Advance codec decoding or encoding by a row count.
 
typedef void(* TIFFPostMethod) (TIFF *tif, uint8_t *buf, tmsize_t size)
 Transform image bytes in place after decoding or before encoding.
 
typedef uint64_t(* TIFFGetMaxCompressionRatioMethod) (TIFF *tif)
 Return the codec allocation-sanity compression-ratio heuristic.
 

Functions

static int TIFFReadAndRealloc (TIFF *tif, tmsize_t size, tmsize_t rawdata_offset, int is_strip, uint32_t strip_or_tile, const char *module)
 Grow and fill the raw buffer from the current client position.
 
static int TIFFFillStripPartial (TIFF *tif, int strip, tmsize_t read_ahead, int restart)
 Refill a partial raw strip while retaining unconsumed bytes.
 
static int TIFFSeek (TIFF *tif, uint32_t row, uint16_t sample)
 Position strip decoding at a requested scanline.
 
static tmsize_t TIFFReadEncodedStripGetStripSize (TIFF *tif, uint32_t strip, uint16_t *pplane)
 Validate a strip and compute its effective decoded extent.
 
static tmsize_t TIFFReadRawStrip1 (TIFF *tif, uint32_t strip, void *buf, tmsize_t size, const char *module)
 Read an exact raw-strip byte extent into caller storage.
 
static tmsize_t TIFFReadRawStripOrTile2 (TIFF *tif, uint32_t strip_or_tile, int is_strip, tmsize_t size, const char *module)
 Seek to a strile and read bytes into the expandable raw cache.
 
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW uint64_t NoSanitizeSubUInt64 (uint64_t a, uint64_t b)
 Subtract unsigned offsets with intentional modular arithmetic.
 
int TIFFFillStrip (TIFF *tif, uint32_t strip)
 Load raw strip bytes and initialise codec decoding.
 
static tmsize_t TIFFReadRawTile1 (TIFF *tif, uint32_t tile, void *buf, tmsize_t size, const char *module)
 Read an exact raw-tile byte extent into caller storage.
 
int TIFFFillTile (TIFF *tif, uint32_t tile)
 Load raw tile bytes and initialise codec decoding.
 
static int TIFFStartStrip (TIFF *tif, uint32_t strip)
 Prepare the codec and raw cursor for strip decoding.
 
static int TIFFStartTile (TIFF *tif, uint32_t tile)
 Prepare the codec and raw cursor for tile decoding.
 
static int TIFFCheckRead (TIFF *tif, int tiles)
 Check readable mode and expected image organisation.
 
static int _TIFFReserveLargeEnoughWriteBuffer (TIFF *tif, uint32_t strip_or_tile)
 Reserve raw output capacity for a possible strile rewrite.
 
static int TIFFGrowStrips (TIFF *tif, uint32_t delta, const char *module)
 Grow contiguous strip offset/count arrays by a requested delta.
 
static int TIFFAppendToStrip (TIFF *tif, uint32_t strip, uint8_t *data, tmsize_t cc)
 Append stored bytes or relocate a growing overwritten strile.
 
void _TIFFNoPostDecode (TIFF *tif, uint8_t *buf, tmsize_t cc)
 Leave decoded bytes unchanged.
 
void _TIFFSwab16BitData (TIFF *tif, uint8_t *buf, tmsize_t cc)
 Swap each 2-byte sample in place.
 
void _TIFFSwab24BitData (TIFF *tif, uint8_t *buf, tmsize_t cc)
 Swap each 3-byte sample in place.
 
void _TIFFSwab32BitData (TIFF *tif, uint8_t *buf, tmsize_t cc)
 Swap each 4-byte sample in place.
 
void _TIFFSwab64BitData (TIFF *tif, uint8_t *buf, tmsize_t cc)
 Swap each 8-byte sample in place.
 
int _TIFFCheckPostDecodeLength (TIFF *tif, TIFFPostMethod tif_postdecode, tmsize_t cc, const char *modulename)
 Check the byte count for a byte-swapping postdecode method.
 
int TIFFFlushData1 (TIFF *tif)
 Append buffered encoded bytes without invoking postencode recursively.
 
tmsize_t _TIFFReadEncodedStripAndAllocBuffer (TIFF *tif, uint32_t strip, void **buf, tmsize_t bufsizetoalloc, tmsize_t size_to_read)
 Decode after deferred allocation of caller-owned output storage.
 
tmsize_t _TIFFReadEncodedTileAndAllocBuffer (TIFF *tif, uint32_t tile, void **buf, tmsize_t bufsizetoalloc, tmsize_t size_to_read)
 Decode after deferred allocation of caller-owned output storage.
 
tmsize_t _TIFFReadTileAndAllocBuffer (TIFF *tif, void **buf, tmsize_t bufsizetoalloc, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
 Decode after deferred allocation of caller-owned output storage.
 

Detailed Description

Manage raw caches, codec progress, strile appends, and postdecode conversion.

Macro Definition Documentation

◆ BUFFERCHECK

#define BUFFERCHECK (   tif)
Value:
((((tif)->tif_flags & TIFF_BUFFERSETUP) && tif->tif_rawdata) || \
TIFFWriteBufferSetup((tif), NULL, (tmsize_t)(-1)))
#define TIFF_BUFFERSETUP
Mark completed data-buffer setup.
Definition tiffiop.h:426
int TIFFWriteBufferSetup(TIFF *tif, void *bp, tmsize_t size)
Replace the handle's encoding buffer.
Definition tif_write.c:860
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Definition tiffio.h:89

Reuse an output buffer or allocate default encoding storage.

Short-circuits when TIFF_BUFFERSETUP is set and tif_rawdata is non-NULL; otherwise calls TIFFWriteBufferSetup() with a NULL buffer and default size, which allocates a handle-owned buffer. tif is evaluated up to three times.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
Returns
Nonzero for usable prior storage or successful setup.

Definition at line 91 of file tif_write.c.

◆ INITIAL_THRESHOLD

#define INITIAL_THRESHOLD   (1024 * 1024)

Start progressive raw-buffer reads at one MiB.

Size in bytes of the first chunk TIFFReadAndRealloc() reads on 64-bit hosts when the raw buffer must grow, so a truncated file does not force one large allocation up front.

Definition at line 56 of file tif_read.c.

◆ isUnspecified

#define isUnspecified (   tif,
  f 
)     (TIFFFieldSet(tif, f) && (tif)->tif_dir.td_imagelength == 0)

Test the zero-image-length provisional strile case.

Pure test with no side effects; it reads the presence bitmap and ImageLength only.

Parameters
[in]tifLive handle expression, evaluated twice.
[in]fValid presence-bit index, evaluated twice (by TIFFFieldSet()).
Returns
Nonzero if the bit is set and ImageLength is zero.

Definition at line 726 of file tif_write.c.

◆ MAX_THRESHOLD

#define MAX_THRESHOLD
Value:
#define INITIAL_THRESHOLD
Start progressive raw-buffer reads at one MiB.
Definition tif_read.c:56
#define THRESHOLD_MULTIPLIER
Grow raw-buffer read allocation stages by a factor of ten.
Definition tif_read.c:64

Set the allocation-growth cutoff to 1000 MiB.

Once the chunk size reaches this value, TIFFReadAndRealloc() reads the whole remaining request at once; it is not a maximum read size.

Definition at line 72 of file tif_read.c.

◆ NOSTRIP

#define NOSTRIP   ((uint32_t)(-1)) /* undefined state */

Local repeat of the NOSTRIP sentinel defined in tif_dir.h.

Definition at line 44 of file tif_write.c.

◆ THRESHOLD_MULTIPLIER

#define THRESHOLD_MULTIPLIER   10

Grow raw-buffer read allocation stages by a factor of ten.

Each chunk TIFFReadAndRealloc() reads is ten times the previous one (1, 10, 100 MiB).

Definition at line 64 of file tif_read.c.

◆ TIFF_INT64_MAX

#define TIFF_INT64_MAX   ((((int64_t)0x7FFFFFFF) << 32) | 0xFFFFFFFF)

Bound accepted raw strile byte counts to INT64_MAX.

Expands to INT64_MAX; TIFFFillStrip() and TIFFFillTile() reject strile byte counts beyond the signed 64-bit range.

Definition at line 83 of file tif_read.c.

◆ WRITECHECKSTRIPS

#define WRITECHECKSTRIPS (   tif,
  module 
)     (((tif)->tif_flags & TIFF_BEENWRITING) || TIFFWriteCheck((tif), 0, module))

Reuse write preparation or check strip organisation.

Short-circuits when TIFF_BEENWRITING is already set, so the organisation is not checked again; otherwise calls TIFFWriteCheck() with tiles = 0, which can allocate and change handle state. tif is evaluated up to twice.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]moduleDiagnostic context evaluated only when preparation runs.
Returns
Nonzero for prior been-writing state or successful preparation.

Definition at line 60 of file tif_write.c.

◆ WRITECHECKTILES

#define WRITECHECKTILES (   tif,
  module 
)     (((tif)->tif_flags & TIFF_BEENWRITING) || TIFFWriteCheck((tif), 1, module))

Reuse write preparation or check tile organisation.

Short-circuits when TIFF_BEENWRITING is already set, so the organisation is not checked again; otherwise calls TIFFWriteCheck() with tiles = 1, which can allocate and change handle state. tif is evaluated up to twice.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]moduleDiagnostic context evaluated only when preparation runs.
Returns
Nonzero for prior been-writing state or successful preparation.

Definition at line 76 of file tif_write.c.

Typedef Documentation

◆ TIFFBoolMethod

typedef int(* TIFFBoolMethod) (TIFF *tif)

Run a codec setup or completion operation.

Used for fixuptags/setupdecode/setupencode/postencode. May allocate state or flush encoded bytes according to its installed role; failure need not undo changes. Invoked synchronously through a borrowed method; keep code/state live for calls, serialise handle access, and avoid recursive dispatch through the same installed slot.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
Returns
One on accepted completion, zero on failure; use Boolean results rather than negative error codes.

Definition at line 202 of file tiffiop.h.

◆ TIFFCodeMethod

typedef int(* TIFFCodeMethod) (TIFF *tif, uint8_t *buf, tmsize_t size, uint16_t sample)

Encode or decode a requested image-data extent.

Direction is selected by the installed encoder/decoder slot. Decoders write caller output; encoders read input that postprocessing/codec paths may mutate. Implementations must respect the supplied nonnegative extent and their format preconditions. No ownership transfer, capacity discovery, or rollback is supplied by the pointer type. Invoked synchronously through a borrowed method; keep code/state live for calls, serialise handle access, and avoid recursive dispatch through the same installed slot.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in,out]bufBorrowed readable/writable image buffer for the installed method role.
[in]sizeNonnegative valid byte extent.
[in]sampleSelected sample plane.
Returns
One on success, zero on failure; negative values are not uniformly rejected by all dispatchers.

Definition at line 241 of file tiffiop.h.

◆ TIFFGetMaxCompressionRatioMethod

typedef uint64_t(* TIFFGetMaxCompressionRatioMethod) (TIFF *tif)

Return the codec allocation-sanity compression-ratio heuristic.

Used for selected large-allocation checks, not a guaranteed codec expansion/capacity bound. No returned ownership; method code and any state must remain live while installed/in flight. Invoked synchronously through a borrowed method; keep code/state live for calls, serialise handle access, and avoid recursive dispatch through the same installed slot.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
Returns
Heuristic ratio; zero disables this bound.

Definition at line 331 of file tiffiop.h.

◆ TIFFPostMethod

typedef void(* TIFFPostMethod) (TIFF *tif, uint8_t *buf, tmsize_t size)

Transform image bytes in place after decoding or before encoding.

Typically swaps sample byte order. Requires writable aligned storage and format-specific whole-sample multiples; no independent failure/status channel or ownership transfer. No dispatcher automatically restores source bytes. Invoked synchronously through a borrowed method; keep code/state live for calls, serialise handle access, and avoid recursive dispatch through the same installed slot.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in,out]bufBorrowed writable image bytes.
[in]sizeNonnegative byte extent satisfying method-specific alignment/multiple rules.

Definition at line 277 of file tiffiop.h.

◆ TIFFPreMethod

typedef int(* TIFFPreMethod) (TIFF *tif, uint16_t sample)

Prepare a codec for one sample plane.

Called after raw input/output state is selected. Borrows the handle; plane-specific allocations/state remain codec-owned until its cleanup. Invoked synchronously through a borrowed method; keep code/state live for calls, serialise handle access, and avoid recursive dispatch through the same installed slot.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]sampleSelected sample plane.
Returns
One on readiness, zero on failure; state can already change.

Definition at line 218 of file tiffiop.h.

◆ TIFFSeekMethod

typedef int(* TIFFSeekMethod) (TIFF *tif, uint32_t nrows)

Advance codec decoding or encoding by a row count.

Updates codec/raw state without transferring ownership. Unsupported skips must return zero; a failed skip need not preserve the starting state. Invoked synchronously through a borrowed method; keep code/state live for calls, serialise handle access, and avoid recursive dispatch through the same installed slot.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]nrowsNumber of rows to skip forward.
Returns
One on supported advancement, zero on failure/unsupported operation.

Definition at line 259 of file tiffiop.h.

◆ TIFFVoidMethod

typedef void(* TIFFVoidMethod) (TIFF *tif)

Run a codec close or cleanup operation.

May release codec-owned state, restore method chains, and change the handle; client resources remain governed by lifecycle ownership. No status result is available; implementations must report failures through diagnostics where applicable. Invoked synchronously through a borrowed method; keep code/state live for calls, serialise handle access, and avoid recursive dispatch through the same installed slot.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.

Definition at line 186 of file tiffiop.h.

Function Documentation

◆ _TIFFCheckPostDecodeLength()

int _TIFFCheckPostDecodeLength ( TIFF *  tif,
TIFFPostMethod  tif_postdecode,
tmsize_t  cc,
const char *  modulename 
)
extern

Check the byte count for a byte-swapping postdecode method.

Recognises the 16-, 24-, 32-, and 64-bit swab methods and checks that cc is a multiple of their sample width. Other methods pass without a check. Does not invoke the method, access pixel storage, allocate, perform I/O, or transfer ownership. A mismatch reports through TIFFErrorExtR(); the caller must reject the operation before invoking postdecode. Diagnostic callbacks can have their own side effects; no errno guarantee is made.

Parameters
[in]tifLive handle used for error dispatch; not modified.
[in]tif_postdecodeEffective postdecode method, including any adjustment for complex samples; borrowed and not invoked.
[in]ccNonnegative byte count to be passed to postdecode.
[in]modulenameBorrowed diagnostic context string, valid for the duration of the call.
Returns
One for a matching multiple or an unrecognised method, zero for a swab-length mismatch after reporting an error.

Definition at line 2260 of file tif_read.c.

References _TIFFSwab16BitData(), _TIFFSwab24BitData(), _TIFFSwab32BitData(), _TIFFSwab64BitData(), TIFF_SSIZE_FORMAT, and TIFFErrorExtR().

Referenced by _TIFFReadEncodedStripAndAllocBuffer(), _TIFFReadEncodedTileAndAllocBuffer(), TIFFReadEncodedStrip(), TIFFReadEncodedTile(), TIFFReadFromUserBuffer(), TIFFReadScanline(), TIFFWriteEncodedStrip(), TIFFWriteEncodedTile(), and TIFFWriteScanline().

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

◆ _TIFFNoPostDecode()

void _TIFFNoPostDecode ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc 
)
extern

Leave decoded bytes unchanged.

No-op: all arguments are ignored and no allocation, diagnostics, state, ownership, or byte changes occur.

Parameters
[in]tifUnused context, may be NULL.
[in]bufIgnored; not dereferenced.
[in]ccIgnored.

Definition at line 2209 of file tif_read.c.

Referenced by _TIFFVSetField(), JPEGSetupDecode(), LogLuvSetupDecode(), PixarLogSetupDecode(), PredictorSetupDecode(), PredictorSetupEncode(), and TIFFDefaultDirectory().

Here is the caller graph for this function:

◆ _TIFFReadEncodedStripAndAllocBuffer()

tmsize_t _TIFFReadEncodedStripAndAllocBuffer ( TIFF *  tif,
uint32_t  strip,
void **  buf,
tmsize_t  bufsizetoalloc,
tmsize_t  size_to_read 
)
extern

Decode after deferred allocation of caller-owned output storage.

An existing *buf delegates to the normal decoder. A NULL slot first loads raw data and applies selected compression-ratio/size sanity checks, then allocates zeroed matching Ext storage. On success the caller owns it and must use _TIFFfreeExt(tif,...); keep the matching handle/accounting context alive. Later decode failure retains that allocation and partial output in *buf for the caller to release. The separate allocation-size and decode-size parameters are caller-established invariants, not an automatic capacity check. Tile coordinate wrapper checks coordinates before delegating. May allocate or replace handle-owned raw/strile buffers, load deferred metadata, seek/read/write client I/O, and invoke codec/tag/diagnostic callbacks. No handle or caller-buffer ownership transfers. Failure is not transactional: buffers, codec progress, indices, flags, metadata, file position, or file bytes can already have changed; disregard partial decoded output unless a codec explicitly documents otherwise. No errno, rollback, 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]stripValid strip index.
[in,out]bufNon-NULL owner slot, initially NULL or a matching writable allocation; existing storage must already have enough capacity.
[in]bufsizetoallocPositive allocation byte count at least the effective decoded output extent; the helper does not verify that relationship.
[in]size_to_readMinus one for full decoded extent, otherwise nonnegative supported output limit.
Returns
Effective decoded byte request on success, minus one on detected rejection/allocation/decoder failure; an allocation may survive failure.

Definition at line 769 of file tif_read.c.

References _TIFFcallocExt(), _TIFFCheckPostDecodeLength(), tiff::tif_decodestrip, tiff::tif_postdecode, tiff::tif_rawdatasize, TIFFErrorExtR(), TIFFFileName(), TIFFFillStrip(), TIFFGetMaxCompressionRatio(), TIFFReadEncodedStrip(), and TIFFReadEncodedStripGetStripSize().

Referenced by gtStripContig(), and gtStripSeparate().

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

◆ _TIFFReadEncodedTileAndAllocBuffer()

tmsize_t _TIFFReadEncodedTileAndAllocBuffer ( TIFF *  tif,
uint32_t  tile,
void **  buf,
tmsize_t  bufsizetoalloc,
tmsize_t  size_to_read 
)
extern

Decode after deferred allocation of caller-owned output storage.

An existing *buf delegates to the normal decoder. A NULL slot first loads raw data and applies selected compression-ratio/size sanity checks, then allocates zeroed matching Ext storage. An uncompressed tile must have a recorded byte count equal to the tile size. On success the caller owns it and must use _TIFFfreeExt(tif,...); keep the matching handle/accounting context alive. Later decode failure retains that allocation and partial output in *buf for the caller to release. The separate allocation-size and decode-size parameters are caller-established invariants, not an automatic capacity check. Tile coordinate wrapper checks coordinates before delegating. May allocate or replace handle-owned raw/strile buffers, load deferred metadata, seek/read/write client I/O, and invoke codec/tag/diagnostic callbacks. No handle or caller-buffer ownership transfers. Failure is not transactional: buffers, codec progress, indices, flags, metadata, file position, or file bytes can already have changed; disregard partial decoded output unless a codec explicitly documents otherwise. No errno, rollback, 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]tileValid tile index.
[in,out]bufNon-NULL owner slot, initially NULL or a matching writable allocation; existing storage must already have enough capacity.
[in]bufsizetoallocPositive allocation byte count at least the effective decoded output extent; the helper does not verify that relationship.
[in]size_to_readMinus one for full decoded extent, otherwise nonnegative supported output limit.
Returns
Effective decoded byte request on success, minus one on detected rejection/allocation/decoder failure; an allocation may survive failure.

Definition at line 1373 of file tif_read.c.

References _TIFFCheckPostDecodeLength(), _TIFFmallocExt(), _TIFFmemset(), COMPRESSION_NONE, TIFFDirectory::td_tilesize, tiff::tif_decodetile, tiff::tif_dir, tiff::tif_postdecode, tiff::tif_rawdatasize, TIFFCheckRead(), TIFFErrorExtR(), TIFFFileName(), TIFFFillTile(), TIFFGetMaxCompressionRatio(), TIFFGetStrileByteCount(), and TIFFReadEncodedTile().

Referenced by _TIFFReadTileAndAllocBuffer().

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

◆ _TIFFReadTileAndAllocBuffer()

tmsize_t _TIFFReadTileAndAllocBuffer ( TIFF *  tif,
void **  buf,
tmsize_t  bufsizetoalloc,
uint32_t  x,
uint32_t  y,
uint32_t  z,
uint16_t  s 
)
extern

Decode after deferred allocation of caller-owned output storage.

An existing *buf delegates to the normal decoder. A NULL slot first loads raw data and applies selected compression-ratio/size sanity checks, then allocates zeroed matching Ext storage. On success the caller owns it and must use _TIFFfreeExt(tif,...); keep the matching handle/accounting context alive. Later decode failure retains that allocation and partial output in *buf for the caller to release. The separate allocation-size and decode-size parameters are caller-established invariants, not an automatic capacity check. Tile coordinate wrapper checks coordinates before delegating. May allocate or replace handle-owned raw/strile buffers, load deferred metadata, seek/read/write client I/O, and invoke codec/tag/diagnostic callbacks. No handle or caller-buffer ownership transfers. Failure is not transactional: buffers, codec progress, indices, flags, metadata, file position, or file bytes can already have changed; disregard partial decoded output unless a codec explicitly documents otherwise. No errno, rollback, 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,out]bufNon-NULL owner slot, initially NULL or a matching writable allocation; existing storage must already have enough capacity.
[in]bufsizetoallocPositive allocation byte count at least the effective decoded output extent; the helper does not verify that relationship.
[in]xImage column.
[in]yImage row.
[in]zDepth slice.
[in]sSeparate sample plane.
Returns
Effective decoded byte request on success, minus one on detected rejection/allocation/decoder failure; an allocation may survive failure.

Definition at line 1350 of file tif_read.c.

References _TIFFComputeTileExt(), _TIFFReadEncodedTileAndAllocBuffer(), TIFFCheckRead(), and TIFFCheckTile().

Referenced by gtTileContig(), and gtTileSeparate().

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

◆ _TIFFReserveLargeEnoughWriteBuffer()

static int _TIFFReserveLargeEnoughWriteBuffer ( TIFF *  tif,
uint32_t  strip_or_tile 
)
static

Reserve raw output capacity for a possible strile rewrite.

Requires a valid count array/index. Can replace output buffering with a rounded owned allocation larger than the previous stored count plus safety margin, even if a borrowed buffer was attached. Byte-count-plus-margin and casts rely on representable metadata; not general overflow validation. Old raw contents can be lost. The only effects are TIFFWriteBufferSetup() replacing the raw buffer and diagnostics; no client I/O. If that allocation fails, the previous raw buffer has already been released and tif_rawdata is NULL. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]strip_or_tileValid logical strile index for this operation.
Returns
One after adequate capacity/no growth, zero on invalid metadata/index or allocation failure.

Definition at line 291 of file tif_write.c.

References NOSTRIP, tiff::tif_dir, tiff::tif_rawdatasize, TIFFErrorExtR(), TIFFroundup_64, and TIFFWriteBufferSetup().

Referenced by TIFFWriteEncodedStrip(), and TIFFWriteEncodedTile().

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

◆ _TIFFSwab16BitData()

void _TIFFSwab16BitData ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc 
)
extern

Swap each 2-byte sample in place.

Swaps complete samples and leaves any trailing partial sample unchanged. A byte count not divisible by 2 emits a warning through TIFFWarningExtR() in all builds, but does not prevent swapping the complete samples. Borrows/modifies bytes without allocation, I/O, or ownership transfer. It is an involution on complete samples, not general sample conversion.

Parameters
[in]tifLive handle used for warning dispatch; not modified.
[in,out]bufWritable storage of cc bytes with alignment suitable for uint16_t.
[in]ccNonnegative byte count; a multiple of 2 swaps all bytes.

Definition at line 2216 of file tif_read.c.

References TIFF_SSIZE_FORMAT, TIFFSwabArrayOfShort(), and TIFFWarningExtR().

Referenced by _TIFFCheckPostDecodeLength(), and _TIFFVSetField().

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

◆ _TIFFSwab24BitData()

void _TIFFSwab24BitData ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc 
)
extern

Swap each 3-byte sample in place.

Swaps complete samples and leaves any trailing partial sample unchanged. A byte count not divisible by 3 emits a warning through TIFFWarningExtR() in all builds, but does not prevent swapping the complete samples. Borrows/modifies bytes without allocation, I/O, or ownership transfer. It is an involution on complete samples, not general sample conversion.

Parameters
[in]tifLive handle used for warning dispatch; not modified.
[in,out]bufWritable storage of cc bytes with any alignment.
[in]ccNonnegative byte count; a multiple of 3 swaps all bytes.

Definition at line 2226 of file tif_read.c.

References TIFF_SSIZE_FORMAT, TIFFSwabArrayOfTriples(), and TIFFWarningExtR().

Referenced by _TIFFCheckPostDecodeLength(), and _TIFFVSetField().

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

◆ _TIFFSwab32BitData()

void _TIFFSwab32BitData ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc 
)
extern

Swap each 4-byte sample in place.

Swaps complete samples and leaves any trailing partial sample unchanged. A byte count not divisible by 4 emits a warning through TIFFWarningExtR() in all builds, but does not prevent swapping the complete samples. Borrows/modifies bytes without allocation, I/O, or ownership transfer. It is an involution on complete samples, not general sample conversion.

Parameters
[in]tifLive handle used for warning dispatch; not modified.
[in,out]bufWritable storage of cc bytes with alignment suitable for uint32_t.
[in]ccNonnegative byte count; a multiple of 4 swaps all bytes.

Definition at line 2236 of file tif_read.c.

References TIFF_SSIZE_FORMAT, TIFFSwabArrayOfLong(), and TIFFWarningExtR().

Referenced by _TIFFCheckPostDecodeLength(), and _TIFFVSetField().

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

◆ _TIFFSwab64BitData()

void _TIFFSwab64BitData ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc 
)
extern

Swap each 8-byte sample in place.

Swaps complete samples and leaves any trailing partial sample unchanged. A byte count not divisible by 8 emits a warning through TIFFWarningExtR() in all builds, but does not prevent swapping the complete samples. Borrows/modifies bytes without allocation, I/O, or ownership transfer. It is an involution on complete samples, not general sample conversion.

Parameters
[in]tifLive handle used for warning dispatch; not modified.
[in,out]bufWritable storage of cc bytes with alignment suitable for double.
[in]ccNonnegative byte count; a multiple of 8 swaps all bytes.

Definition at line 2246 of file tif_read.c.

References TIFF_SSIZE_FORMAT, TIFFSwabArrayOfDouble(), and TIFFWarningExtR().

Referenced by _TIFFCheckPostDecodeLength(), and _TIFFVSetField().

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

◆ NoSanitizeSubUInt64()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW uint64_t NoSanitizeSubUInt64 ( uint64_t  a,
uint64_t  b 
)
static

Subtract unsigned offsets with intentional modular arithmetic.

Pure modulo-2^64 subtraction, without overflow rejection, diagnostics, allocation, state, or ownership effects; unsigned-overflow instrumentation is disabled for this helper.

Parameters
[in]aUnsigned minuend.
[in]bUnsigned subtrahend.
Returns
Wrapped unsigned difference.

Definition at line 1027 of file tif_read.c.

Referenced by TIFFFillStrip().

Here is the caller graph for this function:

◆ TIFFAppendToStrip()

static int TIFFAppendToStrip ( TIFF *  tif,
uint32_t  strip,
uint8_t *  data,
tmsize_t  cc 
)
static

Append stored bytes or relocate a growing overwritten strile.

Validates current arrays/index, chooses existing reusable extent or EOF, resets counts when starting a write, and moves previously appended bytes to EOF if they outgrow a reused extent. Temporary copying storage is freed on ordinary exits. Checks classic-file wrap and reports I/O/allocation failures, but EOF seeks/metadata additions are not all checked. May modify earlier bytes and array offsets/counts before failure; no overlap proof, rollback, IFD persistence, or durability guarantee. Seeks, reads and writes through the client procedures and dispatches diagnostics; does not touch the raw buffer. No handle or caller-buffer ownership transfers. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]stripZero-based strip or tile index; NOSTRIP and values not below td_nstrips are diagnosed and rejected.
[in]dataBorrowed readable stored bytes; no alias with buffers that append/copy may replace.
[in]ccNonnegative byte extent with representable file-offset/count additions.
Returns
One after append, zero on detected metadata/extent/allocation/I/O failure; previous bytes and counts may have changed.

Definition at line 1021 of file tif_write.c.

References _TIFFfreeExt(), _TIFFmallocExt(), NOSTRIP, ReadOK, SeekOK, TIFFDirectory::td_row, tiff::tif_curoff, tiff::tif_dir, tiff::tif_flags, tiff::tif_lastvalidoff, TIFF_BIGTIFF, TIFF_DIRTYSTRIP, TIFFErrorExtR(), TIFFSeekFile, and WriteOK.

Referenced by TIFFFlushData1(), TIFFWriteEncodedStrip(), TIFFWriteEncodedTile(), TIFFWriteRawStrip(), and TIFFWriteRawTile().

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

◆ TIFFCheckRead()

static int TIFFCheckRead ( TIFF *  tif,
int  tiles 
)
static

Check readable mode and expected image organisation.

Checks O_WRONLY rejection and whether tiles matches isTiled(). If a scanline write is pending (TIFF_BUF4WRITE), finishes it with TIFFFlushData() before a read can resize the raw buffer the encoder still points into, then clears TIFF_BUF4WRITE and forgets the current strip and tile so the next read reloads its strile and runs predecode. Flushing can encode and write data; otherwise no allocation, pixel/codec validation, file I/O, or ownership transfer. Errors dispatch diagnostics.

Parameters
[in,out]tifNon-NULL live handle whose mode and organisation are read; serialise access externally.
[in]tilesExactly zero for strips or one for tiles.
Returns
One for compatible mode/organisation after any pending write is flushed; zero for incompatible mode/organisation or a failed flush.

Definition at line 2036 of file tif_read.c.

References isTiled, NOSTRIP, NOTILE, TIFFDirectory::td_curstrip, TIFFDirectory::td_curtile, tiff::tif_dir, tiff::tif_flags, tiff::tif_mode, tiff::tif_name, TIFF_BUF4WRITE, TIFFErrorExtR(), and TIFFFlushData().

Referenced by _TIFFReadEncodedTileAndAllocBuffer(), _TIFFReadTileAndAllocBuffer(), TIFFReadEncodedStripGetStripSize(), TIFFReadEncodedTile(), TIFFReadRawStrip(), TIFFReadRawTile(), TIFFReadScanline(), and TIFFReadTile().

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

◆ TIFFFillStrip()

int TIFFFillStrip ( TIFF *  tif,
uint32_t  strip 
)

Load raw strip bytes and initialise codec decoding.

Caller supplies valid strip metadata/index. Validates byte-count bounds, applies recovery size/ratio heuristics, uses mapped bytes when fill order allows or replaces/grows raw storage, reverses bits when needed, and calls TIFFStartStrip(). Non-raw codecs skip loading. Borrowed raw data can be detached but is not freed as owned storage. Mapping/cache/codec state can change on failure. May allocate or replace the handle-owned raw buffer, load deferred strile metadata, seek and read through the client procedures, and invoke codec and diagnostic callbacks; it never writes to the file. No handle or caller-buffer ownership transfers. Failure is not transactional: buffers, codec progress, indices, flags, or file position can already have changed. No errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]stripValid zero-based strip index; not range-checked here.
Returns
One after load/start, zero on detected byte-count, buffer, allocation, I/O, or codec failure.

Definition at line 1055 of file tif_read.c.

References _TIFFfreeExt(), isFillOrder, isMapped, NoSanitizeSubUInt64(), NOSTRIP, TIFFDirectory::td_curstrip, tiff::tif_base, tiff::tif_dir, tiff::tif_flags, tiff::tif_rawdata, tiff::tif_rawdataloaded, tiff::tif_rawdataoff, tiff::tif_rawdatasize, tiff::tif_size, TIFF_BUFFERMMAP, TIFF_INT64_MAX, TIFF_MYBUFFER, TIFF_NOBITREV, TIFF_NOREADRAW, TIFFErrorExtR(), TIFFGetMaxCompressionRatio(), TIFFGetStrileByteCount(), TIFFGetStrileOffset(), TIFFReadBufferSetup(), TIFFReadRawStrip1(), TIFFReadRawStripOrTile2(), TIFFReverseBits(), TIFFStartStrip(), TIFFStripSize(), and TIFFWarningExtR().

Referenced by _TIFFReadEncodedStripAndAllocBuffer(), TIFFFillStripPartial(), TIFFReadEncodedStrip(), and TIFFSeek().

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

◆ TIFFFillStripPartial()

static int TIFFFillStripPartial ( TIFF *  tif,
int  strip,
tmsize_t  read_ahead,
int  restart 
)
static

Refill a partial raw strip while retaining unconsumed bytes.

Requires a representable nonnegative int strip index, non-mapped raw buffer, valid read-ahead arithmetic, and coherent cursor/loaded counts. Moves unread bytes, grows owned storage, reads the next extent, optionally reverses bits, and restarts decoding when requested. A multi-scan JPEG restart can require a whole-strip fallback. Borrowed undersized buffers fail instead of growing. May grow the handle-owned raw buffer, load deferred strile metadata, seek and read through the client procedures, and invoke codec and diagnostic callbacks; it never writes to the file. Failure is not transactional: buffers, codec progress, indices, flags, or file position can already have changed. No errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]stripValid zero-based strip index; the parameter is int, so the index must be representable by int.
[in]read_aheadNonnegative desired ahead extent with representable cursor arithmetic.
[in]restartNonzero to reset partial-strip decoding; zero to retain unread bytes.
Returns
One after refill/start, zero on detected buffer/seek/read/start failure.

Definition at line 254 of file tif_read.c.

References COMPRESSION_JPEG, isFillOrder, NOSTRIP, SeekOK, TIFFDirectory::td_compression, TIFFDirectory::td_curstrip, 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_BUFFERMMAP, TIFF_MYBUFFER, TIFF_NOBITREV, TIFF_TMSIZE_T_MAX, TIFFErrorExtR(), TIFFFillStrip(), TIFFGetStrileByteCount(), TIFFGetStrileOffset(), TIFFJPEGIsFullStripRequired(), TIFFReadAndRealloc(), TIFFReverseBits(), and TIFFStartStrip().

Referenced by TIFFSeek().

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

◆ TIFFFillTile()

int TIFFFillTile ( TIFF *  tif,
uint32_t  tile 
)

Load raw tile bytes and initialise codec decoding.

Caller supplies valid tile metadata/index. Validates byte-count bounds, applies recovery size/ratio heuristics, uses mapped bytes when fill order allows or replaces/grows raw storage, reverses bits when needed, and calls TIFFStartTile(). Non-raw codecs skip loading. Cache/codec state can change before failure. May allocate or replace the handle-owned raw buffer, load deferred strile metadata, seek and read through the client procedures, and invoke codec and diagnostic callbacks; it never writes to the file. No handle or caller-buffer ownership transfers. Failure is not transactional: buffers, codec progress, indices, flags, or file position can already have changed. No errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]tileValid zero-based tile index; not range-checked here.
Returns
One after load/start, zero on detected byte-count, buffer, allocation, I/O, or codec failure.

Definition at line 1614 of file tif_read.c.

References _TIFFfreeExt(), isFillOrder, isMapped, NOTILE, TIFFDirectory::td_curtile, tiff::tif_base, tiff::tif_dir, tiff::tif_flags, tiff::tif_rawdata, tiff::tif_rawdataloaded, tiff::tif_rawdataoff, tiff::tif_rawdatasize, tiff::tif_size, TIFF_BUFFERMMAP, TIFF_INT64_MAX, TIFF_MYBUFFER, TIFF_NOBITREV, TIFF_NOREADRAW, TIFFErrorExtR(), TIFFGetMaxCompressionRatio(), TIFFGetStrileByteCount(), TIFFGetStrileOffset(), TIFFReadBufferSetup(), TIFFReadRawStripOrTile2(), TIFFReadRawTile1(), TIFFReverseBits(), TIFFStartTile(), TIFFTileSize(), and TIFFWarningExtR().

Referenced by _TIFFReadEncodedTileAndAllocBuffer(), and TIFFReadEncodedTile().

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

◆ TIFFFlushData1()

int TIFFFlushData1 ( TIFF *  tif)
extern

Append buffered encoded bytes without invoking postencode recursively.

When rawcc is positive and BUF4WRITE set, may reverse raw-buffer bits in place and append to current strip/tile. Resets rawcc/rawcp even after append failure, so failed flush loses pending-buffer retry state. Does not write the directory, close/free the handle, or finish codec postencoding. No output ownership transfers; diagnostics/file effects follow append. No rollback.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
Returns
One for successful append or no applicable buffered bytes, zero on detected append failure; buffer contents/cursor may already change.

Definition at line 1213 of file tif_write.c.

References isFillOrder, isTiled, TIFFDirectory::td_curstrip, TIFFDirectory::td_curtile, TIFFDirectory::td_fillorder, tiff::tif_dir, tiff::tif_flags, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdata, TIFF_BUF4WRITE, TIFF_NOBITREV, TIFFAppendToStrip(), and TIFFReverseBits().

Referenced by DumpModeEncode(), JBIGCopyEncodedData(), LERCPostEncode(), LogLuvReserve(), LZMAEncode(), LZMAPostEncode(), LZWEncode(), LZWPostEncode(), PackBitsEncode(), PixarLogEncode(), PixarLogPostEncode(), std_empty_output_buffer(), TIFFFlushData(), TIFFWriteDirectorySec(), TWebPPostEncode(), ZIPEncode(), ZIPPostEncode(), ZSTDEncode(), and ZSTDPostEncode().

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

◆ TIFFGrowStrips()

static int TIFFGrowStrips ( TIFF *  tif,
uint32_t  delta,
const char *  module 
)
static

Grow contiguous strip offset/count arrays by a requested delta.

Requires contiguous layout and representable nonnegative allocation products. Reallocates arrays separately, updates each pointer immediately, zeroes new slots and marks directory dirty on success. If either realloc fails, sets td_nstrips zero but retains the latest allocated pointers; old views can already be invalidated. Does not grow image height itself. No client I/O; diagnoses allocation failure. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]deltaNumber of slots to add; allocation products and new uint32_t count must be representable.
[in]moduleBorrowed diagnostic context string.
Returns
One on both reallocations, zero on failure with changed pointer/count state.

Definition at line 939 of file tif_write.c.

References _TIFFmemset(), _TIFFMultiplySSize(), _TIFFreallocExt(), PLANARCONFIG_CONTIG, TIFFDirectory::td_nstrips, TIFFDirectory::td_planarconfig, TIFFDirectory::td_stripbytecount_p, TIFFDirectory::td_stripoffset_p, tiff::tif_dir, tiff::tif_flags, TIFF_BIGTIFF, TIFF_DIRTYDIRECT, and TIFFErrorExtR().

Referenced by TIFFWriteEncodedStrip(), TIFFWriteRawStrip(), and TIFFWriteScanline().

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

◆ TIFFReadAndRealloc()

static int TIFFReadAndRealloc ( TIFF *  tif,
tmsize_t  size,
tmsize_t  rawdata_offset,
int  is_strip,
uint32_t  strip_or_tile,
const char *  module 
)
static

Grow and fill the raw buffer from the current client position.

Reads from the current client position, which the caller has already set; this function does not seek. Requires nonnegative representable size/offset, and a library-owned raw buffer (TIFF_MYBUFFER) if it must grow. On 64-bit hosts the buffer grows in progressive 1/10/100 MiB read stages; the cutoff is not a maximum read size. On 32-bit hosts, requests above 1e9 bytes that are not smaller than the file size are rejected. Realloc failure frees the old raw allocation and clears capacity; short/error reads zero the remaining allocated tail but retain partial data. tif_rawcp is not updated and can point into freed storage after growth; callers must reset it. Failures report through TIFFErrorExtR(); no errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle whose raw buffer can be grown or freed; the client file position moves; serialise access externally.
[in]sizeNonnegative number of bytes to read at rawdata_offset; zero reads nothing and succeeds.
[in]rawdata_offsetNonnegative raw-buffer destination byte offset with representable sums.
[in]is_stripNonzero for strip wording in diagnostics, zero for tile wording.
[in]strip_or_tileStrile index, used only in diagnostics.
[in]moduleBorrowed diagnostic context string.
Returns
One after all bytes read, zero on size/allocation/short-read failure.

Definition at line 116 of file tif_read.c.

References _TIFFfreeExt(), _TIFFreallocExt(), INITIAL_THRESHOLD, MAX_THRESHOLD, TIFFDirectory::td_col, TIFFDirectory::td_row, THRESHOLD_MULTIPLIER, tiff::tif_dir, tiff::tif_flags, tiff::tif_rawdata, tiff::tif_rawdatasize, TIFF_MYBUFFER, TIFF_SSIZE_FORMAT, TIFFErrorExtR(), TIFFGetFileSize, TIFFReadFile, and TIFFroundup_64.

Referenced by TIFFFillStripPartial(), and TIFFReadRawStripOrTile2().

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

◆ TIFFReadEncodedStripGetStripSize()

static tmsize_t TIFFReadEncodedStripGetStripSize ( TIFF *  tif,
uint32_t  strip,
uint16_t *  pplane 
)
static

Validate a strip and compute its effective decoded extent.

Checks readable strip organisation/index and nonzero row geometry, computes truncated last-strip rows and optional plane, and calls the layout calculator. Does not load/decode pixels or acquire output storage; diagnostics can occur.

Parameters
[in]tifNon-NULL live handle whose mode, organisation and geometry are read; serialise access externally.
[in]stripZero-based strip index; values not below td_nstrips are diagnosed and rejected.
[out]pplaneOptional plane-number output; written once the strip index and RowsPerStrip checks pass, before the size computation, so it can be set even when -1 is returned.
Returns
Positive effective decoded byte size, or minus one on rejected state/geometry.

Definition at line 662 of file tif_read.c.

References tiff::tif_dir, TIFFCheckRead(), TIFFErrorExtR(), TIFFhowmany_32_maxuint_compat, and TIFFVStripSize().

Referenced by _TIFFReadEncodedStripAndAllocBuffer(), and TIFFReadEncodedStrip().

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

◆ TIFFReadRawStrip1()

static tmsize_t TIFFReadRawStrip1 ( TIFF *  tif,
uint32_t  strip,
void *  buf,
tmsize_t  size,
const char *  module 
)
static

Read an exact raw-strip byte extent into caller storage.

Caller validates organisation/index/raw access and positive destination extent. Copies mapped bytes after range checks or seeks/reads exact client bytes. Does not bit-reverse/decode/own the destination; partial stream reads can modify it before failure. Loading the strile offset may read deferred metadata. Allocates nothing, never writes to the file, and leaves the raw buffer and codec state alone; a failed stream read can leave the file position moved. Failures report through TIFFErrorExtR(); no errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle; deferred strile offsets can be loaded and the client file position moves; serialise access externally.
[in]stripValid zero-based strip index; not range-checked here.
[out]bufBorrowed writable caller buffer large enough for size bytes.
[in]sizePositive number of raw bytes to copy into buf.
[in]moduleBorrowed diagnostic context string.
Returns
Requested size on complete copy, minus one on seek/range/short read.

Definition at line 853 of file tif_read.c.

References _TIFFmemcpy(), isMapped, SeekOK, TIFFDirectory::td_row, tiff::tif_base, tiff::tif_dir, tiff::tif_flags, tiff::tif_size, TIFF_NOREADRAW, TIFF_SSIZE_FORMAT, TIFF_TMSIZE_T_MAX, TIFFErrorExtR(), TIFFGetStrileOffset(), and TIFFReadFile.

Referenced by TIFFFillStrip(), TIFFReadEncodedStrip(), and TIFFReadRawStrip().

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

◆ TIFFReadRawStripOrTile2()

static tmsize_t TIFFReadRawStripOrTile2 ( TIFF *  tif,
uint32_t  strip_or_tile,
int  is_strip,
tmsize_t  size,
const char *  module 
)
static

Seek to a strile and read bytes into the expandable raw cache.

Requires non-mapped raw access and valid metadata/index. Delegates allocation/read to TIFFReadAndRealloc(); old owned cache can be lost on failure. Moves file position and reports contextual strip/tile failures. Loading the strile offset may read deferred metadata. Never writes to the file and invokes no codec callbacks; tif_rawcp is not updated. No errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle whose raw buffer can be grown or freed, deferred strile offsets loaded and file position moved; serialise access externally.
[in]strip_or_tileValid strile index whose offset is sought to; not range-checked here.
[in]is_stripNonzero for strip wording in diagnostics, zero for tile wording.
[in]sizeNonnegative number of raw bytes to read into the raw buffer from its start.
[in]moduleBorrowed diagnostic context string.
Returns
Requested size on success, minus one on seek/allocation/read failure.

Definition at line 938 of file tif_read.c.

References isMapped, SeekOK, TIFFDirectory::td_col, TIFFDirectory::td_row, tiff::tif_dir, tiff::tif_flags, TIFF_NOREADRAW, TIFFErrorExtR(), TIFFGetStrileOffset(), and TIFFReadAndRealloc().

Referenced by TIFFFillStrip(), and TIFFFillTile().

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

◆ TIFFReadRawTile1()

static tmsize_t TIFFReadRawTile1 ( TIFF *  tif,
uint32_t  tile,
void *  buf,
tmsize_t  size,
const char *  module 
)
static

Read an exact raw-tile byte extent into caller storage.

Caller validates organisation/index/raw access and positive destination extent. Copies mapped bytes after range checks or seeks/reads exact client bytes. Does not bit-reverse/decode/own the destination; partial stream reads can modify it before failure. Loading the strile offset may read deferred metadata. Allocates nothing, never writes to the file, and leaves the raw buffer and codec state alone; a failed stream read can leave the file position moved. Failures report through TIFFErrorExtR(); no errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle; deferred strile offsets can be loaded and the client file position moves; serialise access externally.
[in]tileValid zero-based tile index; not range-checked here.
[out]bufBorrowed writable caller buffer large enough for size bytes.
[in]sizePositive number of raw bytes to copy into buf.
[in]moduleBorrowed diagnostic context string.
Returns
Requested size on complete copy, minus one on seek/range/short read.

Definition at line 1483 of file tif_read.c.

References _TIFFmemcpy(), isMapped, SeekOK, TIFFDirectory::td_col, TIFFDirectory::td_row, tiff::tif_base, tiff::tif_dir, tiff::tif_flags, tiff::tif_size, TIFF_NOREADRAW, TIFF_SSIZE_FORMAT, TIFF_TMSIZE_T_MAX, TIFFErrorExtR(), TIFFGetStrileOffset(), and TIFFReadFile.

Referenced by TIFFFillTile(), TIFFReadEncodedTile(), and TIFFReadRawTile().

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

◆ TIFFSeek()

static int TIFFSeek ( TIFF *  tif,
uint32_t  row,
uint16_t  sample 
)
static

Position strip decoding at a requested scanline.

Validates row, RowsPerStrip and separate sample, computes strip, fills whole/partial raw input, restarts for backward access, and uses the codec seek callback to skip forward. Backward/random access may be unsupported by the codec. May grow or replace the handle-owned raw buffer, load deferred strile metadata, seek and read through the client procedures, and invoke codec and diagnostic callbacks; it never writes to the file. Failure is not transactional: buffers, codec progress, indices, flags, or file position can already have changed. No errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]rowRequested row; values not below ImageLength are diagnosed and rejected.
[in]sampleSample plane for separate planar images (range-checked against SamplesPerPixel); ignored where contiguous.
Returns
One on positioned decode state, zero on detected bounds/fill/start/codec-seek failure.

Definition at line 439 of file tif_read.c.

References _TIFFAdd64(), _TIFFCastUInt64ToUInt32(), _TIFFMultiply64(), COMPRESSION_JBIG, COMPRESSION_LERC, isMapped, PLANARCONFIG_SEPARATE, TIFFDirectory::td_compression, TIFFDirectory::td_curstrip, TIFFDirectory::td_imagelength, TIFFDirectory::td_planarconfig, TIFFDirectory::td_row, TIFFDirectory::td_rowsperstrip, TIFFDirectory::td_samplesperpixel, TIFFDirectory::td_scanlinesize, TIFFDirectory::td_stripsperimage, tiff::tif_dir, tiff::tif_name, tiff::tif_rawcp, tiff::tif_rawdata, tiff::tif_rawdataloaded, tiff::tif_rawdataoff, tiff::tif_seek, TIFF_TMSIZE_T_MAX, TIFFErrorExtR(), TIFFFillStrip(), TIFFFillStripPartial(), TIFFGetStrileByteCount(), and TIFFStartStrip().

Referenced by TIFFReadScanline().

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

◆ TIFFStartStrip()

static int TIFFStartStrip ( TIFF *  tif,
uint32_t  strip 
)
static

Prepare the codec and raw cursor for strip decoding.

Runs setupdecode once, validates strips-per-plane, sets current strip/row and raw input state, then calls predecode for its plane. Predecode failure invalidates current strip; other setup/state changes survive. Reads no strip payload and allocates no raw buffer itself; when no data is loaded, the raw byte count comes from TIFFGetStrileByteCount(), which may load deferred metadata. The setupdecode and predecode callbacks can allocate codec state, and some codecs (OJPEG) seek and read the file there. No errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]stripValid zero-based strip index; not range-checked here.
Returns
One on successful predecode, zero on detected setup/geometry/predecode failure.

Definition at line 1886 of file tif_read.c.

References NOSTRIP, TIFFDirectory::td_curstrip, TIFFDirectory::td_row, tiff::tif_dir, tiff::tif_flags, tiff::tif_predecode, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdata, tiff::tif_rawdataloaded, tiff::tif_setupdecode, TIFF_CODERSETUP, TIFF_NOREADRAW, TIFFErrorExtR(), TIFFGetStrileByteCount(), and TIFFSafeModMul32.

Referenced by TIFFFillStrip(), TIFFFillStripPartial(), TIFFReadFromUserBuffer(), and TIFFSeek().

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

◆ TIFFStartTile()

static int TIFFStartTile ( TIFF *  tif,
uint32_t  tile 
)
static

Prepare the codec and raw cursor for tile decoding.

Runs setupdecode once, sets current tile and row/column caches using tile geometry, selects raw input, and invokes predecode. Requires nonzero strips-per-plane and valid index from the caller. Unlike strip start, predecode failure does not explicitly invalidate the current tile. Reads no tile payload and allocates no raw buffer itself; when no data is loaded, the raw byte count comes from TIFFGetStrileByteCount(), which may load deferred metadata. The setupdecode and predecode callbacks can allocate codec state, and some codecs (OJPEG) seek and read the file there. State is not rolled back; no errno contract. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]tileValid zero-based tile index; not range-checked here.
Returns
Predecode callback status, or zero for detected setup/geometry failure.

Definition at line 1959 of file tif_read.c.

References TIFFDirectory::td_col, TIFFDirectory::td_curtile, TIFFDirectory::td_row, tiff::tif_dir, tiff::tif_flags, tiff::tif_predecode, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdata, tiff::tif_rawdataloaded, tiff::tif_setupdecode, TIFF_CODERSETUP, TIFF_NOREADRAW, TIFFErrorExtR(), TIFFGetStrileByteCount(), TIFFhowmany_32, and TIFFSafeModMul32.

Referenced by TIFFFillTile(), and TIFFReadFromUserBuffer().

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