Skip to main content

Crate tiny_webp

Crate tiny_webp 

Source
Expand description

Encodes RGB and RGBA pixel buffers as lossy WebP files.

Version 0.1.0 writes one VP8 key frame in a RIFF WebP container. It uses DC prediction, the Y2 transform path, one token partition, and a fixed quantizer chosen from Options::quality. The encoder keeps exact alpha from non-opaque RGBA input in an uncompressed ALPH chunk.

The library is no_std and allocates through alloc. It reads and writes byte slices in memory. Callers own file and stream I/O.

Options is #[non_exhaustive], so build one from its default and assign the fields that change.

let mut opts = tiny_webp::Options::default();
opts.quality = 90;
opts.alpha = tiny_webp::Alpha::Discard;

let rgba = [128u8; 16];
let webp = tiny_webp::encode_rgba(&rgba, 2, 2, &opts)?;
assert_eq!(&webp[..4], b"RIFF");

Structs§

Options
Settings for one encode.

Enums§

Alpha
What the encoder does with the alpha plane of an RGBA input.
Error
A call the encoder refused.
Filter
The loop filter strength the encoder signals in the frame header.

Constants§

MAX_DIMENSION
Largest width or height a WebP bitstream carries, in pixels.

Functions§

encode_rgb
Encodes an RGB buffer into the bytes of a WebP file.
encode_rgba
Encodes an RGBA buffer into the bytes of a WebP file.