pub struct Aviffy { /* private fields */ }
Expand description
Config for the serialization (allows setting advanced image properties).
See Aviffy::new
.
Implementations§
Source§impl Aviffy
impl Aviffy
Sourcepub fn new() -> Self
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
.
Sourcepub fn set_matrix_coefficients(
&mut self,
matrix_coefficients: MatrixCoefficients,
) -> &mut Self
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.
Sourcepub fn set_transfer_characteristics(
&mut self,
transfer_characteristics: TransferCharacteristics,
) -> &mut Self
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.
Sourcepub fn set_color_primaries(
&mut self,
color_primaries: ColorPrimaries,
) -> &mut Self
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.
Sourcepub fn set_full_color_range(&mut self, full_range: bool) -> &mut Self
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.
Sourcepub 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<()>
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
.
Sourcepub fn write_slice<W: Write>(
&self,
into_output: W,
color_av1_data: &[u8],
alpha_av1_data: Option<&[u8]>,
) -> Result<()>
pub fn write_slice<W: Write>( &self, into_output: W, color_av1_data: &[u8], alpha_av1_data: Option<&[u8]>, ) -> Result<()>
See Self::write
Sourcepub fn to_vec(
&self,
color_av1_data: &[u8],
alpha_av1_data: Option<&[u8]>,
width: u32,
height: u32,
depth_bits: u8,
) -> Vec<u8> ⓘ
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.
Sourcepub fn set_chroma_subsampling(
&mut self,
subsampled_xy: (bool, bool),
) -> &mut Self
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.
Sourcepub fn set_monochrome(&mut self, monochrome: bool) -> &mut Self
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.
Sourcepub fn set_exif(&mut self, exif: Vec<u8>) -> &mut Self
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.
Sourcepub fn set_seq_profile(&mut self, seq_profile: u8) -> &mut Self
pub fn set_seq_profile(&mut self, seq_profile: u8) -> &mut Self
Sets minimum required
Higher bit depth may increase this
pub fn set_width(&mut self, width: u32) -> &mut Self
pub fn set_height(&mut self, height: u32) -> &mut Self
Sourcepub fn set_bit_depth(&mut self, bit_depth: u8) -> &mut Self
pub fn set_bit_depth(&mut self, bit_depth: u8) -> &mut Self
8, 10 or 12.
Sourcepub fn set_premultiplied_alpha(&mut self, is_premultiplied: bool) -> &mut Self
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.