Function libwebp::WebPEncodeLosslessRGBA
source · pub fn WebPEncodeLosslessRGBA(
rgba: &[u8],
width: u32,
height: u32,
stride: u32
) -> Result<WebpBox<[u8]>, WebPSimpleError>Expand description
Encodes images pointed to by rgba and returns the WebP binary data.
The ordering of samples in memory is R, G, B, A, R, G, B, A… in scan order (endian-independent).
Compression
This function compresses using the lossless format. Files are usually larger than lossy format, but will not suffer any compression loss.
For lossy compression, you can use the WebPEncodeRGBA family.
Note these functions, like the lossy versions, use the library’s default
settings. For lossless this means exact is disabled. RGB values in
transparent areas will be modified to improve compression. To avoid this,
use WebPEncode() and set WebPConfig::exact to 1.
(The Rust binding does not yet have the corresponding function.)
Errors
Returns Err if data doesn’t contain a valid WebP header.
Panics
Panics when stride is too small or rgba has a wrong size.
Variants
WebPEncodeLosslessRGBAWebPEncodeLosslessBGRAWebPEncodeLosslessRGBWebPEncodeLosslessBGR
Examples
use libwebp::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 = WebPEncodeLosslessRGBA(buf, 2, 2, 8).unwrap();
assert_eq!(&data[..4], b"RIFF");
assert_eq!(&data[8..12], b"WEBP");