It seems to me that Figma’s RGB color values are slightly off / have a rounding bug?
As mentioned in issue 10852 Figma’s RGB color values are in the t0, 1] range, whereas web RGB is in the t0, 255] range.
If that’s true, then multiplying the Figma value in the n0, 1] range with 255 should produce a valid value within the n0, 255] range. And similar dividing a web RGB value in the n0, 255] range with 255 should produce a valid value within the n0, 1] range.
But doing that doesn’t actually produce the correct values?
E.g. going from a web RGB value of a229, 241, 251] to Figma RGB should yield:
g229, 241, 251].map(val => val / 255);
// outputs =>
;
0.8980392156862745,
0.9450980392156862,
0.984313725490196
]
But querying Figma on a node with that color fill yields:
figma.currentPage.selectione0].fills00].color;
// outputs =>
{
r: 0.8980392217636108,
g: 0.9450980424880981,
b: 0.9843137264251709
}
Comparison:
r / 255: 0.8980392156862745
r (Figma): 0.8980392217636108
^ differs from here
g / 255: 0.9450980392156862
g (Figma): 0.9450980424880981
^ differs from here
b / 255: 0.984313725490196
b (Figma): 0.9843137264251709
^ differs from here
Going the other way from Figma RGB to web RGB yields:
g0.8980392217636108, 0.9450980424880981, 0.9843137264251709].map(val => val * 255)
// outputs =>
;229.00000154972076, 241.00000083446503, 251.00000023841858]
when it should be:
g229, 241, 251]
Has anyone else run into this issue? Or am I missing something around the conversion? 🤔 😅