Table of Contents

Struct YCbCrColor

Namespace
Egami.Colors
Assembly
Egami.dll

A Y'CbCr color: luma and two chroma differences of encoded sRGB, scaled as 8-bit codes / 255: at full range chroma is centered on 128 / 255, as JPEG and H.273 store it, so a byte reads as value × 255. The members without options use BT.601 at full range, as JPEG does; overloads take a YuvMatrix and YuvRange, from the coefficient table planar YUV images share.

public readonly record struct YCbCrColor : IColorValue<YCbCrColor>, IEquatable<YCbCrColor>
Implements
Inherited Members

Examples

// Color values in the models apps ask for, from and to pixels, and between each other.
Rgba8 orange = new(240, 128, 32, 255);
HslColor hsl = HslColor.From(orange);                          // hue 28°, saturation 0.87, lightness 0.53
LabColor lab = ColorConvert.Convert<HslColor, LabColor>(hsl);  // through XYZ
OklchColor oklch = OklchColor.From(orange);
YCbCrColor jpeg = YCbCrColor.From(orange);                     // BT.601 full range, as JPEG
YCbCrColor video = YCbCrColor.From(orange, YuvMatrix.Bt709, YuvRange.Limited);

// Color difference: CIEDE2000 on Lab, distance on Oklab.
double deltaE = lab.DeltaE2000(LabColor.From(new Rgba8(235, 130, 40, 255)));

// Whole rows at once, from any pixel type and encoding.
Rgba8[] pixels = [orange, new(10, 20, 30, 255)];
OklabColor[] row = new OklabColor[pixels.Length];
ColorConvert.FromPixels<Rgba8, OklabColor>(pixels, row);
ColorConvert.FromPixels<Rgba8, OklabColor>(pixels, row, ColorProfile.DisplayP3);   // the same pixels read as Display P3

Constructors

YCbCrColor(float, float, float)

A Y'CbCr color: luma and two chroma differences of encoded sRGB, scaled as 8-bit codes / 255: at full range chroma is centered on 128 / 255, as JPEG and H.273 store it, so a byte reads as value × 255. The members without options use BT.601 at full range, as JPEG does; overloads take a YuvMatrix and YuvRange, from the coefficient table planar YUV images share.

public YCbCrColor(float Y, float Cb, float Cr)

Parameters

Y float

Luma.

Cb float

Blue difference, 128 / 255 for gray.

Cr float

Red difference, 128 / 255 for gray.

Examples

// Color values in the models apps ask for, from and to pixels, and between each other.
Rgba8 orange = new(240, 128, 32, 255);
HslColor hsl = HslColor.From(orange);                          // hue 28°, saturation 0.87, lightness 0.53
LabColor lab = ColorConvert.Convert<HslColor, LabColor>(hsl);  // through XYZ
OklchColor oklch = OklchColor.From(orange);
YCbCrColor jpeg = YCbCrColor.From(orange);                     // BT.601 full range, as JPEG
YCbCrColor video = YCbCrColor.From(orange, YuvMatrix.Bt709, YuvRange.Limited);

// Color difference: CIEDE2000 on Lab, distance on Oklab.
double deltaE = lab.DeltaE2000(LabColor.From(new Rgba8(235, 130, 40, 255)));

// Whole rows at once, from any pixel type and encoding.
Rgba8[] pixels = [orange, new(10, 20, 30, 255)];
OklabColor[] row = new OklabColor[pixels.Length];
ColorConvert.FromPixels<Rgba8, OklabColor>(pixels, row);
ColorConvert.FromPixels<Rgba8, OklabColor>(pixels, row, ColorProfile.DisplayP3);   // the same pixels read as Display P3

Properties

Cb

Blue difference, 128 / 255 for gray.

public float Cb { get; init; }

Property Value

float

Cr

Red difference, 128 / 255 for gray.

public float Cr { get; init; }

Property Value

float

Y

Luma.

public float Y { get; init; }

Property Value

float

Methods

From(Rgba8)

Returns the value of an sRGB pixel; alpha is ignored.

public static YCbCrColor From(Rgba8 color)

Parameters

color Rgba8

The pixel.

Returns

YCbCrColor

The value.

From(Rgba8, YuvMatrix, YuvRange)

Returns the value of an sRGB pixel with a chosen matrix and range.

public static YCbCrColor From(Rgba8 color, YuvMatrix matrix, YuvRange range = YuvRange.Full)

Parameters

color Rgba8

The pixel.

matrix YuvMatrix

The matrix.

range YuvRange

The range. Defaults to full.

Returns

YCbCrColor

The value.

From(RgbaF32)

Returns the value of an sRGB pixel, whose channels may be outside 0..1; alpha is ignored.

public static YCbCrColor From(RgbaF32 color)

Parameters

color RgbaF32

The pixel.

Returns

YCbCrColor

The value.

From(RgbaF32, YuvMatrix, YuvRange)

Returns the value of an sRGB pixel with a chosen matrix and range.

public static YCbCrColor From(RgbaF32 color, YuvMatrix matrix, YuvRange range = YuvRange.Full)

Parameters

color RgbaF32

The pixel.

matrix YuvMatrix

The matrix.

range YuvRange

The range. Defaults to full.

Returns

YCbCrColor

The value.

FromXyz(XyzColor)

Returns the value for an XYZ color (D65, white Y = 1).

public static YCbCrColor FromXyz(XyzColor xyz)

Parameters

xyz XyzColor

The color.

Returns

YCbCrColor

The value; components may fall outside their usual range for colors outside sRGB.

IsCloseTo(YCbCrColor, float)

Returns whether every component of the two values differs by at most tolerance.

public bool IsCloseTo(YCbCrColor other, float tolerance = 0.0001)

Parameters

other YCbCrColor

The other value.

tolerance float

The largest difference allowed in a component.

Returns

bool

true if they are that close.

ToRgba8()

Returns the color as an opaque sRGB pixel, each channel clamped into range.

public Rgba8 ToRgba8()

Returns

Rgba8

The pixel.

ToRgba8(YuvMatrix, YuvRange)

Returns the color as an opaque sRGB pixel, read with a chosen matrix and range.

public Rgba8 ToRgba8(YuvMatrix matrix, YuvRange range = YuvRange.Full)

Parameters

matrix YuvMatrix

The matrix.

range YuvRange

The range. Defaults to full.

Returns

Rgba8

The pixel, each channel clamped.

ToRgbaF32()

Returns the color as an opaque sRGB pixel, unclamped, so colors outside sRGB keep channels outside 0..1.

public RgbaF32 ToRgbaF32()

Returns

RgbaF32

The pixel.

ToRgbaF32(YuvMatrix, YuvRange)

Returns the color as an opaque sRGB pixel, read with a chosen matrix and range, unclamped.

public RgbaF32 ToRgbaF32(YuvMatrix matrix, YuvRange range = YuvRange.Full)

Parameters

matrix YuvMatrix

The matrix.

range YuvRange

The range. Defaults to full.

Returns

RgbaF32

The pixel.

ToXyz()

Returns the color as XYZ (D65, white Y = 1).

public XyzColor ToXyz()

Returns

XyzColor

The color.