Give a color O outside the gamut of a canvas color space, display-p3 or
srgb. It is CSS gamut mapped
into that space by each of the three algorithms CSS Color 4 allows, giving
G1, G2 and G3, and also naïvely clipped, giving C.
Their mean G, and a tolerance S within which all three fit but C does not, are what a
web-platform-test needs to paint O into a canvas, read the pixel back,
and tell whether the browser gamut mapped or clipped it.
The margin is slack for implementations whose arithmetic differs a little from Color.js: anything within it of any of the three algorithms must still pass, and anything within it of the clipped color must still fail.
Scans the display-p3 and Rec. 2020 primaries and secondaries, and round-number Oklch colors (lightness 30%–90%, chroma 0.2–0.35, every 30° of hue), keeping only those outside the chosen canvas’s gamut where a test can tell the three algorithms from clipping. Best first: a tight S that could grow many times over before it admitted the clipped color.
One test per canvas color space, since a browser can gamut map on one without supporting the
other. Add to test adds a color to the test for the canvas chosen above. Each color is
painted as a 5×5 patch into a canvas with colorType: "unorm8" — the case the spec
says must be gamut mapped, as it cannot store out-of-gamut values — and the center pixel, clear
of any antialiasing, is read back and reported as gamut mapped, clipped, or neither.