format-png 0.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.
@@ -0,0 +1,1517 @@
1
+ /* @ts-self-types="./format_png_wasm.d.ts" */
2
+
3
+ /**
4
+ * A raw ancillary chunk. JavaScript reads `chunkType` and `position`, then calls
5
+ * `intoData()` once, which copies the data out and frees this object.
6
+ */
7
+ export class Chunk {
8
+ static __wrap(ptr) {
9
+ const obj = Object.create(Chunk.prototype);
10
+ obj.__wbg_ptr = ptr;
11
+ ChunkFinalization.register(obj, obj.__wbg_ptr, obj);
12
+ return obj;
13
+ }
14
+ __destroy_into_raw() {
15
+ const ptr = this.__wbg_ptr;
16
+ this.__wbg_ptr = 0;
17
+ ChunkFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_chunk_free(ptr, 0);
23
+ }
24
+ /**
25
+ * The four-letter type, for example "tEXt".
26
+ * @returns {string}
27
+ */
28
+ get chunkType() {
29
+ let deferred1_0;
30
+ let deferred1_1;
31
+ try {
32
+ const ret = wasm.chunk_chunkType(this.__wbg_ptr);
33
+ deferred1_0 = ret[0];
34
+ deferred1_1 = ret[1];
35
+ return getStringFromWasm0(ret[0], ret[1]);
36
+ } finally {
37
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
38
+ }
39
+ }
40
+ /**
41
+ * The chunk's data, without length, type and CRC. Consumes the chunk.
42
+ * @returns {Uint8Array}
43
+ */
44
+ intoData() {
45
+ const ptr = this.__destroy_into_raw();
46
+ const ret = wasm.chunk_intoData(ptr);
47
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
48
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
49
+ return v1;
50
+ }
51
+ /**
52
+ * "before-palette", "before-image-data" or "after-image-data".
53
+ * @returns {string}
54
+ */
55
+ get position() {
56
+ let deferred1_0;
57
+ let deferred1_1;
58
+ try {
59
+ const ret = wasm.chunk_position(this.__wbg_ptr);
60
+ deferred1_0 = ret[0];
61
+ deferred1_1 = ret[1];
62
+ return getStringFromWasm0(ret[0], ret[1]);
63
+ } finally {
64
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
65
+ }
66
+ }
67
+ }
68
+ if (Symbol.dispose) Chunk.prototype[Symbol.dispose] = Chunk.prototype.free;
69
+
70
+ /**
71
+ * Every chunk of a PNG, from `read_chunks`. The raw chunks are flat arrays,
72
+ * one entry per chunk in file order, so JavaScript can view their data in the
73
+ * input it already has instead of copying it out of wasm memory.
74
+ */
75
+ export class ChunkList {
76
+ static __wrap(ptr) {
77
+ const obj = Object.create(ChunkList.prototype);
78
+ obj.__wbg_ptr = ptr;
79
+ ChunkListFinalization.register(obj, obj.__wbg_ptr, obj);
80
+ return obj;
81
+ }
82
+ __destroy_into_raw() {
83
+ const ptr = this.__wbg_ptr;
84
+ this.__wbg_ptr = 0;
85
+ ChunkListFinalization.unregister(this);
86
+ return ptr;
87
+ }
88
+ free() {
89
+ const ptr = this.__destroy_into_raw();
90
+ wasm.__wbg_chunklist_free(ptr, 0);
91
+ }
92
+ /**
93
+ * @returns {Uint32Array}
94
+ */
95
+ get crcs() {
96
+ const ret = wasm.chunklist_crcs(this.__wbg_ptr);
97
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
98
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
99
+ return v1;
100
+ }
101
+ /**
102
+ * @returns {Header}
103
+ */
104
+ header() {
105
+ const ret = wasm.chunklist_header(this.__wbg_ptr);
106
+ return Header.__wrap(ret);
107
+ }
108
+ /**
109
+ * 1 for each chunk this crate parses, 0 for unknown ones.
110
+ * @returns {Uint8Array}
111
+ */
112
+ get known() {
113
+ const ret = wasm.chunklist_known(this.__wbg_ptr);
114
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
115
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
116
+ return v1;
117
+ }
118
+ /**
119
+ * The length of each chunk's data.
120
+ * @returns {Uint32Array}
121
+ */
122
+ get lengths() {
123
+ const ret = wasm.chunklist_lengths(this.__wbg_ptr);
124
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
125
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
126
+ return v1;
127
+ }
128
+ /**
129
+ * @returns {Metadata}
130
+ */
131
+ metadata() {
132
+ const ret = wasm.chunklist_metadata(this.__wbg_ptr);
133
+ return Metadata.__wrap(ret);
134
+ }
135
+ /**
136
+ * Where each chunk starts in the input: its length field.
137
+ * @returns {Uint32Array}
138
+ */
139
+ get offsets() {
140
+ const ret = wasm.chunklist_offsets(this.__wbg_ptr);
141
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
142
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
143
+ return v1;
144
+ }
145
+ /**
146
+ * `PLTE`: red, green and blue for each entry, in index order.
147
+ * @returns {Uint8Array | undefined}
148
+ */
149
+ get palette() {
150
+ const ret = wasm.chunklist_palette(this.__wbg_ptr);
151
+ let v1;
152
+ if (ret[0] !== 0) {
153
+ v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
154
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
155
+ }
156
+ return v1;
157
+ }
158
+ /**
159
+ * `tRNS`: "gray", "rgb" or "palette".
160
+ * @returns {string | undefined}
161
+ */
162
+ get transparencyKind() {
163
+ const ret = wasm.chunklist_transparencyKind(this.__wbg_ptr);
164
+ let v1;
165
+ if (ret[0] !== 0) {
166
+ v1 = getStringFromWasm0(ret[0], ret[1]);
167
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
168
+ }
169
+ return v1;
170
+ }
171
+ /**
172
+ * `tRNS`: the transparent gray value, the transparent red, green and blue,
173
+ * or an alpha for each palette entry.
174
+ * @returns {Uint16Array | undefined}
175
+ */
176
+ get transparencyValues() {
177
+ const ret = wasm.chunklist_transparencyValues(this.__wbg_ptr);
178
+ let v1;
179
+ if (ret[0] !== 0) {
180
+ v1 = getArrayU16FromWasm0(ret[0], ret[1]).slice();
181
+ wasm.__wbindgen_free(ret[0], ret[1] * 2, 2);
182
+ }
183
+ return v1;
184
+ }
185
+ /**
186
+ * The four-letter types of every chunk, joined.
187
+ * @returns {string}
188
+ */
189
+ get types() {
190
+ let deferred1_0;
191
+ let deferred1_1;
192
+ try {
193
+ const ret = wasm.chunklist_types(this.__wbg_ptr);
194
+ deferred1_0 = ret[0];
195
+ deferred1_1 = ret[1];
196
+ return getStringFromWasm0(ret[0], ret[1]);
197
+ } finally {
198
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
199
+ }
200
+ }
201
+ }
202
+ if (Symbol.dispose) ChunkList.prototype[Symbol.dispose] = ChunkList.prototype.free;
203
+
204
+ /**
205
+ * A decoded RGBA8 image. JavaScript reads `width`, `height`, `metadata()` and
206
+ * `takeChunks()`, then calls `intoPixels()` once, which copies the pixels out
207
+ * and frees this object.
208
+ */
209
+ export class DecodedImage {
210
+ static __wrap(ptr) {
211
+ const obj = Object.create(DecodedImage.prototype);
212
+ obj.__wbg_ptr = ptr;
213
+ DecodedImageFinalization.register(obj, obj.__wbg_ptr, obj);
214
+ return obj;
215
+ }
216
+ __destroy_into_raw() {
217
+ const ptr = this.__wbg_ptr;
218
+ this.__wbg_ptr = 0;
219
+ DecodedImageFinalization.unregister(this);
220
+ return ptr;
221
+ }
222
+ free() {
223
+ const ptr = this.__destroy_into_raw();
224
+ wasm.__wbg_decodedimage_free(ptr, 0);
225
+ }
226
+ /**
227
+ * The RGBA pixels, `width * height * 4` bytes. Consumes the image.
228
+ * @returns {Uint8Array}
229
+ */
230
+ intoPixels() {
231
+ const ptr = this.__destroy_into_raw();
232
+ const ret = wasm.decodedimage_intoPixels(ptr);
233
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
234
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
235
+ return v1;
236
+ }
237
+ /**
238
+ * The parsed ancillary chunks; empty unless `preserveMetadata` was set.
239
+ * @returns {Metadata}
240
+ */
241
+ metadata() {
242
+ const ret = wasm.decodedimage_metadata(this.__wbg_ptr);
243
+ return Metadata.__wrap(ret);
244
+ }
245
+ /**
246
+ * The raw ancillary chunks; empty unless `preserveChunks` was set. Moves
247
+ * them out, so a second call returns none.
248
+ * @returns {Chunk[]}
249
+ */
250
+ takeChunks() {
251
+ const ret = wasm.decodedimage_takeChunks(this.__wbg_ptr);
252
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
253
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
254
+ return v1;
255
+ }
256
+ /**
257
+ * @returns {number}
258
+ */
259
+ get height() {
260
+ const ret = wasm.__wbg_get_decodedimage_height(this.__wbg_ptr);
261
+ return ret >>> 0;
262
+ }
263
+ /**
264
+ * @returns {number}
265
+ */
266
+ get width() {
267
+ const ret = wasm.__wbg_get_decodedimage_width(this.__wbg_ptr);
268
+ return ret >>> 0;
269
+ }
270
+ }
271
+ if (Symbol.dispose) DecodedImage.prototype[Symbol.dispose] = DecodedImage.prototype.free;
272
+
273
+ /**
274
+ * A decoder that keeps its buffers between images.
275
+ */
276
+ export class Decoder {
277
+ __destroy_into_raw() {
278
+ const ptr = this.__wbg_ptr;
279
+ this.__wbg_ptr = 0;
280
+ DecoderFinalization.unregister(this);
281
+ return ptr;
282
+ }
283
+ free() {
284
+ const ptr = this.__destroy_into_raw();
285
+ wasm.__wbg_decoder_free(ptr, 0);
286
+ }
287
+ /**
288
+ * @param {Uint8Array} bytes
289
+ * @returns {DecodedImage}
290
+ */
291
+ decodeRgba8(bytes) {
292
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
293
+ const len0 = WASM_VECTOR_LEN;
294
+ const ret = wasm.decoder_decodeRgba8(this.__wbg_ptr, ptr0, len0);
295
+ if (ret[2]) {
296
+ throw takeFromExternrefTable0(ret[1]);
297
+ }
298
+ return DecodedImage.__wrap(ret[0]);
299
+ }
300
+ /**
301
+ * @param {Uint8Array} bytes
302
+ * @returns {RawImage}
303
+ */
304
+ decode(bytes) {
305
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
306
+ const len0 = WASM_VECTOR_LEN;
307
+ const ret = wasm.decoder_decode(this.__wbg_ptr, ptr0, len0);
308
+ if (ret[2]) {
309
+ throw takeFromExternrefTable0(ret[1]);
310
+ }
311
+ return RawImage.__wrap(ret[0]);
312
+ }
313
+ /**
314
+ * @param {boolean} validate_crc
315
+ * @param {boolean} preserve_metadata
316
+ * @param {boolean} preserve_chunks
317
+ * @param {boolean} strict_ancillary
318
+ */
319
+ constructor(validate_crc, preserve_metadata, preserve_chunks, strict_ancillary) {
320
+ const ret = wasm.decoder_new(validate_crc, preserve_metadata, preserve_chunks, strict_ancillary);
321
+ this.__wbg_ptr = ret;
322
+ DecoderFinalization.register(this, this.__wbg_ptr, this);
323
+ return this;
324
+ }
325
+ /**
326
+ * @param {Uint8Array} bytes
327
+ * @returns {ChunkList}
328
+ */
329
+ readChunks(bytes) {
330
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
331
+ const len0 = WASM_VECTOR_LEN;
332
+ const ret = wasm.decoder_readChunks(this.__wbg_ptr, ptr0, len0);
333
+ if (ret[2]) {
334
+ throw takeFromExternrefTable0(ret[1]);
335
+ }
336
+ return ChunkList.__wrap(ret[0]);
337
+ }
338
+ }
339
+ if (Symbol.dispose) Decoder.prototype[Symbol.dispose] = Decoder.prototype.free;
340
+
341
+ /**
342
+ * An image to encode, built up from JavaScript: the constructor takes the
343
+ * header and pixels, and each setter adds a chunk. Pass it to `encode` or
344
+ * `Encoder.encode`, then call `free()`.
345
+ */
346
+ export class EncodeImage {
347
+ __destroy_into_raw() {
348
+ const ptr = this.__wbg_ptr;
349
+ this.__wbg_ptr = 0;
350
+ EncodeImageFinalization.unregister(this);
351
+ return ptr;
352
+ }
353
+ free() {
354
+ const ptr = this.__destroy_into_raw();
355
+ wasm.__wbg_encodeimage_free(ptr, 0);
356
+ }
357
+ /**
358
+ * Adds a raw chunk, written at `position`: one of the strings
359
+ * `Chunk.position` returns.
360
+ * @param {string} chunk_type
361
+ * @param {Uint8Array} data
362
+ * @param {string} position
363
+ */
364
+ addChunk(chunk_type, data, position) {
365
+ const ptr0 = passStringToWasm0(chunk_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
366
+ const len0 = WASM_VECTOR_LEN;
367
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
368
+ const len1 = WASM_VECTOR_LEN;
369
+ const ptr2 = passStringToWasm0(position, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
370
+ const len2 = WASM_VECTOR_LEN;
371
+ const ret = wasm.encodeimage_addChunk(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
372
+ if (ret[1]) {
373
+ throw takeFromExternrefTable0(ret[0]);
374
+ }
375
+ }
376
+ /**
377
+ * Adds a `tEXt`, `zTXt` or `iTXt` chunk. `compressed` only matters for
378
+ * `iTXt`, and the language tag and translated keyword are only written
379
+ * there.
380
+ * @param {string} chunk_type
381
+ * @param {string} keyword
382
+ * @param {string} text
383
+ * @param {string} language_tag
384
+ * @param {string} translated_keyword
385
+ * @param {boolean} compressed
386
+ */
387
+ addText(chunk_type, keyword, text, language_tag, translated_keyword, compressed) {
388
+ const ptr0 = passStringToWasm0(chunk_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
389
+ const len0 = WASM_VECTOR_LEN;
390
+ const ptr1 = passStringToWasm0(keyword, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
391
+ const len1 = WASM_VECTOR_LEN;
392
+ const ptr2 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
393
+ const len2 = WASM_VECTOR_LEN;
394
+ const ptr3 = passStringToWasm0(language_tag, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
395
+ const len3 = WASM_VECTOR_LEN;
396
+ const ptr4 = passStringToWasm0(translated_keyword, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
397
+ const len4 = WASM_VECTOR_LEN;
398
+ const ret = wasm.encodeimage_addText(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, compressed);
399
+ if (ret[1]) {
400
+ throw takeFromExternrefTable0(ret[0]);
401
+ }
402
+ }
403
+ /**
404
+ * `colorType` is one of the strings `Header.colorType` returns. `data` is
405
+ * in the PNG's own pixel format; see `format_png::ImageRef`.
406
+ * @param {number} width
407
+ * @param {number} height
408
+ * @param {number} bit_depth
409
+ * @param {string} color_type
410
+ * @param {boolean} interlaced
411
+ * @param {Uint8Array} data
412
+ */
413
+ constructor(width, height, bit_depth, color_type, interlaced, data) {
414
+ const ptr0 = passStringToWasm0(color_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
415
+ const len0 = WASM_VECTOR_LEN;
416
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
417
+ const len1 = WASM_VECTOR_LEN;
418
+ const ret = wasm.encodeimage_new(width, height, bit_depth, ptr0, len0, interlaced, ptr1, len1);
419
+ if (ret[2]) {
420
+ throw takeFromExternrefTable0(ret[1]);
421
+ }
422
+ this.__wbg_ptr = ret[0];
423
+ EncodeImageFinalization.register(this, this.__wbg_ptr, this);
424
+ return this;
425
+ }
426
+ /**
427
+ * `cHRM`: white, red, green and blue x and y, in that order, as fractions.
428
+ * @param {Float64Array} values
429
+ */
430
+ setChromaticities(values) {
431
+ const ptr0 = passArrayF64ToWasm0(values, wasm.__wbindgen_malloc);
432
+ const len0 = WASM_VECTOR_LEN;
433
+ const ret = wasm.encodeimage_setChromaticities(this.__wbg_ptr, ptr0, len0);
434
+ if (ret[1]) {
435
+ throw takeFromExternrefTable0(ret[0]);
436
+ }
437
+ }
438
+ /**
439
+ * `cICP`: H.273 color primaries, transfer function and matrix coefficients,
440
+ * and whether samples use the full range.
441
+ * @param {number} color_primaries
442
+ * @param {number} transfer_function
443
+ * @param {number} matrix_coefficients
444
+ * @param {boolean} full_range
445
+ */
446
+ setCicp(color_primaries, transfer_function, matrix_coefficients, full_range) {
447
+ wasm.encodeimage_setCicp(this.__wbg_ptr, color_primaries, transfer_function, matrix_coefficients, full_range);
448
+ }
449
+ /**
450
+ * `eXIf`: Exif data, starting with its TIFF header, which is checked.
451
+ * @param {Uint8Array} data
452
+ */
453
+ setExif(data) {
454
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
455
+ const len0 = WASM_VECTOR_LEN;
456
+ const ret = wasm.encodeimage_setExif(this.__wbg_ptr, ptr0, len0);
457
+ if (ret[1]) {
458
+ throw takeFromExternrefTable0(ret[0]);
459
+ }
460
+ }
461
+ /**
462
+ * `gAMA`, for example 0.45455.
463
+ * @param {number} gamma
464
+ */
465
+ setGamma(gamma) {
466
+ const ret = wasm.encodeimage_setGamma(this.__wbg_ptr, gamma);
467
+ if (ret[1]) {
468
+ throw takeFromExternrefTable0(ret[0]);
469
+ }
470
+ }
471
+ /**
472
+ * `iCCP`: an ICC profile, uncompressed, and its name. The encoder checks
473
+ * the name and compresses the profile.
474
+ * @param {string} name
475
+ * @param {Uint8Array} profile
476
+ */
477
+ setIccProfile(name, profile) {
478
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
479
+ const len0 = WASM_VECTOR_LEN;
480
+ const ptr1 = passArray8ToWasm0(profile, wasm.__wbindgen_malloc);
481
+ const len1 = WASM_VECTOR_LEN;
482
+ wasm.encodeimage_setIccProfile(this.__wbg_ptr, ptr0, len0, ptr1, len1);
483
+ }
484
+ /**
485
+ * `PLTE`: red, green and blue for each entry, in index order.
486
+ * @param {Uint8Array} colors
487
+ */
488
+ setPalette(colors) {
489
+ const ptr0 = passArray8ToWasm0(colors, wasm.__wbindgen_malloc);
490
+ const len0 = WASM_VECTOR_LEN;
491
+ const ret = wasm.encodeimage_setPalette(this.__wbg_ptr, ptr0, len0);
492
+ if (ret[1]) {
493
+ throw takeFromExternrefTable0(ret[0]);
494
+ }
495
+ }
496
+ /**
497
+ * `pHYs`: pixels per unit, with unit "meter" or "unknown".
498
+ * @param {number} x
499
+ * @param {number} y
500
+ * @param {string} unit
501
+ */
502
+ setPhysicalDimensions(x, y, unit) {
503
+ const ptr0 = passStringToWasm0(unit, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
504
+ const len0 = WASM_VECTOR_LEN;
505
+ const ret = wasm.encodeimage_setPhysicalDimensions(this.__wbg_ptr, x, y, ptr0, len0);
506
+ if (ret[1]) {
507
+ throw takeFromExternrefTable0(ret[0]);
508
+ }
509
+ }
510
+ /**
511
+ * `sRGB`, with one of the intents `Metadata.srgb` returns.
512
+ * @param {string} intent
513
+ */
514
+ setSrgb(intent) {
515
+ const ptr0 = passStringToWasm0(intent, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
516
+ const len0 = WASM_VECTOR_LEN;
517
+ const ret = wasm.encodeimage_setSrgb(this.__wbg_ptr, ptr0, len0);
518
+ if (ret[1]) {
519
+ throw takeFromExternrefTable0(ret[0]);
520
+ }
521
+ }
522
+ /**
523
+ * `tIME`: year, month, day, hour, minute and second, in UTC. The encoder
524
+ * checks the ranges.
525
+ * @param {number} year
526
+ * @param {number} month
527
+ * @param {number} day
528
+ * @param {number} hour
529
+ * @param {number} minute
530
+ * @param {number} second
531
+ */
532
+ setTime(year, month, day, hour, minute, second) {
533
+ wasm.encodeimage_setTime(this.__wbg_ptr, year, month, day, hour, minute, second);
534
+ }
535
+ /**
536
+ * `tRNS`: `kind` is "gray", "rgb" or "palette", and `values` as
537
+ * `ChunkList.transparencyValues` returns them.
538
+ * @param {string} kind
539
+ * @param {Uint16Array} values
540
+ */
541
+ setTransparency(kind, values) {
542
+ const ptr0 = passStringToWasm0(kind, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
543
+ const len0 = WASM_VECTOR_LEN;
544
+ const ptr1 = passArray16ToWasm0(values, wasm.__wbindgen_malloc);
545
+ const len1 = WASM_VECTOR_LEN;
546
+ const ret = wasm.encodeimage_setTransparency(this.__wbg_ptr, ptr0, len0, ptr1, len1);
547
+ if (ret[1]) {
548
+ throw takeFromExternrefTable0(ret[0]);
549
+ }
550
+ }
551
+ }
552
+ if (Symbol.dispose) EncodeImage.prototype[Symbol.dispose] = EncodeImage.prototype.free;
553
+
554
+ /**
555
+ * An encoder that keeps its compressor and buffers between images.
556
+ */
557
+ export class Encoder {
558
+ __destroy_into_raw() {
559
+ const ptr = this.__wbg_ptr;
560
+ this.__wbg_ptr = 0;
561
+ EncoderFinalization.unregister(this);
562
+ return ptr;
563
+ }
564
+ free() {
565
+ const ptr = this.__destroy_into_raw();
566
+ wasm.__wbg_encoder_free(ptr, 0);
567
+ }
568
+ /**
569
+ * @param {EncodeImage} image
570
+ * @returns {Uint8Array}
571
+ */
572
+ encode(image) {
573
+ _assertClass(image, EncodeImage);
574
+ const ret = wasm.encoder_encode(this.__wbg_ptr, image.__wbg_ptr);
575
+ if (ret[3]) {
576
+ throw takeFromExternrefTable0(ret[2]);
577
+ }
578
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
579
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
580
+ return v1;
581
+ }
582
+ /**
583
+ * `compression` is 0 to 9. `compressionStrategy` is "dynamic", "fixed" or
584
+ * "stored"; `filter` is "adaptive", "none", "sub", "up", "average" or
585
+ * "paeth"; `palette` is "keep" or "auto"; `strip` is "keep", "safe" or "all".
586
+ * @param {number} compression
587
+ * @param {string} compression_strategy
588
+ * @param {string} filter
589
+ * @param {boolean} keep_unsafe_chunks
590
+ * @param {string} palette
591
+ * @param {string} strip
592
+ */
593
+ constructor(compression, compression_strategy, filter, keep_unsafe_chunks, palette, strip) {
594
+ const ptr0 = passStringToWasm0(compression_strategy, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
595
+ const len0 = WASM_VECTOR_LEN;
596
+ const ptr1 = passStringToWasm0(filter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
597
+ const len1 = WASM_VECTOR_LEN;
598
+ const ptr2 = passStringToWasm0(palette, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
599
+ const len2 = WASM_VECTOR_LEN;
600
+ const ptr3 = passStringToWasm0(strip, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
601
+ const len3 = WASM_VECTOR_LEN;
602
+ const ret = wasm.encoder_new(compression, ptr0, len0, ptr1, len1, keep_unsafe_chunks, ptr2, len2, ptr3, len3);
603
+ if (ret[2]) {
604
+ throw takeFromExternrefTable0(ret[1]);
605
+ }
606
+ this.__wbg_ptr = ret[0];
607
+ EncoderFinalization.register(this, this.__wbg_ptr, this);
608
+ return this;
609
+ }
610
+ }
611
+ if (Symbol.dispose) Encoder.prototype[Symbol.dispose] = Encoder.prototype.free;
612
+
613
+ /**
614
+ * The contents of the `IHDR` chunk.
615
+ */
616
+ export class Header {
617
+ static __wrap(ptr) {
618
+ const obj = Object.create(Header.prototype);
619
+ obj.__wbg_ptr = ptr;
620
+ HeaderFinalization.register(obj, obj.__wbg_ptr, obj);
621
+ return obj;
622
+ }
623
+ __destroy_into_raw() {
624
+ const ptr = this.__wbg_ptr;
625
+ this.__wbg_ptr = 0;
626
+ HeaderFinalization.unregister(this);
627
+ return ptr;
628
+ }
629
+ free() {
630
+ const ptr = this.__destroy_into_raw();
631
+ wasm.__wbg_header_free(ptr, 0);
632
+ }
633
+ /**
634
+ * @returns {number}
635
+ */
636
+ get bitDepth() {
637
+ const ret = wasm.__wbg_get_header_bitDepth(this.__wbg_ptr);
638
+ return ret;
639
+ }
640
+ /**
641
+ * @returns {number}
642
+ */
643
+ get height() {
644
+ const ret = wasm.__wbg_get_header_height(this.__wbg_ptr);
645
+ return ret >>> 0;
646
+ }
647
+ /**
648
+ * @returns {boolean}
649
+ */
650
+ get interlaced() {
651
+ const ret = wasm.__wbg_get_header_interlaced(this.__wbg_ptr);
652
+ return ret !== 0;
653
+ }
654
+ /**
655
+ * @returns {number}
656
+ */
657
+ get width() {
658
+ const ret = wasm.__wbg_get_header_width(this.__wbg_ptr);
659
+ return ret >>> 0;
660
+ }
661
+ /**
662
+ * "grayscale", "rgb", "indexed", "grayscale-alpha" or "rgba".
663
+ * @returns {string}
664
+ */
665
+ get colorType() {
666
+ let deferred1_0;
667
+ let deferred1_1;
668
+ try {
669
+ const ret = wasm.header_colorType(this.__wbg_ptr);
670
+ deferred1_0 = ret[0];
671
+ deferred1_1 = ret[1];
672
+ return getStringFromWasm0(ret[0], ret[1]);
673
+ } finally {
674
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
675
+ }
676
+ }
677
+ }
678
+ if (Symbol.dispose) Header.prototype[Symbol.dispose] = Header.prototype.free;
679
+
680
+ /**
681
+ * The known ancillary chunks. Each getter is `undefined` if the chunk is absent.
682
+ */
683
+ export class Metadata {
684
+ static __wrap(ptr) {
685
+ const obj = Object.create(Metadata.prototype);
686
+ obj.__wbg_ptr = ptr;
687
+ MetadataFinalization.register(obj, obj.__wbg_ptr, obj);
688
+ return obj;
689
+ }
690
+ __destroy_into_raw() {
691
+ const ptr = this.__wbg_ptr;
692
+ this.__wbg_ptr = 0;
693
+ MetadataFinalization.unregister(this);
694
+ return ptr;
695
+ }
696
+ free() {
697
+ const ptr = this.__destroy_into_raw();
698
+ wasm.__wbg_metadata_free(ptr, 0);
699
+ }
700
+ /**
701
+ * `cHRM`: white, red, green and blue x and y, in that order, as fractions.
702
+ * @returns {Float64Array | undefined}
703
+ */
704
+ get chromaticities() {
705
+ const ret = wasm.metadata_chromaticities(this.__wbg_ptr);
706
+ let v1;
707
+ if (ret[0] !== 0) {
708
+ v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
709
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
710
+ }
711
+ return v1;
712
+ }
713
+ /**
714
+ * `cICP`: color primaries, transfer function, matrix coefficients and the
715
+ * full-range flag (1 or 0), in that order.
716
+ * @returns {Uint8Array | undefined}
717
+ */
718
+ get cicp() {
719
+ const ret = wasm.metadata_cicp(this.__wbg_ptr);
720
+ let v1;
721
+ if (ret[0] !== 0) {
722
+ v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
723
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
724
+ }
725
+ return v1;
726
+ }
727
+ /**
728
+ * `eXIf`: "big-endian" or "little-endian".
729
+ * @returns {string | undefined}
730
+ */
731
+ get exifByteOrder() {
732
+ const ret = wasm.metadata_exifByteOrder(this.__wbg_ptr);
733
+ let v1;
734
+ if (ret[0] !== 0) {
735
+ v1 = getStringFromWasm0(ret[0], ret[1]);
736
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
737
+ }
738
+ return v1;
739
+ }
740
+ /**
741
+ * `eXIf`: the Exif data, raw, starting with its TIFF header.
742
+ * @returns {Uint8Array | undefined}
743
+ */
744
+ get exif() {
745
+ const ret = wasm.metadata_exif(this.__wbg_ptr);
746
+ let v1;
747
+ if (ret[0] !== 0) {
748
+ v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
749
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
750
+ }
751
+ return v1;
752
+ }
753
+ /**
754
+ * `gAMA`, for example 0.45455.
755
+ * @returns {number | undefined}
756
+ */
757
+ get gamma() {
758
+ const ret = wasm.metadata_gamma(this.__wbg_ptr);
759
+ return ret[0] === 0 ? undefined : ret[1];
760
+ }
761
+ /**
762
+ * `iCCP`: the profile's name.
763
+ * @returns {string | undefined}
764
+ */
765
+ get iccProfileName() {
766
+ const ret = wasm.metadata_iccProfileName(this.__wbg_ptr);
767
+ let v1;
768
+ if (ret[0] !== 0) {
769
+ v1 = getStringFromWasm0(ret[0], ret[1]);
770
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
771
+ }
772
+ return v1;
773
+ }
774
+ /**
775
+ * `iCCP`: the ICC profile, decompressed.
776
+ * @returns {Uint8Array | undefined}
777
+ */
778
+ get iccProfile() {
779
+ const ret = wasm.metadata_iccProfile(this.__wbg_ptr);
780
+ let v1;
781
+ if (ret[0] !== 0) {
782
+ v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
783
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
784
+ }
785
+ return v1;
786
+ }
787
+ /**
788
+ * `pHYs`: pixels per unit, x then y.
789
+ * @returns {Uint32Array | undefined}
790
+ */
791
+ get physicalPixelsPerUnit() {
792
+ const ret = wasm.metadata_physicalPixelsPerUnit(this.__wbg_ptr);
793
+ let v1;
794
+ if (ret[0] !== 0) {
795
+ v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
796
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
797
+ }
798
+ return v1;
799
+ }
800
+ /**
801
+ * `pHYs` unit: "meter" or "unknown" (the values are only an aspect ratio).
802
+ * @returns {string | undefined}
803
+ */
804
+ get physicalUnit() {
805
+ const ret = wasm.metadata_physicalUnit(this.__wbg_ptr);
806
+ let v1;
807
+ if (ret[0] !== 0) {
808
+ v1 = getStringFromWasm0(ret[0], ret[1]);
809
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
810
+ }
811
+ return v1;
812
+ }
813
+ /**
814
+ * `sRGB`: "perceptual", "relative-colorimetric", "saturation" or "absolute-colorimetric".
815
+ * @returns {string | undefined}
816
+ */
817
+ get srgb() {
818
+ const ret = wasm.metadata_srgb(this.__wbg_ptr);
819
+ let v1;
820
+ if (ret[0] !== 0) {
821
+ v1 = getStringFromWasm0(ret[0], ret[1]);
822
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
823
+ }
824
+ return v1;
825
+ }
826
+ /**
827
+ * `tEXt`, `zTXt` and `iTXt`, in file order.
828
+ * @returns {Text[]}
829
+ */
830
+ text() {
831
+ const ret = wasm.metadata_text(this.__wbg_ptr);
832
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
833
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
834
+ return v1;
835
+ }
836
+ /**
837
+ * `tIME`: year, month, day, hour, minute and second, in UTC.
838
+ * @returns {Uint16Array | undefined}
839
+ */
840
+ get time() {
841
+ const ret = wasm.metadata_time(this.__wbg_ptr);
842
+ let v1;
843
+ if (ret[0] !== 0) {
844
+ v1 = getArrayU16FromWasm0(ret[0], ret[1]).slice();
845
+ wasm.__wbindgen_free(ret[0], ret[1] * 2, 2);
846
+ }
847
+ return v1;
848
+ }
849
+ }
850
+ if (Symbol.dispose) Metadata.prototype[Symbol.dispose] = Metadata.prototype.free;
851
+
852
+ /**
853
+ * A decoded image in the file's own format, from `decode`. JavaScript reads
854
+ * the header, palette, transparency, `metadata()` and `takeChunks()`, then
855
+ * calls `intoData()` once, which copies the samples out and frees this object.
856
+ */
857
+ export class RawImage {
858
+ static __wrap(ptr) {
859
+ const obj = Object.create(RawImage.prototype);
860
+ obj.__wbg_ptr = ptr;
861
+ RawImageFinalization.register(obj, obj.__wbg_ptr, obj);
862
+ return obj;
863
+ }
864
+ __destroy_into_raw() {
865
+ const ptr = this.__wbg_ptr;
866
+ this.__wbg_ptr = 0;
867
+ RawImageFinalization.unregister(this);
868
+ return ptr;
869
+ }
870
+ free() {
871
+ const ptr = this.__destroy_into_raw();
872
+ wasm.__wbg_rawimage_free(ptr, 0);
873
+ }
874
+ /**
875
+ * @returns {Header}
876
+ */
877
+ header() {
878
+ const ret = wasm.rawimage_header(this.__wbg_ptr);
879
+ return Header.__wrap(ret);
880
+ }
881
+ /**
882
+ * The samples in the file's own layout: rows of the header's stride, 16-bit
883
+ * samples big-endian, pixels under 8 bits packed with each row padded to a
884
+ * whole byte, palette indices for indexed images. Consumes the image.
885
+ * @returns {Uint8Array}
886
+ */
887
+ intoData() {
888
+ const ptr = this.__destroy_into_raw();
889
+ const ret = wasm.rawimage_intoData(ptr);
890
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
891
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
892
+ return v1;
893
+ }
894
+ /**
895
+ * The parsed ancillary chunks; empty unless `preserveMetadata` was set.
896
+ * @returns {Metadata}
897
+ */
898
+ metadata() {
899
+ const ret = wasm.rawimage_metadata(this.__wbg_ptr);
900
+ return Metadata.__wrap(ret);
901
+ }
902
+ /**
903
+ * `PLTE`: red, green and blue for each entry, in index order.
904
+ * @returns {Uint8Array | undefined}
905
+ */
906
+ get palette() {
907
+ const ret = wasm.rawimage_palette(this.__wbg_ptr);
908
+ let v1;
909
+ if (ret[0] !== 0) {
910
+ v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
911
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
912
+ }
913
+ return v1;
914
+ }
915
+ /**
916
+ * The raw ancillary chunks; empty unless `preserveChunks` was set.
917
+ * @returns {Chunk[]}
918
+ */
919
+ takeChunks() {
920
+ const ret = wasm.rawimage_takeChunks(this.__wbg_ptr);
921
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
922
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
923
+ return v1;
924
+ }
925
+ /**
926
+ * `tRNS`: "gray", "rgb" or "palette".
927
+ * @returns {string | undefined}
928
+ */
929
+ get transparencyKind() {
930
+ const ret = wasm.rawimage_transparencyKind(this.__wbg_ptr);
931
+ let v1;
932
+ if (ret[0] !== 0) {
933
+ v1 = getStringFromWasm0(ret[0], ret[1]);
934
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
935
+ }
936
+ return v1;
937
+ }
938
+ /**
939
+ * `tRNS`, as `ChunkList.transparencyValues`.
940
+ * @returns {Uint16Array | undefined}
941
+ */
942
+ get transparencyValues() {
943
+ const ret = wasm.rawimage_transparencyValues(this.__wbg_ptr);
944
+ let v1;
945
+ if (ret[0] !== 0) {
946
+ v1 = getArrayU16FromWasm0(ret[0], ret[1]).slice();
947
+ wasm.__wbindgen_free(ret[0], ret[1] * 2, 2);
948
+ }
949
+ return v1;
950
+ }
951
+ }
952
+ if (Symbol.dispose) RawImage.prototype[Symbol.dispose] = RawImage.prototype.free;
953
+
954
+ /**
955
+ * A `tEXt`, `zTXt` or `iTXt` chunk, decoded. JavaScript reads the getters, then
956
+ * calls `free()`.
957
+ */
958
+ export class Text {
959
+ static __wrap(ptr) {
960
+ const obj = Object.create(Text.prototype);
961
+ obj.__wbg_ptr = ptr;
962
+ TextFinalization.register(obj, obj.__wbg_ptr, obj);
963
+ return obj;
964
+ }
965
+ __destroy_into_raw() {
966
+ const ptr = this.__wbg_ptr;
967
+ this.__wbg_ptr = 0;
968
+ TextFinalization.unregister(this);
969
+ return ptr;
970
+ }
971
+ free() {
972
+ const ptr = this.__destroy_into_raw();
973
+ wasm.__wbg_text_free(ptr, 0);
974
+ }
975
+ /**
976
+ * "tEXt", "zTXt" or "iTXt".
977
+ * @returns {string}
978
+ */
979
+ get chunkType() {
980
+ let deferred1_0;
981
+ let deferred1_1;
982
+ try {
983
+ const ret = wasm.text_chunkType(this.__wbg_ptr);
984
+ deferred1_0 = ret[0];
985
+ deferred1_1 = ret[1];
986
+ return getStringFromWasm0(ret[0], ret[1]);
987
+ } finally {
988
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
989
+ }
990
+ }
991
+ /**
992
+ * Whether the text was zlib-compressed in the file.
993
+ * @returns {boolean}
994
+ */
995
+ get compressed() {
996
+ const ret = wasm.text_compressed(this.__wbg_ptr);
997
+ return ret !== 0;
998
+ }
999
+ /**
1000
+ * @returns {string}
1001
+ */
1002
+ get keyword() {
1003
+ let deferred1_0;
1004
+ let deferred1_1;
1005
+ try {
1006
+ const ret = wasm.text_keyword(this.__wbg_ptr);
1007
+ deferred1_0 = ret[0];
1008
+ deferred1_1 = ret[1];
1009
+ return getStringFromWasm0(ret[0], ret[1]);
1010
+ } finally {
1011
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1012
+ }
1013
+ }
1014
+ /**
1015
+ * @returns {string}
1016
+ */
1017
+ get languageTag() {
1018
+ let deferred1_0;
1019
+ let deferred1_1;
1020
+ try {
1021
+ const ret = wasm.text_languageTag(this.__wbg_ptr);
1022
+ deferred1_0 = ret[0];
1023
+ deferred1_1 = ret[1];
1024
+ return getStringFromWasm0(ret[0], ret[1]);
1025
+ } finally {
1026
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1027
+ }
1028
+ }
1029
+ /**
1030
+ * @returns {string}
1031
+ */
1032
+ get text() {
1033
+ let deferred1_0;
1034
+ let deferred1_1;
1035
+ try {
1036
+ const ret = wasm.text_text(this.__wbg_ptr);
1037
+ deferred1_0 = ret[0];
1038
+ deferred1_1 = ret[1];
1039
+ return getStringFromWasm0(ret[0], ret[1]);
1040
+ } finally {
1041
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1042
+ }
1043
+ }
1044
+ /**
1045
+ * @returns {string}
1046
+ */
1047
+ get translatedKeyword() {
1048
+ let deferred1_0;
1049
+ let deferred1_1;
1050
+ try {
1051
+ const ret = wasm.text_translatedKeyword(this.__wbg_ptr);
1052
+ deferred1_0 = ret[0];
1053
+ deferred1_1 = ret[1];
1054
+ return getStringFromWasm0(ret[0], ret[1]);
1055
+ } finally {
1056
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1057
+ }
1058
+ }
1059
+ }
1060
+ if (Symbol.dispose) Text.prototype[Symbol.dispose] = Text.prototype.free;
1061
+
1062
+ /**
1063
+ * Decodes a PNG in its own format with a one-off decoder.
1064
+ * @param {Uint8Array} bytes
1065
+ * @param {boolean} validate_crc
1066
+ * @param {boolean} preserve_metadata
1067
+ * @param {boolean} preserve_chunks
1068
+ * @param {boolean} strict_ancillary
1069
+ * @returns {RawImage}
1070
+ */
1071
+ export function decode(bytes, validate_crc, preserve_metadata, preserve_chunks, strict_ancillary) {
1072
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
1073
+ const len0 = WASM_VECTOR_LEN;
1074
+ const ret = wasm.decode(ptr0, len0, validate_crc, preserve_metadata, preserve_chunks, strict_ancillary);
1075
+ if (ret[2]) {
1076
+ throw takeFromExternrefTable0(ret[1]);
1077
+ }
1078
+ return RawImage.__wrap(ret[0]);
1079
+ }
1080
+
1081
+ /**
1082
+ * Decodes a PNG to RGBA8 with a one-off decoder.
1083
+ * @param {Uint8Array} bytes
1084
+ * @param {boolean} validate_crc
1085
+ * @param {boolean} preserve_metadata
1086
+ * @param {boolean} preserve_chunks
1087
+ * @param {boolean} strict_ancillary
1088
+ * @returns {DecodedImage}
1089
+ */
1090
+ export function decodeRgba8(bytes, validate_crc, preserve_metadata, preserve_chunks, strict_ancillary) {
1091
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
1092
+ const len0 = WASM_VECTOR_LEN;
1093
+ const ret = wasm.decodeRgba8(ptr0, len0, validate_crc, preserve_metadata, preserve_chunks, strict_ancillary);
1094
+ if (ret[2]) {
1095
+ throw takeFromExternrefTable0(ret[1]);
1096
+ }
1097
+ return DecodedImage.__wrap(ret[0]);
1098
+ }
1099
+
1100
+ /**
1101
+ * Encodes an image with a one-off encoder.
1102
+ * @param {EncodeImage} image
1103
+ * @param {number} compression
1104
+ * @param {string} compression_strategy
1105
+ * @param {string} filter
1106
+ * @param {boolean} keep_unsafe_chunks
1107
+ * @param {string} palette
1108
+ * @param {string} strip
1109
+ * @returns {Uint8Array}
1110
+ */
1111
+ export function encode(image, compression, compression_strategy, filter, keep_unsafe_chunks, palette, strip) {
1112
+ _assertClass(image, EncodeImage);
1113
+ const ptr0 = passStringToWasm0(compression_strategy, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1114
+ const len0 = WASM_VECTOR_LEN;
1115
+ const ptr1 = passStringToWasm0(filter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1116
+ const len1 = WASM_VECTOR_LEN;
1117
+ const ptr2 = passStringToWasm0(palette, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1118
+ const len2 = WASM_VECTOR_LEN;
1119
+ const ptr3 = passStringToWasm0(strip, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1120
+ const len3 = WASM_VECTOR_LEN;
1121
+ const ret = wasm.encode(image.__wbg_ptr, compression, ptr0, len0, ptr1, len1, keep_unsafe_chunks, ptr2, len2, ptr3, len3);
1122
+ if (ret[3]) {
1123
+ throw takeFromExternrefTable0(ret[2]);
1124
+ }
1125
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1126
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1127
+ return v5;
1128
+ }
1129
+
1130
+ /**
1131
+ * Parses the data of a `tEXt`, `zTXt` or `iTXt` chunk on its own.
1132
+ * @param {string} chunk_type
1133
+ * @param {Uint8Array} data
1134
+ * @returns {Text}
1135
+ */
1136
+ export function parseText(chunk_type, data) {
1137
+ const ptr0 = passStringToWasm0(chunk_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1138
+ const len0 = WASM_VECTOR_LEN;
1139
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
1140
+ const len1 = WASM_VECTOR_LEN;
1141
+ const ret = wasm.parseText(ptr0, len0, ptr1, len1);
1142
+ if (ret[2]) {
1143
+ throw takeFromExternrefTable0(ret[1]);
1144
+ }
1145
+ return Text.__wrap(ret[0]);
1146
+ }
1147
+
1148
+ /**
1149
+ * Reads and parses every chunk without decompressing the image data.
1150
+ * @param {Uint8Array} bytes
1151
+ * @param {boolean} validate_crc
1152
+ * @param {boolean} strict_ancillary
1153
+ * @returns {ChunkList}
1154
+ */
1155
+ export function readChunks(bytes, validate_crc, strict_ancillary) {
1156
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
1157
+ const len0 = WASM_VECTOR_LEN;
1158
+ const ret = wasm.readChunks(ptr0, len0, validate_crc, strict_ancillary);
1159
+ if (ret[2]) {
1160
+ throw takeFromExternrefTable0(ret[1]);
1161
+ }
1162
+ return ChunkList.__wrap(ret[0]);
1163
+ }
1164
+
1165
+ /**
1166
+ * Reads only the header.
1167
+ * @param {Uint8Array} bytes
1168
+ * @returns {Header}
1169
+ */
1170
+ export function readHeader(bytes) {
1171
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
1172
+ const len0 = WASM_VECTOR_LEN;
1173
+ const ret = wasm.readHeader(ptr0, len0);
1174
+ if (ret[2]) {
1175
+ throw takeFromExternrefTable0(ret[1]);
1176
+ }
1177
+ return Header.__wrap(ret[0]);
1178
+ }
1179
+ function __wbg_get_imports() {
1180
+ const import0 = {
1181
+ __proto__: null,
1182
+ __wbg_Error_67e7344beaa85059: function(arg0, arg1) {
1183
+ const ret = Error(getStringFromWasm0(arg0, arg1));
1184
+ return ret;
1185
+ },
1186
+ __wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
1187
+ throw new Error(getStringFromWasm0(arg0, arg1));
1188
+ },
1189
+ __wbg_chunk_new: function(arg0) {
1190
+ const ret = Chunk.__wrap(arg0);
1191
+ return ret;
1192
+ },
1193
+ __wbg_text_new: function(arg0) {
1194
+ const ret = Text.__wrap(arg0);
1195
+ return ret;
1196
+ },
1197
+ __wbindgen_init_externref_table: function() {
1198
+ const table = wasm.__wbindgen_externrefs;
1199
+ const offset = table.grow(4);
1200
+ table.set(0, undefined);
1201
+ table.set(offset + 0, undefined);
1202
+ table.set(offset + 1, null);
1203
+ table.set(offset + 2, true);
1204
+ table.set(offset + 3, false);
1205
+ },
1206
+ };
1207
+ return {
1208
+ __proto__: null,
1209
+ "./format_png_wasm_bg.js": import0,
1210
+ };
1211
+ }
1212
+
1213
+ const ChunkFinalization = (typeof FinalizationRegistry === 'undefined')
1214
+ ? { register: () => {}, unregister: () => {} }
1215
+ : new FinalizationRegistry(ptr => wasm.__wbg_chunk_free(ptr, 1));
1216
+ const ChunkListFinalization = (typeof FinalizationRegistry === 'undefined')
1217
+ ? { register: () => {}, unregister: () => {} }
1218
+ : new FinalizationRegistry(ptr => wasm.__wbg_chunklist_free(ptr, 1));
1219
+ const DecodedImageFinalization = (typeof FinalizationRegistry === 'undefined')
1220
+ ? { register: () => {}, unregister: () => {} }
1221
+ : new FinalizationRegistry(ptr => wasm.__wbg_decodedimage_free(ptr, 1));
1222
+ const DecoderFinalization = (typeof FinalizationRegistry === 'undefined')
1223
+ ? { register: () => {}, unregister: () => {} }
1224
+ : new FinalizationRegistry(ptr => wasm.__wbg_decoder_free(ptr, 1));
1225
+ const EncodeImageFinalization = (typeof FinalizationRegistry === 'undefined')
1226
+ ? { register: () => {}, unregister: () => {} }
1227
+ : new FinalizationRegistry(ptr => wasm.__wbg_encodeimage_free(ptr, 1));
1228
+ const EncoderFinalization = (typeof FinalizationRegistry === 'undefined')
1229
+ ? { register: () => {}, unregister: () => {} }
1230
+ : new FinalizationRegistry(ptr => wasm.__wbg_encoder_free(ptr, 1));
1231
+ const HeaderFinalization = (typeof FinalizationRegistry === 'undefined')
1232
+ ? { register: () => {}, unregister: () => {} }
1233
+ : new FinalizationRegistry(ptr => wasm.__wbg_header_free(ptr, 1));
1234
+ const MetadataFinalization = (typeof FinalizationRegistry === 'undefined')
1235
+ ? { register: () => {}, unregister: () => {} }
1236
+ : new FinalizationRegistry(ptr => wasm.__wbg_metadata_free(ptr, 1));
1237
+ const RawImageFinalization = (typeof FinalizationRegistry === 'undefined')
1238
+ ? { register: () => {}, unregister: () => {} }
1239
+ : new FinalizationRegistry(ptr => wasm.__wbg_rawimage_free(ptr, 1));
1240
+ const TextFinalization = (typeof FinalizationRegistry === 'undefined')
1241
+ ? { register: () => {}, unregister: () => {} }
1242
+ : new FinalizationRegistry(ptr => wasm.__wbg_text_free(ptr, 1));
1243
+
1244
+ function _assertClass(instance, klass) {
1245
+ if (!(instance instanceof klass)) {
1246
+ throw new Error(`expected instance of ${klass.name}`);
1247
+ }
1248
+ }
1249
+
1250
+ function getArrayF64FromWasm0(ptr, len) {
1251
+ ptr = ptr >>> 0;
1252
+ return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
1253
+ }
1254
+
1255
+ function getArrayJsValueFromWasm0(ptr, len) {
1256
+ ptr = ptr >>> 0;
1257
+ const mem = getDataViewMemory0();
1258
+ const result = [];
1259
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
1260
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
1261
+ }
1262
+ wasm.__externref_drop_slice(ptr, len);
1263
+ return result;
1264
+ }
1265
+
1266
+ function getArrayU16FromWasm0(ptr, len) {
1267
+ ptr = ptr >>> 0;
1268
+ return getUint16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
1269
+ }
1270
+
1271
+ function getArrayU32FromWasm0(ptr, len) {
1272
+ ptr = ptr >>> 0;
1273
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
1274
+ }
1275
+
1276
+ function getArrayU8FromWasm0(ptr, len) {
1277
+ ptr = ptr >>> 0;
1278
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
1279
+ }
1280
+
1281
+ let cachedDataViewMemory0 = null;
1282
+ function getDataViewMemory0() {
1283
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
1284
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
1285
+ }
1286
+ return cachedDataViewMemory0;
1287
+ }
1288
+
1289
+ let cachedFloat64ArrayMemory0 = null;
1290
+ function getFloat64ArrayMemory0() {
1291
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
1292
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
1293
+ }
1294
+ return cachedFloat64ArrayMemory0;
1295
+ }
1296
+
1297
+ function getStringFromWasm0(ptr, len) {
1298
+ return decodeText(ptr >>> 0, len);
1299
+ }
1300
+
1301
+ let cachedUint16ArrayMemory0 = null;
1302
+ function getUint16ArrayMemory0() {
1303
+ if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
1304
+ cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
1305
+ }
1306
+ return cachedUint16ArrayMemory0;
1307
+ }
1308
+
1309
+ let cachedUint32ArrayMemory0 = null;
1310
+ function getUint32ArrayMemory0() {
1311
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
1312
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
1313
+ }
1314
+ return cachedUint32ArrayMemory0;
1315
+ }
1316
+
1317
+ let cachedUint8ArrayMemory0 = null;
1318
+ function getUint8ArrayMemory0() {
1319
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
1320
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
1321
+ }
1322
+ return cachedUint8ArrayMemory0;
1323
+ }
1324
+
1325
+ function passArray16ToWasm0(arg, malloc) {
1326
+ const ptr = malloc(arg.length * 2, 2) >>> 0;
1327
+ getUint16ArrayMemory0().set(arg, ptr / 2);
1328
+ WASM_VECTOR_LEN = arg.length;
1329
+ return ptr;
1330
+ }
1331
+
1332
+ function passArray8ToWasm0(arg, malloc) {
1333
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
1334
+ getUint8ArrayMemory0().set(arg, ptr / 1);
1335
+ WASM_VECTOR_LEN = arg.length;
1336
+ return ptr;
1337
+ }
1338
+
1339
+ function passArrayF64ToWasm0(arg, malloc) {
1340
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
1341
+ getFloat64ArrayMemory0().set(arg, ptr / 8);
1342
+ WASM_VECTOR_LEN = arg.length;
1343
+ return ptr;
1344
+ }
1345
+
1346
+ function passStringToWasm0(arg, malloc, realloc) {
1347
+ if (realloc === undefined) {
1348
+ const buf = cachedTextEncoder.encode(arg);
1349
+ const ptr = malloc(buf.length, 1) >>> 0;
1350
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
1351
+ WASM_VECTOR_LEN = buf.length;
1352
+ return ptr;
1353
+ }
1354
+
1355
+ let len = arg.length;
1356
+ let ptr = malloc(len, 1) >>> 0;
1357
+
1358
+ const mem = getUint8ArrayMemory0();
1359
+
1360
+ let offset = 0;
1361
+
1362
+ for (; offset < len; offset++) {
1363
+ const code = arg.charCodeAt(offset);
1364
+ if (code > 0x7F) break;
1365
+ mem[ptr + offset] = code;
1366
+ }
1367
+ if (offset !== len) {
1368
+ if (offset !== 0) {
1369
+ arg = arg.slice(offset);
1370
+ }
1371
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
1372
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
1373
+ const ret = cachedTextEncoder.encodeInto(arg, view);
1374
+
1375
+ offset += ret.written;
1376
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
1377
+ }
1378
+
1379
+ WASM_VECTOR_LEN = offset;
1380
+ return ptr;
1381
+ }
1382
+
1383
+ function takeFromExternrefTable0(idx) {
1384
+ const value = wasm.__wbindgen_externrefs.get(idx);
1385
+ wasm.__externref_table_dealloc(idx);
1386
+ return value;
1387
+ }
1388
+
1389
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1390
+ cachedTextDecoder.decode();
1391
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
1392
+ let numBytesDecoded = 0;
1393
+ function decodeText(ptr, len) {
1394
+ numBytesDecoded += len;
1395
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
1396
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1397
+ cachedTextDecoder.decode();
1398
+ numBytesDecoded = len;
1399
+ }
1400
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1401
+ }
1402
+
1403
+ const cachedTextEncoder = new TextEncoder();
1404
+
1405
+ if (!('encodeInto' in cachedTextEncoder)) {
1406
+ cachedTextEncoder.encodeInto = function (arg, view) {
1407
+ const buf = cachedTextEncoder.encode(arg);
1408
+ view.set(buf);
1409
+ return {
1410
+ read: arg.length,
1411
+ written: buf.length
1412
+ };
1413
+ };
1414
+ }
1415
+
1416
+ let WASM_VECTOR_LEN = 0;
1417
+
1418
+ let wasmModule, wasmInstance, wasm;
1419
+ function __wbg_finalize_init(instance, module) {
1420
+ wasmInstance = instance;
1421
+ wasm = instance.exports;
1422
+ wasmModule = module;
1423
+ cachedDataViewMemory0 = null;
1424
+ cachedFloat64ArrayMemory0 = null;
1425
+ cachedUint16ArrayMemory0 = null;
1426
+ cachedUint32ArrayMemory0 = null;
1427
+ cachedUint8ArrayMemory0 = null;
1428
+ wasm.__wbindgen_start();
1429
+ return wasm;
1430
+ }
1431
+
1432
+ async function __wbg_load(module, imports) {
1433
+ if (typeof Response === 'function' && module instanceof Response) {
1434
+ if (!module.ok) {
1435
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
1436
+ }
1437
+
1438
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1439
+ try {
1440
+ return await WebAssembly.instantiateStreaming(module, imports);
1441
+ } catch (e) {
1442
+ const validResponse = expectedResponseType(module.type);
1443
+
1444
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1445
+ 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);
1446
+
1447
+ } else { throw e; }
1448
+ }
1449
+ }
1450
+
1451
+ const bytes = await module.arrayBuffer();
1452
+ return await WebAssembly.instantiate(bytes, imports);
1453
+ } else {
1454
+ const instance = await WebAssembly.instantiate(module, imports);
1455
+
1456
+ if (instance instanceof WebAssembly.Instance) {
1457
+ return { instance, module };
1458
+ } else {
1459
+ return instance;
1460
+ }
1461
+ }
1462
+
1463
+ function expectedResponseType(type) {
1464
+ switch (type) {
1465
+ case 'basic': case 'cors': case 'default': return true;
1466
+ }
1467
+ return false;
1468
+ }
1469
+ }
1470
+
1471
+ function initSync(module) {
1472
+ if (wasm !== undefined) return wasm;
1473
+
1474
+
1475
+ if (module !== undefined) {
1476
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1477
+ ({module} = module)
1478
+ } else {
1479
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1480
+ }
1481
+ }
1482
+
1483
+ const imports = __wbg_get_imports();
1484
+ if (!(module instanceof WebAssembly.Module)) {
1485
+ module = new WebAssembly.Module(module);
1486
+ }
1487
+ const instance = new WebAssembly.Instance(module, imports);
1488
+ return __wbg_finalize_init(instance, module);
1489
+ }
1490
+
1491
+ async function __wbg_init(module_or_path) {
1492
+ if (wasm !== undefined) return wasm;
1493
+
1494
+
1495
+ if (module_or_path !== undefined) {
1496
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1497
+ ({module_or_path} = module_or_path)
1498
+ } else {
1499
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1500
+ }
1501
+ }
1502
+
1503
+ if (module_or_path === undefined) {
1504
+ module_or_path = new URL('format_png_wasm_bg.wasm', import.meta.url);
1505
+ }
1506
+ const imports = __wbg_get_imports();
1507
+
1508
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1509
+ module_or_path = fetch(module_or_path);
1510
+ }
1511
+
1512
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1513
+
1514
+ return __wbg_finalize_init(instance, module);
1515
+ }
1516
+
1517
+ export { initSync, __wbg_init as default };