@woosh/meep-engine 2.100.1 → 2.100.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/build/meep.cjs +21 -2
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +21 -2
  4. package/package.json +1 -1
  5. package/src/core/color/oklab/Okhsv.spec.d.ts +2 -0
  6. package/src/core/color/oklab/Okhsv.spec.d.ts.map +1 -0
  7. package/src/core/color/oklab/Okhsv.spec.js +17 -0
  8. package/src/core/color/oklab/XYZ.spec.js +2 -2
  9. package/src/core/color/oklab/compute_max_saturation.d.ts +11 -0
  10. package/src/core/color/oklab/compute_max_saturation.d.ts.map +1 -0
  11. package/src/core/color/oklab/compute_max_saturation.js +84 -0
  12. package/src/core/color/oklab/find_cusp.d.ts +10 -0
  13. package/src/core/color/oklab/find_cusp.d.ts.map +1 -0
  14. package/src/core/color/oklab/find_cusp.js +27 -0
  15. package/src/core/color/oklab/find_gamut_intersection.d.ts +15 -0
  16. package/src/core/color/oklab/find_gamut_intersection.d.ts.map +1 -0
  17. package/src/core/color/oklab/find_gamut_intersection.js +101 -0
  18. package/src/core/color/oklab/linear_srgb_to_okhsv.d.ts +9 -0
  19. package/src/core/color/oklab/linear_srgb_to_okhsv.d.ts.map +1 -0
  20. package/src/core/color/oklab/linear_srgb_to_okhsv.js +74 -0
  21. package/src/core/color/oklab/linear_srgb_to_oklab.d.ts +9 -0
  22. package/src/core/color/oklab/linear_srgb_to_oklab.d.ts.map +1 -0
  23. package/src/core/color/oklab/linear_srgb_to_oklab.js +20 -0
  24. package/src/core/color/oklab/okhsv_to_linear_srgb.d.ts +9 -0
  25. package/src/core/color/oklab/okhsv_to_linear_srgb.d.ts.map +1 -0
  26. package/src/core/color/oklab/okhsv_to_linear_srgb.js +59 -0
  27. package/src/core/color/oklab/oklab_to_linear_srgb.d.ts +10 -0
  28. package/src/core/color/oklab/oklab_to_linear_srgb.d.ts.map +1 -0
  29. package/src/core/color/oklab/oklab_to_linear_srgb.js +21 -0
  30. package/src/core/color/oklab/oklab_to_xyz.d.ts +5 -2
  31. package/src/core/color/oklab/oklab_to_xyz.d.ts.map +1 -1
  32. package/src/core/color/oklab/oklab_to_xyz.js +5 -5
  33. package/src/core/color/oklab/oklab_to_xyz.spec.js +4 -4
  34. package/src/core/color/oklab/toe.d.ts +13 -0
  35. package/src/core/color/oklab/toe.d.ts.map +1 -0
  36. package/src/core/color/oklab/toe.js +22 -0
  37. package/src/core/color/oklab/xyz_to_oklab.d.ts +5 -2
  38. package/src/core/color/oklab/xyz_to_oklab.d.ts.map +1 -1
  39. package/src/core/color/oklab/xyz_to_oklab.js +5 -5
  40. package/src/core/color/oklab/xyz_to_oklab.spec.js +4 -4
  41. package/src/engine/asset/loaders/ArrayBufferLoader.d.ts.map +1 -1
  42. package/src/engine/asset/loaders/ArrayBufferLoader.js +22 -2
@@ -67825,13 +67825,17 @@ class ArrayBufferLoader extends AssetLoader {
67825
67825
 
67826
67826
  }
67827
67827
 
67828
+ /**
67829
+ * @type {ReadableStreamDefaultReader<Uint8Array>}
67830
+ */
67828
67831
  const reader = response.body.getReader();
67832
+
67829
67833
  const contentLength = response.headers.get('Content-Length');
67830
67834
  const total = contentLength ? parseInt(contentLength) : 0;
67831
67835
  let loaded = 0;
67832
67836
 
67833
67837
  // periodically read data into the new stream tracking while download progress
67834
- const stream = new ReadableStream({
67838
+ const stream_prototype = {
67835
67839
  type: "bytes",
67836
67840
  start(controller) {
67837
67841
 
@@ -67860,7 +67864,22 @@ class ArrayBufferLoader extends AssetLoader {
67860
67864
 
67861
67865
  }
67862
67866
 
67863
- });
67867
+ };
67868
+
67869
+ /**
67870
+ * @type {ReadableStream}
67871
+ */
67872
+ let stream;
67873
+
67874
+ try {
67875
+ stream = new ReadableStream(stream_prototype);
67876
+ } catch (e) {
67877
+ /*
67878
+ Workaround for Safari bug: "TypeError: ReadableByteStreamController is not implemented"
67879
+ By not wrapping the response we lose the ability to track progress, but that's not a critical issue in most cases
67880
+ */
67881
+ return response;
67882
+ }
67864
67883
 
67865
67884
  return new Response(stream);
67866
67885
  }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.100.1",
8
+ "version": "2.100.2",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Okhsv.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Okhsv.spec.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/Okhsv.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { linear_srgb_to_okhsv } from "./linear_srgb_to_okhsv.js";
2
+ import { okhsv_to_linear_srgb } from "./okhsv_to_linear_srgb.js";
3
+
4
+ test("to/from consistency", () => {
5
+
6
+ const out = [];
7
+
8
+ const sample = [0.123, 0.345, 0.457];
9
+
10
+ okhsv_to_linear_srgb(out, ...sample);
11
+
12
+ linear_srgb_to_okhsv(out, ...out);
13
+
14
+ expect(out[0]).toBeCloseTo(sample[0]);
15
+ expect(out[1]).toBeCloseTo(sample[1]);
16
+ expect(out[2]).toBeCloseTo(sample[2]);
17
+ });
@@ -7,9 +7,9 @@ test("to/from consistency", () => {
7
7
 
8
8
  const sample = [0.123, 0.345, 0.457];
9
9
 
10
- oklab_to_xyz(sample, out);
10
+ oklab_to_xyz(out, ...sample);
11
11
 
12
- xyz_to_oklab(out, out);
12
+ xyz_to_oklab(out, ...out);
13
13
 
14
14
  expect(out[0]).toBeCloseTo(sample[0]);
15
15
  expect(out[1]).toBeCloseTo(sample[1]);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Finds the maximum saturation possible for a given hue that fits in sRGB
3
+ * Saturation here is defined as S = C/L
4
+ * a and b must be normalized so a^2 + b^2 == 1
5
+ * @copyright "Company Named Limited" 2023
6
+ * @param {number} a
7
+ * @param {number} b
8
+ * @returns {number}
9
+ */
10
+ export function compute_max_saturation(a: number, b: number): number;
11
+ //# sourceMappingURL=compute_max_saturation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute_max_saturation.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/compute_max_saturation.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,0CAJW,MAAM,KACN,MAAM,GACJ,MAAM,CA4ElB"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Finds the maximum saturation possible for a given hue that fits in sRGB
3
+ * Saturation here is defined as S = C/L
4
+ * a and b must be normalized so a^2 + b^2 == 1
5
+ * @copyright "Company Named Limited" 2023
6
+ * @param {number} a
7
+ * @param {number} b
8
+ * @returns {number}
9
+ */
10
+ export function compute_max_saturation(a, b) {
11
+ // Max saturation will be when one of r, g or b goes below zero.
12
+
13
+ // Select different coefficients depending on which component goes below zero first
14
+ let k0, k1, k2, k3, k4, wl, wm, ws;
15
+
16
+ if (-1.88170328 * a - 0.80936493 * b > 1) {
17
+ // Red component
18
+ k0 = +1.19086277;
19
+ k1 = +1.76576728;
20
+ k2 = +0.59662641;
21
+ k3 = +0.75515197;
22
+ k4 = +0.56771245;
23
+ wl = +4.0767416621;
24
+ wm = -3.3077115913;
25
+ ws = +0.2309699292;
26
+ } else if (1.81444104 * a - 1.19445276 * b > 1) {
27
+ // Green component
28
+ k0 = +0.73956515;
29
+ k1 = -0.45954404;
30
+ k2 = +0.08285427;
31
+ k3 = +0.12541070;
32
+ k4 = +0.14503204;
33
+ wl = -1.2684380046;
34
+ wm = +2.6097574011;
35
+ ws = -0.3413193965;
36
+ } else {
37
+ // Blue component
38
+ k0 = +1.35733652;
39
+ k1 = -0.00915799;
40
+ k2 = -1.15130210;
41
+ k3 = -0.50559606;
42
+ k4 = +0.00692167;
43
+ wl = -0.0041960863;
44
+ wm = -0.7034186147;
45
+ ws = +1.7076147010;
46
+ }
47
+
48
+ // Approximate max saturation using a polynomial:
49
+ let S = k0 + k1 * a + k2 * b + k3 * a * a + k4 * a * b;
50
+
51
+ // Do one step of Halley's method to get closer
52
+ // this gives an error less than 10e6, except for some blue hues where the dS/dh is close to infinite
53
+ // this should be sufficient for most applications, otherwise do two/three steps
54
+
55
+ const k_l = +0.3963377774 * a + 0.2158037573 * b;
56
+ const k_m = -0.1055613458 * a - 0.0638541728 * b;
57
+ const k_s = -0.0894841775 * a - 1.2914855480 * b;
58
+
59
+ {
60
+ const l_ = 1. + S * k_l;
61
+ const m_ = 1. + S * k_m;
62
+ const s_ = 1. + S * k_s;
63
+
64
+ const l = l_ * l_ * l_;
65
+ const m = m_ * m_ * m_;
66
+ const s = s_ * s_ * s_;
67
+
68
+ const l_dS = 3. * k_l * l_ * l_;
69
+ const m_dS = 3. * k_m * m_ * m_;
70
+ const s_dS = 3. * k_s * s_ * s_;
71
+
72
+ const l_dS2 = 6. * k_l * k_l * l_;
73
+ const m_dS2 = 6. * k_m * k_m * m_;
74
+ const s_dS2 = 6. * k_s * k_s * s_;
75
+
76
+ const f = wl * l + wm * m + ws * s;
77
+ const f1 = wl * l_dS + wm * m_dS + ws * s_dS;
78
+ const f2 = wl * l_dS2 + wm * m_dS2 + ws * s_dS2;
79
+
80
+ S = S - f * f1 / (f1 * f1 - 0.5 * f * f2);
81
+ }
82
+
83
+ return S;
84
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * finds L_cusp and C_cusp for a given hue
3
+ * a and b must be normalized so a^2 + b^2 == 1
4
+ * @copyright "Company Named Limited" 2023
5
+ * @param {number[]} output [L, C]
6
+ * @param {number} a
7
+ * @param {number} b
8
+ */
9
+ export function find_cusp(output: number[], a: number, b: number): void;
10
+ //# sourceMappingURL=find_cusp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find_cusp.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/find_cusp.js"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,kCAJW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,QAahB"}
@@ -0,0 +1,27 @@
1
+ import { max3 } from "../../math/max3.js";
2
+ import { compute_max_saturation } from "./compute_max_saturation.js";
3
+ import { oklab_to_linear_srgb } from "./oklab_to_linear_srgb.js";
4
+
5
+ const rgb_at_max = [0, 0, 0];
6
+
7
+
8
+ /**
9
+ * finds L_cusp and C_cusp for a given hue
10
+ * a and b must be normalized so a^2 + b^2 == 1
11
+ * @copyright "Company Named Limited" 2023
12
+ * @param {number[]} output [L, C]
13
+ * @param {number} a
14
+ * @param {number} b
15
+ */
16
+ export function find_cusp(output, a, b) {
17
+ // First, find the maximum saturation (saturation S = C/L)
18
+ const S_cusp = compute_max_saturation(a, b);
19
+
20
+ // Convert to linear sRGB to find the first point where at least one of r,g or b >= 1:
21
+ oklab_to_linear_srgb(rgb_at_max, 1, S_cusp * a, S_cusp * b);
22
+ const L_cusp = Math.cbrt(1. / max3(rgb_at_max[0], rgb_at_max[1], rgb_at_max[2]));
23
+ const C_cusp = L_cusp * S_cusp;
24
+
25
+ output[0] = L_cusp;
26
+ output[1] = C_cusp;
27
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Finds intersection of the line defined by
3
+ * L = L0 * (1 - t) + t * L1;
4
+ * C = t * C1;
5
+ * a and b must be normalized so a^2 + b^2 == 1
6
+ * @copyright "Company Named Limited" 2023
7
+ * @param {number} a
8
+ * @param {number} b
9
+ * @param {number} L1
10
+ * @param {number} C1
11
+ * @param {number} L0
12
+ * @returns {number}
13
+ */
14
+ export function find_gamut_intersection(a: number, b: number, L1: number, C1: number, L0: number): number;
15
+ //# sourceMappingURL=find_gamut_intersection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find_gamut_intersection.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/find_gamut_intersection.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,2CAPW,MAAM,KACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CAoFlB"}
@@ -0,0 +1,101 @@
1
+ import { min3 } from "../../math/min3.js";
2
+ import { find_cusp } from "./find_cusp.js";
3
+
4
+ const cusp = [0, 0];
5
+
6
+ /**
7
+ * Finds intersection of the line defined by
8
+ * L = L0 * (1 - t) + t * L1;
9
+ * C = t * C1;
10
+ * a and b must be normalized so a^2 + b^2 == 1
11
+ * @copyright "Company Named Limited" 2023
12
+ * @param {number} a
13
+ * @param {number} b
14
+ * @param {number} L1
15
+ * @param {number} C1
16
+ * @param {number} L0
17
+ * @returns {number}
18
+ */
19
+ export function find_gamut_intersection(a, b, L1, C1, L0) {
20
+ // Find the cusp of the gamut triangle
21
+ find_cusp(cusp, a, b);
22
+
23
+ // Find the intersection for upper and lower half seprately
24
+ let t;
25
+ if (((L1 - L0) * cusp[1] - (cusp[0] - L0) * C1) <= 0.) {
26
+ // Lower half
27
+
28
+ t = cusp[1] * L0 / (C1 * cusp[0] + cusp[1] * (L0 - L1));
29
+ } else {
30
+ // Upper half
31
+
32
+ // First intersect with triangle
33
+ t = cusp[1] * (L0 - 1.) / (C1 * (cusp[0] - 1.) + cusp[1] * (L0 - L1));
34
+
35
+ // Then one step of Halley's method
36
+ {
37
+ const dL = L1 - L0;
38
+ const dC = C1;
39
+
40
+ const k_l = +0.3963377774 * a + 0.2158037573 * b;
41
+ const k_m = -0.1055613458 * a - 0.0638541728 * b;
42
+ const k_s = -0.0894841775 * a - 1.2914855480 * b;
43
+
44
+ const l_dt = dL + dC * k_l;
45
+ const m_dt = dL + dC * k_m;
46
+ const s_dt = dL + dC * k_s;
47
+
48
+
49
+ // If higher accuracy is required, 2 or 3 iterations of the following block can be used:
50
+ {
51
+ const L = L0 * (1 - t) + t * L1;
52
+ const C = t * C1;
53
+
54
+ const l_ = L + C * k_l;
55
+ const m_ = L + C * k_m;
56
+ const s_ = L + C * k_s;
57
+
58
+ const l = l_ * l_ * l_;
59
+ const m = m_ * m_ * m_;
60
+ const s = s_ * s_ * s_;
61
+
62
+ const ldt = 3 * l_dt * l_ * l_;
63
+ const mdt = 3 * m_dt * m_ * m_;
64
+ const sdt = 3 * s_dt * s_ * s_;
65
+
66
+ const ldt2 = 6 * l_dt * l_dt * l_;
67
+ const mdt2 = 6 * m_dt * m_dt * m_;
68
+ const sdt2 = 6 * s_dt * s_dt * s_;
69
+
70
+ const r = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s - 1;
71
+ const r1 = 4.0767416621 * ldt - 3.3077115913 * mdt + 0.2309699292 * sdt;
72
+ const r2 = 4.0767416621 * ldt2 - 3.3077115913 * mdt2 + 0.2309699292 * sdt2;
73
+
74
+ const u_r = r1 / (r1 * r1 - 0.5 * r * r2);
75
+ let t_r = -r * u_r;
76
+
77
+ const g = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s - 1;
78
+ const g1 = -1.2684380046 * ldt + 2.6097574011 * mdt - 0.3413193965 * sdt;
79
+ const g2 = -1.2684380046 * ldt2 + 2.6097574011 * mdt2 - 0.3413193965 * sdt2;
80
+
81
+ const u_g = g1 / (g1 * g1 - 0.5 * g * g2);
82
+ let t_g = -g * u_g;
83
+
84
+ const b = -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s - 1;
85
+ const b1 = -0.0041960863 * ldt - 0.7034186147 * mdt + 1.7076147010 * sdt;
86
+ const b2 = -0.0041960863 * ldt2 - 0.7034186147 * mdt2 + 1.7076147010 * sdt2;
87
+
88
+ const u_b = b1 / (b1 * b1 - 0.5 * b * b2);
89
+ let t_b = -b * u_b;
90
+
91
+ t_r = u_r >= 0 ? t_r : Number.MAX_VALUE;
92
+ t_g = u_g >= 0 ? t_g : Number.MAX_VALUE;
93
+ t_b = u_b >= 0 ? t_b : Number.MAX_VALUE;
94
+
95
+ t += min3(t_r, t_g, t_b);
96
+ }
97
+ }
98
+ }
99
+
100
+ return t;
101
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {number[]} output
4
+ * @param {number} r
5
+ * @param {number} g
6
+ * @param {number} b
7
+ */
8
+ export function linear_srgb_to_okhsv(output: number[], r: number, g: number, b: number): void;
9
+ //# sourceMappingURL=linear_srgb_to_okhsv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linear_srgb_to_okhsv.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/linear_srgb_to_okhsv.js"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,6CALW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,KACN,MAAM,QAkDhB"}
@@ -0,0 +1,74 @@
1
+ import { find_cusp } from "./find_cusp.js";
2
+ import { linear_srgb_to_oklab } from "./linear_srgb_to_oklab.js";
3
+ import { oklab_to_linear_srgb } from "./oklab_to_linear_srgb.js";
4
+ import { toe, toe_inv } from "./toe.js";
5
+
6
+ const Lab = [0, 0, 0];
7
+
8
+ /**
9
+ *
10
+ * @type {number[]}
11
+ */
12
+ const cusp = [0, 0];
13
+ /**
14
+ *
15
+ * @type {number[]}
16
+ */
17
+ const rgb_scale = [0, 0, 0];
18
+
19
+ /**
20
+ *
21
+ * @param {number[]} output
22
+ * @param {number} r
23
+ * @param {number} g
24
+ * @param {number} b
25
+ */
26
+ export function linear_srgb_to_okhsv(output, r, g, b) {
27
+
28
+ linear_srgb_to_oklab(Lab, r, g, b)
29
+
30
+ let C = Math.sqrt(Lab[1] * Lab[1] + Lab[2] * Lab[2]);
31
+ const a_ = Lab[1] / C;
32
+ const b_ = Lab[2] / C;
33
+
34
+ let L = Lab[0];
35
+ const h = 0.5 + 0.5 * Math.atan2(-Lab[2], -Lab[1]) / Math.PI;
36
+
37
+ find_cusp(cusp, a_, b_);
38
+
39
+ const S_max = cusp[1] / cusp[0];
40
+ const T_max = cusp[1] / (1 - cusp[0]);
41
+
42
+ const S_0 = 0.5;
43
+ const k = 1 - S_0 / S_max;
44
+
45
+ // first we find L_v, C_v, L_vt and C_vt
46
+
47
+ const t = T_max / (C + L * T_max);
48
+ const L_v = t * L;
49
+ const C_v = t * C;
50
+
51
+ const L_vt = toe_inv(L_v);
52
+ const C_vt = C_v * L_vt / L_v;
53
+
54
+ // we can then use these to invert the step that compensates for the toe and the curved top part of the triangle:
55
+
56
+ oklab_to_linear_srgb(rgb_scale, L_vt, a_ * C_vt, b_ * C_vt);
57
+
58
+ const scale_L = Math.cbrt(1. / Math.max(rgb_scale[0], rgb_scale[1], rgb_scale[2], 0));
59
+
60
+ L = L / scale_L;
61
+ C = C / scale_L;
62
+
63
+ C = C * toe(L) / L;
64
+ L = toe(L);
65
+
66
+ // we can now compute v and s:
67
+
68
+ const v = L / L_v;
69
+ const s = (S_0 + T_max) * C_v / ((T_max * S_0) + T_max * k * C_v);
70
+
71
+ output[0] = h;
72
+ output[1] = s;
73
+ output[2] = v;
74
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {number[]} output
4
+ * @param {number} r
5
+ * @param {number} g
6
+ * @param {number} b
7
+ */
8
+ export function linear_srgb_to_oklab(output: number[], r: number, g: number, b: number): void;
9
+ //# sourceMappingURL=linear_srgb_to_oklab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linear_srgb_to_oklab.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/linear_srgb_to_oklab.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,6CALW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,KACN,MAAM,QAchB"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ *
3
+ * @param {number[]} output
4
+ * @param {number} r
5
+ * @param {number} g
6
+ * @param {number} b
7
+ */
8
+ export function linear_srgb_to_oklab(output, r, g, b) {
9
+ const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
10
+ const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
11
+ const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
12
+
13
+ const l_ = Math.cbrt(l);
14
+ const m_ = Math.cbrt(m);
15
+ const s_ = Math.cbrt(s);
16
+
17
+ output[0] = 0.2104542553 * l_ + 0.7936177850 * m_ - 0.0040720468 * s_;
18
+ output[1] = 1.9779984951 * l_ - 2.4285922050 * m_ + 0.4505937099 * s_;
19
+ output[2] = 0.0259040371 * l_ + 0.7827717662 * m_ - 0.8086757660 * s_;
20
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @copyright "Company Named Limited" 2023
3
+ * @param {number[]} output
4
+ * @param {number} h
5
+ * @param {number} s
6
+ * @param {number} v
7
+ */
8
+ export function okhsv_to_linear_srgb(output: number[], h: number, s: number, v: number): void;
9
+ //# sourceMappingURL=okhsv_to_linear_srgb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"okhsv_to_linear_srgb.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/okhsv_to_linear_srgb.js"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,6CALW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,KACN,MAAM,QAsChB"}
@@ -0,0 +1,59 @@
1
+ import { find_cusp } from "./find_cusp.js";
2
+ import { oklab_to_linear_srgb } from "./oklab_to_linear_srgb.js";
3
+ import { toe_inv } from "./toe.js";
4
+
5
+ /**
6
+ *
7
+ * @type {number[]}
8
+ */
9
+ const cusp = [0, 0];
10
+ /**
11
+ *
12
+ * @type {number[]}
13
+ */
14
+ const rgb_scale = [0, 0, 0];
15
+
16
+ /**
17
+ * @copyright "Company Named Limited" 2023
18
+ * @param {number[]} output
19
+ * @param {number} h
20
+ * @param {number} s
21
+ * @param {number} v
22
+ */
23
+ export function okhsv_to_linear_srgb(output, h, s, v) {
24
+
25
+ const a_ = Math.cos(2 * Math.PI * h);
26
+ const b_ = Math.sin(2 * Math.PI * h);
27
+
28
+ find_cusp(cusp, a_, b_);
29
+
30
+ const S_max = cusp[1] / cusp[0];
31
+ const T_max = cusp[1] / (1 - cusp[0]);
32
+ const S_0 = 0.5;
33
+ const k = 1 - S_0 / S_max;
34
+
35
+ // first we compute L and V as if the gamut is a perfect triangle:
36
+
37
+ // L, C when v==1:
38
+ const L_v = 1 - s * S_0 / (S_0 + T_max - T_max * k * s);
39
+ const C_v = s * T_max * S_0 / (S_0 + T_max - T_max * k * s);
40
+
41
+ let L = v * L_v;
42
+ let C = v * C_v;
43
+
44
+ // then we compensate for both toe and the curved top part of the triangle:
45
+ const L_vt = toe_inv(L_v);
46
+ const C_vt = C_v * L_vt / L_v;
47
+
48
+ const L_new = toe_inv(L);
49
+ C = C * L_new / L;
50
+ L = L_new;
51
+
52
+ oklab_to_linear_srgb(rgb_scale, L_vt, a_ * C_vt, b_ * C_vt);
53
+ const scale_L = Math.cbrt(1. / Math.max(rgb_scale[0], rgb_scale[1], rgb_scale[2], 0));
54
+
55
+ L = L * scale_L;
56
+ C = C * scale_L;
57
+
58
+ oklab_to_linear_srgb(output, L, C * a_, C * b_);
59
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @copyright "Company Named Limited" 2023
4
+ * @param {number[]} output
5
+ * @param {number} L
6
+ * @param {number} a
7
+ * @param {number} b
8
+ */
9
+ export function oklab_to_linear_srgb(output: number[], L: number, a: number, b: number): void;
10
+ //# sourceMappingURL=oklab_to_linear_srgb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oklab_to_linear_srgb.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/oklab_to_linear_srgb.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,6CALW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,KACN,MAAM,QAchB"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ *
3
+ * @copyright "Company Named Limited" 2023
4
+ * @param {number[]} output
5
+ * @param {number} L
6
+ * @param {number} a
7
+ * @param {number} b
8
+ */
9
+ export function oklab_to_linear_srgb(output, L, a, b) {
10
+ const l_ = L + 0.3963377774 * a + 0.2158037573 * b;
11
+ const m_ = L - 0.1055613458 * a - 0.0638541728 * b;
12
+ const s_ = L - 0.0894841775 * a - 1.2914855480 * b;
13
+
14
+ const l = l_ * l_ * l_;
15
+ const m = m_ * m_ * m_;
16
+ const s = s_ * s_ * s_;
17
+
18
+ output[0] = +4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s;
19
+ output[1] = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s;
20
+ output[2] = -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s;
21
+ }
@@ -2,8 +2,11 @@
2
2
  *
3
3
  * Converts Oklab color space to CIE XYZ.
4
4
  * Oklab as defined by Björn Ottosson
5
- * @param {number[]} input Oklab
5
+ * @copyright "Company Named Limited" 2023
6
6
  * @param {number[]} output XYZ
7
+ * @param {number} L
8
+ * @param {number} a
9
+ * @param {number} b
7
10
  */
8
- export function oklab_to_xyz(input: number[], output: number[]): void;
11
+ export function oklab_to_xyz(output: number[], L: number, a: number, b: number): void;
9
12
  //# sourceMappingURL=oklab_to_xyz.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"oklab_to_xyz.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/oklab_to_xyz.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,oCAHW,MAAM,EAAE,UACR,MAAM,EAAE,QA0BlB"}
1
+ {"version":3,"file":"oklab_to_xyz.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/oklab_to_xyz.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,qCALW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,KACN,MAAM,QAuBhB"}
@@ -2,13 +2,13 @@
2
2
  *
3
3
  * Converts Oklab color space to CIE XYZ.
4
4
  * Oklab as defined by Björn Ottosson
5
- * @param {number[]} input Oklab
5
+ * @copyright "Company Named Limited" 2023
6
6
  * @param {number[]} output XYZ
7
+ * @param {number} L
8
+ * @param {number} a
9
+ * @param {number} b
7
10
  */
8
- export function oklab_to_xyz(input, output) {
9
- const L = input[0];
10
- const a = input[1];
11
- const b = input[2];
11
+ export function oklab_to_xyz(output, L, a, b) {
12
12
 
13
13
  // apply M2 inverse
14
14
 
@@ -4,25 +4,25 @@ test("known samples", () => {
4
4
 
5
5
  const out = [];
6
6
 
7
- oklab_to_xyz([1, 0, 0], out);
7
+ oklab_to_xyz(out, 1, 0, 0);
8
8
 
9
9
  expect(out[0]).toBeCloseTo(0.950);
10
10
  expect(out[1]).toBeCloseTo(1.000);
11
11
  expect(out[2]).toBeCloseTo(1.089);
12
12
 
13
- oklab_to_xyz([0.450, 1.236, -0.019], out);
13
+ oklab_to_xyz(out, 0.450, 1.236, -0.019);
14
14
 
15
15
  expect(out[0]).toBeCloseTo(1);
16
16
  expect(out[1]).toBeCloseTo(0);
17
17
  expect(out[2]).toBeCloseTo(0);
18
18
 
19
- oklab_to_xyz([0.922, -0.671, 0.263], out);
19
+ oklab_to_xyz(out, 0.922, -0.671, 0.263);
20
20
 
21
21
  expect(out[0]).toBeCloseTo(0);
22
22
  expect(out[1]).toBeCloseTo(1);
23
23
  expect(out[2]).toBeCloseTo(0);
24
24
 
25
- oklab_to_xyz([0.153, -1.415, -0.449], out);
25
+ oklab_to_xyz(out, 0.153, -1.415, -0.449);
26
26
 
27
27
  expect(out[0]).toBeCloseTo(0);
28
28
  expect(out[1]).toBeCloseTo(0);