|
LibTIFF 4.7.2
TIFF library public API and implementation reference
|
Stage scalar samples validity masks and secondary compression. More...
Data Structures | |
| struct | LERCState |
| Own LERC full-strile staging masks and secondary-compression state. More... | |
Macros | |
| #define | LIBDEFLATE_MAX_COMPRESSION_LEVEL 12 |
| Highest accepted TIFFTAG_ZIPQUALITY value: 12. | |
| #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 | LERC_AT_LEAST_VERSION(maj, min, patch) 0 |
| Fallback used when the LERC header lacks LERC_AT_LEAST_VERSION. | |
| #define | GetLERCState(tif) ((LERCState *)(tif)->tif_data) |
| Cast tif->tif_data to the LERCState. | |
| #define | LERCDecoderState(tif) GetLERCState(tif) |
| Alias of GetLERCState(), returning the LERCState for decoding. | |
| #define | LERCEncoderState(tif) GetLERCState(tif) |
| Alias of GetLERCState(), returning the LERCState for encoding. | |
Functions | |
| static int | LERCFixupTags (TIFF *tif) |
| Accept LERC tag fixup without changes. | |
| static int | LERCSetupDecode (TIFF *tif) |
| Select LERC decode mode. | |
| static int | GetLercDataType (TIFF *tif) |
| Map TIFF sample format and depth to a LERC scalar code. | |
| static int | SetupBuffers (TIFF *tif, LERCState *sp, const char *module) |
| Size and reserve full-strile sample and validity-mask storage. | |
| static int | LERCPreDecode (TIFF *tif, uint16_t s) |
| Decode and validate an entire LERC strile into owned staging. | |
| static int | LERCDecode (TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s) |
| Copy the next decoded byte extent from LERC staging. | |
| static int | LERCSetupEncode (TIFF *tif) |
| Select LERC encode mode. | |
| static int | LERCPreEncode (TIFF *tif, uint16_t s) |
| Validate LERC sample type and prepare full-strile input storage. | |
| static int | LERCEncode (TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s) |
| Stage the next LERC input bytes for later frame encoding. | |
| static int | LERCPostEncode (TIFF *tif) |
| Encode a fully staged LERC strile and flush optional secondary compression. | |
| static void | LERCCleanup (TIFF *tif) |
| Release LERC staging masks secondary compressors and outer state. | |
| static int | LERCVSetFieldBase (TIFF *tif, uint32_t tag,...) |
| Forward a variadic assignment directly to the saved parent setter. | |
| static int | LERCVSetField (TIFF *tif, uint32_t tag, va_list ap) |
| Set LERC version error tolerance or secondary-compression controls. | |
| static int | LERCVGetField (TIFF *tif, uint32_t tag, va_list ap) |
| Retrieve cached LERC controls or delegate another tag query. | |
| int | TIFFInitLERC (TIFF *tif, int scheme) |
| Allocate LERC staging state and install frame callbacks and pseudo-tags. | |
Variables | |
| static const TIFFField | LERCFields [] |
| Define LERC parameters error tolerance version and secondary-compression tags. | |
Stage scalar samples validity masks and secondary compression.
| #define GetLERCState | ( | tif | ) | ((LERCState *)(tif)->tif_data) |
Cast tif->tif_data to the LERCState.
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 145 of file tif_lerc.c.
| #define LERC_AT_LEAST_VERSION | ( | maj, | |
| min, | |||
| patch | |||
| ) | 0 |
Fallback used when the LERC header lacks LERC_AT_LEAST_VERSION.
Always expands to 0, so code guarded by it treats the dependency as older than any tested version. The operands are not evaluated.
| [in] | maj | Major version (unused). |
| [in] | min | Minor version (unused). |
| [in] | patch | Patch version (unused). |
Definition at line 57 of file tif_lerc.c.
| #define LERCDecoderState | ( | tif | ) | GetLERCState(tif) |
Alias of GetLERCState(), returning the LERCState for decoding.
tif is evaluated once. Requires the codec to be initialised.
| [in] | tif | Handle whose codec state is returned. |
Definition at line 146 of file tif_lerc.c.
| #define LERCEncoderState | ( | tif | ) | GetLERCState(tif) |
Alias of GetLERCState(), returning the LERCState for encoding.
tif is evaluated once. Requires the codec to be initialised.
| [in] | tif | Handle whose codec state is returned. |
Definition at line 147 of file tif_lerc.c.
| #define LIBDEFLATE_MAX_COMPRESSION_LEVEL 12 |
Highest accepted TIFFTAG_ZIPQUALITY value: 12.
Matches the libdeflate maximum level; the zlib path caps the level at Z_BEST_COMPRESSION (9). The tag setter rejects values outside [-1, 12].
Definition at line 49 of file tif_lerc.c.
| #define LSTATE_INIT_DECODE 0x01 |
Bit 0x01 of the codec state field: decoding has been set up.
Set by LERCSetupDecode(). Each setup first tears down the other mode, if active, and clears the field.
Definition at line 53 of file tif_lerc.c.
| #define LSTATE_INIT_ENCODE 0x02 |
Bit 0x02 of the codec state field: encoding has been set up.
Set by LERCSetupEncode(). Each setup first tears down the other mode, if active, and clears the field.
Definition at line 54 of file tif_lerc.c.
|
static |
Map TIFF sample format and depth to a LERC scalar code.
Recognises signed/unsigned 8/16/32-bit integers and IEEE 32/64-bit floats. Diagnoses unsupported combinations; no allocation, I/O, state mutation or ownership transfer.
| [in] | tif | Non-NULL live LERC handle; only its SampleFormat and BitsPerSample are read (and it is passed to the error handler). |
Definition at line 207 of file tif_lerc.c.
References SAMPLEFORMAT_IEEEFP, SAMPLEFORMAT_INT, SAMPLEFORMAT_UINT, TIFFDirectory::td_bitspersample, TIFFDirectory::td_sampleformat, tiff::tif_dir, and TIFFErrorExtR().
Referenced by LERCPostEncode(), LERCPreDecode(), LERCPreEncode(), and SetupBuffers().
|
static |
Release LERC staging masks secondary compressors and outer state.
Restores saved tag hooks, frees sample/multiband/compressed/mask Ext allocations and optional libdeflate objects, frees outer state, clears tif_data and resets compression methods. Invalidates all codec-owned views. Does not encode or flush pending staging, close the borrowed handle or return status.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
Definition at line 1606 of file tif_lerc.c.
References _TIFFfreeExt(), _TIFFSetDefaultCompressionState(), LERCState::compressed_buffer, GetLERCState, LERCState::mask_buffer, tiff::tif_data, tiff::tif_tagmethods, LERCState::uncompressed_buffer, LERCState::uncompressed_buffer_multiband, TIFFTagMethods::vgetfield, LERCState::vgetparent, TIFFTagMethods::vsetfield, and LERCState::vsetparent.
Referenced by TIFFInitLERC().
Copy the next decoded byte extent from LERC staging.
Requires successful predecode and a nonnegative request. Checks staging presence and remaining bounds, copies bytes and advances uncompressed_offset. Rejection clears requested output and diagnoses. No allocation, dependency decoding, client I/O or ownership transfer; source/destination must not overlap.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
| [out] | op | Borrowed writable occ-byte destination, disjoint from codec staging. |
| [in] | occ | Nonnegative decoded byte extent within remaining staging data. |
| [in] | s | Unused sample-plane compatibility argument. |
Definition at line 928 of file tif_lerc.c.
References LERCDecoderState, LSTATE_INIT_DECODE, and TIFFErrorExtR().
Referenced by TIFFInitLERC().
Stage the next LERC input bytes for later frame encoding.
Requires successful preencode and nonnegative cc; a state not initialised for encoding is diagnosed and rejected. Checks offset+cc against decoded strile size, copies borrowed input and advances offset. Does not compress until postencode; input remains unchanged. Rejection diagnoses without copying. No client I/O or ownership transfer.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
| [in] | bp | Borrowed readable cc-byte input copied synchronously; not retained or modified. |
| [in] | cc | Nonnegative input byte extent within remaining staging capacity. |
| [in] | s | Unused sample-plane compatibility argument. |
Definition at line 1049 of file tif_lerc.c.
References LERCEncoderState, LSTATE_INIT_ENCODE, and TIFFErrorExtR().
Referenced by TIFFInitLERC().
|
static |
Accept LERC tag fixup without changes.
No allocation, I/O, diagnostics, state or ownership effects.
| [in] | tif | Unused handle. |
Definition at line 160 of file tif_lerc.c.
Referenced by TIFFInitLERC().
|
static |
Encode a fully staged LERC strile and flush optional secondary compression.
A state not initialised for encoding is diagnosed and rejected. Requires exact staged byte count, valid scalar/geometry arithmetic and suitable masks; pixel-count and multiband byte-count products are checked and an overflow is diagnosed. Compacts binary unassociated alpha into validity masks or detects floating NaNs; per-band NaN masks require supported LERC versions. Can allocate multiband/compressed storage, mutate staging, encode the selected version/error tolerance, then optionally compress with Deflate/ZSTD. Temporarily replaces tif_rawdata and tif_rawdatasize with the codec buffer and its size during flush and restores both afterward; rawcp can still refer into codec staging until reset. Dependency/validation/I/O errors diagnose where handled and can leave changed buffers, metadata or file bytes; no rollback, IFD persistence or durability guarantee. Failure to allocate the compressed or multiband staging buffer returns zero without a codec diagnostic (only _TIFFmallocExt()'s memory-limit error, if a configured limit was exceeded). Caller input had already been copied; no ownership transfer.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
Definition at line 1106 of file tif_lerc.c.
References _TIFFfreeExt(), _TIFFmallocExt(), _TIFFMultiply32(), EXTRASAMPLE_UNASSALPHA, GetLercDataType(), LERC_ADD_COMPRESSION_DEFLATE, LERC_ADD_COMPRESSION_NONE, LERC_ADD_COMPRESSION_ZSTD, LERC_AT_LEAST_VERSION, LERCEncoderState, LSTATE_INIT_ENCODE, PLANARCONFIG_CONTIG, SAMPLEFORMAT_IEEEFP, TIFFDirectory::td_bitspersample, TIFFDirectory::td_extrasamples, TIFFDirectory::td_planarconfig, TIFFDirectory::td_row, TIFFDirectory::td_sampleformat, TIFFDirectory::td_sampleinfo, TIFFDirectory::td_samplesperpixel, tiff::tif_dir, tiff::tif_rawcc, tiff::tif_rawdata, tiff::tif_rawdatasize, TIFFErrorExtR(), and TIFFFlushData1().
Referenced by TIFFInitLERC().
|
static |
Decode and validate an entire LERC strile into owned staging.
Selects data type, reserves buffers and optionally decompresses Deflate/ZSTD into reusable compressed storage. Inspects blob type, dimensions, bands, size and masks, warning on unexpected version. Decodes samples, expands binary alpha masks or restores invalid floating samples as NaNs; supported multi-band mask layouts depend on LERC version. Pixel-count and multiband byte-count products are checked and an overflow is diagnosed. Requires valid representable geometry/counts and raw extents within dependency unsigned sizes. Buffers/dependency state can change on failure and staged data must not be used after failure. Allocations remain codec-owned until replacement/cleanup. Does not copy caller output, consume it, or transfer ownership; dependency/validation errors diagnose. Failure to allocate the compressed or multiband staging buffer returns zero without a codec diagnostic (only _TIFFmallocExt()'s memory-limit error, if a configured limit was exceeded).
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
| [in] | s | Unused sample-plane compatibility argument. |
Definition at line 433 of file tif_lerc.c.
References _TIFFfreeExt(), _TIFFmallocExt(), _TIFFMultiply32(), LERCState::additional_compression, LERCState::compressed_buffer, LERCState::compressed_size, EXTRASAMPLE_UNASSALPHA, GetLercDataType(), LERC_ADD_COMPRESSION_DEFLATE, LERC_ADD_COMPRESSION_NONE, LERC_ADD_COMPRESSION_ZSTD, LERC_AT_LEAST_VERSION, LERCState::lerc_version, LERCDecoderState, LSTATE_INIT_DECODE, LERCState::mask_buffer, PLANARCONFIG_CONTIG, PLANARCONFIG_SEPARATE, SAMPLEFORMAT_IEEEFP, LERCState::segment_height, LERCState::segment_width, SetupBuffers(), LERCState::state, TIFFDirectory::td_bitspersample, TIFFDirectory::td_extrasamples, TIFFDirectory::td_planarconfig, TIFFDirectory::td_row, TIFFDirectory::td_sampleformat, TIFFDirectory::td_sampleinfo, TIFFDirectory::td_samplesperpixel, tiff::tif_dir, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_setupdecode, TIFFErrorExtR(), TIFFWarningExtR(), LERCState::uncompressed_alloc, LERCState::uncompressed_buffer, LERCState::uncompressed_buffer_multiband, and LERCState::uncompressed_buffer_multiband_alloc.
Referenced by TIFFInitLERC().
|
static |
Validate LERC sample type and prepare full-strile input storage.
Ensures encode mode, maps sample type and reserves buffers/masks through SetupBuffers. Requires valid representable geometry and successful setup; helper failures can invalidate old staging. No pixel I/O or caller ownership transfer.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
| [in] | s | Unused sample-plane compatibility argument. |
Definition at line 1005 of file tif_lerc.c.
References GetLercDataType(), LERCEncoderState, LSTATE_INIT_ENCODE, SetupBuffers(), and tiff::tif_setupencode.
Referenced by TIFFInitLERC().
|
static |
Select LERC decode mode.
Clears previous encode mode bits and marks decode initialisation without freeing reusable staging/dependency objects. No allocation, pixel I/O, diagnostics or ownership transfer.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
Definition at line 178 of file tif_lerc.c.
References LERCDecoderState, LSTATE_INIT_DECODE, LSTATE_INIT_ENCODE, and LERCState::state.
Referenced by TIFFInitLERC().
|
static |
Select LERC encode mode.
Clears previous decode mode bits and marks encoding without freeing reusable buffers. No allocation, diagnostics, payload I/O or ownership transfer.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
Definition at line 972 of file tif_lerc.c.
References LERCEncoderState, LSTATE_INIT_DECODE, LSTATE_INIT_ENCODE, and LERCState::state.
Referenced by TIFFInitLERC().
|
static |
Retrieve cached LERC controls or delegate another tag query.
MAXZERROR consumes non-NULL double*; VERSION, ADD_COMPRESSION, ZSTD_LEVEL and ZIPQUALITY consume non-NULL int*. ZSTD_LEVEL returns the cached level even in builds without ZSTD_SUPPORT, where the setter delegates it. LERC_PARAMETERS and other tags follow parent variadic contracts, including borrowed custom-array lifetime. No output allocation or ownership transfer for scalar pseudo-tags.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
| [in] | tag | Codec pseudo-tag/custom tag or delegated identifier. |
| [in,out] | ap | Live tag-specific va_list consumed synchronously; not retained. |
Definition at line 1836 of file tif_lerc.c.
References LERCState::additional_compression, GetLERCState, LERCState::lerc_version, LERCState::maxzerror, TIFFTAG_LERC_ADD_COMPRESSION, TIFFTAG_LERC_MAXZERROR, TIFFTAG_LERC_VERSION, TIFFTAG_ZIPQUALITY, TIFFTAG_ZSTD_LEVEL, LERCState::vgetparent, LERCState::zipquality, and LERCState::zstd_compress_level.
Referenced by TIFFInitLERC().
|
static |
Set LERC version error tolerance or secondary-compression controls.
LERC_PARAMETERS consumes int count then int*; a count below two is rejected, otherwise it caches version/backend and delegates custom-array storage; no validation of those array values is done here. MAXZERROR consumes double without range validation. VERSION and ADD_COMPRESSION consume int, validate supported values, cache and update the two-entry custom tag through the parent. ZSTD_LEVEL (ZSTD_SUPPORT builds only; otherwise delegated to the parent setter) consumes int and stores out-of-range values with a warning. ZIPQUALITY consumes int and stores it before range rejection; on every accepted assignment it frees any cached libdeflate compressor. Other tags delegate. State/custom-tag allocation changes can survive failure; borrowed input arrays are consumed/copied through the parent contract.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
| [in] | tag | Codec pseudo-tag/custom tag or delegated identifier. |
| [in,out] | ap | Live tag-specific va_list consumed synchronously; not retained. |
Definition at line 1709 of file tif_lerc.c.
References GetLERCState, LERC_ADD_COMPRESSION_DEFLATE, LERC_ADD_COMPRESSION_NONE, LERC_ADD_COMPRESSION_ZSTD, LERC_VERSION_2_4, LERCVSetFieldBase(), LIBDEFLATE_MAX_COMPRESSION_LEVEL, TIFFErrorExtR(), TIFFTAG_LERC_ADD_COMPRESSION, TIFFTAG_LERC_MAXZERROR, TIFFTAG_LERC_PARAMETERS, TIFFTAG_LERC_VERSION, TIFFTAG_ZIPQUALITY, TIFFTAG_ZSTD_LEVEL, and TIFFWarningExtR().
Referenced by TIFFInitLERC().
|
static |
Forward a variadic assignment directly to the saved parent setter.
Constructs a va_list and synchronously calls vsetparent, then ends the list. Used to store LERC_PARAMETERS without recursive codec dispatch. Tag-specific promotion, ownership and side effects follow the parent setter; see Tag arguments. No independent payload I/O.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
| [in] | tag | Codec pseudo-tag/custom tag or delegated identifier. |
| [in] | ... | Promoted tag-specific values/pointers required by the saved parent setter; consumed synchronously. |
Definition at line 1673 of file tif_lerc.c.
References GetLERCState, and LERCState::vsetparent.
Referenced by LERCVSetField().
Size and reserve full-strile sample and validity-mask storage.
Computes tile/truncated-strip dimensions and row-interleaved sample bytes, resets staging offset and reserves margin for secondary compression. Rejects an uncompressed size above UINT_MAX before narrowing it. Mask-size products are checked and an overflow is diagnosed. Requires the intermediate uint64_t products/sums and dependency size casts to be representable; these checks are not comprehensive overflow validation. Replaces owned uncompressed storage when growing and optionally grows masks for alpha/NaN/per-band validity. Failure can release prior sample storage and leave capacities/state changed, with the old mask allocation retained after failed realloc. Diagnostics report detected extent/allocation errors; no payload I/O or ownership transfer.
| [in,out] | tif | Non-NULL live LERC handle with valid current geometry/state; serialise access. |
| [in,out] | sp | Borrowed live LERC state owned by tif. |
| [in] | module | Borrowed diagnostic context string, used synchronously. |
Definition at line 283 of file tif_lerc.c.
References _TIFFfreeExt(), _TIFFmallocExt(), _TIFFMultiply32(), _TIFFreallocExt(), EXTRASAMPLE_UNASSALPHA, GetLercDataType(), isTiled, LERCState::mask_buffer, LERCState::mask_size, PLANARCONFIG_CONTIG, SAMPLEFORMAT_IEEEFP, LERCState::segment_height, LERCState::segment_width, TIFFDirectory::td_bitspersample, TIFFDirectory::td_extrasamples, TIFFDirectory::td_imagelength, TIFFDirectory::td_imagewidth, TIFFDirectory::td_planarconfig, TIFFDirectory::td_row, TIFFDirectory::td_rowsperstrip, TIFFDirectory::td_sampleformat, TIFFDirectory::td_sampleinfo, TIFFDirectory::td_samplesperpixel, TIFFDirectory::td_tilelength, TIFFDirectory::td_tilewidth, tiff::tif_dir, TIFFErrorExtR(), LERCState::uncompressed_alloc, LERCState::uncompressed_buffer, LERCState::uncompressed_offset, and LERCState::uncompressed_size.
Referenced by LERCPreDecode(), and LERCPreEncode().
|
extern |
Allocate LERC staging state and install frame callbacks and pseudo-tags.
Requires cleaned-up previous codec state and COMPRESSION_LERC. Merges field metadata, allocates zeroed Ext state, chains tag methods and installs decode plus non-read-only encode callbacks. Sets version/additional-compression defaults through TIFFSetField without checking those statuses, then sets zero error tolerance, ZSTD level nine and default Deflate quality. Reusable buffers/dependency objects are created lazily. No predictor prefix or finite ratio heuristic is installed. Failures diagnose without general rollback; no pixel I/O.
| [in,out] | tif | Non-NULL handle whose previous codec state has been cleaned up; receives the new codec state. Serialise access. |
| [in] | scheme | COMPRESSION_LERC, asserted in debug builds. |
Definition at line 1863 of file tif_lerc.c.
References _TIFFcallocExt(), _TIFFMergeFields(), COMPRESSION_LERC, GetLERCState, LERC_ADD_COMPRESSION_NONE, LERC_VERSION_2_4, LERCCleanup(), LERCDecode(), LERCEncode(), LERCFields, LERCFixupTags(), LERCPostEncode(), LERCPreDecode(), LERCPreEncode(), LERCSetupDecode(), LERCSetupEncode(), LERCVGetField(), LERCVSetField(), 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_postencode, tiff::tif_predecode, tiff::tif_preencode, tiff::tif_setupdecode, tiff::tif_setupencode, tiff::tif_tagmethods, TIFFArrayCount, TIFFErrorExtR(), TIFFSetField(), TIFFTAG_LERC_ADD_COMPRESSION, TIFFTAG_LERC_VERSION, TIFFTagMethods::vgetfield, and TIFFTagMethods::vsetfield.
|
static |
Define LERC parameters error tolerance version and secondary-compression tags.
Immutable library-lifetime metadata merged into a handle; no caller ownership transfer.
Definition at line 1641 of file tif_lerc.c.
Referenced by TIFFInitLERC().