Function maxChromaInSRgb
Measures the maximum directly representable OKLCH chroma in sRGB for fixed lightness and hue.
The query starts at the achromatic in-gamut point C=0, brackets the first sRGB boundary along the canonical non-negative OKLCH chroma ray, and performs a fixed 24-step binary search. It returns the in-gamut side of the final bracket.
This is boundary measurement, not gamut mapping. No clipping, perceptual mapping, theme policy, allocation, or consumer-specific threshold is applied.
lightness must be finite and in [0, 1]. L=0 and L=1 return exactly zero. hue must contain a finite raw degree value; equivalent hue revolutions represent the same direction.
Invalid input produces an invalid SRgbChromaLimit whose value is NaN.
The numerical search is intentionally simple and deterministic. Twenty-four iterations were selected by the R5.1-R5.7 independent research programme: they provide a bounded approximation while preserving the strict in-gamut side of the bracket for both float and double. The iteration count is an implementation detail, not part of the API contract.
Parameters
| Name | Description |
|---|---|
| lightness | Fixed OKLCH lightness in [0, 1]. |
| hue | Fixed Oklab-family hue. |
Returns
A validated sRGB chroma limit, or an invalid measurement for invalid input.
Example
Basic valid boundary and strict in-gamut contract.
enum result =
maxChromaInSRgb!double(
0.5,
OklabHued .fromDegrees(264.0)
);
static assert(result .valid);
const auto rgb =
oklchToLinearSRgb(
Oklchd(
0.5,
result .value,
OklabHued .fromDegrees(264.0)
)
);
assert(rgb .inGamut);
Example
Endpoints collapse to the achromatic boundary.
enum black =
maxChromaInSRgb!double(
0.0,
OklabHued .fromDegrees(123.0)
);
enum white =
maxChromaInSRgb!double(
1.0,
OklabHued .fromDegrees(123.0)
);
static assert(black .valid && black .value == 0.0);
static assert(white .valid && white .value == 0.0);
Example
Invalid lightness and hue are reported rather than silently clamped.
enum below =
maxChromaInSRgb!double(
-0.01,
OklabHued .fromDegrees(0.0)
);
enum above =
maxChromaInSRgb!double(
1.01,
OklabHued .fromDegrees(0.0)
);
enum nanL =
maxChromaInSRgb!double(
double .nan,
OklabHued .fromDegrees(0.0)
);
enum nanH =
maxChromaInSRgb!double(
0.5,
OklabHued .fromDegrees(double .nan)
);
static assert(!below .valid);
static assert(!above .valid);
static assert(!nanL .valid);
static assert(!nanH .valid);
Example
Equivalent hue revolutions represent the same boundary.
enum a =
maxChromaInSRgb!double(
0.5,
OklabHued .fromDegrees(40.0)
);
enum b =
maxChromaInSRgb!double(
0.5,
OklabHued .fromDegrees(400.0)
);
enum c =
maxChromaInSRgb!double(
0.5,
OklabHued .fromDegrees(-320.0)
);
static assert(a .valid && b .valid && c .valid);
static assert(a .value == b .value);
static assert(a .value == c .value);
Example
The public result is compact and naturally invalid before validation.
static assert(SRgbChromaLimit!float .sizeof == float .sizeof);
static assert(SRgbChromaLimit!double .sizeof == double .sizeof);