wcag2ContrastRatio - multiple declarations
Function wcag2ContrastRatio
Computes the WCAG 2 contrast ratio between two linear-light sRGB colors.
Wcag2Measurement!T wcag2ContrastRatio(T)(
LinearSRgb!T first,
LinearSRgb!T second
) pure nothrow @nogc @safe;
Use this when both colors have already been decoded to linear light and any alpha has been resolved. Components must be finite and from 0 through 1 inclusive. Invalid input produces an invalid measurement. No hidden conversion, clipping, gamut mapping, alpha compositing, or threshold policy is applied.
Parameters
| Name | Description |
|---|---|
| first | First normalized linear-light sRGB color. |
| second | Second normalized linear-light sRGB color. |
Returns
A valid WCAG 2 contrast ratio, or an invalid measurement.
Standards
W3C WCAG 2.2 contrast ratio.
Example
import color .rgb : LinearSRgbd;
const contrast = LinearSRgbd(0, 0, 0) .wcag2ContrastRatio(
LinearSRgbd(1, 1, 1)
);
assert(contrast .valid);
assert(contrast .value == 21);
Function wcag2ContrastRatio
Computes the WCAG 2 contrast ratio between two encoded-sRGB colors.
Use this after any alpha has been resolved. Both colors must contain finite normalized components from 0 through 1 inclusive. Invalid input produces an invalid measurement. No clipping, gamut mapping, alpha compositing, or accessibility-threshold classification is applied.
Parameters
| Name | Description |
|---|---|
| first | First normalized encoded-sRGB color. |
| second | Second normalized encoded-sRGB color. |
Returns
A valid WCAG 2 contrast ratio, or an invalid measurement.
Standards
W3C WCAG 2.2 contrast ratio.
Example
Black against white has the maximum WCAG 2 sRGB contrast ratio.
import color .rgb :
SRgbd;
const contrast =
SRgbd(0, 0, 0) .wcag2ContrastRatio(
SRgbd(1, 1, 1)
);
assert(contrast .valid);
assert(
contrast .value > 20.999999 &&
contrast .value < 21.000001
);