RecipesRegister Color Spaces
LCH(uv)
A recipe to register the LCH(uv) color function in Saturon.
import { registerColorFunction } from "saturon/utils";
/**
* @see {@link http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Luv.html|LCH(uv) to Luv}
* @see {@link http://www.brucelindbloom.com/index.html?Eqn_Luv_to_LCH.html|Luv to LCH(uv)}
*/
registerColorFunction("lchuv", {
components: {
l: { index: 0, value: "percentage", precision: 5 },
c: { index: 1, value: "percentage", precision: 5 },
h: { index: 2, value: "angle", precision: 5 },
},
targetGamut: null,
bridge: "luv",
toBridge: ([L, C, H]) => {
const hRad = (H * Math.PI) / 180;
const u = C * Math.cos(hRad);
const v = C * Math.sin(hRad);
return [L, u, v];
},
fromBridge: ([L, u, v]) => {
const C = Math.sqrt(u * u + v * v);
let H = Math.atan2(v, u) * (180 / Math.PI);
if (H < 0) H += 360;
return [L, C, H];
},
});