|
LibTIFF 4.7.2
TIFF library public API and implementation reference
|
Implement zlib and optional whole-strile libdeflate compression. More...
Data Structures | |
| struct | ZIPState |
| Own Deflate dependency streams predictor prefix and backend selection. More... | |
Macros | |
| #define | LIBDEFLATE_MAX_COMPRESSION_LEVEL 12 |
| Highest accepted TIFFTAG_ZIPQUALITY value: 12. | |
| #define | SAFE_MSG(sp) ((sp)->stream.msg == NULL ? "" : (sp)->stream.msg) |
| Borrow the zlib stream error text, or an empty string if none. | |
| #define | ZSTATE_INIT_DECODE 0x01 |
| Bit 0x01 of the codec state field: decoding has been set up. | |
| #define | ZSTATE_INIT_ENCODE 0x02 |
| Bit 0x02 of the codec state field: encoding has been set up. | |
| #define | GetZIPState(tif) ((ZIPState *)(tif)->tif_data) |
| Cast tif->tif_data to the ZIPState. | |
| #define | ZIPDecoderState(tif) GetZIPState(tif) |
| Alias of GetZIPState(), returning the ZIPState for decoding. | |
| #define | ZIPEncoderState(tif) GetZIPState(tif) |
| Alias of GetZIPState(), returning the ZIPState for encoding. | |
Functions | |
| static int | ZIPFixupTags (TIFF *tif) |
| Accept Deflate tag fixup without changes. | |
| static int | ZIPSetupDecode (TIFF *tif) |
| Initialise zlib decode mode and end an active encoder. | |
| static uint64_t | TIFF_MIN_UINT64 (uint64_t a, uint64_t b) |
| Select the smaller of two unsigned values. | |
| static uInt | TIFF_CLAMP_UINT64_TO_INT32_MAX (uint64_t v) |
| Bound a zlib chunk to the signed 32-bit maximum. | |
| static int | ZIPPreDecode (TIFF *tif, uint16_t s) |
| Reset zlib decoding and per-strile backend selection. | |
| static int | ZIPDecode (TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s) |
| Expand zlib or eligible whole-strile libdeflate input. | |
| static int | ZIPSetupEncode (TIFF *tif) |
| Initialise zlib encoding at a capped compression quality. | |
| static int | ZIPPreEncode (TIFF *tif, uint16_t s) |
| Reset zlib encoding and per-strile backend selection. | |
| static int | ZIPEncode (TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s) |
| Compress input with streaming zlib or eligible whole-strile libdeflate. | |
| static int | ZIPPostEncode (TIFF *tif) |
| Finish zlib output or accept an already written libdeflate frame. | |
| static void | ZIPCleanup (TIFF *tif) |
| End Deflate dependency objects and release codec state. | |
| static int | ZIPVSetField (TIFF *tif, uint32_t tag, va_list ap) |
| Set Deflate quality or backend or delegate another tag. | |
| static int | ZIPVGetField (TIFF *tif, uint32_t tag, va_list ap) |
| Retrieve Deflate quality or backend or delegate a tag query. | |
| static void * | TIFF_zalloc (void *opaque, unsigned int items, unsigned int size) |
| Allocate zlib internal storage through handle Ext allocation. | |
| static void | TIFF_zfree (void *opaque, void *ptr) |
| Release zlib storage through the matching handle Ext allocator. | |
| static uint64_t | ZIPGetMaxCompressionRatio (TIFF *tif) |
| Report the Deflate expansion allocation heuristic. | |
| int | TIFFInitZIP (TIFF *tif, int scheme) |
| Install predictor-aware Deflate codec and allocator hooks. | |
Variables | |
| static const TIFFField | zipFields [] |
| Define compression quality and backend pseudo-tags. | |
Implement zlib and optional whole-strile libdeflate compression.
| #define GetZIPState | ( | tif | ) | ((ZIPState *)(tif)->tif_data) |
| #define LIBDEFLATE_MAX_COMPRESSION_LEVEL 12 |
| #define SAFE_MSG | ( | sp | ) | ((sp)->stream.msg == NULL ? "" : (sp)->stream.msg) |
| #define ZIPDecoderState | ( | tif | ) | GetZIPState(tif) |
Alias of GetZIPState(), returning the ZIPState for decoding.
tif is evaluated once. Requires the codec to be initialised.
| [in] | tif | Handle whose codec state is returned. |
| #define ZIPEncoderState | ( | tif | ) | GetZIPState(tif) |
Alias of GetZIPState(), returning the ZIPState for encoding.
tif is evaluated once. Requires the codec to be initialised.
| [in] | tif | Handle whose codec state is returned. |
| #define ZSTATE_INIT_DECODE 0x01 |
Bit 0x01 of the codec state field: decoding has been set up.
Set by ZIPSetupDecode(). Each setup first tears down the other mode, if active, and clears the field.
| #define ZSTATE_INIT_ENCODE 0x02 |
Bit 0x02 of the codec state field: encoding has been set up.
Set by ZIPSetupEncode(). Each setup first tears down the other mode, if active, and clears the field.
|
inlinestatic |
Bound a zlib chunk to the signed 32-bit maximum.
Pure size conversion without allocation, I/O, diagnostics or ownership effects.
| [in] | v | Unsigned size to bound for zlib. |
Definition at line 219 of file tif_zip.c.
References TIFF_MIN_UINT64().
Referenced by ZIPDecode(), ZIPEncode(), and ZIPPreDecode().
|
inlinestatic |
Select the smaller of two unsigned values.
Pure comparison without allocation, I/O, diagnostics, state or ownership effects.
| [in] | a | First unsigned value. |
| [in] | b | Second unsigned value. |
Definition at line 204 of file tif_zip.c.
Referenced by TIFF_CLAMP_UINT64_TO_INT32_MAX().
|
static |
Allocate zlib internal storage through handle Ext allocation.
Requires positive size and a product representable in unsigned int and tmsize_t. Checks items against SIZE_MAX/size, then multiplies unsigned-int operands; that guard alone does not prevent narrower multiplication wrap. Memory is not zeroed by this wrapper. Dependency owns the result until TIFF_zfree. Overflow diagnoses through the handle; allocation limits follow Ext semantics. No pixel I/O.
| [in,out] | opaque | Borrowed live TIFF handle supplied as zlib allocator context. |
| [in] | items | Requested object count; product must fit both unsigned int arithmetic and tmsize_t. |
| [in] | size | Positive bytes per object; zero would divide by zero in the overflow guard. |
Definition at line 970 of file tif_zip.c.
References _TIFFmallocExt(), and TIFFErrorExtR().
Referenced by TIFFInitZIP().
|
static |
Release zlib storage through the matching handle Ext allocator.
Consumes ptr and invalidates all views of it. Does not free the borrowed handle, perform payload I/O or return status; NULL storage is allowed.
| [in,out] | opaque | Borrowed live TIFF handle supplied as zlib allocator context. |
| [in] | ptr | Allocation from the matching Ext family, or NULL; consumed by free. |
Definition at line 996 of file tif_zip.c.
References _TIFFfreeExt().
Referenced by TIFFInitZIP().
|
extern |
Install predictor-aware Deflate codec and allocator hooks.
Requires a supported Deflate scheme and cleaned-up previous state. Merges pseudo-tags, allocates zeroed codec state, installs handle-backed dependency allocators, saves tag hooks, sets default quality/backend and assigns callbacks. Attempts PredictorInit without propagating its status. Merge/allocation failure diagnoses; metadata/state effects are not rolled back. Dependency streams/optional backend objects are initialised 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_DEFLATE or COMPRESSION_ADOBE_DEFLATE, asserted in debug builds. |
Definition at line 1018 of file tif_zip.c.
References _TIFFcallocExt(), _TIFFMergeFields(), COMPRESSION_ADOBE_DEFLATE, COMPRESSION_DEFLATE, DEFLATE_SUBCODEC_LIBDEFLATE, DEFLATE_SUBCODEC_ZLIB, GetZIPState, 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, TIFF_zalloc(), TIFF_zfree(), TIFFArrayCount, TIFFErrorExtR(), TIFFPredictorInit(), TIFFTagMethods::vgetfield, TIFFTagMethods::vsetfield, ZIPCleanup(), ZIPDecode(), ZIPEncode(), zipFields, ZIPFixupTags(), ZIPGetMaxCompressionRatio(), ZIPPostEncode(), ZIPPreDecode(), ZIPPreEncode(), ZIPSetupDecode(), ZIPSetupEncode(), ZIPVGetField(), and ZIPVSetField().
|
static |
End Deflate dependency objects and release codec state.
Restores predictor and saved tag hooks, ends the active zlib mode, frees optional libdeflate objects using dependency free functions, frees outer Ext state, clears tif_data and resets callbacks. Invalidates all codec-owned views. Does not finish/flush pending payload or close the handle; no status result.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
Definition at line 779 of file tif_zip.c.
References _TIFFfreeExt(), _TIFFSetDefaultCompressionState(), GetZIPState, ZIPState::state, ZIPState::stream, tiff::tif_data, tiff::tif_tagmethods, TIFFPredictorCleanup(), TIFFTagMethods::vgetfield, ZIPState::vgetparent, TIFFTagMethods::vsetfield, ZIPState::vsetparent, ZSTATE_INIT_DECODE, and ZSTATE_INIT_ENCODE.
Referenced by TIFFInitZIP().
Expand zlib or eligible whole-strile libdeflate input.
Requires successful predecode and nonnegative output extent. Eligible complete striles can lazily allocate libdeflate state (allocation failure falls back to zlib silently); on success it consumes all raw bytes. An insufficient-output-space status, seen with oversized final strips, leaves the raw cursor unchanged and decodes the strile again with zlib, which stops at occ and ignores the extra data. A repeated same-strile call after the libdeflate path returns zero silently, leaving output untouched and not latching read_error. Other requests use bounded zlib chunks. Decode errors clear unfilled output (whole output for libdeflate error), latch same-strile failure and diagnose. Zlib can decrement rawcc before an error without committing rawcp, so retry state is not transactional. Latched errors clear requested output until predecode. No caller ownership transfer or direct client I/O.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
| [out] | op | Borrowed writable occ-byte output, disjoint from raw input and state. |
| [in] | occ | Nonnegative requested decoded bytes. |
| [in] | s | Unused sample-plane argument. |
Definition at line 299 of file tif_zip.c.
References DEFLATE_SUBCODEC_ZLIB, isTiled, SAFE_MSG, TIFFDirectory::td_imagelength, TIFFDirectory::td_row, TIFFDirectory::td_rowsperstrip, tiff::tif_dir, tiff::tif_rawcc, tiff::tif_rawcp, TIFF_CLAMP_UINT64_TO_INT32_MAX(), TIFFErrorExtR(), TIFFTileSize64(), TIFFVStripSize64(), ZIPDecoderState, and ZSTATE_INIT_DECODE.
Referenced by TIFFInitZIP().
Compress input with streaming zlib or eligible whole-strile libdeflate.
Requires successful preencode and representable nonnegative extents/capacity; a state not initialised for encoding is diagnosed and rejected. Optional libdeflate is used only for full-strile input, nonzero quality and a sufficient worst-case output bound; otherwise zlib is used. Failure to allocate the libdeflate compressor is reported with TIFFErrorExtR() but still falls back to zlib, so the call may succeed after emitting that error. The libdeflate path compresses and flushes a whole frame immediately; a repeated same-strile call afterwards returns zero silently without consuming input. Zlib uses bounded input chunks and flushes full raw storage. Caller bytes remain unchanged. Dependency/flush failures can leave partial state and file bytes; no rollback or ownership transfer.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
| [in] | bp | Borrowed readable cc-byte input; not modified or retained. |
| [in] | cc | Nonnegative input bytes. |
| [in] | s | Unused sample-plane argument. |
Definition at line 562 of file tif_zip.c.
References DEFLATE_SUBCODEC_ZLIB, isTiled, SAFE_MSG, TIFFDirectory::td_imagelength, TIFFDirectory::td_row, TIFFDirectory::td_rowsperstrip, tiff::tif_dir, tiff::tif_rawcc, tiff::tif_rawdata, tiff::tif_rawdatasize, TIFF_CLAMP_UINT64_TO_INT32_MAX(), TIFFErrorExtR(), TIFFFlushData1(), TIFFTileSize64(), TIFFVStripSize64(), ZIPEncoderState, and ZSTATE_INIT_ENCODE.
Referenced by TIFFInitZIP().
|
static |
Accept Deflate tag fixup without changes.
No allocation, I/O, diagnostics, state or ownership effects.
| [in] | tif | Unused handle. |
Definition at line 144 of file tif_zip.c.
Referenced by TIFFInitZIP().
|
static |
Report the Deflate expansion allocation heuristic.
Ignores the handle; no allocation, I/O, diagnostics, state or ownership effects. Not a validation guarantee.
| [in] | tif | Unused handle. |
Definition at line 1011 of file tif_zip.c.
Referenced by TIFFInitZIP().
|
static |
Finish zlib output or accept an already written libdeflate frame.
Returns immediately for completed libdeflate mode. Otherwise runs Z_FINISH until STREAM_END and flushes produced bytes. Requires successful preencode and valid raw capacity; a state not initialised for encoding is diagnosed and rejected. Failures can leave incomplete frames/changed file state; no IFD persistence, durability guarantee or ownership transfer.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
Definition at line 719 of file tif_zip.c.
References SAFE_MSG, tiff::tif_rawcc, tiff::tif_rawdata, tiff::tif_rawdatasize, TIFFErrorExtR(), TIFFFlushData1(), ZIPEncoderState, and ZSTATE_INIT_ENCODE.
Referenced by TIFFInitZIP().
|
static |
Reset zlib decoding and per-strile backend selection.
Attempts setup when needed without checking that return directly, attaches raw input, caps its initial dependency extent and resets inflate. Resets libdeflate selection to undecided when compiled and clears read_error only on reset success. Requires successful setup and coherent nonnegative raw counts. No pixel I/O or output ownership transfer.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
| [in] | s | Unused sample-plane argument. |
Definition at line 243 of file tif_zip.c.
References ZIPState::read_error, ZIPState::state, ZIPState::stream, tiff::tif_rawcc, tiff::tif_rawdata, tiff::tif_setupdecode, TIFF_CLAMP_UINT64_TO_INT32_MAX(), ZIPDecoderState, and ZSTATE_INIT_DECODE.
Referenced by TIFFInitZIP().
|
static |
Reset zlib encoding and per-strile backend selection.
Attempts setup when mode differs without checking its status directly, attaches raw output with a 32-bit bounded extent and calls deflateReset. Marks optional backend selection undecided. Requires successful setup and positive usable raw capacity. No payload flush or ownership transfer.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
| [in] | s | Unused sample-plane argument. |
Definition at line 510 of file tif_zip.c.
References ZIPState::state, ZIPState::stream, tiff::tif_rawdata, tiff::tif_rawdatasize, tiff::tif_setupencode, ZIPEncoderState, and ZSTATE_INIT_ENCODE.
Referenced by TIFFInitZIP().
|
static |
Initialise zlib decode mode and end an active encoder.
Ends previous encode state and lazily calls inflateInit only when needed, supporting repeated successful setup calls. Dependency memory uses the handle Ext allocator hooks. Diagnostics report setup failure; mode/dependency changes are not rolled back. No pixel I/O.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
Definition at line 163 of file tif_zip.c.
References SAFE_MSG, TIFFErrorExtR(), ZIPDecoderState, ZSTATE_INIT_DECODE, and ZSTATE_INIT_ENCODE.
Referenced by TIFFInitZIP().
|
static |
Initialise zlib encoding at a capped compression quality.
Ends previous decode state, caps quality above Z_BEST_COMPRESSION and calls deflateInit using handle allocators. Requires no unreleased active encoder initialisation. Diagnoses dependency errors; state changes are not rolled back. No payload I/O.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
Definition at line 464 of file tif_zip.c.
References SAFE_MSG, TIFFErrorExtR(), ZIPEncoderState, ZSTATE_INIT_DECODE, and ZSTATE_INIT_ENCODE.
Referenced by TIFFInitZIP().
|
static |
Retrieve Deflate quality or backend or delegate a tag query.
ZIPQUALITY and DEFLATE_SUBCODEC consume non-NULL int* outputs. Other tags follow the parent getter contract. No allocation or ownership transfer for codec values.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
| [in] | tag | Pseudo-tag or delegated tag identifier. |
| [in,out] | ap | Live tag-specific va_list cursor consumed synchronously; not retained. |
Definition at line 916 of file tif_zip.c.
References GetZIPState, ZIPState::subcodec, TIFFTAG_DEFLATE_SUBCODEC, TIFFTAG_ZIPQUALITY, ZIPState::vgetparent, and ZIPState::zipquality.
Referenced by TIFFInitZIP().
|
static |
Set Deflate quality or backend or delegate another tag.
ZIPQUALITY and DEFLATE_SUBCODEC each consume int and store before validation, so rejection retains the attempted value. Quality accepts -1..12, caps zlib at nine, can call deflateParams on an active encoder, and frees cached libdeflate compressor after success. Backend accepts zlib/libdeflate constants but rejects unavailable libdeflate support. Parent tags follow their variadic contracts. Diagnostics/state/dependency changes are not rolled back; no caller ownership transfer.
| [in,out] | tif | Non-NULL live Deflate handle with predictor-prefixed state and coherent raw buffers; serialise operations. |
| [in] | tag | Pseudo-tag or delegated tag identifier. |
| [in,out] | ap | Live tag-specific va_list cursor consumed synchronously; not retained. |
Definition at line 834 of file tif_zip.c.
References DEFLATE_SUBCODEC_LIBDEFLATE, DEFLATE_SUBCODEC_ZLIB, GetZIPState, LIBDEFLATE_MAX_COMPRESSION_LEVEL, SAFE_MSG, TIFFErrorExtR(), TIFFTAG_DEFLATE_SUBCODEC, TIFFTAG_ZIPQUALITY, and ZSTATE_INIT_ENCODE.
Referenced by TIFFInitZIP().
|
static |
Define compression quality and backend pseudo-tags.
Immutable library-lifetime metadata merged into a handle; no caller ownership transfer.
Definition at line 943 of file tif_zip.c.
Referenced by TIFFInitZIP().