@jimp/pngjs 0.0.0-stage → 2.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.
Files changed (258) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +335 -2
  3. package/dist/browser/apng.d.ts +38 -0
  4. package/dist/browser/apng.d.ts.map +1 -0
  5. package/dist/browser/apng.js +109 -0
  6. package/dist/browser/apng.js.map +1 -0
  7. package/dist/browser/buffer-browser.d.mts.map +1 -0
  8. package/dist/browser/buffer-browser.mjs.map +1 -0
  9. package/dist/browser/buffer.d.ts +5 -0
  10. package/dist/browser/buffer.js +8 -0
  11. package/dist/browser/constants.d.ts +39 -0
  12. package/dist/browser/constants.d.ts.map +1 -0
  13. package/dist/browser/constants.js +55 -0
  14. package/dist/browser/constants.js.map +1 -0
  15. package/dist/browser/crc.d.ts +3 -0
  16. package/dist/browser/crc.d.ts.map +1 -0
  17. package/dist/browser/crc.js +24 -0
  18. package/dist/browser/crc.js.map +1 -0
  19. package/dist/browser/decode.d.ts +49 -0
  20. package/dist/browser/decode.d.ts.map +1 -0
  21. package/dist/browser/decode.js +49 -0
  22. package/dist/browser/decode.js.map +1 -0
  23. package/dist/browser/encode.d.ts +37 -0
  24. package/dist/browser/encode.d.ts.map +1 -0
  25. package/dist/browser/encode.js +252 -0
  26. package/dist/browser/encode.js.map +1 -0
  27. package/dist/browser/filter.d.ts +17 -0
  28. package/dist/browser/filter.d.ts.map +1 -0
  29. package/dist/browser/filter.js +180 -0
  30. package/dist/browser/filter.js.map +1 -0
  31. package/dist/browser/gamma.d.ts +22 -0
  32. package/dist/browser/gamma.d.ts.map +1 -0
  33. package/dist/browser/gamma.js +34 -0
  34. package/dist/browser/gamma.js.map +1 -0
  35. package/dist/browser/index.d.ts +14 -0
  36. package/dist/browser/index.d.ts.map +1 -0
  37. package/dist/browser/index.js +8 -0
  38. package/dist/browser/index.js.map +1 -0
  39. package/dist/browser/inflate-js.d.ts +10 -0
  40. package/dist/browser/inflate-js.d.ts.map +1 -0
  41. package/dist/browser/inflate-js.js +48 -0
  42. package/dist/browser/inflate-js.js.map +1 -0
  43. package/dist/browser/interlace.d.ts +22 -0
  44. package/dist/browser/interlace.d.ts.map +1 -0
  45. package/dist/browser/interlace.js +42 -0
  46. package/dist/browser/interlace.js.map +1 -0
  47. package/dist/browser/legacy.d.ts +153 -0
  48. package/dist/browser/legacy.d.ts.map +1 -0
  49. package/dist/browser/legacy.js +151 -0
  50. package/dist/browser/legacy.js.map +1 -0
  51. package/dist/browser/pack.d.ts +68 -0
  52. package/dist/browser/pack.d.ts.map +1 -0
  53. package/dist/browser/pack.js +342 -0
  54. package/dist/browser/pack.js.map +1 -0
  55. package/dist/browser/package.json +3 -0
  56. package/dist/browser/pixels.d.ts +18 -0
  57. package/dist/browser/pixels.d.ts.map +1 -0
  58. package/dist/browser/pixels.js +251 -0
  59. package/dist/browser/pixels.js.map +1 -0
  60. package/dist/browser/png.d.ts +87 -0
  61. package/dist/browser/png.d.ts.map +1 -0
  62. package/dist/browser/png.js +341 -0
  63. package/dist/browser/png.js.map +1 -0
  64. package/dist/browser/read.d.ts +71 -0
  65. package/dist/browser/read.d.ts.map +1 -0
  66. package/dist/browser/read.js +404 -0
  67. package/dist/browser/read.js.map +1 -0
  68. package/dist/browser/stream-base-browser.d.mts.map +1 -0
  69. package/dist/browser/stream-base-browser.mjs.map +1 -0
  70. package/dist/browser/stream-base.d.ts +21 -0
  71. package/dist/browser/stream-base.js +71 -0
  72. package/dist/browser/text.d.ts +10 -0
  73. package/dist/browser/text.d.ts.map +1 -0
  74. package/dist/browser/text.js +32 -0
  75. package/dist/browser/text.js.map +1 -0
  76. package/dist/browser/types.d.ts +147 -0
  77. package/dist/browser/types.d.ts.map +1 -0
  78. package/dist/browser/types.js +2 -0
  79. package/dist/browser/types.js.map +1 -0
  80. package/dist/browser/zlib-browser.d.mts.map +1 -0
  81. package/dist/browser/zlib-browser.mjs.map +1 -0
  82. package/dist/browser/zlib-stream.d.ts +9 -0
  83. package/dist/browser/zlib-stream.d.ts.map +1 -0
  84. package/dist/browser/zlib-stream.js +31 -0
  85. package/dist/browser/zlib-stream.js.map +1 -0
  86. package/dist/browser/zlib.d.ts +14 -0
  87. package/dist/browser/zlib.js +20 -0
  88. package/dist/commonjs/apng.d.ts +38 -0
  89. package/dist/commonjs/apng.d.ts.map +1 -0
  90. package/dist/commonjs/apng.js +112 -0
  91. package/dist/commonjs/apng.js.map +1 -0
  92. package/dist/commonjs/buffer.d.ts +7 -0
  93. package/dist/commonjs/buffer.d.ts.map +1 -0
  94. package/dist/commonjs/buffer.js +16 -0
  95. package/dist/commonjs/buffer.js.map +1 -0
  96. package/dist/commonjs/constants.d.ts +39 -0
  97. package/dist/commonjs/constants.d.ts.map +1 -0
  98. package/dist/commonjs/constants.js +59 -0
  99. package/dist/commonjs/constants.js.map +1 -0
  100. package/dist/commonjs/crc.d.ts +3 -0
  101. package/dist/commonjs/crc.d.ts.map +1 -0
  102. package/dist/commonjs/crc.js +27 -0
  103. package/dist/commonjs/crc.js.map +1 -0
  104. package/dist/commonjs/decode.d.ts +49 -0
  105. package/dist/commonjs/decode.d.ts.map +1 -0
  106. package/dist/commonjs/decode.js +55 -0
  107. package/dist/commonjs/decode.js.map +1 -0
  108. package/dist/commonjs/encode.d.ts +37 -0
  109. package/dist/commonjs/encode.d.ts.map +1 -0
  110. package/dist/commonjs/encode.js +262 -0
  111. package/dist/commonjs/encode.js.map +1 -0
  112. package/dist/commonjs/filter.d.ts +17 -0
  113. package/dist/commonjs/filter.d.ts.map +1 -0
  114. package/dist/commonjs/filter.js +184 -0
  115. package/dist/commonjs/filter.js.map +1 -0
  116. package/dist/commonjs/gamma.d.ts +22 -0
  117. package/dist/commonjs/gamma.d.ts.map +1 -0
  118. package/dist/commonjs/gamma.js +37 -0
  119. package/dist/commonjs/gamma.js.map +1 -0
  120. package/dist/commonjs/index.d.ts +14 -0
  121. package/dist/commonjs/index.d.ts.map +1 -0
  122. package/dist/commonjs/index.js +19 -0
  123. package/dist/commonjs/index.js.map +1 -0
  124. package/dist/commonjs/inflate-js.d.ts +10 -0
  125. package/dist/commonjs/inflate-js.d.ts.map +1 -0
  126. package/dist/commonjs/inflate-js.js +51 -0
  127. package/dist/commonjs/inflate-js.js.map +1 -0
  128. package/dist/commonjs/interlace.d.ts +22 -0
  129. package/dist/commonjs/interlace.d.ts.map +1 -0
  130. package/dist/commonjs/interlace.js +48 -0
  131. package/dist/commonjs/interlace.js.map +1 -0
  132. package/dist/commonjs/legacy.d.ts +153 -0
  133. package/dist/commonjs/legacy.d.ts.map +1 -0
  134. package/dist/commonjs/legacy.js +157 -0
  135. package/dist/commonjs/legacy.js.map +1 -0
  136. package/dist/commonjs/pack.d.ts +68 -0
  137. package/dist/commonjs/pack.d.ts.map +1 -0
  138. package/dist/commonjs/pack.js +348 -0
  139. package/dist/commonjs/pack.js.map +1 -0
  140. package/dist/commonjs/package.json +3 -0
  141. package/dist/commonjs/pixels.d.ts +18 -0
  142. package/dist/commonjs/pixels.d.ts.map +1 -0
  143. package/dist/commonjs/pixels.js +255 -0
  144. package/dist/commonjs/pixels.js.map +1 -0
  145. package/dist/commonjs/png.d.ts +87 -0
  146. package/dist/commonjs/png.d.ts.map +1 -0
  147. package/dist/commonjs/png.js +345 -0
  148. package/dist/commonjs/png.js.map +1 -0
  149. package/dist/commonjs/read.d.ts +71 -0
  150. package/dist/commonjs/read.d.ts.map +1 -0
  151. package/dist/commonjs/read.js +409 -0
  152. package/dist/commonjs/read.js.map +1 -0
  153. package/dist/commonjs/stream-base.d.ts +2 -0
  154. package/dist/commonjs/stream-base.d.ts.map +1 -0
  155. package/dist/commonjs/stream-base.js +8 -0
  156. package/dist/commonjs/stream-base.js.map +1 -0
  157. package/dist/commonjs/text.d.ts +10 -0
  158. package/dist/commonjs/text.d.ts.map +1 -0
  159. package/dist/commonjs/text.js +38 -0
  160. package/dist/commonjs/text.js.map +1 -0
  161. package/dist/commonjs/types.d.ts +147 -0
  162. package/dist/commonjs/types.d.ts.map +1 -0
  163. package/dist/commonjs/types.js +3 -0
  164. package/dist/commonjs/types.js.map +1 -0
  165. package/dist/commonjs/zlib-stream.d.ts +9 -0
  166. package/dist/commonjs/zlib-stream.d.ts.map +1 -0
  167. package/dist/commonjs/zlib-stream.js +35 -0
  168. package/dist/commonjs/zlib-stream.js.map +1 -0
  169. package/dist/commonjs/zlib.d.ts +20 -0
  170. package/dist/commonjs/zlib.d.ts.map +1 -0
  171. package/dist/commonjs/zlib.js +77 -0
  172. package/dist/commonjs/zlib.js.map +1 -0
  173. package/dist/esm/apng.d.ts +38 -0
  174. package/dist/esm/apng.d.ts.map +1 -0
  175. package/dist/esm/apng.js +109 -0
  176. package/dist/esm/apng.js.map +1 -0
  177. package/dist/esm/buffer.d.ts +7 -0
  178. package/dist/esm/buffer.d.ts.map +1 -0
  179. package/dist/esm/buffer.js +12 -0
  180. package/dist/esm/buffer.js.map +1 -0
  181. package/dist/esm/constants.d.ts +39 -0
  182. package/dist/esm/constants.d.ts.map +1 -0
  183. package/dist/esm/constants.js +55 -0
  184. package/dist/esm/constants.js.map +1 -0
  185. package/dist/esm/crc.d.ts +3 -0
  186. package/dist/esm/crc.d.ts.map +1 -0
  187. package/dist/esm/crc.js +24 -0
  188. package/dist/esm/crc.js.map +1 -0
  189. package/dist/esm/decode.d.ts +49 -0
  190. package/dist/esm/decode.d.ts.map +1 -0
  191. package/dist/esm/decode.js +49 -0
  192. package/dist/esm/decode.js.map +1 -0
  193. package/dist/esm/encode.d.ts +37 -0
  194. package/dist/esm/encode.d.ts.map +1 -0
  195. package/dist/esm/encode.js +252 -0
  196. package/dist/esm/encode.js.map +1 -0
  197. package/dist/esm/filter.d.ts +17 -0
  198. package/dist/esm/filter.d.ts.map +1 -0
  199. package/dist/esm/filter.js +180 -0
  200. package/dist/esm/filter.js.map +1 -0
  201. package/dist/esm/gamma.d.ts +22 -0
  202. package/dist/esm/gamma.d.ts.map +1 -0
  203. package/dist/esm/gamma.js +34 -0
  204. package/dist/esm/gamma.js.map +1 -0
  205. package/dist/esm/index.d.ts +14 -0
  206. package/dist/esm/index.d.ts.map +1 -0
  207. package/dist/esm/index.js +8 -0
  208. package/dist/esm/index.js.map +1 -0
  209. package/dist/esm/inflate-js.d.ts +10 -0
  210. package/dist/esm/inflate-js.d.ts.map +1 -0
  211. package/dist/esm/inflate-js.js +48 -0
  212. package/dist/esm/inflate-js.js.map +1 -0
  213. package/dist/esm/interlace.d.ts +22 -0
  214. package/dist/esm/interlace.d.ts.map +1 -0
  215. package/dist/esm/interlace.js +42 -0
  216. package/dist/esm/interlace.js.map +1 -0
  217. package/dist/esm/legacy.d.ts +153 -0
  218. package/dist/esm/legacy.d.ts.map +1 -0
  219. package/dist/esm/legacy.js +151 -0
  220. package/dist/esm/legacy.js.map +1 -0
  221. package/dist/esm/pack.d.ts +68 -0
  222. package/dist/esm/pack.d.ts.map +1 -0
  223. package/dist/esm/pack.js +342 -0
  224. package/dist/esm/pack.js.map +1 -0
  225. package/dist/esm/package.json +3 -0
  226. package/dist/esm/pixels.d.ts +18 -0
  227. package/dist/esm/pixels.d.ts.map +1 -0
  228. package/dist/esm/pixels.js +251 -0
  229. package/dist/esm/pixels.js.map +1 -0
  230. package/dist/esm/png.d.ts +87 -0
  231. package/dist/esm/png.d.ts.map +1 -0
  232. package/dist/esm/png.js +341 -0
  233. package/dist/esm/png.js.map +1 -0
  234. package/dist/esm/read.d.ts +71 -0
  235. package/dist/esm/read.d.ts.map +1 -0
  236. package/dist/esm/read.js +404 -0
  237. package/dist/esm/read.js.map +1 -0
  238. package/dist/esm/stream-base.d.ts +2 -0
  239. package/dist/esm/stream-base.d.ts.map +1 -0
  240. package/dist/esm/stream-base.js +4 -0
  241. package/dist/esm/stream-base.js.map +1 -0
  242. package/dist/esm/text.d.ts +10 -0
  243. package/dist/esm/text.d.ts.map +1 -0
  244. package/dist/esm/text.js +32 -0
  245. package/dist/esm/text.js.map +1 -0
  246. package/dist/esm/types.d.ts +147 -0
  247. package/dist/esm/types.d.ts.map +1 -0
  248. package/dist/esm/types.js +2 -0
  249. package/dist/esm/types.js.map +1 -0
  250. package/dist/esm/zlib-stream.d.ts +9 -0
  251. package/dist/esm/zlib-stream.d.ts.map +1 -0
  252. package/dist/esm/zlib-stream.js +31 -0
  253. package/dist/esm/zlib-stream.js.map +1 -0
  254. package/dist/esm/zlib.d.ts +20 -0
  255. package/dist/esm/zlib.d.ts.map +1 -0
  256. package/dist/esm/zlib.js +39 -0
  257. package/dist/esm/zlib.js.map +1 -0
  258. package/package.json +95 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ pngjs original work Copyright (c) 2015 Luke Page & Original Contributors
2
+ pngjs derived work Copyright (c) 2012 Kuba Niegowski
3
+ @jimp/pngjs modifications Copyright (c) 2026 Jimp contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,336 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
+ <img width="140" alt=""
3
+ src="https://raw.githubusercontent.com/jimp-dev/jimp/main/.github/assets/jimpy.png">
4
+ <h1>@jimp/pngjs</h1>
5
+ <p>A PNG encoder and decoder in pure JavaScript, for Node.js and browsers.</p>
6
+ </div>
2
7
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
8
+ - Decodes every PNG: all bit depths (1, 2, 4, 8, 16), colour types, interlacing and transparency, checked pixel for pixel against libpng on [PngSuite](http://www.schaik.com/pngsuite/)
9
+ - Encodes to the smallest lossless format by default, including palettes and 1, 2 and 4-bit grayscale
10
+ - Decodes APNG animations
11
+ - Reads and writes metadata: text, pHYs, gamma, sRGB, ICC profiles and EXIF
12
+ - Sync, with no Node.js polyfills in browsers
13
+ - A drop-in replacement for [pngjs](https://github.com/pngjs/pngjs), with its bugs fixed, and faster
14
+
15
+ ## Based on pngjs
16
+
17
+ This package is a fork of [pngjs](https://github.com/pngjs/pngjs) 7.0.0 by
18
+ Luke Page and the pngjs contributors, which is in turn based on
19
+ [node-pngjs](https://github.com/niegowski/node-pngjs) by Kuba Niegowski. It
20
+ was rewritten in TypeScript, but keeps pngjs's API, and its encoder writes the
21
+ same bytes for the same settings. pngjs's MIT license and copyright notices
22
+ are in [LICENSE](./LICENSE).
23
+
24
+ pngjs hasn't had a release since 2023. This fork fixes the bugs in its issue
25
+ tracker ([see below](#fixed-from-pngjs)) and is maintained as part of
26
+ [Jimp](https://github.com/jimp-dev/jimp).
27
+
28
+ ## Install
29
+
30
+ ```sh
31
+ npm install @jimp/pngjs
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```js
37
+ import { decode, encode } from "@jimp/pngjs";
38
+
39
+ const image = decode(fs.readFileSync("in.png"));
40
+ // { width, height, data, depth, colorType, interlace, gamma, text, ... }
41
+
42
+ // Invert the colours
43
+ for (let i = 0; i < image.data.length; i += 4) {
44
+ image.data[i] = 255 - image.data[i];
45
+ image.data[i + 1] = 255 - image.data[i + 1];
46
+ image.data[i + 2] = 255 - image.data[i + 2];
47
+ }
48
+
49
+ fs.writeFileSync("out.png", encode(image));
50
+ ```
51
+
52
+ Both work on bytes: a `Uint8Array` (or `Buffer`) or an `ArrayBuffer` in, a
53
+ `Uint8Array` out (a `Buffer` in Node.js). In a browser:
54
+
55
+ ```js
56
+ const response = await fetch("image.png");
57
+ const image = decode(await response.arrayBuffer());
58
+ ```
59
+
60
+ ### `decode(data, options?)`
61
+
62
+ Decodes a PNG to RGBA pixels, row by row, 8 bits per sample. Returns:
63
+
64
+ | Property | Description |
65
+ | ------------------ | ----------------------------------------------------------------------------------------------- |
66
+ | `width`, `height` | The size in pixels |
67
+ | `data` | The pixels as R, G, B, A samples: a `Uint8Array`, or a `Uint16Array` with `outputDepth: 16` |
68
+ | `depth` | The file's bit depth: 1, 2, 4, 8 or 16 |
69
+ | `colorType` | The file's colour type, a `ColorType` |
70
+ | `interlace` | Whether the file is interlaced |
71
+ | `palette` | The palette of palette images, as `[r, g, b, a]` entries |
72
+ | `transparentColor` | The tRNS colour of grayscale and colour images, at the file's bit depth |
73
+ | `gamma` | The gAMA chunk's gamma, e.g. `0.45455` |
74
+ | `srgb` | The sRGB chunk's rendering intent |
75
+ | `iccProfile` | The iCCP chunk: `{ name, data }`, with the profile uncompressed |
76
+ | `physical` | The pHYs chunk: `{ x, y, unit }`, pixels per unit, with `unit` `"meter"` or `"unknown"` |
77
+ | `text` | The tEXt, zTXt and iTXt chunks: `{ keyword, text, compressed?, language?, translatedKeyword? }` |
78
+ | `exif` | The eXIf chunk's EXIF data |
79
+
80
+ Options:
81
+
82
+ - `checkCRC` (default `true`): check each chunk's CRC. A wrong CRC in a chunk
83
+ the image needs throws, while metadata chunks with one are skipped.
84
+ - `outputDepth` (default `8`): `16` decodes to 16-bit samples in a
85
+ `Uint16Array`, which keeps the precision of 16-bit images.
86
+
87
+ Errors throw an `Error` that says what's wrong, e.g. `Invalid file signature:
88
+ not a PNG file` or `Not enough image data: expected 4128 bytes, got 1000`.
89
+ Like browsers, the decoder doesn't mind data after the end of the file, a
90
+ missing IEND chunk, a wrong zlib checksum or broken metadata chunks.
91
+
92
+ ### `encode(image, options?)`
93
+
94
+ Encodes `{ width, height, data }`, with `data` as RGBA samples: 8 bits each in
95
+ a `Uint8Array` (or `Buffer`), or 16 bits each in a `Uint16Array`.
96
+
97
+ By default it writes the smallest format that keeps every pixel as it is:
98
+
99
+ | Image | Written as |
100
+ | ----------------------------------- | --------------------------------------------------- |
101
+ | Every pixel opaque and gray | Grayscale, at 1, 2, 4 or 8 bits if the levels allow |
102
+ | 256 colours or fewer | A palette, at 1, 2, 4 or 8 bits |
103
+ | Every pixel opaque | RGB |
104
+ | Every pixel gray, some transparent | Gray and alpha |
105
+ | Anything else | RGBA |
106
+ | 16-bit data that doesn't fit 8 bits | The same, at 16 bits (no palette) |
107
+
108
+ | Option | Default | Description |
109
+ | --------------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
110
+ | `colorType` | smallest | A `ColorType`. Converting colour to gray uses the mean of R, G and B. |
111
+ | `bitDepth` | smallest | 1, 2, 4, 8 or 16, if the colour type allows it |
112
+ | `filterType` | `-1` | `-1` (`FilterType.AUTO`) picks the best filter for each line. A filter type 0-4, or a list of them to pick from. Palette and low bit depth images default to `0`, as filters rarely help them. |
113
+ | `deflateLevel` | `9` | zlib's compression level, 0-9 |
114
+ | `deflateStrategy` | `3` | zlib's strategy. 3 (run-length) is fast. 0 or 1 are a little smaller and much slower. |
115
+ | `interlace` | `false` | Write an Adam7 interlaced PNG |
116
+ | `background` | white | `{ red, green, blue }` to blend transparent pixels with when the colour type has no alpha |
117
+ | `idatChunkSize` | one chunk | Split the image data into IDAT chunks of at most this many bytes |
118
+ | `gamma`, `srgb`, `iccProfile`, `physical`, `text`, `exif` | | Metadata to write, as `decode` returns it |
119
+
120
+ ### `decodeFrames(data, options?)`
121
+
122
+ Decodes every frame of an animated PNG (APNG). Each frame is the whole image
123
+ at that point of the animation, with the frames before it drawn underneath as
124
+ the animation says. Returns `{ width, height, frames: [{ data, delay }], plays }`,
125
+ with `delay` in milliseconds and `plays` the number of times the animation
126
+ plays, 0 for forever. A PNG that isn't animated has one frame and no `plays`.
127
+
128
+ Takes `decode`'s options, and `maxFrames` to stop early. `decode` returns the
129
+ image viewers without APNG support show.
130
+
131
+ ### `readHeader(data)`
132
+
133
+ Reads the IHDR chunk: `{ width, height, depth, colorType, interlace }`, without
134
+ decoding anything else.
135
+
136
+ ### `adjustGamma(image, displayGamma = 2.2)`
137
+
138
+ Applies the image's `gamma` to its pixels for a display with the given gamma,
139
+ and sets `gamma` to 0. For 16-bit images, use it on the `outputDepth: 16`
140
+ pixels, which keeps the precision rounding to 8 bits first would lose.
141
+
142
+ ## The pngjs API
143
+
144
+ Everything pngjs exports works the same way, so you can replace
145
+
146
+ ```js
147
+ const { PNG } = require("pngjs");
148
+ ```
149
+
150
+ with
151
+
152
+ ```js
153
+ const { PNG } = require("@jimp/pngjs");
154
+ ```
155
+
156
+ `@types/pngjs` isn't needed: the types are included.
157
+
158
+ ```js
159
+ // Sync
160
+ const png = PNG.sync.read(buffer, { checkCRC, skipRescale, keepIndexed });
161
+ const file = PNG.sync.write(png, { colorType, bitDepth, filterType, ... });
162
+
163
+ // Streams
164
+ fs.createReadStream("in.png")
165
+ .pipe(new PNG({ filterType: 4 }))
166
+ .on("parsed", function () {
167
+ // this.width, this.height, this.data, this.gamma, ...
168
+ this.pack().pipe(fs.createWriteStream("out.png"));
169
+ });
170
+
171
+ new PNG().parse(buffer, (error, png) => {});
172
+
173
+ PNG.bitblt(src, dst, srcX, srcY, width, height, deltaX, deltaY);
174
+ PNG.adjustGamma(png);
175
+ ```
176
+
177
+ The options, events and properties are documented in
178
+ [pngjs's README](https://github.com/pngjs/pngjs#readme). Additions:
179
+
180
+ - `colorType: 3` writes a palette, and `bitDepth` can be 1, 2 or 4 for
181
+ palette and grayscale output.
182
+ - `keepIndexed: true` decodes palette images to one palette index per pixel.
183
+ - `filterType` takes a list of filter types, as pngjs's README says it does.
184
+ - `idatChunkSize` splits the image data into several IDAT chunks.
185
+ - Parsed images also have `palette`, `transColor`, `iccProfile`, `physical`
186
+ and `text`.
187
+ - `PNG` emits `finish` and `close` once parsed, so `stream.pipeline` works,
188
+ and `for await (const chunk of png.pack())` reads the packed PNG.
189
+
190
+ Differences you might notice:
191
+
192
+ - Pixels made transparent by a tRNS colour keep their colour, like in libpng
193
+ and browsers. pngjs made them transparent black.
194
+ - Converting colour to gray rounds the mean of R, G and B. pngjs truncated it.
195
+ - Events are always emitted asynchronously, `metadata` too.
196
+ - `pack()` emits the PNG as one `data` event, unless you pass a
197
+ `deflateFactory`.
198
+ - Errors are always `Error` objects. pngjs sometimes emitted strings.
199
+ - In browsers `data` is a `Uint8Array`, as there's no `Buffer`, and `PNG` is
200
+ an event emitter with `pipe()` rather than a Node.js stream.
201
+
202
+ ## Browsers
203
+
204
+ In Node.js the package compresses with the built-in `node:zlib`. Its
205
+ `browser` export condition, which bundlers use when they build for browsers,
206
+ swaps that for [pako](https://github.com/nodeca/pako), a port of zlib, so the
207
+ output is the same byte for byte. There's nothing to polyfill or configure.
208
+
209
+ Bundled and minified, `decode` alone is 40 KB (14 KB gzipped), and the whole
210
+ package is 70 KB (23 KB gzipped). pngjs's browser build is 205 KB (62 KB
211
+ gzipped).
212
+
213
+ We picked pako over [fflate](https://github.com/101arrowz/fflate), which is
214
+ smaller, because fflate has no run-length (`Z_RLE`) strategy. That's the
215
+ default of pngjs and Jimp, and with fflate encoding was several times slower
216
+ and the files a little bigger.
217
+
218
+ ## Fixed from pngjs
219
+
220
+ Every open issue and pull request on [pngjs](https://github.com/pngjs/pngjs/issues)
221
+ as of November 2026. Most fixes have a test named after the issue in
222
+ [src/issues.test.ts](./src/issues.test.ts) or
223
+ [src/issues.node.test.ts](./src/issues.node.test.ts).
224
+
225
+ | Issue | Problem | Status |
226
+ | ------------------------------------------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------- |
227
+ | [#9](https://github.com/pngjs/pngjs/issues/9) | 16-bit gamma correction off by 1 | Fixed: `adjustGamma` works on 16-bit data |
228
+ | [#10](https://github.com/pngjs/pngjs/issues/10) | 16-bit gamma off by 16 | Obsolete: an old test setting, see #9 |
229
+ | [#54](https://github.com/pngjs/pngjs/issues/54) | BGRA/ARGB to PNG | Usage question |
230
+ | [#64](https://github.com/pngjs/pngjs/issues/64) | `pack()` isn't a real Readable | Improved: `for await` works. It's still a classic stream |
231
+ | [#81](https://github.com/pngjs/pngjs/issues/81) | Grayscale from RGB data | Usage (`inputColorType: 0`). RGB to gray now rounds |
232
+ | [#90](https://github.com/pngjs/pngjs/issues/90) | Palette images | Added: palette writing and `keepIndexed` |
233
+ | [#101](https://github.com/pngjs/pngjs/issues/101) | No `close` event, `stream.pipeline` never finishes | Fixed |
234
+ | [#107](https://github.com/pngjs/pngjs/issues/107) | 24/32-bit support | Usage: that's 8-bit RGB/RGBA, supported |
235
+ | [#115](https://github.com/pngjs/pngjs/issues/115) | Writing metadata | Added: text chunks, pHYs, gamma, sRGB, iCCP, eXIf |
236
+ | [#122](https://github.com/pngjs/pngjs/issues/122) | "Invalid file signature" | Not a bug: the files were JPEGs. The error says "not a PNG file" |
237
+ | [#128](https://github.com/pngjs/pngjs/issues/128) | Fetch and web streams | `decode` takes the `ArrayBuffer` from `response.arrayBuffer()` |
238
+ | [#136](https://github.com/pngjs/pngjs/issues/136) | "incorrect data check" | Fixed: a wrong zlib checksum is ignored, sync and async |
239
+ | [#146](https://github.com/pngjs/pngjs/issues/146) | Colours differ from Chrome | Not a bug: the file has a Display P3 profile, now in `iccProfile` |
240
+ | [#178](https://github.com/pngjs/pngjs/issues/178) | Custom gamma | Added: `adjustGamma`'s `displayGamma` |
241
+ | [#209](https://github.com/pngjs/pngjs/issues/209) | "Unexpected end of input" | Can't reproduce: the file was cut off. Cut-off files now say so |
242
+ | [#219](https://github.com/pngjs/pngjs/issues/219) | Resizing | Out of scope, see [Jimp](https://github.com/jimp-dev/jimp) |
243
+ | [#247](https://github.com/pngjs/pngjs/issues/247) | Streaming pixel rows | Not planned |
244
+ | [#252](https://github.com/pngjs/pngjs/issues/252) | Packing twice writes broken files | Fixed |
245
+ | [#281](https://github.com/pngjs/pngjs/issues/281) | Cropping | Usage: `bitblt` into a smaller PNG |
246
+ | [#282](https://github.com/pngjs/pngjs/issues/282) | `this` in `parsed` | Usage: arrow functions |
247
+ | [#283](https://github.com/pngjs/pngjs/issues/283) | Colour type options | Usage question |
248
+ | [#284](https://github.com/pngjs/pngjs/issues/284) | A weird issue | Usage: wrong `require` path |
249
+ | [#285](https://github.com/pngjs/pngjs/issues/285) | `filterType: 0` with transparent pixels | Fixed in pngjs 2018, has a test |
250
+ | [#286](https://github.com/pngjs/pngjs/issues/286) | Large images | Fixed: memory is only allocated as the data proves it's needed. Tested at 6000x4000 |
251
+ | [#287](https://github.com/pngjs/pngjs/issues/287) | `bitblt` in the README | Fixed: the instance method is in the types |
252
+ | [#288](https://github.com/pngjs/pngjs/issues/288) | Browser and Node.js entry points | Done: `browser` export condition |
253
+ | [#295](https://github.com/pngjs/pngjs/issues/295) | Babel and the browser build | Gone with the browserify build |
254
+ | [#298](https://github.com/pngjs/pngjs/issues/298) | "read requests waiting on finished stream" | Fixed: a missing IEND chunk is fine if the image is complete |
255
+ | [#329](https://github.com/pngjs/pngjs/issues/329) | `this.on is not a function` | Fixed: no zlib internals are used |
256
+ | [#356](https://github.com/pngjs/pngjs/issues/356) | An API without streams | Added: `decode` and `encode` |
257
+ | [#360](https://github.com/pngjs/pngjs/issues/360) | Writing grayscale | Usage (option spelling and byte order). Grayscale writing has tests |
258
+ | [#380](https://github.com/pngjs/pngjs/issues/380) | Memory leak | Fixed: a `PNG` schedules nothing until it's used |
259
+ | [#381](https://github.com/pngjs/pngjs/issues/381) | File permissions in the package | Not applicable to this package |
260
+ | [#382](https://github.com/pngjs/pngjs/issues/382) | Base64 | Usage: `PNG.sync.write(png).toString("base64")` |
261
+ | [#383](https://github.com/pngjs/pngjs/issues/383) | pHYs | Added, read and written |
262
+ | [#386](https://github.com/pngjs/pngjs/issues/386) | Losing colours | Like #146: the ICC profile is in `iccProfile` |
263
+ | [#389](https://github.com/pngjs/pngjs/issues/389) | Accessing the palette | Added: `palette` |
264
+ | [#390](https://github.com/pngjs/pngjs/issues/390) | IEND bytes | Not a bug: they are IEND. Has a test |
265
+ | [#392](https://github.com/pngjs/pngjs/issues/392) | "pin pngjs to v2.3.0" on Node.js 24 | Fixed: zlib comes from the right build, no feature detection |
266
+ | [#394](https://github.com/pngjs/pngjs/issues/394) | Huge allocations from a small file | Fixed: sizes are checked, and allocated only once the data is there |
267
+
268
+ | Pull request | Change | Status |
269
+ | ----------------------------------------------- | ---------------------- | ------------------------------------------------------- |
270
+ | [#225](https://github.com/pngjs/pngjs/pull/225) | Writing palette images | Reimplemented, with `keepIndexed` |
271
+ | [#334](https://github.com/pngjs/pngjs/pull/334) | CRC cleanup | Not needed: native `zlib.crc32` where available |
272
+ | [#384](https://github.com/pngjs/pngjs/pull/384) | Reading pHYs | Reimplemented, with writing |
273
+ | [#385](https://github.com/pngjs/pngjs/pull/385) | Several IDAT chunks | Reimplemented as `idatChunkSize` |
274
+ | [#387](https://github.com/pngjs/pngjs/pull/387) | Native zlib | Reimplemented: native zlib in Node.js, pako in browsers |
275
+ | [#395](https://github.com/pngjs/pngjs/pull/395) | Next-tick retention | Reimplemented: no ticks until data arrives |
276
+
277
+ Bugs without an issue, some found in forks of pngjs:
278
+
279
+ - Async errors (like a bad filter byte) crashed the process instead of
280
+ emitting `error`
281
+ - A short zlib stream returned uninitialised memory as pixels
282
+ - Image data that was too short decoded to a black image instead of an error
283
+ - 16-bit input ignored a `Buffer`'s offset, reading the wrong memory
284
+ - `inputHasAlpha: false` shifted the pixels
285
+ - `filterType` lists threw, though the README documents them
286
+ - gAMA was floored instead of rounded on write (0.45455 became 0.45454)
287
+ - `new PNG({ bitDepth: 16 })` allocated half the memory it needed
288
+ - `bitblt` accepted negative coordinates
289
+ - `PNG.sync.write` added its defaults to the options object you passed
290
+ - Out-of-range palette indices threw (now opaque black, like libpng)
291
+ - A CRC error in a metadata chunk failed the whole image
292
+ - APNG files couldn't be read in Jimp, and interlaced output wasn't
293
+ supported
294
+
295
+ ## Conformance and testing
296
+
297
+ - **[PngSuite](http://www.schaik.com/pngsuite/)**: all 162 valid images decode
298
+ to exactly the pixels libpng does, at 8 and 16 bits, and all 14 corrupt ones
299
+ throw an `Error`. The reference pixels come from netpbm's `pngtopam`,
300
+ checked against ImageMagick, see
301
+ [scripts/generate-pngsuite-reference.mjs](./scripts/generate-pngsuite-reference.mjs).
302
+ Each image also round-trips through `encode`.
303
+ - **pngjs**: the encoder writes the same bytes as pngjs 7.0.0 for the same
304
+ settings, pngjs decodes what it writes, and decoded pixels match except for
305
+ the differences above.
306
+ - **APNG**: frames match ffmpeg's decoder.
307
+ - **Fuzzing**: tens of thousands of randomly broken PngSuite images, from a
308
+ fixed seed, must decode or throw an `Error`, within a second.
309
+
310
+ Each runs with both zlib backends.
311
+
312
+ ## Benchmarks
313
+
314
+ Median of 7 runs on an Apple M5 with Node.js 24, from `pnpm bench`, against
315
+ pngjs 7.0.0. "Browser" is each package's browser build, run in Node.js.
316
+ Encoding uses level 9 and strategy 3, which are both packages' defaults.
317
+
318
+ | Image | Decode: pngjs | Decode: this | Browser decode: pngjs | Browser decode: this |
319
+ | --------------------------- | ------------: | -----------: | --------------------: | -------------------: |
320
+ | Photo, 555x680 RGBA | 5.7 ms | 3.6 ms | 10.7 ms | 7.8 ms |
321
+ | Dice, 800x600 RGBA | 7.7 ms | 2.9 ms | 13.6 ms | 5.2 ms |
322
+ | Font atlas, 4093x146 | 5.2 ms | 0.9 ms | 11.4 ms | 2.9 ms |
323
+ | Photo tiled, 2220x2720 RGBA | 173.1 ms | 118.2 ms | 311.8 ms | 213.2 ms |
324
+
325
+ | Image | Encode: pngjs | Encode: this, same settings | `encode()`, smallest format | Browser encode: pngjs | Browser encode: this |
326
+ | --------------------------- | ------------------: | --------------------------: | --------------------------: | --------------------: | -------------------: |
327
+ | Photo, 555x680 RGBA | 23.5 ms, 494.7 KB | 18.2 ms, 494.7 KB | 17.1 ms, 415.6 KB | 32.0 ms | 28.3 ms |
328
+ | Dice, 800x600 RGBA | 17.6 ms, 232.9 KB | 11.7 ms, 232.9 KB | 11.7 ms, 232.9 KB | 23.8 ms | 17.7 ms |
329
+ | Font atlas, 4093x146 | 17.8 ms, 90.6 KB | 11.8 ms, 90.6 KB | 8.1 ms, 46.9 KB | 22.9 ms | 16.4 ms |
330
+ | Photo tiled, 2220x2720 RGBA | 330.5 ms, 7855.8 KB | 252.8 ms, 7855.8 KB | 233.2 ms, 6598.8 KB | 473.0 ms | 403.1 ms |
331
+
332
+ ## License
333
+
334
+ MIT. See [LICENSE](./LICENSE) for pngjs's and node-pngjs's copyright notices.
335
+ PngSuite's images are by Willem van Schaik, see
336
+ [test/pngsuite/PngSuite.LICENSE](./test/pngsuite/PngSuite.LICENSE).
@@ -0,0 +1,38 @@
1
+ import type { PngInput } from "./decode.js";
2
+ import type { DecodeOptions, PngHeader } from "./types.js";
3
+ export interface DecodeFramesOptions extends DecodeOptions {
4
+ /** Only decode this many frames, from the start @default Infinity */
5
+ maxFrames?: number;
6
+ }
7
+ export interface PngFrame<Data extends Uint8Array | Uint16Array = Uint8Array> {
8
+ /**
9
+ * The whole image as it looks during this frame, as RGBA samples: the
10
+ * frame has been drawn over the ones before it
11
+ */
12
+ data: Data;
13
+ /** How long the frame is shown, in milliseconds */
14
+ delay: number;
15
+ }
16
+ export interface DecodedFrames<Data extends Uint8Array | Uint16Array = Uint8Array> extends PngHeader {
17
+ frames: PngFrame<Data>[];
18
+ /**
19
+ * How many times the animation plays, 0 for forever. Undefined for PNGs
20
+ * that aren't animated.
21
+ */
22
+ plays?: number;
23
+ }
24
+ /**
25
+ * Decodes every frame of an animated PNG (APNG). Each frame is the whole
26
+ * image, with the frames before it drawn underneath as the animation says.
27
+ * A PNG that isn't animated has one frame, the image.
28
+ *
29
+ * Frames after a broken one are dropped, so the animation plays as far as it
30
+ * can, like in browsers.
31
+ */
32
+ export declare function decodeFrames(data: PngInput, options: DecodeFramesOptions & {
33
+ outputDepth: 16;
34
+ }): DecodedFrames<Uint16Array>;
35
+ export declare function decodeFrames(data: PngInput, options?: DecodeFramesOptions & {
36
+ outputDepth?: 8;
37
+ }): DecodedFrames<Uint8Array>;
38
+ //# sourceMappingURL=apng.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apng.d.ts","sourceRoot":"","sources":["../../src/apng.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,WAAW,mBAAoB,SAAQ,aAAa;IACxD,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ,CAAC,IAAI,SAAS,UAAU,GAAG,WAAW,GAAG,UAAU;IAC1E;;;OAGG;IACH,IAAI,EAAE,IAAI,CAAC;IACX,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa,CAC5B,IAAI,SAAS,UAAU,GAAG,WAAW,GAAG,UAAU,CAClD,SAAQ,SAAS;IACjB,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IACzB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAmED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,mBAAmB,GAAG;IAAE,WAAW,EAAE,EAAE,CAAA;CAAE,GACjD,aAAa,CAAC,WAAW,CAAC,CAAC;AAC9B,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,EACd,OAAO,CAAC,EAAE,mBAAmB,GAAG;IAAE,WAAW,CAAC,EAAE,CAAC,CAAA;CAAE,GAClD,aAAa,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { toBuffer, toUint8Array } from "./buffer.js";
2
+ import { decodePixels } from "./pixels.js";
3
+ import { readPng } from "./read.js";
4
+ const DISPOSE_BACKGROUND = 1;
5
+ const DISPOSE_PREVIOUS = 2;
6
+ const BLEND_OVER = 1;
7
+ /** Copies a rectangle of RGBA pixels between images of different widths */
8
+ function copyRect(from, fromWidth, to, toWidth, x, y, width, height, toCanvas) {
9
+ for (let row = 0; row < height; row++) {
10
+ const canvasStart = ((y + row) * (toCanvas ? toWidth : fromWidth) + x) * 4;
11
+ const rectStart = row * width * 4;
12
+ if (toCanvas) {
13
+ to.set(from.subarray(rectStart, rectStart + width * 4), canvasStart);
14
+ }
15
+ else {
16
+ to.set(from.subarray(canvasStart, canvasStart + width * 4), rectStart);
17
+ }
18
+ }
19
+ }
20
+ /** Draws a frame over the canvas with "over" alpha compositing */
21
+ function blendOver(frame, canvas, canvasWidth, control, max) {
22
+ for (let row = 0; row < control.height; row++) {
23
+ let i = row * control.width * 4;
24
+ let o = ((control.y + row) * canvasWidth + control.x) * 4;
25
+ for (let x = 0; x < control.width; x++, i += 4, o += 4) {
26
+ const sa = frame[i + 3];
27
+ if (sa === max) {
28
+ canvas[o] = frame[i];
29
+ canvas[o + 1] = frame[i + 1];
30
+ canvas[o + 2] = frame[i + 2];
31
+ canvas[o + 3] = max;
32
+ }
33
+ else if (sa > 0) {
34
+ const da = (canvas[o + 3] * (max - sa)) / max;
35
+ const a = sa + da;
36
+ canvas[o] = Math.round((frame[i] * sa + canvas[o] * da) / a);
37
+ canvas[o + 1] = Math.round((frame[i + 1] * sa + canvas[o + 1] * da) / a);
38
+ canvas[o + 2] = Math.round((frame[i + 2] * sa + canvas[o + 2] * da) / a);
39
+ canvas[o + 3] = Math.round(a);
40
+ }
41
+ }
42
+ }
43
+ }
44
+ export function decodeFrames(data, { checkCRC = true, outputDepth = 8, maxFrames = Infinity, } = {}) {
45
+ const file = readPng(toUint8Array(data), { checkCRC, frames: true });
46
+ const mode = outputDepth === 16 ? 16 : 8;
47
+ const info = {
48
+ ...file.header,
49
+ palette: file.palette,
50
+ transparentColor: file.transparentColor,
51
+ };
52
+ const wrap = (pixels) => pixels instanceof Uint8Array ? toBuffer(pixels) : pixels;
53
+ if (!file.animation || file.frames.length === 0) {
54
+ return {
55
+ ...file.header,
56
+ frames: [{ data: wrap(decodePixels(info, file.idat, mode)), delay: 0 }],
57
+ };
58
+ }
59
+ const { width, height } = file.header;
60
+ const max = mode === 16 ? 65535 : 255;
61
+ const canvas = mode === 16
62
+ ? new Uint16Array(width * height * 4)
63
+ : new Uint8Array(width * height * 4);
64
+ const frames = [];
65
+ for (const [index, frame] of file.frames.entries()) {
66
+ if (frames.length >= maxFrames) {
67
+ break;
68
+ }
69
+ const { control } = frame;
70
+ let pixels;
71
+ try {
72
+ pixels = decodePixels({ ...info, width: control.width, height: control.height }, frame.data, mode);
73
+ }
74
+ catch (error) {
75
+ if (index === 0) {
76
+ throw error;
77
+ }
78
+ break;
79
+ }
80
+ // The first frame can't restore the canvas from before it
81
+ const dispose = index === 0 && control.dispose === DISPOSE_PREVIOUS
82
+ ? DISPOSE_BACKGROUND
83
+ : control.dispose;
84
+ let saved;
85
+ if (dispose === DISPOSE_PREVIOUS) {
86
+ saved = canvas.slice(0, control.width * control.height * 4);
87
+ copyRect(canvas, width, saved, control.width, control.x, control.y, control.width, control.height, false);
88
+ }
89
+ if (control.blend === BLEND_OVER) {
90
+ blendOver(pixels, canvas, width, control, max);
91
+ }
92
+ else {
93
+ copyRect(pixels, control.width, canvas, width, control.x, control.y, control.width, control.height, true);
94
+ }
95
+ frames.push({ data: wrap(canvas.slice()), delay: control.delay });
96
+ if (dispose === DISPOSE_BACKGROUND) {
97
+ copyRect(new Uint8Array(control.width * control.height * 4), control.width, canvas, width, control.x, control.y, control.width, control.height, true);
98
+ }
99
+ else if (saved) {
100
+ copyRect(saved, control.width, canvas, width, control.x, control.y, control.width, control.height, true);
101
+ }
102
+ }
103
+ return {
104
+ ...file.header,
105
+ frames,
106
+ plays: file.animation.loops,
107
+ };
108
+ }
109
+ //# sourceMappingURL=apng.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apng.js","sourceRoot":"","sources":["../../src/apng.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8BpC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,2EAA2E;AAC3E,SAAS,QAAQ,CACf,IAA8B,EAC9B,SAAiB,EACjB,EAA4B,EAC5B,OAAe,EACf,CAAS,EACT,CAAS,EACT,KAAa,EACb,MAAc,EACd,QAAiB;IAEjB,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;QACtC,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QAC3E,MAAM,SAAS,GAAG,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC;QAElC,IAAI,QAAQ,EAAE,CAAC;YACb,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;QACvE,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC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I,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAElE,IAAI,OAAO,KAAK,kBAAkB,EAAE,CAAC;YACnC,QAAQ,CACN,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,EAClD,OAAO,CAAC,KAAK,EACb,MAAM,EACN,KAAK,EACL,OAAO,CAAC,CAAC,EACT,OAAO,CAAC,CAAC,EACT,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,MAAM,EACd,IAAI,CACL,CAAC;QACJ,CAAC;aAAM,IAAI,KAAK,EAAE,CAAC;YACjB,QAAQ,CACN,KAAK,EACL,OAAO,CAAC,KAAK,EACb,MAAM,EACN,KAAK,EACL,OAAO,CAAC,CAAC,EACT,OAAO,CAAC,CAAC,EACT,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,MAAM,EACd,IAAI,CACL,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,GAAG,IAAI,CAAC,MAAM;QACd,MAAM;QACN,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK;KACC,CAAC;AACjC,CAAC","sourcesContent":["import { toBuffer, toUint8Array } from \"./buffer.js\";\nimport type { PngInput } from \"./decode.js\";\nimport { decodePixels } from \"./pixels.js\";\nimport { readPng } from \"./read.js\";\nimport type { FrameControl } from \"./read.js\";\nimport type { DecodeOptions, PngHeader } from \"./types.js\";\n\nexport interface DecodeFramesOptions extends DecodeOptions {\n /** Only decode this many frames, from the start @default Infinity */\n maxFrames?: number;\n}\n\nexport interface PngFrame<Data extends Uint8Array | Uint16Array = Uint8Array> {\n /**\n * The whole image as it looks during this frame, as RGBA samples: the\n * frame has been drawn over the ones before it\n */\n data: Data;\n /** How long the frame is shown, in milliseconds */\n delay: number;\n}\n\nexport interface DecodedFrames<\n Data extends Uint8Array | Uint16Array = Uint8Array,\n> extends PngHeader {\n frames: PngFrame<Data>[];\n /**\n * How many times the animation plays, 0 for forever. Undefined for PNGs\n * that aren't animated.\n */\n plays?: number;\n}\n\nconst DISPOSE_BACKGROUND = 1;\nconst DISPOSE_PREVIOUS = 2;\nconst BLEND_OVER = 1;\n\n/** Copies a rectangle of RGBA pixels between images of different widths */\nfunction copyRect(\n from: Uint8Array | Uint16Array,\n fromWidth: number,\n to: Uint8Array | Uint16Array,\n toWidth: number,\n x: number,\n y: number,\n width: number,\n height: number,\n toCanvas: boolean,\n) {\n for (let row = 0; row < height; row++) {\n const canvasStart = ((y + row) * (toCanvas ? toWidth : fromWidth) + x) * 4;\n const rectStart = row * width * 4;\n\n if (toCanvas) {\n to.set(from.subarray(rectStart, rectStart + width * 4), canvasStart);\n } else {\n to.set(from.subarray(canvasStart, canvasStart + width * 4), rectStart);\n }\n }\n}\n\n/** Draws a frame over the canvas with \"over\" alpha compositing */\nfunction blendOver(\n frame: Uint8Array | Uint16Array,\n canvas: Uint8Array | Uint16Array,\n canvasWidth: number,\n control: FrameControl,\n max: number,\n) {\n for (let row = 0; row < control.height; row++) {\n let i = row * control.width * 4;\n let o = ((control.y + row) * canvasWidth + control.x) * 4;\n\n for (let x = 0; x < control.width; x++, i += 4, o += 4) {\n const sa = frame[i + 3]!;\n\n if (sa === max) {\n canvas[o] = frame[i]!;\n canvas[o + 1] = frame[i + 1]!;\n canvas[o + 2] = frame[i + 2]!;\n canvas[o + 3] = max;\n } else if (sa > 0) {\n const da = (canvas[o + 3]! * (max - sa)) / max;\n const a = sa + da;\n\n canvas[o] = Math.round((frame[i]! * sa + canvas[o]! * da) / a);\n canvas[o + 1] = Math.round(\n (frame[i + 1]! * sa + canvas[o + 1]! * da) / a,\n );\n canvas[o + 2] = Math.round(\n (frame[i + 2]! * sa + canvas[o + 2]! * da) / a,\n );\n canvas[o + 3] = Math.round(a);\n }\n }\n }\n}\n\n/**\n * Decodes every frame of an animated PNG (APNG). Each frame is the whole\n * image, with the frames before it drawn underneath as the animation says.\n * A PNG that isn't animated has one frame, the image.\n *\n * Frames after a broken one are dropped, so the animation plays as far as it\n * can, like in browsers.\n */\nexport function decodeFrames(\n data: PngInput,\n options: DecodeFramesOptions & { outputDepth: 16 },\n): DecodedFrames<Uint16Array>;\nexport function decodeFrames(\n data: PngInput,\n options?: DecodeFramesOptions & { outputDepth?: 8 },\n): DecodedFrames<Uint8Array>;\nexport function decodeFrames(\n data: PngInput,\n {\n checkCRC = true,\n outputDepth = 8,\n maxFrames = Infinity,\n }: DecodeFramesOptions = {},\n): DecodedFrames<Uint8Array> | DecodedFrames<Uint16Array> {\n const file = readPng(toUint8Array(data), { checkCRC, frames: true });\n const mode = outputDepth === 16 ? 16 : 8;\n const info = {\n ...file.header,\n palette: file.palette,\n transparentColor: file.transparentColor,\n };\n const wrap = (pixels: Uint8Array | Uint16Array) =>\n pixels instanceof Uint8Array ? toBuffer(pixels) : pixels;\n\n if (!file.animation || file.frames.length === 0) {\n return {\n ...file.header,\n frames: [{ data: wrap(decodePixels(info, file.idat, mode)), delay: 0 }],\n } as DecodedFrames<Uint8Array>;\n }\n\n const { width, height } = file.header;\n const max = mode === 16 ? 65535 : 255;\n const canvas =\n mode === 16\n ? new Uint16Array(width * height * 4)\n : new Uint8Array(width * height * 4);\n const frames: PngFrame<Uint8Array | Uint16Array>[] = [];\n\n for (const [index, frame] of file.frames.entries()) {\n if (frames.length >= maxFrames) {\n break;\n }\n\n const { control } = frame;\n let pixels: Uint8Array | Uint16Array;\n\n try {\n pixels = decodePixels(\n { ...info, width: control.width, height: control.height },\n frame.data,\n mode,\n );\n } catch (error) {\n if (index === 0) {\n throw error;\n }\n\n break;\n }\n\n // The first frame can't restore the canvas from before it\n const dispose =\n index === 0 && control.dispose === DISPOSE_PREVIOUS\n ? DISPOSE_BACKGROUND\n : control.dispose;\n let saved: Uint8Array | Uint16Array | undefined;\n\n if (dispose === DISPOSE_PREVIOUS) {\n saved = canvas.slice(0, control.width * control.height * 4);\n copyRect(\n canvas,\n width,\n saved,\n control.width,\n control.x,\n control.y,\n control.width,\n control.height,\n false,\n );\n }\n\n if (control.blend === BLEND_OVER) {\n blendOver(pixels, canvas, width, control, max);\n } else {\n copyRect(\n pixels,\n control.width,\n canvas,\n width,\n control.x,\n control.y,\n control.width,\n control.height,\n true,\n );\n }\n\n frames.push({ data: wrap(canvas.slice()), delay: control.delay });\n\n if (dispose === DISPOSE_BACKGROUND) {\n copyRect(\n new Uint8Array(control.width * control.height * 4),\n control.width,\n canvas,\n width,\n control.x,\n control.y,\n control.width,\n control.height,\n true,\n );\n } else if (saved) {\n copyRect(\n saved,\n control.width,\n canvas,\n width,\n control.x,\n control.y,\n control.width,\n control.height,\n true,\n );\n }\n }\n\n return {\n ...file.header,\n frames,\n plays: file.animation.loops,\n } as DecodedFrames<Uint8Array>;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer-browser.d.mts","sourceRoot":"","sources":["../../src/buffer-browser.mts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC;AAEpC,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAErD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,UAAU,CAEvE"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer-browser.mjs","sourceRoot":"","sources":["../../src/buffer-browser.mts"],"names":[],"mappings":"AAAA,0DAA0D;AAK1D,MAAM,UAAU,QAAQ,CAAC,IAAgB;IACvC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAA8B;IACzD,OAAO,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC","sourcesContent":["// Browsers have no Buffer, so the data stays a Uint8Array\n\n/** A Buffer in Node.js, a Uint8Array in browsers */\nexport type BufferLike = Uint8Array;\n\nexport function toBuffer(data: Uint8Array): BufferLike {\n return data;\n}\n\nexport function toUint8Array(data: Uint8Array | ArrayBuffer): Uint8Array {\n return data instanceof Uint8Array ? data : new Uint8Array(data);\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /** A Buffer in Node.js, a Uint8Array in browsers */
2
+ export type BufferLike = Uint8Array;
3
+ export declare function toBuffer(data: Uint8Array): BufferLike;
4
+ export declare function toUint8Array(data: Uint8Array | ArrayBuffer): Uint8Array;
5
+ //# sourceMappingURL=buffer-browser.d.mts.map
@@ -0,0 +1,8 @@
1
+ // Browsers have no Buffer, so the data stays a Uint8Array
2
+ export function toBuffer(data) {
3
+ return data;
4
+ }
5
+ export function toUint8Array(data) {
6
+ return data instanceof Uint8Array ? data : new Uint8Array(data);
7
+ }
8
+ //# sourceMappingURL=buffer-browser.mjs.map
@@ -0,0 +1,39 @@
1
+ export declare const PNG_SIGNATURE: Uint8Array<ArrayBuffer>;
2
+ /**
3
+ * How a PNG stores its pixels. The value is a sum of 1 (palette), 2 (colour)
4
+ * and 4 (alpha channel).
5
+ */
6
+ export declare enum ColorType {
7
+ GRAYSCALE = 0,
8
+ COLOR = 2,
9
+ PALETTE = 3,
10
+ GRAYSCALE_ALPHA = 4,
11
+ COLOR_ALPHA = 6
12
+ }
13
+ /** Bits per sample, or per palette index for palette images */
14
+ export type BitDepth = 1 | 2 | 4 | 8 | 16;
15
+ /** How each scanline is transformed before compression */
16
+ export declare enum FilterType {
17
+ /** Try every filter on each line and keep the one that looks smallest */
18
+ AUTO = -1,
19
+ /** The line is stored as is */
20
+ NONE = 0,
21
+ /** Each byte minus the one a pixel to its left */
22
+ SUB = 1,
23
+ /** Each byte minus the one above it */
24
+ UP = 2,
25
+ /** Each byte minus the average of the ones to its left and above */
26
+ AVERAGE = 3,
27
+ /** Each byte minus whichever of left, above or above-left predicts it best */
28
+ PAETH = 4
29
+ }
30
+ /** The bit depths each colour type allows */
31
+ export declare const ALLOWED_BIT_DEPTHS: Record<ColorType, readonly BitDepth[]>;
32
+ /** Samples (channels) per pixel of each colour type */
33
+ export declare const CHANNELS: Record<ColorType, number>;
34
+ /** gAMA stores the gamma times 100000 */
35
+ export declare const GAMMA_DIVISION = 100000;
36
+ /** The largest length a chunk may have, 2^31 - 1 */
37
+ export declare const MAX_CHUNK_LENGTH = 2147483647;
38
+ export declare function isColorType(value: number): value is ColorType;
39
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,yBAExB,CAAC;AAEH;;;GAGG;AACH,oBAAY,SAAS;IACnB,SAAS,IAAI;IACb,KAAK,IAAI;IACT,OAAO,IAAI;IACX,eAAe,IAAI;IACnB,WAAW,IAAI;CAChB;AAED,+DAA+D;AAC/D,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;AAE1C,0DAA0D;AAC1D,oBAAY,UAAU;IACpB,yEAAyE;IACzE,IAAI,KAAK;IACT,+BAA+B;IAC/B,IAAI,IAAI;IACR,kDAAkD;IAClD,GAAG,IAAI;IACP,uCAAuC;IACvC,EAAE,IAAI;IACN,oEAAoE;IACpE,OAAO,IAAI;IACX,8EAA8E;IAC9E,KAAK,IAAI;CACV;AAED,6CAA6C;AAC7C,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAMrE,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAM9C,CAAC;AAEF,yCAAyC;AACzC,eAAO,MAAM,cAAc,SAAS,CAAC;AAErC,oDAAoD;AACpD,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,SAAS,CAE7D"}