format-png 0.1.2 → 0.3.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.
@@ -184,9 +184,18 @@ export class Encoder {
184
184
  /**
185
185
  * `compression` is 0 to 9. `compressionStrategy` is "dynamic", "fixed" or
186
186
  * "stored"; `filter` is "adaptive", "none", "sub", "up", "average" or
187
- * "paeth"; `palette` is "keep" or "auto"; `strip` is "keep", "safe" or "all".
187
+ * "paeth"; `palette` is "keep" or "auto"; `strip` is "keep", "safe" or
188
+ * "all"; `threads` is "single" or "auto". WebAssembly has no threads, so
189
+ * "auto" compresses the image data in segments on this thread: the same
190
+ * file as `format_png::Threads::Auto` writes natively.
188
191
  */
189
- constructor(compression: number, compression_strategy: string, filter: string, keep_unsafe_chunks: boolean, palette: string, strip: string);
192
+ constructor(compression: number, compression_strategy: string, filter: string, keep_unsafe_chunks: boolean, palette: string, strip: string, threads: string);
193
+ /**
194
+ * Everything `encode` does except compressing the image data, which is
195
+ * left in segments to compress anywhere, such as in other Web Workers.
196
+ * Always in segments, whatever `threads` says.
197
+ */
198
+ prepare(image: EncodeImage): Prepared;
190
199
  }
191
200
 
192
201
  /**
@@ -264,6 +273,44 @@ export class Metadata {
264
273
  readonly time: Uint16Array | undefined;
265
274
  }
266
275
 
276
+ /**
277
+ * An image from `Encoder.prepare`, waiting for its segments to be compressed.
278
+ * Copy each `segment(i)` out, compress it with `compressSegment`, pass the
279
+ * results to `pushCompressed` in segment order, then call `finish()`. Call
280
+ * `free()` when done with it, finished or not.
281
+ */
282
+ export class Prepared {
283
+ private constructor();
284
+ free(): void;
285
+ [Symbol.dispose](): void;
286
+ /**
287
+ * Joins the compressed segments into the PNG. Only once: afterwards the
288
+ * other methods throw.
289
+ */
290
+ finish(): Uint8Array;
291
+ /**
292
+ * Adds the next compressed segment, in segment order.
293
+ */
294
+ pushCompressed(segment: Uint8Array): void;
295
+ /**
296
+ * Segment `index`, copied out of WebAssembly memory.
297
+ */
298
+ segment(index: number): Uint8Array;
299
+ /**
300
+ * The level to pass to `compressSegment`.
301
+ */
302
+ readonly compressionLevel: number;
303
+ /**
304
+ * The strategy to pass to `compressSegment`: "dynamic", "fixed" or "stored".
305
+ */
306
+ readonly compressionStrategy: string;
307
+ /**
308
+ * 0 for images with 1 MiB of filtered data or less, which are already
309
+ * encoded: call `finish()` for the PNG.
310
+ */
311
+ readonly segmentCount: number;
312
+ }
313
+
267
314
  /**
268
315
  * A decoded image in the file's own format, from `decode`. JavaScript reads
269
316
  * the header, palette, transparency, `metadata()` and `takeChunks()`, then
@@ -324,6 +371,12 @@ export class Text {
324
371
  readonly translatedKeyword: string;
325
372
  }
326
373
 
374
+ /**
375
+ * Compresses one segment of a `Prepared`, with its `compressionLevel` and
376
+ * `compressionStrategy`. The same result in any WebAssembly instance.
377
+ */
378
+ export function compressSegment(segment: Uint8Array, level: number, strategy: string): Uint8Array;
379
+
327
380
  /**
328
381
  * Decodes a PNG in its own format with a one-off decoder.
329
382
  */
@@ -335,9 +388,9 @@ export function decode(bytes: Uint8Array, validate_crc: boolean, preserve_metada
335
388
  export function decodeRgba8(bytes: Uint8Array, validate_crc: boolean, preserve_metadata: boolean, preserve_chunks: boolean, strict_ancillary: boolean): DecodedImage;
336
389
 
337
390
  /**
338
- * Encodes an image with a one-off encoder.
391
+ * Encodes an image with a one-off encoder: the image, then `Encoder`'s options.
339
392
  */
340
- export function encode(image: EncodeImage, compression: number, compression_strategy: string, filter: string, keep_unsafe_chunks: boolean, palette: string, strip: string): Uint8Array;
393
+ export function encode(image: EncodeImage, compression: number, compression_strategy: string, filter: string, keep_unsafe_chunks: boolean, palette: string, strip: string, threads: string): Uint8Array;
341
394
 
342
395
  /**
343
396
  * Parses the data of a `tEXt`, `zTXt` or `iTXt` chunk on its own.
@@ -372,82 +425,88 @@ export interface InitOutput {
372
425
  readonly __wbg_get_header_width: (a: number) => number;
373
426
  readonly __wbg_header_free: (a: number, b: number) => void;
374
427
  readonly __wbg_metadata_free: (a: number, b: number) => void;
428
+ readonly __wbg_prepared_free: (a: number, b: number) => void;
375
429
  readonly __wbg_rawimage_free: (a: number, b: number) => void;
376
430
  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];
431
+ readonly chunk_chunkType: (a: number, b: number) => void;
432
+ readonly chunk_intoData: (a: number, b: number) => void;
433
+ readonly chunk_position: (a: number, b: number) => void;
434
+ readonly chunklist_crcs: (a: number, b: number) => void;
381
435
  readonly chunklist_header: (a: number) => number;
382
- readonly chunklist_known: (a: number) => [number, number];
383
- readonly chunklist_lengths: (a: number) => [number, number];
436
+ readonly chunklist_known: (a: number, b: number) => void;
437
+ readonly chunklist_lengths: (a: number, b: number) => void;
384
438
  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];
439
+ readonly chunklist_offsets: (a: number, b: number) => void;
440
+ readonly chunklist_palette: (a: number, b: number) => void;
441
+ readonly chunklist_transparencyKind: (a: number, b: number) => void;
442
+ readonly chunklist_transparencyValues: (a: number, b: number) => void;
443
+ readonly chunklist_types: (a: number, b: number) => void;
444
+ readonly compressSegment: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
445
+ readonly decode: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
446
+ readonly decodeRgba8: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
447
+ readonly decodedimage_intoPixels: (a: number, b: number) => void;
393
448
  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];
449
+ readonly decodedimage_takeChunks: (a: number, b: number) => void;
450
+ readonly decoder_decode: (a: number, b: number, c: number, d: number) => void;
451
+ readonly decoder_decodeRgba8: (a: number, b: number, c: number, d: number) => void;
397
452
  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];
453
+ readonly decoder_readChunks: (a: number, b: number, c: number, d: number) => void;
454
+ readonly encode: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number) => void;
455
+ readonly encodeimage_addChunk: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
456
+ 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, m: number) => void;
457
+ readonly encodeimage_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
458
+ readonly encodeimage_setChromaticities: (a: number, b: number, c: number, d: number) => void;
404
459
  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];
460
+ readonly encodeimage_setExif: (a: number, b: number, c: number, d: number) => void;
461
+ readonly encodeimage_setGamma: (a: number, b: number, c: number) => void;
407
462
  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];
463
+ readonly encodeimage_setPalette: (a: number, b: number, c: number, d: number) => void;
464
+ readonly encodeimage_setPhysicalDimensions: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
465
+ readonly encodeimage_setSrgb: (a: number, b: number, c: number, d: number) => void;
411
466
  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];
467
+ readonly encodeimage_setTransparency: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
468
+ readonly encoder_encode: (a: number, b: number, c: number) => void;
469
+ readonly encoder_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => void;
470
+ readonly encoder_prepare: (a: number, b: number, c: number) => void;
471
+ readonly header_colorType: (a: number, b: number) => void;
472
+ readonly metadata_chromaticities: (a: number, b: number) => void;
473
+ readonly metadata_cicp: (a: number, b: number) => void;
474
+ readonly metadata_exif: (a: number, b: number) => void;
475
+ readonly metadata_exifByteOrder: (a: number, b: number) => void;
476
+ readonly metadata_gamma: (a: number, b: number) => void;
477
+ readonly metadata_iccProfile: (a: number, b: number) => void;
478
+ readonly metadata_iccProfileName: (a: number, b: number) => void;
479
+ readonly metadata_physicalPixelsPerUnit: (a: number, b: number) => void;
480
+ readonly metadata_physicalUnit: (a: number, b: number) => void;
481
+ readonly metadata_srgb: (a: number, b: number) => void;
482
+ readonly metadata_text: (a: number, b: number) => void;
483
+ readonly metadata_time: (a: number, b: number) => void;
484
+ readonly parseText: (a: number, b: number, c: number, d: number, e: number) => void;
485
+ readonly prepared_compressionLevel: (a: number) => number;
486
+ readonly prepared_compressionStrategy: (a: number, b: number) => void;
487
+ readonly prepared_finish: (a: number, b: number) => void;
488
+ readonly prepared_pushCompressed: (a: number, b: number, c: number) => void;
489
+ readonly prepared_segment: (a: number, b: number, c: number) => void;
490
+ readonly prepared_segmentCount: (a: number) => number;
429
491
  readonly rawimage_header: (a: number) => number;
430
- readonly rawimage_intoData: (a: number) => [number, number];
492
+ readonly rawimage_intoData: (a: number, b: number) => void;
431
493
  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];
494
+ readonly rawimage_palette: (a: number, b: number) => void;
495
+ readonly rawimage_takeChunks: (a: number, b: number) => void;
496
+ readonly rawimage_transparencyKind: (a: number, b: number) => void;
497
+ readonly rawimage_transparencyValues: (a: number, b: number) => void;
498
+ readonly readChunks: (a: number, b: number, c: number, d: number, e: number) => void;
499
+ readonly readHeader: (a: number, b: number, c: number) => void;
500
+ readonly text_chunkType: (a: number, b: number) => void;
439
501
  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;
502
+ readonly text_keyword: (a: number, b: number) => void;
503
+ readonly text_languageTag: (a: number, b: number) => void;
504
+ readonly text_text: (a: number, b: number) => void;
505
+ readonly text_translatedKeyword: (a: number, b: number) => void;
506
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
507
+ readonly __wbindgen_export: (a: number, b: number, c: number) => void;
508
+ readonly __wbindgen_export2: (a: number, b: number) => number;
509
+ readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
451
510
  }
452
511
 
453
512
  export type SyncInitInput = BufferSource | WebAssembly.Module;