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

Implement filtered LZMA2 stream compression. More...

Collaboration diagram for LZMA2 streaming codec:

Data Structures

struct  LZMAState
 Own a filtered liblzma stream and predictor-prefixed methods. 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 GetLZMAState(tif)   ((LZMAState *)(tif)->tif_data)
 Cast tif->tif_data to the LZMAState.
 
#define LZMADecoderState(tif)   GetLZMAState(tif)
 Alias of GetLZMAState(), returning the LZMAState for decoding.
 
#define LZMAEncoderState(tif)   GetLZMAState(tif)
 Alias of GetLZMAState(), returning the LZMAState for encoding.
 

Functions

static const char * LZMAStrerror (lzma_ret ret)
 Describe a liblzma status using immutable text.
 
static int LZMAFixupTags (TIFF *tif)
 Accept LZMA tag fixup without changes.
 
static int LZMASetupDecode (TIFF *tif)
 Switch the liblzma stream to decode mode.
 
static int LZMAPreDecode (TIFF *tif, uint16_t s)
 Initialise the liblzma decoder for one strile.
 
static int LZMADecode (TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 Expand cached liblzma input into caller output.
 
static int LZMASetupEncode (TIFF *tif)
 Switch the liblzma stream to encode mode.
 
static int LZMAPreEncode (TIFF *tif, uint16_t s)
 Initialise a filtered LZMA2 stream for one output strile.
 
static int LZMAEncode (TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 Consume input through the active liblzma encoder.
 
static int LZMAPostEncode (TIFF *tif)
 Finish the LZMA2 stream and flush produced output.
 
static void LZMACleanup (TIFF *tif)
 End the dependency stream and release LZMA codec state.
 
static int LZMAVSetField (TIFF *tif, uint32_t tag, va_list ap)
 Store LZMA preset or delegate a tag assignment.
 
static int LZMAVGetField (TIFF *tif, uint32_t tag, va_list ap)
 Retrieve LZMA preset or delegate a tag query.
 
static uint64_t LZMAGetMaxCompressionRatio (TIFF *tif)
 Report the empirical LZMA expansion heuristic.
 
int TIFFInitLZMA (TIFF *tif, int scheme)
 Allocate predictor-aware LZMA2 codec state and install callbacks.
 

Variables

static const TIFFField lzmaFields []
 Define the LZMA compression-preset pseudo-tag.
 

Detailed Description

Implement filtered LZMA2 stream compression.

Macro Definition Documentation

◆ GetLZMAState

#define GetLZMAState (   tif)    ((LZMAState *)(tif)->tif_data)

Cast tif->tif_data to the LZMAState.

tif is evaluated once. Requires the codec to be initialised (tif_data non-NULL).

Parameters
[in]tifHandle whose codec state is returned.

Definition at line 94 of file tif_lzma.c.

◆ LSTATE_INIT_DECODE

#define LSTATE_INIT_DECODE   0x01

Bit 0x01 of the codec state field: decoding has been set up.

Set by LZMASetupDecode(). Each setup first tears down the other mode, if active, and clears the field.

Definition at line 85 of file tif_lzma.c.

◆ LSTATE_INIT_ENCODE

#define LSTATE_INIT_ENCODE   0x02

Bit 0x02 of the codec state field: encoding has been set up.

Set by LZMASetupEncode(). Each setup first tears down the other mode, if active, and clears the field.

Definition at line 86 of file tif_lzma.c.

◆ LZMADecoderState

#define LZMADecoderState (   tif)    GetLZMAState(tif)

Alias of GetLZMAState(), returning the LZMAState for decoding.

tif is evaluated once. Requires the codec to be initialised.

Parameters
[in]tifHandle whose codec state is returned.

Definition at line 95 of file tif_lzma.c.

◆ LZMAEncoderState

#define LZMAEncoderState (   tif)    GetLZMAState(tif)

Alias of GetLZMAState(), returning the LZMAState for encoding.

tif is evaluated once. Requires the codec to be initialised.

Parameters
[in]tifHandle whose codec state is returned.

Definition at line 96 of file tif_lzma.c.

Function Documentation

◆ LZMACleanup()

static void LZMACleanup ( TIFF *  tif)
static

End the dependency stream and release LZMA codec state.

Restores predictor and saved tag hooks, ends active liblzma state, frees the outer Ext allocation, clears tif_data and installs default callbacks. Invalidates codec/dependency views. Does not finalise or flush pending payload, close the handle, or provide an error status.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.

Definition at line 607 of file tif_lzma.c.

References _TIFFfreeExt(), _TIFFSetDefaultCompressionState(), GetLZMAState, LZMAState::state, LZMAState::stream, tiff::tif_data, tiff::tif_tagmethods, TIFFPredictorCleanup(), TIFFTagMethods::vgetfield, LZMAState::vgetparent, TIFFTagMethods::vsetfield, and LZMAState::vsetparent.

Referenced by TIFFInitLZMA().

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

◆ LZMADecode()

static int LZMADecode ( TIFF *  tif,
uint8_t *  op,
tmsize_t  occ,
uint16_t  s 
)
static

Expand cached liblzma input into caller output.

Requires successful predecode. A latched same-strile error clears requested output and fails. Configures input/output and runs until filled/end/error; memory-limit recovery can reinitialise the decoder at reported usage and restore saved input. Short output clears its remaining tail and latches failure. Other dependency errors can diagnose yet return success if output is already full. Only successful completion commits rawcp/rawcc; stream and output can change before failure. No caller ownership transfer or direct client I/O.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.
[out]opBorrowed writable occ-byte decoded output, disjoint from raw/state storage.
[in]occNonnegative decoded byte count representable by size_t.
[in]sUnused sample-plane compatibility argument.
Returns
One if requested output fills, zero on latched error, size rejection or short output; not a full-stream integrity guarantee.

Definition at line 279 of file tif_lzma.c.

References LSTATE_INIT_DECODE, LZMADecoderState, LZMAStrerror(), TIFFDirectory::td_row, tiff::tif_dir, tiff::tif_rawcc, tiff::tif_rawcp, TIFF_SIZE_FORMAT, and TIFFErrorExtR().

Referenced by TIFFInitLZMA().

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

◆ LZMAEncode()

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

Consume input through the active liblzma encoder.

Requires successful preencode and positive raw output capacity; a state not initialised for encoding is diagnosed and rejected. Checks size_t input conversion, calls lzma_code with RUN and flushes full raw buffers. Input remains unchanged. Dependency/flush failure can leave partial stream/file/cache progress and is not transactional; diagnostics follow the failing operation. No ownership transfer.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.
[in]bpBorrowed readable cc-byte input, consumed synchronously without modification.
[in]ccNonnegative input byte count representable by size_t.
[in]sUnused sample-plane compatibility argument.
Returns
One when input consumed, zero on wrong codec state or size/dependency/flush failure.

Definition at line 464 of file tif_lzma.c.

References LSTATE_INIT_ENCODE, LZMAEncoderState, LZMAStrerror(), TIFFDirectory::td_row, tiff::tif_dir, tiff::tif_rawcc, tiff::tif_rawdata, tiff::tif_rawdatasize, TIFFErrorExtR(), and TIFFFlushData1().

Referenced by TIFFInitLZMA().

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

◆ LZMAFixupTags()

static int LZMAFixupTags ( TIFF *  tif)
static

Accept LZMA tag fixup without changes.

No allocation, I/O, diagnostics, state or ownership effects.

Parameters
[in]tifUnused handle.
Returns
One unconditionally.

Definition at line 165 of file tif_lzma.c.

Referenced by TIFFInitLZMA().

Here is the caller graph for this function:

◆ LZMAGetMaxCompressionRatio()

static uint64_t LZMAGetMaxCompressionRatio ( TIFF *  tif)
static

Report the empirical LZMA expansion heuristic.

Ignores the handle; no allocation, I/O, diagnostics, state or ownership effects. This estimate is not a universal bound.

Parameters
[in]tifUnused handle.
Returns
Seven thousand.

Definition at line 726 of file tif_lzma.c.

Referenced by TIFFInitLZMA().

Here is the caller graph for this function:

◆ LZMAPostEncode()

static int LZMAPostEncode ( TIFF *  tif)
static

Finish the LZMA2 stream and flush produced output.

Runs FINISH until STREAM_END and flushes every nonempty raw extent. Requires valid preencode state; a state not initialised for encoding is diagnosed and rejected. Errors can leave an incomplete stream and changed file/cursor state. Does not persist the IFD or promise storage durability; no ownership transfer.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.
Returns
One after stream completion, zero on wrong codec state or dependency or flush failure.

Definition at line 530 of file tif_lzma.c.

References LSTATE_INIT_ENCODE, LZMAEncoderState, LZMAStrerror(), tiff::tif_rawcc, tiff::tif_rawdata, tiff::tif_rawdatasize, TIFFErrorExtR(), and TIFFFlushData1().

Referenced by TIFFInitLZMA().

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

◆ LZMAPreDecode()

static int LZMAPreDecode ( TIFF *  tif,
uint16_t  s 
)
static

Initialise the liblzma decoder for one strile.

Ensures decode mode, attaches raw input and checks size_t round-trip conversion, then calls lzma_stream_decoder with the memory limit disabled. Clears read_error only after successful setup. Dependency allocations remain codec-owned for cleanup; failures diagnose without rollback. No direct client I/O.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.
[in]sUnused sample-plane compatibility argument.
Returns
One after decoder initialisation, zero on size rejection or dependency setup failure.

Definition at line 219 of file tif_lzma.c.

References LSTATE_INIT_DECODE, LZMADecoderState, LZMAStrerror(), tiff::tif_rawcc, tiff::tif_rawdata, tiff::tif_setupdecode, and TIFFErrorExtR().

Referenced by TIFFInitLZMA().

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

◆ LZMAPreEncode()

static int LZMAPreEncode ( TIFF *  tif,
uint16_t  s 
)
static

Initialise a filtered LZMA2 stream for one output strile.

Ensures encode mode, attaches positive-capacity raw output, checks size_t conversion and initialises the configured filter chain/integrity-check mode. Dependency setup can allocate; errors diagnose with partial state retained for cleanup. No payload flush or ownership transfer.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.
[in]sUnused sample-plane compatibility argument.
Returns
One on encoder setup, zero on size rejection or dependency failure.

Definition at line 412 of file tif_lzma.c.

References LSTATE_INIT_ENCODE, LZMAEncoderState, LZMAStrerror(), tiff::tif_rawdata, tiff::tif_rawdatasize, tiff::tif_setupencode, and TIFFErrorExtR().

Referenced by TIFFInitLZMA().

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

◆ LZMASetupDecode()

static int LZMASetupDecode ( TIFF *  tif)
static

Switch the liblzma stream to decode mode.

Ends a previous encode stream, clears mode and marks decode setup. Dependency allocations/views from the old mode can be invalidated. No payload I/O or caller storage ownership transfer.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.
Returns
One unconditionally.

Definition at line 183 of file tif_lzma.c.

References LSTATE_INIT_DECODE, LSTATE_INIT_ENCODE, LZMADecoderState, LZMAState::state, and LZMAState::stream.

Referenced by TIFFInitLZMA().

Here is the caller graph for this function:

◆ LZMASetupEncode()

static int LZMASetupEncode ( TIFF *  tif)
static

Switch the liblzma stream to encode mode.

Ends previous decode state, clears mode and marks encode setup. Dependency allocations/views can be invalidated. Does not emit payload, allocate caller output or transfer ownership.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.
Returns
One unconditionally.

Definition at line 379 of file tif_lzma.c.

References LSTATE_INIT_DECODE, LSTATE_INIT_ENCODE, LZMAEncoderState, LZMAState::state, and LZMAState::stream.

Referenced by TIFFInitLZMA().

Here is the caller graph for this function:

◆ LZMAStrerror()

static const char * LZMAStrerror ( lzma_ret  ret)
static

Describe a liblzma status using immutable text.

Returns static library-lifetime string literals; unknown or newly added codes use a generic message. Do not modify or free the borrowed text. No allocation, I/O, diagnostics or state effects.

Parameters
[in]retDependency status code to describe.
Returns
Borrowed non-NULL terminated status description.

Definition at line 112 of file tif_lzma.c.

Referenced by LZMADecode(), LZMAEncode(), LZMAPostEncode(), LZMAPreDecode(), LZMAPreEncode(), and LZMAVSetField().

Here is the caller graph for this function:

◆ LZMAVGetField()

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

Retrieve LZMA preset or delegate a tag query.

TIFFTAG_LZMAPRESET consumes a non-NULL int* and writes the cached preset; other tags follow the parent getter contract. No allocation or ownership transfer for the preset.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.
[in]tagCodec pseudo-tag or delegated tag identifier.
[in,out]apLive tag-specific va_list consumed synchronously; not retained.
Returns
One for preset retrieval, otherwise parent getter status.

Definition at line 689 of file tif_lzma.c.

References GetLZMAState, LZMAState::preset, TIFFTAG_LZMAPRESET, and LZMAState::vgetparent.

Referenced by TIFFInitLZMA().

Here is the caller graph for this function:

◆ LZMAVSetField()

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

Store LZMA preset or delegate a tag assignment.

TIFFTAG_LZMAPRESET consumes int, stores it, updates LZMA options without checking lzma_lzma_preset status and, in encode mode, reinitialises the stream immediately. Dependency reinitialisation errors diagnose but still return success. This can disturb an active frame; no rollback or ownership transfer. Other tags follow parent variadic contracts.

Parameters
[in,out]tifNon-NULL live LZMA handle with predictor-prefixed state and valid raw buffers; serialise operations.
[in]tagCodec pseudo-tag or delegated tag identifier.
[in,out]apLive tag-specific va_list consumed synchronously; not retained.
Returns
One for preset assignment including diagnosed reinitialisation errors, otherwise parent setter status.

Definition at line 647 of file tif_lzma.c.

References GetLZMAState, LSTATE_INIT_ENCODE, LZMAStrerror(), TIFFErrorExtR(), and TIFFTAG_LZMAPRESET.

Referenced by TIFFInitLZMA().

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

◆ TIFFInitLZMA()

int TIFFInitLZMA ( TIFF *  tif,
int  scheme 
)
extern

Allocate predictor-aware LZMA2 codec state and install callbacks.

Requires cleaned-up previous state and COMPRESSION_LZMA. Merges preset metadata, allocates state and initialises dependency stream, saved tag hooks, default preset and no integrity check. Configures a byte-delta filter followed by LZMA2; delta distance is BitsPerSample/8 when BitsPerSample is a multiple of eight, otherwise one, using the bit depth current at initialisation. Installs methods and attempts PredictorInit without propagating its status. Failures diagnose; merged metadata or state changes are not rolled back. No pixel I/O.

Parameters
[in,out]tifNon-NULL handle whose previous codec state has been cleaned up; receives the new codec state. Serialise operations.
[in]schemeCOMPRESSION_LZMA, asserted in debug builds.
Returns
One after installation, zero on field merge or outer allocation failure.

Definition at line 741 of file tif_lzma.c.

References _TIFFmallocExt(), _TIFFMergeFields(), COMPRESSION_LZMA, GetLZMAState, LZMACleanup(), LZMADecode(), LZMAEncode(), lzmaFields, LZMAFixupTags(), LZMAGetMaxCompressionRatio(), LZMAPostEncode(), LZMAPreDecode(), LZMAPreEncode(), LZMASetupDecode(), LZMASetupEncode(), LZMAVGetField(), LZMAVSetField(), TIFFDirectory::td_bitspersample, tiff::tif_cleanup, tiff::tif_data, tiff::tif_decoderow, tiff::tif_decodestrip, tiff::tif_decodetile, tiff::tif_dir, 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, and TIFFTagMethods::vsetfield.

Here is the call graph for this function:

Variable Documentation

◆ lzmaFields

const TIFFField lzmaFields[]
static
Initial value:
= {
FALSE, "LZMA2 Compression Preset", NULL},
}
#define FIELD_PSEUDO
Share bit zero with FIELD_IGNORE for pseudo-tags.
Definition tif_dir.h:620
@ TIFF_SETGET_INT
Promoted int scalar representation.
Definition tif_dir.h:762
#define TRUE
Represent the legacy internal true value.
Definition tiffiop.h:131
#define FALSE
Represent the legacy internal false value.
Definition tiffiop.h:136
#define TIFF_ANY
Match any data type when searching for a field descriptor.
Definition tiffio.h:1289
#define TIFFTAG_LZMAPRESET
Pseudo-tag: LZMA2 preset (compression level).
Definition tiff.h:1633

Define the LZMA compression-preset pseudo-tag.

Immutable library-lifetime metadata merged into a handle; no caller ownership transfer.

Definition at line 711 of file tif_lzma.c.

Referenced by TIFFInitLZMA().