Struct SRgba8

Packed 8-bit encoded-sRGB storage with straight alpha.

struct SRgba8;

RGB components are unsigned encoded-sRGB bytes. a is straight opacity: 0 is fully transparent and 255 is fully opaque. RGB bytes are never premultiplied by alpha; hidden RGB remains stored even at zero alpha.

This type does not implicitly convert to floating-point straight-alpha or premultiplied computational representations. Construction performs no normalization, clipping, transfer conversion, alpha conversion, or gamut mapping.

Fields

NameTypeDescription
a ubyteStraight-alpha byte: 0 is transparent, 255 is opaque.
b ubyteBlue encoded-sRGB byte.
g ubyteGreen encoded-sRGB byte.
r ubyteRed encoded-sRGB byte.

Methods

NameDescription
toAlphaSRgb () Converts packed RGBA bytes to normalized straight-alpha encoded sRGB.
toHex () Serializes this byte value as canonical eight-digit hexadecimal RGBA.

Aliases

NameDescription
Channel Storage channel type for RGB and alpha.

Layout

Exactly four bytes in red, green, blue, alpha order: r at byte 0, g at byte 1, b at byte 2, and a at byte 3.

Default

.init is SRgba8(0, 0, 0, 0), transparent black.

Example

enum translucentAccent = SRgba8(0x24, 0x7A, 0xC4, 0x80);

static assert(translucentAccent.r == 0x24);
static assert(translucentAccent.g == 0x7A);
static assert(translucentAccent.b == 0xC4);
static assert(translucentAccent.a == 0x80);

// Straight alpha keeps RGB independent from opacity.
enum transparentAccent = SRgba8(0x24, 0x7A, 0xC4, 0);
static assert(transparentAccent.r == 0x24);
static assert(transparentAccent.g == 0x7A);
static assert(transparentAccent.b == 0xC4);