Support wide-gamut colour spaces

#1140 · closed · 1 comments

View on GitHub ↗

benjaminleonard

uPlot creates its drawing context with no attributes: ```ts const ctx = self.ctx = can.getContext("2d") ``` which means the canvas is always sRGB. Colours that exceed the sRGB gamut get clamped when drawn to the canvas, so on wide-gamut (P3) displays a uPlot chart looks visibly washed out next to the exact same colour rendered by CSS/SVG elsewhere on the page. ```tsx // example attrs { ctxAttrs: { colorSpace: 'display-p3' } const ctx = self.ctx = can.getContext("2d", opts.ctxAttrs); ``` I _think_ browsers that don't support `colorSpace` ignore it, so no feature detection is needed in uPlot itself. `desynchronized` and `alpha` (in the context attrs) are likely not useful, so an alternative is passing `colorSpace` as a bespoke option. Happy to submit a PR if you're open to it.

Comments

leeoniya

added in https://github.com/leeoniya/uPlot/commit/a6d12f901841972ef24aa72f533a42548207b916 will be in 1.7.0, in a couple weeks.