Table of Contents

Class AvifReaderOptions

Namespace
Egami.Formats.Avif
Assembly
Egami.dll

Options for reading AVIF.

public sealed record AvifReaderOptions : ReaderOptions, IEquatable<ReaderOptions>, IEquatable<AvifReaderOptions>
Inheritance
AvifReaderOptions
Implements
Inherited Members

Examples

// Load decodes the AV1 image, converts it to RGB the way libavif does, and crops the clean aperture.
using Raster image = Raster.Load("duck.avif");

// The image as coded, without the film grain its AV1 stream asks the decoder to add.
using Raster clean = Raster.Load("duck.avif", options: new AvifReaderOptions { FilmGrain = false });
AvifFilmGrain? grain = ((AvifDetails)clean.Metadata.FormatDetails!).FilmGrain;   // null when there is none

Properties

FilmGrain

Gets whether the film grain an AV1 image carries is added to its pixels, as the AV1 specification's output process does (the default, true), or left out, giving the image as coded; the parameters are in FilmGrain either way.

public bool FilmGrain { get; init; }

Property Value

bool

Layer

Gets the layer of a layered (progressive) image to load, counted from 0 for the first and lowest quality one in decoding order, or null (the default) for the layer the file picks with its lsel property, else the best. A layer past the last gives the last; a layer smaller than the image is scaled up to its full size. Images that are not layered ignore it; Layers lists the layers.

public int? Layer { get; init; }

Property Value

int?

Examples

// A progressive file: a small first layer a viewer can show early, then the image (as avifenc --progressive writes it).
duck.Save("duck-progressive.avif", new AvifWriterOptions { Quality = 60, Progressive = true });

// Or up to four layers, each with its own quality and size; the last is the image at full size.
duck.Save("duck-layers.avif", new AvifWriterOptions
{
    Layers = [new AvifLayer { Quality = 20, Scale = 0.5 }, new AvifLayer { Quality = 45 }, new AvifLayer { Quality = 75 }],
});

// Load gives the best layer; AvifReaderOptions.Layer picks another, at full size.
using Raster best = Raster.Load("duck-layers.avif");
IReadOnlyList<Size> layers = ((AvifDetails)best.Metadata.FormatDetails!).Layers;   // 160x120, 320x240, 320x240
using Raster first = Raster.Load("duck-layers.avif", options: new AvifReaderOptions { Layer = 0 });

Exceptions

ArgumentOutOfRangeException

The value is negative.

SampleTransform

Gets whether a sample transform derived image (a sato item, AVIF 1.2.0) that the file prefers to its primary image is applied, giving its output at its own depth, such as 16 bits from a 12-bit image and an 8-bit residual (the default, true), or left out, giving the primary image the file keeps as the fallback for readers without sample transforms.

public bool SampleTransform { get; init; }

Property Value

bool

Examples

// 16 bits a sample, which AV1 cannot code, as a sample transform (AVIF 1.2): a 12-bit image and an 8-bit residual (or,
// lossless, the high and low bytes), with the first image as the fallback for readers without sample transforms.
using Raster<Rgb16> wide = duck.As<Rgb16>();
wide.Save("duck-16bit.avif", new AvifWriterOptions { BitDepth = 16, Quality = 90 });
using Raster deep = Raster.Load("duck-16bit.avif");
bool transformed = ((AvifDetails)deep.Metadata.FormatDetails!).HasSampleTransform;   // true, at 16 bits
using Raster fallback = Raster.Load("duck-16bit.avif", options: new AvifReaderOptions { SampleTransform = false });