Debian Codegraph @

node/colorjs.io/src/contrast/deltaPhi.js

raw
1 // Delta Phi Star perceptual lightness contrast
2 // See https://github.com/Myndex/deltaphistar
3 // The (difference between two Lstars each raised to phi) raised to (1/phi)
4 // Symmetric, does not matter which is foreground and which is background
5
6 import getColor from "../getColor.js";
7 import get from "../get.js";
8 import lab_d65 from "../spaces/lab-d65.js";
9
10 const phi = Math.pow(5, 0.5) * 0.5 + 0.5; // Math.phi can be used if Math.js
11
12 /**
13 * @param {import("../types.js").ColorTypes} color1
14 * @param {import("../types.js").ColorTypes} color2
15 * @returns {number}
16 */
17 export default function contrastDeltaPhi (color1, color2) {
18 color1 = getColor(color1);
19 color2 = getColor(color2);
20
21 let Lstr1 = get(color1, [lab_d65, "l"]);
22 let Lstr2 = get(color2, [lab_d65, "l"]);
23
24 let deltaPhiStar = Math.abs(Math.pow(Lstr1, phi) - Math.pow(Lstr2, phi));
25
26 let contrast = Math.pow(deltaPhiStar, 1 / phi) * Math.SQRT2 - 40;
27
28 return contrast < 7.5 ? 0.0 : contrast;
29 }