Function ravif::encode_rgba [−][src]
pub fn encode_rgba(
buffer: Img<&[RGBA8]>,
config: &EncConfig
) -> Result<(Vec<u8>, usize, usize), Box<dyn Error + Send + Sync>>
Make a new AVIF image from RGBA pixels (non-premultiplied, alpha last)
Make the Img
for the buffer
like this:
ⓘ
Img::new(&pixels_rgba[..], width, height)
If you have pixels as u8
slice, then first do:
ⓘ
use rgb::ComponentSlice; let pixels_rgba = pixels_u8.as_rgba();
If all pixels are opaque, alpha channel will be left out automatically.
It’s highly recommended to apply cleared_alpha
first.
returns AVIF file, size of color metadata, size of alpha metadata overhead