smart-downscaler 0.6.3 → 0.6.4
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.
- package/package.json +6 -2
- package/smart_downscaler.d.ts +131 -0
- package/smart_downscaler.js +124 -55
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smart-downscaler",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"collaborators": [
|
|
4
5
|
"Pixagram"
|
|
5
6
|
],
|
|
6
7
|
"description": "Intelligent pixel art downscaler with region-aware color quantization",
|
|
7
|
-
"version": "0.6.
|
|
8
|
+
"version": "0.6.4",
|
|
8
9
|
"license": "MIT",
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -17,6 +18,9 @@
|
|
|
17
18
|
],
|
|
18
19
|
"main": "smart_downscaler.js",
|
|
19
20
|
"types": "smart_downscaler.d.ts",
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"./snippets/*"
|
|
23
|
+
],
|
|
20
24
|
"keywords": [
|
|
21
25
|
"pixel-art",
|
|
22
26
|
"image-processing",
|
|
@@ -24,4 +28,4 @@
|
|
|
24
28
|
"quantization",
|
|
25
29
|
"wasm"
|
|
26
30
|
]
|
|
27
|
-
}
|
|
31
|
+
}
|
package/smart_downscaler.d.ts
CHANGED
|
@@ -161,3 +161,134 @@ export function quantize_to_palette(image_data: Uint8Array, width: number, heigh
|
|
|
161
161
|
export function rgb_to_oklab(r: number, g: number, b: number): Float32Array;
|
|
162
162
|
|
|
163
163
|
export function version(): string;
|
|
164
|
+
|
|
165
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
166
|
+
|
|
167
|
+
export interface InitOutput {
|
|
168
|
+
readonly memory: WebAssembly.Memory;
|
|
169
|
+
readonly __wbg_coloranalysisresult_free: (a: number, b: number) => void;
|
|
170
|
+
readonly __wbg_colorentry_free: (a: number, b: number) => void;
|
|
171
|
+
readonly __wbg_get_wasmdownscaleconfig_chroma_recovery: (a: number) => number;
|
|
172
|
+
readonly __wbg_get_wasmdownscaleconfig_color_rarity: (a: number) => number;
|
|
173
|
+
readonly __wbg_get_wasmdownscaleconfig_detail_boost: (a: number) => number;
|
|
174
|
+
readonly __wbg_get_wasmdownscaleconfig_edge_weight: (a: number) => number;
|
|
175
|
+
readonly __wbg_get_wasmdownscaleconfig_hierarchy_min_size: (a: number) => number;
|
|
176
|
+
readonly __wbg_get_wasmdownscaleconfig_hierarchy_threshold: (a: number) => number;
|
|
177
|
+
readonly __wbg_get_wasmdownscaleconfig_k_centroid: (a: number) => number;
|
|
178
|
+
readonly __wbg_get_wasmdownscaleconfig_k_centroid_iterations: (a: number) => number;
|
|
179
|
+
readonly __wbg_get_wasmdownscaleconfig_kmeans_iterations: (a: number) => number;
|
|
180
|
+
readonly __wbg_get_wasmdownscaleconfig_max_color_preprocess: (a: number) => number;
|
|
181
|
+
readonly __wbg_get_wasmdownscaleconfig_max_resolution_mp: (a: number) => number;
|
|
182
|
+
readonly __wbg_get_wasmdownscaleconfig_neighbor_weight: (a: number) => number;
|
|
183
|
+
readonly __wbg_get_wasmdownscaleconfig_palette_size: (a: number) => number;
|
|
184
|
+
readonly __wbg_get_wasmdownscaleconfig_refinement_iterations: (a: number) => number;
|
|
185
|
+
readonly __wbg_get_wasmdownscaleconfig_region_weight: (a: number) => number;
|
|
186
|
+
readonly __wbg_get_wasmdownscaleconfig_reserve_colors: (a: number) => number;
|
|
187
|
+
readonly __wbg_get_wasmdownscaleconfig_skin_protection: (a: number) => number;
|
|
188
|
+
readonly __wbg_get_wasmdownscaleconfig_slic_compactness: (a: number) => number;
|
|
189
|
+
readonly __wbg_get_wasmdownscaleconfig_slic_superpixels: (a: number) => number;
|
|
190
|
+
readonly __wbg_get_wasmdownscaleconfig_two_pass_refinement: (a: number) => number;
|
|
191
|
+
readonly __wbg_set_wasmdownscaleconfig_chroma_recovery: (a: number, b: number) => void;
|
|
192
|
+
readonly __wbg_set_wasmdownscaleconfig_color_rarity: (a: number, b: number) => void;
|
|
193
|
+
readonly __wbg_set_wasmdownscaleconfig_detail_boost: (a: number, b: number) => void;
|
|
194
|
+
readonly __wbg_set_wasmdownscaleconfig_edge_weight: (a: number, b: number) => void;
|
|
195
|
+
readonly __wbg_set_wasmdownscaleconfig_hierarchy_min_size: (a: number, b: number) => void;
|
|
196
|
+
readonly __wbg_set_wasmdownscaleconfig_hierarchy_threshold: (a: number, b: number) => void;
|
|
197
|
+
readonly __wbg_set_wasmdownscaleconfig_k_centroid: (a: number, b: number) => void;
|
|
198
|
+
readonly __wbg_set_wasmdownscaleconfig_k_centroid_iterations: (a: number, b: number) => void;
|
|
199
|
+
readonly __wbg_set_wasmdownscaleconfig_kmeans_iterations: (a: number, b: number) => void;
|
|
200
|
+
readonly __wbg_set_wasmdownscaleconfig_max_color_preprocess: (a: number, b: number) => void;
|
|
201
|
+
readonly __wbg_set_wasmdownscaleconfig_max_resolution_mp: (a: number, b: number) => void;
|
|
202
|
+
readonly __wbg_set_wasmdownscaleconfig_neighbor_weight: (a: number, b: number) => void;
|
|
203
|
+
readonly __wbg_set_wasmdownscaleconfig_palette_size: (a: number, b: number) => void;
|
|
204
|
+
readonly __wbg_set_wasmdownscaleconfig_refinement_iterations: (a: number, b: number) => void;
|
|
205
|
+
readonly __wbg_set_wasmdownscaleconfig_region_weight: (a: number, b: number) => void;
|
|
206
|
+
readonly __wbg_set_wasmdownscaleconfig_reserve_colors: (a: number, b: number) => void;
|
|
207
|
+
readonly __wbg_set_wasmdownscaleconfig_skin_protection: (a: number, b: number) => void;
|
|
208
|
+
readonly __wbg_set_wasmdownscaleconfig_slic_compactness: (a: number, b: number) => void;
|
|
209
|
+
readonly __wbg_set_wasmdownscaleconfig_slic_superpixels: (a: number, b: number) => void;
|
|
210
|
+
readonly __wbg_set_wasmdownscaleconfig_two_pass_refinement: (a: number, b: number) => void;
|
|
211
|
+
readonly __wbg_wasmdownscaleconfig_free: (a: number, b: number) => void;
|
|
212
|
+
readonly __wbg_wasmdownscaleresult_free: (a: number, b: number) => void;
|
|
213
|
+
readonly __wbg_wasmpreparedimage_free: (a: number, b: number) => void;
|
|
214
|
+
readonly analyze_colors: (a: any, b: number, c: number, d: number) => [number, number, number];
|
|
215
|
+
readonly color_distance: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
216
|
+
readonly coloranalysisresult_color_count: (a: number) => number;
|
|
217
|
+
readonly coloranalysisresult_get_color: (a: number, b: number) => number;
|
|
218
|
+
readonly coloranalysisresult_get_colors_flat: (a: number) => any;
|
|
219
|
+
readonly coloranalysisresult_success: (a: number) => number;
|
|
220
|
+
readonly coloranalysisresult_to_json: (a: number) => [number, number, number];
|
|
221
|
+
readonly coloranalysisresult_total_pixels: (a: number) => number;
|
|
222
|
+
readonly colorentry_b: (a: number) => number;
|
|
223
|
+
readonly colorentry_count: (a: number) => number;
|
|
224
|
+
readonly colorentry_g: (a: number) => number;
|
|
225
|
+
readonly colorentry_hex: (a: number) => [number, number];
|
|
226
|
+
readonly colorentry_percentage: (a: number) => number;
|
|
227
|
+
readonly colorentry_r: (a: number) => number;
|
|
228
|
+
readonly downscale: (a: any, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
229
|
+
readonly downscale_prepared: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
230
|
+
readonly downscale_prepared_with_palette: (a: number, b: number, c: number, d: any, e: number) => [number, number, number];
|
|
231
|
+
readonly downscale_rgba: (a: any, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
232
|
+
readonly downscale_simple: (a: any, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
233
|
+
readonly downscale_with_palette: (a: any, b: number, c: number, d: number, e: number, f: any, g: number) => [number, number, number];
|
|
234
|
+
readonly extract_palette_from_image: (a: any, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
235
|
+
readonly get_chroma: (a: number, b: number, c: number) => number;
|
|
236
|
+
readonly get_lightness: (a: number, b: number, c: number) => number;
|
|
237
|
+
readonly get_palette_strategies: () => any;
|
|
238
|
+
readonly init: () => void;
|
|
239
|
+
readonly log: (a: number, b: number) => void;
|
|
240
|
+
readonly oklab_to_rgb: (a: number, b: number, c: number) => any;
|
|
241
|
+
readonly prepare: (a: any, b: number, c: number, d: number) => [number, number, number];
|
|
242
|
+
readonly prepare_rgba: (a: any, b: number, c: number, d: number) => [number, number, number];
|
|
243
|
+
readonly quantize_to_palette: (a: any, b: number, c: number, d: any) => [number, number, number];
|
|
244
|
+
readonly rgb_to_oklab: (a: number, b: number, c: number) => any;
|
|
245
|
+
readonly version: () => [number, number];
|
|
246
|
+
readonly wasmdownscaleconfig_exact_colors: () => number;
|
|
247
|
+
readonly wasmdownscaleconfig_fast: () => number;
|
|
248
|
+
readonly wasmdownscaleconfig_new: () => number;
|
|
249
|
+
readonly wasmdownscaleconfig_palette_strategy: (a: number) => [number, number];
|
|
250
|
+
readonly wasmdownscaleconfig_quality: () => number;
|
|
251
|
+
readonly wasmdownscaleconfig_segmentation_method: (a: number) => [number, number];
|
|
252
|
+
readonly wasmdownscaleconfig_set_palette_strategy: (a: number, b: number, c: number) => void;
|
|
253
|
+
readonly wasmdownscaleconfig_set_segmentation_method: (a: number, b: number, c: number) => void;
|
|
254
|
+
readonly wasmdownscaleconfig_vibrant: () => number;
|
|
255
|
+
readonly wasmdownscaleresult_data: (a: number) => any;
|
|
256
|
+
readonly wasmdownscaleresult_height: (a: number) => number;
|
|
257
|
+
readonly wasmdownscaleresult_indices: (a: number) => any;
|
|
258
|
+
readonly wasmdownscaleresult_palette: (a: number) => any;
|
|
259
|
+
readonly wasmdownscaleresult_palette_size: (a: number) => number;
|
|
260
|
+
readonly wasmdownscaleresult_rgb_data: (a: number) => any;
|
|
261
|
+
readonly wasmdownscaleresult_width: (a: number) => number;
|
|
262
|
+
readonly wasmpreparedimage_height: (a: number) => number;
|
|
263
|
+
readonly wasmpreparedimage_width: (a: number) => number;
|
|
264
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
265
|
+
readonly __externref_table_alloc: () => number;
|
|
266
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
267
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
268
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
269
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
270
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
271
|
+
readonly __wbindgen_start: () => void;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
278
|
+
* a precompiled `WebAssembly.Module`.
|
|
279
|
+
*
|
|
280
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
281
|
+
*
|
|
282
|
+
* @returns {InitOutput}
|
|
283
|
+
*/
|
|
284
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
288
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
289
|
+
*
|
|
290
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
291
|
+
*
|
|
292
|
+
* @returns {Promise<InitOutput>}
|
|
293
|
+
*/
|
|
294
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/smart_downscaler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* @ts-self-types="./smart_downscaler.d.ts" */
|
|
2
2
|
|
|
3
|
-
class ColorAnalysisResult {
|
|
3
|
+
export class ColorAnalysisResult {
|
|
4
4
|
static __wrap(ptr) {
|
|
5
5
|
ptr = ptr >>> 0;
|
|
6
6
|
const obj = Object.create(ColorAnalysisResult.prototype);
|
|
@@ -66,9 +66,8 @@ class ColorAnalysisResult {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
if (Symbol.dispose) ColorAnalysisResult.prototype[Symbol.dispose] = ColorAnalysisResult.prototype.free;
|
|
69
|
-
exports.ColorAnalysisResult = ColorAnalysisResult;
|
|
70
69
|
|
|
71
|
-
class ColorEntry {
|
|
70
|
+
export class ColorEntry {
|
|
72
71
|
static __wrap(ptr) {
|
|
73
72
|
ptr = ptr >>> 0;
|
|
74
73
|
const obj = Object.create(ColorEntry.prototype);
|
|
@@ -138,9 +137,8 @@ class ColorEntry {
|
|
|
138
137
|
}
|
|
139
138
|
}
|
|
140
139
|
if (Symbol.dispose) ColorEntry.prototype[Symbol.dispose] = ColorEntry.prototype.free;
|
|
141
|
-
exports.ColorEntry = ColorEntry;
|
|
142
140
|
|
|
143
|
-
class WasmDownscaleConfig {
|
|
141
|
+
export class WasmDownscaleConfig {
|
|
144
142
|
static __wrap(ptr) {
|
|
145
143
|
ptr = ptr >>> 0;
|
|
146
144
|
const obj = Object.create(WasmDownscaleConfig.prototype);
|
|
@@ -510,9 +508,8 @@ class WasmDownscaleConfig {
|
|
|
510
508
|
}
|
|
511
509
|
}
|
|
512
510
|
if (Symbol.dispose) WasmDownscaleConfig.prototype[Symbol.dispose] = WasmDownscaleConfig.prototype.free;
|
|
513
|
-
exports.WasmDownscaleConfig = WasmDownscaleConfig;
|
|
514
511
|
|
|
515
|
-
class WasmDownscaleResult {
|
|
512
|
+
export class WasmDownscaleResult {
|
|
516
513
|
static __wrap(ptr) {
|
|
517
514
|
ptr = ptr >>> 0;
|
|
518
515
|
const obj = Object.create(WasmDownscaleResult.prototype);
|
|
@@ -581,7 +578,6 @@ class WasmDownscaleResult {
|
|
|
581
578
|
}
|
|
582
579
|
}
|
|
583
580
|
if (Symbol.dispose) WasmDownscaleResult.prototype[Symbol.dispose] = WasmDownscaleResult.prototype.free;
|
|
584
|
-
exports.WasmDownscaleResult = WasmDownscaleResult;
|
|
585
581
|
|
|
586
582
|
/**
|
|
587
583
|
* Opaque handle holding the prepared (preprocessed + segmented) source image.
|
|
@@ -591,7 +587,7 @@ exports.WasmDownscaleResult = WasmDownscaleResult;
|
|
|
591
587
|
* size and target dimensions may differ on every [`downscale_prepared`] call.
|
|
592
588
|
* If you change resolution / color-preprocess / segmentation settings, prepare again.
|
|
593
589
|
*/
|
|
594
|
-
class WasmPreparedImage {
|
|
590
|
+
export class WasmPreparedImage {
|
|
595
591
|
static __wrap(ptr) {
|
|
596
592
|
ptr = ptr >>> 0;
|
|
597
593
|
const obj = Object.create(WasmPreparedImage.prototype);
|
|
@@ -625,7 +621,6 @@ class WasmPreparedImage {
|
|
|
625
621
|
}
|
|
626
622
|
}
|
|
627
623
|
if (Symbol.dispose) WasmPreparedImage.prototype[Symbol.dispose] = WasmPreparedImage.prototype.free;
|
|
628
|
-
exports.WasmPreparedImage = WasmPreparedImage;
|
|
629
624
|
|
|
630
625
|
/**
|
|
631
626
|
* Analyze colors — FIX: uses HashMap<u32, usize> for O(1) lookup (was O(n) linear scan)
|
|
@@ -634,7 +629,7 @@ exports.WasmPreparedImage = WasmPreparedImage;
|
|
|
634
629
|
* @param {string} sort_method
|
|
635
630
|
* @returns {ColorAnalysisResult}
|
|
636
631
|
*/
|
|
637
|
-
function analyze_colors(image_data, max_colors, sort_method) {
|
|
632
|
+
export function analyze_colors(image_data, max_colors, sort_method) {
|
|
638
633
|
const ptr0 = passStringToWasm0(sort_method, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
639
634
|
const len0 = WASM_VECTOR_LEN;
|
|
640
635
|
const ret = wasm.analyze_colors(image_data, max_colors, ptr0, len0);
|
|
@@ -643,7 +638,6 @@ function analyze_colors(image_data, max_colors, sort_method) {
|
|
|
643
638
|
}
|
|
644
639
|
return ColorAnalysisResult.__wrap(ret[0]);
|
|
645
640
|
}
|
|
646
|
-
exports.analyze_colors = analyze_colors;
|
|
647
641
|
|
|
648
642
|
/**
|
|
649
643
|
* @param {number} r1
|
|
@@ -654,11 +648,10 @@ exports.analyze_colors = analyze_colors;
|
|
|
654
648
|
* @param {number} b2
|
|
655
649
|
* @returns {number}
|
|
656
650
|
*/
|
|
657
|
-
function color_distance(r1, g1, b1, r2, g2, b2) {
|
|
651
|
+
export function color_distance(r1, g1, b1, r2, g2, b2) {
|
|
658
652
|
const ret = wasm.color_distance(r1, g1, b1, r2, g2, b2);
|
|
659
653
|
return ret;
|
|
660
654
|
}
|
|
661
|
-
exports.color_distance = color_distance;
|
|
662
655
|
|
|
663
656
|
/**
|
|
664
657
|
* @param {Uint8Array} image_data
|
|
@@ -669,7 +662,7 @@ exports.color_distance = color_distance;
|
|
|
669
662
|
* @param {WasmDownscaleConfig | null} [config]
|
|
670
663
|
* @returns {WasmDownscaleResult}
|
|
671
664
|
*/
|
|
672
|
-
function downscale(image_data, width, height, target_width, target_height, config) {
|
|
665
|
+
export function downscale(image_data, width, height, target_width, target_height, config) {
|
|
673
666
|
let ptr0 = 0;
|
|
674
667
|
if (!isLikeNone(config)) {
|
|
675
668
|
_assertClass(config, WasmDownscaleConfig);
|
|
@@ -681,7 +674,6 @@ function downscale(image_data, width, height, target_width, target_height, confi
|
|
|
681
674
|
}
|
|
682
675
|
return WasmDownscaleResult.__wrap(ret[0]);
|
|
683
676
|
}
|
|
684
|
-
exports.downscale = downscale;
|
|
685
677
|
|
|
686
678
|
/**
|
|
687
679
|
* Downscale a prepared image. Pass an optional `config` to override per-target
|
|
@@ -694,7 +686,7 @@ exports.downscale = downscale;
|
|
|
694
686
|
* @param {WasmDownscaleConfig | null} [config]
|
|
695
687
|
* @returns {WasmDownscaleResult}
|
|
696
688
|
*/
|
|
697
|
-
function downscale_prepared(prepared, target_width, target_height, config) {
|
|
689
|
+
export function downscale_prepared(prepared, target_width, target_height, config) {
|
|
698
690
|
_assertClass(prepared, WasmPreparedImage);
|
|
699
691
|
let ptr0 = 0;
|
|
700
692
|
if (!isLikeNone(config)) {
|
|
@@ -707,7 +699,6 @@ function downscale_prepared(prepared, target_width, target_height, config) {
|
|
|
707
699
|
}
|
|
708
700
|
return WasmDownscaleResult.__wrap(ret[0]);
|
|
709
701
|
}
|
|
710
|
-
exports.downscale_prepared = downscale_prepared;
|
|
711
702
|
|
|
712
703
|
/**
|
|
713
704
|
* Downscale a prepared image with a caller-supplied palette.
|
|
@@ -718,7 +709,7 @@ exports.downscale_prepared = downscale_prepared;
|
|
|
718
709
|
* @param {WasmDownscaleConfig | null} [config]
|
|
719
710
|
* @returns {WasmDownscaleResult}
|
|
720
711
|
*/
|
|
721
|
-
function downscale_prepared_with_palette(prepared, target_width, target_height, palette_data, config) {
|
|
712
|
+
export function downscale_prepared_with_palette(prepared, target_width, target_height, palette_data, config) {
|
|
722
713
|
_assertClass(prepared, WasmPreparedImage);
|
|
723
714
|
let ptr0 = 0;
|
|
724
715
|
if (!isLikeNone(config)) {
|
|
@@ -731,7 +722,6 @@ function downscale_prepared_with_palette(prepared, target_width, target_height,
|
|
|
731
722
|
}
|
|
732
723
|
return WasmDownscaleResult.__wrap(ret[0]);
|
|
733
724
|
}
|
|
734
|
-
exports.downscale_prepared_with_palette = downscale_prepared_with_palette;
|
|
735
725
|
|
|
736
726
|
/**
|
|
737
727
|
* @param {Uint8ClampedArray} image_data
|
|
@@ -742,7 +732,7 @@ exports.downscale_prepared_with_palette = downscale_prepared_with_palette;
|
|
|
742
732
|
* @param {WasmDownscaleConfig | null} [config]
|
|
743
733
|
* @returns {WasmDownscaleResult}
|
|
744
734
|
*/
|
|
745
|
-
function downscale_rgba(image_data, width, height, target_width, target_height, config) {
|
|
735
|
+
export function downscale_rgba(image_data, width, height, target_width, target_height, config) {
|
|
746
736
|
let ptr0 = 0;
|
|
747
737
|
if (!isLikeNone(config)) {
|
|
748
738
|
_assertClass(config, WasmDownscaleConfig);
|
|
@@ -754,7 +744,6 @@ function downscale_rgba(image_data, width, height, target_width, target_height,
|
|
|
754
744
|
}
|
|
755
745
|
return WasmDownscaleResult.__wrap(ret[0]);
|
|
756
746
|
}
|
|
757
|
-
exports.downscale_rgba = downscale_rgba;
|
|
758
747
|
|
|
759
748
|
/**
|
|
760
749
|
* @param {Uint8Array} image_data
|
|
@@ -765,14 +754,13 @@ exports.downscale_rgba = downscale_rgba;
|
|
|
765
754
|
* @param {number} num_colors
|
|
766
755
|
* @returns {WasmDownscaleResult}
|
|
767
756
|
*/
|
|
768
|
-
function downscale_simple(image_data, width, height, target_width, target_height, num_colors) {
|
|
757
|
+
export function downscale_simple(image_data, width, height, target_width, target_height, num_colors) {
|
|
769
758
|
const ret = wasm.downscale_simple(image_data, width, height, target_width, target_height, num_colors);
|
|
770
759
|
if (ret[2]) {
|
|
771
760
|
throw takeFromExternrefTable0(ret[1]);
|
|
772
761
|
}
|
|
773
762
|
return WasmDownscaleResult.__wrap(ret[0]);
|
|
774
763
|
}
|
|
775
|
-
exports.downscale_simple = downscale_simple;
|
|
776
764
|
|
|
777
765
|
/**
|
|
778
766
|
* @param {Uint8Array} image_data
|
|
@@ -784,7 +772,7 @@ exports.downscale_simple = downscale_simple;
|
|
|
784
772
|
* @param {WasmDownscaleConfig | null} [config]
|
|
785
773
|
* @returns {WasmDownscaleResult}
|
|
786
774
|
*/
|
|
787
|
-
function downscale_with_palette(image_data, width, height, target_width, target_height, palette_data, config) {
|
|
775
|
+
export function downscale_with_palette(image_data, width, height, target_width, target_height, palette_data, config) {
|
|
788
776
|
let ptr0 = 0;
|
|
789
777
|
if (!isLikeNone(config)) {
|
|
790
778
|
_assertClass(config, WasmDownscaleConfig);
|
|
@@ -796,7 +784,6 @@ function downscale_with_palette(image_data, width, height, target_width, target_
|
|
|
796
784
|
}
|
|
797
785
|
return WasmDownscaleResult.__wrap(ret[0]);
|
|
798
786
|
}
|
|
799
|
-
exports.downscale_with_palette = downscale_with_palette;
|
|
800
787
|
|
|
801
788
|
/**
|
|
802
789
|
* @param {Uint8Array} image_data
|
|
@@ -807,7 +794,7 @@ exports.downscale_with_palette = downscale_with_palette;
|
|
|
807
794
|
* @param {string | null} [strategy]
|
|
808
795
|
* @returns {Uint8Array}
|
|
809
796
|
*/
|
|
810
|
-
function extract_palette_from_image(image_data, _width, _height, num_colors, kmeans_iterations, strategy) {
|
|
797
|
+
export function extract_palette_from_image(image_data, _width, _height, num_colors, kmeans_iterations, strategy) {
|
|
811
798
|
var ptr0 = isLikeNone(strategy) ? 0 : passStringToWasm0(strategy, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
812
799
|
var len0 = WASM_VECTOR_LEN;
|
|
813
800
|
const ret = wasm.extract_palette_from_image(image_data, _width, _height, num_colors, kmeans_iterations, ptr0, len0);
|
|
@@ -816,7 +803,6 @@ function extract_palette_from_image(image_data, _width, _height, num_colors, kme
|
|
|
816
803
|
}
|
|
817
804
|
return takeFromExternrefTable0(ret[0]);
|
|
818
805
|
}
|
|
819
|
-
exports.extract_palette_from_image = extract_palette_from_image;
|
|
820
806
|
|
|
821
807
|
/**
|
|
822
808
|
* @param {number} r
|
|
@@ -824,11 +810,10 @@ exports.extract_palette_from_image = extract_palette_from_image;
|
|
|
824
810
|
* @param {number} b
|
|
825
811
|
* @returns {number}
|
|
826
812
|
*/
|
|
827
|
-
function get_chroma(r, g, b) {
|
|
813
|
+
export function get_chroma(r, g, b) {
|
|
828
814
|
const ret = wasm.get_chroma(r, g, b);
|
|
829
815
|
return ret;
|
|
830
816
|
}
|
|
831
|
-
exports.get_chroma = get_chroma;
|
|
832
817
|
|
|
833
818
|
/**
|
|
834
819
|
* @param {number} r
|
|
@@ -836,35 +821,31 @@ exports.get_chroma = get_chroma;
|
|
|
836
821
|
* @param {number} b
|
|
837
822
|
* @returns {number}
|
|
838
823
|
*/
|
|
839
|
-
function get_lightness(r, g, b) {
|
|
824
|
+
export function get_lightness(r, g, b) {
|
|
840
825
|
const ret = wasm.get_lightness(r, g, b);
|
|
841
826
|
return ret;
|
|
842
827
|
}
|
|
843
|
-
exports.get_lightness = get_lightness;
|
|
844
828
|
|
|
845
829
|
/**
|
|
846
830
|
* @returns {Array<any>}
|
|
847
831
|
*/
|
|
848
|
-
function get_palette_strategies() {
|
|
832
|
+
export function get_palette_strategies() {
|
|
849
833
|
const ret = wasm.get_palette_strategies();
|
|
850
834
|
return ret;
|
|
851
835
|
}
|
|
852
|
-
exports.get_palette_strategies = get_palette_strategies;
|
|
853
836
|
|
|
854
|
-
function init() {
|
|
837
|
+
export function init() {
|
|
855
838
|
wasm.init();
|
|
856
839
|
}
|
|
857
|
-
exports.init = init;
|
|
858
840
|
|
|
859
841
|
/**
|
|
860
842
|
* @param {string} message
|
|
861
843
|
*/
|
|
862
|
-
function log(message) {
|
|
844
|
+
export function log(message) {
|
|
863
845
|
const ptr0 = passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
864
846
|
const len0 = WASM_VECTOR_LEN;
|
|
865
847
|
wasm.log(ptr0, len0);
|
|
866
848
|
}
|
|
867
|
-
exports.log = log;
|
|
868
849
|
|
|
869
850
|
/**
|
|
870
851
|
* @param {number} l
|
|
@@ -872,11 +853,10 @@ exports.log = log;
|
|
|
872
853
|
* @param {number} b
|
|
873
854
|
* @returns {Uint8Array}
|
|
874
855
|
*/
|
|
875
|
-
function oklab_to_rgb(l, a, b) {
|
|
856
|
+
export function oklab_to_rgb(l, a, b) {
|
|
876
857
|
const ret = wasm.oklab_to_rgb(l, a, b);
|
|
877
858
|
return ret;
|
|
878
859
|
}
|
|
879
|
-
exports.oklab_to_rgb = oklab_to_rgb;
|
|
880
860
|
|
|
881
861
|
/**
|
|
882
862
|
* Prepare from a `Uint8Array` (RGBA).
|
|
@@ -886,7 +866,7 @@ exports.oklab_to_rgb = oklab_to_rgb;
|
|
|
886
866
|
* @param {WasmDownscaleConfig | null} [config]
|
|
887
867
|
* @returns {WasmPreparedImage}
|
|
888
868
|
*/
|
|
889
|
-
function prepare(image_data, width, height, config) {
|
|
869
|
+
export function prepare(image_data, width, height, config) {
|
|
890
870
|
let ptr0 = 0;
|
|
891
871
|
if (!isLikeNone(config)) {
|
|
892
872
|
_assertClass(config, WasmDownscaleConfig);
|
|
@@ -898,7 +878,6 @@ function prepare(image_data, width, height, config) {
|
|
|
898
878
|
}
|
|
899
879
|
return WasmPreparedImage.__wrap(ret[0]);
|
|
900
880
|
}
|
|
901
|
-
exports.prepare = prepare;
|
|
902
881
|
|
|
903
882
|
/**
|
|
904
883
|
* Prepare from a `Uint8ClampedArray` (canvas `getImageData`).
|
|
@@ -908,7 +887,7 @@ exports.prepare = prepare;
|
|
|
908
887
|
* @param {WasmDownscaleConfig | null} [config]
|
|
909
888
|
* @returns {WasmPreparedImage}
|
|
910
889
|
*/
|
|
911
|
-
function prepare_rgba(image_data, width, height, config) {
|
|
890
|
+
export function prepare_rgba(image_data, width, height, config) {
|
|
912
891
|
let ptr0 = 0;
|
|
913
892
|
if (!isLikeNone(config)) {
|
|
914
893
|
_assertClass(config, WasmDownscaleConfig);
|
|
@@ -920,7 +899,6 @@ function prepare_rgba(image_data, width, height, config) {
|
|
|
920
899
|
}
|
|
921
900
|
return WasmPreparedImage.__wrap(ret[0]);
|
|
922
901
|
}
|
|
923
|
-
exports.prepare_rgba = prepare_rgba;
|
|
924
902
|
|
|
925
903
|
/**
|
|
926
904
|
* Quantize to palette — FIX: compute Oklab once per pixel (was twice)
|
|
@@ -930,14 +908,13 @@ exports.prepare_rgba = prepare_rgba;
|
|
|
930
908
|
* @param {Uint8Array} palette_data
|
|
931
909
|
* @returns {WasmDownscaleResult}
|
|
932
910
|
*/
|
|
933
|
-
function quantize_to_palette(image_data, width, height, palette_data) {
|
|
911
|
+
export function quantize_to_palette(image_data, width, height, palette_data) {
|
|
934
912
|
const ret = wasm.quantize_to_palette(image_data, width, height, palette_data);
|
|
935
913
|
if (ret[2]) {
|
|
936
914
|
throw takeFromExternrefTable0(ret[1]);
|
|
937
915
|
}
|
|
938
916
|
return WasmDownscaleResult.__wrap(ret[0]);
|
|
939
917
|
}
|
|
940
|
-
exports.quantize_to_palette = quantize_to_palette;
|
|
941
918
|
|
|
942
919
|
/**
|
|
943
920
|
* @param {number} r
|
|
@@ -945,16 +922,15 @@ exports.quantize_to_palette = quantize_to_palette;
|
|
|
945
922
|
* @param {number} b
|
|
946
923
|
* @returns {Float32Array}
|
|
947
924
|
*/
|
|
948
|
-
function rgb_to_oklab(r, g, b) {
|
|
925
|
+
export function rgb_to_oklab(r, g, b) {
|
|
949
926
|
const ret = wasm.rgb_to_oklab(r, g, b);
|
|
950
927
|
return ret;
|
|
951
928
|
}
|
|
952
|
-
exports.rgb_to_oklab = rgb_to_oklab;
|
|
953
929
|
|
|
954
930
|
/**
|
|
955
931
|
* @returns {string}
|
|
956
932
|
*/
|
|
957
|
-
function version() {
|
|
933
|
+
export function version() {
|
|
958
934
|
let deferred1_0;
|
|
959
935
|
let deferred1_1;
|
|
960
936
|
try {
|
|
@@ -966,7 +942,6 @@ function version() {
|
|
|
966
942
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
967
943
|
}
|
|
968
944
|
}
|
|
969
|
-
exports.version = version;
|
|
970
945
|
|
|
971
946
|
function __wbg_get_imports() {
|
|
972
947
|
const import0 = {
|
|
@@ -1156,7 +1131,15 @@ function takeFromExternrefTable0(idx) {
|
|
|
1156
1131
|
|
|
1157
1132
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
1158
1133
|
cachedTextDecoder.decode();
|
|
1134
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
1135
|
+
let numBytesDecoded = 0;
|
|
1159
1136
|
function decodeText(ptr, len) {
|
|
1137
|
+
numBytesDecoded += len;
|
|
1138
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
1139
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
1140
|
+
cachedTextDecoder.decode();
|
|
1141
|
+
numBytesDecoded = len;
|
|
1142
|
+
}
|
|
1160
1143
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
1161
1144
|
}
|
|
1162
1145
|
|
|
@@ -1175,8 +1158,94 @@ if (!('encodeInto' in cachedTextEncoder)) {
|
|
|
1175
1158
|
|
|
1176
1159
|
let WASM_VECTOR_LEN = 0;
|
|
1177
1160
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1161
|
+
let wasmModule, wasm;
|
|
1162
|
+
function __wbg_finalize_init(instance, module) {
|
|
1163
|
+
wasm = instance.exports;
|
|
1164
|
+
wasmModule = module;
|
|
1165
|
+
cachedUint8ArrayMemory0 = null;
|
|
1166
|
+
wasm.__wbindgen_start();
|
|
1167
|
+
return wasm;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
async function __wbg_load(module, imports) {
|
|
1171
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
1172
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
1173
|
+
try {
|
|
1174
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
1175
|
+
} catch (e) {
|
|
1176
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
1177
|
+
|
|
1178
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
1179
|
+
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);
|
|
1180
|
+
|
|
1181
|
+
} else { throw e; }
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
const bytes = await module.arrayBuffer();
|
|
1186
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
1187
|
+
} else {
|
|
1188
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
1189
|
+
|
|
1190
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
1191
|
+
return { instance, module };
|
|
1192
|
+
} else {
|
|
1193
|
+
return instance;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function expectedResponseType(type) {
|
|
1198
|
+
switch (type) {
|
|
1199
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
1200
|
+
}
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
function initSync(module) {
|
|
1206
|
+
if (wasm !== undefined) return wasm;
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
if (module !== undefined) {
|
|
1210
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
1211
|
+
({module} = module)
|
|
1212
|
+
} else {
|
|
1213
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
const imports = __wbg_get_imports();
|
|
1218
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
1219
|
+
module = new WebAssembly.Module(module);
|
|
1220
|
+
}
|
|
1221
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
1222
|
+
return __wbg_finalize_init(instance, module);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
async function __wbg_init(module_or_path) {
|
|
1226
|
+
if (wasm !== undefined) return wasm;
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
if (module_or_path !== undefined) {
|
|
1230
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
1231
|
+
({module_or_path} = module_or_path)
|
|
1232
|
+
} else {
|
|
1233
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
if (module_or_path === undefined) {
|
|
1238
|
+
module_or_path = new URL('smart_downscaler_bg.wasm', import.meta.url);
|
|
1239
|
+
}
|
|
1240
|
+
const imports = __wbg_get_imports();
|
|
1241
|
+
|
|
1242
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
1243
|
+
module_or_path = fetch(module_or_path);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
1247
|
+
|
|
1248
|
+
return __wbg_finalize_init(instance, module);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
export { initSync, __wbg_init as default };
|