smart-downscaler 0.1.4 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/smart_downscaler.d.ts +11 -0
- package/smart_downscaler_bg.js +56 -0
- package/smart_downscaler_bg.wasm +0 -0
package/package.json
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
"Pixagram"
|
|
6
6
|
],
|
|
7
7
|
"description": "Intelligent pixel art downscaler with region-aware color quantization",
|
|
8
|
-
"version": "0.1
|
|
8
|
+
"version": "0.2.1",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/pixagram/smart-downscaler"
|
|
12
|
+
"url": "https://github.com/pixagram-blockchain/smart-downscaler"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"smart_downscaler_bg.wasm",
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
"quantization",
|
|
31
31
|
"wasm"
|
|
32
32
|
]
|
|
33
|
-
}
|
|
33
|
+
}
|
package/smart_downscaler.d.ts
CHANGED
|
@@ -104,6 +104,17 @@ export class WasmDownscaleResult {
|
|
|
104
104
|
readonly palette_size: number;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Highly optimized color analysis using a custom linear-probing hash table.
|
|
109
|
+
*
|
|
110
|
+
* OPTIMIZATIONS:
|
|
111
|
+
* 1. Casts u8 slice to u32 slice (Zero Copy, 4x read speed)
|
|
112
|
+
* 2. Uses Power-of-Two capacity for bitwise masking (vs modulo)
|
|
113
|
+
* 3. FxHash-style integer mixer
|
|
114
|
+
* 4. Linear probing with localized memory access
|
|
115
|
+
*/
|
|
116
|
+
export function analyze_colors(image_data: Uint8Array, max_colors: number, sort_method: string): any;
|
|
117
|
+
|
|
107
118
|
/**
|
|
108
119
|
* Main downscaling function for WebAssembly
|
|
109
120
|
*
|
package/smart_downscaler_bg.js
CHANGED
|
@@ -31,6 +31,13 @@ function isLikeNone(x) {
|
|
|
31
31
|
return x === undefined || x === null;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
35
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
36
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
37
|
+
WASM_VECTOR_LEN = arg.length;
|
|
38
|
+
return ptr;
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
35
42
|
if (realloc === undefined) {
|
|
36
43
|
const buf = cachedTextEncoder.encode(arg);
|
|
@@ -439,6 +446,31 @@ export class WasmDownscaleResult {
|
|
|
439
446
|
}
|
|
440
447
|
if (Symbol.dispose) WasmDownscaleResult.prototype[Symbol.dispose] = WasmDownscaleResult.prototype.free;
|
|
441
448
|
|
|
449
|
+
/**
|
|
450
|
+
* Highly optimized color analysis using a custom linear-probing hash table.
|
|
451
|
+
*
|
|
452
|
+
* OPTIMIZATIONS:
|
|
453
|
+
* 1. Casts u8 slice to u32 slice (Zero Copy, 4x read speed)
|
|
454
|
+
* 2. Uses Power-of-Two capacity for bitwise masking (vs modulo)
|
|
455
|
+
* 3. FxHash-style integer mixer
|
|
456
|
+
* 4. Linear probing with localized memory access
|
|
457
|
+
* @param {Uint8Array} image_data
|
|
458
|
+
* @param {number} max_colors
|
|
459
|
+
* @param {string} sort_method
|
|
460
|
+
* @returns {any}
|
|
461
|
+
*/
|
|
462
|
+
export function analyze_colors(image_data, max_colors, sort_method) {
|
|
463
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
|
|
464
|
+
const len0 = WASM_VECTOR_LEN;
|
|
465
|
+
const ptr1 = passStringToWasm0(sort_method, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
466
|
+
const len1 = WASM_VECTOR_LEN;
|
|
467
|
+
const ret = wasm.analyze_colors(ptr0, len0, max_colors, ptr1, len1);
|
|
468
|
+
if (ret[2]) {
|
|
469
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
470
|
+
}
|
|
471
|
+
return takeFromExternrefTable0(ret[0]);
|
|
472
|
+
}
|
|
473
|
+
|
|
442
474
|
/**
|
|
443
475
|
* Main downscaling function for WebAssembly
|
|
444
476
|
*
|
|
@@ -618,6 +650,16 @@ export function __wbg_log_1d990106d99dacb7(arg0) {
|
|
|
618
650
|
console.log(arg0);
|
|
619
651
|
};
|
|
620
652
|
|
|
653
|
+
export function __wbg_new_1ba21ce319a06297() {
|
|
654
|
+
const ret = new Object();
|
|
655
|
+
return ret;
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
export function __wbg_new_25f239778d6112b9() {
|
|
659
|
+
const ret = new Array();
|
|
660
|
+
return ret;
|
|
661
|
+
};
|
|
662
|
+
|
|
621
663
|
export function __wbg_new_6421f6084cc5bc5a(arg0) {
|
|
622
664
|
const ret = new Uint8Array(arg0);
|
|
623
665
|
return ret;
|
|
@@ -642,12 +684,26 @@ export function __wbg_prototypesetcall_dfe9b766cdc1f1fd(arg0, arg1, arg2) {
|
|
|
642
684
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
643
685
|
};
|
|
644
686
|
|
|
687
|
+
export function __wbg_set_3f1d0b984ed272ed(arg0, arg1, arg2) {
|
|
688
|
+
arg0[arg1] = arg2;
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
export function __wbg_set_7df433eea03a5c14(arg0, arg1, arg2) {
|
|
692
|
+
arg0[arg1 >>> 0] = arg2;
|
|
693
|
+
};
|
|
694
|
+
|
|
645
695
|
export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
|
|
646
696
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
647
697
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
648
698
|
return ret;
|
|
649
699
|
};
|
|
650
700
|
|
|
701
|
+
export function __wbindgen_cast_d6cd19b81560fd6e(arg0) {
|
|
702
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
703
|
+
const ret = arg0;
|
|
704
|
+
return ret;
|
|
705
|
+
};
|
|
706
|
+
|
|
651
707
|
export function __wbindgen_init_externref_table() {
|
|
652
708
|
const table = wasm.__wbindgen_externrefs;
|
|
653
709
|
const offset = table.grow(4);
|
package/smart_downscaler_bg.wasm
CHANGED
|
Binary file
|