googlefonts / colr-gradients-spec

63 stars 8 forks source link

Define how to interpolate colors #27

Closed rsheeter closed 3 years ago

rsheeter commented 4 years ago

https://github.com/googlefonts/colr-gradients-spec/blob/master/colr-gradients-spec.md#color-palette-variation currently reads "Colors expressed in sRGB r/g/b channels cannot be easily interpolated. Another solution is needed, perhaps involving transforming to a linear color space and back."

Courtesy of Romain Guy I have a concrete suggestion on how to interpolate in linear space: "apply the color space's EOTF before interpolating, then apply the OETF." I hope I'm not the only one who had to look up the terms :D

Android implements this for animated colors and users seem satisfied. https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/animation/ArgbEvaluator.java. Related, https://developer.android.com/reference/android/graphics/ColorSpace.Named gives names and equations [in source] for a bunch more color spaces.

I suggest we might consider directly adopting this approach; it's been used in real world animation and has a well defined implementation :)

https://www.colour-science.org/posts/the-importance-of-terminology-and-srgb-uncertainty/

PeterConstable commented 3 years ago

@svgeesus : Please review #214. (For whatever reason, GitHub isn't allowing me to add you there as a reviewer.)

svgeesus commented 3 years ago

@svgeesus : Please review #214.

Done, sorry for the delay. Mostly correct. One important omission (undoing pre-multiplication after interpolation, to get actual colors back), where I suggested text and therefore requested changes. A couple of small suggestions for clarity.

(For whatever reason, GitHub isn't allowing me to add you there as a reviewer.)

I get that too sometimes and don't understand why, either.

PeterConstable commented 3 years ago

Changes (#214) merged.