smallpeg 0.13.1 → 0.14.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.
@@ -1,292 +1,34 @@
1
+ /* @ts-self-types="./smallpeg_wasm.d.ts" */
1
2
 
2
- let imports = {};
3
- imports['__wbindgen_placeholder__'] = module.exports;
4
- let wasm;
5
- const { TextDecoder } = require(`util`);
6
-
7
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
8
-
9
- cachedTextDecoder.decode();
10
-
11
- let cachedUint8ArrayMemory0 = null;
12
-
13
- function getUint8ArrayMemory0() {
14
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
15
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
16
- }
17
- return cachedUint8ArrayMemory0;
18
- }
19
-
20
- function getStringFromWasm0(ptr, len) {
21
- ptr = ptr >>> 0;
22
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
23
- }
24
-
25
- let WASM_VECTOR_LEN = 0;
26
-
27
- function passArray8ToWasm0(arg, malloc) {
28
- const ptr = malloc(arg.length * 1, 1) >>> 0;
29
- getUint8ArrayMemory0().set(arg, ptr / 1);
30
- WASM_VECTOR_LEN = arg.length;
31
- return ptr;
32
- }
33
-
34
- function isLikeNone(x) {
35
- return x === undefined || x === null;
36
- }
37
-
38
- function takeFromExternrefTable0(idx) {
39
- const value = wasm.__wbindgen_export_0.get(idx);
40
- wasm.__externref_table_dealloc(idx);
41
- return value;
42
- }
43
-
44
- function getArrayU8FromWasm0(ptr, len) {
45
- ptr = ptr >>> 0;
46
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
47
- }
48
- /**
49
- * Encode pixels as a JPEG.
50
- *
51
- * `channels` is 1 (gray), 3 (RGB) or 4 (RGBA, as from a canvas; alpha is
52
- * flattened onto white). `quality` is 1..=100 (default 80). `fullColor`
53
- * keeps chroma at full resolution (4:4:4) instead of halving it (4:2:0):
54
- * sharper colored text and lines, larger files. Both dimensions must be at
55
- * most 65535.
56
- * @param {Uint8Array} pixels
57
- * @param {number} width
58
- * @param {number} height
59
- * @param {number} channels
60
- * @param {number | undefined} [quality]
61
- * @param {boolean | undefined} [fullColor]
62
- * @returns {Uint8Array}
63
- */
64
- module.exports.encode = function(pixels, width, height, channels, quality, fullColor) {
65
- const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
66
- const len0 = WASM_VECTOR_LEN;
67
- const ret = wasm.encode(ptr0, len0, width, height, channels, isLikeNone(quality) ? 0xFFFFFF : quality, isLikeNone(fullColor) ? 0xFFFFFF : fullColor ? 1 : 0);
68
- if (ret[3]) {
69
- throw takeFromExternrefTable0(ret[2]);
70
- }
71
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
72
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
73
- return v2;
74
- };
75
-
76
- /**
77
- * Make an existing JPEG smaller without changing a pixel. `undefined` if
78
- * the file is not one this can re-code. The result can come out larger
79
- * for files that are already optimized; compare lengths. `baseline`
80
- * forces baseline sequential output (for targets that dislike
81
- * progressive JPEGs, such as PDF embedding).
82
- * @param {Uint8Array} jpeg
83
- * @param {boolean | undefined} [baseline]
84
- * @returns {Uint8Array | undefined}
85
- */
86
- module.exports.optimize = function(jpeg, baseline) {
87
- const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
88
- const len0 = WASM_VECTOR_LEN;
89
- const ret = wasm.optimize(ptr0, len0, isLikeNone(baseline) ? 0xFFFFFF : baseline ? 1 : 0);
90
- let v2;
91
- if (ret[0] !== 0) {
92
- v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
93
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
94
- }
95
- return v2;
96
- };
97
-
98
- /**
99
- * Remove EXIF (including GPS), XMP, comments and other metadata without
100
- * touching the image data. Keeps the color profile and the photo's
101
- * orientation. `undefined` if the file cannot be parsed.
102
- * @param {Uint8Array} jpeg
103
- * @returns {Uint8Array | undefined}
104
- */
105
- module.exports.stripMetadata = function(jpeg) {
106
- const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
107
- const len0 = WASM_VECTOR_LEN;
108
- const ret = wasm.stripMetadata(ptr0, len0);
109
- let v2;
110
- if (ret[0] !== 0) {
111
- v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
112
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
113
- }
114
- return v2;
115
- };
116
-
117
- /**
118
- * Read a JPEG's frame header without decoding it. `undefined` if the
119
- * bytes are not a JPEG this library understands.
120
- * @param {Uint8Array} jpeg
121
- * @returns {JpegInfo | undefined}
122
- */
123
- module.exports.info = function(jpeg) {
124
- const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
125
- const len0 = WASM_VECTOR_LEN;
126
- const ret = wasm.info(ptr0, len0);
127
- return ret === 0 ? undefined : JpegInfo.__wrap(ret);
128
- };
129
-
130
- /**
131
- * Decode a grayscale or color JPEG to 8-bit gray or RGB pixels, as
132
- * stored (see `applyOrientation`). `undefined` for CMYK files, codings
133
- * this library does not decode, malformed input, or frames over 100
134
- * megapixels.
135
- * @param {Uint8Array} jpeg
136
- * @returns {Image | undefined}
137
- */
138
- module.exports.decode = function(jpeg) {
139
- const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
140
- const len0 = WASM_VECTOR_LEN;
141
- const ret = wasm.decode(ptr0, len0);
142
- return ret === 0 ? undefined : Image.__wrap(ret);
143
- };
144
-
145
- /**
146
- * Turn decoded pixels upright for an EXIF orientation (1..=8; other
147
- * values leave them as they are). Orientations 5 to 8 swap width and
148
- * height.
149
- * @param {Uint8Array} pixels
150
- * @param {number} width
151
- * @param {number} height
152
- * @param {number} channels
153
- * @param {number} orientation
154
- * @returns {Image}
155
- */
156
- module.exports.applyOrientation = function(pixels, width, height, channels, orientation) {
157
- const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
158
- const len0 = WASM_VECTOR_LEN;
159
- const ret = wasm.applyOrientation(ptr0, len0, width, height, channels, orientation);
160
- if (ret[2]) {
161
- throw takeFromExternrefTable0(ret[1]);
162
- }
163
- return Image.__wrap(ret[0]);
164
- };
165
-
166
- /**
167
- * Resize with a Lanczos3 filter. `channels` is 1 (gray), 3 (RGB) or 4
168
- * (any four-channel layout, each channel filtered independently).
169
- * `linear` filters RGB or gray in linear light, which keeps fine
170
- * light-and-dark detail from darkening when reducing; it assumes sRGB
171
- * input and is not available for 4 channels.
172
- * @param {Uint8Array} pixels
173
- * @param {number} width
174
- * @param {number} height
175
- * @param {number} channels
176
- * @param {number} newWidth
177
- * @param {number} newHeight
178
- * @param {boolean | undefined} [linear]
179
- * @returns {Uint8Array}
180
- */
181
- module.exports.resize = function(pixels, width, height, channels, newWidth, newHeight, linear) {
182
- const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
183
- const len0 = WASM_VECTOR_LEN;
184
- const ret = wasm.resize(ptr0, len0, width, height, channels, newWidth, newHeight, isLikeNone(linear) ? 0xFFFFFF : linear ? 1 : 0);
185
- if (ret[3]) {
186
- throw takeFromExternrefTable0(ret[2]);
187
- }
188
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
189
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
190
- return v2;
191
- };
192
-
193
- /**
194
- * Copy a rectangle out of pixels with any channel count. `undefined` if
195
- * the rectangle is empty or not entirely inside the image.
196
- * @param {Uint8Array} pixels
197
- * @param {number} width
198
- * @param {number} height
199
- * @param {number} channels
200
- * @param {number} x
201
- * @param {number} y
202
- * @param {number} cropWidth
203
- * @param {number} cropHeight
204
- * @returns {Uint8Array | undefined}
205
- */
206
- module.exports.crop = function(pixels, width, height, channels, x, y, cropWidth, cropHeight) {
207
- const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
208
- const len0 = WASM_VECTOR_LEN;
209
- const ret = wasm.crop(ptr0, len0, width, height, channels, x, y, cropWidth, cropHeight);
210
- if (ret[3]) {
211
- throw takeFromExternrefTable0(ret[2]);
212
- }
213
- let v2;
214
- if (ret[0] !== 0) {
215
- v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
216
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
217
- }
218
- return v2;
219
- };
220
-
221
- let cachedUint32ArrayMemory0 = null;
222
-
223
- function getUint32ArrayMemory0() {
224
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
225
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
226
- }
227
- return cachedUint32ArrayMemory0;
228
- }
229
-
230
- function getArrayU32FromWasm0(ptr, len) {
231
- ptr = ptr >>> 0;
232
- return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
233
- }
234
- /**
235
- * The largest `[width, height]` that fits inside `maxWidth` x `maxHeight`
236
- * with the same aspect ratio. Never enlarges.
237
- * @param {number} width
238
- * @param {number} height
239
- * @param {number} maxWidth
240
- * @param {number} maxHeight
241
- * @returns {Uint32Array}
242
- */
243
- module.exports.fitWithin = function(width, height, maxWidth, maxHeight) {
244
- const ret = wasm.fitWithin(width, height, maxWidth, maxHeight);
245
- if (ret[3]) {
246
- throw takeFromExternrefTable0(ret[2]);
247
- }
248
- var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
249
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
250
- return v1;
251
- };
252
-
253
- const ImageFinalization = (typeof FinalizationRegistry === 'undefined')
254
- ? { register: () => {}, unregister: () => {} }
255
- : new FinalizationRegistry(ptr => wasm.__wbg_image_free(ptr >>> 0, 1));
256
3
  /**
257
- * Pixels plus their layout, returned by `decode` and `applyOrientation`.
4
+ * Decoded or transformed pixels. The TypeScript layer reads the fields,
5
+ * moves the pixels out with `take_pixels`, and frees it.
258
6
  */
259
7
  class Image {
260
-
261
8
  static __wrap(ptr) {
262
- ptr = ptr >>> 0;
263
9
  const obj = Object.create(Image.prototype);
264
10
  obj.__wbg_ptr = ptr;
265
11
  ImageFinalization.register(obj, obj.__wbg_ptr, obj);
266
12
  return obj;
267
13
  }
268
-
269
14
  __destroy_into_raw() {
270
15
  const ptr = this.__wbg_ptr;
271
16
  this.__wbg_ptr = 0;
272
17
  ImageFinalization.unregister(this);
273
18
  return ptr;
274
19
  }
275
-
276
20
  free() {
277
21
  const ptr = this.__destroy_into_raw();
278
22
  wasm.__wbg_image_free(ptr, 0);
279
23
  }
280
24
  /**
281
- * Width in pixels.
282
25
  * @returns {number}
283
26
  */
284
- get width() {
285
- const ret = wasm.image_width(this.__wbg_ptr);
286
- return ret >>> 0;
27
+ get channels() {
28
+ const ret = wasm.image_channels(this.__wbg_ptr);
29
+ return ret;
287
30
  }
288
31
  /**
289
- * Height in pixels.
290
32
  * @returns {number}
291
33
  */
292
34
  get height() {
@@ -294,56 +36,48 @@ class Image {
294
36
  return ret >>> 0;
295
37
  }
296
38
  /**
297
- * `width * height * channels` bytes, interleaved, top row first.
39
+ * Moves the pixels out (no copy on the Rust side); a second call
40
+ * returns an empty array.
298
41
  * @returns {Uint8Array}
299
42
  */
300
- get pixels() {
301
- const ret = wasm.image_pixels(this.__wbg_ptr);
43
+ take_pixels() {
44
+ const ret = wasm.image_take_pixels(this.__wbg_ptr);
302
45
  var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
303
46
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
304
47
  return v1;
305
48
  }
306
49
  /**
307
- * 1 (gray) or 3 (RGB) for decoded JPEGs; whatever was passed in for
308
- * `applyOrientation`.
309
50
  * @returns {number}
310
51
  */
311
- get channels() {
312
- const ret = wasm.image_channels(this.__wbg_ptr);
313
- return ret;
52
+ get width() {
53
+ const ret = wasm.image_width(this.__wbg_ptr);
54
+ return ret >>> 0;
314
55
  }
315
56
  }
316
- module.exports.Image = Image;
57
+ if (Symbol.dispose) Image.prototype[Symbol.dispose] = Image.prototype.free;
58
+ exports.Image = Image;
317
59
 
318
- const JpegInfoFinalization = (typeof FinalizationRegistry === 'undefined')
319
- ? { register: () => {}, unregister: () => {} }
320
- : new FinalizationRegistry(ptr => wasm.__wbg_jpeginfo_free(ptr >>> 0, 1));
321
60
  /**
322
- * Frame-header facts about a JPEG, returned by `info`.
61
+ * Frame-header facts, returned by `info`.
323
62
  */
324
63
  class JpegInfo {
325
-
326
64
  static __wrap(ptr) {
327
- ptr = ptr >>> 0;
328
65
  const obj = Object.create(JpegInfo.prototype);
329
66
  obj.__wbg_ptr = ptr;
330
67
  JpegInfoFinalization.register(obj, obj.__wbg_ptr, obj);
331
68
  return obj;
332
69
  }
333
-
334
70
  __destroy_into_raw() {
335
71
  const ptr = this.__wbg_ptr;
336
72
  this.__wbg_ptr = 0;
337
73
  JpegInfoFinalization.unregister(this);
338
74
  return ptr;
339
75
  }
340
-
341
76
  free() {
342
77
  const ptr = this.__destroy_into_raw();
343
78
  wasm.__wbg_jpeginfo_free(ptr, 0);
344
79
  }
345
80
  /**
346
- * 1 (gray), 3 (color) or 4 (CMYK / YCCK).
347
81
  * @returns {number}
348
82
  */
349
83
  get components() {
@@ -351,7 +85,13 @@ class JpegInfo {
351
85
  return ret;
352
86
  }
353
87
  /**
354
- * EXIF orientation, 1..=8 (1 when the file has none).
88
+ * @returns {number}
89
+ */
90
+ get height() {
91
+ const ret = wasm.jpeginfo_height(this.__wbg_ptr);
92
+ return ret >>> 0;
93
+ }
94
+ /**
355
95
  * @returns {number}
356
96
  */
357
97
  get orientation() {
@@ -359,7 +99,6 @@ class JpegInfo {
359
99
  return ret;
360
100
  }
361
101
  /**
362
- * True for progressive files.
363
102
  * @returns {boolean}
364
103
  */
365
104
  get progressive() {
@@ -367,51 +106,279 @@ class JpegInfo {
367
106
  return ret !== 0;
368
107
  }
369
108
  /**
370
- * Width in pixels.
371
109
  * @returns {number}
372
110
  */
373
111
  get width() {
374
112
  const ret = wasm.jpeginfo_width(this.__wbg_ptr);
375
113
  return ret >>> 0;
376
114
  }
377
- /**
378
- * Height in pixels.
379
- * @returns {number}
380
- */
381
- get height() {
382
- const ret = wasm.jpeginfo_height(this.__wbg_ptr);
383
- return ret >>> 0;
115
+ }
116
+ if (Symbol.dispose) JpegInfo.prototype[Symbol.dispose] = JpegInfo.prototype.free;
117
+ exports.JpegInfo = JpegInfo;
118
+
119
+ /**
120
+ * @param {Uint8Array} pixels
121
+ * @param {number} width
122
+ * @param {number} height
123
+ * @param {number} channels
124
+ * @param {number} orientation
125
+ * @returns {Image}
126
+ */
127
+ function apply_orientation(pixels, width, height, channels, orientation) {
128
+ const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
129
+ const len0 = WASM_VECTOR_LEN;
130
+ const ret = wasm.apply_orientation(ptr0, len0, width, height, channels, orientation);
131
+ if (ret[2]) {
132
+ throw takeFromExternrefTable0(ret[1]);
384
133
  }
134
+ return Image.__wrap(ret[0]);
385
135
  }
386
- module.exports.JpegInfo = JpegInfo;
136
+ exports.apply_orientation = apply_orientation;
387
137
 
388
- module.exports.__wbindgen_error_new = function(arg0, arg1) {
389
- const ret = new Error(getStringFromWasm0(arg0, arg1));
390
- return ret;
391
- };
138
+ /**
139
+ * `undefined` if the rectangle is empty or not entirely inside the image.
140
+ * @param {Uint8Array} pixels
141
+ * @param {number} width
142
+ * @param {number} height
143
+ * @param {number} channels
144
+ * @param {number} x
145
+ * @param {number} y
146
+ * @param {number} crop_width
147
+ * @param {number} crop_height
148
+ * @returns {Uint8Array | undefined}
149
+ */
150
+ function crop(pixels, width, height, channels, x, y, crop_width, crop_height) {
151
+ const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
152
+ const len0 = WASM_VECTOR_LEN;
153
+ const ret = wasm.crop(ptr0, len0, width, height, channels, x, y, crop_width, crop_height);
154
+ if (ret[3]) {
155
+ throw takeFromExternrefTable0(ret[2]);
156
+ }
157
+ let v2;
158
+ if (ret[0] !== 0) {
159
+ v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
160
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
161
+ }
162
+ return v2;
163
+ }
164
+ exports.crop = crop;
392
165
 
393
- module.exports.__wbindgen_throw = function(arg0, arg1) {
394
- throw new Error(getStringFromWasm0(arg0, arg1));
395
- };
166
+ /**
167
+ * @param {Uint8Array} jpeg
168
+ * @returns {Image | undefined}
169
+ */
170
+ function decode(jpeg) {
171
+ const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
172
+ const len0 = WASM_VECTOR_LEN;
173
+ const ret = wasm.decode(ptr0, len0);
174
+ return ret === 0 ? undefined : Image.__wrap(ret);
175
+ }
176
+ exports.decode = decode;
396
177
 
397
- module.exports.__wbindgen_init_externref_table = function() {
398
- const table = wasm.__wbindgen_export_0;
399
- const offset = table.grow(4);
400
- table.set(0, undefined);
401
- table.set(offset + 0, undefined);
402
- table.set(offset + 1, null);
403
- table.set(offset + 2, true);
404
- table.set(offset + 3, false);
405
- ;
406
- };
178
+ /**
179
+ * Encode pixels; 4 channels are RGBA, flattened onto white.
180
+ * @param {Uint8Array} pixels
181
+ * @param {number} width
182
+ * @param {number} height
183
+ * @param {number} channels
184
+ * @param {number | null} [quality]
185
+ * @param {boolean | null} [full_color]
186
+ * @returns {Uint8Array}
187
+ */
188
+ function encode(pixels, width, height, channels, quality, full_color) {
189
+ const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
190
+ const len0 = WASM_VECTOR_LEN;
191
+ const ret = wasm.encode(ptr0, len0, width, height, channels, isLikeNone(quality) ? 0xFFFFFF : quality, isLikeNone(full_color) ? 0xFFFFFF : full_color ? 1 : 0);
192
+ if (ret[3]) {
193
+ throw takeFromExternrefTable0(ret[2]);
194
+ }
195
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
196
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
197
+ return v2;
198
+ }
199
+ exports.encode = encode;
407
200
 
408
- const path = require('path').join(__dirname, 'smallpeg_wasm_bg.wasm');
409
- const bytes = require('fs').readFileSync(path);
201
+ /**
202
+ * `[width, height]` that fits, keeping the aspect ratio; never enlarges.
203
+ * @param {number} width
204
+ * @param {number} height
205
+ * @param {number} max_width
206
+ * @param {number} max_height
207
+ * @returns {Uint32Array}
208
+ */
209
+ function fit_within(width, height, max_width, max_height) {
210
+ const ret = wasm.fit_within(width, height, max_width, max_height);
211
+ if (ret[3]) {
212
+ throw takeFromExternrefTable0(ret[2]);
213
+ }
214
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
215
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
216
+ return v1;
217
+ }
218
+ exports.fit_within = fit_within;
410
219
 
411
- const wasmModule = new WebAssembly.Module(bytes);
412
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
413
- wasm = wasmInstance.exports;
414
- module.exports.__wasm = wasm;
220
+ /**
221
+ * @param {Uint8Array} jpeg
222
+ * @returns {JpegInfo | undefined}
223
+ */
224
+ function info(jpeg) {
225
+ const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
226
+ const len0 = WASM_VECTOR_LEN;
227
+ const ret = wasm.info(ptr0, len0);
228
+ return ret === 0 ? undefined : JpegInfo.__wrap(ret);
229
+ }
230
+ exports.info = info;
415
231
 
416
- wasm.__wbindgen_start();
232
+ /**
233
+ * Lossless re-coding; `baseline` forces sequential output.
234
+ * @param {Uint8Array} jpeg
235
+ * @param {boolean} baseline
236
+ * @returns {Uint8Array | undefined}
237
+ */
238
+ function optimize(jpeg, baseline) {
239
+ const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
240
+ const len0 = WASM_VECTOR_LEN;
241
+ const ret = wasm.optimize(ptr0, len0, baseline);
242
+ let v2;
243
+ if (ret[0] !== 0) {
244
+ v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
245
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
246
+ }
247
+ return v2;
248
+ }
249
+ exports.optimize = optimize;
250
+
251
+ /**
252
+ * Lanczos3 resize; `linear` filters gray or RGB in linear light.
253
+ * @param {Uint8Array} pixels
254
+ * @param {number} width
255
+ * @param {number} height
256
+ * @param {number} channels
257
+ * @param {number} new_width
258
+ * @param {number} new_height
259
+ * @param {boolean} linear
260
+ * @returns {Uint8Array}
261
+ */
262
+ function resize(pixels, width, height, channels, new_width, new_height, linear) {
263
+ const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
264
+ const len0 = WASM_VECTOR_LEN;
265
+ const ret = wasm.resize(ptr0, len0, width, height, channels, new_width, new_height, linear);
266
+ if (ret[3]) {
267
+ throw takeFromExternrefTable0(ret[2]);
268
+ }
269
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
270
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
271
+ return v2;
272
+ }
273
+ exports.resize = resize;
417
274
 
275
+ /**
276
+ * @param {Uint8Array} jpeg
277
+ * @returns {Uint8Array | undefined}
278
+ */
279
+ function strip_metadata(jpeg) {
280
+ const ptr0 = passArray8ToWasm0(jpeg, wasm.__wbindgen_malloc);
281
+ const len0 = WASM_VECTOR_LEN;
282
+ const ret = wasm.strip_metadata(ptr0, len0);
283
+ let v2;
284
+ if (ret[0] !== 0) {
285
+ v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
286
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
287
+ }
288
+ return v2;
289
+ }
290
+ exports.strip_metadata = strip_metadata;
291
+ function __wbg_get_imports() {
292
+ const import0 = {
293
+ __proto__: null,
294
+ __wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
295
+ const ret = Error(getStringFromWasm0(arg0, arg1));
296
+ return ret;
297
+ },
298
+ __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
299
+ throw new Error(getStringFromWasm0(arg0, arg1));
300
+ },
301
+ __wbindgen_init_externref_table: function() {
302
+ const table = wasm.__wbindgen_externrefs;
303
+ const offset = table.grow(4);
304
+ table.set(0, undefined);
305
+ table.set(offset + 0, undefined);
306
+ table.set(offset + 1, null);
307
+ table.set(offset + 2, true);
308
+ table.set(offset + 3, false);
309
+ },
310
+ };
311
+ return {
312
+ __proto__: null,
313
+ "./smallpeg_wasm_bg.js": import0,
314
+ };
315
+ }
316
+
317
+ const ImageFinalization = (typeof FinalizationRegistry === 'undefined')
318
+ ? { register: () => {}, unregister: () => {} }
319
+ : new FinalizationRegistry(ptr => wasm.__wbg_image_free(ptr, 1));
320
+ const JpegInfoFinalization = (typeof FinalizationRegistry === 'undefined')
321
+ ? { register: () => {}, unregister: () => {} }
322
+ : new FinalizationRegistry(ptr => wasm.__wbg_jpeginfo_free(ptr, 1));
323
+
324
+ function getArrayU32FromWasm0(ptr, len) {
325
+ ptr = ptr >>> 0;
326
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
327
+ }
328
+
329
+ function getArrayU8FromWasm0(ptr, len) {
330
+ ptr = ptr >>> 0;
331
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
332
+ }
333
+
334
+ function getStringFromWasm0(ptr, len) {
335
+ return decodeText(ptr >>> 0, len);
336
+ }
337
+
338
+ let cachedUint32ArrayMemory0 = null;
339
+ function getUint32ArrayMemory0() {
340
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
341
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
342
+ }
343
+ return cachedUint32ArrayMemory0;
344
+ }
345
+
346
+ let cachedUint8ArrayMemory0 = null;
347
+ function getUint8ArrayMemory0() {
348
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
349
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
350
+ }
351
+ return cachedUint8ArrayMemory0;
352
+ }
353
+
354
+ function isLikeNone(x) {
355
+ return x === undefined || x === null;
356
+ }
357
+
358
+ function passArray8ToWasm0(arg, malloc) {
359
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
360
+ getUint8ArrayMemory0().set(arg, ptr / 1);
361
+ WASM_VECTOR_LEN = arg.length;
362
+ return ptr;
363
+ }
364
+
365
+ function takeFromExternrefTable0(idx) {
366
+ const value = wasm.__wbindgen_externrefs.get(idx);
367
+ wasm.__externref_table_dealloc(idx);
368
+ return value;
369
+ }
370
+
371
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
372
+ cachedTextDecoder.decode();
373
+ function decodeText(ptr, len) {
374
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
375
+ }
376
+
377
+ let WASM_VECTOR_LEN = 0;
378
+
379
+ const wasmPath = `${__dirname}/smallpeg_wasm_bg.wasm`;
380
+ const wasmBytes = require('fs').readFileSync(wasmPath);
381
+ const wasmModule = new WebAssembly.Module(wasmBytes);
382
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
383
+ let wasm = wasmInstance.exports;
384
+ wasm.__wbindgen_start();
Binary file