-
Notifications
You must be signed in to change notification settings - Fork 1
/
lch.js
36 lines (33 loc) · 1011 Bytes
/
lch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { fromLabD50, toLabD50 } from "./lab.js";
import { lchToLab, labToLch } from "./utils.js";
/**
* @typedef {number[]} lch CIELCh Luminance Chroma Hue. Cylindrical form of Lab.
*
* All components in the range 0 <= x <= 1
* @see {@link https://en.wikipedia.org/wiki/CIELAB_color_space#Cylindrical_model}
*/
/**
* Updates a color based on LCH values and alpha.
* @alias module:pex-color.fromLCH
* @param {import("./color.js").color} color
* @param {number} l
* @param {number} c
* @param {number} h
* @param {number} [a]
* @returns {import("./color.js").color}
*/
export function fromLCH(color, l, c, h, a) {
lchToLab(l, c, h, color);
return fromLabD50(color, color[0], color[1], color[2], a);
}
/**
* Returns a LCH representation of a given color.
* @alias module:pex-color.toLCH
* @param {import("./color.js").color} color
* @param {Array} out
* @returns {lch}
*/
export function toLCH(color, out = []) {
toLabD50(color, out);
return labToLch(out[0], out[1], out[2], out);
}