Struct Aviffy

Source
pub struct Aviffy { /* private fields */ }
Expand description

Config for the serialization (allows setting advanced image properties).

See Aviffy::new.

Implementations§

Source§

impl Aviffy

Source

pub fn new() -> Self

You will have to set image properties to match the AV1 bitstream.

You can get this information out of the AV1 payload with avif-parse.

Source

pub fn set_matrix_coefficients( &mut self, matrix_coefficients: MatrixCoefficients, ) -> &mut Self

If set, must match the AV1 color payload, and will result in colr box added to AVIF. Defaults to BT.601, because that’s what Safari assumes when colr is missing. Other browsers are smart enough to read this from the AV1 payload instead.

Source

pub fn set_transfer_characteristics( &mut self, transfer_characteristics: TransferCharacteristics, ) -> &mut Self

If set, must match the AV1 color payload, and will result in colr box added to AVIF. Defaults to sRGB.

Source

pub fn set_color_primaries( &mut self, color_primaries: ColorPrimaries, ) -> &mut Self

If set, must match the AV1 color payload, and will result in colr box added to AVIF. Defaults to sRGB/Rec.709.

Source

pub fn set_full_color_range(&mut self, full_range: bool) -> &mut Self

If set, must match the AV1 color payload, and will result in colr box added to AVIF. Defaults to full.

Source

pub fn write<W: Write>( &self, into_output: W, color_av1_data: &[u8], alpha_av1_data: Option<&[u8]>, width: u32, height: u32, depth_bits: u8, ) -> Result<()>

Makes an AVIF file given encoded AV1 data (create the data with rav1e)

color_av1_data is already-encoded AV1 image data for the color channels (YUV, RGB, etc.). The color image should have been encoded without chroma subsampling AKA YUV444 (Cs444 in rav1e) AV1 handles full-res color so effortlessly, you should never need chroma subsampling ever again.

Optional alpha_av1_data is a monochrome image (rav1e calls it “YUV400”/Cs400) representing transparency. Alpha adds a lot of header bloat, so don’t specify it unless it’s necessary.

width/height is image size in pixels. It must of course match the size of encoded image data. depth_bits should be 8, 10 or 12, depending on how the image has been encoded in AV1.

Color and alpha must have the same dimensions and depth.

Data is written (streamed) to into_output.

Source

pub fn write_slice<W: Write>( &self, into_output: W, color_av1_data: &[u8], alpha_av1_data: Option<&[u8]>, ) -> Result<()>

Source

pub fn to_vec( &self, color_av1_data: &[u8], alpha_av1_data: Option<&[u8]>, width: u32, height: u32, depth_bits: u8, ) -> Vec<u8>

Panics if the input arguments were invalid. Use Self::write to handle the errors.

Source

pub fn set_chroma_subsampling( &mut self, subsampled_xy: (bool, bool), ) -> &mut Self

(false, false) is 4:4:4 (true, true) is 4:2:0

chroma_sample_position is always 0. Don’t use chroma subsampling with AVIF.

Source

pub fn set_monochrome(&mut self, monochrome: bool) -> &mut Self

Set whether the image is monochrome (grayscale). This is used to set the monochrome flag in the AV1 sequence header.

Source

pub fn set_exif(&mut self, exif: Vec<u8>) -> &mut Self

Set exif metadata to be included in the AVIF file as a separate item.

Source

pub fn set_seq_profile(&mut self, seq_profile: u8) -> &mut Self

Sets minimum required

Higher bit depth may increase this

Source

pub fn set_width(&mut self, width: u32) -> &mut Self

Source

pub fn set_height(&mut self, height: u32) -> &mut Self

Source

pub fn set_bit_depth(&mut self, bit_depth: u8) -> &mut Self

8, 10 or 12.

Source

pub fn set_premultiplied_alpha(&mut self, is_premultiplied: bool) -> &mut Self

Set whether image’s colorspace uses premultiplied alpha, i.e. RGB channels were multiplied by their alpha value, so that transparent areas are all black. Image decoders will be instructed to undo the premultiplication.

Premultiplied alpha images usually compress better and tolerate heavier compression, but may not be supported correctly by less capable AVIF decoders.

This just sets the configuration property. The pixel data must have already been processed before compression. If a decoder displays semitransparent colors too dark, it doesn’t support premultiplied alpha. If a decoder displays semitransparent colors too bright, you didn’t premultiply the colors before encoding.

If you’re not using premultiplied alpha, consider bleeding RGB colors into transparent areas, otherwise there may be unwanted outlines around edges of transparency.

Auto Trait Implementations§

§

impl Freeze for Aviffy

§

impl RefUnwindSafe for Aviffy

§

impl Send for Aviffy

§

impl Sync for Aviffy

§

impl Unpin for Aviffy

§

impl UnwindSafe for Aviffy

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.