@squoosh-kit/hqx 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.
@@ -0,0 +1,108 @@
1
+
2
+ let wasm;
3
+
4
+ let cachegetUint32Memory0 = null;
5
+ function getUint32Memory0() {
6
+ if (cachegetUint32Memory0 === null || cachegetUint32Memory0.buffer !== wasm.memory.buffer) {
7
+ cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
8
+ }
9
+ return cachegetUint32Memory0;
10
+ }
11
+
12
+ let WASM_VECTOR_LEN = 0;
13
+
14
+ function passArray32ToWasm0(arg, malloc) {
15
+ const ptr = malloc(arg.length * 4);
16
+ getUint32Memory0().set(arg, ptr / 4);
17
+ WASM_VECTOR_LEN = arg.length;
18
+ return ptr;
19
+ }
20
+
21
+ let cachegetInt32Memory0 = null;
22
+ function getInt32Memory0() {
23
+ if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
24
+ cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
25
+ }
26
+ return cachegetInt32Memory0;
27
+ }
28
+
29
+ function getArrayU32FromWasm0(ptr, len) {
30
+ return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
31
+ }
32
+ /**
33
+ * @param {Uint32Array} input_image
34
+ * @param {number} input_width
35
+ * @param {number} input_height
36
+ * @param {number} factor
37
+ * @returns {Uint32Array}
38
+ */
39
+ export function resize(input_image, input_width, input_height, factor) {
40
+ try {
41
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
42
+ var ptr0 = passArray32ToWasm0(input_image, wasm.__wbindgen_malloc);
43
+ var len0 = WASM_VECTOR_LEN;
44
+ wasm.resize(retptr, ptr0, len0, input_width, input_height, factor);
45
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
46
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
47
+ var v1 = getArrayU32FromWasm0(r0, r1).slice();
48
+ wasm.__wbindgen_free(r0, r1 * 4);
49
+ return v1;
50
+ } finally {
51
+ wasm.__wbindgen_add_to_stack_pointer(16);
52
+ }
53
+ }
54
+
55
+ async function load(module, imports) {
56
+ if (typeof Response === 'function' && module instanceof Response) {
57
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
58
+ try {
59
+ return await WebAssembly.instantiateStreaming(module, imports);
60
+
61
+ } catch (e) {
62
+ if (module.headers.get('Content-Type') != 'application/wasm') {
63
+ 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);
64
+
65
+ } else {
66
+ throw e;
67
+ }
68
+ }
69
+ }
70
+
71
+ const bytes = await module.arrayBuffer();
72
+ return await WebAssembly.instantiate(bytes, imports);
73
+
74
+ } else {
75
+ const instance = await WebAssembly.instantiate(module, imports);
76
+
77
+ if (instance instanceof WebAssembly.Instance) {
78
+ return { instance, module };
79
+
80
+ } else {
81
+ return instance;
82
+ }
83
+ }
84
+ }
85
+
86
+ async function init(input) {
87
+ if (typeof input === 'undefined') {
88
+ input = new URL('squooshhqx_bg.wasm', import.meta.url);
89
+ }
90
+ const imports = {};
91
+
92
+
93
+ if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
94
+ input = fetch(input);
95
+ }
96
+
97
+
98
+
99
+ const { instance, module } = await load(await input, imports);
100
+
101
+ wasm = instance.exports;
102
+ init.__wbindgen_wasm_module = module;
103
+
104
+ return wasm;
105
+ }
106
+
107
+ export default init;
108
+
Binary file
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@squoosh-kit/hqx",
3
+ "version": "0.2.1",
4
+ "type": "module",
5
+ "description": "HQX upscaler codec for squoosh-kit, providing wasm-bindgen-based image upscaling.",
6
+ "author": "Bartosz Nowak <bnowak008@gmail.com>",
7
+ "license": "MIT AND Apache-2.0",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/bnowak008/squoosh-kit.git",
11
+ "directory": "packages/hqx"
12
+ },
13
+ "homepage": "https://github.com/bnowak008/squoosh-kit/tree/main/packages/hqx#readme",
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "registry": "https://registry.npmjs.org/"
17
+ },
18
+ "main": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "browser": "./dist/index.browser.mjs",
24
+ "bun": "./dist/index.bun.js",
25
+ "import": "./dist/index.node.mjs",
26
+ "require": "./dist/index.node.cjs"
27
+ },
28
+ "./hqx.worker.js": {
29
+ "types": "./dist/hqx.worker.d.ts",
30
+ "browser": "./dist/hqx.worker.browser.mjs",
31
+ "bun": "./dist/hqx.worker.bun.js",
32
+ "import": "./dist/hqx.worker.node.mjs",
33
+ "require": "./dist/hqx.worker.node.cjs"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist/**",
38
+ "README.md",
39
+ "LICENSE",
40
+ "NOTICE"
41
+ ],
42
+ "sideEffects": false,
43
+ "scripts": {
44
+ "build": "bun run build.ts",
45
+ "clean:local": "rm -rf dist node_modules .bun/install/cache bun.lockb bun.lock *.tsbuildinfo",
46
+ "prepack": "bun run build && bun test",
47
+ "test": "bun test"
48
+ },
49
+ "dependencies": {
50
+ "@squoosh-kit/runtime": "workspace:*"
51
+ }
52
+ }