Table of Contents

Struct YuvColor

Namespace
Egami.Pixels
Assembly
Egami.dll

How the samples of a YuvRaster turn into RGB: the matrix, the range and where chroma sits. Every load, wrap and conversion states one, so a picture is never read with a guessed matrix.

public readonly record struct YuvColor : IEquatable<YuvColor>
Implements
Inherited Members

Examples

// How samples turn into RGB is always stated: a preset, or the codes a video container carries (ITU-T H.273).
YuvColor jpeg = YuvColor.Jpeg;                                         // BT.601, full range, chroma centered
YuvColor custom = new(YuvMatrix.Bt709, YuvRange.Full, ChromaSiting.Left);
if (YuvColor.TryFromH273(matrixCoefficients: 9, fullRange: false, ChromaSiting.TopLeft, out YuvColor fromStream))
{
    Console.WriteLine($"{fromStream.Matrix}, {fromStream.Range}; back to code {fromStream.ToH273()}");
}

// Or straight from the code points an AVIF or PNG cICP box carries.
Egami.Colors.ColorCodePoints hdr10 = new(Primaries: 9, TransferCharacteristics: 16, MatrixCoefficients: 9, FullRange: false);
hdr10.TryGetYuvColor(ChromaSiting.TopLeft, out YuvColor fromBox);

Constructors

YuvColor(YuvMatrix, YuvRange, ChromaSiting)

How the samples of a YuvRaster turn into RGB: the matrix, the range and where chroma sits. Every load, wrap and conversion states one, so a picture is never read with a guessed matrix.

public YuvColor(YuvMatrix Matrix, YuvRange Range, ChromaSiting Siting)

Parameters

Matrix YuvMatrix

The matrix between RGB and luma-chroma.

Range YuvRange

Whether samples use the full range or the video range.

Siting ChromaSiting

Where subsampled chroma sits against luma.

Examples

// How samples turn into RGB is always stated: a preset, or the codes a video container carries (ITU-T H.273).
YuvColor jpeg = YuvColor.Jpeg;                                         // BT.601, full range, chroma centered
YuvColor custom = new(YuvMatrix.Bt709, YuvRange.Full, ChromaSiting.Left);
if (YuvColor.TryFromH273(matrixCoefficients: 9, fullRange: false, ChromaSiting.TopLeft, out YuvColor fromStream))
{
    Console.WriteLine($"{fromStream.Matrix}, {fromStream.Range}; back to code {fromStream.ToH273()}");
}

// Or straight from the code points an AVIF or PNG cICP box carries.
Egami.Colors.ColorCodePoints hdr10 = new(Primaries: 9, TransferCharacteristics: 16, MatrixCoefficients: 9, FullRange: false);
hdr10.TryGetYuvColor(ChromaSiting.TopLeft, out YuvColor fromBox);

Properties

Bt2020Limited

Gets UHD and HDR video: BT.2020 non-constant luminance, limited range, chroma on the top-left sample.

public static YuvColor Bt2020Limited { get; }

Property Value

YuvColor

Bt601Limited

Gets standard-definition video: BT.601, limited range, chroma on the left column.

public static YuvColor Bt601Limited { get; }

Property Value

YuvColor

Bt709Limited

Gets high-definition video: BT.709, limited range, chroma on the left column.

public static YuvColor Bt709Limited { get; }

Property Value

YuvColor

Jpeg

Gets JPEG's encoding (JFIF): BT.601, full range, chroma centered.

public static YuvColor Jpeg { get; }

Property Value

YuvColor

Matrix

The matrix between RGB and luma-chroma.

public YuvMatrix Matrix { get; init; }

Property Value

YuvMatrix

Range

Whether samples use the full range or the video range.

public YuvRange Range { get; init; }

Property Value

YuvRange

Siting

Where subsampled chroma sits against luma.

public ChromaSiting Siting { get; init; }

Property Value

ChromaSiting

Methods

ToH273()

Returns the ITU-T H.273 matrix_coefficients code of Matrix: 0, 1, 6 or 9.

public int ToH273()

Returns

int

The code.

TryFromH273(int, bool, ChromaSiting, out YuvColor)

Gets the color that ITU-T H.273's matrix_coefficients code and full-range flag name, as AV1, VP9, HEVC and CICP boxes carry them: 0 is identity (GBR), 1 BT.709, 5 and 6 BT.601, 9 BT.2020 non-constant luminance.

public static bool TryFromH273(int matrixCoefficients, bool fullRange, ChromaSiting siting, out YuvColor color)

Parameters

matrixCoefficients int

The H.273 code.

fullRange bool

The full-range flag.

siting ChromaSiting

Where chroma sits, which H.273 does not carry.

color YuvColor

The color, or the default when the code is not one Egami knows.

Returns

bool

true if the code names a matrix Egami knows; unknown codes return false rather than a guess.