Palette pass now accepts colors regardless of their color space

This commit is contained in:
Rezmason
2022-09-27 22:44:47 -07:00
parent cde709b044
commit 67cfdcb132
4 changed files with 67 additions and 55 deletions

12
js/colorToRGB.js Normal file
View File

@@ -0,0 +1,12 @@
export default ({ space, values }) => {
if (space === "rgb") {
return values;
}
const [hue, saturation, lightness] = values;
const a = saturation * Math.min(lightness, 1 - lightness);
const f = (n) => {
const k = (n + hue * 12) % 12;
return lightness - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
};
return [f(0), f(8), f(4)];
};