| 1 |
import oklab from "../spaces/oklab.js"; |
| 2 |
import getColor from "../getColor.js"; |
| 3 |
|
| 4 |
/** |
| 5 |
* More accurate color-difference formulae |
| 6 |
* than the simple 1976 Euclidean distance in CIE Lab |
| 7 |
* @param {import("../types.js").ColorTypes} color |
| 8 |
* @param {import("../types.js").ColorTypes} sample |
| 9 |
* @returns {number} |
| 10 |
*/ |
| 11 |
export default function (color, sample) { |
| 12 |
[color, sample] = getColor([color, sample]); |
| 13 |
|
| 14 |
// Given this color as the reference |
| 15 |
// and a sample, |
| 16 |
// calculate deltaEOK, term by term as root sum of squares |
| 17 |
let [L1, a1, b1] = oklab.from(color); |
| 18 |
let [L2, a2, b2] = oklab.from(sample); |
| 19 |
let ΔL = L1 - L2; |
| 20 |
let Δa = a1 - a2; |
| 21 |
let Δb = b1 - b2; |
| 22 |
return Math.sqrt(ΔL ** 2 + Δa ** 2 + Δb ** 2); |
| 23 |
} |