Struct ravif::Encoder

source ·
pub struct Encoder { /* private fields */ }
Expand description

Encoder config builder

Implementations§

source§

impl Encoder

Builder methods

source

pub fn new() -> Self

Start here

source

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

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

source

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

Depth 8 or 10. None picks automatically.

source

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

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

source

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.

source

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.

source

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.

source

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

source

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.

source

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_rgb = pixels_u8.as_rgb();

returns AVIF file, size of color metadata

source

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

source

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§

source§

impl Clone for Encoder

source§

fn clone(&self) -> Encoder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Encoder

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.