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,473 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * A raw ancillary chunk. JavaScript reads `chunkType` and `position`, then calls
6
+ * `intoData()` once, which copies the data out and frees this object.
7
+ */
8
+ export class Chunk {
9
+ private constructor();
10
+ free(): void;
11
+ [Symbol.dispose](): void;
12
+ /**
13
+ * The chunk's data, without length, type and CRC. Consumes the chunk.
14
+ */
15
+ intoData(): Uint8Array;
16
+ /**
17
+ * The four-letter type, for example "tEXt".
18
+ */
19
+ readonly chunkType: string;
20
+ /**
21
+ * "before-palette", "before-image-data" or "after-image-data".
22
+ */
23
+ readonly position: string;
24
+ }
25
+
26
+ /**
27
+ * Every chunk of a PNG, from `read_chunks`. The raw chunks are flat arrays,
28
+ * one entry per chunk in file order, so JavaScript can view their data in the
29
+ * input it already has instead of copying it out of wasm memory.
30
+ */
31
+ export class ChunkList {
32
+ private constructor();
33
+ free(): void;
34
+ [Symbol.dispose](): void;
35
+ header(): Header;
36
+ metadata(): Metadata;
37
+ readonly crcs: Uint32Array;
38
+ /**
39
+ * 1 for each chunk this crate parses, 0 for unknown ones.
40
+ */
41
+ readonly known: Uint8Array;
42
+ /**
43
+ * The length of each chunk's data.
44
+ */
45
+ readonly lengths: Uint32Array;
46
+ /**
47
+ * Where each chunk starts in the input: its length field.
48
+ */
49
+ readonly offsets: Uint32Array;
50
+ /**
51
+ * `PLTE`: red, green and blue for each entry, in index order.
52
+ */
53
+ readonly palette: Uint8Array | undefined;
54
+ /**
55
+ * `tRNS`: "gray", "rgb" or "palette".
56
+ */
57
+ readonly transparencyKind: string | undefined;
58
+ /**
59
+ * `tRNS`: the transparent gray value, the transparent red, green and blue,
60
+ * or an alpha for each palette entry.
61
+ */
62
+ readonly transparencyValues: Uint16Array | undefined;
63
+ /**
64
+ * The four-letter types of every chunk, joined.
65
+ */
66
+ readonly types: string;
67
+ }
68
+
69
+ /**
70
+ * A decoded RGBA8 image. JavaScript reads `width`, `height`, `metadata()` and
71
+ * `takeChunks()`, then calls `intoPixels()` once, which copies the pixels out
72
+ * and frees this object.
73
+ */
74
+ export class DecodedImage {
75
+ private constructor();
76
+ free(): void;
77
+ [Symbol.dispose](): void;
78
+ /**
79
+ * The RGBA pixels, `width * height * 4` bytes. Consumes the image.
80
+ */
81
+ intoPixels(): Uint8Array;
82
+ /**
83
+ * The parsed ancillary chunks; empty unless `preserveMetadata` was set.
84
+ */
85
+ metadata(): Metadata;
86
+ /**
87
+ * The raw ancillary chunks; empty unless `preserveChunks` was set. Moves
88
+ * them out, so a second call returns none.
89
+ */
90
+ takeChunks(): Chunk[];
91
+ readonly height: number;
92
+ readonly width: number;
93
+ }
94
+
95
+ /**
96
+ * A decoder that keeps its buffers between images.
97
+ */
98
+ export class Decoder {
99
+ free(): void;
100
+ [Symbol.dispose](): void;
101
+ decodeRgba8(bytes: Uint8Array): DecodedImage;
102
+ decode(bytes: Uint8Array): RawImage;
103
+ constructor(validate_crc: boolean, preserve_metadata: boolean, preserve_chunks: boolean, strict_ancillary: boolean);
104
+ readChunks(bytes: Uint8Array): ChunkList;
105
+ }
106
+
107
+ /**
108
+ * An image to encode, built up from JavaScript: the constructor takes the
109
+ * header and pixels, and each setter adds a chunk. Pass it to `encode` or
110
+ * `Encoder.encode`, then call `free()`.
111
+ */
112
+ export class EncodeImage {
113
+ free(): void;
114
+ [Symbol.dispose](): void;
115
+ /**
116
+ * Adds a raw chunk, written at `position`: one of the strings
117
+ * `Chunk.position` returns.
118
+ */
119
+ addChunk(chunk_type: string, data: Uint8Array, position: string): void;
120
+ /**
121
+ * Adds a `tEXt`, `zTXt` or `iTXt` chunk. `compressed` only matters for
122
+ * `iTXt`, and the language tag and translated keyword are only written
123
+ * there.
124
+ */
125
+ addText(chunk_type: string, keyword: string, text: string, language_tag: string, translated_keyword: string, compressed: boolean): void;
126
+ /**
127
+ * `colorType` is one of the strings `Header.colorType` returns. `data` is
128
+ * in the PNG's own pixel format; see `format_png::ImageRef`.
129
+ */
130
+ constructor(width: number, height: number, bit_depth: number, color_type: string, interlaced: boolean, data: Uint8Array);
131
+ /**
132
+ * `cHRM`: white, red, green and blue x and y, in that order, as fractions.
133
+ */
134
+ setChromaticities(values: Float64Array): void;
135
+ /**
136
+ * `cICP`: H.273 color primaries, transfer function and matrix coefficients,
137
+ * and whether samples use the full range.
138
+ */
139
+ setCicp(color_primaries: number, transfer_function: number, matrix_coefficients: number, full_range: boolean): void;
140
+ /**
141
+ * `eXIf`: Exif data, starting with its TIFF header, which is checked.
142
+ */
143
+ setExif(data: Uint8Array): void;
144
+ /**
145
+ * `gAMA`, for example 0.45455.
146
+ */
147
+ setGamma(gamma: number): void;
148
+ /**
149
+ * `iCCP`: an ICC profile, uncompressed, and its name. The encoder checks
150
+ * the name and compresses the profile.
151
+ */
152
+ setIccProfile(name: string, profile: Uint8Array): void;
153
+ /**
154
+ * `PLTE`: red, green and blue for each entry, in index order.
155
+ */
156
+ setPalette(colors: Uint8Array): void;
157
+ /**
158
+ * `pHYs`: pixels per unit, with unit "meter" or "unknown".
159
+ */
160
+ setPhysicalDimensions(x: number, y: number, unit: string): void;
161
+ /**
162
+ * `sRGB`, with one of the intents `Metadata.srgb` returns.
163
+ */
164
+ setSrgb(intent: string): void;
165
+ /**
166
+ * `tIME`: year, month, day, hour, minute and second, in UTC. The encoder
167
+ * checks the ranges.
168
+ */
169
+ setTime(year: number, month: number, day: number, hour: number, minute: number, second: number): void;
170
+ /**
171
+ * `tRNS`: `kind` is "gray", "rgb" or "palette", and `values` as
172
+ * `ChunkList.transparencyValues` returns them.
173
+ */
174
+ setTransparency(kind: string, values: Uint16Array): void;
175
+ }
176
+
177
+ /**
178
+ * An encoder that keeps its compressor and buffers between images.
179
+ */
180
+ export class Encoder {
181
+ free(): void;
182
+ [Symbol.dispose](): void;
183
+ encode(image: EncodeImage): Uint8Array;
184
+ /**
185
+ * `compression` is 0 to 9. `compressionStrategy` is "dynamic", "fixed" or
186
+ * "stored"; `filter` is "adaptive", "none", "sub", "up", "average" or
187
+ * "paeth"; `palette` is "keep" or "auto"; `strip` is "keep", "safe" or "all".
188
+ */
189
+ constructor(compression: number, compression_strategy: string, filter: string, keep_unsafe_chunks: boolean, palette: string, strip: string);
190
+ }
191
+
192
+ /**
193
+ * The contents of the `IHDR` chunk.
194
+ */
195
+ export class Header {
196
+ private constructor();
197
+ free(): void;
198
+ [Symbol.dispose](): void;
199
+ readonly bitDepth: number;
200
+ readonly height: number;
201
+ readonly interlaced: boolean;
202
+ readonly width: number;
203
+ /**
204
+ * "grayscale", "rgb", "indexed", "grayscale-alpha" or "rgba".
205
+ */
206
+ readonly colorType: string;
207
+ }
208
+
209
+ /**
210
+ * The known ancillary chunks. Each getter is `undefined` if the chunk is absent.
211
+ */
212
+ export class Metadata {
213
+ private constructor();
214
+ free(): void;
215
+ [Symbol.dispose](): void;
216
+ /**
217
+ * `tEXt`, `zTXt` and `iTXt`, in file order.
218
+ */
219
+ text(): Text[];
220
+ /**
221
+ * `cHRM`: white, red, green and blue x and y, in that order, as fractions.
222
+ */
223
+ readonly chromaticities: Float64Array | undefined;
224
+ /**
225
+ * `cICP`: color primaries, transfer function, matrix coefficients and the
226
+ * full-range flag (1 or 0), in that order.
227
+ */
228
+ readonly cicp: Uint8Array | undefined;
229
+ /**
230
+ * `eXIf`: "big-endian" or "little-endian".
231
+ */
232
+ readonly exifByteOrder: string | undefined;
233
+ /**
234
+ * `eXIf`: the Exif data, raw, starting with its TIFF header.
235
+ */
236
+ readonly exif: Uint8Array | undefined;
237
+ /**
238
+ * `gAMA`, for example 0.45455.
239
+ */
240
+ readonly gamma: number | undefined;
241
+ /**
242
+ * `iCCP`: the profile's name.
243
+ */
244
+ readonly iccProfileName: string | undefined;
245
+ /**
246
+ * `iCCP`: the ICC profile, decompressed.
247
+ */
248
+ readonly iccProfile: Uint8Array | undefined;
249
+ /**
250
+ * `pHYs`: pixels per unit, x then y.
251
+ */
252
+ readonly physicalPixelsPerUnit: Uint32Array | undefined;
253
+ /**
254
+ * `pHYs` unit: "meter" or "unknown" (the values are only an aspect ratio).
255
+ */
256
+ readonly physicalUnit: string | undefined;
257
+ /**
258
+ * `sRGB`: "perceptual", "relative-colorimetric", "saturation" or "absolute-colorimetric".
259
+ */
260
+ readonly srgb: string | undefined;
261
+ /**
262
+ * `tIME`: year, month, day, hour, minute and second, in UTC.
263
+ */
264
+ readonly time: Uint16Array | undefined;
265
+ }
266
+
267
+ /**
268
+ * A decoded image in the file's own format, from `decode`. JavaScript reads
269
+ * the header, palette, transparency, `metadata()` and `takeChunks()`, then
270
+ * calls `intoData()` once, which copies the samples out and frees this object.
271
+ */
272
+ export class RawImage {
273
+ private constructor();
274
+ free(): void;
275
+ [Symbol.dispose](): void;
276
+ header(): Header;
277
+ /**
278
+ * The samples in the file's own layout: rows of the header's stride, 16-bit
279
+ * samples big-endian, pixels under 8 bits packed with each row padded to a
280
+ * whole byte, palette indices for indexed images. Consumes the image.
281
+ */
282
+ intoData(): Uint8Array;
283
+ /**
284
+ * The parsed ancillary chunks; empty unless `preserveMetadata` was set.
285
+ */
286
+ metadata(): Metadata;
287
+ /**
288
+ * The raw ancillary chunks; empty unless `preserveChunks` was set.
289
+ */
290
+ takeChunks(): Chunk[];
291
+ /**
292
+ * `PLTE`: red, green and blue for each entry, in index order.
293
+ */
294
+ readonly palette: Uint8Array | undefined;
295
+ /**
296
+ * `tRNS`: "gray", "rgb" or "palette".
297
+ */
298
+ readonly transparencyKind: string | undefined;
299
+ /**
300
+ * `tRNS`, as `ChunkList.transparencyValues`.
301
+ */
302
+ readonly transparencyValues: Uint16Array | undefined;
303
+ }
304
+
305
+ /**
306
+ * A `tEXt`, `zTXt` or `iTXt` chunk, decoded. JavaScript reads the getters, then
307
+ * calls `free()`.
308
+ */
309
+ export class Text {
310
+ private constructor();
311
+ free(): void;
312
+ [Symbol.dispose](): void;
313
+ /**
314
+ * "tEXt", "zTXt" or "iTXt".
315
+ */
316
+ readonly chunkType: string;
317
+ /**
318
+ * Whether the text was zlib-compressed in the file.
319
+ */
320
+ readonly compressed: boolean;
321
+ readonly keyword: string;
322
+ readonly languageTag: string;
323
+ readonly text: string;
324
+ readonly translatedKeyword: string;
325
+ }
326
+
327
+ /**
328
+ * Decodes a PNG in its own format with a one-off decoder.
329
+ */
330
+ export function decode(bytes: Uint8Array, validate_crc: boolean, preserve_metadata: boolean, preserve_chunks: boolean, strict_ancillary: boolean): RawImage;
331
+
332
+ /**
333
+ * Decodes a PNG to RGBA8 with a one-off decoder.
334
+ */
335
+ export function decodeRgba8(bytes: Uint8Array, validate_crc: boolean, preserve_metadata: boolean, preserve_chunks: boolean, strict_ancillary: boolean): DecodedImage;
336
+
337
+ /**
338
+ * Encodes an image with a one-off encoder.
339
+ */
340
+ export function encode(image: EncodeImage, compression: number, compression_strategy: string, filter: string, keep_unsafe_chunks: boolean, palette: string, strip: string): Uint8Array;
341
+
342
+ /**
343
+ * Parses the data of a `tEXt`, `zTXt` or `iTXt` chunk on its own.
344
+ */
345
+ export function parseText(chunk_type: string, data: Uint8Array): Text;
346
+
347
+ /**
348
+ * Reads and parses every chunk without decompressing the image data.
349
+ */
350
+ export function readChunks(bytes: Uint8Array, validate_crc: boolean, strict_ancillary: boolean): ChunkList;
351
+
352
+ /**
353
+ * Reads only the header.
354
+ */
355
+ export function readHeader(bytes: Uint8Array): Header;
356
+
357
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
358
+
359
+ export interface InitOutput {
360
+ readonly memory: WebAssembly.Memory;
361
+ readonly __wbg_chunk_free: (a: number, b: number) => void;
362
+ readonly __wbg_chunklist_free: (a: number, b: number) => void;
363
+ readonly __wbg_decodedimage_free: (a: number, b: number) => void;
364
+ readonly __wbg_decoder_free: (a: number, b: number) => void;
365
+ readonly __wbg_encodeimage_free: (a: number, b: number) => void;
366
+ readonly __wbg_encoder_free: (a: number, b: number) => void;
367
+ readonly __wbg_get_decodedimage_height: (a: number) => number;
368
+ readonly __wbg_get_decodedimage_width: (a: number) => number;
369
+ readonly __wbg_get_header_bitDepth: (a: number) => number;
370
+ readonly __wbg_get_header_height: (a: number) => number;
371
+ readonly __wbg_get_header_interlaced: (a: number) => number;
372
+ readonly __wbg_get_header_width: (a: number) => number;
373
+ readonly __wbg_header_free: (a: number, b: number) => void;
374
+ readonly __wbg_metadata_free: (a: number, b: number) => void;
375
+ readonly __wbg_rawimage_free: (a: number, b: number) => void;
376
+ readonly __wbg_text_free: (a: number, b: number) => void;
377
+ readonly chunk_chunkType: (a: number) => [number, number];
378
+ readonly chunk_intoData: (a: number) => [number, number];
379
+ readonly chunk_position: (a: number) => [number, number];
380
+ readonly chunklist_crcs: (a: number) => [number, number];
381
+ readonly chunklist_header: (a: number) => number;
382
+ readonly chunklist_known: (a: number) => [number, number];
383
+ readonly chunklist_lengths: (a: number) => [number, number];
384
+ readonly chunklist_metadata: (a: number) => number;
385
+ readonly chunklist_offsets: (a: number) => [number, number];
386
+ readonly chunklist_palette: (a: number) => [number, number];
387
+ readonly chunklist_transparencyKind: (a: number) => [number, number];
388
+ readonly chunklist_transparencyValues: (a: number) => [number, number];
389
+ readonly chunklist_types: (a: number) => [number, number];
390
+ readonly decode: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
391
+ readonly decodeRgba8: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
392
+ readonly decodedimage_intoPixels: (a: number) => [number, number];
393
+ readonly decodedimage_metadata: (a: number) => number;
394
+ readonly decodedimage_takeChunks: (a: number) => [number, number];
395
+ readonly decoder_decode: (a: number, b: number, c: number) => [number, number, number];
396
+ readonly decoder_decodeRgba8: (a: number, b: number, c: number) => [number, number, number];
397
+ readonly decoder_new: (a: number, b: number, c: number, d: number) => number;
398
+ readonly decoder_readChunks: (a: number, b: number, c: number) => [number, number, number];
399
+ readonly encode: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => [number, number, number, number];
400
+ readonly encodeimage_addChunk: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
401
+ readonly encodeimage_addText: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => [number, number];
402
+ readonly encodeimage_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number];
403
+ readonly encodeimage_setChromaticities: (a: number, b: number, c: number) => [number, number];
404
+ readonly encodeimage_setCicp: (a: number, b: number, c: number, d: number, e: number) => void;
405
+ readonly encodeimage_setExif: (a: number, b: number, c: number) => [number, number];
406
+ readonly encodeimage_setGamma: (a: number, b: number) => [number, number];
407
+ readonly encodeimage_setIccProfile: (a: number, b: number, c: number, d: number, e: number) => void;
408
+ readonly encodeimage_setPalette: (a: number, b: number, c: number) => [number, number];
409
+ readonly encodeimage_setPhysicalDimensions: (a: number, b: number, c: number, d: number, e: number) => [number, number];
410
+ readonly encodeimage_setSrgb: (a: number, b: number, c: number) => [number, number];
411
+ readonly encodeimage_setTime: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
412
+ readonly encodeimage_setTransparency: (a: number, b: number, c: number, d: number, e: number) => [number, number];
413
+ readonly encoder_encode: (a: number, b: number) => [number, number, number, number];
414
+ readonly encoder_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number, number];
415
+ readonly header_colorType: (a: number) => [number, number];
416
+ readonly metadata_chromaticities: (a: number) => [number, number];
417
+ readonly metadata_cicp: (a: number) => [number, number];
418
+ readonly metadata_exif: (a: number) => [number, number];
419
+ readonly metadata_exifByteOrder: (a: number) => [number, number];
420
+ readonly metadata_gamma: (a: number) => [number, number];
421
+ readonly metadata_iccProfile: (a: number) => [number, number];
422
+ readonly metadata_iccProfileName: (a: number) => [number, number];
423
+ readonly metadata_physicalPixelsPerUnit: (a: number) => [number, number];
424
+ readonly metadata_physicalUnit: (a: number) => [number, number];
425
+ readonly metadata_srgb: (a: number) => [number, number];
426
+ readonly metadata_text: (a: number) => [number, number];
427
+ readonly metadata_time: (a: number) => [number, number];
428
+ readonly parseText: (a: number, b: number, c: number, d: number) => [number, number, number];
429
+ readonly rawimage_header: (a: number) => number;
430
+ readonly rawimage_intoData: (a: number) => [number, number];
431
+ readonly rawimage_metadata: (a: number) => number;
432
+ readonly rawimage_palette: (a: number) => [number, number];
433
+ readonly rawimage_takeChunks: (a: number) => [number, number];
434
+ readonly rawimage_transparencyKind: (a: number) => [number, number];
435
+ readonly rawimage_transparencyValues: (a: number) => [number, number];
436
+ readonly readChunks: (a: number, b: number, c: number, d: number) => [number, number, number];
437
+ readonly readHeader: (a: number, b: number) => [number, number, number];
438
+ readonly text_chunkType: (a: number) => [number, number];
439
+ readonly text_compressed: (a: number) => number;
440
+ readonly text_keyword: (a: number) => [number, number];
441
+ readonly text_languageTag: (a: number) => [number, number];
442
+ readonly text_text: (a: number) => [number, number];
443
+ readonly text_translatedKeyword: (a: number) => [number, number];
444
+ readonly __wbindgen_externrefs: WebAssembly.Table;
445
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
446
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
447
+ readonly __externref_table_dealloc: (a: number) => void;
448
+ readonly __externref_drop_slice: (a: number, b: number) => void;
449
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
450
+ readonly __wbindgen_start: () => void;
451
+ }
452
+
453
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
454
+
455
+ /**
456
+ * Instantiates the given `module`, which can either be bytes or
457
+ * a precompiled `WebAssembly.Module`.
458
+ *
459
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
460
+ *
461
+ * @returns {InitOutput}
462
+ */
463
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
464
+
465
+ /**
466
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
467
+ * for everything else, calls `WebAssembly.instantiate` directly.
468
+ *
469
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
470
+ *
471
+ * @returns {Promise<InitOutput>}
472
+ */
473
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;