Skip to main content

Crate zenwebp

Crate zenwebp 

Source
Expand description

Decoding and Encoding of WebP Images

This crate provides both encoding and decoding of WebP images.

§Features

  • std (default): Enable standard library support including lossy encoding.
  • simd: Enable SIMD optimizations for faster encoding/decoding.
  • fast-yuv: Enable optimized YUV conversion.

§no_std Support

Decoding is fully supported in no_std environments (requires alloc):

[dependencies]
zenwebp = { version = "...", default-features = false }

All decoding functions take &[u8] slices directly - no Read/Seek traits required.

§Encoding (requires std)

Use the Encoder builder for a fluent API:

use zenwebp::{Encoder, Preset};

let rgba_data = vec![255u8; 4 * 4 * 4]; // 4x4 RGBA image
let webp = Encoder::new_rgba(&rgba_data, 4, 4)
    .preset(Preset::Photo)
    .quality(85.0)
    .encode()?;

Or use EncoderConfig for reusable configuration:

use zenwebp::{EncoderConfig, Preset};

let config = EncoderConfig::new().quality(85.0).preset(Preset::Photo);
let rgba_data = vec![255u8; 4 * 4 * 4];
let webp = config.encode_rgba(&rgba_data, 4, 4)?;

§Decoding

Use the convenience functions:

let webp_data: &[u8] = &[]; // your WebP data
let (pixels, width, height) = zenwebp::decode_rgba(webp_data)?;

Or the WebPDecoder for more control:

use zenwebp::WebPDecoder;

let webp_data: &[u8] = &[]; // your WebP data
let mut decoder = WebPDecoder::new(webp_data)?;
let (width, height) = decoder.dimensions();
let mut output = vec![0u8; decoder.output_buffer_size().unwrap()];
decoder.read_image(&mut output)?;

Re-exports§

pub use decoder::decode_rgb;
pub use decoder::decode_rgb_into;
pub use decoder::decode_rgba;
pub use decoder::decode_rgba_into;
pub use decoder::DecodingError;
pub use decoder::ImageInfo;
pub use decoder::LoopCount;
pub use decoder::UpsamplingMethod;
pub use decoder::WebPDecodeOptions;
pub use decoder::WebPDecoder;
pub use encoder::ColorType;
pub use encoder::Encoder;
pub use encoder::EncoderConfig;
pub use encoder::EncoderParams;
pub use encoder::EncodingError;
pub use encoder::Preset;
pub use encoder::WebPEncoder;
pub use decoder::vp8;

Modules§

common
Common types and utilities shared between encoder and decoder
decoder
WebP decoder implementation
encoder
WebP encoder implementation