Table of Contents

Struct ColorCodePoints

Namespace
Egami.Colors
Assembly
Egami.dll

The ITU-T H.273 code points that PNG's cICP chunk, AVIF and JPEG XL use to name a color encoding: colour primaries, transfer characteristics, matrix coefficients and the full-range flag, kept exactly as stored so codes Egami does not know round-trip.

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

Examples

// H.273 code points, as PNG cICP, AVIF and JPEG XL store them, name an encoding in four bytes.
ColorCodePoints pq = ColorCodePoints.Rec2100Pq;
ColorProfile? profile = ColorProfile.FromCodePoints(pq);              // Rec. 2100 PQ
ColorCodePoints? back = ColorProfile.DisplayP3.ToCodePoints();         // 12, 13, 0, full range

Constructors

ColorCodePoints(byte, byte, byte, bool)

The ITU-T H.273 code points that PNG's cICP chunk, AVIF and JPEG XL use to name a color encoding: colour primaries, transfer characteristics, matrix coefficients and the full-range flag, kept exactly as stored so codes Egami does not know round-trip.

public ColorCodePoints(byte Primaries, byte TransferCharacteristics, byte MatrixCoefficients, bool FullRange)

Parameters

Primaries byte

The colour primaries code: 1 for BT.709, 9 for BT.2020, 12 for Display P3.

TransferCharacteristics byte

The transfer characteristics code: 1 for BT.709, 8 for linear, 13 for sRGB, 16 for PQ, 18 for HLG.

MatrixCoefficients byte

The matrix coefficients code: 0 for RGB, which is what still images use.

FullRange bool

Whether samples use the full range (true for RGB images) rather than the video range.

Examples

// H.273 code points, as PNG cICP, AVIF and JPEG XL store them, name an encoding in four bytes.
ColorCodePoints pq = ColorCodePoints.Rec2100Pq;
ColorProfile? profile = ColorProfile.FromCodePoints(pq);              // Rec. 2100 PQ
ColorCodePoints? back = ColorProfile.DisplayP3.ToCodePoints();         // 12, 13, 0, full range

Properties

FullRange

Whether samples use the full range (true for RGB images) rather than the video range.

public bool FullRange { get; init; }

Property Value

bool

MatrixCoefficients

The matrix coefficients code: 0 for RGB, which is what still images use.

public byte MatrixCoefficients { get; init; }

Property Value

byte

Primaries

The colour primaries code: 1 for BT.709, 9 for BT.2020, 12 for Display P3.

public byte Primaries { get; init; }

Property Value

byte

Rec2100Hlg

Gets the code points of Rec. 2100 HLG: BT.2020 primaries, the HLG transfer, RGB, full range.

public static ColorCodePoints Rec2100Hlg { get; }

Property Value

ColorCodePoints

Rec2100Pq

Gets the code points of Rec. 2100 PQ: BT.2020 primaries, the PQ transfer, RGB, full range.

public static ColorCodePoints Rec2100Pq { get; }

Property Value

ColorCodePoints

Srgb

Gets the code points of sRGB: BT.709 primaries, the sRGB transfer, RGB, full range.

public static ColorCodePoints Srgb { get; }

Property Value

ColorCodePoints

TransferCharacteristics

The transfer characteristics code: 1 for BT.709, 8 for linear, 13 for sRGB, 16 for PQ, 18 for HLG.

public byte TransferCharacteristics { get; init; }

Property Value

byte

Methods

GetPrimaries()

Returns the primaries the code names, or null for a code Egami cannot use (unspecified, reserved, or XYZ).

public ColorPrimaries? GetPrimaries()

Returns

ColorPrimaries

The primaries, or null.

GetTransferFunction()

Returns the transfer function the code names, or null for a code Egami does not implement.

public TransferFunction? GetTransferFunction()

Returns

TransferFunction

The transfer function, or null.

TryGetYuvColor(ChromaSiting, out YuvColor)

Gets how YUV samples tagged with these code points turn into RGB: the matrix MatrixCoefficients names and the range FullRange gives, with the chroma siting the container states separately. See TryFromH273(int, bool, ChromaSiting, out YuvColor).

public bool TryGetYuvColor(ChromaSiting siting, out YuvColor color)

Parameters

siting ChromaSiting

Where chroma sits, which the code points do not carry.

color YuvColor

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

Returns

bool

true if the matrix code is known: 0, 1, 5, 6 or 9.

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);