@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
@@ -0,0 +1,147 @@
1
+ import type { BitDepth, ColorType } from "./constants.js";
2
+ /** The IHDR chunk: how the image's pixels are stored */
3
+ export interface PngHeader {
4
+ width: number;
5
+ height: number;
6
+ /** Bits per sample, or per palette index */
7
+ depth: BitDepth;
8
+ colorType: ColorType;
9
+ /** Whether the pixels are stored in Adam7 interlaced order */
10
+ interlace: boolean;
11
+ }
12
+ /** An RGBA palette entry, with 8-bit samples */
13
+ export type PaletteColor = [r: number, g: number, b: number, a: number];
14
+ /** The pHYs chunk: the intended pixel size or aspect ratio */
15
+ export interface PhysicalDimensions {
16
+ /** Pixels per unit, horizontally */
17
+ x: number;
18
+ /** Pixels per unit, vertically */
19
+ y: number;
20
+ /**
21
+ * "meter" if `x` and `y` are pixels per meter. "unknown" if they only give
22
+ * the aspect ratio.
23
+ */
24
+ unit: "unknown" | "meter";
25
+ }
26
+ /**
27
+ * A text chunk. Encoding writes tEXt, zTXt when `compressed`, or iTXt when the
28
+ * text isn't Latin-1 or has a `language` or `translatedKeyword`.
29
+ */
30
+ export interface PngText {
31
+ /** 1-79 Latin-1 characters, e.g. "Title", "Author", "Description" */
32
+ keyword: string;
33
+ text: string;
34
+ /** Whether the text is (or should be) zlib compressed */
35
+ compressed?: boolean;
36
+ /** The language of the text, as a BCP 47 tag like "en-GB" (iTXt only) */
37
+ language?: string;
38
+ /** The keyword, in the text's language (iTXt only) */
39
+ translatedKeyword?: string;
40
+ }
41
+ /** The iCCP chunk: an ICC colour profile */
42
+ export interface IccProfile {
43
+ /** The profile's name, 1-79 Latin-1 characters */
44
+ name: string;
45
+ /** The profile, uncompressed */
46
+ data: Uint8Array;
47
+ }
48
+ /**
49
+ * The sRGB chunk's rendering intent: 0 perceptual, 1 relative colorimetric,
50
+ * 2 saturation, 3 absolute colorimetric
51
+ */
52
+ export type RenderingIntent = 0 | 1 | 2 | 3;
53
+ /** Metadata stored in ancillary chunks, which encode() can also write */
54
+ export interface PngMetadata {
55
+ /** The gAMA chunk: the image's gamma, e.g. 0.45455 for 1 / 2.2 */
56
+ gamma?: number;
57
+ /** The sRGB chunk: the pixels are sRGB, rendered with this intent */
58
+ srgb?: RenderingIntent;
59
+ iccProfile?: IccProfile;
60
+ physical?: PhysicalDimensions;
61
+ /** tEXt, zTXt and iTXt chunks, in file order */
62
+ text?: PngText[];
63
+ /** The eXIf chunk: EXIF data, starting with the TIFF header */
64
+ exif?: Uint8Array;
65
+ }
66
+ export interface DecodedPng<Data extends Uint8Array | Uint16Array = Uint8Array> extends PngHeader, PngMetadata {
67
+ /**
68
+ * The pixels, row by row, as R, G, B, A samples. 8 bits each, or 16 with
69
+ * `outputDepth: 16`.
70
+ */
71
+ data: Data;
72
+ /** The palette of palette images, with the tRNS alpha applied */
73
+ palette?: PaletteColor[];
74
+ /**
75
+ * The tRNS colour of grayscale and colour images: pixels with this gray
76
+ * value, or these R, G, B values, are transparent. The samples are at the
77
+ * image's bit depth.
78
+ */
79
+ transparentColor?: number[];
80
+ text: PngText[];
81
+ }
82
+ export interface DecodeOptions {
83
+ /**
84
+ * Check the CRC of each chunk. A wrong CRC in a chunk the image needs is an
85
+ * error, while chunks with only metadata are skipped.
86
+ * @default true
87
+ */
88
+ checkCRC?: boolean;
89
+ /**
90
+ * The bit depth of the decoded samples. 16 returns a Uint16Array, which
91
+ * keeps the full precision of 16-bit images.
92
+ * @default 8
93
+ */
94
+ outputDepth?: 8 | 16;
95
+ }
96
+ /** An RGBA image to encode */
97
+ export interface ImageData<Data extends Uint8Array | Uint16Array = Uint8Array> {
98
+ width: number;
99
+ height: number;
100
+ /**
101
+ * The pixels, row by row, as R, G, B, A samples: 8 bits each in a
102
+ * Uint8Array (or Buffer), 16 in a Uint16Array
103
+ */
104
+ data: Data;
105
+ }
106
+ export interface EncodeOptions extends PngMetadata {
107
+ /**
108
+ * The colour type to write. By default the smallest one that stores the
109
+ * image without loss: grayscale if every pixel is gray, a palette if there
110
+ * are 256 colours or fewer, and an alpha channel only if a pixel isn't
111
+ * opaque.
112
+ */
113
+ colorType?: ColorType;
114
+ /**
115
+ * Bits per sample (or palette index). By default the smallest that's
116
+ * lossless for the colour type. 16 needs 16-bit input to be lossless.
117
+ */
118
+ bitDepth?: BitDepth;
119
+ /**
120
+ * The filter for each line, or the filters to choose from. AUTO picks the
121
+ * best of all five for each line. By default AUTO, or NONE for palette and
122
+ * low bit depth images, as filters rarely help them.
123
+ */
124
+ filterType?: number | number[];
125
+ /** @default 9 */
126
+ deflateLevel?: number;
127
+ /** zlib's strategy, e.g. 3 (Z_RLE) or 0 (Z_DEFAULT_STRATEGY) @default 3 */
128
+ deflateStrategy?: number;
129
+ /**
130
+ * Split the compressed data into IDAT chunks of at most this many bytes.
131
+ * By default it's one chunk, which is smallest.
132
+ */
133
+ idatChunkSize?: number;
134
+ /**
135
+ * With a colour type without alpha, blend transparent pixels with this
136
+ * background colour. 8-bit samples for 8-bit output, 16-bit for 16-bit.
137
+ * @default white
138
+ */
139
+ background?: {
140
+ red: number;
141
+ green: number;
142
+ blue: number;
143
+ };
144
+ /** Write the image interlaced (Adam7). Bigger, but it can show early. */
145
+ interlace?: boolean;
146
+ }
147
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,gBAAg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E,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1D,yEAAyE;IACzE,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { BitDepth, ColorType } from \"./constants.js\";\n\n/** The IHDR chunk: how the image's pixels are stored */\nexport interface PngHeader {\n width: number;\n height: number;\n /** Bits per sample, or per palette index */\n depth: BitDepth;\n colorType: ColorType;\n /** Whether the pixels are stored in Adam7 interlaced order */\n interlace: boolean;\n}\n\n/** An RGBA palette entry, with 8-bit samples */\nexport type PaletteColor = [r: number, g: number, b: number, a: number];\n\n/** The pHYs chunk: the intended pixel size or aspect ratio */\nexport interface PhysicalDimensions {\n /** Pixels per unit, horizontally */\n x: number;\n /** Pixels per unit, vertically */\n y: number;\n /**\n * \"meter\" if `x` and `y` are pixels per meter. \"unknown\" if they only give\n * the aspect ratio.\n */\n unit: \"unknown\" | \"meter\";\n}\n\n/**\n * A text chunk. Encoding writes tEXt, zTXt when `compressed`, or iTXt when the\n * text isn't Latin-1 or has a `language` or `translatedKeyword`.\n */\nexport interface PngText {\n /** 1-79 Latin-1 characters, e.g. \"Title\", \"Author\", \"Description\" */\n keyword: string;\n text: string;\n /** Whether the text is (or should be) zlib compressed */\n compressed?: boolean;\n /** The language of the text, as a BCP 47 tag like \"en-GB\" (iTXt only) */\n language?: string;\n /** The keyword, in the text's language (iTXt only) */\n translatedKeyword?: string;\n}\n\n/** The iCCP chunk: an ICC colour profile */\nexport interface IccProfile {\n /** The profile's name, 1-79 Latin-1 characters */\n name: string;\n /** The profile, uncompressed */\n data: Uint8Array;\n}\n\n/**\n * The sRGB chunk's rendering intent: 0 perceptual, 1 relative colorimetric,\n * 2 saturation, 3 absolute colorimetric\n */\nexport type RenderingIntent = 0 | 1 | 2 | 3;\n\n/** Metadata stored in ancillary chunks, which encode() can also write */\nexport interface PngMetadata {\n /** The gAMA chunk: the image's gamma, e.g. 0.45455 for 1 / 2.2 */\n gamma?: number;\n /** The sRGB chunk: the pixels are sRGB, rendered with this intent */\n srgb?: RenderingIntent;\n iccProfile?: IccProfile;\n physical?: PhysicalDimensions;\n /** tEXt, zTXt and iTXt chunks, in file order */\n text?: PngText[];\n /** The eXIf chunk: EXIF data, starting with the TIFF header */\n exif?: Uint8Array;\n}\n\nexport interface DecodedPng<Data extends Uint8Array | Uint16Array = Uint8Array>\n extends PngHeader, PngMetadata {\n /**\n * The pixels, row by row, as R, G, B, A samples. 8 bits each, or 16 with\n * `outputDepth: 16`.\n */\n data: Data;\n /** The palette of palette images, with the tRNS alpha applied */\n palette?: PaletteColor[];\n /**\n * The tRNS colour of grayscale and colour images: pixels with this gray\n * value, or these R, G, B values, are transparent. The samples are at the\n * image's bit depth.\n */\n transparentColor?: number[];\n text: PngText[];\n}\n\nexport interface DecodeOptions {\n /**\n * Check the CRC of each chunk. A wrong CRC in a chunk the image needs is an\n * error, while chunks with only metadata are skipped.\n * @default true\n */\n checkCRC?: boolean;\n /**\n * The bit depth of the decoded samples. 16 returns a Uint16Array, which\n * keeps the full precision of 16-bit images.\n * @default 8\n */\n outputDepth?: 8 | 16;\n}\n\n/** An RGBA image to encode */\nexport interface ImageData<Data extends Uint8Array | Uint16Array = Uint8Array> {\n width: number;\n height: number;\n /**\n * The pixels, row by row, as R, G, B, A samples: 8 bits each in a\n * Uint8Array (or Buffer), 16 in a Uint16Array\n */\n data: Data;\n}\n\nexport interface EncodeOptions extends PngMetadata {\n /**\n * The colour type to write. By default the smallest one that stores the\n * image without loss: grayscale if every pixel is gray, a palette if there\n * are 256 colours or fewer, and an alpha channel only if a pixel isn't\n * opaque.\n */\n colorType?: ColorType;\n /**\n * Bits per sample (or palette index). By default the smallest that's\n * lossless for the colour type. 16 needs 16-bit input to be lossless.\n */\n bitDepth?: BitDepth;\n /**\n * The filter for each line, or the filters to choose from. AUTO picks the\n * best of all five for each line. By default AUTO, or NONE for palette and\n * low bit depth images, as filters rarely help them.\n */\n filterType?: number | number[];\n /** @default 9 */\n deflateLevel?: number;\n /** zlib's strategy, e.g. 3 (Z_RLE) or 0 (Z_DEFAULT_STRATEGY) @default 3 */\n deflateStrategy?: number;\n /**\n * Split the compressed data into IDAT chunks of at most this many bytes.\n * By default it's one chunk, which is smallest.\n */\n idatChunkSize?: number;\n /**\n * With a colour type without alpha, blend transparent pixels with this\n * background colour. 8-bit samples for 8-bit output, 16-bit for 16-bit.\n * @default white\n */\n background?: { red: number; green: number; blue: number };\n /** Write the image interlaced (Adam7). Bigger, but it can show early. */\n interlace?: boolean;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zlib-browser.d.mts","sourceRoot":"","sources":["../../src/zlib-browser.mts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,KAAK,gBAAU,CAAC;AAC7B,eAAO,MAAM,UAAU,qBAAe,CAAC;AAEvC,uCAAuC;AACvC,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,2BAgBhE"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zlib-browser.mjs","sourceRoot":"","sources":["../../src/zlib-browser.mts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,2DAA2D;AAC3D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAG9C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAC;AAC7B,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AAEvC,uCAAuC;AACvC,MAAM,UAAU,OAAO,CAAC,IAAgB,EAAE,OAAuB;IAC/D,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAErE,wEAAwE;IACxE,OAAO,WAAW,CAChB,IAAI,EACJ,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC;QACb,KAAK;QACL,QAAQ,EAAE,QAAkC;QAC5C,UAAU;QACV,QAAQ;QACR,SAAS;KACV,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAC9C,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Browsers: use pako, a port of zlib, so output matches Node's byte for byte\n// and every deflate level and strategy works the same way.\nimport { deflate as pakoDeflate } from \"pako\";\nimport type { Z_Strategy } from \"pako\";\n\nimport { crc32Js } from \"./crc.js\";\nimport { inflateRawJs } from \"./inflate-js.js\";\n\nexport interface DeflateOptions {\n level?: number;\n strategy?: number;\n windowBits?: number;\n memLevel?: number;\n chunkSize?: number;\n}\n\nexport const crc32 = crc32Js;\nexport const inflateRaw = inflateRawJs;\n\n/** Compresses data to a zlib stream */\nexport function deflate(data: Uint8Array, options: DeflateOptions) {\n const { level, strategy, windowBits, memLevel, chunkSize } = options;\n\n // pako's defaults are replaced by any key that's set, even to undefined\n return pakoDeflate(\n data,\n Object.fromEntries(\n Object.entries({\n level,\n strategy: strategy as Z_Strategy | undefined,\n windowBits,\n memLevel,\n chunkSize,\n }).filter(([, value]) => value !== undefined),\n ),\n );\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /** The most a compressed metadata chunk (zTXt, iTXt, iCCP) may inflate to */
2
+ export declare const MAX_METADATA_LENGTH: number;
3
+ /**
4
+ * Inflates a zlib stream, up to `maxLength` bytes. The Adler-32 checksum at
5
+ * the end isn't checked: like browsers, a wrong one doesn't stop the image
6
+ * from loading. Each chunk has a CRC anyway.
7
+ */
8
+ export declare function inflateZlib(data: Uint8Array, maxLength: number): Uint8Array<ArrayBufferLike>;
9
+ //# sourceMappingURL=zlib-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zlib-stream.d.ts","sourceRoot":"","sources":["../../src/zlib-stream.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,QAAmB,CAAC;AAKpD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,+BA0B9D"}
@@ -0,0 +1,31 @@
1
+ import { inflateRaw } from "./zlib.js";
2
+ /** The most a compressed metadata chunk (zTXt, iTXt, iCCP) may inflate to */
3
+ export const MAX_METADATA_LENGTH = 16 * 1024 * 1024;
4
+ /** Deflate can't compress better than this */
5
+ const MAX_DEFLATE_RATIO = 1032;
6
+ /**
7
+ * Inflates a zlib stream, up to `maxLength` bytes. The Adler-32 checksum at
8
+ * the end isn't checked: like browsers, a wrong one doesn't stop the image
9
+ * from loading. Each chunk has a CRC anyway.
10
+ */
11
+ export function inflateZlib(data, maxLength) {
12
+ if (data.length < 2) {
13
+ throw new Error("Invalid compressed data: too short");
14
+ }
15
+ const cmf = data[0];
16
+ const flg = data[1];
17
+ if ((cmf & 0x0f) !== 8 || cmf >> 4 > 7 || ((cmf << 8) | flg) % 31 !== 0) {
18
+ throw new Error("Invalid compressed data: bad zlib header");
19
+ }
20
+ if (flg & 0x20) {
21
+ throw new Error("Invalid compressed data: zlib preset dictionary");
22
+ }
23
+ const sizeHint = Math.min(maxLength, data.length * MAX_DEFLATE_RATIO + 1024);
24
+ try {
25
+ return inflateRaw(data.subarray(2), maxLength, sizeHint);
26
+ }
27
+ catch (error) {
28
+ throw new Error(`Invalid compressed data: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
29
+ }
30
+ }
31
+ //# sourceMappingURL=zlib-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zlib-stream.js","sourceRoot":"","sources":["../../src/zlib-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpD,8CAA8C;AAC9C,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAgB,EAAE,SAAiB;IAC7D,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;IACrB,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;IAErB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,GAAG,GAAG,IAAI,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAE7E,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,4BAA4B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACpF,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { inflateRaw } from \"./zlib.js\";\n\n/** The most a compressed metadata chunk (zTXt, iTXt, iCCP) may inflate to */\nexport const MAX_METADATA_LENGTH = 16 * 1024 * 1024;\n\n/** Deflate can't compress better than this */\nconst MAX_DEFLATE_RATIO = 1032;\n\n/**\n * Inflates a zlib stream, up to `maxLength` bytes. The Adler-32 checksum at\n * the end isn't checked: like browsers, a wrong one doesn't stop the image\n * from loading. Each chunk has a CRC anyway.\n */\nexport function inflateZlib(data: Uint8Array, maxLength: number) {\n if (data.length < 2) {\n throw new Error(\"Invalid compressed data: too short\");\n }\n\n const cmf = data[0]!;\n const flg = data[1]!;\n\n if ((cmf & 0x0f) !== 8 || cmf >> 4 > 7 || ((cmf << 8) | flg) % 31 !== 0) {\n throw new Error(\"Invalid compressed data: bad zlib header\");\n }\n\n if (flg & 0x20) {\n throw new Error(\"Invalid compressed data: zlib preset dictionary\");\n }\n\n const sizeHint = Math.min(maxLength, data.length * MAX_DEFLATE_RATIO + 1024);\n\n try {\n return inflateRaw(data.subarray(2), maxLength, sizeHint);\n } catch (error) {\n throw new Error(\n `Invalid compressed data: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { crc32Js } from "./crc.js";
2
+ import { inflateRawJs } from "./inflate-js.js";
3
+ export interface DeflateOptions {
4
+ level?: number;
5
+ strategy?: number;
6
+ windowBits?: number;
7
+ memLevel?: number;
8
+ chunkSize?: number;
9
+ }
10
+ export declare const crc32: typeof crc32Js;
11
+ export declare const inflateRaw: typeof inflateRawJs;
12
+ /** Compresses data to a zlib stream */
13
+ export declare function deflate(data: Uint8Array, options: DeflateOptions): Uint8Array<ArrayBuffer>;
14
+ //# sourceMappingURL=zlib-browser.d.mts.map
@@ -0,0 +1,20 @@
1
+ // Browsers: use pako, a port of zlib, so output matches Node's byte for byte
2
+ // and every deflate level and strategy works the same way.
3
+ import { deflate as pakoDeflate } from "pako";
4
+ import { crc32Js } from "./crc.js";
5
+ import { inflateRawJs } from "./inflate-js.js";
6
+ export const crc32 = crc32Js;
7
+ export const inflateRaw = inflateRawJs;
8
+ /** Compresses data to a zlib stream */
9
+ export function deflate(data, options) {
10
+ const { level, strategy, windowBits, memLevel, chunkSize } = options;
11
+ // pako's defaults are replaced by any key that's set, even to undefined
12
+ return pakoDeflate(data, Object.fromEntries(Object.entries({
13
+ level,
14
+ strategy: strategy,
15
+ windowBits,
16
+ memLevel,
17
+ chunkSize,
18
+ }).filter(([, value]) => value !== undefined)));
19
+ }
20
+ //# sourceMappingURL=zlib-browser.mjs.map
@@ -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,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeFrames = decodeFrames;
4
+ const buffer_js_1 = require("./buffer.js");
5
+ const pixels_js_1 = require("./pixels.js");
6
+ const read_js_1 = require("./read.js");
7
+ const DISPOSE_BACKGROUND = 1;
8
+ const DISPOSE_PREVIOUS = 2;
9
+ const BLEND_OVER = 1;
10
+ /** Copies a rectangle of RGBA pixels between images of different widths */
11
+ function copyRect(from, fromWidth, to, toWidth, x, y, width, height, toCanvas) {
12
+ for (let row = 0; row < height; row++) {
13
+ const canvasStart = ((y + row) * (toCanvas ? toWidth : fromWidth) + x) * 4;
14
+ const rectStart = row * width * 4;
15
+ if (toCanvas) {
16
+ to.set(from.subarray(rectStart, rectStart + width * 4), canvasStart);
17
+ }
18
+ else {
19
+ to.set(from.subarray(canvasStart, canvasStart + width * 4), rectStart);
20
+ }
21
+ }
22
+ }
23
+ /** Draws a frame over the canvas with "over" alpha compositing */
24
+ function blendOver(frame, canvas, canvasWidth, control, max) {
25
+ for (let row = 0; row < control.height; row++) {
26
+ let i = row * control.width * 4;
27
+ let o = ((control.y + row) * canvasWidth + control.x) * 4;
28
+ for (let x = 0; x < control.width; x++, i += 4, o += 4) {
29
+ const sa = frame[i + 3];
30
+ if (sa === max) {
31
+ canvas[o] = frame[i];
32
+ canvas[o + 1] = frame[i + 1];
33
+ canvas[o + 2] = frame[i + 2];
34
+ canvas[o + 3] = max;
35
+ }
36
+ else if (sa > 0) {
37
+ const da = (canvas[o + 3] * (max - sa)) / max;
38
+ const a = sa + da;
39
+ canvas[o] = Math.round((frame[i] * sa + canvas[o] * da) / a);
40
+ canvas[o + 1] = Math.round((frame[i + 1] * sa + canvas[o + 1] * da) / a);
41
+ canvas[o + 2] = Math.round((frame[i + 2] * sa + canvas[o + 2] * da) / a);
42
+ canvas[o + 3] = Math.round(a);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ function decodeFrames(data, { checkCRC = true, outputDepth = 8, maxFrames = Infinity, } = {}) {
48
+ const file = (0, read_js_1.readPng)((0, buffer_js_1.toUint8Array)(data), { checkCRC, frames: true });
49
+ const mode = outputDepth === 16 ? 16 : 8;
50
+ const info = {
51
+ ...file.header,
52
+ palette: file.palette,
53
+ transparentColor: file.transparentColor,
54
+ };
55
+ const wrap = (pixels) => pixels instanceof Uint8Array ? (0, buffer_js_1.toBuffer)(pixels) : pixels;
56
+ if (!file.animation || file.frames.length === 0) {
57
+ return {
58
+ ...file.header,
59
+ frames: [{ data: wrap((0, pixels_js_1.decodePixels)(info, file.idat, mode)), delay: 0 }],
60
+ };
61
+ }
62
+ const { width, height } = file.header;
63
+ const max = mode === 16 ? 65535 : 255;
64
+ const canvas = mode === 16
65
+ ? new Uint16Array(width * height * 4)
66
+ : new Uint8Array(width * height * 4);
67
+ const frames = [];
68
+ for (const [index, frame] of file.frames.entries()) {
69
+ if (frames.length >= maxFrames) {
70
+ break;
71
+ }
72
+ const { control } = frame;
73
+ let pixels;
74
+ try {
75
+ pixels = (0, pixels_js_1.decodePixels)({ ...info, width: control.width, height: control.height }, frame.data, mode);
76
+ }
77
+ catch (error) {
78
+ if (index === 0) {
79
+ throw error;
80
+ }
81
+ break;
82
+ }
83
+ // The first frame can't restore the canvas from before it
84
+ const dispose = index === 0 && control.dispose === DISPOSE_PREVIOUS
85
+ ? DISPOSE_BACKGROUND
86
+ : control.dispose;
87
+ let saved;
88
+ if (dispose === DISPOSE_PREVIOUS) {
89
+ saved = canvas.slice(0, control.width * control.height * 4);
90
+ copyRect(canvas, width, saved, control.width, control.x, control.y, control.width, control.height, false);
91
+ }
92
+ if (control.blend === BLEND_OVER) {
93
+ blendOver(pixels, canvas, width, control, max);
94
+ }
95
+ else {
96
+ copyRect(pixels, control.width, canvas, width, control.x, control.y, control.width, control.height, true);
97
+ }
98
+ frames.push({ data: wrap(canvas.slice()), delay: control.delay });
99
+ if (dispose === DISPOSE_BACKGROUND) {
100
+ copyRect(new Uint8Array(control.width * control.height * 4), control.width, canvas, width, control.x, control.y, control.width, control.height, true);
101
+ }
102
+ else if (saved) {
103
+ copyRect(saved, control.width, canvas, width, control.x, control.y, control.width, control.height, true);
104
+ }
105
+ }
106
+ return {
107
+ ...file.header,
108
+ frames,
109
+ plays: file.animation.loops,
110
+ };
111
+ }
112
+ //# sourceMappingURL=apng.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apng.js","sourceRoot":"","sources":["../../src/apng.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AAErD,2CAA2C;AAC3C,uCAAoC;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,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M,EACN,KAAK,EACL,OAAO,CAAC,CAAC,EACT,OAAO,CAAC,CAAC,EACT,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,MAAM,EACd,IAAI,CACL,CAAC;QACJ,CAAC;QAED,MAAM,CAAC,IAAI,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,7 @@
1
+ import { Buffer } from "node:buffer";
2
+ /** A Buffer in Node.js, a Uint8Array in browsers */
3
+ export type BufferLike = Buffer;
4
+ /** Wraps bytes in a Buffer without copying them */
5
+ export declare function toBuffer(data: Uint8Array): BufferLike;
6
+ export declare function toUint8Array(data: Uint8Array | ArrayBuffer): Uint8Array;
7
+ //# sourceMappingURL=buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../src/buffer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,oDAAoD;AACpD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,mDAAmD;AACnD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAIrD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,UAAU,CAEvE"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBuffer = toBuffer;
4
+ exports.toUint8Array = toUint8Array;
5
+ // Node.js: hand out Buffers, like pngjs did. Browsers use buffer-browser.mts.
6
+ const node_buffer_1 = require("node:buffer");
7
+ /** Wraps bytes in a Buffer without copying them */
8
+ function toBuffer(data) {
9
+ return node_buffer_1.Buffer.isBuffer(data)
10
+ ? data
11
+ : node_buffer_1.Buffer.from(data.buffer, data.byteOffset, data.byteLength);
12
+ }
13
+ function toUint8Array(data) {
14
+ return data instanceof Uint8Array ? data : new Uint8Array(data);
15
+ }
16
+ //# sourceMappingURL=buffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../src/buffer.ts"],"names":[],"mappings":";;;;AAAA,8EAA8E;AAC9E,6CAAqC;AAKrC,mDAAmD;AACnD,kBAAyB,IAAgB;IACvC,OAAO,oBAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC1B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,oBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACjE,CAAC;AAED,sBAA6B,IAA8B;IACzD,OAAO,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC","sourcesContent":["// Node.js: hand out Buffers, like pngjs did. Browsers use buffer-browser.mts.\nimport { Buffer } from \"node:buffer\";\n\n/** A Buffer in Node.js, a Uint8Array in browsers */\nexport type BufferLike = Buffer;\n\n/** Wraps bytes in a Buffer without copying them */\nexport function toBuffer(data: Uint8Array): BufferLike {\n return Buffer.isBuffer(data)\n ? data\n : Buffer.from(data.buffer, data.byteOffset, data.byteLength);\n}\n\nexport function toUint8Array(data: Uint8Array | ArrayBuffer): Uint8Array {\n return data instanceof Uint8Array ? data : new Uint8Array(data);\n}\n"]}
@@ -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"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_CHUNK_LENGTH = exports.GAMMA_DIVISION = exports.CHANNELS = exports.ALLOWED_BIT_DEPTHS = exports.FilterType = exports.ColorType = exports.PNG_SIGNATURE = void 0;
4
+ exports.isColorType = isColorType;
5
+ exports.PNG_SIGNATURE = new Uint8Array([
6
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
7
+ ]);
8
+ /**
9
+ * How a PNG stores its pixels. The value is a sum of 1 (palette), 2 (colour)
10
+ * and 4 (alpha channel).
11
+ */
12
+ var ColorType;
13
+ (function (ColorType) {
14
+ ColorType[ColorType["GRAYSCALE"] = 0] = "GRAYSCALE";
15
+ ColorType[ColorType["COLOR"] = 2] = "COLOR";
16
+ ColorType[ColorType["PALETTE"] = 3] = "PALETTE";
17
+ ColorType[ColorType["GRAYSCALE_ALPHA"] = 4] = "GRAYSCALE_ALPHA";
18
+ ColorType[ColorType["COLOR_ALPHA"] = 6] = "COLOR_ALPHA";
19
+ })(ColorType || (exports.ColorType = ColorType = {}));
20
+ /** How each scanline is transformed before compression */
21
+ var FilterType;
22
+ (function (FilterType) {
23
+ /** Try every filter on each line and keep the one that looks smallest */
24
+ FilterType[FilterType["AUTO"] = -1] = "AUTO";
25
+ /** The line is stored as is */
26
+ FilterType[FilterType["NONE"] = 0] = "NONE";
27
+ /** Each byte minus the one a pixel to its left */
28
+ FilterType[FilterType["SUB"] = 1] = "SUB";
29
+ /** Each byte minus the one above it */
30
+ FilterType[FilterType["UP"] = 2] = "UP";
31
+ /** Each byte minus the average of the ones to its left and above */
32
+ FilterType[FilterType["AVERAGE"] = 3] = "AVERAGE";
33
+ /** Each byte minus whichever of left, above or above-left predicts it best */
34
+ FilterType[FilterType["PAETH"] = 4] = "PAETH";
35
+ })(FilterType || (exports.FilterType = FilterType = {}));
36
+ /** The bit depths each colour type allows */
37
+ exports.ALLOWED_BIT_DEPTHS = {
38
+ [ColorType.GRAYSCALE]: [1, 2, 4, 8, 16],
39
+ [ColorType.COLOR]: [8, 16],
40
+ [ColorType.PALETTE]: [1, 2, 4, 8],
41
+ [ColorType.GRAYSCALE_ALPHA]: [8, 16],
42
+ [ColorType.COLOR_ALPHA]: [8, 16],
43
+ };
44
+ /** Samples (channels) per pixel of each colour type */
45
+ exports.CHANNELS = {
46
+ [ColorType.GRAYSCALE]: 1,
47
+ [ColorType.COLOR]: 3,
48
+ [ColorType.PALETTE]: 1,
49
+ [ColorType.GRAYSCALE_ALPHA]: 2,
50
+ [ColorType.COLOR_ALPHA]: 4,
51
+ };
52
+ /** gAMA stores the gamma times 100000 */
53
+ exports.GAMMA_DIVISION = 100000;
54
+ /** The largest length a chunk may have, 2^31 - 1 */
55
+ exports.MAX_CHUNK_LENGTH = 0x7fffffff;
56
+ function isColorType(value) {
57
+ return value in exports.CHANNELS;
58
+ }
59
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;;AAAa,QAAA,aAAa,GAAG,IAAI,UAAU,CAAC;IAC1C,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CAC/C,CAAC,CAAC;AAEH;;;GAGG;AACH,IAAY,SAMX;AAND,WAAY,SAAS;IACnB,mDAAa,CAAA;IACb,2CAAS,CAAA;IACT,+CAAW,CAAA;IACX,+DAAmB,CAAA;IACnB,uDAAe,CAAA;AACjB,CAAC,EANW,SAAS,aAAT,SAAS,GAAT,SAAS,QAMpB;AAKD,0DAA0D;AAC1D,IAAY,UAaX;AAbD,WAAY,UAAU;IACpB,yEAAyE;IACzE,4CAAS,CAAA;IACT,+BAA+B;IAC/B,2CAAQ,CAAA;IACR,kDAAkD;IAClD,yCAAO,CAAA;IACP,uCAAuC;IACvC,uCAAM,CAAA;IACN,oEAAoE;IACpE,iDAAW,CAAA;IACX,8EAA8E;IAC9E,6CAAS,CAAA;AACX,CAAC,EAbW,UAAU,aAAV,UAAU,GAAV,UAAU,QAarB;AAED,6CAA6C;AAChC,QAAA,kBAAkB,GAA2C;IACxE,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACvC,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IAC1B,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACpC,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;CACjC,CAAC;AAEF,uDAAuD;AAC1C,QAAA,QAAQ,GAA8B;IACjD,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;IACxB,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;IACpB,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;IACtB,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC;IAC9B,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;CAC3B,CAAC;AAEF,yCAAyC;AAC5B,QAAA,cAAc,GAAG,MAAM,CAAC;AAErC,oDAAoD;AACvC,QAAA,gBAAgB,GAAG,UAAU,CAAC;AAE3C,qBAA4B,KAAa;IACvC,OAAO,KAAK,IAAI,QAAA,QAAQ,CAAC;AAC3B,CAAC","sourcesContent":["export const PNG_SIGNATURE = new Uint8Array([\n 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,\n]);\n\n/**\n * How a PNG stores its pixels. The value is a sum of 1 (palette), 2 (colour)\n * and 4 (alpha channel).\n */\nexport enum ColorType {\n GRAYSCALE = 0,\n COLOR = 2,\n PALETTE = 3,\n GRAYSCALE_ALPHA = 4,\n COLOR_ALPHA = 6,\n}\n\n/** Bits per sample, or per palette index for palette images */\nexport type BitDepth = 1 | 2 | 4 | 8 | 16;\n\n/** How each scanline is transformed before compression */\nexport enum FilterType {\n /** Try every filter on each line and keep the one that looks smallest */\n AUTO = -1,\n /** The line is stored as is */\n NONE = 0,\n /** Each byte minus the one a pixel to its left */\n SUB = 1,\n /** Each byte minus the one above it */\n UP = 2,\n /** Each byte minus the average of the ones to its left and above */\n AVERAGE = 3,\n /** Each byte minus whichever of left, above or above-left predicts it best */\n PAETH = 4,\n}\n\n/** The bit depths each colour type allows */\nexport const ALLOWED_BIT_DEPTHS: Record<ColorType, readonly BitDepth[]> = {\n [ColorType.GRAYSCALE]: [1, 2, 4, 8, 16],\n [ColorType.COLOR]: [8, 16],\n [ColorType.PALETTE]: [1, 2, 4, 8],\n [ColorType.GRAYSCALE_ALPHA]: [8, 16],\n [ColorType.COLOR_ALPHA]: [8, 16],\n};\n\n/** Samples (channels) per pixel of each colour type */\nexport const CHANNELS: Record<ColorType, number> = {\n [ColorType.GRAYSCALE]: 1,\n [ColorType.COLOR]: 3,\n [ColorType.PALETTE]: 1,\n [ColorType.GRAYSCALE_ALPHA]: 2,\n [ColorType.COLOR_ALPHA]: 4,\n};\n\n/** gAMA stores the gamma times 100000 */\nexport const GAMMA_DIVISION = 100000;\n\n/** The largest length a chunk may have, 2^31 - 1 */\nexport const MAX_CHUNK_LENGTH = 0x7fffffff;\n\nexport function isColorType(value: number): value is ColorType {\n return value in CHANNELS;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ /** CRC-32 as PNG uses it, continuing from `crc` if given */
2
+ export declare function crc32Js(data: Uint8Array, crc?: number): number;
3
+ //# sourceMappingURL=crc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crc.d.ts","sourceRoot":"","sources":["../../src/crc.ts"],"names":[],"mappings":"AAoBA,4DAA4D;AAC5D,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,SAAI,UAShD"}