pub struct Encoder { /* private fields */ }
Expand description
Encoder config builder
Implementations§
Source§impl Encoder
Builder methods
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_depth(self, depth: Option<u8>) -> Self
pub fn with_depth(self, depth: Option<u8>) -> Self
Depth 8 or 10. None
picks automatically.
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_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
Once done with config, call one of the encode_*
functions
impl Encoder
Once done with config, call one of the encode_*
functions
Sourcepub fn encode_rgba(
&self,
in_buffer: Img<&[RGBA<u8>]>,
) -> Result<EncodedImage, Error>
pub fn encode_rgba( &self, in_buffer: Img<&[RGBA<u8>]>, ) -> 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, the alpha channel will be left out automatically.
This function takes 8-bit inputs, but will generate an AVIF file using 10-bit depth.
returns AVIF file with info about sizes about AV1 payload.
Sourcepub fn encode_rgb(&self, buffer: Img<&[RGB8]>) -> Result<EncodedImage, Error>
pub fn encode_rgb(&self, buffer: Img<&[RGB8]>) -> Result<EncodedImage, Error>
Sourcepub fn encode_raw_planes_8_bit(
&self,
width: usize,
height: usize,
planes: impl IntoIterator<Item = [u8; 3]> + Send,
alpha: Option<impl IntoIterator<Item = u8> + Send>,
color_pixel_range: PixelRange,
matrix_coefficients: MatrixCoefficients,
) -> Result<EncodedImage, Error>
pub fn encode_raw_planes_8_bit( &self, width: usize, height: usize, planes: impl IntoIterator<Item = [u8; 3]> + Send, alpha: Option<impl IntoIterator<Item = u8> + Send>, color_pixel_range: PixelRange, matrix_coefficients: MatrixCoefficients, ) -> Result<EncodedImage, Error>
Encodes AVIF from 3 planar channels that are in the color space described by matrix_coefficients
,
with sRGB transfer characteristics and color primaries.
Alpha always uses full range. Chroma subsampling is not supported, and it’s a bad idea for AVIF anyway.
If there’s no alpha, use None::<[_; 0]>
.
returns AVIF file, size of color metadata, size of alpha metadata overhead
Sourcepub fn encode_raw_planes_10_bit(
&self,
width: usize,
height: usize,
planes: impl IntoIterator<Item = [u16; 3]> + Send,
alpha: Option<impl IntoIterator<Item = u16> + Send>,
color_pixel_range: PixelRange,
matrix_coefficients: MatrixCoefficients,
) -> Result<EncodedImage, Error>
pub fn encode_raw_planes_10_bit( &self, width: usize, height: usize, planes: impl IntoIterator<Item = [u16; 3]> + Send, alpha: Option<impl IntoIterator<Item = u16> + Send>, color_pixel_range: PixelRange, matrix_coefficients: MatrixCoefficients, ) -> Result<EncodedImage, Error>
Encodes AVIF from 3 planar channels that are in the color space described by matrix_coefficients
,
with sRGB transfer characteristics and color primaries.
The pixels are 10-bit (values 0.=1023
).
Alpha always uses full range. Chroma subsampling is not supported, and it’s a bad idea for AVIF anyway.
If there’s no alpha, use None::<[_; 0]>
.
returns AVIF file, size of color metadata, size of alpha metadata overhead
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Encoder
impl RefUnwindSafe for Encoder
impl Send for Encoder
impl Sync for Encoder
impl Unpin for Encoder
impl UnwindSafe for Encoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more