Table of Contents

Struct Rgb10A2

Namespace
Egami.Pixels
Assembly
Egami.dll

A 32-bit packed pixel: red in bits 0 to 9, green in 10 to 19, blue in 20 to 29 and straight alpha in 30 and 31. The same memory as the DXGI R10G10B10A2 and Vulkan A2B10G10R10 formats, used by 10-bit displays. Ten-bit levels round to the nearest 16-bit value and convert through Rgba16 exactly; two-bit alpha widens by multiplying.

public struct Rgb10A2 : IPixelType<Rgb10A2>, IEquatable<Rgb10A2>
Implements
Inherited Members

Examples

// Eight-bit, sixteen-bit and float pixels; every type converts to every other through PixelConvert.
Rgba8 orange = new(255, 128, 0, 255);
Bgr8 bgr = Bgr8.FromRgba8(orange);
Gray8 gray = Gray8.FromRgba8(orange);
GrayAlpha8 grayAlpha = new(gray.L, 128);
Gray16 deep = Gray16.FromRgba8(orange);
Rgba16 wide = new(65535, 32896, 0, 65535);
Rgb16 wideOpaque = Rgb16.FromRgba16(wide);           // exact: 16-bit to 16-bit never rounds
GrayAlpha16 deepMask = new(deep.L, 32768);
Argb8 alphaFirst = Argb8.FromRgba8(orange);             // bytes A, R, G, B
Alpha8 mask = Alpha8.FromRgba8(orange);                 // alpha only; reads back as black
RgbaF16 hdr = RgbaF16.FromScaled(new Vector4(4f, 2f, 0.5f, 1f)); // half floats keep values above 1
GrayF32 depth = new(12.5f);                              // floats hold any value until written to an integer type
Bgr565 packed = Bgr565.FromRgba8(orange);                // 5-6-5 levels in one ushort; rounds to the nearest level
Bgra5551 gdi16 = Bgra5551.FromRgba8(orange);             // 5-5-5 levels and a 1-bit alpha, the GDI+ 16-bit ARGB layout
Cmyk8 ink = Cmyk8.FromRgba8(orange);                     // inks by the plain formula: (0, 127, 255, 0)
PremulRgba8 glass = PremulRgba8.FromRgba8(new Rgba8(255, 128, 0, 128)); // stored (128, 64, 0, 128); converts back straight
RgbaF32 linear = RgbaF32.FromScaled(orange.ToScaled());

Rgba8[] row = [orange, Rgba8.Transparent];
Bgra8[] converted = new Bgra8[row.Length];
PixelConvert.Convert<Rgba8, Bgra8>(row, converted);

Constructors

Rgb10A2(int, int, int, int)

Initializes a new instance of the Rgb10A2 struct from channel levels.

public Rgb10A2(int r, int g, int b, int a)

Parameters

r int

The red level, 0 to 1023.

g int

The green level, 0 to 1023.

b int

The blue level, 0 to 1023.

a int

The alpha level, 0 to 3.

Exceptions

ArgumentOutOfRangeException

A level is out of its range.

Rgb10A2(uint)

Initializes a new instance of the Rgb10A2 struct from its packed value.

public Rgb10A2(uint value)

Parameters

value uint

The packed value.

Fields

Value

The packed value.

public uint Value

Field Value

uint

Properties

A

Gets the alpha level, 0 to 3.

public readonly int A { get; }

Property Value

int

B

Gets the blue level, 0 to 1023.

public readonly int B { get; }

Property Value

int

G

Gets the green level, 0 to 1023.

public readonly int G { get; }

Property Value

int

Layout

Gets the memory layout of this pixel type.

public static PixelLayoutInfo Layout { get; }

Property Value

PixelLayoutInfo

R

Gets the red level, 0 to 1023.

public readonly int R { get; }

Property Value

int

Methods

Equals(Rgb10A2)

Indicates whether the current object is equal to another object of the same type.

public readonly bool Equals(Rgb10A2 other)

Parameters

other Rgb10A2

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

FromRgba16(Rgba16)

Creates a pixel from a 16-bit color. Conversions between two integer types wider than 8 bits go through this, so they are exact wherever the type can hold the color. The default goes through FromScaled(Vector4); types with integer channels may override it with exact integer code.

public static Rgb10A2 FromRgba16(Rgba16 value)

Parameters

value Rgba16

The color.

Returns

Rgb10A2

The pixel.

FromRgba8(Rgba8)

Creates a pixel from an 8-bit color. The conversion is exact wherever the type can hold the color. Gray types take the Rec. 709 luma, weighted in linear light. Types without alpha drop it.

public static Rgb10A2 FromRgba8(Rgba8 value)

Parameters

value Rgba8

The color.

Returns

Rgb10A2

The pixel.

FromScaled(Vector4)

Creates a pixel from red, green, blue and alpha scaled to 0..1, with straight alpha. Values outside 0..1 are clamped and NaN becomes 0. Gray types take the Rec. 709 luma of the color, weighted in linear light. Types without alpha drop it.

public static Rgb10A2 FromScaled(Vector4 rgba)

Parameters

rgba Vector4

The color, with each channel scaled to 0..1.

Returns

Rgb10A2

The nearest pixel of this type.

GetHashCode()

Returns the hash code for this instance.

public override readonly int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToRgba16()

Returns the pixel as a 16-bit color. The default goes through ToScaled(); types with integer channels may override it with exact integer code.

public readonly Rgba16 ToRgba16()

Returns

Rgba16

The 16-bit color.

ToRgba8()

Returns the pixel as an 8-bit color. 16-bit channels are rounded to the nearest 8-bit value, and gray is copied to red, green and blue.

public readonly Rgba8 ToRgba8()

Returns

Rgba8

The 8-bit color.

ToScaled()

Returns red, green, blue and alpha scaled to 0..1. Types without alpha return an alpha of 1.

public readonly Vector4 ToScaled()

Returns

Vector4

The scaled color.

ToString()

Returns the fully qualified type name of this instance.

public override readonly string ToString()

Returns

string

The fully qualified type name.

Operators

operator ==(Rgb10A2, Rgb10A2)

Returns a value indicating whether two pixels are equal.

public static bool operator ==(Rgb10A2 left, Rgb10A2 right)

Parameters

left Rgb10A2

The first pixel.

right Rgb10A2

The second pixel.

Returns

bool

true if the packed values are equal.

operator !=(Rgb10A2, Rgb10A2)

Returns a value indicating whether two pixels differ.

public static bool operator !=(Rgb10A2 left, Rgb10A2 right)

Parameters

left Rgb10A2

The first pixel.

right Rgb10A2

The second pixel.

Returns

bool

true if the packed values differ.