保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Convert between RGB and Hue
/* ========================================================================== */
 
export function rgb2hue(rgbR, rgbG, rgbB, fallbackhue = 0) {
    const value     = rgb2value(rgbR, rgbG, rgbB);
    const whiteness = rgb2whiteness(rgbR, rgbG, rgbB);
    const delta     = value - whiteness;
 
    if (delta) {
        // calculate segment
        const segment = value === rgbR
            ? (rgbG - rgbB) / delta
        : value === rgbG
            ? (rgbB - rgbR) / delta
        : (rgbR - rgbG) / delta;
 
        // calculate shift
        const shift = value === rgbR
            ? segment < 0
                ? 360 / 60
                : 0 / 60
        : value === rgbG
            ? 120 / 60
        : 240 / 60;
 
        // calculate hue
        const hue = (segment + shift) * 60;
 
        return hue;
    } else {
        // otherwise return the fallback hue
        return fallbackhue;
    }
}
 
export function hue2rgb(t1, t2, hue) {
    // calculate the ranged hue
    const rhue = hue < 0 ? hue + 360 : hue > 360 ? hue - 360 : hue;
 
    // calculate the rgb value
    const rgb = rhue * 6 < 360
        ? t1 + (t2 - t1) * rhue / 60
    : rhue * 2 < 360
        ? t2
    : rhue * 3 < 720
        ? t1 + (t2 - t1) * (240 - rhue) / 60
    : t1;
 
    return rgb;
}
 
/* RGB tooling
/* ========================================================================== */
 
export function rgb2value(rgbR, rgbG, rgbB) {
    const value = Math.max(rgbR, rgbG, rgbB);
 
    return value;
}
 
export function rgb2whiteness(rgbR, rgbG, rgbB) {
    const whiteness = Math.min(rgbR, rgbG, rgbB);
 
    return whiteness;
}
 
/* Math matrix
/* ========================================================================== */
 
export function matrix(params, mats) {
    return mats.map(mat => mat.reduce((acc, value, index) => acc + params[index] * value, 0));
}
 
/* D50 reference white
/* ========================================================================== */
 
export const [ wd50X, wd50Y, wd50Z ] = [ 96.42, 100, 82.49 ];
 
/* Epsilon
/* ========================================================================== */
 
export const epsilon = Math.pow(6, 3) / Math.pow(29, 3);
 
/* Kappa
/* ========================================================================== */
 
export const kappa = Math.pow(29, 3) / Math.pow(3, 3);