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§
- WebP
DecodeARGB - Same as
WebPDecodeRGBA
, but returning A, R, G, B, A, R, G, B… ordered data. - WebP
DecodeARGB Into - Same as
WebPDecodeRGBAInto
, but returning A, R, G, B, A, R, G, B… ordered data. - WebP
DecodeBGR - Same as
WebPDecodeRGBA
, but returning B, G, R, B, G, R… ordered data. - WebP
DecodeBGRA - Same as
WebPDecodeRGBA
, but returning B, G, R, A, B, G, R, A… ordered data. - WebP
DecodeBGRA Into - Same as
WebPDecodeRGBAInto
, but returning B, G, R, A, B, G, R, A… ordered data. - WebP
DecodeBGR Into - Same as
WebPDecodeRGBAInto
, but returning B, G, R, B, G, R… ordered data. - WebP
DecodeRGB - Same as
WebPDecodeRGBA
, but returning R, G, B, R, G, B… ordered data. - WebP
DecodeRGBA - Decodes WebP images pointed to by
data
and returns RGBA samples, along with the dimensions (width and height). - WebP
DecodeRGBA Into - Decodes WebP images pointed to by
data
and writes RGBA samples tooutput_buffer
. - WebP
DecodeRGB Into - Same as
WebPDecodeRGBAInto
, but returning R, G, B, R, G, B… ordered data. - WebP
DecodeYUV - Decodes WebP images pointed to by
data
to Y’UV format[^1]. - WebP
DecodeYUV Into - A variant of
WebPDecodeYUVInto
that operates directly into pre-allocated buffers. - WebP
EncodeBGR - Same as
WebPEncodeRGBA
, but expecting B, G, R, B, G, R… ordered data. - WebP
EncodeBGRA - Same as
WebPEncodeRGBA
, but expecting B, G, R, A, B, G, R, A… ordered data. - WebP
Encode LosslessBGR - Same as
WebPEncodeLosslessRGBA
, but expecting B, G, R, B, G, R… ordered data. - WebP
Encode LosslessBGRA - Same as
WebPEncodeLosslessRGBA
, but expecting B, G, R, A, B, G, R, A… ordered data. - WebP
Encode LosslessRGB - Same as
WebPEncodeLosslessRGBA
, but expecting R, G, B, R, G, B… ordered data. - WebP
Encode LosslessRGBA - Encodes images pointed to by
rgba
and returns the WebP binary data. - WebP
EncodeRGB - Same as
WebPEncodeRGBA
, but expecting R, G, B, R, G, B… ordered data. - WebP
EncodeRGBA - Encodes images pointed to by
rgba
and returns the WebP binary data. - WebP
GetDecoder Version - Return the decoder’s version number, packed in hexadecimal using 8bits for each of major/minor/revision.
- WebP
GetEncoder Version - Return the encoder’s version number, packed in hexadecimal using 8bits for each of major/minor/revision.
- WebP
GetInfo - Retrieve basic header information: width, height.
- WebPI
Append - WebPI
DecGetRGB - WebPI
DecGetYUVA - WebPI
NewDecoder - WebPI
NewRGB - WebPI
NewYUVA - WebP
IsAlpha Mode - WebP
IsPremultiplied Mode - WebP
IsRGB Mode