[][src]Function libwebp::WebPEncodeRGBA

pub fn WebPEncodeRGBA(
    rgba: &[u8],
    width: u32,
    height: u32,
    stride: u32,
    quality_factor: f32
) -> Result<WebpBox<[u8]>, WebPSimpleError>

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 lossy format, and the quality_factor can go from 0 (smaller output, lower quality) to 100 (best quality, larger output).

For lossless compression, you can use the WebPEncodeLosslessRGBA family.

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

Examples

use libwebp::WebPEncodeRGBA;

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();
assert_eq!(&data[..4], b"RIFF");
assert_eq!(&data[8..12], b"WEBP");