Skip to main content

Crate webpkit

Crate webpkit 

Source
Expand description

webpkit — a pure-Rust WebP codec: lossless (VP8L) and lossy (VP8) behind one API.

This is the umbrella crate. decode reads any still WebP file, inspecting the container to route VP8L payloads to the [crate::lossless] (lossless) decoder and VP8 payloads to the [crate::lossy] (lossy) decoder; both return the shared Image type. A lossy image’s sibling ALPH alpha chunk is composited here, where both codecs are in scope. The type-state Encoder writes output with either codec — Encoder::lossless or Encoder::lossy — sharing the effort/metadata knobs (only the lossy builder has a quality). The container framing, image model, and error type are defined once in crate and re-exported here.

Like the codec crates it wraps, this crate forbids unsafe, has zero required runtime dependencies, and targets no_std (with alloc).

§Status

Lossless decode/encode is complete (see [crate::lossless]). Lossy (VP8) decoding reconstructs baseline key frames (via [crate::lossy]), composites a separate ALPH alpha channel, and decodes lossy animations (frames dispatched into the lossless codec’s compositor). The unified IncrementalDecoder streams any still or animation, row-streaming a bare lossy VP8 still through [crate::lossy]. Lossy encoding (Encoder::lossy) writes a baseline VP8 key frame, carrying a lossless ALPH alpha plane for non-opaque images and ICC/Exif/XMP Metadata via the extended VP8X container (Encoder::encode preserves a source Image’s metadata by default).

Structs§

AnimInfo
Canvas-wide animation parameters, from the VP8X and ANIM chunks.
AnimationEncoder
A type-state builder for animated (ANIM/ANMF) WebP files.
CompositedFrame
A composited animation frame: the whole canvas at one point in time, plus how long it is shown.
DecodeOptions
Options controlling a decode.
DecodedFrame
A decoded animation frame’s native-ARGB pixels plus its compositing-relevant alpha flag (libwebp keys the compositor on the declared/ALPH-present flag, not a pixel scan).
Dimensions
A validated image size: both sides lie in 1..=16384.
Encoder
A builder that encodes an image into a complete WebP file with one codec.
Frame
A decoded animation frame: its metadata plus its own (frame-sized) pixels.
FrameMeta
A single frame’s placement and timing within the animation.
FramePayload
The located sub-chunk payloads of one ANMF animation frame, handed to a FrameDecoder. Exactly one of vp8l/vp8 is Some for a well-formed frame.
Image
A decoded image: pixels in a chosen PixelLayout plus size, alpha, and sidecar Metadata.
ImageInfo
A summary of an image, obtainable before a full decode.
ImageRef
A borrowed view of pixels to encode: size, layout, and a byte slice.
IncrementalDecoder
A push-based decoder for any still WebP or animation.
Lossless
Type-state marker: a lossless (VP8L) Encoder.
Lossy
Type-state marker: a lossy (VP8 ) Encoder.
Metadata
Optional sidecar metadata carried by a WebP extended (VP8X) container.
RowDrain
A zero-copy borrow of contiguous finalized rows, yielded by a decoder’s drain_rows.
WebpFrameDecoder
The umbrella’s FrameDecoder: the seam that drives both codecs.

Enums§

BlendMode
How a frame combines with the canvas underneath it.
Codec
Which of the two WebP bitstream codecs a bitstream error refers to.
DisposalMode
What happens to a frame’s rectangle after the frame has been displayed.
Effort
How hard an encoder searches for a smaller result.
Error
Errors returned by the WebP codecs (VP8L lossless, VP8 lossy) and this shell crate.
MetadataPolicy
How an encoder treats the metadata inherited from a source Image.
PixelLayout
The byte order of a pixel buffer at the API boundary.
Progress
Progress reported by a push-based decoder’s push.

Constants§

DEFAULT_MAX_PIXELS
The pixel cap (width * height) a default DecodeOptions applies — the safe-by-default guard against a hostile header that claims a huge image to exhaust memory.
MAX_DIMENSION
Largest image side any WebP bitstream can express, in pixels.

Traits§

FrameDecoder
Decodes one located animation frame (FramePayload) into pixels.

Functions§

decode
Decode a still WebP file — lossless (VP8L) or lossy (VP8 ) — into an Image (RGBA8 by default), dispatching on the container’s image chunk.
decode_frames
Decode an animated WebP into a lazy Frames iterator.
decode_frames_with
Like decode_frames with explicit DecodeOptions (output layout, per-frame pixel limit); the both-codecs WebpFrameDecoder is always wired in.
decode_frames_with_decoder
Decode an animated WebP into a lazy [Frames] iterator, decoding each frame through the caller-supplied FrameDecoder.
decode_reader
Decode a still WebP read from any std::io::Read source into an Image.
decode_rgba
Decode a still WebP straight to its RGBA8 pixels and Dimensions.
decode_with
Decode a still WebP file into an Image with explicit DecodeOptions (output layout, pixel limit), dispatching on the container’s image chunk.
encode_lossless_rgba
Encode an RGBA8 pixel buffer as a lossless (VP8L) WebP file.
encode_lossy_rgba
Encode an RGBA8 pixel buffer as a lossy (VP8 ) WebP file at quality.
incremental_decoder
A push-based IncrementalDecoder for still images and animations, with the lossy-frame hook wired so animated VP8 frames decode.
is_animated
Whether input is an animated WebP.
version
The crate version, as reported by Cargo.

Type Aliases§

CompositedFrames
A compositing iterator that paints each animation frame onto the persistent canvas (see [crate::anim::CompositedFrames]).
Frames
A lazy per-frame iterator over a WebP animation — each frame decoded by the both-codecs WebpFrameDecoder (lossless VP8L or lossy VP8 ).
Result
Result alias for WebP operations.