pub struct Encoder { /* private fields */ }Expand description
Encoder config builder
Implementations§
source§impl Encoder
impl Encoder
Builder methods
sourcepub fn with_quality(self, quality: f32) -> Self
pub fn with_quality(self, quality: f32) -> Self
Quality 1..=100. Panics if out of range.
sourcepub fn with_alpha_quality(self, quality: f32) -> Self
pub fn with_alpha_quality(self, quality: f32) -> Self
Quality for the alpha channel only. 1..=100. Panics if out of range.
sourcepub fn with_speed(self, speed: u8) -> Self
pub fn with_speed(self, speed: u8) -> Self
1..=10. 1 = very very slow, but max compression. 10 = quick, but larger file sizes and lower quality.
sourcepub fn with_internal_color_space(self, color_space: ColorSpace) -> Self
pub fn with_internal_color_space(self, color_space: ColorSpace) -> Self
Changes how color channels are stored in the image. The default is YCbCr.
Note that this is only internal detail for the AVIF file, and doesn’t change color space of inputs to encode functions.
sourcepub fn with_internal_10_bit_depth(self, high_bit_depth: bool) -> Self
pub fn with_internal_10_bit_depth(self, high_bit_depth: bool) -> Self
Store color channels using 10-bit depth instead of the default 8-bit.
sourcepub fn with_num_threads(self, num_threads: Option<usize>) -> Self
pub fn with_num_threads(self, num_threads: Option<usize>) -> Self
Configures rayon thread pool size.
The default None is to use all threads in the default rayon thread pool.
sourcepub fn with_alpha_color_mode(self, mode: AlphaColorMode) -> Self
pub fn with_alpha_color_mode(self, mode: AlphaColorMode) -> Self
Configure handling of color channels in transparent images
source§impl Encoder
impl Encoder
Once done with config, call one of the encode_* functions
sourcepub fn encode_rgba(
&self,
in_buffer: Img<&[RGBA8]>
) -> Result<EncodedImage, Error>
pub fn encode_rgba(
&self,
in_buffer: Img<&[RGBA8]>
) -> Result<EncodedImage, Error>
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
sourcepub fn encode_rgb(&self, buffer: Img<&[RGB8]>) -> Result<EncodedImage, Error>
pub fn encode_rgb(&self, buffer: Img<&[RGB8]>) -> Result<EncodedImage, Error>
Make a new AVIF image from RGB pixels
Make the Img for the buffer like this:
Img::new(&pixels_rgb[..], width, height)If you have pixels as u8 slice, then first do:
use rgb::ComponentSlice;
let pixels_rgba = pixels_u8.as_rgb();returns AVIF file, size of color metadata
sourcepub fn encode_raw_planes_8_bit(
&self,
width: usize,
height: usize,
y_plane: &[u8],
u_plane: &[u8],
v_plane: &[u8],
a_plane: Option<&[u8]>,
color_pixel_range: PixelRange
) -> Result<EncodedImage, Error>
pub fn encode_raw_planes_8_bit(
&self,
width: usize,
height: usize,
y_plane: &[u8],
u_plane: &[u8],
v_plane: &[u8],
a_plane: Option<&[u8]>,
color_pixel_range: PixelRange
) -> Result<EncodedImage, Error>
If config.color_space is ColorSpace::YCbCr, then it takes 8-bit BT.709 color space.
Alpha always uses full range. Chroma subsampling is not supported, and it’s a bad idea for AVIF anyway.
returns AVIF file, size of color metadata, size of alpha metadata overhead