Struct Encoder

struct Encoder { ... }

Encoder config builder

Implementations

impl Encoder

fn new() -> Self

Start here

fn with_quality(self: Self, quality: f32) -> Self

Quality 1..=100. Panics if out of range.

fn with_depth(self: Self, depth: Option<u8>) -> Self

Depth 8 or 10. None picks automatically.

fn with_alpha_quality(self: Self, quality: f32) -> Self

Quality for the alpha channel only. 1..=100. Panics if out of range.

fn with_speed(self: Self, speed: u8) -> Self

1..=10. 1 = very very slow, but max compression. 10 = quick, but larger file sizes and lower quality.

fn with_internal_color_space(self: 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.

fn with_num_threads(self: 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.

fn with_alpha_color_mode(self: Self, mode: AlphaColorMode) -> Self

Configure handling of color channels in transparent images

impl Encoder

fn encode_rgba(self: &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.

fn encode_rgb(self: &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_rgb = pixels_u8.as_rgb();

returns AVIF file, size of color metadata

fn encode_raw_planes_8_bit<impl IntoIterator<Item = [u8; 3]> + Send: IntoIterator<Item = [u8; 3]> + Send, impl IntoIterator<Item = u8> + Send: IntoIterator<Item = u8> + Send>(self: &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

fn encode_raw_planes_10_bit<impl IntoIterator<Item = [u16; 3]> + Send: IntoIterator<Item = [u16; 3]> + Send, impl IntoIterator<Item = u16> + Send: IntoIterator<Item = u16> + Send>(self: &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

impl Clone for Encoder

fn clone(self: &Self) -> Encoder

impl Debug for Encoder

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Freeze for Encoder

impl RefUnwindSafe for Encoder

impl Send for Encoder

impl Sync for Encoder

impl Unpin for Encoder

impl UnsafeUnpin for Encoder

impl UnwindSafe for Encoder

impl<T> Any for Encoder

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Encoder

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Encoder

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Encoder

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Encoder

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Encoder

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for Encoder

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Encoder

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Encoder

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>