smart-downscaler 0.6.3 → 0.6.5

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.
@@ -1,1182 +1,9 @@
1
1
  /* @ts-self-types="./smart_downscaler.d.ts" */
2
2
 
3
- class ColorAnalysisResult {
4
- static __wrap(ptr) {
5
- ptr = ptr >>> 0;
6
- const obj = Object.create(ColorAnalysisResult.prototype);
7
- obj.__wbg_ptr = ptr;
8
- ColorAnalysisResultFinalization.register(obj, obj.__wbg_ptr, obj);
9
- return obj;
10
- }
11
- __destroy_into_raw() {
12
- const ptr = this.__wbg_ptr;
13
- this.__wbg_ptr = 0;
14
- ColorAnalysisResultFinalization.unregister(this);
15
- return ptr;
16
- }
17
- free() {
18
- const ptr = this.__destroy_into_raw();
19
- wasm.__wbg_coloranalysisresult_free(ptr, 0);
20
- }
21
- /**
22
- * @returns {number}
23
- */
24
- get color_count() {
25
- const ret = wasm.coloranalysisresult_color_count(this.__wbg_ptr);
26
- return ret >>> 0;
27
- }
28
- /**
29
- * @param {number} index
30
- * @returns {ColorEntry | undefined}
31
- */
32
- get_color(index) {
33
- const ret = wasm.coloranalysisresult_get_color(this.__wbg_ptr, index);
34
- return ret === 0 ? undefined : ColorEntry.__wrap(ret);
35
- }
36
- /**
37
- * @returns {Uint8Array}
38
- */
39
- get_colors_flat() {
40
- const ret = wasm.coloranalysisresult_get_colors_flat(this.__wbg_ptr);
41
- return ret;
42
- }
43
- /**
44
- * @returns {boolean}
45
- */
46
- get success() {
47
- const ret = wasm.coloranalysisresult_success(this.__wbg_ptr);
48
- return ret !== 0;
49
- }
50
- /**
51
- * @returns {any}
52
- */
53
- to_json() {
54
- const ret = wasm.coloranalysisresult_to_json(this.__wbg_ptr);
55
- if (ret[2]) {
56
- throw takeFromExternrefTable0(ret[1]);
57
- }
58
- return takeFromExternrefTable0(ret[0]);
59
- }
60
- /**
61
- * @returns {number}
62
- */
63
- get total_pixels() {
64
- const ret = wasm.coloranalysisresult_total_pixels(this.__wbg_ptr);
65
- return ret >>> 0;
66
- }
67
- }
68
- if (Symbol.dispose) ColorAnalysisResult.prototype[Symbol.dispose] = ColorAnalysisResult.prototype.free;
69
- exports.ColorAnalysisResult = ColorAnalysisResult;
70
-
71
- class ColorEntry {
72
- static __wrap(ptr) {
73
- ptr = ptr >>> 0;
74
- const obj = Object.create(ColorEntry.prototype);
75
- obj.__wbg_ptr = ptr;
76
- ColorEntryFinalization.register(obj, obj.__wbg_ptr, obj);
77
- return obj;
78
- }
79
- __destroy_into_raw() {
80
- const ptr = this.__wbg_ptr;
81
- this.__wbg_ptr = 0;
82
- ColorEntryFinalization.unregister(this);
83
- return ptr;
84
- }
85
- free() {
86
- const ptr = this.__destroy_into_raw();
87
- wasm.__wbg_colorentry_free(ptr, 0);
88
- }
89
- /**
90
- * @returns {number}
91
- */
92
- get b() {
93
- const ret = wasm.colorentry_b(this.__wbg_ptr);
94
- return ret;
95
- }
96
- /**
97
- * @returns {number}
98
- */
99
- get count() {
100
- const ret = wasm.colorentry_count(this.__wbg_ptr);
101
- return ret >>> 0;
102
- }
103
- /**
104
- * @returns {number}
105
- */
106
- get g() {
107
- const ret = wasm.colorentry_g(this.__wbg_ptr);
108
- return ret;
109
- }
110
- /**
111
- * @returns {string}
112
- */
113
- get hex() {
114
- let deferred1_0;
115
- let deferred1_1;
116
- try {
117
- const ret = wasm.colorentry_hex(this.__wbg_ptr);
118
- deferred1_0 = ret[0];
119
- deferred1_1 = ret[1];
120
- return getStringFromWasm0(ret[0], ret[1]);
121
- } finally {
122
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
123
- }
124
- }
125
- /**
126
- * @returns {number}
127
- */
128
- get percentage() {
129
- const ret = wasm.colorentry_percentage(this.__wbg_ptr);
130
- return ret;
131
- }
132
- /**
133
- * @returns {number}
134
- */
135
- get r() {
136
- const ret = wasm.colorentry_r(this.__wbg_ptr);
137
- return ret;
138
- }
139
- }
140
- if (Symbol.dispose) ColorEntry.prototype[Symbol.dispose] = ColorEntry.prototype.free;
141
- exports.ColorEntry = ColorEntry;
142
-
143
- class WasmDownscaleConfig {
144
- static __wrap(ptr) {
145
- ptr = ptr >>> 0;
146
- const obj = Object.create(WasmDownscaleConfig.prototype);
147
- obj.__wbg_ptr = ptr;
148
- WasmDownscaleConfigFinalization.register(obj, obj.__wbg_ptr, obj);
149
- return obj;
150
- }
151
- __destroy_into_raw() {
152
- const ptr = this.__wbg_ptr;
153
- this.__wbg_ptr = 0;
154
- WasmDownscaleConfigFinalization.unregister(this);
155
- return ptr;
156
- }
157
- free() {
158
- const ptr = this.__destroy_into_raw();
159
- wasm.__wbg_wasmdownscaleconfig_free(ptr, 0);
160
- }
161
- /**
162
- * Restore chroma lost to merging (constant hue, gamut-clamped). 0.0 = off, ~0.6 natural.
163
- * @returns {number}
164
- */
165
- get chroma_recovery() {
166
- const ret = wasm.__wbg_get_wasmdownscaleconfig_chroma_recovery(this.__wbg_ptr);
167
- return ret;
168
- }
169
- /**
170
- * Rare-color preservation: 0.0 = pure area weighting, 1.0 = strong (count^0.5).
171
- * @returns {number}
172
- */
173
- get color_rarity() {
174
- const ret = wasm.__wbg_get_wasmdownscaleconfig_color_rarity(this.__wbg_ptr);
175
- return ret;
176
- }
177
- /**
178
- * Detail-color boost via local-contrast saliency. 0.0 = off.
179
- * @returns {number}
180
- */
181
- get detail_boost() {
182
- const ret = wasm.__wbg_get_wasmdownscaleconfig_detail_boost(this.__wbg_ptr);
183
- return ret;
184
- }
185
- /**
186
- * @returns {number}
187
- */
188
- get edge_weight() {
189
- const ret = wasm.__wbg_get_wasmdownscaleconfig_edge_weight(this.__wbg_ptr);
190
- return ret;
191
- }
192
- /**
193
- * @returns {number}
194
- */
195
- get hierarchy_min_size() {
196
- const ret = wasm.__wbg_get_wasmdownscaleconfig_hierarchy_min_size(this.__wbg_ptr);
197
- return ret >>> 0;
198
- }
199
- /**
200
- * @returns {number}
201
- */
202
- get hierarchy_threshold() {
203
- const ret = wasm.__wbg_get_wasmdownscaleconfig_hierarchy_threshold(this.__wbg_ptr);
204
- return ret;
205
- }
206
- /**
207
- * @returns {number}
208
- */
209
- get k_centroid_iterations() {
210
- const ret = wasm.__wbg_get_wasmdownscaleconfig_k_centroid_iterations(this.__wbg_ptr);
211
- return ret >>> 0;
212
- }
213
- /**
214
- * @returns {number}
215
- */
216
- get k_centroid() {
217
- const ret = wasm.__wbg_get_wasmdownscaleconfig_k_centroid(this.__wbg_ptr);
218
- return ret >>> 0;
219
- }
220
- /**
221
- * @returns {number}
222
- */
223
- get kmeans_iterations() {
224
- const ret = wasm.__wbg_get_wasmdownscaleconfig_kmeans_iterations(this.__wbg_ptr);
225
- return ret >>> 0;
226
- }
227
- /**
228
- * @returns {number}
229
- */
230
- get max_color_preprocess() {
231
- const ret = wasm.__wbg_get_wasmdownscaleconfig_max_color_preprocess(this.__wbg_ptr);
232
- return ret >>> 0;
233
- }
234
- /**
235
- * @returns {number}
236
- */
237
- get max_resolution_mp() {
238
- const ret = wasm.__wbg_get_wasmdownscaleconfig_max_resolution_mp(this.__wbg_ptr);
239
- return ret;
240
- }
241
- /**
242
- * @returns {number}
243
- */
244
- get neighbor_weight() {
245
- const ret = wasm.__wbg_get_wasmdownscaleconfig_neighbor_weight(this.__wbg_ptr);
246
- return ret;
247
- }
248
- /**
249
- * @returns {number}
250
- */
251
- get palette_size() {
252
- const ret = wasm.__wbg_get_wasmdownscaleconfig_palette_size(this.__wbg_ptr);
253
- return ret >>> 0;
254
- }
255
- /**
256
- * @returns {number}
257
- */
258
- get refinement_iterations() {
259
- const ret = wasm.__wbg_get_wasmdownscaleconfig_refinement_iterations(this.__wbg_ptr);
260
- return ret >>> 0;
261
- }
262
- /**
263
- * @returns {number}
264
- */
265
- get region_weight() {
266
- const ret = wasm.__wbg_get_wasmdownscaleconfig_region_weight(this.__wbg_ptr);
267
- return ret;
268
- }
269
- /**
270
- * Reserve N palette slots for distinct, important, under-represented colors. 0 = off.
271
- * @returns {number}
272
- */
273
- get reserve_colors() {
274
- const ret = wasm.__wbg_get_wasmdownscaleconfig_reserve_colors(this.__wbg_ptr);
275
- return ret >>> 0;
276
- }
277
- /**
278
- * Isolate skin tones from non-skin (separate domains + mismatch penalty). 0.0 = off, ~0.5.
279
- * @returns {number}
280
- */
281
- get skin_protection() {
282
- const ret = wasm.__wbg_get_wasmdownscaleconfig_skin_protection(this.__wbg_ptr);
283
- return ret;
284
- }
285
- /**
286
- * @returns {number}
287
- */
288
- get slic_compactness() {
289
- const ret = wasm.__wbg_get_wasmdownscaleconfig_slic_compactness(this.__wbg_ptr);
290
- return ret;
291
- }
292
- /**
293
- * @returns {number}
294
- */
295
- get slic_superpixels() {
296
- const ret = wasm.__wbg_get_wasmdownscaleconfig_slic_superpixels(this.__wbg_ptr);
297
- return ret >>> 0;
298
- }
299
- /**
300
- * @returns {boolean}
301
- */
302
- get two_pass_refinement() {
303
- const ret = wasm.__wbg_get_wasmdownscaleconfig_two_pass_refinement(this.__wbg_ptr);
304
- return ret !== 0;
305
- }
306
- /**
307
- * Restore chroma lost to merging (constant hue, gamut-clamped). 0.0 = off, ~0.6 natural.
308
- * @param {number} arg0
309
- */
310
- set chroma_recovery(arg0) {
311
- wasm.__wbg_set_wasmdownscaleconfig_chroma_recovery(this.__wbg_ptr, arg0);
312
- }
313
- /**
314
- * Rare-color preservation: 0.0 = pure area weighting, 1.0 = strong (count^0.5).
315
- * @param {number} arg0
316
- */
317
- set color_rarity(arg0) {
318
- wasm.__wbg_set_wasmdownscaleconfig_color_rarity(this.__wbg_ptr, arg0);
319
- }
320
- /**
321
- * Detail-color boost via local-contrast saliency. 0.0 = off.
322
- * @param {number} arg0
323
- */
324
- set detail_boost(arg0) {
325
- wasm.__wbg_set_wasmdownscaleconfig_detail_boost(this.__wbg_ptr, arg0);
326
- }
327
- /**
328
- * @param {number} arg0
329
- */
330
- set edge_weight(arg0) {
331
- wasm.__wbg_set_wasmdownscaleconfig_edge_weight(this.__wbg_ptr, arg0);
332
- }
333
- /**
334
- * @param {number} arg0
335
- */
336
- set hierarchy_min_size(arg0) {
337
- wasm.__wbg_set_wasmdownscaleconfig_hierarchy_min_size(this.__wbg_ptr, arg0);
338
- }
339
- /**
340
- * @param {number} arg0
341
- */
342
- set hierarchy_threshold(arg0) {
343
- wasm.__wbg_set_wasmdownscaleconfig_hierarchy_threshold(this.__wbg_ptr, arg0);
344
- }
345
- /**
346
- * @param {number} arg0
347
- */
348
- set k_centroid_iterations(arg0) {
349
- wasm.__wbg_set_wasmdownscaleconfig_k_centroid_iterations(this.__wbg_ptr, arg0);
350
- }
351
- /**
352
- * @param {number} arg0
353
- */
354
- set k_centroid(arg0) {
355
- wasm.__wbg_set_wasmdownscaleconfig_k_centroid(this.__wbg_ptr, arg0);
356
- }
357
- /**
358
- * @param {number} arg0
359
- */
360
- set kmeans_iterations(arg0) {
361
- wasm.__wbg_set_wasmdownscaleconfig_kmeans_iterations(this.__wbg_ptr, arg0);
362
- }
363
- /**
364
- * @param {number} arg0
365
- */
366
- set max_color_preprocess(arg0) {
367
- wasm.__wbg_set_wasmdownscaleconfig_max_color_preprocess(this.__wbg_ptr, arg0);
368
- }
369
- /**
370
- * @param {number} arg0
371
- */
372
- set max_resolution_mp(arg0) {
373
- wasm.__wbg_set_wasmdownscaleconfig_max_resolution_mp(this.__wbg_ptr, arg0);
374
- }
375
- /**
376
- * @param {number} arg0
377
- */
378
- set neighbor_weight(arg0) {
379
- wasm.__wbg_set_wasmdownscaleconfig_neighbor_weight(this.__wbg_ptr, arg0);
380
- }
381
- /**
382
- * @param {number} arg0
383
- */
384
- set palette_size(arg0) {
385
- wasm.__wbg_set_wasmdownscaleconfig_palette_size(this.__wbg_ptr, arg0);
386
- }
387
- /**
388
- * @param {number} arg0
389
- */
390
- set refinement_iterations(arg0) {
391
- wasm.__wbg_set_wasmdownscaleconfig_refinement_iterations(this.__wbg_ptr, arg0);
392
- }
393
- /**
394
- * @param {number} arg0
395
- */
396
- set region_weight(arg0) {
397
- wasm.__wbg_set_wasmdownscaleconfig_region_weight(this.__wbg_ptr, arg0);
398
- }
399
- /**
400
- * Reserve N palette slots for distinct, important, under-represented colors. 0 = off.
401
- * @param {number} arg0
402
- */
403
- set reserve_colors(arg0) {
404
- wasm.__wbg_set_wasmdownscaleconfig_reserve_colors(this.__wbg_ptr, arg0);
405
- }
406
- /**
407
- * Isolate skin tones from non-skin (separate domains + mismatch penalty). 0.0 = off, ~0.5.
408
- * @param {number} arg0
409
- */
410
- set skin_protection(arg0) {
411
- wasm.__wbg_set_wasmdownscaleconfig_skin_protection(this.__wbg_ptr, arg0);
412
- }
413
- /**
414
- * @param {number} arg0
415
- */
416
- set slic_compactness(arg0) {
417
- wasm.__wbg_set_wasmdownscaleconfig_slic_compactness(this.__wbg_ptr, arg0);
418
- }
419
- /**
420
- * @param {number} arg0
421
- */
422
- set slic_superpixels(arg0) {
423
- wasm.__wbg_set_wasmdownscaleconfig_slic_superpixels(this.__wbg_ptr, arg0);
424
- }
425
- /**
426
- * @param {boolean} arg0
427
- */
428
- set two_pass_refinement(arg0) {
429
- wasm.__wbg_set_wasmdownscaleconfig_two_pass_refinement(this.__wbg_ptr, arg0);
430
- }
431
- /**
432
- * @returns {WasmDownscaleConfig}
433
- */
434
- static exact_colors() {
435
- const ret = wasm.wasmdownscaleconfig_exact_colors();
436
- return WasmDownscaleConfig.__wrap(ret);
437
- }
438
- /**
439
- * @returns {WasmDownscaleConfig}
440
- */
441
- static fast() {
442
- const ret = wasm.wasmdownscaleconfig_fast();
443
- return WasmDownscaleConfig.__wrap(ret);
444
- }
445
- constructor() {
446
- const ret = wasm.wasmdownscaleconfig_new();
447
- this.__wbg_ptr = ret >>> 0;
448
- WasmDownscaleConfigFinalization.register(this, this.__wbg_ptr, this);
449
- return this;
450
- }
451
- /**
452
- * @returns {string}
453
- */
454
- get palette_strategy() {
455
- let deferred1_0;
456
- let deferred1_1;
457
- try {
458
- const ret = wasm.wasmdownscaleconfig_palette_strategy(this.__wbg_ptr);
459
- deferred1_0 = ret[0];
460
- deferred1_1 = ret[1];
461
- return getStringFromWasm0(ret[0], ret[1]);
462
- } finally {
463
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
464
- }
465
- }
466
- /**
467
- * @returns {WasmDownscaleConfig}
468
- */
469
- static quality() {
470
- const ret = wasm.wasmdownscaleconfig_quality();
471
- return WasmDownscaleConfig.__wrap(ret);
472
- }
473
- /**
474
- * @returns {string}
475
- */
476
- get segmentation_method() {
477
- let deferred1_0;
478
- let deferred1_1;
479
- try {
480
- const ret = wasm.wasmdownscaleconfig_segmentation_method(this.__wbg_ptr);
481
- deferred1_0 = ret[0];
482
- deferred1_1 = ret[1];
483
- return getStringFromWasm0(ret[0], ret[1]);
484
- } finally {
485
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
486
- }
487
- }
488
- /**
489
- * @param {string} strategy
490
- */
491
- set palette_strategy(strategy) {
492
- const ptr0 = passStringToWasm0(strategy, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
493
- const len0 = WASM_VECTOR_LEN;
494
- wasm.wasmdownscaleconfig_set_palette_strategy(this.__wbg_ptr, ptr0, len0);
495
- }
496
- /**
497
- * @param {string} method
498
- */
499
- set segmentation_method(method) {
500
- const ptr0 = passStringToWasm0(method, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
501
- const len0 = WASM_VECTOR_LEN;
502
- wasm.wasmdownscaleconfig_set_segmentation_method(this.__wbg_ptr, ptr0, len0);
503
- }
504
- /**
505
- * @returns {WasmDownscaleConfig}
506
- */
507
- static vibrant() {
508
- const ret = wasm.wasmdownscaleconfig_vibrant();
509
- return WasmDownscaleConfig.__wrap(ret);
510
- }
511
- }
512
- if (Symbol.dispose) WasmDownscaleConfig.prototype[Symbol.dispose] = WasmDownscaleConfig.prototype.free;
513
- exports.WasmDownscaleConfig = WasmDownscaleConfig;
514
-
515
- class WasmDownscaleResult {
516
- static __wrap(ptr) {
517
- ptr = ptr >>> 0;
518
- const obj = Object.create(WasmDownscaleResult.prototype);
519
- obj.__wbg_ptr = ptr;
520
- WasmDownscaleResultFinalization.register(obj, obj.__wbg_ptr, obj);
521
- return obj;
522
- }
523
- __destroy_into_raw() {
524
- const ptr = this.__wbg_ptr;
525
- this.__wbg_ptr = 0;
526
- WasmDownscaleResultFinalization.unregister(this);
527
- return ptr;
528
- }
529
- free() {
530
- const ptr = this.__destroy_into_raw();
531
- wasm.__wbg_wasmdownscaleresult_free(ptr, 0);
532
- }
533
- /**
534
- * @returns {Uint8ClampedArray}
535
- */
536
- get data() {
537
- const ret = wasm.wasmdownscaleresult_data(this.__wbg_ptr);
538
- return ret;
539
- }
540
- /**
541
- * @returns {number}
542
- */
543
- get height() {
544
- const ret = wasm.wasmdownscaleresult_height(this.__wbg_ptr);
545
- return ret >>> 0;
546
- }
547
- /**
548
- * @returns {Uint8Array}
549
- */
550
- get indices() {
551
- const ret = wasm.wasmdownscaleresult_indices(this.__wbg_ptr);
552
- return ret;
553
- }
554
- /**
555
- * @returns {Uint8Array}
556
- */
557
- get palette() {
558
- const ret = wasm.wasmdownscaleresult_palette(this.__wbg_ptr);
559
- return ret;
560
- }
561
- /**
562
- * @returns {number}
563
- */
564
- get palette_size() {
565
- const ret = wasm.wasmdownscaleresult_palette_size(this.__wbg_ptr);
566
- return ret >>> 0;
567
- }
568
- /**
569
- * @returns {Uint8Array}
570
- */
571
- rgb_data() {
572
- const ret = wasm.wasmdownscaleresult_rgb_data(this.__wbg_ptr);
573
- return ret;
574
- }
575
- /**
576
- * @returns {number}
577
- */
578
- get width() {
579
- const ret = wasm.wasmdownscaleresult_width(this.__wbg_ptr);
580
- return ret >>> 0;
581
- }
582
- }
583
- if (Symbol.dispose) WasmDownscaleResult.prototype[Symbol.dispose] = WasmDownscaleResult.prototype.free;
584
- exports.WasmDownscaleResult = WasmDownscaleResult;
585
-
586
- /**
587
- * Opaque handle holding the prepared (preprocessed + segmented) source image.
588
- * Build with [`prepare`] / [`prepare_rgba`], reuse with [`downscale_prepared`].
589
- *
590
- * The segmentation is fixed at prepare time from the config you pass. Palette
591
- * size and target dimensions may differ on every [`downscale_prepared`] call.
592
- * If you change resolution / color-preprocess / segmentation settings, prepare again.
593
- */
594
- class WasmPreparedImage {
595
- static __wrap(ptr) {
596
- ptr = ptr >>> 0;
597
- const obj = Object.create(WasmPreparedImage.prototype);
598
- obj.__wbg_ptr = ptr;
599
- WasmPreparedImageFinalization.register(obj, obj.__wbg_ptr, obj);
600
- return obj;
601
- }
602
- __destroy_into_raw() {
603
- const ptr = this.__wbg_ptr;
604
- this.__wbg_ptr = 0;
605
- WasmPreparedImageFinalization.unregister(this);
606
- return ptr;
607
- }
608
- free() {
609
- const ptr = this.__destroy_into_raw();
610
- wasm.__wbg_wasmpreparedimage_free(ptr, 0);
611
- }
612
- /**
613
- * @returns {number}
614
- */
615
- get height() {
616
- const ret = wasm.wasmpreparedimage_height(this.__wbg_ptr);
617
- return ret >>> 0;
618
- }
619
- /**
620
- * @returns {number}
621
- */
622
- get width() {
623
- const ret = wasm.wasmpreparedimage_width(this.__wbg_ptr);
624
- return ret >>> 0;
625
- }
626
- }
627
- if (Symbol.dispose) WasmPreparedImage.prototype[Symbol.dispose] = WasmPreparedImage.prototype.free;
628
- exports.WasmPreparedImage = WasmPreparedImage;
629
-
630
- /**
631
- * Analyze colors — FIX: uses HashMap<u32, usize> for O(1) lookup (was O(n) linear scan)
632
- * @param {Uint8Array} image_data
633
- * @param {number} max_colors
634
- * @param {string} sort_method
635
- * @returns {ColorAnalysisResult}
636
- */
637
- function analyze_colors(image_data, max_colors, sort_method) {
638
- const ptr0 = passStringToWasm0(sort_method, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
639
- const len0 = WASM_VECTOR_LEN;
640
- const ret = wasm.analyze_colors(image_data, max_colors, ptr0, len0);
641
- if (ret[2]) {
642
- throw takeFromExternrefTable0(ret[1]);
643
- }
644
- return ColorAnalysisResult.__wrap(ret[0]);
645
- }
646
- exports.analyze_colors = analyze_colors;
647
-
648
- /**
649
- * @param {number} r1
650
- * @param {number} g1
651
- * @param {number} b1
652
- * @param {number} r2
653
- * @param {number} g2
654
- * @param {number} b2
655
- * @returns {number}
656
- */
657
- function color_distance(r1, g1, b1, r2, g2, b2) {
658
- const ret = wasm.color_distance(r1, g1, b1, r2, g2, b2);
659
- return ret;
660
- }
661
- exports.color_distance = color_distance;
662
-
663
- /**
664
- * @param {Uint8Array} image_data
665
- * @param {number} width
666
- * @param {number} height
667
- * @param {number} target_width
668
- * @param {number} target_height
669
- * @param {WasmDownscaleConfig | null} [config]
670
- * @returns {WasmDownscaleResult}
671
- */
672
- function downscale(image_data, width, height, target_width, target_height, config) {
673
- let ptr0 = 0;
674
- if (!isLikeNone(config)) {
675
- _assertClass(config, WasmDownscaleConfig);
676
- ptr0 = config.__destroy_into_raw();
677
- }
678
- const ret = wasm.downscale(image_data, width, height, target_width, target_height, ptr0);
679
- if (ret[2]) {
680
- throw takeFromExternrefTable0(ret[1]);
681
- }
682
- return WasmDownscaleResult.__wrap(ret[0]);
683
- }
684
- exports.downscale = downscale;
685
-
686
- /**
687
- * Downscale a prepared image. Pass an optional `config` to override per-target
688
- * knobs (palette_size, k_centroid, chroma_recovery, skin_protection, …). The
689
- * preprocess/segmentation settings always come from prepare time. When `config`
690
- * is omitted, the prepare-time config is reused as-is.
691
- * @param {WasmPreparedImage} prepared
692
- * @param {number} target_width
693
- * @param {number} target_height
694
- * @param {WasmDownscaleConfig | null} [config]
695
- * @returns {WasmDownscaleResult}
696
- */
697
- function downscale_prepared(prepared, target_width, target_height, config) {
698
- _assertClass(prepared, WasmPreparedImage);
699
- let ptr0 = 0;
700
- if (!isLikeNone(config)) {
701
- _assertClass(config, WasmDownscaleConfig);
702
- ptr0 = config.__destroy_into_raw();
703
- }
704
- const ret = wasm.downscale_prepared(prepared.__wbg_ptr, target_width, target_height, ptr0);
705
- if (ret[2]) {
706
- throw takeFromExternrefTable0(ret[1]);
707
- }
708
- return WasmDownscaleResult.__wrap(ret[0]);
709
- }
710
- exports.downscale_prepared = downscale_prepared;
711
-
712
- /**
713
- * Downscale a prepared image with a caller-supplied palette.
714
- * @param {WasmPreparedImage} prepared
715
- * @param {number} target_width
716
- * @param {number} target_height
717
- * @param {Uint8Array} palette_data
718
- * @param {WasmDownscaleConfig | null} [config]
719
- * @returns {WasmDownscaleResult}
720
- */
721
- function downscale_prepared_with_palette(prepared, target_width, target_height, palette_data, config) {
722
- _assertClass(prepared, WasmPreparedImage);
723
- let ptr0 = 0;
724
- if (!isLikeNone(config)) {
725
- _assertClass(config, WasmDownscaleConfig);
726
- ptr0 = config.__destroy_into_raw();
727
- }
728
- const ret = wasm.downscale_prepared_with_palette(prepared.__wbg_ptr, target_width, target_height, palette_data, ptr0);
729
- if (ret[2]) {
730
- throw takeFromExternrefTable0(ret[1]);
731
- }
732
- return WasmDownscaleResult.__wrap(ret[0]);
733
- }
734
- exports.downscale_prepared_with_palette = downscale_prepared_with_palette;
735
-
736
- /**
737
- * @param {Uint8ClampedArray} image_data
738
- * @param {number} width
739
- * @param {number} height
740
- * @param {number} target_width
741
- * @param {number} target_height
742
- * @param {WasmDownscaleConfig | null} [config]
743
- * @returns {WasmDownscaleResult}
744
- */
745
- function downscale_rgba(image_data, width, height, target_width, target_height, config) {
746
- let ptr0 = 0;
747
- if (!isLikeNone(config)) {
748
- _assertClass(config, WasmDownscaleConfig);
749
- ptr0 = config.__destroy_into_raw();
750
- }
751
- const ret = wasm.downscale_rgba(image_data, width, height, target_width, target_height, ptr0);
752
- if (ret[2]) {
753
- throw takeFromExternrefTable0(ret[1]);
754
- }
755
- return WasmDownscaleResult.__wrap(ret[0]);
756
- }
757
- exports.downscale_rgba = downscale_rgba;
758
-
759
- /**
760
- * @param {Uint8Array} image_data
761
- * @param {number} width
762
- * @param {number} height
763
- * @param {number} target_width
764
- * @param {number} target_height
765
- * @param {number} num_colors
766
- * @returns {WasmDownscaleResult}
767
- */
768
- function downscale_simple(image_data, width, height, target_width, target_height, num_colors) {
769
- const ret = wasm.downscale_simple(image_data, width, height, target_width, target_height, num_colors);
770
- if (ret[2]) {
771
- throw takeFromExternrefTable0(ret[1]);
772
- }
773
- return WasmDownscaleResult.__wrap(ret[0]);
774
- }
775
- exports.downscale_simple = downscale_simple;
776
-
777
- /**
778
- * @param {Uint8Array} image_data
779
- * @param {number} width
780
- * @param {number} height
781
- * @param {number} target_width
782
- * @param {number} target_height
783
- * @param {Uint8Array} palette_data
784
- * @param {WasmDownscaleConfig | null} [config]
785
- * @returns {WasmDownscaleResult}
786
- */
787
- function downscale_with_palette(image_data, width, height, target_width, target_height, palette_data, config) {
788
- let ptr0 = 0;
789
- if (!isLikeNone(config)) {
790
- _assertClass(config, WasmDownscaleConfig);
791
- ptr0 = config.__destroy_into_raw();
792
- }
793
- const ret = wasm.downscale_with_palette(image_data, width, height, target_width, target_height, palette_data, ptr0);
794
- if (ret[2]) {
795
- throw takeFromExternrefTable0(ret[1]);
796
- }
797
- return WasmDownscaleResult.__wrap(ret[0]);
798
- }
799
- exports.downscale_with_palette = downscale_with_palette;
800
-
801
- /**
802
- * @param {Uint8Array} image_data
803
- * @param {number} _width
804
- * @param {number} _height
805
- * @param {number} num_colors
806
- * @param {number} kmeans_iterations
807
- * @param {string | null} [strategy]
808
- * @returns {Uint8Array}
809
- */
810
- function extract_palette_from_image(image_data, _width, _height, num_colors, kmeans_iterations, strategy) {
811
- var ptr0 = isLikeNone(strategy) ? 0 : passStringToWasm0(strategy, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
812
- var len0 = WASM_VECTOR_LEN;
813
- const ret = wasm.extract_palette_from_image(image_data, _width, _height, num_colors, kmeans_iterations, ptr0, len0);
814
- if (ret[2]) {
815
- throw takeFromExternrefTable0(ret[1]);
816
- }
817
- return takeFromExternrefTable0(ret[0]);
818
- }
819
- exports.extract_palette_from_image = extract_palette_from_image;
820
-
821
- /**
822
- * @param {number} r
823
- * @param {number} g
824
- * @param {number} b
825
- * @returns {number}
826
- */
827
- function get_chroma(r, g, b) {
828
- const ret = wasm.get_chroma(r, g, b);
829
- return ret;
830
- }
831
- exports.get_chroma = get_chroma;
832
-
833
- /**
834
- * @param {number} r
835
- * @param {number} g
836
- * @param {number} b
837
- * @returns {number}
838
- */
839
- function get_lightness(r, g, b) {
840
- const ret = wasm.get_lightness(r, g, b);
841
- return ret;
842
- }
843
- exports.get_lightness = get_lightness;
844
-
845
- /**
846
- * @returns {Array<any>}
847
- */
848
- function get_palette_strategies() {
849
- const ret = wasm.get_palette_strategies();
850
- return ret;
851
- }
852
- exports.get_palette_strategies = get_palette_strategies;
853
-
854
- function init() {
855
- wasm.init();
856
- }
857
- exports.init = init;
858
-
859
- /**
860
- * @param {string} message
861
- */
862
- function log(message) {
863
- const ptr0 = passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
864
- const len0 = WASM_VECTOR_LEN;
865
- wasm.log(ptr0, len0);
866
- }
867
- exports.log = log;
868
-
869
- /**
870
- * @param {number} l
871
- * @param {number} a
872
- * @param {number} b
873
- * @returns {Uint8Array}
874
- */
875
- function oklab_to_rgb(l, a, b) {
876
- const ret = wasm.oklab_to_rgb(l, a, b);
877
- return ret;
878
- }
879
- exports.oklab_to_rgb = oklab_to_rgb;
880
-
881
- /**
882
- * Prepare from a `Uint8Array` (RGBA).
883
- * @param {Uint8Array} image_data
884
- * @param {number} width
885
- * @param {number} height
886
- * @param {WasmDownscaleConfig | null} [config]
887
- * @returns {WasmPreparedImage}
888
- */
889
- function prepare(image_data, width, height, config) {
890
- let ptr0 = 0;
891
- if (!isLikeNone(config)) {
892
- _assertClass(config, WasmDownscaleConfig);
893
- ptr0 = config.__destroy_into_raw();
894
- }
895
- const ret = wasm.prepare(image_data, width, height, ptr0);
896
- if (ret[2]) {
897
- throw takeFromExternrefTable0(ret[1]);
898
- }
899
- return WasmPreparedImage.__wrap(ret[0]);
900
- }
901
- exports.prepare = prepare;
902
-
903
- /**
904
- * Prepare from a `Uint8ClampedArray` (canvas `getImageData`).
905
- * @param {Uint8ClampedArray} image_data
906
- * @param {number} width
907
- * @param {number} height
908
- * @param {WasmDownscaleConfig | null} [config]
909
- * @returns {WasmPreparedImage}
910
- */
911
- function prepare_rgba(image_data, width, height, config) {
912
- let ptr0 = 0;
913
- if (!isLikeNone(config)) {
914
- _assertClass(config, WasmDownscaleConfig);
915
- ptr0 = config.__destroy_into_raw();
916
- }
917
- const ret = wasm.prepare_rgba(image_data, width, height, ptr0);
918
- if (ret[2]) {
919
- throw takeFromExternrefTable0(ret[1]);
920
- }
921
- return WasmPreparedImage.__wrap(ret[0]);
922
- }
923
- exports.prepare_rgba = prepare_rgba;
924
-
925
- /**
926
- * Quantize to palette — FIX: compute Oklab once per pixel (was twice)
927
- * @param {Uint8Array} image_data
928
- * @param {number} width
929
- * @param {number} height
930
- * @param {Uint8Array} palette_data
931
- * @returns {WasmDownscaleResult}
932
- */
933
- function quantize_to_palette(image_data, width, height, palette_data) {
934
- const ret = wasm.quantize_to_palette(image_data, width, height, palette_data);
935
- if (ret[2]) {
936
- throw takeFromExternrefTable0(ret[1]);
937
- }
938
- return WasmDownscaleResult.__wrap(ret[0]);
939
- }
940
- exports.quantize_to_palette = quantize_to_palette;
941
-
942
- /**
943
- * @param {number} r
944
- * @param {number} g
945
- * @param {number} b
946
- * @returns {Float32Array}
947
- */
948
- function rgb_to_oklab(r, g, b) {
949
- const ret = wasm.rgb_to_oklab(r, g, b);
950
- return ret;
951
- }
952
- exports.rgb_to_oklab = rgb_to_oklab;
953
-
954
- /**
955
- * @returns {string}
956
- */
957
- function version() {
958
- let deferred1_0;
959
- let deferred1_1;
960
- try {
961
- const ret = wasm.version();
962
- deferred1_0 = ret[0];
963
- deferred1_1 = ret[1];
964
- return getStringFromWasm0(ret[0], ret[1]);
965
- } finally {
966
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
967
- }
968
- }
969
- exports.version = version;
970
-
971
- function __wbg_get_imports() {
972
- const import0 = {
973
- __proto__: null,
974
- __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
975
- throw new Error(getStringFromWasm0(arg0, arg1));
976
- },
977
- __wbg_length_32ed9a279acd054c: function(arg0) {
978
- const ret = arg0.length;
979
- return ret;
980
- },
981
- __wbg_log_6b5ca2e6124b2808: function(arg0) {
982
- console.log(arg0);
983
- },
984
- __wbg_new_361308b2356cecd0: function() {
985
- const ret = new Object();
986
- return ret;
987
- },
988
- __wbg_new_3eb36ae241fe6f44: function() {
989
- const ret = new Array();
990
- return ret;
991
- },
992
- __wbg_new_dd2b680c8bf6ae29: function(arg0) {
993
- const ret = new Uint8Array(arg0);
994
- return ret;
995
- },
996
- __wbg_new_from_slice_48496fd78013671b: function(arg0, arg1) {
997
- const ret = new Uint8ClampedArray(getArrayU8FromWasm0(arg0, arg1));
998
- return ret;
999
- },
1000
- __wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) {
1001
- const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
1002
- return ret;
1003
- },
1004
- __wbg_new_with_length_63f2683cc2521026: function(arg0) {
1005
- const ret = new Float32Array(arg0 >>> 0);
1006
- return ret;
1007
- },
1008
- __wbg_new_with_length_a2c39cbe88fd8ff1: function(arg0) {
1009
- const ret = new Uint8Array(arg0 >>> 0);
1010
- return ret;
1011
- },
1012
- __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
1013
- Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
1014
- },
1015
- __wbg_push_8ffdcb2063340ba5: function(arg0, arg1) {
1016
- const ret = arg0.push(arg1);
1017
- return ret;
1018
- },
1019
- __wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
1020
- const ret = Reflect.set(arg0, arg1, arg2);
1021
- return ret;
1022
- }, arguments); },
1023
- __wbg_set_index_41955224420ba3c6: function(arg0, arg1, arg2) {
1024
- arg0[arg1 >>> 0] = arg2;
1025
- },
1026
- __wbg_set_index_b3244a6c458021e4: function(arg0, arg1, arg2) {
1027
- arg0[arg1 >>> 0] = arg2;
1028
- },
1029
- __wbindgen_cast_0000000000000001: function(arg0) {
1030
- // Cast intrinsic for `F64 -> Externref`.
1031
- const ret = arg0;
1032
- return ret;
1033
- },
1034
- __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1035
- // Cast intrinsic for `Ref(String) -> Externref`.
1036
- const ret = getStringFromWasm0(arg0, arg1);
1037
- return ret;
1038
- },
1039
- __wbindgen_init_externref_table: function() {
1040
- const table = wasm.__wbindgen_externrefs;
1041
- const offset = table.grow(4);
1042
- table.set(0, undefined);
1043
- table.set(offset + 0, undefined);
1044
- table.set(offset + 1, null);
1045
- table.set(offset + 2, true);
1046
- table.set(offset + 3, false);
1047
- },
1048
- };
1049
- return {
1050
- __proto__: null,
1051
- "./smart_downscaler_bg.js": import0,
1052
- };
1053
- }
1054
-
1055
- const ColorAnalysisResultFinalization = (typeof FinalizationRegistry === 'undefined')
1056
- ? { register: () => {}, unregister: () => {} }
1057
- : new FinalizationRegistry(ptr => wasm.__wbg_coloranalysisresult_free(ptr >>> 0, 1));
1058
- const ColorEntryFinalization = (typeof FinalizationRegistry === 'undefined')
1059
- ? { register: () => {}, unregister: () => {} }
1060
- : new FinalizationRegistry(ptr => wasm.__wbg_colorentry_free(ptr >>> 0, 1));
1061
- const WasmDownscaleConfigFinalization = (typeof FinalizationRegistry === 'undefined')
1062
- ? { register: () => {}, unregister: () => {} }
1063
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmdownscaleconfig_free(ptr >>> 0, 1));
1064
- const WasmDownscaleResultFinalization = (typeof FinalizationRegistry === 'undefined')
1065
- ? { register: () => {}, unregister: () => {} }
1066
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmdownscaleresult_free(ptr >>> 0, 1));
1067
- const WasmPreparedImageFinalization = (typeof FinalizationRegistry === 'undefined')
1068
- ? { register: () => {}, unregister: () => {} }
1069
- : new FinalizationRegistry(ptr => wasm.__wbg_wasmpreparedimage_free(ptr >>> 0, 1));
1070
-
1071
- function addToExternrefTable0(obj) {
1072
- const idx = wasm.__externref_table_alloc();
1073
- wasm.__wbindgen_externrefs.set(idx, obj);
1074
- return idx;
1075
- }
1076
-
1077
- function _assertClass(instance, klass) {
1078
- if (!(instance instanceof klass)) {
1079
- throw new Error(`expected instance of ${klass.name}`);
1080
- }
1081
- }
1082
-
1083
- function getArrayU8FromWasm0(ptr, len) {
1084
- ptr = ptr >>> 0;
1085
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
1086
- }
1087
-
1088
- function getStringFromWasm0(ptr, len) {
1089
- ptr = ptr >>> 0;
1090
- return decodeText(ptr, len);
1091
- }
1092
-
1093
- let cachedUint8ArrayMemory0 = null;
1094
- function getUint8ArrayMemory0() {
1095
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
1096
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
1097
- }
1098
- return cachedUint8ArrayMemory0;
1099
- }
1100
-
1101
- function handleError(f, args) {
1102
- try {
1103
- return f.apply(this, args);
1104
- } catch (e) {
1105
- const idx = addToExternrefTable0(e);
1106
- wasm.__wbindgen_exn_store(idx);
1107
- }
1108
- }
1109
-
1110
- function isLikeNone(x) {
1111
- return x === undefined || x === null;
1112
- }
1113
-
1114
- function passStringToWasm0(arg, malloc, realloc) {
1115
- if (realloc === undefined) {
1116
- const buf = cachedTextEncoder.encode(arg);
1117
- const ptr = malloc(buf.length, 1) >>> 0;
1118
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
1119
- WASM_VECTOR_LEN = buf.length;
1120
- return ptr;
1121
- }
1122
-
1123
- let len = arg.length;
1124
- let ptr = malloc(len, 1) >>> 0;
1125
-
1126
- const mem = getUint8ArrayMemory0();
1127
-
1128
- let offset = 0;
1129
-
1130
- for (; offset < len; offset++) {
1131
- const code = arg.charCodeAt(offset);
1132
- if (code > 0x7F) break;
1133
- mem[ptr + offset] = code;
1134
- }
1135
- if (offset !== len) {
1136
- if (offset !== 0) {
1137
- arg = arg.slice(offset);
1138
- }
1139
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
1140
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
1141
- const ret = cachedTextEncoder.encodeInto(arg, view);
1142
-
1143
- offset += ret.written;
1144
- ptr = realloc(ptr, len, offset, 1) >>> 0;
1145
- }
1146
-
1147
- WASM_VECTOR_LEN = offset;
1148
- return ptr;
1149
- }
1150
-
1151
- function takeFromExternrefTable0(idx) {
1152
- const value = wasm.__wbindgen_externrefs.get(idx);
1153
- wasm.__externref_table_dealloc(idx);
1154
- return value;
1155
- }
1156
-
1157
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1158
- cachedTextDecoder.decode();
1159
- function decodeText(ptr, len) {
1160
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1161
- }
1162
-
1163
- const cachedTextEncoder = new TextEncoder();
1164
-
1165
- if (!('encodeInto' in cachedTextEncoder)) {
1166
- cachedTextEncoder.encodeInto = function (arg, view) {
1167
- const buf = cachedTextEncoder.encode(arg);
1168
- view.set(buf);
1169
- return {
1170
- read: arg.length,
1171
- written: buf.length
1172
- };
1173
- };
1174
- }
1175
-
1176
- let WASM_VECTOR_LEN = 0;
1177
-
1178
- const wasmPath = `${__dirname}/smart_downscaler_bg.wasm`;
1179
- const wasmBytes = require('fs').readFileSync(wasmPath);
1180
- const wasmModule = new WebAssembly.Module(wasmBytes);
1181
- const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
3
+ import * as wasm from "./smart_downscaler_bg.wasm";
4
+ import { __wbg_set_wasm } from "./smart_downscaler_bg.js";
5
+ __wbg_set_wasm(wasm);
1182
6
  wasm.__wbindgen_start();
7
+ export {
8
+ ColorAnalysisResult, ColorEntry, WasmDownscaleConfig, WasmDownscaleResult, WasmPreparedImage, analyze_colors, color_distance, downscale, downscale_prepared, downscale_prepared_with_palette, downscale_rgba, downscale_simple, downscale_with_palette, extract_palette_from_image, get_chroma, get_lightness, get_palette_strategies, init, log, oklab_to_rgb, prepare, prepare_rgba, quantize_to_palette, rgb_to_oklab, version
9
+ } from "./smart_downscaler_bg.js";