← Previous Next →

Scrawl-canvas v8 - Canvas test 016

CSS color space strings - srgb, srgb-linear, display-p3, a98-rgb, prophoto-rgb, rec2020, xyz-d50, xyz-d65, xyz

Note: this canvas will use the display-p3 color space where the device, browser and display screen all support it.

Test purpose

Note that: browser support for different color spaces only reached broad support across browsers in 2023. Some older browsers that do support the newer color spaces in CSS may not support them in <canvas> elements.

For browsers that do not currently support a given color() CSS string, SC will render that color as transparent black - which is the expected action. Malformed CSS strings may be rendered as either a clamped version of the color, or opaque/transparent black (again, the expected action).

Touch test: not required

Annotated code

 
Test if color strings work for CSS in this browser:

color(srgb 0.5 1 0.25)
color(srgb 20% 0.6 100%)
color(srgb 0.5 0 1 / 0.5)
color(srgb-linear 0.5 1 0.25)
color(srgb-linear 20% 0.6 100%)
color(srgb-linear 0.5 0 1 / 0.5)
color(display-p3 0.5 1 0.25)
color(display-p3 20% 0.6 100%)
color(display-p3 0.5 0 1 / 0.5)
color(a98-rgb 0.5 1 0.25)
color(a98-rgb 20% 0.6 100%)
color(a98-rgb 0.5 0 1 / 0.5)
color(prophoto-rgb 0.5 1 0.25)
color(prophoto-rgb 20% 0.6 100%)
color(prophoto-rgb 0.5 0 1 / 0.5)
color(rec2020 0.5 1 0.25)
color(rec2020 20% 0.6 100%)
color(rec2020 0.5 0 1 / 0.5)
color(xyz 0.5 1 0.25)
color(xyz 20% 0.6 100%)
color(xyz 0.5 0 1 / 0.5)
color(xyz-d50 0.5 1 0.25)
color(xyz-d50 20% 0.6 100%)
color(xyz-d50 0.5 0 1 / 0.5)
color(xyz-d65 0.5 1 0.25)
color(xyz-d65 20% 0.6 100%)
color(xyz-d65 0.5 0 1 / 0.5)


Malformed strings

color(rec2020 0.5 1.2 0.25)
color(srgb 0.5 1.2 0.25)
color(display-p3 0.5 1.2 0.25)