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