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

Stage and transfer WebP RGB or RGBA frames. More...

Collaboration diagram for WebP frame codec:

Data Structures

struct  WebPState
 Own WebP frame staging dependency objects and saved tag 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 LState(tif)   ((WebPState *)(tif)->tif_data)
 Cast tif->tif_data to the WebPState.
 
#define DecoderState(tif)   LState(tif)
 Alias of LState(), returning the WebPState for decoding.
 
#define EncoderState(tif)   LState(tif)
 Alias of LState(), returning the WebPState for encoding.
 

Functions

static void TWebPGetStrileDimensions (const TIFF *tif, uint32_t *width, uint32_t *height)
 Compute the pixel extent of the current strip or tile.
 
static int TWebPDatasetWriter (const uint8_t *data, size_t data_size, const WebPPicture *const picture)
 Append one dependency output fragment to the raw TIFF buffer.
 
static int TWebPEncode (TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 Accumulate decoded WebP input in the strile staging buffer.
 
static int TWebPDecode (TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 Decode a WebP strile or retrieve its next decoded rows.
 
static int TWebPFixupTags (TIFF *tif)
 Reject noncontiguous WebP sample organisation.
 
static int TWebPSetupDecode (TIFF *tif)
 Validate WebP channel support and enter decode mode.
 
static int TWebPPreDecode (TIFF *tif, uint16_t s)
 Reset WebP per-strile decode state and error latch.
 
static int TWebPSetupEncode (TIFF *tif)
 Validate WebP input and initialise picture and encoder configuration.
 
static int TWebPPreEncode (TIFF *tif, uint16_t s)
 Allocate full-strile WebP input staging and attach the output writer.
 
static int TWebPPostEncode (TIFF *tif)
 Import staged RGB or RGBA encode it and flush the WebP frame.
 
static void TWebPCleanup (TIFF *tif)
 Release WebP picture decoder staging and outer codec state.
 
static int TWebPVSetField (TIFF *tif, uint32_t tag, va_list ap)
 Store WebP quality lossless settings or delegate another tag.
 
static int TWebPVGetField (TIFF *tif, uint32_t tag, va_list ap)
 Retrieve WebP quality or lossless settings or delegate a tag.
 
static uint64_t TWebPGetMaxCompressionRatio (TIFF *tif)
 Report the channel-dependent WebP expansion heuristic.
 
int TIFFInitWebP (TIFF *tif, int scheme)
 Allocate WebP codec state and install buffered frame callbacks.
 

Variables

static const TIFFField TWebPFields []
 Define WebP quality lossless and exact pseudo-tags.
 

Detailed Description

Stage and transfer WebP RGB or RGBA frames.

Macro Definition Documentation

◆ DecoderState

#define DecoderState (   tif)    LState(tif)

Alias of LState(), returning the WebPState for decoding.

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

Parameters
[in]tifHandle whose codec state is returned.

Definition at line 117 of file tif_webp.c.

◆ EncoderState

#define EncoderState (   tif)    LState(tif)

Alias of LState(), returning the WebPState for encoding.

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

Parameters
[in]tifHandle whose codec state is returned.

Definition at line 118 of file tif_webp.c.

◆ LState

#define LState (   tif)    ((WebPState *)(tif)->tif_data)

Cast tif->tif_data to the WebPState.

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 116 of file tif_webp.c.

◆ LSTATE_INIT_DECODE

#define LSTATE_INIT_DECODE   0x01

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

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

Definition at line 45 of file tif_webp.c.

◆ LSTATE_INIT_ENCODE

#define LSTATE_INIT_ENCODE   0x02

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

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

Definition at line 46 of file tif_webp.c.

Function Documentation

◆ TIFFInitWebP()

int TIFFInitWebP ( TIFF *  tif,
int  scheme 
)
extern

Allocate WebP codec state and install buffered frame callbacks.

Requires cleaned-up previous codec state and COMPRESSION_WEBP. Merges pseudo-tags, allocates outer Ext state, saves tag hooks and sets defaults quality 75, lossy, exact enabled for later lossless use. Installs row/strile transfer and cleanup callbacks; row encoding stages input until postencode. Field/allocation failure diagnoses without general rollback. Dependency objects and staging are created lazily. No pixel I/O.

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

Definition at line 1167 of file tif_webp.c.

References _TIFFmallocExt(), _TIFFMergeFields(), COMPRESSION_WEBP, LState, 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(), TWebPCleanup(), TWebPDecode(), TWebPEncode(), TWebPFields, TWebPFixupTags(), TWebPGetMaxCompressionRatio(), TWebPPostEncode(), TWebPPreDecode(), TWebPPreEncode(), TWebPSetupDecode(), TWebPSetupEncode(), TWebPVGetField(), TWebPVSetField(), TIFFTagMethods::vgetfield, and TIFFTagMethods::vsetfield.

Here is the call graph for this function:

◆ TWebPCleanup()

static void TWebPCleanup ( TIFF *  tif)
static

Release WebP picture decoder staging and outer codec state.

Restores saved tag hooks, releases dependency picture/decoder/buffer descriptor and Ext staging/state allocations, clears tif_data and resets methods. Invalidates state, dependency and retained borrowed-output views. Does not finish or flush a pending frame or close the borrowed handle; no status result.

Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.

Definition at line 991 of file tif_webp.c.

References _TIFFfreeExt(), _TIFFSetDefaultCompressionState(), WebPState::last_y, LState, LSTATE_INIT_ENCODE, WebPState::pBuffer, WebPState::psDecoder, WebPState::sDecBuffer, WebPState::sPicture, WebPState::state, tiff::tif_data, tiff::tif_tagmethods, TIFFTagMethods::vgetfield, WebPState::vgetparent, TIFFTagMethods::vsetfield, and WebPState::vsetparent.

Referenced by TIFFInitWebP().

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

◆ TWebPDatasetWriter()

static int TWebPDatasetWriter ( const uint8_t *  data,
size_t  data_size,
const WebPPicture *const  picture 
)
static

Append one dependency output fragment to the raw TIFF buffer.

Requires valid picture context and representable byte/cursor arithmetic. Checks remaining raw capacity, copies bytes and advances rawcp/rawcc; diagnoses insufficient space without flushing. No retained input, allocation or ownership transfer.

Parameters
[in]dataBorrowed dependency output valid for the duration of the writer callback.
[in]data_sizeOutput byte extent, representable by tmsize_t with checked-by-caller cursor sums.
[in]pictureBorrowed picture whose custom_ptr contains the live TIFF handle.
Returns
One after copy, zero for insufficient capacity.

Definition at line 172 of file tif_webp.c.

References _TIFFmemcpy(), TIFF_SIZE_FORMAT, and TIFFErrorExtR().

Referenced by TWebPPreEncode().

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

◆ TWebPDecode()

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

Decode a WebP strile or retrieve its next decoded rows.

Requires successful predecode and validated positive geometry/stride. On first use checks blob dimensions and, for available ABI, channel compatibility (opaque RGB blob may fill RGBA). Uses caller output directly for a full-strile request or codec-owned staging for partial rows; lazily creates a dependency decoder. Requires complete row extents and enough newly decoded rows. Success consumes all raw input, advances last_y, and deletes a completed direct-output decoder. Errors normally clear requested output and latch read_error; fractional-row usage errors do not latch. Decoder/stream state can change before failure, and a direct-output decoder can retain the borrowed output pointer until the next predecode/cleanup. No ownership transfer or direct client I/O.

Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.
[out]opBorrowed writable occ-byte output; keep it live until predecode/cleanup if an external-buffer decode fails before decoder release.
[in]occNonnegative whole-row output byte extent.
[in]sUnused sample-plane argument.
Returns
One after requested rows supplied, zero on detected setup/content/extent/decode failure; partial output is discarded on failure.

Definition at line 275 of file tif_webp.c.

References _TIFFfreeExt(), _TIFFmallocExt(), WebPState::buffer_size, DecoderState, WebPState::last_y, LSTATE_INIT_DECODE, WebPState::nSamples, WebPState::pBuffer, WebPState::psDecoder, WebPState::read_error, WebPState::sDecBuffer, WebPState::state, TIFFDirectory::td_row, tiff::tif_dir, tiff::tif_rawcc, tiff::tif_rawcp, TIFFErrorExtR(), and TWebPGetStrileDimensions().

Referenced by TIFFInitWebP().

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

◆ TWebPEncode()

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

Accumulate decoded WebP input in the strile staging buffer.

Requires successful preencode and nonnegative count; a state not initialised for encoding, as after reading on an "r+" handle, is diagnosed and rejected. Bounds offset+cc against buffer_size using uint64_t, copies input and advances offset. Does not compress until postencode. Input remains caller-owned/unmodified; rejection diagnoses, no client I/O or ownership transfer.

Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.
[in]bpBorrowed readable cc-byte input, copied synchronously without modification.
[in]ccNonnegative input byte extent within the remaining strile allocation.
[in]sUnused sample-plane argument.
Returns
One after staging, zero on wrong codec state or when input exceeds capacity.

Definition at line 221 of file tif_webp.c.

References EncoderState, LSTATE_INIT_ENCODE, and TIFFErrorExtR().

Referenced by TIFFInitWebP().

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

◆ TWebPFixupTags()

static int TWebPFixupTags ( TIFF *  tif)
static

Reject noncontiguous WebP sample organisation.

Checks PLANARCONFIG_CONTIG and diagnoses rejection. No allocation, payload I/O, state mutation or ownership transfer.

Parameters
[in]tifNon-NULL live WebP handle whose PlanarConfiguration is checked.
Returns
One for contiguous layout, zero otherwise.

Definition at line 526 of file tif_webp.c.

References PLANARCONFIG_CONTIG, TIFFDirectory::td_planarconfig, tiff::tif_dir, and TIFFErrorExtR().

Referenced by TIFFInitWebP().

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

◆ TWebPGetMaxCompressionRatio()

static uint64_t TWebPGetMaxCompressionRatio ( TIFF *  tif)
static

Report the channel-dependent WebP expansion heuristic.

Reads sample count without allocation, diagnostics, I/O or state/ownership effects. Uses lossless-derived estimates regardless of selected mode; not a universal bound.

Parameters
[in]tifNon-NULL live WebP handle; only SamplesPerPixel is read.
Returns
104194 for four samples, otherwise 78146.

Definition at line 1156 of file tif_webp.c.

References TIFFDirectory::td_samplesperpixel, and tiff::tif_dir.

Referenced by TIFFInitWebP().

Here is the caller graph for this function:

◆ TWebPGetStrileDimensions()

static void TWebPGetStrileDimensions ( const TIFF *  tif,
uint32_t *  width,
uint32_t *  height 
)
static

Compute the pixel extent of the current strip or tile.

A tile always has the full TileWidth by TileLength extent. A strip is ImageWidth wide and RowsPerStrip high, truncated to the rows left from td_row for the final strip. Reads directory state only.

Parameters
[in]tifNon-NULL live handle with established geometry and current row.
[out]widthNon-NULL slot receiving the strile width in pixels.
[out]heightNon-NULL slot receiving the strile height in rows.

Definition at line 136 of file tif_webp.c.

References isTiled, TIFFDirectory::td_imagelength, TIFFDirectory::td_imagewidth, TIFFDirectory::td_row, TIFFDirectory::td_rowsperstrip, TIFFDirectory::td_tilelength, TIFFDirectory::td_tilewidth, and tiff::tif_dir.

Referenced by TWebPDecode(), TWebPPreDecode(), and TWebPPreEncode().

Here is the caller graph for this function:

◆ TWebPPostEncode()

static int TWebPPostEncode ( TIFF *  tif)
static

Import staged RGB or RGBA encode it and flush the WebP frame.

Fails with a diagnostic unless the state is initialised for encoding. Staging that was not fully filled has its unwritten tail cleared, so uninitialised memory is never compressed; the cleared bytes are encoded as zero samples. Imports dependency picture data, encodes through the bounded raw-buffer writer then flushes. Picture/custom context and raw/file state can change on failure. Dependency ABI selects RGBA/error-detail support. No IFD persistence, durability guarantee or input ownership transfer.

Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.
Returns
One after frame encoding and flush, zero on wrong codec state or import/encoding/flush failure.

Definition at line 870 of file tif_webp.c.

References WebPState::buffer_offset, WebPState::buffer_size, EncoderState, LSTATE_INIT_ENCODE, WebPState::nSamples, WebPState::pBuffer, WebPState::sEncoderConfig, WebPState::sPicture, WebPState::state, TIFFErrorExtR(), and TIFFFlushData1().

Referenced by TIFFInitWebP().

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

◆ TWebPPreDecode()

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

Reset WebP per-strile decode state and error latch.

Computes tile or truncated-strip dimensions and rejects either above

  1. Attempts setup without directly checking its status, deletes any previous dependency decoder/buffer descriptor and clears read_error. Requires positive valid geometry and successful setup from the caller. Invalidates borrowed decoder views; retains codec staging allocation for reuse. No pixel I/O.
Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.
[in]sUnused sample-plane argument.
Returns
One after reset, zero on dimension rejection.

Definition at line 633 of file tif_webp.c.

References DecoderState, LSTATE_INIT_DECODE, WebPState::psDecoder, WebPState::read_error, WebPState::sDecBuffer, WebPState::state, tiff::tif_setupdecode, TIFFErrorExtR(), and TWebPGetStrileDimensions().

Referenced by TIFFInitWebP().

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

◆ TWebPPreEncode()

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

Allocate full-strile WebP input staging and attach the output writer.

Runs encoder setup when the state is not yet initialised for encoding and fails if it fails, computes the tile/truncated-strip extent with TWebPGetStrileDimensions(), rejects dimensions above 16383 and replaces the old staging allocation. Requires valid positive geometry and a successful encoder configuration. Size is bounded below one GiB for at most four samples. Sets picture width/height, writer and borrowed handle context. Failure can discard the old staging buffer; no payload I/O or ownership transfer.

Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.
[in]sUnused sample-plane argument.
Returns
One after allocation/attachment, zero on setup/dimension/allocation failure.

Definition at line 801 of file tif_webp.c.

References _TIFFfreeExt(), _TIFFmallocExt(), WebPState::buffer_offset, WebPState::buffer_size, EncoderState, LSTATE_INIT_ENCODE, WebPState::nSamples, WebPState::pBuffer, WebPState::sPicture, WebPState::state, tiff::tif_setupencode, TIFFErrorExtR(), TWebPDatasetWriter(), and TWebPGetStrileDimensions().

Referenced by TIFFInitWebP().

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

◆ TWebPSetupDecode()

static int TWebPSetupDecode ( TIFF *  tif)
static

Validate WebP channel support and enter decode mode.

Caches sample count and accepts three channels or four when encoder ABI supports them. Current sample-format check rejects only when both bit depth differs from eight and format differs from unsigned, so caller must establish valid eight-bit unsigned data separately. Releases an old encoder picture/staging buffer when switching modes. State/views can change before later failure; no client I/O or caller ownership transfer.

Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.
Returns
One after mode setup, zero on detected channel/format rejection.

Definition at line 560 of file tif_webp.c.

References _TIFFfreeExt(), WebPState::buffer_offset, DecoderState, LSTATE_INIT_DECODE, LSTATE_INIT_ENCODE, WebPState::nSamples, WebPState::pBuffer, WebPState::sPicture, WebPState::state, TIFFDirectory::td_bitspersample, TIFFDirectory::td_sampleformat, TIFFDirectory::td_samplesperpixel, tiff::tif_dir, and TIFFErrorExtR().

Referenced by TIFFInitWebP().

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

◆ TWebPSetupEncode()

static int TWebPSetupEncode ( TIFF *  tif)
static

Validate WebP input and initialise picture and encoder configuration.

Requires unsigned eight-bit RGB or ABI-supported RGBA; separate PlanarConfig is diagnosed and rejected, since the dependency encodes interleaved pixels only. Ends decoder mode, initialises dependency picture/config at cached quality, applies supported lossless/exact settings and validates config. Errors diagnose after some mode/config state can change. Dependency picture storage is codec-owned until cleanup; no pixel I/O or caller ownership transfer.

Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.
Returns
One after configuration, zero on unsupported geometry/ABI/dependency setup failure.

Definition at line 684 of file tif_webp.c.

References EncoderState, WebPState::last_y, WebPState::lossless, WebPState::lossless_exact, LSTATE_INIT_DECODE, LSTATE_INIT_ENCODE, WebPState::nSamples, PLANARCONFIG_CONTIG, WebPState::psDecoder, WebPState::quality_level, SAMPLEFORMAT_UINT, WebPState::sDecBuffer, WebPState::sEncoderConfig, WebPState::sPicture, WebPState::state, TIFFDirectory::td_bitspersample, TIFFDirectory::td_planarconfig, TIFFDirectory::td_sampleformat, TIFFDirectory::td_samplesperpixel, tiff::tif_dir, and TIFFErrorExtR().

Referenced by TIFFInitWebP().

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

◆ TWebPVGetField()

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

Retrieve WebP quality or lossless settings or delegate a tag.

Codec pseudo-tags consume non-NULL int* outputs for cached level, lossless and exact values; other tags follow parent getter contracts. No allocation or ownership transfer for codec settings.

Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.
[in]tagCodec pseudo-tag or delegated tag identifier.
[in,out]apLive tag-specific va_list consumed synchronously; not retained.
Returns
One for codec retrieval, otherwise parent getter status.

Definition at line 1108 of file tif_webp.c.

References WebPState::lossless, WebPState::lossless_exact, LState, WebPState::quality_level, TIFFTAG_WEBP_LEVEL, TIFFTAG_WEBP_LOSSLESS, TIFFTAG_WEBP_LOSSLESS_EXACT, and WebPState::vgetparent.

Referenced by TIFFInitWebP().

Here is the caller graph for this function:

◆ TWebPVSetField()

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

Store WebP quality lossless settings or delegate another tag.

WEBP_LEVEL consumes int and stores it even outside 1..100, warning without rejection. WEBP_LOSSLESS consumes int when supported and sets quality to 100 when enabled. WEBP_LOSSLESS_EXACT consumes int when supported. Older ABI rejection diagnoses and returns zero. Values apply at encoder setup; current active config is not generally rebuilt. Parent tags follow their variadic contracts; no ownership transfer.

Parameters
[in,out]tifNon-NULL live WebP handle with coherent raw buffers and established contiguous eight-bit RGB/RGBA geometry; serialise operations.
[in]tagCodec pseudo-tag or delegated tag identifier.
[in,out]apLive tag-specific va_list consumed synchronously; not retained.
Returns
One for accepted settings including warned levels, zero for unsupported ABI controls, otherwise parent status.

Definition at line 1045 of file tif_webp.c.

References LState, TIFFErrorExtR(), TIFFTAG_WEBP_LEVEL, TIFFTAG_WEBP_LOSSLESS, TIFFTAG_WEBP_LOSSLESS_EXACT, and TIFFWarningExtR().

Referenced by TIFFInitWebP().

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

Variable Documentation

◆ TWebPFields

const TIFFField TWebPFields[]
static
Initial value:
= {
FALSE, "WEBP quality", NULL},
TRUE, FALSE, "WEBP lossless/lossy", NULL},
FIELD_PSEUDO, TRUE, FALSE, "WEBP exact lossless", 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_WEBP_LEVEL
Pseudo-tag: WebP quality setting.
Definition tiff.h:1657
#define TIFFTAG_WEBP_LOSSLESS_EXACT
Pseudo-tag: Preserve RGB values under fully transparent pixels in lossless WebP.
Definition tiff.h:1669
#define TIFFTAG_WEBP_LOSSLESS
Pseudo-tag: WebP lossless/lossy.
Definition tiff.h:1659

Define WebP quality lossless and exact pseudo-tags.

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

Definition at line 1136 of file tif_webp.c.

Referenced by TIFFInitWebP().