compress-jpeg 1.0.5 → 1.0.6
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 +10 -7
- package/compress_jpeg.d.ts +10 -6
- package/compress_jpeg.js +150 -15
- package/compress_jpeg_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,8 +70,8 @@ fileInput.addEventListener("change", async () => {
|
|
|
70
70
|
const file = fileInput.files?.[0];
|
|
71
71
|
if (!file) return;
|
|
72
72
|
|
|
73
|
-
// Initialize the WASM module
|
|
74
|
-
await init(
|
|
73
|
+
// Initialize the WASM module
|
|
74
|
+
await init();
|
|
75
75
|
|
|
76
76
|
// Load image into an off-screen canvas
|
|
77
77
|
const img = new Image();
|
|
@@ -89,22 +89,25 @@ fileInput.addEventListener("change", async () => {
|
|
|
89
89
|
|
|
90
90
|
// Extract raw pixel data
|
|
91
91
|
const browserImageData = ctx.getImageData(0, 0, img.width, img.height);
|
|
92
|
-
const
|
|
92
|
+
const input = new RustImageData(
|
|
93
|
+
new Uint8ClampedArray(browserImageData.data),
|
|
93
94
|
browserImageData.width,
|
|
94
|
-
browserImageData.height
|
|
95
|
-
new Uint8ClampedArray(browserImageData.data)
|
|
95
|
+
browserImageData.height
|
|
96
96
|
);
|
|
97
97
|
|
|
98
98
|
// Simulate JPEG compression at quality=30
|
|
99
|
-
const output = compress_jpeg(
|
|
99
|
+
const output = compress_jpeg(input, 30);
|
|
100
100
|
|
|
101
101
|
// Convert back to browser ImageData
|
|
102
|
-
const processedData = new ImageData(output.data(), output.width(), output.height());
|
|
102
|
+
const processedData = new ImageData(new Uint8ClampedArray(output.data()), output.width(), output.height());
|
|
103
103
|
|
|
104
104
|
// Draw on visible canvas
|
|
105
105
|
processedCanvas.width = output.width();
|
|
106
106
|
processedCanvas.height = output.height();
|
|
107
107
|
processedCanvas.getContext("2d")!.putImageData(processedData, 0, 0);
|
|
108
|
+
|
|
109
|
+
// Free the WebAssembly memory
|
|
110
|
+
output.free();
|
|
108
111
|
};
|
|
109
112
|
});
|
|
110
113
|
```
|
package/compress_jpeg.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
export function compress_jpeg(image_data: ImageData, quality: number): ImageData
|
|
3
|
+
export function compress_jpeg(image_data: ImageData, quality: number): Promise<ImageData>;
|
|
4
4
|
export class ImageData {
|
|
5
5
|
free(): void;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(data: Uint8ClampedArray, width: number, height: number);
|
|
7
7
|
width(): number;
|
|
8
8
|
height(): number;
|
|
9
9
|
data(): Uint8ClampedArray;
|
|
@@ -14,13 +14,17 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
14
14
|
export interface InitOutput {
|
|
15
15
|
readonly memory: WebAssembly.Memory;
|
|
16
16
|
readonly __wbg_imagedata_free: (a: number, b: number) => void;
|
|
17
|
-
readonly imagedata_new: (a:
|
|
17
|
+
readonly imagedata_new: (a: any, b: number, c: number) => number;
|
|
18
18
|
readonly imagedata_width: (a: number) => number;
|
|
19
19
|
readonly imagedata_height: (a: number) => number;
|
|
20
20
|
readonly imagedata_data: (a: number) => any;
|
|
21
|
-
readonly compress_jpeg: (a: number, b: number) =>
|
|
22
|
-
readonly
|
|
23
|
-
readonly
|
|
21
|
+
readonly compress_jpeg: (a: number, b: number) => any;
|
|
22
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
23
|
+
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;
|
|
24
28
|
readonly __wbindgen_start: () => void;
|
|
25
29
|
}
|
|
26
30
|
|
package/compress_jpeg.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
let wasm;
|
|
2
2
|
|
|
3
|
+
function addToExternrefTable0(obj) {
|
|
4
|
+
const idx = wasm.__externref_table_alloc();
|
|
5
|
+
wasm.__wbindgen_export_2.set(idx, obj);
|
|
6
|
+
return idx;
|
|
7
|
+
}
|
|
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
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
3
18
|
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
4
19
|
|
|
5
20
|
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
@@ -18,30 +33,64 @@ function getStringFromWasm0(ptr, len) {
|
|
|
18
33
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
19
34
|
}
|
|
20
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;
|
|
69
|
+
}
|
|
70
|
+
|
|
21
71
|
function _assertClass(instance, klass) {
|
|
22
72
|
if (!(instance instanceof klass)) {
|
|
23
73
|
throw new Error(`expected instance of ${klass.name}`);
|
|
24
74
|
}
|
|
25
75
|
}
|
|
26
|
-
|
|
27
|
-
function takeFromExternrefTable0(idx) {
|
|
28
|
-
const value = wasm.__wbindgen_export_0.get(idx);
|
|
29
|
-
wasm.__externref_table_dealloc(idx);
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
76
|
/**
|
|
33
77
|
* @param {ImageData} image_data
|
|
34
78
|
* @param {number} quality
|
|
35
|
-
* @returns {ImageData}
|
|
79
|
+
* @returns {Promise<ImageData>}
|
|
36
80
|
*/
|
|
37
81
|
export function compress_jpeg(image_data, quality) {
|
|
38
82
|
_assertClass(image_data, ImageData);
|
|
39
83
|
var ptr0 = image_data.__destroy_into_raw();
|
|
40
84
|
const ret = wasm.compress_jpeg(ptr0, quality);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
85
|
+
return ret;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function __wbg_adapter_18(arg0, arg1, arg2) {
|
|
89
|
+
wasm.closure6_externref_shim(arg0, arg1, arg2);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function __wbg_adapter_36(arg0, arg1, arg2, arg3) {
|
|
93
|
+
wasm.closure23_externref_shim(arg0, arg1, arg2, arg3);
|
|
45
94
|
}
|
|
46
95
|
|
|
47
96
|
const ImageDataFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
@@ -70,12 +119,12 @@ export class ImageData {
|
|
|
70
119
|
wasm.__wbg_imagedata_free(ptr, 0);
|
|
71
120
|
}
|
|
72
121
|
/**
|
|
122
|
+
* @param {Uint8ClampedArray} data
|
|
73
123
|
* @param {number} width
|
|
74
124
|
* @param {number} height
|
|
75
|
-
* @param {Uint8ClampedArray} data
|
|
76
125
|
*/
|
|
77
|
-
constructor(width, height
|
|
78
|
-
const ret = wasm.imagedata_new(width, height
|
|
126
|
+
constructor(data, width, height) {
|
|
127
|
+
const ret = wasm.imagedata_new(data, width, height);
|
|
79
128
|
this.__wbg_ptr = ret >>> 0;
|
|
80
129
|
ImageDataFinalization.register(this, this.__wbg_ptr, this);
|
|
81
130
|
return this;
|
|
@@ -141,23 +190,101 @@ function __wbg_get_imports() {
|
|
|
141
190
|
const ret = arg0.buffer;
|
|
142
191
|
return ret;
|
|
143
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
|
+
};
|
|
144
205
|
imports.wbg.__wbg_length_238152a0aedbb6e7 = function(arg0) {
|
|
145
206
|
const ret = arg0.length;
|
|
146
207
|
return ret;
|
|
147
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
|
+
};
|
|
148
227
|
imports.wbg.__wbg_new_7a91e41fe43b3c92 = function(arg0) {
|
|
149
228
|
const ret = new Uint8ClampedArray(arg0);
|
|
150
229
|
return ret;
|
|
151
230
|
};
|
|
231
|
+
imports.wbg.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
|
|
232
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
233
|
+
return ret;
|
|
234
|
+
};
|
|
152
235
|
imports.wbg.__wbg_newwithbyteoffsetandlength_6d34787141015158 = function(arg0, arg1, arg2) {
|
|
153
236
|
const ret = new Uint8ClampedArray(arg0, arg1 >>> 0, arg2 >>> 0);
|
|
154
237
|
return ret;
|
|
155
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
|
+
};
|
|
156
250
|
imports.wbg.__wbg_set_6775f73144c2ef27 = function(arg0, arg1, arg2) {
|
|
157
251
|
arg0.set(arg1, arg2 >>> 0);
|
|
158
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);
|
|
264
|
+
};
|
|
265
|
+
imports.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
|
|
266
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
267
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
268
|
+
};
|
|
269
|
+
imports.wbg.__wbg_then_44b73946d2fb3e7d = function(arg0, arg1) {
|
|
270
|
+
const ret = arg0.then(arg1);
|
|
271
|
+
return ret;
|
|
272
|
+
};
|
|
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;
|
|
280
|
+
return ret;
|
|
281
|
+
};
|
|
282
|
+
imports.wbg.__wbindgen_closure_wrapper52 = function(arg0, arg1, arg2) {
|
|
283
|
+
const ret = makeMutClosure(arg0, arg1, 7, __wbg_adapter_18);
|
|
284
|
+
return ret;
|
|
285
|
+
};
|
|
159
286
|
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
160
|
-
const table = wasm.
|
|
287
|
+
const table = wasm.__wbindgen_export_2;
|
|
161
288
|
const offset = table.grow(4);
|
|
162
289
|
table.set(0, undefined);
|
|
163
290
|
table.set(offset + 0, undefined);
|
|
@@ -166,6 +293,14 @@ function __wbg_get_imports() {
|
|
|
166
293
|
table.set(offset + 3, false);
|
|
167
294
|
;
|
|
168
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
|
+
};
|
|
169
304
|
imports.wbg.__wbindgen_memory = function() {
|
|
170
305
|
const ret = wasm.memory;
|
|
171
306
|
return ret;
|
package/compress_jpeg_bg.wasm
CHANGED
|
Binary file
|