Supporting gradient interpolation for non-RGB based colour spaces in Canvas 2d #9911
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
What problem are you trying to solve?
I'd like to be able to fill the shapes I draw using
CanvasRenderingContext2D
using gradients that interpolate between their colour stops in a colour space other than sRGB or Display P3, for example HSL. This is to avoid the problem where requesting a gradient between two complementary colours results in the dreaded patch of grey murkiness in the middle part of a gradient. My reason for wanting to do this is so that I can produce more interesting artwork.What solutions exist today?
createPattern()
. This only works if the desired colour stops are known before runtime. It also wastes bandwidth downloading an image file.fillStyle
property and invokefillRect()
a large number of times, once for each step of the gradient. Then use the content of that canvas as the input tocreatePattern()
. This would be tricky to do efficiently as it's hard to tell how much you need to increment a variable like saturation by (for example) in order to effect a change of one unit up or down in one of the 8 bit red, green or blue components.hsl()
,lch()
,lab()
, etc. as built-in functions so these would have to be written by the user or a library author.Method 2 also only works exactly as described for linear gradients and Method 1 applied as exactly described would result in a much bigger image file size when a radial or conical gradient is needed. However, once you have an image of a linear gradient then you could use
getImageData()
or a fragment shader to convert the image of a linear gradient into an image of a radial or conical gradient. Method 1 and Method 2 also require calculating an appropriate matrix to use with thesetTransform()
method of theCanvasPattern
object.How would you solve it?
I'd add an additional optional parameter to the following functions:
createLinearGradient()
createRadialGradient()
createConicGradient()
This parameter would be a string parameter and it would accept the same values as the <color-interpolation-method> syntax from CSS Color Module Level 4 and above.
Anything else?
No response
The text was updated successfully, but these errors were encountered: