@dawcore/spectrogram 0.0.1

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.
@@ -0,0 +1,3615 @@
1
+ // src/worker/createSpectrogramWorker.ts
2
+ var SpectrogramAbortError = class extends Error {
3
+ constructor() {
4
+ super("aborted");
5
+ this.name = "SpectrogramAbortError";
6
+ }
7
+ };
8
+ function addPending(map, id, resolve, reject) {
9
+ map.set(id, { resolve, reject });
10
+ }
11
+ var idCounter = 0;
12
+ function createSpectrogramWorker(worker) {
13
+ const pending = /* @__PURE__ */ new Map();
14
+ const registeredClipIds = /* @__PURE__ */ new Set();
15
+ let terminated = false;
16
+ worker.onmessage = (e) => {
17
+ const msg = e.data;
18
+ const entry = pending.get(msg.id);
19
+ if (entry) {
20
+ pending.delete(msg.id);
21
+ switch (msg.type) {
22
+ case "error":
23
+ entry.reject(new Error(msg.error));
24
+ break;
25
+ case "aborted":
26
+ entry.reject(new SpectrogramAbortError());
27
+ break;
28
+ case "cache-key":
29
+ entry.resolve({ cacheKey: msg.cacheKey });
30
+ break;
31
+ case "done":
32
+ entry.resolve(void 0);
33
+ break;
34
+ }
35
+ } else if (msg.id) {
36
+ console.warn(`[spectrogram] Received response for unknown message ID: ${msg.id}`);
37
+ }
38
+ };
39
+ worker.onerror = (e) => {
40
+ terminated = true;
41
+ for (const [, entry] of pending) {
42
+ entry.reject(e.error ?? new Error(e.message));
43
+ }
44
+ pending.clear();
45
+ };
46
+ return {
47
+ computeFFT(params, generation = 0) {
48
+ if (terminated) return Promise.reject(new Error("Worker terminated"));
49
+ const id = String(++idCounter);
50
+ return new Promise((resolve, reject) => {
51
+ addPending(pending, id, resolve, reject);
52
+ const isPreRegistered = registeredClipIds.has(params.clipId);
53
+ const transferableArrays = isPreRegistered ? [] : params.channelDataArrays.map((arr) => arr.slice());
54
+ const transferables = transferableArrays.map((arr) => arr.buffer);
55
+ worker.postMessage(
56
+ {
57
+ type: "compute-fft",
58
+ id,
59
+ generation,
60
+ clipId: params.clipId,
61
+ channelDataArrays: transferableArrays,
62
+ config: params.config,
63
+ sampleRate: params.sampleRate,
64
+ offsetSamples: params.offsetSamples,
65
+ durationSamples: params.durationSamples,
66
+ mono: params.mono,
67
+ ...params.sampleRange ? { sampleRange: params.sampleRange } : {},
68
+ ...params.channelFilter !== void 0 ? { channelFilter: params.channelFilter } : {}
69
+ },
70
+ transferables
71
+ );
72
+ });
73
+ },
74
+ renderChunks(params, generation = 0) {
75
+ if (terminated) return Promise.reject(new Error("Worker terminated"));
76
+ const id = String(++idCounter);
77
+ return new Promise((resolve, reject) => {
78
+ addPending(pending, id, resolve, reject);
79
+ worker.postMessage({
80
+ type: "render-chunks",
81
+ id,
82
+ generation,
83
+ cacheKey: params.cacheKey,
84
+ canvasIds: params.canvasIds,
85
+ canvasWidths: params.canvasWidths,
86
+ globalPixelOffsets: params.globalPixelOffsets,
87
+ canvasHeight: params.canvasHeight,
88
+ devicePixelRatio: params.devicePixelRatio,
89
+ samplesPerPixel: params.samplesPerPixel,
90
+ colorLUT: params.colorLUT,
91
+ frequencyScale: params.frequencyScale,
92
+ minFrequency: params.minFrequency,
93
+ maxFrequency: params.maxFrequency,
94
+ gainDb: params.gainDb,
95
+ rangeDb: params.rangeDb,
96
+ channelIndex: params.channelIndex
97
+ });
98
+ });
99
+ },
100
+ abortGeneration(generation) {
101
+ if (terminated) return;
102
+ worker.postMessage({ type: "abort-generation", generation });
103
+ },
104
+ registerCanvas(canvasId, canvas) {
105
+ worker.postMessage({ type: "register-canvas", canvasId, canvas }, [canvas]);
106
+ },
107
+ unregisterCanvas(canvasId) {
108
+ worker.postMessage({ type: "unregister-canvas", canvasId });
109
+ },
110
+ registerAudioData(clipId, channelDataArrays, sampleRate) {
111
+ const transferableArrays = channelDataArrays.map((arr) => arr.slice());
112
+ const transferables = transferableArrays.map((arr) => arr.buffer);
113
+ worker.postMessage(
114
+ { type: "register-audio-data", clipId, channelDataArrays: transferableArrays, sampleRate },
115
+ transferables
116
+ );
117
+ registeredClipIds.add(clipId);
118
+ },
119
+ unregisterAudioData(clipId) {
120
+ worker.postMessage({ type: "unregister-audio-data", clipId });
121
+ registeredClipIds.delete(clipId);
122
+ },
123
+ terminate() {
124
+ terminated = true;
125
+ worker.terminate();
126
+ for (const [, entry] of pending) {
127
+ entry.reject(new Error("Worker terminated"));
128
+ }
129
+ pending.clear();
130
+ }
131
+ };
132
+ }
133
+
134
+ // src/worker/createSpectrogramWorkerPool.ts
135
+ function parseChannelFromCanvasId(canvasId) {
136
+ const match = canvasId.match(/-ch(\d+)-/);
137
+ return match ? parseInt(match[1], 10) : 0;
138
+ }
139
+ function defaultPoolSize() {
140
+ return 2;
141
+ }
142
+ function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize()) {
143
+ const workers = [];
144
+ try {
145
+ for (let i = 0; i < poolSize; i++) {
146
+ workers.push(createSpectrogramWorker(createWorker()));
147
+ }
148
+ } catch (err) {
149
+ for (const w of workers) {
150
+ w.terminate();
151
+ }
152
+ throw err;
153
+ }
154
+ function getWorkerForChannel(channelIndex) {
155
+ return workers[channelIndex % workers.length];
156
+ }
157
+ return {
158
+ computeFFT(params, generation = 0) {
159
+ if (params.mono) {
160
+ return workers[0].computeFFT(params, generation);
161
+ }
162
+ const channelCount = params.channelDataArrays.length;
163
+ const activeWorkers = workers.slice(0, channelCount);
164
+ const promises = activeWorkers.map(
165
+ (w, i) => w.computeFFT({ ...params, channelFilter: i }, generation)
166
+ );
167
+ return Promise.all(promises).then((results) => results[0]);
168
+ },
169
+ renderChunks(params, generation = 0) {
170
+ const worker = getWorkerForChannel(params.channelIndex);
171
+ return worker.renderChunks({ ...params, channelIndex: 0 }, generation);
172
+ },
173
+ abortGeneration(generation) {
174
+ for (const w of workers) {
175
+ w.abortGeneration(generation);
176
+ }
177
+ },
178
+ registerCanvas(canvasId, canvas) {
179
+ const ch = parseChannelFromCanvasId(canvasId);
180
+ getWorkerForChannel(ch).registerCanvas(canvasId, canvas);
181
+ },
182
+ unregisterCanvas(canvasId) {
183
+ const ch = parseChannelFromCanvasId(canvasId);
184
+ getWorkerForChannel(ch).unregisterCanvas(canvasId);
185
+ },
186
+ registerAudioData(clipId, channelDataArrays, sampleRate) {
187
+ for (const w of workers) {
188
+ w.registerAudioData(clipId, channelDataArrays, sampleRate);
189
+ }
190
+ },
191
+ unregisterAudioData(clipId) {
192
+ for (const w of workers) {
193
+ w.unregisterAudioData(clipId);
194
+ }
195
+ },
196
+ terminate() {
197
+ for (const w of workers) {
198
+ w.terminate();
199
+ }
200
+ }
201
+ };
202
+ }
203
+
204
+ // src/computation/colorMaps.ts
205
+ function interpolateLUT(stops) {
206
+ const lut = new Uint8Array(256 * 3);
207
+ const n = stops.length;
208
+ for (let i = 0; i < 256; i++) {
209
+ const t = i / 255;
210
+ const pos = t * (n - 1);
211
+ const lo = Math.floor(pos);
212
+ const hi = Math.min(lo + 1, n - 1);
213
+ const frac = pos - lo;
214
+ lut[i * 3] = Math.round(stops[lo][0] * (1 - frac) + stops[hi][0] * frac);
215
+ lut[i * 3 + 1] = Math.round(stops[lo][1] * (1 - frac) + stops[hi][1] * frac);
216
+ lut[i * 3 + 2] = Math.round(stops[lo][2] * (1 - frac) + stops[hi][2] * frac);
217
+ }
218
+ return lut;
219
+ }
220
+ var VIRIDIS_LUT = new Uint8Array([
221
+ 68,
222
+ 1,
223
+ 84,
224
+ 68,
225
+ 2,
226
+ 86,
227
+ 69,
228
+ 4,
229
+ 87,
230
+ 69,
231
+ 5,
232
+ 89,
233
+ 70,
234
+ 7,
235
+ 90,
236
+ 70,
237
+ 8,
238
+ 92,
239
+ 70,
240
+ 10,
241
+ 93,
242
+ 70,
243
+ 11,
244
+ 94,
245
+ 71,
246
+ 13,
247
+ 96,
248
+ 71,
249
+ 14,
250
+ 97,
251
+ 71,
252
+ 16,
253
+ 99,
254
+ 71,
255
+ 17,
256
+ 100,
257
+ 71,
258
+ 19,
259
+ 101,
260
+ 72,
261
+ 20,
262
+ 103,
263
+ 72,
264
+ 22,
265
+ 104,
266
+ 72,
267
+ 23,
268
+ 105,
269
+ 72,
270
+ 24,
271
+ 106,
272
+ 72,
273
+ 26,
274
+ 108,
275
+ 72,
276
+ 27,
277
+ 109,
278
+ 72,
279
+ 28,
280
+ 110,
281
+ 72,
282
+ 29,
283
+ 111,
284
+ 72,
285
+ 31,
286
+ 112,
287
+ 72,
288
+ 32,
289
+ 113,
290
+ 72,
291
+ 33,
292
+ 115,
293
+ 72,
294
+ 35,
295
+ 116,
296
+ 72,
297
+ 36,
298
+ 117,
299
+ 72,
300
+ 37,
301
+ 118,
302
+ 72,
303
+ 38,
304
+ 119,
305
+ 72,
306
+ 40,
307
+ 120,
308
+ 72,
309
+ 41,
310
+ 121,
311
+ 71,
312
+ 42,
313
+ 122,
314
+ 71,
315
+ 44,
316
+ 122,
317
+ 71,
318
+ 45,
319
+ 123,
320
+ 71,
321
+ 46,
322
+ 124,
323
+ 71,
324
+ 47,
325
+ 125,
326
+ 70,
327
+ 48,
328
+ 126,
329
+ 70,
330
+ 50,
331
+ 126,
332
+ 70,
333
+ 51,
334
+ 127,
335
+ 70,
336
+ 52,
337
+ 128,
338
+ 69,
339
+ 53,
340
+ 129,
341
+ 69,
342
+ 55,
343
+ 129,
344
+ 69,
345
+ 56,
346
+ 130,
347
+ 68,
348
+ 57,
349
+ 131,
350
+ 68,
351
+ 58,
352
+ 131,
353
+ 68,
354
+ 59,
355
+ 132,
356
+ 67,
357
+ 61,
358
+ 132,
359
+ 67,
360
+ 62,
361
+ 133,
362
+ 66,
363
+ 63,
364
+ 133,
365
+ 66,
366
+ 64,
367
+ 134,
368
+ 66,
369
+ 65,
370
+ 134,
371
+ 65,
372
+ 66,
373
+ 135,
374
+ 65,
375
+ 68,
376
+ 135,
377
+ 64,
378
+ 69,
379
+ 136,
380
+ 64,
381
+ 70,
382
+ 136,
383
+ 63,
384
+ 71,
385
+ 136,
386
+ 63,
387
+ 72,
388
+ 137,
389
+ 62,
390
+ 73,
391
+ 137,
392
+ 62,
393
+ 74,
394
+ 137,
395
+ 62,
396
+ 76,
397
+ 138,
398
+ 61,
399
+ 77,
400
+ 138,
401
+ 61,
402
+ 78,
403
+ 138,
404
+ 60,
405
+ 79,
406
+ 138,
407
+ 60,
408
+ 80,
409
+ 139,
410
+ 59,
411
+ 81,
412
+ 139,
413
+ 59,
414
+ 82,
415
+ 139,
416
+ 58,
417
+ 83,
418
+ 139,
419
+ 58,
420
+ 84,
421
+ 140,
422
+ 57,
423
+ 85,
424
+ 140,
425
+ 57,
426
+ 86,
427
+ 140,
428
+ 56,
429
+ 88,
430
+ 140,
431
+ 56,
432
+ 89,
433
+ 140,
434
+ 55,
435
+ 90,
436
+ 140,
437
+ 55,
438
+ 91,
439
+ 141,
440
+ 54,
441
+ 92,
442
+ 141,
443
+ 54,
444
+ 93,
445
+ 141,
446
+ 53,
447
+ 94,
448
+ 141,
449
+ 53,
450
+ 95,
451
+ 141,
452
+ 52,
453
+ 96,
454
+ 141,
455
+ 52,
456
+ 97,
457
+ 141,
458
+ 51,
459
+ 98,
460
+ 141,
461
+ 51,
462
+ 99,
463
+ 141,
464
+ 50,
465
+ 100,
466
+ 142,
467
+ 50,
468
+ 101,
469
+ 142,
470
+ 49,
471
+ 102,
472
+ 142,
473
+ 49,
474
+ 103,
475
+ 142,
476
+ 49,
477
+ 104,
478
+ 142,
479
+ 48,
480
+ 105,
481
+ 142,
482
+ 48,
483
+ 106,
484
+ 142,
485
+ 47,
486
+ 107,
487
+ 142,
488
+ 47,
489
+ 108,
490
+ 142,
491
+ 46,
492
+ 109,
493
+ 142,
494
+ 46,
495
+ 110,
496
+ 142,
497
+ 46,
498
+ 111,
499
+ 142,
500
+ 45,
501
+ 112,
502
+ 142,
503
+ 45,
504
+ 113,
505
+ 142,
506
+ 44,
507
+ 113,
508
+ 142,
509
+ 44,
510
+ 114,
511
+ 142,
512
+ 44,
513
+ 115,
514
+ 142,
515
+ 43,
516
+ 116,
517
+ 142,
518
+ 43,
519
+ 117,
520
+ 142,
521
+ 42,
522
+ 118,
523
+ 142,
524
+ 42,
525
+ 119,
526
+ 142,
527
+ 42,
528
+ 120,
529
+ 142,
530
+ 41,
531
+ 121,
532
+ 142,
533
+ 41,
534
+ 122,
535
+ 142,
536
+ 41,
537
+ 123,
538
+ 142,
539
+ 40,
540
+ 124,
541
+ 142,
542
+ 40,
543
+ 125,
544
+ 142,
545
+ 39,
546
+ 126,
547
+ 142,
548
+ 39,
549
+ 127,
550
+ 142,
551
+ 39,
552
+ 128,
553
+ 142,
554
+ 38,
555
+ 129,
556
+ 142,
557
+ 38,
558
+ 130,
559
+ 142,
560
+ 38,
561
+ 130,
562
+ 142,
563
+ 37,
564
+ 131,
565
+ 142,
566
+ 37,
567
+ 132,
568
+ 142,
569
+ 37,
570
+ 133,
571
+ 142,
572
+ 36,
573
+ 134,
574
+ 142,
575
+ 36,
576
+ 135,
577
+ 142,
578
+ 35,
579
+ 136,
580
+ 142,
581
+ 35,
582
+ 137,
583
+ 142,
584
+ 35,
585
+ 138,
586
+ 141,
587
+ 34,
588
+ 139,
589
+ 141,
590
+ 34,
591
+ 140,
592
+ 141,
593
+ 34,
594
+ 141,
595
+ 141,
596
+ 33,
597
+ 142,
598
+ 141,
599
+ 33,
600
+ 143,
601
+ 141,
602
+ 33,
603
+ 144,
604
+ 141,
605
+ 33,
606
+ 145,
607
+ 140,
608
+ 32,
609
+ 146,
610
+ 140,
611
+ 32,
612
+ 146,
613
+ 140,
614
+ 32,
615
+ 147,
616
+ 140,
617
+ 31,
618
+ 148,
619
+ 140,
620
+ 31,
621
+ 149,
622
+ 139,
623
+ 31,
624
+ 150,
625
+ 139,
626
+ 31,
627
+ 151,
628
+ 139,
629
+ 31,
630
+ 152,
631
+ 139,
632
+ 31,
633
+ 153,
634
+ 138,
635
+ 31,
636
+ 154,
637
+ 138,
638
+ 30,
639
+ 155,
640
+ 138,
641
+ 30,
642
+ 156,
643
+ 137,
644
+ 30,
645
+ 157,
646
+ 137,
647
+ 31,
648
+ 158,
649
+ 137,
650
+ 31,
651
+ 159,
652
+ 136,
653
+ 31,
654
+ 160,
655
+ 136,
656
+ 31,
657
+ 161,
658
+ 136,
659
+ 31,
660
+ 161,
661
+ 135,
662
+ 31,
663
+ 162,
664
+ 135,
665
+ 32,
666
+ 163,
667
+ 134,
668
+ 32,
669
+ 164,
670
+ 134,
671
+ 33,
672
+ 165,
673
+ 133,
674
+ 33,
675
+ 166,
676
+ 133,
677
+ 34,
678
+ 167,
679
+ 133,
680
+ 34,
681
+ 168,
682
+ 132,
683
+ 35,
684
+ 169,
685
+ 131,
686
+ 36,
687
+ 170,
688
+ 131,
689
+ 37,
690
+ 171,
691
+ 130,
692
+ 37,
693
+ 172,
694
+ 130,
695
+ 38,
696
+ 173,
697
+ 129,
698
+ 39,
699
+ 173,
700
+ 129,
701
+ 40,
702
+ 174,
703
+ 128,
704
+ 41,
705
+ 175,
706
+ 127,
707
+ 42,
708
+ 176,
709
+ 127,
710
+ 44,
711
+ 177,
712
+ 126,
713
+ 45,
714
+ 178,
715
+ 125,
716
+ 46,
717
+ 179,
718
+ 124,
719
+ 47,
720
+ 180,
721
+ 124,
722
+ 49,
723
+ 181,
724
+ 123,
725
+ 50,
726
+ 182,
727
+ 122,
728
+ 52,
729
+ 182,
730
+ 121,
731
+ 53,
732
+ 183,
733
+ 121,
734
+ 55,
735
+ 184,
736
+ 120,
737
+ 56,
738
+ 185,
739
+ 119,
740
+ 58,
741
+ 186,
742
+ 118,
743
+ 59,
744
+ 187,
745
+ 117,
746
+ 61,
747
+ 188,
748
+ 116,
749
+ 63,
750
+ 188,
751
+ 115,
752
+ 64,
753
+ 189,
754
+ 114,
755
+ 66,
756
+ 190,
757
+ 113,
758
+ 68,
759
+ 191,
760
+ 112,
761
+ 70,
762
+ 192,
763
+ 111,
764
+ 72,
765
+ 193,
766
+ 110,
767
+ 74,
768
+ 193,
769
+ 109,
770
+ 76,
771
+ 194,
772
+ 108,
773
+ 78,
774
+ 195,
775
+ 107,
776
+ 80,
777
+ 196,
778
+ 106,
779
+ 82,
780
+ 197,
781
+ 105,
782
+ 84,
783
+ 197,
784
+ 104,
785
+ 86,
786
+ 198,
787
+ 103,
788
+ 88,
789
+ 199,
790
+ 101,
791
+ 90,
792
+ 200,
793
+ 100,
794
+ 92,
795
+ 200,
796
+ 99,
797
+ 94,
798
+ 201,
799
+ 98,
800
+ 96,
801
+ 202,
802
+ 96,
803
+ 99,
804
+ 203,
805
+ 95,
806
+ 101,
807
+ 203,
808
+ 94,
809
+ 103,
810
+ 204,
811
+ 92,
812
+ 105,
813
+ 205,
814
+ 91,
815
+ 108,
816
+ 205,
817
+ 90,
818
+ 110,
819
+ 206,
820
+ 88,
821
+ 112,
822
+ 207,
823
+ 87,
824
+ 115,
825
+ 208,
826
+ 86,
827
+ 117,
828
+ 208,
829
+ 84,
830
+ 119,
831
+ 209,
832
+ 83,
833
+ 122,
834
+ 209,
835
+ 81,
836
+ 124,
837
+ 210,
838
+ 80,
839
+ 127,
840
+ 211,
841
+ 78,
842
+ 129,
843
+ 211,
844
+ 77,
845
+ 132,
846
+ 212,
847
+ 75,
848
+ 134,
849
+ 213,
850
+ 73,
851
+ 137,
852
+ 213,
853
+ 72,
854
+ 139,
855
+ 214,
856
+ 70,
857
+ 142,
858
+ 214,
859
+ 69,
860
+ 144,
861
+ 215,
862
+ 67,
863
+ 147,
864
+ 215,
865
+ 65,
866
+ 149,
867
+ 216,
868
+ 64,
869
+ 152,
870
+ 216,
871
+ 62,
872
+ 155,
873
+ 217,
874
+ 60,
875
+ 157,
876
+ 217,
877
+ 59,
878
+ 160,
879
+ 218,
880
+ 57,
881
+ 162,
882
+ 218,
883
+ 55,
884
+ 165,
885
+ 219,
886
+ 54,
887
+ 168,
888
+ 219,
889
+ 52,
890
+ 170,
891
+ 220,
892
+ 50,
893
+ 173,
894
+ 220,
895
+ 48,
896
+ 176,
897
+ 221,
898
+ 47,
899
+ 178,
900
+ 221,
901
+ 45,
902
+ 181,
903
+ 222,
904
+ 43,
905
+ 184,
906
+ 222,
907
+ 41,
908
+ 186,
909
+ 222,
910
+ 40,
911
+ 189,
912
+ 223,
913
+ 38,
914
+ 192,
915
+ 223,
916
+ 37,
917
+ 194,
918
+ 223,
919
+ 35,
920
+ 197,
921
+ 224,
922
+ 33,
923
+ 200,
924
+ 224,
925
+ 32,
926
+ 202,
927
+ 225,
928
+ 31,
929
+ 205,
930
+ 225,
931
+ 29,
932
+ 208,
933
+ 225,
934
+ 28,
935
+ 210,
936
+ 226,
937
+ 27,
938
+ 213,
939
+ 226,
940
+ 26,
941
+ 216,
942
+ 226,
943
+ 25,
944
+ 218,
945
+ 227,
946
+ 25,
947
+ 221,
948
+ 227,
949
+ 24,
950
+ 223,
951
+ 227,
952
+ 24,
953
+ 226,
954
+ 228,
955
+ 24,
956
+ 229,
957
+ 228,
958
+ 25,
959
+ 231,
960
+ 228,
961
+ 25,
962
+ 234,
963
+ 229,
964
+ 26,
965
+ 236,
966
+ 229,
967
+ 27,
968
+ 239,
969
+ 229,
970
+ 28,
971
+ 241,
972
+ 229,
973
+ 29,
974
+ 244,
975
+ 230,
976
+ 30,
977
+ 246,
978
+ 230,
979
+ 32,
980
+ 248,
981
+ 230,
982
+ 33,
983
+ 251,
984
+ 231,
985
+ 35,
986
+ 253,
987
+ 231,
988
+ 37
989
+ ]);
990
+ var MAGMA_LUT = new Uint8Array([
991
+ 0,
992
+ 0,
993
+ 4,
994
+ 1,
995
+ 0,
996
+ 5,
997
+ 1,
998
+ 1,
999
+ 6,
1000
+ 1,
1001
+ 1,
1002
+ 8,
1003
+ 2,
1004
+ 1,
1005
+ 9,
1006
+ 2,
1007
+ 2,
1008
+ 11,
1009
+ 2,
1010
+ 2,
1011
+ 13,
1012
+ 3,
1013
+ 3,
1014
+ 15,
1015
+ 3,
1016
+ 3,
1017
+ 18,
1018
+ 4,
1019
+ 4,
1020
+ 20,
1021
+ 5,
1022
+ 4,
1023
+ 22,
1024
+ 6,
1025
+ 5,
1026
+ 24,
1027
+ 6,
1028
+ 5,
1029
+ 26,
1030
+ 7,
1031
+ 6,
1032
+ 28,
1033
+ 8,
1034
+ 7,
1035
+ 30,
1036
+ 9,
1037
+ 7,
1038
+ 32,
1039
+ 10,
1040
+ 8,
1041
+ 34,
1042
+ 11,
1043
+ 9,
1044
+ 36,
1045
+ 12,
1046
+ 9,
1047
+ 38,
1048
+ 13,
1049
+ 10,
1050
+ 41,
1051
+ 14,
1052
+ 11,
1053
+ 43,
1054
+ 16,
1055
+ 11,
1056
+ 45,
1057
+ 17,
1058
+ 12,
1059
+ 47,
1060
+ 18,
1061
+ 13,
1062
+ 49,
1063
+ 19,
1064
+ 13,
1065
+ 52,
1066
+ 20,
1067
+ 14,
1068
+ 54,
1069
+ 21,
1070
+ 14,
1071
+ 56,
1072
+ 22,
1073
+ 15,
1074
+ 59,
1075
+ 24,
1076
+ 15,
1077
+ 61,
1078
+ 25,
1079
+ 16,
1080
+ 63,
1081
+ 26,
1082
+ 16,
1083
+ 66,
1084
+ 28,
1085
+ 16,
1086
+ 68,
1087
+ 29,
1088
+ 17,
1089
+ 71,
1090
+ 30,
1091
+ 17,
1092
+ 73,
1093
+ 32,
1094
+ 17,
1095
+ 75,
1096
+ 33,
1097
+ 17,
1098
+ 78,
1099
+ 34,
1100
+ 17,
1101
+ 80,
1102
+ 36,
1103
+ 18,
1104
+ 83,
1105
+ 37,
1106
+ 18,
1107
+ 85,
1108
+ 39,
1109
+ 18,
1110
+ 88,
1111
+ 41,
1112
+ 17,
1113
+ 90,
1114
+ 42,
1115
+ 17,
1116
+ 92,
1117
+ 44,
1118
+ 17,
1119
+ 95,
1120
+ 45,
1121
+ 17,
1122
+ 97,
1123
+ 47,
1124
+ 17,
1125
+ 99,
1126
+ 49,
1127
+ 17,
1128
+ 101,
1129
+ 51,
1130
+ 16,
1131
+ 103,
1132
+ 52,
1133
+ 16,
1134
+ 105,
1135
+ 54,
1136
+ 16,
1137
+ 107,
1138
+ 56,
1139
+ 16,
1140
+ 108,
1141
+ 57,
1142
+ 15,
1143
+ 110,
1144
+ 59,
1145
+ 15,
1146
+ 112,
1147
+ 61,
1148
+ 15,
1149
+ 113,
1150
+ 63,
1151
+ 15,
1152
+ 114,
1153
+ 64,
1154
+ 15,
1155
+ 116,
1156
+ 66,
1157
+ 15,
1158
+ 117,
1159
+ 68,
1160
+ 15,
1161
+ 118,
1162
+ 69,
1163
+ 16,
1164
+ 119,
1165
+ 71,
1166
+ 16,
1167
+ 120,
1168
+ 73,
1169
+ 16,
1170
+ 120,
1171
+ 74,
1172
+ 16,
1173
+ 121,
1174
+ 76,
1175
+ 17,
1176
+ 122,
1177
+ 78,
1178
+ 17,
1179
+ 123,
1180
+ 79,
1181
+ 18,
1182
+ 123,
1183
+ 81,
1184
+ 18,
1185
+ 124,
1186
+ 82,
1187
+ 19,
1188
+ 124,
1189
+ 84,
1190
+ 19,
1191
+ 125,
1192
+ 86,
1193
+ 20,
1194
+ 125,
1195
+ 87,
1196
+ 21,
1197
+ 126,
1198
+ 89,
1199
+ 21,
1200
+ 126,
1201
+ 90,
1202
+ 22,
1203
+ 126,
1204
+ 92,
1205
+ 22,
1206
+ 127,
1207
+ 93,
1208
+ 23,
1209
+ 127,
1210
+ 95,
1211
+ 24,
1212
+ 127,
1213
+ 96,
1214
+ 24,
1215
+ 128,
1216
+ 98,
1217
+ 25,
1218
+ 128,
1219
+ 100,
1220
+ 26,
1221
+ 128,
1222
+ 101,
1223
+ 26,
1224
+ 128,
1225
+ 103,
1226
+ 27,
1227
+ 128,
1228
+ 104,
1229
+ 28,
1230
+ 129,
1231
+ 106,
1232
+ 28,
1233
+ 129,
1234
+ 107,
1235
+ 29,
1236
+ 129,
1237
+ 109,
1238
+ 29,
1239
+ 129,
1240
+ 110,
1241
+ 30,
1242
+ 129,
1243
+ 112,
1244
+ 31,
1245
+ 129,
1246
+ 114,
1247
+ 31,
1248
+ 129,
1249
+ 115,
1250
+ 32,
1251
+ 129,
1252
+ 117,
1253
+ 33,
1254
+ 129,
1255
+ 118,
1256
+ 33,
1257
+ 129,
1258
+ 120,
1259
+ 34,
1260
+ 129,
1261
+ 121,
1262
+ 34,
1263
+ 130,
1264
+ 123,
1265
+ 35,
1266
+ 130,
1267
+ 124,
1268
+ 35,
1269
+ 130,
1270
+ 126,
1271
+ 36,
1272
+ 130,
1273
+ 128,
1274
+ 37,
1275
+ 130,
1276
+ 129,
1277
+ 37,
1278
+ 129,
1279
+ 131,
1280
+ 38,
1281
+ 129,
1282
+ 132,
1283
+ 38,
1284
+ 129,
1285
+ 134,
1286
+ 39,
1287
+ 129,
1288
+ 136,
1289
+ 39,
1290
+ 129,
1291
+ 137,
1292
+ 40,
1293
+ 129,
1294
+ 139,
1295
+ 41,
1296
+ 129,
1297
+ 140,
1298
+ 41,
1299
+ 129,
1300
+ 142,
1301
+ 42,
1302
+ 129,
1303
+ 144,
1304
+ 42,
1305
+ 129,
1306
+ 145,
1307
+ 43,
1308
+ 129,
1309
+ 147,
1310
+ 43,
1311
+ 128,
1312
+ 148,
1313
+ 44,
1314
+ 128,
1315
+ 150,
1316
+ 44,
1317
+ 128,
1318
+ 152,
1319
+ 45,
1320
+ 128,
1321
+ 153,
1322
+ 45,
1323
+ 128,
1324
+ 155,
1325
+ 46,
1326
+ 127,
1327
+ 156,
1328
+ 46,
1329
+ 127,
1330
+ 158,
1331
+ 47,
1332
+ 127,
1333
+ 160,
1334
+ 47,
1335
+ 127,
1336
+ 161,
1337
+ 48,
1338
+ 126,
1339
+ 163,
1340
+ 48,
1341
+ 126,
1342
+ 165,
1343
+ 49,
1344
+ 126,
1345
+ 166,
1346
+ 49,
1347
+ 125,
1348
+ 168,
1349
+ 50,
1350
+ 125,
1351
+ 170,
1352
+ 51,
1353
+ 125,
1354
+ 171,
1355
+ 51,
1356
+ 124,
1357
+ 173,
1358
+ 52,
1359
+ 124,
1360
+ 174,
1361
+ 52,
1362
+ 123,
1363
+ 176,
1364
+ 53,
1365
+ 123,
1366
+ 178,
1367
+ 53,
1368
+ 123,
1369
+ 179,
1370
+ 54,
1371
+ 122,
1372
+ 181,
1373
+ 54,
1374
+ 122,
1375
+ 183,
1376
+ 55,
1377
+ 121,
1378
+ 184,
1379
+ 55,
1380
+ 121,
1381
+ 186,
1382
+ 56,
1383
+ 120,
1384
+ 188,
1385
+ 57,
1386
+ 120,
1387
+ 189,
1388
+ 57,
1389
+ 119,
1390
+ 191,
1391
+ 58,
1392
+ 119,
1393
+ 192,
1394
+ 58,
1395
+ 118,
1396
+ 194,
1397
+ 59,
1398
+ 117,
1399
+ 196,
1400
+ 60,
1401
+ 117,
1402
+ 197,
1403
+ 60,
1404
+ 116,
1405
+ 199,
1406
+ 61,
1407
+ 115,
1408
+ 200,
1409
+ 62,
1410
+ 115,
1411
+ 202,
1412
+ 62,
1413
+ 114,
1414
+ 204,
1415
+ 63,
1416
+ 113,
1417
+ 205,
1418
+ 64,
1419
+ 113,
1420
+ 207,
1421
+ 64,
1422
+ 112,
1423
+ 208,
1424
+ 65,
1425
+ 111,
1426
+ 210,
1427
+ 66,
1428
+ 111,
1429
+ 211,
1430
+ 67,
1431
+ 110,
1432
+ 213,
1433
+ 68,
1434
+ 109,
1435
+ 214,
1436
+ 69,
1437
+ 108,
1438
+ 216,
1439
+ 69,
1440
+ 108,
1441
+ 217,
1442
+ 70,
1443
+ 107,
1444
+ 219,
1445
+ 71,
1446
+ 106,
1447
+ 220,
1448
+ 72,
1449
+ 105,
1450
+ 222,
1451
+ 73,
1452
+ 104,
1453
+ 223,
1454
+ 74,
1455
+ 104,
1456
+ 224,
1457
+ 76,
1458
+ 103,
1459
+ 226,
1460
+ 77,
1461
+ 102,
1462
+ 227,
1463
+ 78,
1464
+ 101,
1465
+ 228,
1466
+ 79,
1467
+ 100,
1468
+ 229,
1469
+ 80,
1470
+ 100,
1471
+ 231,
1472
+ 82,
1473
+ 99,
1474
+ 232,
1475
+ 83,
1476
+ 98,
1477
+ 233,
1478
+ 84,
1479
+ 98,
1480
+ 234,
1481
+ 86,
1482
+ 97,
1483
+ 235,
1484
+ 87,
1485
+ 96,
1486
+ 236,
1487
+ 88,
1488
+ 96,
1489
+ 237,
1490
+ 90,
1491
+ 95,
1492
+ 238,
1493
+ 91,
1494
+ 94,
1495
+ 239,
1496
+ 93,
1497
+ 94,
1498
+ 240,
1499
+ 95,
1500
+ 94,
1501
+ 241,
1502
+ 96,
1503
+ 93,
1504
+ 242,
1505
+ 98,
1506
+ 93,
1507
+ 242,
1508
+ 100,
1509
+ 92,
1510
+ 243,
1511
+ 101,
1512
+ 92,
1513
+ 244,
1514
+ 103,
1515
+ 92,
1516
+ 244,
1517
+ 105,
1518
+ 92,
1519
+ 245,
1520
+ 107,
1521
+ 92,
1522
+ 246,
1523
+ 108,
1524
+ 92,
1525
+ 246,
1526
+ 110,
1527
+ 92,
1528
+ 247,
1529
+ 112,
1530
+ 92,
1531
+ 247,
1532
+ 114,
1533
+ 92,
1534
+ 248,
1535
+ 116,
1536
+ 92,
1537
+ 248,
1538
+ 118,
1539
+ 92,
1540
+ 249,
1541
+ 120,
1542
+ 93,
1543
+ 249,
1544
+ 121,
1545
+ 93,
1546
+ 249,
1547
+ 123,
1548
+ 93,
1549
+ 250,
1550
+ 125,
1551
+ 94,
1552
+ 250,
1553
+ 127,
1554
+ 94,
1555
+ 250,
1556
+ 129,
1557
+ 95,
1558
+ 251,
1559
+ 131,
1560
+ 95,
1561
+ 251,
1562
+ 133,
1563
+ 96,
1564
+ 251,
1565
+ 135,
1566
+ 97,
1567
+ 252,
1568
+ 137,
1569
+ 97,
1570
+ 252,
1571
+ 138,
1572
+ 98,
1573
+ 252,
1574
+ 140,
1575
+ 99,
1576
+ 252,
1577
+ 142,
1578
+ 100,
1579
+ 252,
1580
+ 144,
1581
+ 101,
1582
+ 253,
1583
+ 146,
1584
+ 102,
1585
+ 253,
1586
+ 148,
1587
+ 103,
1588
+ 253,
1589
+ 150,
1590
+ 104,
1591
+ 253,
1592
+ 152,
1593
+ 105,
1594
+ 253,
1595
+ 154,
1596
+ 106,
1597
+ 253,
1598
+ 155,
1599
+ 107,
1600
+ 254,
1601
+ 157,
1602
+ 108,
1603
+ 254,
1604
+ 159,
1605
+ 109,
1606
+ 254,
1607
+ 161,
1608
+ 110,
1609
+ 254,
1610
+ 163,
1611
+ 111,
1612
+ 254,
1613
+ 165,
1614
+ 113,
1615
+ 254,
1616
+ 167,
1617
+ 114,
1618
+ 254,
1619
+ 169,
1620
+ 115,
1621
+ 254,
1622
+ 170,
1623
+ 116,
1624
+ 254,
1625
+ 172,
1626
+ 118,
1627
+ 254,
1628
+ 174,
1629
+ 119,
1630
+ 254,
1631
+ 176,
1632
+ 120,
1633
+ 254,
1634
+ 178,
1635
+ 122,
1636
+ 254,
1637
+ 180,
1638
+ 123,
1639
+ 254,
1640
+ 182,
1641
+ 124,
1642
+ 254,
1643
+ 183,
1644
+ 126,
1645
+ 254,
1646
+ 185,
1647
+ 127,
1648
+ 254,
1649
+ 187,
1650
+ 129,
1651
+ 254,
1652
+ 189,
1653
+ 130,
1654
+ 254,
1655
+ 191,
1656
+ 132,
1657
+ 254,
1658
+ 193,
1659
+ 133,
1660
+ 254,
1661
+ 194,
1662
+ 135,
1663
+ 254,
1664
+ 196,
1665
+ 136,
1666
+ 254,
1667
+ 198,
1668
+ 138,
1669
+ 254,
1670
+ 200,
1671
+ 140,
1672
+ 254,
1673
+ 202,
1674
+ 141,
1675
+ 254,
1676
+ 204,
1677
+ 143,
1678
+ 254,
1679
+ 205,
1680
+ 144,
1681
+ 254,
1682
+ 207,
1683
+ 146,
1684
+ 254,
1685
+ 209,
1686
+ 148,
1687
+ 254,
1688
+ 211,
1689
+ 149,
1690
+ 254,
1691
+ 213,
1692
+ 151,
1693
+ 254,
1694
+ 215,
1695
+ 153,
1696
+ 254,
1697
+ 216,
1698
+ 154,
1699
+ 253,
1700
+ 218,
1701
+ 156,
1702
+ 253,
1703
+ 220,
1704
+ 158,
1705
+ 253,
1706
+ 222,
1707
+ 160,
1708
+ 253,
1709
+ 224,
1710
+ 161,
1711
+ 253,
1712
+ 226,
1713
+ 163,
1714
+ 253,
1715
+ 227,
1716
+ 165,
1717
+ 253,
1718
+ 229,
1719
+ 167,
1720
+ 253,
1721
+ 231,
1722
+ 169,
1723
+ 253,
1724
+ 233,
1725
+ 170,
1726
+ 253,
1727
+ 235,
1728
+ 172,
1729
+ 252,
1730
+ 236,
1731
+ 174,
1732
+ 252,
1733
+ 238,
1734
+ 176,
1735
+ 252,
1736
+ 240,
1737
+ 178,
1738
+ 252,
1739
+ 242,
1740
+ 180,
1741
+ 252,
1742
+ 244,
1743
+ 182,
1744
+ 252,
1745
+ 246,
1746
+ 184,
1747
+ 252,
1748
+ 247,
1749
+ 185,
1750
+ 252,
1751
+ 249,
1752
+ 187,
1753
+ 252,
1754
+ 251,
1755
+ 189,
1756
+ 252,
1757
+ 253,
1758
+ 191
1759
+ ]);
1760
+ var INFERNO_LUT = new Uint8Array([
1761
+ 0,
1762
+ 0,
1763
+ 4,
1764
+ 1,
1765
+ 0,
1766
+ 5,
1767
+ 1,
1768
+ 1,
1769
+ 6,
1770
+ 1,
1771
+ 1,
1772
+ 8,
1773
+ 2,
1774
+ 1,
1775
+ 10,
1776
+ 2,
1777
+ 2,
1778
+ 12,
1779
+ 2,
1780
+ 2,
1781
+ 14,
1782
+ 3,
1783
+ 2,
1784
+ 16,
1785
+ 4,
1786
+ 3,
1787
+ 18,
1788
+ 4,
1789
+ 3,
1790
+ 20,
1791
+ 5,
1792
+ 4,
1793
+ 23,
1794
+ 6,
1795
+ 4,
1796
+ 25,
1797
+ 7,
1798
+ 5,
1799
+ 27,
1800
+ 8,
1801
+ 5,
1802
+ 29,
1803
+ 9,
1804
+ 6,
1805
+ 31,
1806
+ 10,
1807
+ 7,
1808
+ 34,
1809
+ 11,
1810
+ 7,
1811
+ 36,
1812
+ 12,
1813
+ 8,
1814
+ 38,
1815
+ 13,
1816
+ 8,
1817
+ 41,
1818
+ 14,
1819
+ 9,
1820
+ 43,
1821
+ 16,
1822
+ 9,
1823
+ 45,
1824
+ 17,
1825
+ 10,
1826
+ 48,
1827
+ 18,
1828
+ 10,
1829
+ 50,
1830
+ 20,
1831
+ 11,
1832
+ 52,
1833
+ 21,
1834
+ 11,
1835
+ 55,
1836
+ 22,
1837
+ 11,
1838
+ 57,
1839
+ 24,
1840
+ 12,
1841
+ 60,
1842
+ 25,
1843
+ 12,
1844
+ 62,
1845
+ 27,
1846
+ 12,
1847
+ 65,
1848
+ 28,
1849
+ 12,
1850
+ 67,
1851
+ 30,
1852
+ 12,
1853
+ 69,
1854
+ 31,
1855
+ 12,
1856
+ 72,
1857
+ 33,
1858
+ 12,
1859
+ 74,
1860
+ 35,
1861
+ 12,
1862
+ 76,
1863
+ 36,
1864
+ 12,
1865
+ 79,
1866
+ 38,
1867
+ 12,
1868
+ 81,
1869
+ 40,
1870
+ 11,
1871
+ 83,
1872
+ 41,
1873
+ 11,
1874
+ 85,
1875
+ 43,
1876
+ 11,
1877
+ 87,
1878
+ 45,
1879
+ 11,
1880
+ 89,
1881
+ 47,
1882
+ 10,
1883
+ 91,
1884
+ 49,
1885
+ 10,
1886
+ 92,
1887
+ 50,
1888
+ 10,
1889
+ 94,
1890
+ 52,
1891
+ 10,
1892
+ 95,
1893
+ 54,
1894
+ 9,
1895
+ 97,
1896
+ 56,
1897
+ 9,
1898
+ 98,
1899
+ 57,
1900
+ 9,
1901
+ 99,
1902
+ 59,
1903
+ 9,
1904
+ 100,
1905
+ 61,
1906
+ 9,
1907
+ 101,
1908
+ 62,
1909
+ 9,
1910
+ 102,
1911
+ 64,
1912
+ 10,
1913
+ 103,
1914
+ 66,
1915
+ 10,
1916
+ 104,
1917
+ 68,
1918
+ 10,
1919
+ 104,
1920
+ 69,
1921
+ 10,
1922
+ 105,
1923
+ 71,
1924
+ 11,
1925
+ 106,
1926
+ 73,
1927
+ 11,
1928
+ 106,
1929
+ 74,
1930
+ 12,
1931
+ 107,
1932
+ 76,
1933
+ 12,
1934
+ 107,
1935
+ 77,
1936
+ 13,
1937
+ 108,
1938
+ 79,
1939
+ 13,
1940
+ 108,
1941
+ 81,
1942
+ 14,
1943
+ 108,
1944
+ 82,
1945
+ 14,
1946
+ 109,
1947
+ 84,
1948
+ 15,
1949
+ 109,
1950
+ 85,
1951
+ 15,
1952
+ 109,
1953
+ 87,
1954
+ 16,
1955
+ 110,
1956
+ 89,
1957
+ 16,
1958
+ 110,
1959
+ 90,
1960
+ 17,
1961
+ 110,
1962
+ 92,
1963
+ 18,
1964
+ 110,
1965
+ 93,
1966
+ 18,
1967
+ 110,
1968
+ 95,
1969
+ 19,
1970
+ 110,
1971
+ 97,
1972
+ 19,
1973
+ 110,
1974
+ 98,
1975
+ 20,
1976
+ 110,
1977
+ 100,
1978
+ 21,
1979
+ 110,
1980
+ 101,
1981
+ 21,
1982
+ 110,
1983
+ 103,
1984
+ 22,
1985
+ 110,
1986
+ 105,
1987
+ 22,
1988
+ 110,
1989
+ 106,
1990
+ 23,
1991
+ 110,
1992
+ 108,
1993
+ 24,
1994
+ 110,
1995
+ 109,
1996
+ 24,
1997
+ 110,
1998
+ 111,
1999
+ 25,
2000
+ 110,
2001
+ 113,
2002
+ 25,
2003
+ 110,
2004
+ 114,
2005
+ 26,
2006
+ 110,
2007
+ 116,
2008
+ 26,
2009
+ 110,
2010
+ 117,
2011
+ 27,
2012
+ 110,
2013
+ 119,
2014
+ 28,
2015
+ 109,
2016
+ 120,
2017
+ 28,
2018
+ 109,
2019
+ 122,
2020
+ 29,
2021
+ 109,
2022
+ 124,
2023
+ 29,
2024
+ 109,
2025
+ 125,
2026
+ 30,
2027
+ 109,
2028
+ 127,
2029
+ 30,
2030
+ 108,
2031
+ 128,
2032
+ 31,
2033
+ 108,
2034
+ 130,
2035
+ 32,
2036
+ 108,
2037
+ 132,
2038
+ 32,
2039
+ 107,
2040
+ 133,
2041
+ 33,
2042
+ 107,
2043
+ 135,
2044
+ 33,
2045
+ 107,
2046
+ 136,
2047
+ 34,
2048
+ 106,
2049
+ 138,
2050
+ 34,
2051
+ 106,
2052
+ 140,
2053
+ 35,
2054
+ 105,
2055
+ 141,
2056
+ 35,
2057
+ 105,
2058
+ 143,
2059
+ 36,
2060
+ 105,
2061
+ 144,
2062
+ 37,
2063
+ 104,
2064
+ 146,
2065
+ 37,
2066
+ 104,
2067
+ 147,
2068
+ 38,
2069
+ 103,
2070
+ 149,
2071
+ 38,
2072
+ 103,
2073
+ 151,
2074
+ 39,
2075
+ 102,
2076
+ 152,
2077
+ 39,
2078
+ 102,
2079
+ 154,
2080
+ 40,
2081
+ 101,
2082
+ 155,
2083
+ 41,
2084
+ 100,
2085
+ 157,
2086
+ 41,
2087
+ 100,
2088
+ 159,
2089
+ 42,
2090
+ 99,
2091
+ 160,
2092
+ 42,
2093
+ 99,
2094
+ 162,
2095
+ 43,
2096
+ 98,
2097
+ 163,
2098
+ 44,
2099
+ 97,
2100
+ 165,
2101
+ 44,
2102
+ 96,
2103
+ 166,
2104
+ 45,
2105
+ 96,
2106
+ 168,
2107
+ 46,
2108
+ 95,
2109
+ 169,
2110
+ 46,
2111
+ 94,
2112
+ 171,
2113
+ 47,
2114
+ 94,
2115
+ 173,
2116
+ 48,
2117
+ 93,
2118
+ 174,
2119
+ 48,
2120
+ 92,
2121
+ 176,
2122
+ 49,
2123
+ 91,
2124
+ 177,
2125
+ 50,
2126
+ 90,
2127
+ 179,
2128
+ 50,
2129
+ 90,
2130
+ 180,
2131
+ 51,
2132
+ 89,
2133
+ 182,
2134
+ 52,
2135
+ 88,
2136
+ 183,
2137
+ 53,
2138
+ 87,
2139
+ 185,
2140
+ 53,
2141
+ 86,
2142
+ 186,
2143
+ 54,
2144
+ 85,
2145
+ 188,
2146
+ 55,
2147
+ 84,
2148
+ 189,
2149
+ 56,
2150
+ 83,
2151
+ 191,
2152
+ 57,
2153
+ 82,
2154
+ 192,
2155
+ 58,
2156
+ 81,
2157
+ 193,
2158
+ 58,
2159
+ 80,
2160
+ 195,
2161
+ 59,
2162
+ 79,
2163
+ 196,
2164
+ 60,
2165
+ 78,
2166
+ 198,
2167
+ 61,
2168
+ 77,
2169
+ 199,
2170
+ 62,
2171
+ 76,
2172
+ 200,
2173
+ 63,
2174
+ 75,
2175
+ 202,
2176
+ 64,
2177
+ 74,
2178
+ 203,
2179
+ 65,
2180
+ 73,
2181
+ 204,
2182
+ 66,
2183
+ 72,
2184
+ 206,
2185
+ 67,
2186
+ 71,
2187
+ 207,
2188
+ 68,
2189
+ 70,
2190
+ 208,
2191
+ 69,
2192
+ 69,
2193
+ 210,
2194
+ 70,
2195
+ 68,
2196
+ 211,
2197
+ 71,
2198
+ 67,
2199
+ 212,
2200
+ 72,
2201
+ 66,
2202
+ 213,
2203
+ 74,
2204
+ 65,
2205
+ 215,
2206
+ 75,
2207
+ 63,
2208
+ 216,
2209
+ 76,
2210
+ 62,
2211
+ 217,
2212
+ 77,
2213
+ 61,
2214
+ 218,
2215
+ 78,
2216
+ 60,
2217
+ 219,
2218
+ 80,
2219
+ 59,
2220
+ 221,
2221
+ 81,
2222
+ 58,
2223
+ 222,
2224
+ 82,
2225
+ 56,
2226
+ 223,
2227
+ 83,
2228
+ 55,
2229
+ 224,
2230
+ 85,
2231
+ 54,
2232
+ 225,
2233
+ 86,
2234
+ 53,
2235
+ 226,
2236
+ 87,
2237
+ 52,
2238
+ 227,
2239
+ 89,
2240
+ 51,
2241
+ 228,
2242
+ 90,
2243
+ 49,
2244
+ 229,
2245
+ 92,
2246
+ 48,
2247
+ 230,
2248
+ 93,
2249
+ 47,
2250
+ 231,
2251
+ 94,
2252
+ 46,
2253
+ 232,
2254
+ 96,
2255
+ 45,
2256
+ 233,
2257
+ 97,
2258
+ 43,
2259
+ 234,
2260
+ 99,
2261
+ 42,
2262
+ 235,
2263
+ 100,
2264
+ 41,
2265
+ 235,
2266
+ 102,
2267
+ 40,
2268
+ 236,
2269
+ 103,
2270
+ 38,
2271
+ 237,
2272
+ 105,
2273
+ 37,
2274
+ 238,
2275
+ 106,
2276
+ 36,
2277
+ 239,
2278
+ 108,
2279
+ 35,
2280
+ 239,
2281
+ 110,
2282
+ 33,
2283
+ 240,
2284
+ 111,
2285
+ 32,
2286
+ 241,
2287
+ 113,
2288
+ 31,
2289
+ 241,
2290
+ 115,
2291
+ 29,
2292
+ 242,
2293
+ 116,
2294
+ 28,
2295
+ 243,
2296
+ 118,
2297
+ 27,
2298
+ 243,
2299
+ 120,
2300
+ 25,
2301
+ 244,
2302
+ 121,
2303
+ 24,
2304
+ 245,
2305
+ 123,
2306
+ 23,
2307
+ 245,
2308
+ 125,
2309
+ 21,
2310
+ 246,
2311
+ 126,
2312
+ 20,
2313
+ 246,
2314
+ 128,
2315
+ 19,
2316
+ 247,
2317
+ 130,
2318
+ 18,
2319
+ 247,
2320
+ 132,
2321
+ 16,
2322
+ 248,
2323
+ 133,
2324
+ 15,
2325
+ 248,
2326
+ 135,
2327
+ 14,
2328
+ 248,
2329
+ 137,
2330
+ 12,
2331
+ 249,
2332
+ 139,
2333
+ 11,
2334
+ 249,
2335
+ 140,
2336
+ 10,
2337
+ 249,
2338
+ 142,
2339
+ 9,
2340
+ 250,
2341
+ 144,
2342
+ 8,
2343
+ 250,
2344
+ 146,
2345
+ 7,
2346
+ 250,
2347
+ 148,
2348
+ 7,
2349
+ 251,
2350
+ 150,
2351
+ 6,
2352
+ 251,
2353
+ 151,
2354
+ 6,
2355
+ 251,
2356
+ 153,
2357
+ 6,
2358
+ 251,
2359
+ 155,
2360
+ 6,
2361
+ 251,
2362
+ 157,
2363
+ 7,
2364
+ 252,
2365
+ 159,
2366
+ 7,
2367
+ 252,
2368
+ 161,
2369
+ 8,
2370
+ 252,
2371
+ 163,
2372
+ 9,
2373
+ 252,
2374
+ 165,
2375
+ 10,
2376
+ 252,
2377
+ 166,
2378
+ 12,
2379
+ 252,
2380
+ 168,
2381
+ 13,
2382
+ 252,
2383
+ 170,
2384
+ 15,
2385
+ 252,
2386
+ 172,
2387
+ 17,
2388
+ 252,
2389
+ 174,
2390
+ 18,
2391
+ 252,
2392
+ 176,
2393
+ 20,
2394
+ 252,
2395
+ 178,
2396
+ 22,
2397
+ 252,
2398
+ 180,
2399
+ 24,
2400
+ 251,
2401
+ 182,
2402
+ 26,
2403
+ 251,
2404
+ 184,
2405
+ 29,
2406
+ 251,
2407
+ 186,
2408
+ 31,
2409
+ 251,
2410
+ 188,
2411
+ 33,
2412
+ 251,
2413
+ 190,
2414
+ 35,
2415
+ 250,
2416
+ 192,
2417
+ 38,
2418
+ 250,
2419
+ 194,
2420
+ 40,
2421
+ 250,
2422
+ 196,
2423
+ 42,
2424
+ 250,
2425
+ 198,
2426
+ 45,
2427
+ 249,
2428
+ 199,
2429
+ 47,
2430
+ 249,
2431
+ 201,
2432
+ 50,
2433
+ 249,
2434
+ 203,
2435
+ 53,
2436
+ 248,
2437
+ 205,
2438
+ 55,
2439
+ 248,
2440
+ 207,
2441
+ 58,
2442
+ 247,
2443
+ 209,
2444
+ 61,
2445
+ 247,
2446
+ 211,
2447
+ 64,
2448
+ 246,
2449
+ 213,
2450
+ 67,
2451
+ 246,
2452
+ 215,
2453
+ 70,
2454
+ 245,
2455
+ 217,
2456
+ 73,
2457
+ 245,
2458
+ 219,
2459
+ 76,
2460
+ 244,
2461
+ 221,
2462
+ 79,
2463
+ 244,
2464
+ 223,
2465
+ 83,
2466
+ 244,
2467
+ 225,
2468
+ 86,
2469
+ 243,
2470
+ 227,
2471
+ 90,
2472
+ 243,
2473
+ 229,
2474
+ 93,
2475
+ 242,
2476
+ 230,
2477
+ 97,
2478
+ 242,
2479
+ 232,
2480
+ 101,
2481
+ 242,
2482
+ 234,
2483
+ 105,
2484
+ 241,
2485
+ 236,
2486
+ 109,
2487
+ 241,
2488
+ 237,
2489
+ 113,
2490
+ 241,
2491
+ 239,
2492
+ 117,
2493
+ 241,
2494
+ 241,
2495
+ 121,
2496
+ 242,
2497
+ 242,
2498
+ 125,
2499
+ 242,
2500
+ 244,
2501
+ 130,
2502
+ 243,
2503
+ 245,
2504
+ 134,
2505
+ 243,
2506
+ 246,
2507
+ 138,
2508
+ 244,
2509
+ 248,
2510
+ 142,
2511
+ 245,
2512
+ 249,
2513
+ 146,
2514
+ 246,
2515
+ 250,
2516
+ 150,
2517
+ 248,
2518
+ 251,
2519
+ 154,
2520
+ 249,
2521
+ 252,
2522
+ 157,
2523
+ 250,
2524
+ 253,
2525
+ 161,
2526
+ 252,
2527
+ 255,
2528
+ 164
2529
+ ]);
2530
+ var ROSEUS_LUT = new Uint8Array([
2531
+ 1,
2532
+ 1,
2533
+ 1,
2534
+ 1,
2535
+ 2,
2536
+ 2,
2537
+ 2,
2538
+ 2,
2539
+ 2,
2540
+ 2,
2541
+ 3,
2542
+ 3,
2543
+ 2,
2544
+ 3,
2545
+ 4,
2546
+ 2,
2547
+ 4,
2548
+ 5,
2549
+ 2,
2550
+ 5,
2551
+ 6,
2552
+ 3,
2553
+ 6,
2554
+ 7,
2555
+ 3,
2556
+ 7,
2557
+ 8,
2558
+ 3,
2559
+ 8,
2560
+ 10,
2561
+ 3,
2562
+ 9,
2563
+ 12,
2564
+ 3,
2565
+ 10,
2566
+ 14,
2567
+ 3,
2568
+ 12,
2569
+ 16,
2570
+ 3,
2571
+ 13,
2572
+ 17,
2573
+ 3,
2574
+ 14,
2575
+ 19,
2576
+ 2,
2577
+ 15,
2578
+ 21,
2579
+ 2,
2580
+ 16,
2581
+ 23,
2582
+ 2,
2583
+ 17,
2584
+ 25,
2585
+ 2,
2586
+ 18,
2587
+ 27,
2588
+ 2,
2589
+ 19,
2590
+ 30,
2591
+ 1,
2592
+ 20,
2593
+ 32,
2594
+ 1,
2595
+ 21,
2596
+ 34,
2597
+ 1,
2598
+ 22,
2599
+ 36,
2600
+ 1,
2601
+ 23,
2602
+ 38,
2603
+ 1,
2604
+ 24,
2605
+ 40,
2606
+ 0,
2607
+ 25,
2608
+ 43,
2609
+ 0,
2610
+ 26,
2611
+ 45,
2612
+ 0,
2613
+ 27,
2614
+ 47,
2615
+ 0,
2616
+ 27,
2617
+ 50,
2618
+ 0,
2619
+ 28,
2620
+ 52,
2621
+ 0,
2622
+ 29,
2623
+ 54,
2624
+ 0,
2625
+ 30,
2626
+ 57,
2627
+ 0,
2628
+ 30,
2629
+ 59,
2630
+ 1,
2631
+ 31,
2632
+ 62,
2633
+ 1,
2634
+ 32,
2635
+ 64,
2636
+ 1,
2637
+ 32,
2638
+ 67,
2639
+ 2,
2640
+ 33,
2641
+ 69,
2642
+ 3,
2643
+ 33,
2644
+ 72,
2645
+ 4,
2646
+ 34,
2647
+ 74,
2648
+ 5,
2649
+ 35,
2650
+ 77,
2651
+ 6,
2652
+ 35,
2653
+ 79,
2654
+ 8,
2655
+ 35,
2656
+ 82,
2657
+ 9,
2658
+ 36,
2659
+ 84,
2660
+ 11,
2661
+ 36,
2662
+ 86,
2663
+ 13,
2664
+ 37,
2665
+ 89,
2666
+ 15,
2667
+ 37,
2668
+ 91,
2669
+ 17,
2670
+ 37,
2671
+ 94,
2672
+ 19,
2673
+ 37,
2674
+ 96,
2675
+ 21,
2676
+ 38,
2677
+ 99,
2678
+ 23,
2679
+ 38,
2680
+ 101,
2681
+ 25,
2682
+ 38,
2683
+ 104,
2684
+ 27,
2685
+ 38,
2686
+ 106,
2687
+ 29,
2688
+ 38,
2689
+ 108,
2690
+ 31,
2691
+ 38,
2692
+ 111,
2693
+ 33,
2694
+ 38,
2695
+ 113,
2696
+ 35,
2697
+ 38,
2698
+ 115,
2699
+ 38,
2700
+ 38,
2701
+ 118,
2702
+ 40,
2703
+ 38,
2704
+ 120,
2705
+ 42,
2706
+ 38,
2707
+ 122,
2708
+ 44,
2709
+ 38,
2710
+ 124,
2711
+ 46,
2712
+ 38,
2713
+ 126,
2714
+ 49,
2715
+ 38,
2716
+ 128,
2717
+ 51,
2718
+ 38,
2719
+ 130,
2720
+ 53,
2721
+ 37,
2722
+ 132,
2723
+ 55,
2724
+ 37,
2725
+ 134,
2726
+ 58,
2727
+ 37,
2728
+ 136,
2729
+ 60,
2730
+ 36,
2731
+ 138,
2732
+ 62,
2733
+ 36,
2734
+ 139,
2735
+ 65,
2736
+ 36,
2737
+ 141,
2738
+ 67,
2739
+ 35,
2740
+ 143,
2741
+ 69,
2742
+ 35,
2743
+ 144,
2744
+ 72,
2745
+ 35,
2746
+ 146,
2747
+ 74,
2748
+ 34,
2749
+ 147,
2750
+ 76,
2751
+ 34,
2752
+ 149,
2753
+ 79,
2754
+ 33,
2755
+ 150,
2756
+ 81,
2757
+ 33,
2758
+ 151,
2759
+ 84,
2760
+ 32,
2761
+ 152,
2762
+ 86,
2763
+ 32,
2764
+ 153,
2765
+ 88,
2766
+ 31,
2767
+ 154,
2768
+ 91,
2769
+ 31,
2770
+ 155,
2771
+ 93,
2772
+ 30,
2773
+ 156,
2774
+ 95,
2775
+ 29,
2776
+ 157,
2777
+ 98,
2778
+ 29,
2779
+ 158,
2780
+ 100,
2781
+ 28,
2782
+ 159,
2783
+ 103,
2784
+ 28,
2785
+ 159,
2786
+ 105,
2787
+ 27,
2788
+ 160,
2789
+ 107,
2790
+ 27,
2791
+ 160,
2792
+ 110,
2793
+ 26,
2794
+ 161,
2795
+ 112,
2796
+ 26,
2797
+ 161,
2798
+ 114,
2799
+ 25,
2800
+ 161,
2801
+ 117,
2802
+ 25,
2803
+ 162,
2804
+ 119,
2805
+ 24,
2806
+ 162,
2807
+ 121,
2808
+ 24,
2809
+ 162,
2810
+ 124,
2811
+ 23,
2812
+ 162,
2813
+ 126,
2814
+ 23,
2815
+ 162,
2816
+ 128,
2817
+ 23,
2818
+ 162,
2819
+ 131,
2820
+ 22,
2821
+ 161,
2822
+ 133,
2823
+ 22,
2824
+ 161,
2825
+ 135,
2826
+ 22,
2827
+ 161,
2828
+ 137,
2829
+ 22,
2830
+ 161,
2831
+ 140,
2832
+ 22,
2833
+ 160,
2834
+ 142,
2835
+ 22,
2836
+ 160,
2837
+ 144,
2838
+ 22,
2839
+ 159,
2840
+ 146,
2841
+ 22,
2842
+ 159,
2843
+ 148,
2844
+ 22,
2845
+ 158,
2846
+ 150,
2847
+ 22,
2848
+ 157,
2849
+ 153,
2850
+ 22,
2851
+ 157,
2852
+ 155,
2853
+ 23,
2854
+ 156,
2855
+ 157,
2856
+ 23,
2857
+ 155,
2858
+ 159,
2859
+ 23,
2860
+ 154,
2861
+ 161,
2862
+ 24,
2863
+ 153,
2864
+ 163,
2865
+ 24,
2866
+ 152,
2867
+ 165,
2868
+ 25,
2869
+ 151,
2870
+ 167,
2871
+ 26,
2872
+ 150,
2873
+ 169,
2874
+ 26,
2875
+ 149,
2876
+ 171,
2877
+ 27,
2878
+ 148,
2879
+ 173,
2880
+ 28,
2881
+ 147,
2882
+ 175,
2883
+ 29,
2884
+ 146,
2885
+ 177,
2886
+ 29,
2887
+ 145,
2888
+ 179,
2889
+ 30,
2890
+ 144,
2891
+ 181,
2892
+ 31,
2893
+ 142,
2894
+ 183,
2895
+ 32,
2896
+ 141,
2897
+ 184,
2898
+ 33,
2899
+ 140,
2900
+ 186,
2901
+ 34,
2902
+ 139,
2903
+ 188,
2904
+ 35,
2905
+ 137,
2906
+ 190,
2907
+ 36,
2908
+ 136,
2909
+ 192,
2910
+ 37,
2911
+ 135,
2912
+ 193,
2913
+ 39,
2914
+ 133,
2915
+ 195,
2916
+ 40,
2917
+ 132,
2918
+ 197,
2919
+ 41,
2920
+ 130,
2921
+ 198,
2922
+ 42,
2923
+ 129,
2924
+ 200,
2925
+ 43,
2926
+ 128,
2927
+ 202,
2928
+ 45,
2929
+ 126,
2930
+ 203,
2931
+ 46,
2932
+ 125,
2933
+ 205,
2934
+ 47,
2935
+ 123,
2936
+ 206,
2937
+ 48,
2938
+ 122,
2939
+ 208,
2940
+ 50,
2941
+ 120,
2942
+ 209,
2943
+ 51,
2944
+ 119,
2945
+ 211,
2946
+ 52,
2947
+ 117,
2948
+ 212,
2949
+ 54,
2950
+ 116,
2951
+ 214,
2952
+ 55,
2953
+ 114,
2954
+ 215,
2955
+ 57,
2956
+ 113,
2957
+ 217,
2958
+ 58,
2959
+ 111,
2960
+ 218,
2961
+ 60,
2962
+ 110,
2963
+ 219,
2964
+ 61,
2965
+ 109,
2966
+ 221,
2967
+ 63,
2968
+ 107,
2969
+ 222,
2970
+ 64,
2971
+ 106,
2972
+ 223,
2973
+ 66,
2974
+ 104,
2975
+ 225,
2976
+ 67,
2977
+ 103,
2978
+ 226,
2979
+ 69,
2980
+ 101,
2981
+ 227,
2982
+ 70,
2983
+ 100,
2984
+ 228,
2985
+ 72,
2986
+ 99,
2987
+ 229,
2988
+ 73,
2989
+ 97,
2990
+ 230,
2991
+ 75,
2992
+ 96,
2993
+ 231,
2994
+ 77,
2995
+ 94,
2996
+ 233,
2997
+ 78,
2998
+ 93,
2999
+ 234,
3000
+ 80,
3001
+ 92,
3002
+ 235,
3003
+ 82,
3004
+ 91,
3005
+ 236,
3006
+ 83,
3007
+ 89,
3008
+ 237,
3009
+ 85,
3010
+ 88,
3011
+ 237,
3012
+ 87,
3013
+ 87,
3014
+ 238,
3015
+ 89,
3016
+ 86,
3017
+ 239,
3018
+ 90,
3019
+ 84,
3020
+ 240,
3021
+ 92,
3022
+ 83,
3023
+ 241,
3024
+ 94,
3025
+ 82,
3026
+ 242,
3027
+ 96,
3028
+ 81,
3029
+ 242,
3030
+ 97,
3031
+ 80,
3032
+ 243,
3033
+ 99,
3034
+ 79,
3035
+ 244,
3036
+ 101,
3037
+ 78,
3038
+ 245,
3039
+ 103,
3040
+ 77,
3041
+ 245,
3042
+ 105,
3043
+ 76,
3044
+ 246,
3045
+ 107,
3046
+ 75,
3047
+ 246,
3048
+ 108,
3049
+ 74,
3050
+ 247,
3051
+ 110,
3052
+ 74,
3053
+ 248,
3054
+ 112,
3055
+ 73,
3056
+ 248,
3057
+ 114,
3058
+ 72,
3059
+ 248,
3060
+ 116,
3061
+ 72,
3062
+ 249,
3063
+ 118,
3064
+ 71,
3065
+ 249,
3066
+ 120,
3067
+ 71,
3068
+ 250,
3069
+ 122,
3070
+ 70,
3071
+ 250,
3072
+ 124,
3073
+ 70,
3074
+ 250,
3075
+ 126,
3076
+ 70,
3077
+ 251,
3078
+ 128,
3079
+ 70,
3080
+ 251,
3081
+ 130,
3082
+ 69,
3083
+ 251,
3084
+ 132,
3085
+ 70,
3086
+ 251,
3087
+ 134,
3088
+ 70,
3089
+ 251,
3090
+ 136,
3091
+ 70,
3092
+ 252,
3093
+ 138,
3094
+ 70,
3095
+ 252,
3096
+ 140,
3097
+ 70,
3098
+ 252,
3099
+ 142,
3100
+ 71,
3101
+ 252,
3102
+ 144,
3103
+ 72,
3104
+ 252,
3105
+ 146,
3106
+ 72,
3107
+ 252,
3108
+ 148,
3109
+ 73,
3110
+ 252,
3111
+ 150,
3112
+ 74,
3113
+ 251,
3114
+ 152,
3115
+ 75,
3116
+ 251,
3117
+ 154,
3118
+ 76,
3119
+ 251,
3120
+ 156,
3121
+ 77,
3122
+ 251,
3123
+ 158,
3124
+ 78,
3125
+ 251,
3126
+ 160,
3127
+ 80,
3128
+ 251,
3129
+ 162,
3130
+ 81,
3131
+ 250,
3132
+ 164,
3133
+ 83,
3134
+ 250,
3135
+ 166,
3136
+ 85,
3137
+ 250,
3138
+ 168,
3139
+ 87,
3140
+ 249,
3141
+ 170,
3142
+ 88,
3143
+ 249,
3144
+ 172,
3145
+ 90,
3146
+ 248,
3147
+ 174,
3148
+ 93,
3149
+ 248,
3150
+ 176,
3151
+ 95,
3152
+ 248,
3153
+ 178,
3154
+ 97,
3155
+ 247,
3156
+ 180,
3157
+ 99,
3158
+ 247,
3159
+ 182,
3160
+ 102,
3161
+ 246,
3162
+ 184,
3163
+ 104,
3164
+ 246,
3165
+ 186,
3166
+ 107,
3167
+ 245,
3168
+ 188,
3169
+ 110,
3170
+ 244,
3171
+ 190,
3172
+ 112,
3173
+ 244,
3174
+ 192,
3175
+ 115,
3176
+ 243,
3177
+ 194,
3178
+ 118,
3179
+ 243,
3180
+ 195,
3181
+ 121,
3182
+ 242,
3183
+ 197,
3184
+ 124,
3185
+ 242,
3186
+ 199,
3187
+ 127,
3188
+ 241,
3189
+ 201,
3190
+ 131,
3191
+ 240,
3192
+ 203,
3193
+ 134,
3194
+ 240,
3195
+ 205,
3196
+ 137,
3197
+ 239,
3198
+ 207,
3199
+ 140,
3200
+ 239,
3201
+ 208,
3202
+ 144,
3203
+ 238,
3204
+ 210,
3205
+ 147,
3206
+ 238,
3207
+ 212,
3208
+ 151,
3209
+ 237,
3210
+ 213,
3211
+ 154,
3212
+ 237,
3213
+ 215,
3214
+ 158,
3215
+ 236,
3216
+ 217,
3217
+ 161,
3218
+ 236,
3219
+ 218,
3220
+ 165,
3221
+ 236,
3222
+ 220,
3223
+ 169,
3224
+ 236,
3225
+ 222,
3226
+ 172,
3227
+ 235,
3228
+ 223,
3229
+ 176,
3230
+ 235,
3231
+ 225,
3232
+ 180,
3233
+ 235,
3234
+ 226,
3235
+ 183,
3236
+ 235,
3237
+ 228,
3238
+ 187,
3239
+ 235,
3240
+ 229,
3241
+ 191,
3242
+ 235,
3243
+ 230,
3244
+ 194,
3245
+ 236,
3246
+ 232,
3247
+ 198,
3248
+ 236,
3249
+ 233,
3250
+ 201,
3251
+ 236,
3252
+ 234,
3253
+ 205,
3254
+ 237,
3255
+ 236,
3256
+ 208,
3257
+ 237,
3258
+ 237,
3259
+ 212,
3260
+ 238,
3261
+ 238,
3262
+ 215,
3263
+ 239,
3264
+ 239,
3265
+ 219,
3266
+ 240,
3267
+ 240,
3268
+ 222,
3269
+ 241,
3270
+ 242,
3271
+ 225,
3272
+ 242,
3273
+ 243,
3274
+ 228,
3275
+ 243,
3276
+ 244,
3277
+ 231,
3278
+ 244,
3279
+ 245,
3280
+ 234,
3281
+ 246,
3282
+ 246,
3283
+ 237,
3284
+ 247,
3285
+ 247,
3286
+ 240,
3287
+ 249,
3288
+ 248,
3289
+ 242,
3290
+ 251,
3291
+ 249,
3292
+ 245,
3293
+ 253,
3294
+ 250,
3295
+ 247,
3296
+ 254,
3297
+ 251,
3298
+ 249
3299
+ ]);
3300
+ var lutCache = /* @__PURE__ */ new Map();
3301
+ function grayscaleLUT() {
3302
+ let lut = lutCache.get("grayscale");
3303
+ if (!lut) {
3304
+ lut = new Uint8Array(256 * 3);
3305
+ for (let i = 0; i < 256; i++) {
3306
+ lut[i * 3] = lut[i * 3 + 1] = lut[i * 3 + 2] = i;
3307
+ }
3308
+ lutCache.set("grayscale", lut);
3309
+ }
3310
+ return lut;
3311
+ }
3312
+ function igrayLUT() {
3313
+ let lut = lutCache.get("igray");
3314
+ if (!lut) {
3315
+ lut = new Uint8Array(256 * 3);
3316
+ for (let i = 0; i < 256; i++) {
3317
+ const v = 255 - i;
3318
+ lut[i * 3] = lut[i * 3 + 1] = lut[i * 3 + 2] = v;
3319
+ }
3320
+ lutCache.set("igray", lut);
3321
+ }
3322
+ return lut;
3323
+ }
3324
+ function getColorMap(value) {
3325
+ if (Array.isArray(value)) {
3326
+ return interpolateLUT(value);
3327
+ }
3328
+ switch (value) {
3329
+ case "viridis":
3330
+ return VIRIDIS_LUT;
3331
+ case "magma":
3332
+ return MAGMA_LUT;
3333
+ case "inferno":
3334
+ return INFERNO_LUT;
3335
+ case "roseus":
3336
+ return ROSEUS_LUT;
3337
+ case "grayscale":
3338
+ return grayscaleLUT();
3339
+ case "igray":
3340
+ return igrayLUT();
3341
+ default:
3342
+ return VIRIDIS_LUT;
3343
+ }
3344
+ }
3345
+
3346
+ // src/orchestrator/color-lut-cache.ts
3347
+ var ColorLUTCache = class {
3348
+ constructor() {
3349
+ this.cache = /* @__PURE__ */ new Map();
3350
+ }
3351
+ get(colorMap) {
3352
+ const key = cacheKey(colorMap);
3353
+ let lut = this.cache.get(key);
3354
+ if (!lut) {
3355
+ lut = new Uint8Array(getColorMap(colorMap));
3356
+ this.cache.set(key, lut);
3357
+ }
3358
+ return lut;
3359
+ }
3360
+ clear() {
3361
+ this.cache.clear();
3362
+ }
3363
+ };
3364
+ function cacheKey(colorMap) {
3365
+ return typeof colorMap === "string" ? colorMap : JSON.stringify(colorMap);
3366
+ }
3367
+
3368
+ // src/orchestrator/viewport-classify.ts
3369
+ function intersects(a0, a1, b0, b1) {
3370
+ return a1 > b0 && a0 < b1;
3371
+ }
3372
+ function classifyViewport(canvases, bounds) {
3373
+ const viewport = [];
3374
+ const buffer = [];
3375
+ const remaining = [];
3376
+ for (const c of canvases) {
3377
+ const start = c.globalPixelOffset;
3378
+ const end = c.globalPixelOffset + c.widthPx;
3379
+ if (intersects(start, end, bounds.visibleStartPx, bounds.visibleEndPx)) {
3380
+ viewport.push(c);
3381
+ } else if (intersects(start, end, bounds.bufferStartPx, bounds.bufferEndPx)) {
3382
+ buffer.push(c);
3383
+ } else {
3384
+ remaining.push(c);
3385
+ }
3386
+ }
3387
+ return { viewport, buffer, remaining };
3388
+ }
3389
+
3390
+ // src/orchestrator/chunk-grouping.ts
3391
+ function groupContiguousChunks(chunks) {
3392
+ if (chunks.length === 0) return [];
3393
+ const sorted = [...chunks].sort((a, b) => a.chunkIndex - b.chunkIndex);
3394
+ const groups = [];
3395
+ let current = [sorted[0]];
3396
+ for (let i = 1; i < sorted.length; i++) {
3397
+ const prev = sorted[i - 1].chunkIndex;
3398
+ const curr = sorted[i].chunkIndex;
3399
+ if (curr === prev + 1) {
3400
+ current.push(sorted[i]);
3401
+ } else {
3402
+ groups.push(current);
3403
+ current = [sorted[i]];
3404
+ }
3405
+ }
3406
+ groups.push(current);
3407
+ return groups;
3408
+ }
3409
+
3410
+ // src/orchestrator/SpectrogramOrchestrator.ts
3411
+ var SpectrogramOrchestrator = class extends EventTarget {
3412
+ constructor(opts) {
3413
+ super();
3414
+ this.clips = /* @__PURE__ */ new Map();
3415
+ this.canvases = /* @__PURE__ */ new Map();
3416
+ this.viewport = null;
3417
+ this.generation = 0;
3418
+ this.colorLUT = new ColorLUTCache();
3419
+ this.disposed = false;
3420
+ this.renderInFlight = false;
3421
+ const poolSize = opts.workerPoolSize ?? 2;
3422
+ this.pool = createSpectrogramWorkerPool(opts.workerFactory, poolSize);
3423
+ this.config = opts.config;
3424
+ this.colorMap = opts.colorMap ?? "viridis";
3425
+ this.devicePixelRatio = opts.devicePixelRatio ?? (typeof window !== "undefined" ? window.devicePixelRatio : 1);
3426
+ }
3427
+ registerClip(reg) {
3428
+ if (this.disposed) return;
3429
+ this.clips.set(reg.clipId, {
3430
+ trackId: reg.trackId,
3431
+ channelData: reg.channelData,
3432
+ sampleRate: reg.sampleRate,
3433
+ durationSamples: reg.durationSamples,
3434
+ offsetSamples: reg.offsetSamples
3435
+ });
3436
+ this.pool.registerAudioData(reg.clipId, reg.channelData, reg.sampleRate);
3437
+ }
3438
+ unregisterClip(clipId) {
3439
+ if (this.disposed) return;
3440
+ if (!this.clips.has(clipId)) return;
3441
+ this.clips.delete(clipId);
3442
+ this.pool.unregisterAudioData(clipId);
3443
+ }
3444
+ registerCanvas(reg) {
3445
+ if (this.disposed) return;
3446
+ this.canvases.set(reg.canvasId, {
3447
+ canvasId: reg.canvasId,
3448
+ globalPixelOffset: reg.globalPixelOffset,
3449
+ widthPx: reg.widthPx,
3450
+ heightPx: reg.heightPx,
3451
+ clipId: reg.clipId,
3452
+ trackId: reg.trackId,
3453
+ channelIndex: reg.channelIndex,
3454
+ chunkIndex: reg.chunkIndex
3455
+ });
3456
+ this.pool.registerCanvas(reg.canvasId, reg.canvas);
3457
+ if (this.viewport) this.scheduleRender();
3458
+ }
3459
+ unregisterCanvas(canvasId) {
3460
+ if (this.disposed) return;
3461
+ if (!this.canvases.has(canvasId)) return;
3462
+ this.canvases.delete(canvasId);
3463
+ this.pool.unregisterCanvas(canvasId);
3464
+ }
3465
+ setViewport(state) {
3466
+ if (this.disposed) return;
3467
+ const prevGeneration = this.generation;
3468
+ this.generation += 1;
3469
+ this.pool.abortGeneration(prevGeneration);
3470
+ this.viewport = state;
3471
+ this.scheduleRender();
3472
+ }
3473
+ setConfig(config) {
3474
+ if (this.disposed) return;
3475
+ this.config = config;
3476
+ const prevGeneration = this.generation;
3477
+ this.generation += 1;
3478
+ this.pool.abortGeneration(prevGeneration);
3479
+ this.colorLUT.clear();
3480
+ this.scheduleRender();
3481
+ }
3482
+ setColorMap(colorMap) {
3483
+ if (this.disposed) return;
3484
+ this.colorMap = colorMap;
3485
+ const prevGeneration = this.generation;
3486
+ this.generation += 1;
3487
+ this.pool.abortGeneration(prevGeneration);
3488
+ this.scheduleRender();
3489
+ }
3490
+ setDevicePixelRatio(dpr) {
3491
+ this.devicePixelRatio = dpr;
3492
+ }
3493
+ dispose() {
3494
+ if (this.disposed) return;
3495
+ this.disposed = true;
3496
+ this.clips.clear();
3497
+ this.canvases.clear();
3498
+ this.viewport = null;
3499
+ this.colorLUT.clear();
3500
+ this.pool.terminate();
3501
+ }
3502
+ scheduleRender() {
3503
+ if (this.renderInFlight) return;
3504
+ if (!this.viewport) return;
3505
+ this.renderInFlight = true;
3506
+ queueMicrotask(() => {
3507
+ this.renderInFlight = false;
3508
+ void this.runRender(this.generation);
3509
+ });
3510
+ }
3511
+ async runRender(generation) {
3512
+ if (this.disposed) return;
3513
+ const viewport = this.viewport;
3514
+ if (!viewport) return;
3515
+ const canvasesByTrack = /* @__PURE__ */ new Map();
3516
+ for (const c of this.canvases.values()) {
3517
+ const list = canvasesByTrack.get(c.trackId) ?? [];
3518
+ list.push(c);
3519
+ canvasesByTrack.set(c.trackId, list);
3520
+ }
3521
+ for (const [trackId, trackCanvases] of canvasesByTrack) {
3522
+ const tiers = classifyViewport(trackCanvases, viewport);
3523
+ await this.renderTier(tiers.viewport, generation, viewport);
3524
+ if (this.generation !== generation || this.disposed) return;
3525
+ this.dispatchEvent(new CustomEvent("viewport-ready", { detail: { trackId } }));
3526
+ await this.renderTier(tiers.buffer, generation, viewport);
3527
+ if (this.generation !== generation || this.disposed) return;
3528
+ await this.renderRemainingViaIdle(tiers.remaining, generation, viewport);
3529
+ }
3530
+ }
3531
+ async renderTier(canvases, generation, viewport) {
3532
+ if (canvases.length === 0) return;
3533
+ const groups = groupContiguousChunks(canvases);
3534
+ for (const group of groups) {
3535
+ if (this.generation !== generation || this.disposed) return;
3536
+ await this.renderGroup(group, generation, viewport);
3537
+ }
3538
+ }
3539
+ async renderGroup(group, generation, viewport) {
3540
+ if (group.length === 0) return;
3541
+ const first = group[0];
3542
+ const clip = this.clips.get(first.clipId);
3543
+ if (!clip) return;
3544
+ const fftSize = this.config.fftSize ?? 2048;
3545
+ const startPx = Math.min(...group.map((c) => c.globalPixelOffset));
3546
+ const endPx = Math.max(...group.map((c) => c.globalPixelOffset + c.widthPx));
3547
+ const startSample = clip.offsetSamples + Math.floor(startPx * viewport.samplesPerPixel);
3548
+ const endSample = Math.min(
3549
+ clip.offsetSamples + clip.durationSamples,
3550
+ clip.offsetSamples + Math.ceil(endPx * viewport.samplesPerPixel)
3551
+ );
3552
+ const paddedStart = Math.max(clip.offsetSamples, startSample - fftSize);
3553
+ const paddedEnd = Math.min(clip.offsetSamples + clip.durationSamples, endSample + fftSize);
3554
+ const { cacheKey: cacheKey2 } = await this.pool.computeFFT(
3555
+ {
3556
+ clipId: first.clipId,
3557
+ channelDataArrays: clip.channelData,
3558
+ config: this.config,
3559
+ sampleRate: clip.sampleRate,
3560
+ offsetSamples: clip.offsetSamples,
3561
+ durationSamples: clip.durationSamples,
3562
+ mono: false,
3563
+ sampleRange: { start: paddedStart, end: paddedEnd }
3564
+ },
3565
+ generation
3566
+ );
3567
+ if (this.generation !== generation || this.disposed) return;
3568
+ const colorLUT = this.colorLUT.get(this.colorMap);
3569
+ await this.pool.renderChunks(
3570
+ {
3571
+ cacheKey: cacheKey2,
3572
+ canvasIds: group.map((c) => c.canvasId),
3573
+ canvasWidths: group.map((c) => c.widthPx),
3574
+ globalPixelOffsets: group.map((c) => c.globalPixelOffset),
3575
+ canvasHeight: first.heightPx,
3576
+ devicePixelRatio: this.devicePixelRatio,
3577
+ samplesPerPixel: viewport.samplesPerPixel,
3578
+ colorLUT,
3579
+ frequencyScale: String(this.config.frequencyScale ?? "mel"),
3580
+ minFrequency: this.config.minFrequency ?? 0,
3581
+ maxFrequency: this.config.maxFrequency ?? clip.sampleRate / 2,
3582
+ gainDb: this.config.gainDb ?? 20,
3583
+ rangeDb: this.config.rangeDb ?? 80,
3584
+ channelIndex: first.channelIndex
3585
+ },
3586
+ generation
3587
+ );
3588
+ }
3589
+ async renderRemainingViaIdle(canvases, generation, viewport) {
3590
+ if (canvases.length === 0) return;
3591
+ const groups = groupContiguousChunks(canvases);
3592
+ for (const group of groups) {
3593
+ if (this.generation !== generation || this.disposed) return;
3594
+ await this.yieldUntilIdle();
3595
+ if (this.generation !== generation || this.disposed) return;
3596
+ await this.renderGroup(group, generation, viewport);
3597
+ }
3598
+ }
3599
+ yieldUntilIdle() {
3600
+ return new Promise((resolve) => {
3601
+ if (typeof requestIdleCallback === "function") {
3602
+ requestIdleCallback(() => resolve());
3603
+ } else {
3604
+ setTimeout(resolve, 0);
3605
+ }
3606
+ });
3607
+ }
3608
+ };
3609
+ export {
3610
+ ColorLUTCache,
3611
+ SpectrogramOrchestrator,
3612
+ classifyViewport,
3613
+ groupContiguousChunks
3614
+ };
3615
+ //# sourceMappingURL=index.mjs.map