Module color.storage
Compact encoded-sRGB storage values.
SRgb8 stores encoded sRGB red, green, and blue bytes. SRgba8 adds a
straight-alpha byte while keeping the RGB bytes independent of opacity.
Both are deliberately distinct from the floating-point computational color
types.
Storage/computational conversion is explicit. Byte storage normalizes through division by 255; checked conversion back to storage rejects values outside inclusive [0, 1] and uses nearest-byte half-up quantization. It does not implicitly clip, gamut-map, or repair special values.
Storage Model
The packed layouts are:
SRgb8
r : ubyte
g : ubyte
b : ubyte
SRgba8
r : ubyte
g : ubyte
b : ubyte
a : ubyte
SRgb8 is exactly three bytes in R/G/B order. SRgba8 is exactly
four bytes in R/G/B/A order. Both use byte alignment.
Alpha Model
SRgba8 is straight alpha: 0 is fully transparent and 255 is fully
opaque. RGB bytes are not premultiplied and remain independently stored,
including when alpha is zero.
Default State
SRgb8 is encoded sRGB black. SRgba8 is transparent
black.
Allocation
Both storage types are plain values with no hidden allocation or ownership.
Conversion
Storage to computation is total and normalized. Computation to storage is checked; out-of-range values, NaN, and infinities fail without modifying caller-owned output.
Hex Interop
SRgb8 uses exactly #RRGGBB; SRgba8 uses exactly
#RRGGBBAA. Parsing accepts upper- or lowercase hexadecimal digits.
Serialization is deterministic lowercase and returns fixed-size character
arrays without allocation.
Compile Time
Aggregate construction and the public conversion operations are usable at CTFE.
See Also
color.rgb, color.alpha
Functions
| Name | Description |
|---|---|
parseSRgb8Hex(text)
|
Parses #RRGGBB and returns a typed public failure when parsing fails.
|
parseSRgba8Hex(text)
|
Parses #RRGGBBAA and returns a typed public failure when parsing fails.
|
toSRgb8Result(value)
|
Checked computational-to-storage conversion with a typed public result. |
toSRgba8Result(value)
|
Checked straight-alpha computational-to-storage conversion with a typed result. |
tryParseSRgb8Hex(text, output)
|
Tries to parse exact six-digit hexadecimal encoded-sRGB storage. |
tryParseSRgba8Hex(text, output)
|
Tries to parse exact eight-digit hexadecimal encoded-sRGB straight-alpha storage. |
tryToSRgb8(value, output)
|
Tries to quantize normalized encoded sRGB into SRgb8.
|
tryToSRgba8(value, output)
|
Tries to quantize normalized straight-alpha encoded sRGB into SRgba8.
|
Structs
| Name | Description |
|---|---|
SRgb8
|
Packed 8-bit encoded-sRGB storage. |
SRgba8
|
Packed 8-bit encoded-sRGB storage with straight alpha. |
Enums
| Name | Description |
|---|---|
ColorParseError
|
Errors returned by Result-based hexadecimal storage parsing. |
ColorStorageError
|
Errors returned by Result-based computational-to-storage conversion. |