Expand description
libwebp
This is a binding to the libwebp library.
Usage
Preparation
# Cargo.toml
[dependencies]
libwebp = { version = "0.1.2", features = ["0_6"] }
Simple decoding
You can use WebPDecodeRGBA or WebPDecodeRGBAInto families for
simple decoding.
use libwebp::WebPDecodeRGBA;
let data: &[u8];
let (width, height, buf) = WebPDecodeRGBA(data).unwrap();
assert_eq!(buf.len(), width as usize * height as usize * 4);
eprintln!("width = {}, height = {}", width, height);
eprintln!(
"top-left pixel: rgba({}, {}, {}, {})",
buf[0],
buf[1],
buf[2],
buf[3] as f64 / 255.0,
)Simple encoding
You can use WebPEncodeRGBA or WebPEncodeLosslessRGBA families for
simple encoding.
use libwebp::{WebPEncodeRGBA, WebPEncodeLosslessRGBA};
let buf: &[u8] = &[
255, 255, 255, 255, // white
255, 0, 0, 255, // red
0, 255, 0, 255, // green
0, 0, 255, 255, // blue
];
let data = WebPEncodeRGBA(buf, 2, 2, 8, 75.0).unwrap();
let lossless_data = WebPEncodeLosslessRGBA(buf, 2, 2, 8).unwrap();
assert_eq!(&data[..4], b"RIFF");
assert_eq!(&data[8..12], b"WEBP");
assert_eq!(&lossless_data[..4], b"RIFF");
assert_eq!(&lossless_data[8..12], b"WEBP");Modules
Structs
Enums
Functions
Same as
WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B…
ordered data.Same as
WebPDecodeRGBAInto, but returning A, R, G, B, A, R, G, B…
ordered data.Same as
WebPDecodeRGBA, but returning B, G, R, B, G, R… ordered data.Same as
WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A…
ordered data.Same as
WebPDecodeRGBAInto, but returning B, G, R, A, B, G, R, A…
ordered data.Same as
WebPDecodeRGBAInto, but returning B, G, R, B, G, R…
ordered data.Same as
WebPDecodeRGBA, but returning R, G, B, R, G, B… ordered data.Decodes WebP images pointed to by
data and returns RGBA samples, along
with the dimensions (width and height).Decodes WebP images pointed to by
data and writes RGBA samples to
output_buffer.Same as
WebPDecodeRGBAInto, but returning R, G, B, R, G, B…
ordered data.Decodes WebP images pointed to by
data to Y’UV format1.A variant of
WebPDecodeYUVInto that operates directly into
pre-allocated buffers.Same as
WebPEncodeRGBA, but expecting B, G, R, B, G, R…
ordered data.Same as
WebPEncodeRGBA, but expecting B, G, R, A, B, G, R, A…
ordered data.Same as
WebPEncodeLosslessRGBA, but expecting B, G, R, B, G, R…
ordered data.Same as
WebPEncodeLosslessRGBA, but expecting B, G, R, A, B, G, R, A…
ordered data.Same as
WebPEncodeLosslessRGBA, but expecting R, G, B, R, G, B…
ordered data.Encodes images pointed to by
rgba and returns the WebP binary data.Same as
WebPEncodeRGBA, but expecting R, G, B, R, G, B…
ordered data.Encodes images pointed to by
rgba and returns the WebP binary data.Return the decoder’s version number, packed in hexadecimal using 8bits for
each of major/minor/revision.
Return the encoder’s version number, packed in hexadecimal using 8bits for
each of major/minor/revision.
Retrieve basic header information: width, height.