compress-jpeg 1.0.6 → 1.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/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
- Copyright © 2025 Ganemede Labs
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright © 2025 Ganemede Labs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,121 +1,82 @@
1
- # Compress JPEG
2
-
3
- ![npm](https://img.shields.io/npm/v/compress-jpeg)
4
- ![npm](https://img.shields.io/npm/dw/compress-jpeg)
5
- ![License](https://img.shields.io/npm/l/compress-jpeg)
6
-
7
- A high-performance **WASM** module that simulates JPEG compression artifacts on raw image data, designed to be used easily in JavaScript or TypeScript environments via an npm package.
8
-
9
- ## 📋 Table of Contents
10
-
11
- - [Features](#-features)
12
- - [Installation](#-installation)
13
- - [Usage](#-usage)
14
- - [License](#-license)
15
- - [Contact](#-contact)
16
-
17
- ## Features
18
-
19
- - **Fast** and **portable** through WebAssembly.
20
- - Supports customizable **compression quality**.
21
- - Accepts and returns raw **RGBA pixel data**.
22
- - Pure Rust core with zero dependencies beyond `wasm-bindgen`.
23
-
24
- ## 🔧 Installation
25
-
26
- Install the package via npm:
27
-
28
- ```bash
29
- npm install compress-jpeg
30
- ```
31
-
32
- ## 🚀 Usage
33
-
34
- Here's an example of how to integrate **compress-jpeg** with plain TypeScript in the browser. This snippet shows:
35
-
36
- 1. Loading an image file via an HTML `<input>`.
37
- 2. Drawing it to an off-screen canvas and extracting pixel data.
38
- 3. Passing the data to the WASM function.
39
- 4. Rendering the compressed output back onto a visible canvas.
40
-
41
- ```html
42
- <!-- index.html -->
43
- <!DOCTYPE html>
44
- <html lang="en">
45
- <head>
46
- <meta charset="UTF-8" />
47
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
48
- <title>WASM JPEG Simulator Demo</title>
49
- </head>
50
- <body>
51
- <!-- File input and canvases -->
52
- <input id="fileInput" type="file" accept="image/*" />
53
- <canvas id="originalCanvas" style="display:none;"></canvas>
54
- <canvas id="processedCanvas"></canvas>
55
-
56
- <script type="module" src="main.ts"></script>
57
- </body>
58
- </html>
59
- ```
60
-
61
- ```typescript
62
- // main.ts
63
- import init, { ImageData as RustImageData, compress_jpeg } from "compress-jpeg";
64
-
65
- const fileInput = document.getElementById("fileInput") as HTMLInputElement;
66
- const originalCanvas = document.getElementById("originalCanvas") as HTMLCanvasElement;
67
- const processedCanvas = document.getElementById("processedCanvas") as HTMLCanvasElement;
68
-
69
- fileInput.addEventListener("change", async () => {
70
- const file = fileInput.files?.[0];
71
- if (!file) return;
72
-
73
- // Initialize the WASM module
74
- await init();
75
-
76
- // Load image into an off-screen canvas
77
- const img = new Image();
78
- const reader = new FileReader();
79
- reader.onload = () => {
80
- img.src = reader.result as string;
81
- };
82
- reader.readAsDataURL(file);
83
-
84
- img.onload = () => {
85
- originalCanvas.width = img.width;
86
- originalCanvas.height = img.height;
87
- const ctx = originalCanvas.getContext("2d")!;
88
- ctx.drawImage(img, 0, 0);
89
-
90
- // Extract raw pixel data
91
- const browserImageData = ctx.getImageData(0, 0, img.width, img.height);
92
- const input = new RustImageData(
93
- new Uint8ClampedArray(browserImageData.data),
94
- browserImageData.width,
95
- browserImageData.height
96
- );
97
-
98
- // Simulate JPEG compression at quality=30
99
- const output = compress_jpeg(input, 30);
100
-
101
- // Convert back to browser ImageData
102
- const processedData = new ImageData(new Uint8ClampedArray(output.data()), output.width(), output.height());
103
-
104
- // Draw on visible canvas
105
- processedCanvas.width = output.width();
106
- processedCanvas.height = output.height();
107
- processedCanvas.getContext("2d")!.putImageData(processedData, 0, 0);
108
-
109
- // Free the WebAssembly memory
110
- output.free();
111
- };
112
- });
113
- ```
114
-
115
- ## 📜 License
116
-
117
- This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
118
-
119
- ## 📧 Contact
120
-
121
- For inquiries or more information, you can reach out to us at [ganemedelabs@gmail.com](mailto:ganemedelabs@gmail.com).
1
+ # Compress JPEG
2
+
3
+ ![Version](https://img.shields.io/npm/v/compress-jpeg)
4
+ ![Downloads](https://img.shields.io/npm/dw/compress-jpeg)
5
+ ![License](https://img.shields.io/npm/l/compress-jpeg)
6
+
7
+ A lightweight WebAssembly-powered JPEG-like compressor written in Rust, exposed as an easy-to-use JavaScript API. This package performs a simplified JPEG pipeline entirely in WASM, including:
8
+
9
+ - RGB YCbCr conversion
10
+ - 4:2:0 chroma subsampling
11
+ - 8×8 DCT + quantization
12
+ - Inverse DCT
13
+ - Reconstruction to RGBA
14
+
15
+ The output is not a `.jpg` file, but a visually compressed `ImageData` that simulates JPEG compression artifacts—including blockiness, color loss, and ringing—directly in the browser.
16
+
17
+ ## 📋 Table of Contents
18
+
19
+ - [Features](#-features)
20
+ - [Installation](#-installation)
21
+ - [Usage](#-usage)
22
+ - [License](#-license)
23
+ - [Contact](#-contact)
24
+
25
+ ## ✨ Features
26
+
27
+ - Fast WebAssembly image compression (Rust + wasm-bindgen)
28
+ - Fully controllable compression strength (`0.0 → 1.0`)
29
+ - Implements a full JPEG-style DCT/IDCT pipeline
30
+ - Produces visible JPEG artifacts at higher compression levels
31
+ - Works directly with Canvas `ImageData`
32
+ - Zero dependencies — tiny package size
33
+ - Browser-friendly and easy to use
34
+ - Simple API: `compress_jpeg(imageData: ImageData, compression: number): ImageData`
35
+
36
+ ## 🔧 Installation
37
+
38
+ ```bash
39
+ npm install compress-jpeg
40
+ # or
41
+ yarn add compress-jpeg
42
+ ```
43
+
44
+ ## 🚀 Usage
45
+
46
+ ```typescript
47
+ import init, { compress_jpeg } from "compress-jpeg";
48
+
49
+ async function run() {
50
+ await init(); // initialize WASM module
51
+
52
+ const canvas = document.getElementById("my-canvas") as HTMLCanvasElement;
53
+ const ctx = canvas.getContext("2d")!;
54
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
55
+
56
+ /**
57
+ * Compression strength (0.0 → 1.0)
58
+ *
59
+ * - 0.0 = no compression (highest quality)
60
+ * - 1.0 = strongest compression (lowest quality, heavy artifacts)
61
+ *
62
+ * Recommended ranges:
63
+ * - 0.7–1.0 strong blockiness / heavy JPEG artifacts
64
+ * - 0.3–0.7 → medium compression
65
+ * - 0.0–0.3 light compression / near-lossless
66
+ */
67
+ const compression = 0.4;
68
+
69
+ const output = compress_jpeg(imageData, compression);
70
+
71
+ // Draw result onto canvas
72
+ ctx.putImageData(output, 0, 0);
73
+ }
74
+ ```
75
+
76
+ ## 📜 License
77
+
78
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
79
+
80
+ ## 📧 Contact
81
+
82
+ For inquiries or more information, you can reach out to us at [ganemedelabs@gmail.com](mailto:ganemedelabs@gmail.com).
@@ -1,34 +1,35 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- export function compress_jpeg(image_data: ImageData, quality: number): Promise<ImageData>;
4
- export class ImageData {
5
- free(): void;
6
- constructor(data: Uint8ClampedArray, width: number, height: number);
7
- width(): number;
8
- height(): number;
9
- data(): Uint8ClampedArray;
10
- }
3
+
4
+ /**
5
+ * Compress an ImageData using a simplified JPEG-style pipeline.
6
+ *
7
+ * **Parameters:**
8
+ * - `image_data`: The RGBA ImageData to compress.
9
+ * - `compression`: A value from 0.0–1.0:
10
+ * - 0.0 = no compression (highest quality)
11
+ * - 1.0 = strongest compression (lowest quality)
12
+ *
13
+ * **Returns:**
14
+ * A new `ImageData` object containing the visually compressed pixels.
15
+ */
16
+ export function compress_jpeg(image_data: ImageData, compression: number): ImageData;
11
17
 
12
18
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
13
19
 
14
20
  export interface InitOutput {
15
21
  readonly memory: WebAssembly.Memory;
16
- readonly __wbg_imagedata_free: (a: number, b: number) => void;
17
- readonly imagedata_new: (a: any, b: number, c: number) => number;
18
- readonly imagedata_width: (a: number) => number;
19
- readonly imagedata_height: (a: number) => number;
20
- readonly imagedata_data: (a: number) => any;
21
- readonly compress_jpeg: (a: number, b: number) => any;
22
+ readonly compress_jpeg: (a: any, b: number) => [number, number, number];
23
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
22
24
  readonly __wbindgen_exn_store: (a: number) => void;
23
25
  readonly __externref_table_alloc: () => number;
24
- readonly __wbindgen_export_2: WebAssembly.Table;
25
- readonly __wbindgen_export_3: WebAssembly.Table;
26
- readonly closure6_externref_shim: (a: number, b: number, c: any) => void;
27
- readonly closure23_externref_shim: (a: number, b: number, c: any, d: any) => void;
26
+ readonly __wbindgen_externrefs: WebAssembly.Table;
27
+ readonly __externref_table_dealloc: (a: number) => void;
28
28
  readonly __wbindgen_start: () => void;
29
29
  }
30
30
 
31
31
  export type SyncInitInput = BufferSource | WebAssembly.Module;
32
+
32
33
  /**
33
34
  * Instantiates the given `module`, which can either be bytes or
34
35
  * a precompiled `WebAssembly.Module`.
package/compress_jpeg.js CHANGED
@@ -2,25 +2,29 @@ let wasm;
2
2
 
3
3
  function addToExternrefTable0(obj) {
4
4
  const idx = wasm.__externref_table_alloc();
5
- wasm.__wbindgen_export_2.set(idx, obj);
5
+ wasm.__wbindgen_externrefs.set(idx, obj);
6
6
  return idx;
7
7
  }
8
8
 
9
- function handleError(f, args) {
10
- try {
11
- return f.apply(this, args);
12
- } catch (e) {
13
- const idx = addToExternrefTable0(e);
14
- wasm.__wbindgen_exn_store(idx);
15
- }
9
+ function getClampedArrayU8FromWasm0(ptr, len) {
10
+ ptr = ptr >>> 0;
11
+ return getUint8ClampedArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
16
12
  }
17
13
 
18
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
14
+ let cachedDataViewMemory0 = null;
15
+ function getDataViewMemory0() {
16
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
17
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
18
+ }
19
+ return cachedDataViewMemory0;
20
+ }
19
21
 
20
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
22
+ function getStringFromWasm0(ptr, len) {
23
+ ptr = ptr >>> 0;
24
+ return decodeText(ptr, len);
25
+ }
21
26
 
22
27
  let cachedUint8ArrayMemory0 = null;
23
-
24
28
  function getUint8ArrayMemory0() {
25
29
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
26
30
  cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
@@ -28,138 +32,86 @@ function getUint8ArrayMemory0() {
28
32
  return cachedUint8ArrayMemory0;
29
33
  }
30
34
 
31
- function getStringFromWasm0(ptr, len) {
32
- ptr = ptr >>> 0;
33
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
34
- }
35
-
36
- function isLikeNone(x) {
37
- return x === undefined || x === null;
38
- }
39
-
40
- const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
41
- ? { register: () => {}, unregister: () => {} }
42
- : new FinalizationRegistry(state => {
43
- wasm.__wbindgen_export_3.get(state.dtor)(state.a, state.b)
44
- });
45
-
46
- function makeMutClosure(arg0, arg1, dtor, f) {
47
- const state = { a: arg0, b: arg1, cnt: 1, dtor };
48
- const real = (...args) => {
49
- // First up with a closure we increment the internal reference
50
- // count. This ensures that the Rust closure environment won't
51
- // be deallocated while we're invoking it.
52
- state.cnt++;
53
- const a = state.a;
54
- state.a = 0;
55
- try {
56
- return f(a, state.b, ...args);
57
- } finally {
58
- if (--state.cnt === 0) {
59
- wasm.__wbindgen_export_3.get(state.dtor)(a, state.b);
60
- CLOSURE_DTORS.unregister(state);
61
- } else {
62
- state.a = a;
63
- }
64
- }
65
- };
66
- real.original = state;
67
- CLOSURE_DTORS.register(real, state, state);
68
- return real;
35
+ let cachedUint8ClampedArrayMemory0 = null;
36
+ function getUint8ClampedArrayMemory0() {
37
+ if (cachedUint8ClampedArrayMemory0 === null || cachedUint8ClampedArrayMemory0.byteLength === 0) {
38
+ cachedUint8ClampedArrayMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
39
+ }
40
+ return cachedUint8ClampedArrayMemory0;
69
41
  }
70
42
 
71
- function _assertClass(instance, klass) {
72
- if (!(instance instanceof klass)) {
73
- throw new Error(`expected instance of ${klass.name}`);
43
+ function handleError(f, args) {
44
+ try {
45
+ return f.apply(this, args);
46
+ } catch (e) {
47
+ const idx = addToExternrefTable0(e);
48
+ wasm.__wbindgen_exn_store(idx);
74
49
  }
75
50
  }
76
- /**
77
- * @param {ImageData} image_data
78
- * @param {number} quality
79
- * @returns {Promise<ImageData>}
80
- */
81
- export function compress_jpeg(image_data, quality) {
82
- _assertClass(image_data, ImageData);
83
- var ptr0 = image_data.__destroy_into_raw();
84
- const ret = wasm.compress_jpeg(ptr0, quality);
85
- return ret;
86
- }
87
51
 
88
- function __wbg_adapter_18(arg0, arg1, arg2) {
89
- wasm.closure6_externref_shim(arg0, arg1, arg2);
52
+ function passArray8ToWasm0(arg, malloc) {
53
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
54
+ getUint8ArrayMemory0().set(arg, ptr / 1);
55
+ WASM_VECTOR_LEN = arg.length;
56
+ return ptr;
90
57
  }
91
58
 
92
- function __wbg_adapter_36(arg0, arg1, arg2, arg3) {
93
- wasm.closure23_externref_shim(arg0, arg1, arg2, arg3);
59
+ function takeFromExternrefTable0(idx) {
60
+ const value = wasm.__wbindgen_externrefs.get(idx);
61
+ wasm.__externref_table_dealloc(idx);
62
+ return value;
94
63
  }
95
64
 
96
- const ImageDataFinalization = (typeof FinalizationRegistry === 'undefined')
97
- ? { register: () => {}, unregister: () => {} }
98
- : new FinalizationRegistry(ptr => wasm.__wbg_imagedata_free(ptr >>> 0, 1));
99
-
100
- export class ImageData {
101
-
102
- static __wrap(ptr) {
103
- ptr = ptr >>> 0;
104
- const obj = Object.create(ImageData.prototype);
105
- obj.__wbg_ptr = ptr;
106
- ImageDataFinalization.register(obj, obj.__wbg_ptr, obj);
107
- return obj;
65
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
66
+ cachedTextDecoder.decode();
67
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
68
+ let numBytesDecoded = 0;
69
+ function decodeText(ptr, len) {
70
+ numBytesDecoded += len;
71
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
72
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
73
+ cachedTextDecoder.decode();
74
+ numBytesDecoded = len;
108
75
  }
76
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
77
+ }
109
78
 
110
- __destroy_into_raw() {
111
- const ptr = this.__wbg_ptr;
112
- this.__wbg_ptr = 0;
113
- ImageDataFinalization.unregister(this);
114
- return ptr;
115
- }
79
+ let WASM_VECTOR_LEN = 0;
116
80
 
117
- free() {
118
- const ptr = this.__destroy_into_raw();
119
- wasm.__wbg_imagedata_free(ptr, 0);
120
- }
121
- /**
122
- * @param {Uint8ClampedArray} data
123
- * @param {number} width
124
- * @param {number} height
125
- */
126
- constructor(data, width, height) {
127
- const ret = wasm.imagedata_new(data, width, height);
128
- this.__wbg_ptr = ret >>> 0;
129
- ImageDataFinalization.register(this, this.__wbg_ptr, this);
130
- return this;
131
- }
132
- /**
133
- * @returns {number}
134
- */
135
- width() {
136
- const ret = wasm.imagedata_width(this.__wbg_ptr);
137
- return ret >>> 0;
138
- }
139
- /**
140
- * @returns {number}
141
- */
142
- height() {
143
- const ret = wasm.imagedata_height(this.__wbg_ptr);
144
- return ret >>> 0;
145
- }
146
- /**
147
- * @returns {Uint8ClampedArray}
148
- */
149
- data() {
150
- const ret = wasm.imagedata_data(this.__wbg_ptr);
151
- return ret;
81
+ /**
82
+ * Compress an ImageData using a simplified JPEG-style pipeline.
83
+ *
84
+ * **Parameters:**
85
+ * - `image_data`: The RGBA ImageData to compress.
86
+ * - `compression`: A value from 0.0–1.0:
87
+ * - 0.0 = no compression (highest quality)
88
+ * - 1.0 = strongest compression (lowest quality)
89
+ *
90
+ * **Returns:**
91
+ * A new `ImageData` object containing the visually compressed pixels.
92
+ * @param {ImageData} image_data
93
+ * @param {number} compression
94
+ * @returns {ImageData}
95
+ */
96
+ export function compress_jpeg(image_data, compression) {
97
+ const ret = wasm.compress_jpeg(image_data, compression);
98
+ if (ret[2]) {
99
+ throw takeFromExternrefTable0(ret[1]);
152
100
  }
101
+ return takeFromExternrefTable0(ret[0]);
153
102
  }
154
103
 
104
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
105
+
155
106
  async function __wbg_load(module, imports) {
156
107
  if (typeof Response === 'function' && module instanceof Response) {
157
108
  if (typeof WebAssembly.instantiateStreaming === 'function') {
158
109
  try {
159
110
  return await WebAssembly.instantiateStreaming(module, imports);
160
-
161
111
  } catch (e) {
162
- if (module.headers.get('Content-Type') != 'application/wasm') {
112
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
113
+
114
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
163
115
  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);
164
116
 
165
117
  } else {
@@ -170,13 +122,11 @@ async function __wbg_load(module, imports) {
170
122
 
171
123
  const bytes = await module.arrayBuffer();
172
124
  return await WebAssembly.instantiate(bytes, imports);
173
-
174
125
  } else {
175
126
  const instance = await WebAssembly.instantiate(module, imports);
176
127
 
177
128
  if (instance instanceof WebAssembly.Instance) {
178
129
  return { instance, module };
179
-
180
130
  } else {
181
131
  return instance;
182
132
  }
@@ -186,140 +136,47 @@ async function __wbg_load(module, imports) {
186
136
  function __wbg_get_imports() {
187
137
  const imports = {};
188
138
  imports.wbg = {};
189
- imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
190
- const ret = arg0.buffer;
191
- return ret;
192
- };
193
- imports.wbg.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) {
194
- const ret = arg0.call(arg1);
195
- return ret;
196
- }, arguments) };
197
- imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
198
- const ret = arg0.call(arg1, arg2);
199
- return ret;
200
- }, arguments) };
201
- imports.wbg.__wbg_imagedata_new = function(arg0) {
202
- const ret = ImageData.__wrap(arg0);
203
- return ret;
204
- };
205
- imports.wbg.__wbg_length_238152a0aedbb6e7 = function(arg0) {
206
- const ret = arg0.length;
207
- return ret;
208
- };
209
- imports.wbg.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
210
- try {
211
- var state0 = {a: arg0, b: arg1};
212
- var cb0 = (arg0, arg1) => {
213
- const a = state0.a;
214
- state0.a = 0;
215
- try {
216
- return __wbg_adapter_36(a, state0.b, arg0, arg1);
217
- } finally {
218
- state0.a = a;
219
- }
220
- };
221
- const ret = new Promise(cb0);
222
- return ret;
223
- } finally {
224
- state0.a = state0.b = 0;
225
- }
226
- };
227
- imports.wbg.__wbg_new_7a91e41fe43b3c92 = function(arg0) {
228
- const ret = new Uint8ClampedArray(arg0);
229
- return ret;
230
- };
231
- imports.wbg.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
232
- const ret = new Function(getStringFromWasm0(arg0, arg1));
233
- return ret;
234
- };
235
- imports.wbg.__wbg_newwithbyteoffsetandlength_6d34787141015158 = function(arg0, arg1, arg2) {
236
- const ret = new Uint8ClampedArray(arg0, arg1 >>> 0, arg2 >>> 0);
237
- return ret;
238
- };
239
- imports.wbg.__wbg_queueMicrotask_97d92b4fcc8a61c5 = function(arg0) {
240
- queueMicrotask(arg0);
241
- };
242
- imports.wbg.__wbg_queueMicrotask_d3219def82552485 = function(arg0) {
243
- const ret = arg0.queueMicrotask;
244
- return ret;
245
- };
246
- imports.wbg.__wbg_resolve_4851785c9c5f573d = function(arg0) {
247
- const ret = Promise.resolve(arg0);
248
- return ret;
249
- };
250
- imports.wbg.__wbg_set_6775f73144c2ef27 = function(arg0, arg1, arg2) {
251
- arg0.set(arg1, arg2 >>> 0);
252
- };
253
- imports.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
254
- const ret = typeof global === 'undefined' ? null : global;
255
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
256
- };
257
- imports.wbg.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
258
- const ret = typeof globalThis === 'undefined' ? null : globalThis;
259
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
260
- };
261
- imports.wbg.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
262
- const ret = typeof self === 'undefined' ? null : self;
263
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
139
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
140
+ throw new Error(getStringFromWasm0(arg0, arg1));
264
141
  };
265
- imports.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
266
- const ret = typeof window === 'undefined' ? null : window;
267
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
142
+ imports.wbg.__wbg_data_83b2a9a09dd4ab39 = function(arg0, arg1) {
143
+ const ret = arg1.data;
144
+ const ptr1 = passArray8ToWasm0(ret, wasm.__wbindgen_malloc);
145
+ const len1 = WASM_VECTOR_LEN;
146
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
147
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
268
148
  };
269
- imports.wbg.__wbg_then_44b73946d2fb3e7d = function(arg0, arg1) {
270
- const ret = arg0.then(arg1);
149
+ imports.wbg.__wbg_height_93d6779af8295699 = function(arg0) {
150
+ const ret = arg0.height;
271
151
  return ret;
272
152
  };
273
- imports.wbg.__wbindgen_cb_drop = function(arg0) {
274
- const obj = arg0.original;
275
- if (obj.cnt-- == 1) {
276
- obj.a = 0;
277
- return true;
278
- }
279
- const ret = false;
153
+ imports.wbg.__wbg_new_with_u8_clamped_array_and_sh_5ac77cce3f6497ff = function() { return handleError(function (arg0, arg1, arg2, arg3) {
154
+ const ret = new ImageData(getClampedArrayU8FromWasm0(arg0, arg1), arg2 >>> 0, arg3 >>> 0);
280
155
  return ret;
281
- };
282
- imports.wbg.__wbindgen_closure_wrapper52 = function(arg0, arg1, arg2) {
283
- const ret = makeMutClosure(arg0, arg1, 7, __wbg_adapter_18);
156
+ }, arguments) };
157
+ imports.wbg.__wbg_width_73a6511a2370c184 = function(arg0) {
158
+ const ret = arg0.width;
284
159
  return ret;
285
160
  };
286
161
  imports.wbg.__wbindgen_init_externref_table = function() {
287
- const table = wasm.__wbindgen_export_2;
162
+ const table = wasm.__wbindgen_externrefs;
288
163
  const offset = table.grow(4);
289
164
  table.set(0, undefined);
290
165
  table.set(offset + 0, undefined);
291
166
  table.set(offset + 1, null);
292
167
  table.set(offset + 2, true);
293
168
  table.set(offset + 3, false);
294
- ;
295
- };
296
- imports.wbg.__wbindgen_is_function = function(arg0) {
297
- const ret = typeof(arg0) === 'function';
298
- return ret;
299
- };
300
- imports.wbg.__wbindgen_is_undefined = function(arg0) {
301
- const ret = arg0 === undefined;
302
- return ret;
303
- };
304
- imports.wbg.__wbindgen_memory = function() {
305
- const ret = wasm.memory;
306
- return ret;
307
- };
308
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
309
- throw new Error(getStringFromWasm0(arg0, arg1));
310
169
  };
311
170
 
312
171
  return imports;
313
172
  }
314
173
 
315
- function __wbg_init_memory(imports, memory) {
316
-
317
- }
318
-
319
174
  function __wbg_finalize_init(instance, module) {
320
175
  wasm = instance.exports;
321
176
  __wbg_init.__wbindgen_wasm_module = module;
177
+ cachedDataViewMemory0 = null;
322
178
  cachedUint8ArrayMemory0 = null;
179
+ cachedUint8ClampedArrayMemory0 = null;
323
180
 
324
181
 
325
182
  wasm.__wbindgen_start();
@@ -339,15 +196,10 @@ function initSync(module) {
339
196
  }
340
197
 
341
198
  const imports = __wbg_get_imports();
342
-
343
- __wbg_init_memory(imports);
344
-
345
199
  if (!(module instanceof WebAssembly.Module)) {
346
200
  module = new WebAssembly.Module(module);
347
201
  }
348
-
349
202
  const instance = new WebAssembly.Instance(module, imports);
350
-
351
203
  return __wbg_finalize_init(instance, module);
352
204
  }
353
205
 
@@ -372,8 +224,6 @@ async function __wbg_init(module_or_path) {
372
224
  module_or_path = fetch(module_or_path);
373
225
  }
374
226
 
375
- __wbg_init_memory(imports);
376
-
377
227
  const { instance, module } = await __wbg_load(await module_or_path, imports);
378
228
 
379
229
  return __wbg_finalize_init(instance, module);
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "compress-jpeg",
3
3
  "type": "module",
4
4
  "description": "A simple JPEG compression library for WebAssembly",
5
- "version": "1.0.6",
5
+ "version": "1.1.0",
6
6
  "license": "MIT",
7
7
  "files": [
8
8
  "compress_jpeg_bg.wasm",