|
LibTIFF 4.7.2
TIFF library public API and implementation reference
|
Implement predictor-aware ZSTD frame streaming. More...
Data Structures | |
| struct | ZSTDState |
| Own ZSTD streams predictor prefix and output cursor. More... | |
Macros | |
| #define | LSTATE_INIT_DECODE 0x01 |
| Bit 0x01 of the codec state field: decoding has been set up. | |
| #define | LSTATE_INIT_ENCODE 0x02 |
| Bit 0x02 of the codec state field: encoding has been set up. | |
| #define | GetZSTDState(tif) ((ZSTDState *)(tif)->tif_data) |
| Cast tif->tif_data to the ZSTDState. | |
| #define | ZSTDDecoderState(tif) GetZSTDState(tif) |
| Alias of GetZSTDState(), returning the ZSTDState for decoding. | |
| #define | ZSTDEncoderState(tif) GetZSTDState(tif) |
| Alias of GetZSTDState(), returning the ZSTDState for encoding. | |
Functions | |
| static int | ZSTDFixupTags (TIFF *tif) |
| Accept ZSTD tag fixup without changes. | |
| static int | ZSTDSetupDecode (TIFF *tif) |
| Switch ZSTD state into decode mode. | |
| static int | ZSTDPreDecode (TIFF *tif, uint16_t s) |
| Create or reset the ZSTD decompression stream for a strile. | |
| static int | ZSTDDecode (TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s) |
| Decompress cached ZSTD input into caller output. | |
| static int | ZSTDSetupEncode (TIFF *tif) |
| Switch ZSTD state into encode mode. | |
| static int | ZSTDPreEncode (TIFF *tif, uint16_t s) |
| Create and initialise a ZSTD compression stream for a strile. | |
| static int | ZSTDEncode (TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s) |
| Compress input through the active ZSTD stream. | |
| static int | ZSTDPostEncode (TIFF *tif) |
| Finish the ZSTD frame and flush its remaining output. | |
| static void | ZSTDCleanup (TIFF *tif) |
| Release ZSTD streams state and chained codec methods. | |
| static int | ZSTDVSetField (TIFF *tif, uint32_t tag, va_list ap) |
| Store ZSTD compression level or delegate another tag assignment. | |
| static int | ZSTDVGetField (TIFF *tif, uint32_t tag, va_list ap) |
| Retrieve ZSTD compression level or delegate another tag query. | |
| static uint64_t | ZSTDGetMaxCompressionRatio (TIFF *tif) |
| Report the ZSTD expansion allocation heuristic. | |
| int | TIFFInitZSTD (TIFF *tif, int scheme) |
| Allocate ZSTD state and install predictor-aware streaming methods. | |
Variables | |
| static const TIFFField | ZSTDFields [] |
| Define the ZSTD compression-level pseudo-tag. | |
Implement predictor-aware ZSTD frame streaming.
| #define GetZSTDState | ( | tif | ) | ((ZSTDState *)(tif)->tif_data) |
Cast tif->tif_data to the ZSTDState.
tif is evaluated once. Requires the codec to be initialised (tif_data non-NULL).
| [in] | tif | Handle whose codec state is returned. |
Definition at line 89 of file tif_zstd.c.
| #define LSTATE_INIT_DECODE 0x01 |
Bit 0x01 of the codec state field: decoding has been set up.
Set by ZSTDSetupDecode(). Each setup first tears down the other mode, if active, and clears the field.
Definition at line 80 of file tif_zstd.c.
| #define LSTATE_INIT_ENCODE 0x02 |
Bit 0x02 of the codec state field: encoding has been set up.
Set by ZSTDSetupEncode(). Each setup first tears down the other mode, if active, and clears the field.
Definition at line 81 of file tif_zstd.c.
| #define ZSTDDecoderState | ( | tif | ) | GetZSTDState(tif) |
Alias of GetZSTDState(), returning the ZSTDState for decoding.
tif is evaluated once. Requires the codec to be initialised.
| [in] | tif | Handle whose codec state is returned. |
Definition at line 90 of file tif_zstd.c.
| #define ZSTDEncoderState | ( | tif | ) | GetZSTDState(tif) |
Alias of GetZSTDState(), returning the ZSTDState for encoding.
tif is evaluated once. Requires the codec to be initialised.
| [in] | tif | Handle whose codec state is returned. |
Definition at line 91 of file tif_zstd.c.
|
extern |
Allocate ZSTD state and install predictor-aware streaming methods.
Requires cleaned-up previous codec state and COMPRESSION_ZSTD. Merges pseudo-tag metadata, allocates handle-owned state, saves tag hooks, defaults level to nine, and installs stream/cleanup methods. Attempts PredictorInit without propagating its status. Field/allocation failure diagnoses; merged metadata or other changes are not rolled back. Dependency streams are created lazily. No pixel I/O.
| [in,out] | tif | Non-NULL handle whose previous codec state has been cleaned up; receives the new codec state. Serialise operations. |
| [in] | scheme | COMPRESSION_ZSTD, asserted in debug builds. |
Definition at line 603 of file tif_zstd.c.
References _TIFFmallocExt(), _TIFFMergeFields(), COMPRESSION_ZSTD, GetZSTDState, tiff::tif_cleanup, tiff::tif_data, tiff::tif_decoderow, tiff::tif_decodestrip, tiff::tif_decodetile, tiff::tif_encoderow, tiff::tif_encodestrip, tiff::tif_encodetile, tiff::tif_fixuptags, tiff::tif_getmaxcompressionratio, tiff::tif_postencode, tiff::tif_predecode, tiff::tif_preencode, tiff::tif_setupdecode, tiff::tif_setupencode, tiff::tif_tagmethods, TIFFArrayCount, TIFFErrorExtR(), TIFFPredictorInit(), TIFFTagMethods::vgetfield, TIFFTagMethods::vsetfield, ZSTDCleanup(), ZSTDDecode(), ZSTDEncode(), ZSTDFields, ZSTDFixupTags(), ZSTDGetMaxCompressionRatio(), ZSTDPostEncode(), ZSTDPreDecode(), ZSTDPreEncode(), ZSTDSetupDecode(), ZSTDSetupEncode(), ZSTDVGetField(), and ZSTDVSetField().
|
static |
Release ZSTD streams state and chained codec methods.
Restores predictor and saved tag hooks, frees dependency streams with their matching ZSTD free functions, frees outer Ext state, clears tif_data and installs default callbacks. Invalidates state/stream views. Does not finish frames, flush payload, close the handle or return a status.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
Definition at line 475 of file tif_zstd.c.
References _TIFFfreeExt(), _TIFFSetDefaultCompressionState(), ZSTDState::cstream, ZSTDState::dstream, GetZSTDState, tiff::tif_data, tiff::tif_tagmethods, TIFFPredictorCleanup(), TIFFTagMethods::vgetfield, ZSTDState::vgetparent, TIFFTagMethods::vsetfield, and ZSTDState::vsetparent.
Referenced by TIFFInitZSTD().
Decompress cached ZSTD input into caller output.
Requires decode mode and initialised DStream. Repeatedly decompresses until output fills, frame ends or input exhausts. On dependency error or short output zeroes the unfilled tail and diagnoses, without committing local raw cursor consumption; stream/output may already change. On success advances rawcp and reduces rawcc. Does not require consuming a complete frame when the requested output fills. No allocation owned by caller, client I/O or ownership transfer.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
| [out] | op | Borrowed writable occ-byte decoded output, disjoint from raw input/state. |
| [in] | occ | Nonnegative decoded byte extent representable by size_t. |
| [in] | s | Unused sample-plane argument. |
Definition at line 212 of file tif_zstd.c.
References LSTATE_INIT_DECODE, TIFFDirectory::td_row, tiff::tif_dir, tiff::tif_rawcc, tiff::tif_rawcp, TIFFErrorExtR(), and ZSTDDecoderState.
Referenced by TIFFInitZSTD().
Compress input through the active ZSTD stream.
Requires successful preencode and live positive-capacity raw storage; a state not initialised for encoding is diagnosed and rejected. Consumes borrowed input synchronously, flushing full output buffers via TIFFFlushData1. Dependency/flush failures diagnose where applicable and leave partial stream, cache and file progress. Input bytes are not changed; no ownership transfer or rollback.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
| [in] | bp | Borrowed readable cc-byte input, not retained or modified. |
| [in] | cc | Nonnegative input byte extent representable by size_t. |
| [in] | s | Unused sample-plane argument. |
Definition at line 366 of file tif_zstd.c.
References LSTATE_INIT_ENCODE, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdatasize, TIFFErrorExtR(), TIFFFlushData1(), and ZSTDEncoderState.
Referenced by TIFFInitZSTD().
|
static |
Accept ZSTD tag fixup without changes.
No allocation, I/O, diagnostics, state or ownership effects.
| [in] | tif | Unused handle. |
Definition at line 105 of file tif_zstd.c.
Referenced by TIFFInitZSTD().
|
static |
Report the ZSTD expansion allocation heuristic.
Returns a fixed estimate without handle inspection, I/O, diagnostics, allocation or state changes; not a universal bound.
| [in] | tif | Unused handle. |
Definition at line 595 of file tif_zstd.c.
Referenced by TIFFInitZSTD().
|
static |
Finish the ZSTD frame and flush its remaining output.
Repeatedly ends the active stream and flushes produced bytes. Dependency or I/O failure can leave an incomplete frame and changed state/file bytes. Requires successful preencode and valid raw capacity; a state not initialised for encoding is diagnosed and rejected. Does not write the IFD or promise durability; no ownership transfer.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
Definition at line 428 of file tif_zstd.c.
References LSTATE_INIT_ENCODE, tiff::tif_rawcc, tiff::tif_rawcp, TIFFErrorExtR(), TIFFFlushData1(), and ZSTDEncoderState.
Referenced by TIFFInitZSTD().
|
static |
Create or reset the ZSTD decompression stream for a strile.
Ensures decode setup, lazily creates a dependency-owned DStream and resets it. Stream remains codec-owned for cleanup even after init failure. Diagnoses dependency allocation/init errors; no pixel reads or caller storage ownership transfer.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
| [in] | s | Unused sample-plane argument. |
Definition at line 158 of file tif_zstd.c.
References LSTATE_INIT_DECODE, tiff::tif_setupdecode, TIFFErrorExtR(), and ZSTDDecoderState.
Referenced by TIFFInitZSTD().
|
static |
Create and initialise a ZSTD compression stream for a strile.
Ensures encode mode, lazily creates CStream, initialises it at the cached compression level and attaches the raw output buffer. Requires positive usable raw capacity. Dependency stream remains codec-owned on later failure; diagnoses dependency allocation/init errors. No payload flush or input ownership transfer.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
| [in] | s | Unused sample-plane argument. |
Definition at line 308 of file tif_zstd.c.
References LSTATE_INIT_ENCODE, tiff::tif_rawdata, tiff::tif_rawdatasize, tiff::tif_setupencode, TIFFErrorExtR(), and ZSTDEncoderState.
Referenced by TIFFInitZSTD().
|
static |
Switch ZSTD state into decode mode.
Frees any previous compression stream and clears its pointer, then sets decode flags. Invalidates compression-stream views; no raw/pixel I/O, diagnostics or output allocation. Requires initialised state.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
Definition at line 123 of file tif_zstd.c.
References ZSTDState::cstream, LSTATE_INIT_DECODE, LSTATE_INIT_ENCODE, ZSTDState::state, and ZSTDDecoderState.
Referenced by TIFFInitZSTD().
|
static |
Switch ZSTD state into encode mode.
Frees any previous decompression stream and clears its pointer, then sets encode flags. No pixel I/O or caller-owned output allocation; dependency views are invalidated.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
Definition at line 273 of file tif_zstd.c.
References ZSTDState::dstream, LSTATE_INIT_DECODE, LSTATE_INIT_ENCODE, ZSTDState::state, and ZSTDEncoderState.
Referenced by TIFFInitZSTD().
|
static |
Retrieve ZSTD compression level or delegate another tag query.
TIFFTAG_ZSTD_LEVEL consumes a non-NULL int* and writes the cached level. Other tags follow parent variadic contracts. No allocation or ownership transfer for the level.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
| [in] | tag | Pseudo-tag or delegated tag identifier. |
| [in,out] | ap | Live tag-specific va_list consumed synchronously; not retained. |
Definition at line 558 of file tif_zstd.c.
References ZSTDState::compression_level, GetZSTDState, TIFFTAG_ZSTD_LEVEL, and ZSTDState::vgetparent.
Referenced by TIFFInitZSTD().
|
static |
Store ZSTD compression level or delegate another tag assignment.
TIFFTAG_ZSTD_LEVEL consumes int, stores it even outside 1..ZSTD_maxCLevel(), warns for that range and returns success. Stream reinitialisation applies it later. Other tags follow parent variadic contracts; no ownership transfer for the level. Callbacks/diagnostics can mutate state.
| [in,out] | tif | Non-NULL live ZSTD handle with valid predictor-prefixed state; serialise operations. |
| [in] | tag | Pseudo-tag or delegated tag identifier. |
| [in,out] | ap | Live tag-specific va_list consumed synchronously; not retained. |
Definition at line 520 of file tif_zstd.c.
References GetZSTDState, TIFFTAG_ZSTD_LEVEL, and TIFFWarningExtR().
Referenced by TIFFInitZSTD().
|
static |
Define the ZSTD compression-level pseudo-tag.
Immutable library-lifetime metadata merged into a handle; no caller ownership transfer.
Definition at line 580 of file tif_zstd.c.
Referenced by TIFFInitZSTD().