LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions | Variables

Chain codec methods and transform predicted rows. More...

Collaboration diagram for Predictor transforms:

Data Structures

struct  TIFFPredictorState
 Prefix codec state with Predictor method chains and row geometry. More...
 

Macros

#define PredictorState(tif)   ((TIFFPredictorState *)(tif)->tif_data)
 Borrow the predictor prefix of codec-owned tif_data.
 
#define REPEAT4(n, op)
 Repeat a statement using an unrolled small-count switch.
 
#define OP
 Accumulate the next byte in the floating-point fast path.
 
#define FIELD_PREDICTOR   (FIELD_CODEC + 0) /* XXX */
 Reserve the codec field bit for Predictor.
 

Typedefs

typedef int(* TIFFEncodeDecodeMethod) (TIFF *tif, uint8_t *buf, tmsize_t size)
 Transform one decoded row in place for a Predictor wrapper.
 

Functions

static int PredictorSetup (TIFF *tif)
 Validate predictor format and cache stride and row extent.
 
static int PredictorSetupDecode (TIFF *tif)
 Chain parent decoder setup and install predictor decoding.
 
static int PredictorSetupEncode (TIFF *tif)
 Chain parent encoder setup and install predictor encoding.
 
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void PredictorAccumulate16NativeUnaligned (uint8_t *current, const uint8_t *previous)
 Add two unaligned native-order 16-bit samples modulo their width.
 
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void PredictorAccumulate32NativeUnaligned (uint8_t *current, const uint8_t *previous)
 Add two unaligned native-order 32-bit samples modulo their width.
 
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void PredictorAccumulate64NativeUnaligned (uint8_t *current, const uint8_t *previous)
 Add two unaligned native-order 64-bit samples modulo their width.
 
static void PredictorSwabByteStream16 (uint8_t *cp, tmsize_t n)
 Reverse each 16-bit sample in an unaligned byte stream.
 
static void PredictorSwabByteStream32 (uint8_t *cp, tmsize_t n)
 Reverse each 32-bit sample in an unaligned byte stream.
 
static void PredictorSwabByteStream64 (uint8_t *cp, tmsize_t n)
 Reverse each 64-bit sample in an unaligned byte stream.
 
static int horAcc8 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Accumulate 8-bit horizontal predictor samples in place.
 
static int swabHorAcc16 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Swap and accumulate 16-bit horizontal predictor samples in place.
 
static int horAcc16 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Accumulate 16-bit horizontal predictor samples in place.
 
static int swabHorAcc32 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Swap and accumulate 32-bit horizontal predictor samples in place.
 
static int horAcc32 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Accumulate 32-bit horizontal predictor samples in place.
 
static int swabHorAcc64 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Swap and accumulate 64-bit horizontal predictor samples in place.
 
static int horAcc64 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Accumulate 64-bit horizontal predictor samples in place.
 
static int fpAcc (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Undo floating-point byte-plane prediction on one row.
 
static int PredictorDecodeRow (TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s)
 Decode one row then undo prediction in place.
 
static int PredictorDecodeTile (TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s)
 Decode a strile then undo prediction row by row.
 
static int horDiff8 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Difference 8-bit horizontal predictor samples in place.
 
static int horDiff16 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Difference 16-bit horizontal predictor samples in place.
 
static int swabHorDiff16 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Swap and difference 16-bit horizontal predictor samples in place.
 
static int horDiff32 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Difference 32-bit horizontal predictor samples in place.
 
static int swabHorDiff32 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Swap and difference 32-bit horizontal predictor samples in place.
 
static int horDiff64 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Difference 64-bit horizontal predictor samples in place.
 
static int swabHorDiff64 (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Swap and difference 64-bit horizontal predictor samples in place.
 
static int fpDiff (TIFF *tif, uint8_t *cp0, tmsize_t cc)
 Apply floating-point byte-plane prediction on one row.
 
static int PredictorEncodeRow (TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 Transform a temporary row copy then call the parent encoder.
 
static int PredictorEncodeTile (TIFF *tif, uint8_t *bp0, tmsize_t cc0, uint16_t s)
 Transform a temporary strile copy then call the parent encoder.
 
static int PredictorVSetField (TIFF *tif, uint32_t tag, va_list ap)
 Store Predictor or delegate another variadic tag assignment.
 
static int PredictorVGetField (TIFF *tif, uint32_t tag, va_list ap)
 Fetch Predictor or delegate another variadic tag query.
 
static void PredictorPrintDir (TIFF *tif, FILE *fd, long flags)
 Print predictor information then chain the parent printer.
 
int TIFFPredictorInit (TIFF *tif)
 Install Predictor tag and setup hooks around a codec.
 
int TIFFPredictorCleanup (TIFF *tif)
 Restore saved Predictor tag print and setup hooks.
 

Variables

static const TIFFField predictFields []
 Define the codec-owned Predictor field metadata.
 

Detailed Description

Chain codec methods and transform predicted rows.

Macro Definition Documentation

◆ FIELD_PREDICTOR

#define FIELD_PREDICTOR   (FIELD_CODEC + 0) /* XXX */

Reserve the codec field bit for Predictor.

Value FIELD_CODEC + 0, the first codec-private field bit. Used in predictFields, set by PredictorVSetField when Predictor is assigned, and tested by PredictorPrintDir.

Definition at line 1620 of file tif_predict.c.

◆ OP

#define OP
Value:
do \
{ \
cp[1] = (uint8_t)((cp[1] + cp[0]) & 0xff); \
++cp; \
} while (0)

Accumulate the next byte in the floating-point fast path.

Local to the stride-1 path of fpAcc: adds the byte at cp[0] to cp[1] modulo 256 and advances the enclosing cp by one. Undefined again after that loop.

◆ PredictorState

#define PredictorState (   tif)    ((TIFFPredictorState *)(tif)->tif_data)

Borrow the predictor prefix of codec-owned tif_data.

Expands to a cast of tif->tif_data to TIFFPredictorState *, evaluating tif once. Valid only for codecs whose state struct begins with a TIFFPredictorState member and that have called TIFFPredictorInit; nothing is checked.

Parameters
[in]tifTIFF handle whose codec state is borrowed.

Definition at line 42 of file tif_predict.c.

◆ REPEAT4

#define REPEAT4 (   n,
  op 
)
Value:
switch (n) \
{ \
default: \
{ \
tmsize_t i; \
for (i = n - 4; i > 0; i--) \
{ \
op; \
} \
} /*-fallthrough*/ \
case 4: \
op; /*-fallthrough*/ \
case 3: \
op; /*-fallthrough*/ \
case 2: \
op; /*-fallthrough*/ \
case 1: \
op; /*-fallthrough*/ \
case 0:; \
}
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Definition tiffio.h:89

Repeat a statement using an unrolled small-count switch.

Expands to a switch on n whose cases fall through, so op runs n times for n from 0 to 4 and, through a loop in the default case, n times for larger n. A negative n reaches the default case and runs op four times. n is evaluated twice. The default case declares a block-local tmsize_t i, so op must not refer to an outer i.

Parameters
[in]nRepeat count, normally the stride; evaluated twice.
[in]opStatement to repeat.

Definition at line 389 of file tif_predict.c.

Typedef Documentation

◆ TIFFEncodeDecodeMethod

typedef int(* TIFFEncodeDecodeMethod) (TIFF *tif, uint8_t *buf, tmsize_t size)

Transform one decoded row in place for a Predictor wrapper.

Called synchronously with a selected integer or floating-point transform. Borrows storage and handle; no returned ownership. Integer transforms generally diagnose divisibility errors without allocation; floating transforms allocate temporary storage. Buffer can change before failure; callers must honour the transform-specific alignment/extent requirements.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
[in,out]bufBorrowed writable complete row in the transform-specific byte/sample order.
[in]sizePositive complete row byte count satisfying stride/sample-size divisibility.
Returns
One on transformation, zero on detected extent/allocation failure.

Definition at line 59 of file tif_predict.h.

Function Documentation

◆ fpAcc()

static int fpAcc ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Undo floating-point byte-plane prediction on one row.

Requires setup-selected nonzero bytes per sample and stride, a positive complete row extent divisible by their product, and sufficient writable storage. Accumulates byte planes then interlaces them into native sample order. Allocates a row-sized temporary buffer, released on success; rejected divisibility or allocation returns zero. Does not perform floating-point arithmetic on sample values. Buffer mutations survive later failure; no pixel I/O or ownership transfer.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
[in,out]cp0Borrowed writable row storage of cc bytes; cc must be positive, since a zero extent fails the temporary allocation.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on extent/allocation failure.

Definition at line 903 of file tif_predict.c.

References _TIFFfreeExt(), _TIFFmallocExt(), _TIFFmemcpy(), OP, PredictorState, REPEAT4, TIFFDirectory::td_bitspersample, tiff::tif_dir, and TIFFErrorExtR().

Referenced by PredictorSetupDecode().

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

◆ fpDiff()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW int fpDiff ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Apply floating-point byte-plane prediction on one row.

Requires setup-selected nonzero bytes per sample and stride, a positive complete row extent divisible by their product, and sufficient writable storage. Reorders native sample bytes into byte planes then differences those planes. Allocates a row-sized temporary buffer, released on success; rejected divisibility or allocation returns zero. Does not perform floating-point arithmetic on sample values. Buffer mutations survive later failure; no pixel I/O or ownership transfer.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
[in,out]cp0Borrowed writable row storage of cc bytes; cc must be positive, since a zero extent fails the temporary allocation.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on extent/allocation failure.

Definition at line 1449 of file tif_predict.c.

References _TIFFfreeExt(), _TIFFmallocExt(), _TIFFmemcpy(), PredictorState, REPEAT4, TIFFDirectory::td_bitspersample, tiff::tif_dir, and TIFFErrorExtR().

Referenced by PredictorSetupEncode().

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

◆ horAcc16()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW int horAcc16 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Accumulate 16-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 2*stride, with representable products and live writable storage. Uses unsigned modular arithmetic; first-pixel channel samples remain unchanged. Accumulation uses byte-stream/memcpy helpers and accepts unaligned storage. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 715 of file tif_predict.c.

References PredictorAccumulate16NativeUnaligned(), PredictorState, REPEAT4, and TIFFErrorExtR().

Referenced by PredictorSetupDecode(), and swabHorAcc16().

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

◆ horAcc32()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW int horAcc32 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Accumulate 32-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 4*stride, with representable products and live writable storage. Uses unsigned modular arithmetic; first-pixel channel samples remain unchanged. Accumulation uses byte-stream/memcpy helpers and accepts unaligned storage. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 785 of file tif_predict.c.

References PredictorAccumulate32NativeUnaligned(), PredictorState, REPEAT4, and TIFFErrorExtR().

Referenced by PredictorSetupDecode(), and swabHorAcc32().

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

◆ horAcc64()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW int horAcc64 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Accumulate 64-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 8*stride, with representable products and live writable storage. Uses unsigned modular arithmetic; first-pixel channel samples remain unchanged. Accumulation uses byte-stream/memcpy helpers and accepts unaligned storage. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 855 of file tif_predict.c.

References PredictorAccumulate64NativeUnaligned(), PredictorState, REPEAT4, and TIFFErrorExtR().

Referenced by PredictorSetupDecode(), and swabHorAcc64().

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

◆ horAcc8()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW int horAcc8 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Accumulate 8-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 1*stride, with representable products and live writable storage. Uses unsigned modular arithmetic; first-pixel channel samples remain unchanged. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 596 of file tif_predict.c.

References PredictorState, REPEAT4, and TIFFErrorExtR().

Referenced by PredictorSetupDecode().

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

◆ horDiff16()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW int horDiff16 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Difference 16-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 2*stride, with representable products and live writable storage. Uses unsigned modular arithmetic; first-pixel channel samples remain unchanged. Requires uint16_t alignment for typed differencing. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 1222 of file tif_predict.c.

References PredictorState, REPEAT4, TIFFPredictorState::stride, and TIFFErrorExtR().

Referenced by PredictorSetupEncode(), and swabHorDiff16().

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

◆ horDiff32()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW int horDiff32 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Difference 32-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 4*stride, with representable products and live writable storage. Uses unsigned modular arithmetic; first-pixel channel samples remain unchanged. Requires uint32_t alignment for typed differencing. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 1298 of file tif_predict.c.

References PredictorState, REPEAT4, TIFFPredictorState::stride, and TIFFErrorExtR().

Referenced by PredictorSetupEncode(), and swabHorDiff32().

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

◆ horDiff64()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW int horDiff64 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Difference 64-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 8*stride, with representable products and live writable storage. Uses unsigned modular arithmetic; first-pixel channel samples remain unchanged. Requires uint64_t alignment for typed differencing. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 1371 of file tif_predict.c.

References PredictorState, REPEAT4, TIFFPredictorState::stride, and TIFFErrorExtR().

Referenced by PredictorSetupEncode(), and swabHorDiff64().

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

◆ horDiff8()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW int horDiff8 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Difference 8-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 1*stride, with representable products and live writable storage. Uses unsigned modular arithmetic; first-pixel channel samples remain unchanged. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 1127 of file tif_predict.c.

References PredictorState, REPEAT4, TIFFPredictorState::stride, and TIFFErrorExtR().

Referenced by PredictorSetupEncode().

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

◆ PredictorAccumulate16NativeUnaligned()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void PredictorAccumulate16NativeUnaligned ( uint8_t *  current,
const uint8_t *  previous 
)
static

Add two unaligned native-order 16-bit samples modulo their width.

Uses fixed-size memcpy to load/store without typed alignment requirements. Reads previous before overwriting current, permitting identical slots. No bounds checks, allocation, I/O, diagnostics, handle changes or ownership effects.

Parameters
[in,out]currentWritable byte storage for one native-order sample, unaligned allowed.
[in]previousReadable byte storage for one same-width native-order sample, unaligned allowed.

Definition at line 440 of file tif_predict.c.

Referenced by horAcc16().

Here is the caller graph for this function:

◆ PredictorAccumulate32NativeUnaligned()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void PredictorAccumulate32NativeUnaligned ( uint8_t *  current,
const uint8_t *  previous 
)
static

Add two unaligned native-order 32-bit samples modulo their width.

Uses fixed-size memcpy to load/store without typed alignment requirements. Reads previous before overwriting current, permitting identical slots. No bounds checks, allocation, I/O, diagnostics, handle changes or ownership effects.

Parameters
[in,out]currentWritable byte storage for one native-order sample, unaligned allowed.
[in]previousReadable byte storage for one same-width native-order sample, unaligned allowed.

Definition at line 467 of file tif_predict.c.

Referenced by horAcc32().

Here is the caller graph for this function:

◆ PredictorAccumulate64NativeUnaligned()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW void PredictorAccumulate64NativeUnaligned ( uint8_t *  current,
const uint8_t *  previous 
)
static

Add two unaligned native-order 64-bit samples modulo their width.

Uses fixed-size memcpy to load/store without typed alignment requirements. Reads previous before overwriting current, permitting identical slots. No bounds checks, allocation, I/O, diagnostics, handle changes or ownership effects.

Parameters
[in,out]currentWritable byte storage for one native-order sample, unaligned allowed.
[in]previousReadable byte storage for one same-width native-order sample, unaligned allowed.

Definition at line 493 of file tif_predict.c.

Referenced by horAcc64().

Here is the caller graph for this function:

◆ PredictorDecodeRow()

static int PredictorDecodeRow ( TIFF *  tif,
uint8_t *  op0,
tmsize_t  occ0,
uint16_t  s 
)
static

Decode one row then undo prediction in place.

Requires installed parent decoder and transform. Parent callback consumes raw input and can allocate/diagnose; transform runs only on nonzero parent status. Caller retains output, which can be partial or changed on failure. No rollback or ownership transfer.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
[out]op0Caller-owned writable decoded output of occ0 bytes.
[in]occ0Nonnegative decoded byte extent, complete rows for strile wrappers.
[in]sSample plane passed unchanged to the parent codec.
Returns
Transform status after parent success, zero on parent failure.

Definition at line 1036 of file tif_predict.c.

References TIFFPredictorState::decodepfunc, TIFFPredictorState::decoderow, and PredictorState.

Referenced by PredictorSetupDecode().

Here is the caller graph for this function:

◆ PredictorDecodeTile()

static int PredictorDecodeTile ( TIFF *  tif,
uint8_t *  op0,
tmsize_t  occ0,
uint16_t  s 
)
static

Decode a strile then undo prediction row by row.

Calls saved decodetile for both strip and tile wrapping, then requires an extent divisible by positive rowsize. Invokes decodepfunc per row and stops on failure. Parent input progress and earlier output rows remain changed. No rollback or output ownership transfer; callbacks may allocate, diagnose and read client data.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
[out]op0Caller-owned writable decoded output of occ0 bytes.
[in]occ0Nonnegative decoded byte extent, complete rows for strile wrappers.
[in]sSample plane passed unchanged to the parent codec.
Returns
One after all rows, zero on parent, extent, or transform failure.

Definition at line 1078 of file tif_predict.c.

References TIFFPredictorState::decodepfunc, TIFFPredictorState::decodetile, PredictorState, TIFFPredictorState::rowsize, and TIFFErrorExtR().

Referenced by PredictorSetupDecode().

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

◆ PredictorEncodeRow()

static int PredictorEncodeRow ( TIFF *  tif,
uint8_t *  bp,
tmsize_t  cc,
uint16_t  s 
)
static

Transform a temporary row copy then call the parent encoder.

Allocates a working copy, preserves caller bytes from this predictor layer, checks transform status, invokes the parent encoder and frees temporary storage on each exit. Parent state/output effects remain on failure; public write postdecode conversion can separately mutate the original input. Reports allocation failure; no ownership transfer.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
[in]bpBorrowed readable row input of cc bytes, copied before prediction.
[in]ccRow byte extent under the selected transform preconditions.
[in]sSample plane passed unchanged to the parent codec.
Returns
Parent encoder status, or zero on allocation/transform failure.

Definition at line 1510 of file tif_predict.c.

References _TIFFfreeExt(), _TIFFmallocExt(), PredictorState, and TIFFErrorExtR().

Referenced by PredictorSetupEncode().

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

◆ PredictorEncodeTile()

static int PredictorEncodeTile ( TIFF *  tif,
uint8_t *  bp0,
tmsize_t  cc0,
uint16_t  s 
)
static

Transform a temporary strile copy then call the parent encoder.

Allocates/copies input and validates divisibility by positive rowsize. Transforms each row, failing without calling the parent if any encodepfunc transform fails, then calls saved encodetile for both strip and tile wrappers. Frees temporary storage on every ordinary exit. Caller bytes are preserved by this layer; parent state/output can change on failure. No ownership transfer.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
[in]bp0Borrowed readable strile input of cc0 bytes, copied before prediction.
[in]cc0Positive complete-row input byte extent.
[in]sSample plane passed unchanged to the parent codec.
Returns
Parent encoder status, or zero on allocation/extent rejection or a failed row transform.

Definition at line 1566 of file tif_predict.c.

References _TIFFfreeExt(), _TIFFmallocExt(), PredictorState, and TIFFErrorExtR().

Referenced by PredictorSetupEncode().

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

◆ PredictorPrintDir()

static void PredictorPrintDir ( TIFF *  tif,
FILE *  fd,
long  flags 
)
static

Print predictor information then chain the parent printer.

Writes to borrowed FILE without checking stdio errors, prints only when its field bit is set, then invokes saved printer with flags. Does not close the stream or transfer ownership; parent printer effects apply. No separate status channel.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState holds the predictor value and saved parent printer; not modified.
[in,out]fdBorrowed writable stdio stream; remains caller-owned.
[in]flagsPrint flags forwarded to the saved printer.

Definition at line 1721 of file tif_predict.c.

References FIELD_PREDICTOR, TIFFPredictorState::predictor, PredictorState, TIFFPredictorState::printdir, and TIFFFieldSet.

Referenced by TIFFPredictorInit().

Here is the caller graph for this function:

◆ PredictorSetup()

static int PredictorSetup ( TIFF *  tif)
static

Validate predictor format and cache stride and row extent.

Accepts no predictor, integer horizontal 8/16/32/64-bit samples, or floating-point 16/24/32/64-bit samples. Derives contiguous sample stride or separate stride one and a positive decoded row size. Diagnoses unsupported settings; no pixel I/O or owned result allocation. Cached state may change before failure.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
Returns
One for accepted setup, zero on unsupported predictor/format or zero row size.

Definition at line 83 of file tif_predict.c.

References _TIFFCastUInt64ToSSize(), _TIFFMultiply64(), isTiled, PLANARCONFIG_CONTIG, PREDICTOR_FLOATINGPOINT, PREDICTOR_HORIZONTAL, PREDICTOR_NONE, PredictorState, SAMPLEFORMAT_IEEEFP, TIFFDirectory::td_bitspersample, TIFFDirectory::td_planarconfig, TIFFDirectory::td_sampleformat, TIFFDirectory::td_samplesperpixel, TIFFDirectory::td_tilewidth, tiff::tif_dir, TIFFErrorExtR(), TIFFhowmany8_64, and TIFFScanlineSize().

Referenced by PredictorSetupDecode(), and PredictorSetupEncode().

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

◆ PredictorSetupDecode()

static int PredictorSetupDecode ( TIFF *  tif)
static

Chain parent decoder setup and install predictor decoding.

Invokes parent setup first without undoing its effects on later failure. Selects accumulation, wraps row/strile callbacks, and disables ordinary postdecode swapping where the predictor handles byte order. Requires fresh/non-recursive parent chains; may allocate through parent setup and diagnostics, but does not read pixels directly.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
Returns
One after setup, zero on parent or predictor validation failure.

Definition at line 177 of file tif_predict.c.

References _TIFFNoPostDecode(), TIFFPredictorState::decodepfunc, TIFFPredictorState::decoderow, TIFFPredictorState::decodestrip, TIFFPredictorState::decodetile, fpAcc(), horAcc16(), horAcc32(), horAcc64(), horAcc8(), TIFFPredictorState::predictor, PredictorDecodeRow(), PredictorDecodeTile(), PredictorSetup(), PredictorState, TIFFPredictorState::setupdecode, swabHorAcc16(), swabHorAcc32(), swabHorAcc64(), TIFFDirectory::td_bitspersample, tiff::tif_decoderow, tiff::tif_decodestrip, tiff::tif_decodetile, tiff::tif_dir, tiff::tif_flags, tiff::tif_postdecode, and TIFF_SWAB.

Referenced by TIFFPredictorInit().

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

◆ PredictorSetupEncode()

static int PredictorSetupEncode ( TIFF *  tif)
static

Chain parent encoder setup and install predictor encoding.

Invokes parent setup then validates predictor geometry and selects differencing/wrappers. Can disable ordinary postdecode swapping. Parent and wrapper changes survive failure; parent allocation/diagnostic effects apply. Does not write pixels directly.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
Returns
One after setup, zero on parent or predictor validation failure.

Definition at line 291 of file tif_predict.c.

References _TIFFNoPostDecode(), TIFFPredictorState::encodepfunc, TIFFPredictorState::encoderow, TIFFPredictorState::encodestrip, TIFFPredictorState::encodetile, fpDiff(), horDiff16(), horDiff32(), horDiff64(), horDiff8(), TIFFPredictorState::predictor, PredictorEncodeRow(), PredictorEncodeTile(), PredictorSetup(), PredictorState, TIFFPredictorState::setupencode, swabHorDiff16(), swabHorDiff32(), swabHorDiff64(), TIFFDirectory::td_bitspersample, tiff::tif_dir, tiff::tif_encoderow, tiff::tif_encodestrip, tiff::tif_encodetile, tiff::tif_flags, tiff::tif_postdecode, and TIFF_SWAB.

Referenced by TIFFPredictorInit().

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

◆ PredictorSwabByteStream16()

static void PredictorSwabByteStream16 ( uint8_t *  cp,
tmsize_t  n 
)
static

Reverse each 16-bit sample in an unaligned byte stream.

Swaps bytes directly; zero count performs no accesses. No bounds checks, allocation, I/O, diagnostics, or ownership effects.

Parameters
[in,out]cpWritable byte stream covering n complete samples.
[in]nNonnegative sample count.

Definition at line 514 of file tif_predict.c.

Referenced by swabHorAcc16().

Here is the caller graph for this function:

◆ PredictorSwabByteStream32()

static void PredictorSwabByteStream32 ( uint8_t *  cp,
tmsize_t  n 
)
static

Reverse each 32-bit sample in an unaligned byte stream.

Swaps bytes directly; zero count performs no accesses. No bounds checks, allocation, I/O, diagnostics, or ownership effects.

Parameters
[in,out]cpWritable byte stream covering n complete samples.
[in]nNonnegative sample count.

Definition at line 535 of file tif_predict.c.

Referenced by swabHorAcc32().

Here is the caller graph for this function:

◆ PredictorSwabByteStream64()

static void PredictorSwabByteStream64 ( uint8_t *  cp,
tmsize_t  n 
)
static

Reverse each 64-bit sample in an unaligned byte stream.

Swaps bytes directly; zero count performs no accesses. No bounds checks, allocation, I/O, diagnostics, or ownership effects.

Parameters
[in,out]cpWritable byte stream covering n complete samples.
[in]nNonnegative sample count.

Definition at line 559 of file tif_predict.c.

Referenced by swabHorAcc64().

Here is the caller graph for this function:

◆ PredictorVGetField()

static int PredictorVGetField ( TIFF *  tif,
uint32_t  tag,
va_list  ap 
)
static

Fetch Predictor or delegate another variadic tag query.

For TIFFTAG_PREDICTOR consumes a non-NULL uint16_t* and writes the cached value. Other tags follow the saved parent getter contract. No output allocation or ownership transfer for Predictor; parent effects depend on tag.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
[in]tagTag identifier; delegated tags follow their usual argument contract.
[in,out]apLive va_list cursor carrying the tag-specific promoted value/output pointer; consumed synchronously, not retained.
Returns
One for Predictor retrieval, otherwise parent getter status.

Definition at line 1689 of file tif_predict.c.

References TIFFPredictorState::predictor, PredictorState, TIFFTAG_PREDICTOR, and TIFFPredictorState::vgetparent.

Referenced by TIFFPredictorInit().

Here is the caller graph for this function:

◆ PredictorVSetField()

static int PredictorVSetField ( TIFF *  tif,
uint32_t  tag,
va_list  ap 
)
static

Store Predictor or delegate another variadic tag assignment.

For TIFFTAG_PREDICTOR consumes uint16_vap (normally promoted int), narrows to uint16_t, sets the field bit and directory dirty flag. Does not validate predictor support until setup. Other tags consume their usual variadic contract through saved vsetparent. Callbacks can mutate/allocate/diagnose; no ownership transfer for Predictor.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
[in]tagTag identifier; delegated tags follow their usual argument contract.
[in,out]apLive va_list cursor carrying the tag-specific promoted value/output pointer; consumed synchronously, not retained.
Returns
One for Predictor assignment, otherwise parent setter status.

Definition at line 1652 of file tif_predict.c.

References FIELD_PREDICTOR, TIFFPredictorState::predictor, PredictorState, tiff::tif_flags, TIFF_DIRTYDIRECT, TIFFSetFieldBit, TIFFTAG_PREDICTOR, and TIFFPredictorState::vsetparent.

Referenced by TIFFPredictorInit().

Here is the caller graph for this function:

◆ swabHorAcc16()

static int swabHorAcc16 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Swap and accumulate 16-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 2*stride, with representable products and live writable storage. Swaps complete samples before accumulation, even before the inner divisibility rejection; input can change on rejection. Accumulation uses byte-stream/memcpy helpers and accepts unaligned storage. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 689 of file tif_predict.c.

References horAcc16(), and PredictorSwabByteStream16().

Referenced by PredictorSetupDecode().

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

◆ swabHorAcc32()

static int swabHorAcc32 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Swap and accumulate 32-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 4*stride, with representable products and live writable storage. Swaps complete samples before accumulation, even before the inner divisibility rejection; input can change on rejection. Accumulation uses byte-stream/memcpy helpers and accepts unaligned storage. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 759 of file tif_predict.c.

References horAcc32(), and PredictorSwabByteStream32().

Referenced by PredictorSetupDecode().

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

◆ swabHorAcc64()

static int swabHorAcc64 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Swap and accumulate 64-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 8*stride, with representable products and live writable storage. Swaps complete samples before accumulation, even before the inner divisibility rejection; input can change on rejection. Accumulation uses byte-stream/memcpy helpers and accepts unaligned storage. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 829 of file tif_predict.c.

References horAcc64(), and PredictorSwabByteStream64().

Referenced by PredictorSetupDecode().

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

◆ swabHorDiff16()

static int swabHorDiff16 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Swap and difference 16-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 2*stride, with representable products and live writable storage. Differences native-order samples first, then swaps after success. Requires uint16_t alignment for typed differencing. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 1268 of file tif_predict.c.

References horDiff16(), and TIFFSwabArrayOfShort().

Referenced by PredictorSetupEncode().

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

◆ swabHorDiff32()

static int swabHorDiff32 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Swap and difference 32-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 4*stride, with representable products and live writable storage. Differences native-order samples first, then swaps after success. Requires uint32_t alignment for typed differencing. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 1341 of file tif_predict.c.

References horDiff32(), and TIFFSwabArrayOfLong().

Referenced by PredictorSetupEncode().

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

◆ swabHorDiff64()

static int swabHorDiff64 ( TIFF *  tif,
uint8_t *  cp0,
tmsize_t  cc 
)
static

Swap and difference 64-bit horizontal predictor samples in place.

Requires positive nonzero cached stride and nonnegative complete row bytes divisible by 8*stride, with representable products and live writable storage. Differences native-order samples first, then swaps after success. Requires uint64_t alignment for typed differencing. No allocation, pixel I/O, or ownership transfer; invalid extent is diagnosed through handle callbacks.

Parameters
[in]tifNon-NULL handle whose TIFFPredictorState supplies the cached stride; used otherwise only for diagnostics.
[in,out]cp0Borrowed writable row storage of cc bytes.
[in]ccRow byte extent under the selected transform preconditions.
Returns
One on transformation, zero on rejected row extent.

Definition at line 1414 of file tif_predict.c.

References horDiff64(), and TIFFSwabArrayOfLong8().

Referenced by PredictorSetupEncode().

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

◆ TIFFPredictorCleanup()

int TIFFPredictorCleanup ( TIFF *  tif)
extern

Restore saved Predictor tag print and setup hooks.

Requires initialised predictor state and still-valid saved callbacks. Restores tag get/set, printer and setup hooks; does not restore wrapped row/strile methods, postdecode swapping, or remove field definitions. Does not free tif_data, flush, allocate, or perform pixel I/O. The outer codec must complete teardown before state is released.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
Returns
One unconditionally.

Definition at line 1789 of file tif_predict.c.

References PredictorState, TIFFPredictorState::printdir, TIFFTagMethods::printdir, TIFFPredictorState::setupdecode, TIFFPredictorState::setupencode, tiff::tif_setupdecode, tiff::tif_setupencode, tiff::tif_tagmethods, TIFFTagMethods::vgetfield, TIFFPredictorState::vgetparent, TIFFTagMethods::vsetfield, and TIFFPredictorState::vsetparent.

Referenced by LZMACleanup(), LZWCleanup(), PixarLogCleanup(), ZIPCleanup(), and ZSTDCleanup().

Here is the caller graph for this function:

◆ TIFFPredictorInit()

int TIFFPredictorInit ( TIFF *  tif)
extern

Install Predictor tag and setup hooks around a codec.

Requires predictor state first in an existing codec-owned tif_data block and initialised parent methods. Merges field metadata, saves the parent tag get/set, print and setup-decode/encode methods and installs predictor wrappers for them, sets the predictor to one and clears the transform functions. The row/strip/tile decode and encode wrappers are installed later by the setup wrappers, only when a predictor is active. Must not be called repeatedly on active chains. Field merge failure is diagnosed; allocations/state changes are not transactional. Does not allocate the outer codec state or perform pixel I/O.

Parameters
[in,out]tifNon-NULL live handle whose tif_data begins with a valid TIFFPredictorState; serialise codec operations.
Returns
One after installation, zero on field-merge failure.

Definition at line 1749 of file tif_predict.c.

References _TIFFMergeFields(), TIFFPredictorState::decodepfunc, TIFFPredictorState::encodepfunc, predictFields, TIFFPredictorState::predictor, PredictorPrintDir(), PredictorSetupDecode(), PredictorSetupEncode(), PredictorState, PredictorVGetField(), PredictorVSetField(), TIFFPredictorState::printdir, TIFFTagMethods::printdir, TIFFPredictorState::setupdecode, TIFFPredictorState::setupencode, tiff::tif_setupdecode, tiff::tif_setupencode, tiff::tif_tagmethods, TIFFArrayCount, TIFFErrorExtR(), TIFFTagMethods::vgetfield, TIFFPredictorState::vgetparent, TIFFTagMethods::vsetfield, and TIFFPredictorState::vsetparent.

Referenced by LZWSetupDecode(), TIFFInitLZMA(), TIFFInitLZW(), TIFFInitPixarLog(), TIFFInitZIP(), and TIFFInitZSTD().

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

Variable Documentation

◆ predictFields

const TIFFField predictFields[]
static
Initial value:
= {
FIELD_PREDICTOR, FALSE, FALSE, "Predictor", NULL},
}
@ TIFF_SETGET_UINT16
Unsigned 16-bit scalar storage.
Definition tif_dir.h:744
#define FIELD_PREDICTOR
Reserve the codec field bit for Predictor.
#define FALSE
Represent the legacy internal false value.
Definition tiffiop.h:136
#define TIFFTAG_PREDICTOR
TIFF tag: Prediction scheme applied before compression.
Definition tiff.h:548
@ TIFF_SHORT
Unsigned 16-bit integer.
Definition tiff.h:237

Define the codec-owned Predictor field metadata.

Immutable library-lifetime table merged during initialisation; do not free it.

Definition at line 1629 of file tif_predict.c.

Referenced by TIFFPredictorInit().