@jsquash/resize 1.1.1 → 2.1.0

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/README.md CHANGED
@@ -11,6 +11,9 @@ Composed of:
11
11
  - https://github.com/PistonDevelopers/resize
12
12
  - https://github.com/CryZe/wasmboy-rs/tree/master/hqx
13
13
 
14
+ Addtionally we have added support for the Magic Kernel algorithm for resizing images. This is a Rust implementation of the algorithm.
15
+ - https://github.com/SevInf/magic-kernel-rust
16
+
14
17
  A [jSquash](https://github.com/jamsinclair/jSquash) package. Codecs and supporting code derived from the [Squoosh](https://github.com/GoogleChromeLabs/squoosh) app.
15
18
 
16
19
  ## Installation
@@ -26,7 +29,7 @@ Note: You will need to either manually include the wasm files from the codec dir
26
29
 
27
30
  ### resize(data: ImageData, options: ResizeOptions): Promise<ImageData>
28
31
 
29
- Resizes an ImageData object to the
32
+ Resizes an ImageData object to the specified dimensions.
30
33
 
31
34
  #### data
32
35
  Type: `ImageData`
@@ -37,7 +40,7 @@ Type: `Partial<ResizeOptions> & { width: number, height: number }`
37
40
  The resize options for the output image. [See default values](./meta.ts).
38
41
  - `width` (number) the width to resize the image to
39
42
  - `height` (number) the height to resize the image to
40
- - `method?` (`'triangle'` | `'catrom'` | `'mitchell'` | `'lanczos3'` | `'hqx'`) the algorithm used to resize the image. Defaults to `lanczos3`.
43
+ - `method?` (`'triangle'` | `'catrom'` | `'mitchell'` | `'lanczos3'` | `'hqx'` | `'magicKernel'` | `'magicKernelSharp2013'` | `'magicKernelSharp2021'`) the algorithm used to resize the image. Defaults to `lanczos3`.
41
44
  - `fitMethod?` (`'stretch'` | `'contain'`) whether the image is stretched to fit the dimensions or cropped. Defaults to `stretch`.
42
45
  - `premultiply?` (boolean) Defaults to `true`
43
46
  - `linearRGB?` (boolean) Defaults to `true`
@@ -68,4 +71,10 @@ import resize, { initResize } from '@jsquash/resize';
68
71
  initResize(WASM_MODULE); // The `WASM_MODULE` variable will need to be sourced by yourself and passed as an ArrayBuffer.
69
72
 
70
73
  resize(image, options);
74
+
75
+ // Optionally if you know you are using the hqx method or magicKernel method you can also initialise those modules
76
+ import { initHqx, initMagicKernel } from '@jsquash/resize';
77
+
78
+ initHqx(HQX_WASM_MODULE);
79
+ initMagicKernel(MAGIC_KERNEL_WASM_MODULE);
71
80
  ```
package/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import type { WorkerResizeOptions } from './meta.js';
2
- import type { InitInput as InitResizeInput } from './lib/resize/squoosh_resize.js';
3
- import type { InitInput as InitHqxInput } from './lib/hqx/squooshhqx.js';
2
+ import type { InitInput as InitResizeInput } from './lib/resize/pkg/squoosh_resize.js';
3
+ import type { InitInput as InitHqxInput } from './lib/hqx/pkg/squooshhqx.js';
4
+ import type { InitInput as InitMagicKernelInput } from './lib/magic-kernel/pkg/jsquash_magic_kernel.js';
4
5
  export declare function initResize(moduleOrPath?: InitResizeInput): Promise<unknown>;
5
6
  export declare function initHqx(moduleOrPath?: InitHqxInput): Promise<unknown>;
7
+ export declare function initMagicKernel(moduleOrPath?: InitMagicKernelInput): Promise<unknown>;
6
8
  export default function resize(data: ImageData, overrideOptions: Partial<WorkerResizeOptions> & {
7
9
  width: number;
8
10
  height: number;
package/index.js CHANGED
@@ -1,9 +1,16 @@
1
1
  import { getContainOffsets } from './util.js';
2
- import initResizeWasm, { resize as wasmResize, } from './lib/resize/squoosh_resize.js';
3
- import initHqxWasm, { resize as wasmHqx } from './lib/hqx/squooshhqx.js';
2
+ import initResizeWasm, { resize as wasmResize, } from './lib/resize/pkg/squoosh_resize.js';
3
+ import initHqxWasm, { resize as wasmHqx } from './lib/hqx/pkg/squooshhqx.js';
4
+ import initMagicKernelWasm, { resize as wasmMagicKernel, } from './lib/magic-kernel/pkg/jsquash_magic_kernel.js';
4
5
  import { defaultOptions } from './meta.js';
6
+ const MAGIC_KERNEL_METHODS = [
7
+ 'magicKernel',
8
+ 'magicKernelSharp2013',
9
+ 'magicKernelSharp2021',
10
+ ];
5
11
  let resizeWasmReady;
6
12
  let hqxWasmReady;
13
+ let magicKernelWasmReady;
7
14
  export function initResize(moduleOrPath) {
8
15
  if (!resizeWasmReady) {
9
16
  resizeWasmReady = initResizeWasm(moduleOrPath);
@@ -16,9 +23,18 @@ export function initHqx(moduleOrPath) {
16
23
  }
17
24
  return hqxWasmReady;
18
25
  }
26
+ export function initMagicKernel(moduleOrPath) {
27
+ if (!magicKernelWasmReady) {
28
+ magicKernelWasmReady = initMagicKernelWasm(moduleOrPath);
29
+ }
30
+ return magicKernelWasmReady;
31
+ }
19
32
  function optsIsHqxOpts(opts) {
20
33
  return opts.method === 'hqx';
21
34
  }
35
+ function optsIsMagicKernelOpts(opts) {
36
+ return MAGIC_KERNEL_METHODS.includes(opts.method);
37
+ }
22
38
  function crop(data, sx, sy, sw, sh) {
23
39
  const inputPixels = new Uint32Array(data.data.buffer);
24
40
  // Copy within the same buffer for speed and memory efficiency.
@@ -49,6 +65,11 @@ async function hqx(input, opts) {
49
65
  const result = wasmHqx(new Uint32Array(input.data.buffer), input.width, input.height, factor);
50
66
  return new ImageData(new Uint8ClampedArray(result.buffer), input.width * factor, input.height * factor);
51
67
  }
68
+ async function magicKernel(input, opts) {
69
+ await initMagicKernel();
70
+ const result = wasmMagicKernel(new Uint8Array(input.data.buffer), input.width, input.height, opts.width, opts.height, opts.method);
71
+ return result;
72
+ }
52
73
  export default async function resize(data, overrideOptions) {
53
74
  let options = {
54
75
  ...defaultOptions,
@@ -66,6 +87,9 @@ export default async function resize(data, overrideOptions) {
66
87
  const { sx, sy, sw, sh } = getContainOffsets(data.width, data.height, options.width, options.height);
67
88
  input = crop(input, Math.round(sx), Math.round(sy), Math.round(sw), Math.round(sh));
68
89
  }
90
+ if (optsIsMagicKernelOpts(options)) {
91
+ return magicKernel(input, options);
92
+ }
69
93
  const result = wasmResize(new Uint8Array(input.data.buffer), input.width, input.height, options.width, options.height, resizeMethods.indexOf(options.method), options.premultiply, options.linearRGB);
70
94
  return new ImageData(new Uint8ClampedArray(result.buffer), options.width, options.height);
71
95
  }
@@ -0,0 +1,5 @@
1
+ # HQX
2
+
3
+ - Source: <https://github.com/CryZe/wasmboy-rs>
4
+ - Version: v0.1.2
5
+ - License: Apache 2.0
@@ -0,0 +1,41 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {Uint32Array} input_image
5
+ * @param {number} input_width
6
+ * @param {number} input_height
7
+ * @param {number} factor
8
+ * @returns {Uint32Array}
9
+ */
10
+ export function resize(input_image: Uint32Array, input_width: number, input_height: number, factor: number): Uint32Array;
11
+
12
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
13
+
14
+ export interface InitOutput {
15
+ readonly memory: WebAssembly.Memory;
16
+ readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
17
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
18
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
19
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
20
+ }
21
+
22
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
23
+ /**
24
+ * Instantiates the given `module`, which can either be bytes or
25
+ * a precompiled `WebAssembly.Module`.
26
+ *
27
+ * @param {SyncInitInput} module
28
+ *
29
+ * @returns {InitOutput}
30
+ */
31
+ export function initSync(module: SyncInitInput): InitOutput;
32
+
33
+ /**
34
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
35
+ * for everything else, calls `WebAssembly.instantiate` directly.
36
+ *
37
+ * @param {InitInput | Promise<InitInput>} module_or_path
38
+ *
39
+ * @returns {Promise<InitOutput>}
40
+ */
41
+ export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -1,32 +1,34 @@
1
-
2
1
  let wasm;
3
2
 
4
- let cachegetUint32Memory0 = null;
3
+ let cachedUint32Memory0 = null;
4
+
5
5
  function getUint32Memory0() {
6
- if (cachegetUint32Memory0 === null || cachegetUint32Memory0.buffer !== wasm.memory.buffer) {
7
- cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
6
+ if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
7
+ cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
8
8
  }
9
- return cachegetUint32Memory0;
9
+ return cachedUint32Memory0;
10
10
  }
11
11
 
12
12
  let WASM_VECTOR_LEN = 0;
13
13
 
14
14
  function passArray32ToWasm0(arg, malloc) {
15
- const ptr = malloc(arg.length * 4);
15
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
16
16
  getUint32Memory0().set(arg, ptr / 4);
17
17
  WASM_VECTOR_LEN = arg.length;
18
18
  return ptr;
19
19
  }
20
20
 
21
- let cachegetInt32Memory0 = null;
21
+ let cachedInt32Memory0 = null;
22
+
22
23
  function getInt32Memory0() {
23
- if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
24
- cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
24
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
25
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
25
26
  }
26
- return cachegetInt32Memory0;
27
+ return cachedInt32Memory0;
27
28
  }
28
29
 
29
30
  function getArrayU32FromWasm0(ptr, len) {
31
+ ptr = ptr >>> 0;
30
32
  return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
31
33
  }
32
34
  /**
@@ -39,20 +41,20 @@ function getArrayU32FromWasm0(ptr, len) {
39
41
  export function resize(input_image, input_width, input_height, factor) {
40
42
  try {
41
43
  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
+ const ptr0 = passArray32ToWasm0(input_image, wasm.__wbindgen_malloc);
45
+ const len0 = WASM_VECTOR_LEN;
44
46
  wasm.resize(retptr, ptr0, len0, input_width, input_height, factor);
45
47
  var r0 = getInt32Memory0()[retptr / 4 + 0];
46
48
  var r1 = getInt32Memory0()[retptr / 4 + 1];
47
- var v1 = getArrayU32FromWasm0(r0, r1).slice();
48
- wasm.__wbindgen_free(r0, r1 * 4);
49
- return v1;
49
+ var v2 = getArrayU32FromWasm0(r0, r1).slice();
50
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
51
+ return v2;
50
52
  } finally {
51
53
  wasm.__wbindgen_add_to_stack_pointer(16);
52
54
  }
53
55
  }
54
56
 
55
- async function load(module, imports) {
57
+ async function __wbg_load(module, imports) {
56
58
  if (typeof Response === 'function' && module instanceof Response) {
57
59
  if (typeof WebAssembly.instantiateStreaming === 'function') {
58
60
  try {
@@ -83,29 +85,64 @@ async function load(module, imports) {
83
85
  }
84
86
  }
85
87
 
86
- async function init(input) {
88
+ function __wbg_get_imports() {
89
+ const imports = {};
90
+ imports.wbg = {};
91
+
92
+ return imports;
93
+ }
94
+
95
+ function __wbg_init_memory(imports, maybe_memory) {
96
+
97
+ }
98
+
99
+ function __wbg_finalize_init(instance, module) {
100
+ wasm = instance.exports;
101
+ __wbg_init.__wbindgen_wasm_module = module;
102
+ cachedInt32Memory0 = null;
103
+ cachedUint32Memory0 = null;
104
+
105
+
106
+ return wasm;
107
+ }
108
+
109
+ function initSync(module) {
110
+ if (wasm !== undefined) return wasm;
111
+
112
+ const imports = __wbg_get_imports();
113
+
114
+ __wbg_init_memory(imports);
115
+
116
+ if (!(module instanceof WebAssembly.Module)) {
117
+ module = new WebAssembly.Module(module);
118
+ }
119
+
120
+ const instance = new WebAssembly.Instance(module, imports);
121
+
122
+ return __wbg_finalize_init(instance, module);
123
+ }
124
+
125
+ async function __wbg_init(input) {
126
+ if (wasm !== undefined) return wasm;
127
+
87
128
  if (typeof input === 'undefined') {
88
129
  input = new URL('squooshhqx_bg.wasm', import.meta.url);
89
130
  }
90
- const imports = {};
91
-
131
+ const imports = __wbg_get_imports();
92
132
 
93
133
  if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
94
134
  input = fetch(input);
95
135
  }
96
136
 
137
+ __wbg_init_memory(imports);
97
138
 
139
+ const { instance, module } = await __wbg_load(await input, imports);
98
140
 
99
- const { instance, module } = await load(await input, imports);
100
-
101
- wasm = instance.exports;
102
- init.__wbindgen_wasm_module = module;
103
-
104
- return wasm;
141
+ return __wbg_finalize_init(instance, module);
105
142
  }
106
143
 
107
- export default init;
108
-
144
+ export { initSync }
145
+ export default __wbg_init;
109
146
  const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
110
147
  const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
111
148
  const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
Binary file
@@ -0,0 +1,7 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export function resize(a: number, b: number, c: number, d: number, e: number, f: number): void;
5
+ export function __wbindgen_add_to_stack_pointer(a: number): number;
6
+ export function __wbindgen_malloc(a: number, b: number): number;
7
+ export function __wbindgen_free(a: number, b: number, c: number): void;
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Serhii Tatarintsev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ # Magic Kernel
2
+
3
+ - Source: https://github.com/SevInf/magic-kernel-rust
4
+ - Version: v0.1.0
5
+ - License: MIT
@@ -0,0 +1,5 @@
1
+ # Magic Kernel
2
+
3
+ - Source: https://github.com/SevInf/magic-kernel-rust
4
+ - Version: v0.1.0
5
+ - License: MIT
@@ -0,0 +1,43 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * @param {Uint8Array} data
5
+ * @param {number} input_width
6
+ * @param {number} input_height
7
+ * @param {number} output_width
8
+ * @param {number} output_height
9
+ * @param {string} version
10
+ * @returns {ImageData}
11
+ */
12
+ export function resize(data: Uint8Array, input_width: number, input_height: number, output_width: number, output_height: number, version: string): ImageData;
13
+
14
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
15
+
16
+ export interface InitOutput {
17
+ readonly memory: WebAssembly.Memory;
18
+ readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
19
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
20
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
21
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
22
+ }
23
+
24
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
25
+ /**
26
+ * Instantiates the given `module`, which can either be bytes or
27
+ * a precompiled `WebAssembly.Module`.
28
+ *
29
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
30
+ *
31
+ * @returns {InitOutput}
32
+ */
33
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
34
+
35
+ /**
36
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
37
+ * for everything else, calls `WebAssembly.instantiate` directly.
38
+ *
39
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
40
+ *
41
+ * @returns {Promise<InitOutput>}
42
+ */
43
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,248 @@
1
+ let wasm;
2
+
3
+ let cachedUint8ClampedArrayMemory0 = null;
4
+
5
+ function getUint8ClampedArrayMemory0() {
6
+ if (cachedUint8ClampedArrayMemory0 === null || cachedUint8ClampedArrayMemory0.byteLength === 0) {
7
+ cachedUint8ClampedArrayMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
8
+ }
9
+ return cachedUint8ClampedArrayMemory0;
10
+ }
11
+
12
+ function getClampedArrayU8FromWasm0(ptr, len) {
13
+ ptr = ptr >>> 0;
14
+ return getUint8ClampedArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
15
+ }
16
+
17
+ const heap = new Array(128).fill(undefined);
18
+
19
+ heap.push(undefined, null, true, false);
20
+
21
+ let heap_next = heap.length;
22
+
23
+ function addHeapObject(obj) {
24
+ if (heap_next === heap.length) heap.push(heap.length + 1);
25
+ const idx = heap_next;
26
+ heap_next = heap[idx];
27
+
28
+ heap[idx] = obj;
29
+ return idx;
30
+ }
31
+
32
+ let cachedUint8ArrayMemory0 = null;
33
+
34
+ function getUint8ArrayMemory0() {
35
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
36
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
37
+ }
38
+ return cachedUint8ArrayMemory0;
39
+ }
40
+
41
+ let WASM_VECTOR_LEN = 0;
42
+
43
+ function passArray8ToWasm0(arg, malloc) {
44
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
45
+ getUint8ArrayMemory0().set(arg, ptr / 1);
46
+ WASM_VECTOR_LEN = arg.length;
47
+ return ptr;
48
+ }
49
+
50
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
51
+
52
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
53
+ ? function (arg, view) {
54
+ return cachedTextEncoder.encodeInto(arg, view);
55
+ }
56
+ : function (arg, view) {
57
+ const buf = cachedTextEncoder.encode(arg);
58
+ view.set(buf);
59
+ return {
60
+ read: arg.length,
61
+ written: buf.length
62
+ };
63
+ });
64
+
65
+ function passStringToWasm0(arg, malloc, realloc) {
66
+
67
+ if (realloc === undefined) {
68
+ const buf = cachedTextEncoder.encode(arg);
69
+ const ptr = malloc(buf.length, 1) >>> 0;
70
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
71
+ WASM_VECTOR_LEN = buf.length;
72
+ return ptr;
73
+ }
74
+
75
+ let len = arg.length;
76
+ let ptr = malloc(len, 1) >>> 0;
77
+
78
+ const mem = getUint8ArrayMemory0();
79
+
80
+ let offset = 0;
81
+
82
+ for (; offset < len; offset++) {
83
+ const code = arg.charCodeAt(offset);
84
+ if (code > 0x7F) break;
85
+ mem[ptr + offset] = code;
86
+ }
87
+
88
+ if (offset !== len) {
89
+ if (offset !== 0) {
90
+ arg = arg.slice(offset);
91
+ }
92
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
93
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
94
+ const ret = encodeString(arg, view);
95
+
96
+ offset += ret.written;
97
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
98
+ }
99
+
100
+ WASM_VECTOR_LEN = offset;
101
+ return ptr;
102
+ }
103
+
104
+ function getObject(idx) { return heap[idx]; }
105
+
106
+ function dropObject(idx) {
107
+ if (idx < 132) return;
108
+ heap[idx] = heap_next;
109
+ heap_next = idx;
110
+ }
111
+
112
+ function takeObject(idx) {
113
+ const ret = getObject(idx);
114
+ dropObject(idx);
115
+ return ret;
116
+ }
117
+ /**
118
+ * @param {Uint8Array} data
119
+ * @param {number} input_width
120
+ * @param {number} input_height
121
+ * @param {number} output_width
122
+ * @param {number} output_height
123
+ * @param {string} version
124
+ * @returns {ImageData}
125
+ */
126
+ export function resize(data, input_width, input_height, output_width, output_height, version) {
127
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
128
+ const len0 = WASM_VECTOR_LEN;
129
+ const ptr1 = passStringToWasm0(version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
130
+ const len1 = WASM_VECTOR_LEN;
131
+ const ret = wasm.resize(ptr0, len0, input_width, input_height, output_width, output_height, ptr1, len1);
132
+ return takeObject(ret);
133
+ }
134
+
135
+ async function __wbg_load(module, imports) {
136
+ if (typeof Response === 'function' && module instanceof Response) {
137
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
138
+ try {
139
+ return await WebAssembly.instantiateStreaming(module, imports);
140
+
141
+ } catch (e) {
142
+ if (module.headers.get('Content-Type') != 'application/wasm') {
143
+ 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);
144
+
145
+ } else {
146
+ throw e;
147
+ }
148
+ }
149
+ }
150
+
151
+ const bytes = await module.arrayBuffer();
152
+ return await WebAssembly.instantiate(bytes, imports);
153
+
154
+ } else {
155
+ const instance = await WebAssembly.instantiate(module, imports);
156
+
157
+ if (instance instanceof WebAssembly.Instance) {
158
+ return { instance, module };
159
+
160
+ } else {
161
+ return instance;
162
+ }
163
+ }
164
+ }
165
+
166
+ function __wbg_get_imports() {
167
+ const imports = {};
168
+ imports.wbg = {};
169
+ imports.wbg.__wbg_newwithownedu8clampedarrayandsh_2ac355435db12a85 = function(arg0, arg1, arg2, arg3) {
170
+ var v0 = getClampedArrayU8FromWasm0(arg0, arg1).slice();
171
+ wasm.__wbindgen_free(arg0, arg1 * 1, 1);
172
+ const ret = new ImageData(v0, arg2 >>> 0, arg3 >>> 0);
173
+ return addHeapObject(ret);
174
+ };
175
+
176
+ return imports;
177
+ }
178
+
179
+ function __wbg_init_memory(imports, memory) {
180
+
181
+ }
182
+
183
+ function __wbg_finalize_init(instance, module) {
184
+ wasm = instance.exports;
185
+ __wbg_init.__wbindgen_wasm_module = module;
186
+ cachedUint8ArrayMemory0 = null;
187
+ cachedUint8ClampedArrayMemory0 = null;
188
+
189
+
190
+
191
+ return wasm;
192
+ }
193
+
194
+ function initSync(module) {
195
+ if (wasm !== undefined) return wasm;
196
+
197
+
198
+ if (typeof module !== 'undefined') {
199
+ if (Object.getPrototypeOf(module) === Object.prototype) {
200
+ ({module} = module)
201
+ } else {
202
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
203
+ }
204
+ }
205
+
206
+ const imports = __wbg_get_imports();
207
+
208
+ __wbg_init_memory(imports);
209
+
210
+ if (!(module instanceof WebAssembly.Module)) {
211
+ module = new WebAssembly.Module(module);
212
+ }
213
+
214
+ const instance = new WebAssembly.Instance(module, imports);
215
+
216
+ return __wbg_finalize_init(instance, module);
217
+ }
218
+
219
+ async function __wbg_init(module_or_path) {
220
+ if (wasm !== undefined) return wasm;
221
+
222
+
223
+ if (typeof module_or_path !== 'undefined') {
224
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
225
+ ({module_or_path} = module_or_path)
226
+ } else {
227
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
228
+ }
229
+ }
230
+
231
+ if (typeof module_or_path === 'undefined') {
232
+ module_or_path = new URL('jsquash_magic_kernel_bg.wasm', import.meta.url);
233
+ }
234
+ const imports = __wbg_get_imports();
235
+
236
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
237
+ module_or_path = fetch(module_or_path);
238
+ }
239
+
240
+ __wbg_init_memory(imports);
241
+
242
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
243
+
244
+ return __wbg_finalize_init(instance, module);
245
+ }
246
+
247
+ export { initSync };
248
+ export default __wbg_init;
@@ -0,0 +1,7 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export function resize(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number;
5
+ export function __wbindgen_free(a: number, b: number, c: number): void;
6
+ export function __wbindgen_malloc(a: number, b: number): number;
7
+ export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
@@ -0,0 +1,5 @@
1
+ # Resize
2
+
3
+ - Source: <https://github.com/PistonDevelopers/resize>
4
+ - Version: v0.3.0
5
+ - License: MIT
@@ -19,10 +19,21 @@ export interface InitOutput {
19
19
  readonly memory: WebAssembly.Memory;
20
20
  readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
21
21
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
22
- readonly __wbindgen_malloc: (a: number) => number;
23
- readonly __wbindgen_free: (a: number, b: number) => void;
22
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
23
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
24
24
  }
25
25
 
26
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
27
+ /**
28
+ * Instantiates the given `module`, which can either be bytes or
29
+ * a precompiled `WebAssembly.Module`.
30
+ *
31
+ * @param {SyncInitInput} module
32
+ *
33
+ * @returns {InitOutput}
34
+ */
35
+ export function initSync(module: SyncInitInput): InitOutput;
36
+
26
37
  /**
27
38
  * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
28
39
  * for everything else, calls `WebAssembly.instantiate` directly.
@@ -31,4 +42,4 @@ export interface InitOutput {
31
42
  *
32
43
  * @returns {Promise<InitOutput>}
33
44
  */
34
- export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
45
+ export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -1,40 +1,43 @@
1
-
2
1
  let wasm;
3
2
 
4
- let cachegetUint8Memory0 = null;
3
+ let cachedUint8Memory0 = null;
4
+
5
5
  function getUint8Memory0() {
6
- if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
7
- cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
6
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
7
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
8
8
  }
9
- return cachegetUint8Memory0;
9
+ return cachedUint8Memory0;
10
10
  }
11
11
 
12
12
  let WASM_VECTOR_LEN = 0;
13
13
 
14
14
  function passArray8ToWasm0(arg, malloc) {
15
- const ptr = malloc(arg.length * 1);
15
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
16
16
  getUint8Memory0().set(arg, ptr / 1);
17
17
  WASM_VECTOR_LEN = arg.length;
18
18
  return ptr;
19
19
  }
20
20
 
21
- let cachegetInt32Memory0 = null;
21
+ let cachedInt32Memory0 = null;
22
+
22
23
  function getInt32Memory0() {
23
- if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
24
- cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
24
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
25
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
25
26
  }
26
- return cachegetInt32Memory0;
27
+ return cachedInt32Memory0;
27
28
  }
28
29
 
29
- let cachegetUint8ClampedMemory0 = null;
30
+ let cachedUint8ClampedMemory0 = null;
31
+
30
32
  function getUint8ClampedMemory0() {
31
- if (cachegetUint8ClampedMemory0 === null || cachegetUint8ClampedMemory0.buffer !== wasm.memory.buffer) {
32
- cachegetUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
33
+ if (cachedUint8ClampedMemory0 === null || cachedUint8ClampedMemory0.byteLength === 0) {
34
+ cachedUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
33
35
  }
34
- return cachegetUint8ClampedMemory0;
36
+ return cachedUint8ClampedMemory0;
35
37
  }
36
38
 
37
39
  function getClampedArrayU8FromWasm0(ptr, len) {
40
+ ptr = ptr >>> 0;
38
41
  return getUint8ClampedMemory0().subarray(ptr / 1, ptr / 1 + len);
39
42
  }
40
43
  /**
@@ -51,20 +54,20 @@ function getClampedArrayU8FromWasm0(ptr, len) {
51
54
  export function resize(input_image, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion) {
52
55
  try {
53
56
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
54
- var ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc);
55
- var len0 = WASM_VECTOR_LEN;
57
+ const ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc);
58
+ const len0 = WASM_VECTOR_LEN;
56
59
  wasm.resize(retptr, ptr0, len0, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion);
57
60
  var r0 = getInt32Memory0()[retptr / 4 + 0];
58
61
  var r1 = getInt32Memory0()[retptr / 4 + 1];
59
- var v1 = getClampedArrayU8FromWasm0(r0, r1).slice();
60
- wasm.__wbindgen_free(r0, r1 * 1);
61
- return v1;
62
+ var v2 = getClampedArrayU8FromWasm0(r0, r1).slice();
63
+ wasm.__wbindgen_free(r0, r1 * 1, 1);
64
+ return v2;
62
65
  } finally {
63
66
  wasm.__wbindgen_add_to_stack_pointer(16);
64
67
  }
65
68
  }
66
69
 
67
- async function load(module, imports) {
70
+ async function __wbg_load(module, imports) {
68
71
  if (typeof Response === 'function' && module instanceof Response) {
69
72
  if (typeof WebAssembly.instantiateStreaming === 'function') {
70
73
  try {
@@ -95,29 +98,65 @@ async function load(module, imports) {
95
98
  }
96
99
  }
97
100
 
98
- async function init(input) {
101
+ function __wbg_get_imports() {
102
+ const imports = {};
103
+ imports.wbg = {};
104
+
105
+ return imports;
106
+ }
107
+
108
+ function __wbg_init_memory(imports, maybe_memory) {
109
+
110
+ }
111
+
112
+ function __wbg_finalize_init(instance, module) {
113
+ wasm = instance.exports;
114
+ __wbg_init.__wbindgen_wasm_module = module;
115
+ cachedInt32Memory0 = null;
116
+ cachedUint8Memory0 = null;
117
+ cachedUint8ClampedMemory0 = null;
118
+
119
+
120
+ return wasm;
121
+ }
122
+
123
+ function initSync(module) {
124
+ if (wasm !== undefined) return wasm;
125
+
126
+ const imports = __wbg_get_imports();
127
+
128
+ __wbg_init_memory(imports);
129
+
130
+ if (!(module instanceof WebAssembly.Module)) {
131
+ module = new WebAssembly.Module(module);
132
+ }
133
+
134
+ const instance = new WebAssembly.Instance(module, imports);
135
+
136
+ return __wbg_finalize_init(instance, module);
137
+ }
138
+
139
+ async function __wbg_init(input) {
140
+ if (wasm !== undefined) return wasm;
141
+
99
142
  if (typeof input === 'undefined') {
100
143
  input = new URL('squoosh_resize_bg.wasm', import.meta.url);
101
144
  }
102
- const imports = {};
103
-
145
+ const imports = __wbg_get_imports();
104
146
 
105
147
  if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
106
148
  input = fetch(input);
107
149
  }
108
150
 
151
+ __wbg_init_memory(imports);
109
152
 
153
+ const { instance, module } = await __wbg_load(await input, imports);
110
154
 
111
- const { instance, module } = await load(await input, imports);
112
-
113
- wasm = instance.exports;
114
- init.__wbindgen_wasm_module = module;
115
-
116
- return wasm;
155
+ return __wbg_finalize_init(instance, module);
117
156
  }
118
157
 
119
- export default init;
120
-
158
+ export { initSync }
159
+ export default __wbg_init;
121
160
  const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
122
161
  const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
123
162
  const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
@@ -3,5 +3,5 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export function resize(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
5
5
  export function __wbindgen_add_to_stack_pointer(a: number): number;
6
- export function __wbindgen_malloc(a: number): number;
7
- export function __wbindgen_free(a: number, b: number): void;
6
+ export function __wbindgen_malloc(a: number, b: number): number;
7
+ export function __wbindgen_free(a: number, b: number, c: number): void;
package/meta.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * See the License for the specific language governing permissions and
11
11
  * limitations under the License.
12
12
  */
13
- type WorkerResizeMethods = 'triangle' | 'catrom' | 'mitchell' | 'lanczos3' | 'hqx';
13
+ type WorkerResizeMethods = 'triangle' | 'catrom' | 'mitchell' | 'lanczos3' | 'hqx' | 'magicKernel' | 'magicKernelSharp2013' | 'magicKernelSharp2021';
14
14
  export declare const workerResizeMethods: WorkerResizeMethods[];
15
15
  export type Options = WorkerResizeOptions | VectorResizeOptions;
16
16
  export interface ResizeOptionsCommon {
package/meta.js CHANGED
@@ -16,6 +16,9 @@ export const workerResizeMethods = [
16
16
  'mitchell',
17
17
  'lanczos3',
18
18
  'hqx',
19
+ 'magicKernel',
20
+ 'magicKernelSharp2013',
21
+ 'magicKernelSharp2021',
19
22
  ];
20
23
  export const defaultOptions = {
21
24
  // Width and height will always default to the image size.
package/package.json CHANGED
@@ -1,33 +1,34 @@
1
1
  {
2
- "name": "@jsquash/resize",
3
- "version": "1.1.1",
4
- "main": "index.js",
5
- "description": "Wasm image resize methods supporting the browser and V8 environments. Repackaged from Squoosh App.",
6
- "repository": "jamsinclair/jSquash/packages/resize",
7
- "author": {
8
- "name": "Jamie Sinclair",
9
- "email": "jamsinclairnz+npm@gmail.com"
10
- },
11
- "keywords": [
12
- "image",
13
- "resize",
14
- "hqx",
15
- "squoosh",
16
- "wasm",
17
- "webassembly",
18
- "lanczos3",
19
- "crop"
20
- ],
21
- "license": "Apache-2.0",
22
- "scripts": {
23
- "clean": "rm -rf dist",
24
- "build": "npm run clean && tsc && cp -r lib package.json README.md .npmignore ../../LICENSE dist",
25
- "prepublishOnly": "[[ \"$PWD\" == *'/dist' ]] && exit 0 || (echo 'Please run npm publish from the dist directory' && exit 1)"
26
- },
27
- "devDependencies": {
28
- "typescript": "^4.4.4"
29
- },
30
- "type": "module",
31
- "sideEffects": false
32
- }
33
-
2
+ "name": "@jsquash/resize",
3
+ "version": "2.1.0",
4
+ "main": "index.js",
5
+ "description": "Wasm image resize methods supporting the browser and V8 environments. Repackaged from Squoosh App.",
6
+ "repository": "jamsinclair/jSquash/packages/resize",
7
+ "author": {
8
+ "name": "Jamie Sinclair",
9
+ "email": "jamsinclairnz+npm@gmail.com"
10
+ },
11
+ "keywords": [
12
+ "image",
13
+ "resize",
14
+ "hqx",
15
+ "squoosh",
16
+ "wasm",
17
+ "webassembly",
18
+ "lanczos3",
19
+ "crop",
20
+ "magic-kernel",
21
+ "magic kernel"
22
+ ],
23
+ "license": "Apache-2.0",
24
+ "scripts": {
25
+ "clean": "rm -rf dist",
26
+ "build": "npm run clean && tsc && cp -r lib package.json README.md .npmignore ../../LICENSE dist && (rm dist/lib/*/pkg/package.json dist/lib/*/pkg/.gitignore || true)",
27
+ "prepublishOnly": "[[ \"$PWD\" == *'/dist' ]] && exit 0 || (echo 'Please run npm publish from the dist directory' && exit 1)"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "^4.4.4"
31
+ },
32
+ "type": "module",
33
+ "sideEffects": false
34
+ }
@@ -1,16 +0,0 @@
1
- {
2
- "name": "squooshhqx",
3
- "collaborators": [
4
- "Surma <surma@surma.link>"
5
- ],
6
- "version": "0.1.0",
7
- "files": [
8
- "squooshhqx_bg.wasm",
9
- "squooshhqx.js",
10
- "squooshhqx.d.ts"
11
- ],
12
- "module": "squooshhqx.js",
13
- "types": "squooshhqx.d.ts",
14
- "sideEffects": false,
15
- "type": "module"
16
- }
package/lib/hqx/pre.js DELETED
@@ -1,24 +0,0 @@
1
- const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
2
- const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
3
- const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
4
-
5
- if (isRunningInCloudFlareWorkers || isRunningInNode) {
6
- if (!globalThis.ImageData) {
7
- // Simple Polyfill for ImageData Object
8
- globalThis.ImageData = class ImageData {
9
- constructor(data, width, height) {
10
- this.data = data;
11
- this.width = width;
12
- this.height = height;
13
- }
14
- };
15
- }
16
-
17
- if (import.meta.url === undefined) {
18
- import.meta.url = 'https://localhost';
19
- }
20
-
21
- if (typeof self !== 'undefined' && self.location === undefined) {
22
- self.location = { href: '' };
23
- }
24
- }
Binary file
@@ -1,16 +0,0 @@
1
- {
2
- "name": "squoosh-resize",
3
- "collaborators": [
4
- "Surma <surma@surma.link>"
5
- ],
6
- "version": "0.1.0",
7
- "files": [
8
- "squoosh_resize_bg.wasm",
9
- "squoosh_resize.js",
10
- "squoosh_resize.d.ts"
11
- ],
12
- "module": "squoosh_resize.js",
13
- "types": "squoosh_resize.d.ts",
14
- "sideEffects": false,
15
- "type": "module"
16
- }
package/lib/resize/pre.js DELETED
@@ -1,24 +0,0 @@
1
- const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
2
- const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
3
- const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
4
-
5
- if (isRunningInCloudFlareWorkers || isRunningInNode) {
6
- if (!globalThis.ImageData) {
7
- // Simple Polyfill for ImageData Object
8
- globalThis.ImageData = class ImageData {
9
- constructor(data, width, height) {
10
- this.data = data;
11
- this.width = width;
12
- this.height = height;
13
- }
14
- };
15
- }
16
-
17
- if (import.meta.url === undefined) {
18
- import.meta.url = 'https://localhost';
19
- }
20
-
21
- if (typeof self !== 'undefined' && self.location === undefined) {
22
- self.location = { href: '' };
23
- }
24
- }
Binary file