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§
- Anim
Info - Canvas-wide animation parameters, from the
VP8XandANIMchunks. - Animation
Encoder - A type-state builder for animated (
ANIM/ANMF) WebP files. - Composited
Frame - A composited animation frame: the whole canvas at one point in time, plus how long it is shown.
- Decode
Options - Options controlling a decode.
- Decoded
Frame - 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.
- Frame
Meta - A single frame’s placement and timing within the animation.
- Frame
Payload - The located sub-chunk payloads of one
ANMFanimation frame, handed to aFrameDecoder. Exactly one ofvp8l/vp8isSomefor a well-formed frame. - Image
- A decoded image: pixels in a chosen
PixelLayoutplus size, alpha, and sidecarMetadata. - Image
Info - A summary of an image, obtainable before a full decode.
- Image
Ref - A borrowed view of pixels to encode: size, layout, and a byte slice.
- Incremental
Decoder - 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. - Webp
Frame Decoder - The umbrella’s
FrameDecoder: the seam that drives both codecs.
Enums§
- Blend
Mode - How a frame combines with the canvas underneath it.
- Codec
- Which of the two WebP bitstream codecs a bitstream error refers to.
- Disposal
Mode - 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.
- Metadata
Policy - How an encoder treats the metadata inherited from a source
Image. - Pixel
Layout - 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 defaultDecodeOptionsapplies — 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§
- Frame
Decoder - Decodes one located animation frame (
FramePayload) into pixels.
Functions§
- decode
- Decode a still WebP file — lossless (
VP8L) or lossy (VP8) — into anImage(RGBA8 by default), dispatching on the container’s image chunk. - decode_
frames - Decode an animated WebP into a lazy
Framesiterator. - decode_
frames_ with - Like
decode_frameswith explicitDecodeOptions(output layout, per-frame pixel limit); the both-codecsWebpFrameDecoderis always wired in. - decode_
frames_ with_ decoder - Decode an animated WebP into a lazy [
Frames] iterator, decoding each frame through the caller-suppliedFrameDecoder. - decode_
reader - Decode a still WebP read from any
std::io::Readsource into anImage. - decode_
rgba - Decode a still WebP straight to its RGBA8 pixels and
Dimensions. - decode_
with - Decode a still WebP file into an
Imagewith explicitDecodeOptions(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 atquality. - incremental_
decoder - A push-based
IncrementalDecoderfor still images and animations, with the lossy-frame hook wired so animatedVP8frames decode. - is_
animated - Whether
inputis an animated WebP. - version
- The crate version, as reported by Cargo.
Type Aliases§
- Composited
Frames - 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(losslessVP8Lor lossyVP8). - Result
- Result alias for WebP operations.