sniff-qa 0.8.1 → 0.9.1

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 (176) hide show
  1. package/.claude-plugin/icon.png +0 -0
  2. package/.claude-plugin/plugin.json +9 -2
  3. package/CHANGELOG.md +73 -0
  4. package/NOTICE +7 -4
  5. package/README.md +169 -102
  6. package/THIRD-PARTY-NOTICES.md +1800 -0
  7. package/dist/{accessibility-JXRMWF5Y.js → accessibility-42JOUOGH.js} +8 -2
  8. package/dist/{anthropic-api-ZR3UEB3Z.js → anthropic-api-VSG2X6FS.js} +7 -5
  9. package/dist/assert-budget-WG4BRCLX.js +10 -0
  10. package/dist/{caps-G3ZGJI7B.js → caps-YZPFNPIN.js} +3 -2
  11. package/dist/{chunk-VEI2O6AK.js → chunk-33JL2AB5.js} +14 -6
  12. package/dist/{chunk-7ZOFYET5.js → chunk-3E4W4H6S.js} +36 -16
  13. package/dist/{chunk-EGANHIIE.js → chunk-3NR2K5B3.js} +49 -5
  14. package/dist/chunk-3ROWRVZE.js +422 -0
  15. package/dist/{chunk-MYWWSM3V.js → chunk-3YFE3H23.js} +2 -1
  16. package/dist/{chunk-MMISGY2Q.js → chunk-4F6ZXOPE.js} +2 -1
  17. package/dist/chunk-A4TTASVS.js +27862 -0
  18. package/dist/{chunk-IXDUD2UG.js → chunk-AA744N7E.js} +2 -1
  19. package/dist/chunk-DZMX3VT2.js +267 -0
  20. package/dist/{chunk-NG2IGCAK.js → chunk-FR5QCJLH.js} +2 -1
  21. package/dist/{chunk-GV27IOMC.js → chunk-GC47B6MM.js} +2 -1
  22. package/dist/chunk-HP4TY3UY.js +80 -0
  23. package/dist/chunk-LZAPYYNR.js +4595 -0
  24. package/dist/{chunk-ZM6MGWO4.js → chunk-NBJLMLDA.js} +2 -1
  25. package/dist/chunk-RAGYZ54R.js +15480 -0
  26. package/dist/{chunk-GX36BPK7.js → chunk-RSGFFRXQ.js} +2 -2
  27. package/dist/chunk-SOBWDC35.js +38 -0
  28. package/dist/{chunk-CZKMOAXU.js → chunk-US4HFUCH.js} +3 -2
  29. package/dist/chunk-YM22FEIA.js +5807 -0
  30. package/dist/{ci-ISCWZJD3.js → ci-F6FUXT3O.js} +5 -3
  31. package/dist/{classifier-MWQMQ727.js → classifier-5FQ2FBTO.js} +3 -1
  32. package/dist/{claude-code-ZFTBQXY4.js → claude-code-J43C22IR.js} +7 -5
  33. package/dist/{claude-exploration-provider-QJH6IPYU.js → claude-exploration-provider-EWQNNE7D.js} +4 -3
  34. package/dist/cli/index.js +87 -35
  35. package/dist/compiler-sfc.cjs-JX56AWNS.js +48568 -0
  36. package/dist/crawl-KN7SW753.js +26 -0
  37. package/dist/{crawl-command-RDWGHZC4.js → crawl-command-Y45FIXNK.js} +14 -9
  38. package/dist/{cross-reference-MHNPSLEN.js → cross-reference-XOOBW6UZ.js} +3 -1
  39. package/dist/{dev-server-detector-XQ5AYPDT.js → dev-server-detector-FMFVKDJR.js} +3 -1
  40. package/dist/{discover-QKGMYPHK.js → discover-HA63UA4K.js} +20 -18
  41. package/dist/dist-3CYER35S.js +8 -0
  42. package/dist/{domain-UQ34YE4B.js → domain-FU3WIW64.js} +45 -30
  43. package/dist/{edge-cases-ZADKDZHL.js → edge-cases-B6IV3IKK.js} +3 -1
  44. package/dist/{element-extractor-OZTFBVKZ.js → element-extractor-QAG4MRUO.js} +18 -6
  45. package/dist/engine-AXB5O4ZH.js +39 -0
  46. package/dist/ensure-browsers-TNMHMLRS.js +147 -0
  47. package/dist/errors-NWB25P4K.js +8 -0
  48. package/dist/esm-IMWPYLSN.js +3469 -0
  49. package/dist/{fix-R33D34NP.js → fix-IXOEHAOS.js} +12 -5
  50. package/dist/{flakiness-OLJAY7CS.js → flakiness-7SSSM4SW.js} +3 -2
  51. package/dist/flakiness-CBKV4U54.js +12 -0
  52. package/dist/formatter-N4CC7SCM.js +176 -0
  53. package/dist/{framework-detector-ISSM2Q2I.js → framework-detector-4ZVHNT7N.js} +3 -1
  54. package/dist/generator-GGJYWYI2.js +8 -0
  55. package/dist/index.d.ts +15 -5
  56. package/dist/index.js +9 -6
  57. package/dist/{init-IQKT4ANC.js → init-POX5ZJ6V.js} +4 -2
  58. package/dist/json-4VOVHDQG.js +10 -0
  59. package/dist/{junit-GL44ATRR.js → junit-V24COOSR.js} +3 -1
  60. package/dist/{llm-VJAI6H6G.js → llm-TZ2WZGRZ.js} +3 -1
  61. package/dist/{loader-Z2DUGG5Z.js → loader-AMM63AOJ.js} +12 -3
  62. package/dist/mcp/server.js +13049 -73
  63. package/dist/{model-SP6HJN6J.js → model-BL2AID5Q.js} +6 -5
  64. package/dist/page-hooks-SECSGZR6.js +14 -0
  65. package/dist/{page-state-extractor-GYYLYRFR.js → page-state-extractor-AP4FQVLY.js} +3 -1
  66. package/dist/{performance-7HWKY5O2.js → performance-JVEYVBTV.js} +9 -3
  67. package/dist/{persistence-XLFJ5EY4.js → persistence-SHKJVSIS.js} +5 -4
  68. package/dist/{persistence-KTCRIGHU.js → persistence-SQ6QT3HP.js} +3 -1
  69. package/dist/picocolors-3W2AX5TJ.js +6 -0
  70. package/dist/pixelmatch-GATIVDQX.js +188 -0
  71. package/dist/png-HTC2G4ZG.js +2093 -0
  72. package/dist/{prompt-builder-D3FBH534.js → prompt-builder-EI2BFKLZ.js} +4 -2
  73. package/dist/{provider-BCKFVPTN.js → provider-O3UOALQH.js} +14 -12
  74. package/dist/{quality-run-YAURB242.js → quality-run-CTLX5YA5.js} +12 -10
  75. package/dist/{redaction-CHAIVPCF.js → redaction-QNBV5QZ3.js} +4 -3
  76. package/dist/{registry-5XCXUAYJ.js → registry-JBBTSD7I.js} +3 -1
  77. package/dist/{repo-analyzer-4OURSITY.js → repo-analyzer-4XITIIAF.js} +6 -4
  78. package/dist/{report-SDZWX25B.js → report-4UVJL7QV.js} +3 -1
  79. package/dist/{report-7FQFH4HW.js → report-BOVSPRCR.js} +8 -6
  80. package/dist/{response-parser-PUGNWF7S.js → response-parser-GHVJSYXQ.js} +3 -2
  81. package/dist/{route-discoverer-QBZCRQLJ.js → route-discoverer-ZXYJQIYE.js} +15 -8
  82. package/dist/{runner-RDVVIGBU.js → runner-DOLCFA3S.js} +10 -5
  83. package/dist/{runner-QHSYX7J2.js → runner-MCSDHFLN.js} +12 -7
  84. package/dist/{runner-AXZXNWYH.js → runner-MUBXHOIG.js} +10 -4
  85. package/dist/{scenarios-I7YYVTD2.js → scenarios-T2U6ZDRL.js} +3 -1
  86. package/dist/sdk-FQKA5HSQ.js +7184 -0
  87. package/dist/{source-5LS2B7TN.js → source-T5MHBY5G.js} +14 -7
  88. package/dist/{tiebreak-L5UFNKU2.js → tiebreak-SXBXPT7B.js} +3 -1
  89. package/dist/{unified-YSOTPG5B.js → unified-NUR2X5JV.js} +23 -21
  90. package/dist/{update-baselines-JYKUUIZG.js → update-baselines-TMERPIDV.js} +4 -2
  91. package/dist/version-FEHABGAH.js +10 -0
  92. package/dist/{visual-EUZG2STF.js → visual-XHFPFQFX.js} +5 -3
  93. package/dist/{workflow-template-6DADGPHA.js → workflow-template-7C5CCK67.js} +13 -7
  94. package/dist/{write-report-6RJWN54I.js → write-report-6Q4MXBYD.js} +5 -4
  95. package/package.json +21 -14
  96. package/dist/accessibility-JXRMWF5Y.js.map +0 -1
  97. package/dist/anthropic-api-ZR3UEB3Z.js.map +0 -1
  98. package/dist/assert-budget-NBF3JYM7.js +0 -9
  99. package/dist/assert-budget-NBF3JYM7.js.map +0 -1
  100. package/dist/caps-G3ZGJI7B.js.map +0 -1
  101. package/dist/chunk-7ZOFYET5.js.map +0 -1
  102. package/dist/chunk-CZKMOAXU.js.map +0 -1
  103. package/dist/chunk-EGANHIIE.js.map +0 -1
  104. package/dist/chunk-GV27IOMC.js.map +0 -1
  105. package/dist/chunk-GX36BPK7.js.map +0 -1
  106. package/dist/chunk-IXDUD2UG.js.map +0 -1
  107. package/dist/chunk-MMISGY2Q.js.map +0 -1
  108. package/dist/chunk-MYWWSM3V.js.map +0 -1
  109. package/dist/chunk-NG2IGCAK.js.map +0 -1
  110. package/dist/chunk-VEI2O6AK.js.map +0 -1
  111. package/dist/chunk-ZM6MGWO4.js.map +0 -1
  112. package/dist/ci-ISCWZJD3.js.map +0 -1
  113. package/dist/classifier-MWQMQ727.js.map +0 -1
  114. package/dist/claude-code-ZFTBQXY4.js.map +0 -1
  115. package/dist/claude-exploration-provider-QJH6IPYU.js.map +0 -1
  116. package/dist/cli/index.js.map +0 -1
  117. package/dist/crawl-ZXZRF4Q7.js +0 -15
  118. package/dist/crawl-ZXZRF4Q7.js.map +0 -1
  119. package/dist/crawl-command-RDWGHZC4.js.map +0 -1
  120. package/dist/cross-reference-MHNPSLEN.js.map +0 -1
  121. package/dist/dev-server-detector-XQ5AYPDT.js.map +0 -1
  122. package/dist/discover-QKGMYPHK.js.map +0 -1
  123. package/dist/domain-UQ34YE4B.js.map +0 -1
  124. package/dist/edge-cases-ZADKDZHL.js.map +0 -1
  125. package/dist/element-extractor-OZTFBVKZ.js.map +0 -1
  126. package/dist/ensure-browsers-AYKMLUHV.js +0 -86
  127. package/dist/ensure-browsers-AYKMLUHV.js.map +0 -1
  128. package/dist/errors-RFEOR527.js +0 -7
  129. package/dist/errors-RFEOR527.js.map +0 -1
  130. package/dist/fix-R33D34NP.js.map +0 -1
  131. package/dist/flakiness-OLJAY7CS.js.map +0 -1
  132. package/dist/flakiness-OVC7KGN2.js +0 -11
  133. package/dist/flakiness-OVC7KGN2.js.map +0 -1
  134. package/dist/formatter-HC3LT3VH.js +0 -146
  135. package/dist/formatter-HC3LT3VH.js.map +0 -1
  136. package/dist/framework-detector-ISSM2Q2I.js.map +0 -1
  137. package/dist/generator-HIFV67NI.js +0 -7
  138. package/dist/generator-HIFV67NI.js.map +0 -1
  139. package/dist/index.js.map +0 -1
  140. package/dist/init-IQKT4ANC.js.map +0 -1
  141. package/dist/json-YDWEB33Q.js +0 -8
  142. package/dist/json-YDWEB33Q.js.map +0 -1
  143. package/dist/junit-GL44ATRR.js.map +0 -1
  144. package/dist/llm-VJAI6H6G.js.map +0 -1
  145. package/dist/loader-Z2DUGG5Z.js.map +0 -1
  146. package/dist/mcp/server.js.map +0 -1
  147. package/dist/model-SP6HJN6J.js.map +0 -1
  148. package/dist/page-hooks-6RALVZB5.js +0 -13
  149. package/dist/page-hooks-6RALVZB5.js.map +0 -1
  150. package/dist/page-state-extractor-GYYLYRFR.js.map +0 -1
  151. package/dist/performance-7HWKY5O2.js.map +0 -1
  152. package/dist/persistence-KTCRIGHU.js.map +0 -1
  153. package/dist/persistence-XLFJ5EY4.js.map +0 -1
  154. package/dist/prompt-builder-D3FBH534.js.map +0 -1
  155. package/dist/provider-BCKFVPTN.js.map +0 -1
  156. package/dist/quality-run-YAURB242.js.map +0 -1
  157. package/dist/redaction-CHAIVPCF.js.map +0 -1
  158. package/dist/registry-5XCXUAYJ.js.map +0 -1
  159. package/dist/repo-analyzer-4OURSITY.js.map +0 -1
  160. package/dist/report-7FQFH4HW.js.map +0 -1
  161. package/dist/report-SDZWX25B.js.map +0 -1
  162. package/dist/response-parser-PUGNWF7S.js.map +0 -1
  163. package/dist/route-discoverer-QBZCRQLJ.js.map +0 -1
  164. package/dist/runner-AXZXNWYH.js.map +0 -1
  165. package/dist/runner-QHSYX7J2.js.map +0 -1
  166. package/dist/runner-RDVVIGBU.js.map +0 -1
  167. package/dist/scenarios-I7YYVTD2.js.map +0 -1
  168. package/dist/source-5LS2B7TN.js.map +0 -1
  169. package/dist/tiebreak-L5UFNKU2.js.map +0 -1
  170. package/dist/unified-YSOTPG5B.js.map +0 -1
  171. package/dist/update-baselines-JYKUUIZG.js.map +0 -1
  172. package/dist/version-FLE7ZHDX.js +0 -7
  173. package/dist/version-FLE7ZHDX.js.map +0 -1
  174. package/dist/visual-EUZG2STF.js.map +0 -1
  175. package/dist/workflow-template-6DADGPHA.js.map +0 -1
  176. package/dist/write-report-6RJWN54I.js.map +0 -1
@@ -0,0 +1,2093 @@
1
+ import { createRequire as __sniffCreateRequire } from 'node:module'; const require = __sniffCreateRequire(import.meta.url);
2
+ import {
3
+ __commonJS,
4
+ __require
5
+ } from "./chunk-SOBWDC35.js";
6
+
7
+ // node_modules/pngjs/lib/chunkstream.js
8
+ var require_chunkstream = __commonJS({
9
+ "node_modules/pngjs/lib/chunkstream.js"(exports, module) {
10
+ "use strict";
11
+ var util = __require("util");
12
+ var Stream = __require("stream");
13
+ var ChunkStream = module.exports = function() {
14
+ Stream.call(this);
15
+ this._buffers = [];
16
+ this._buffered = 0;
17
+ this._reads = [];
18
+ this._paused = false;
19
+ this._encoding = "utf8";
20
+ this.writable = true;
21
+ };
22
+ util.inherits(ChunkStream, Stream);
23
+ ChunkStream.prototype.read = function(length, callback) {
24
+ this._reads.push({
25
+ length: Math.abs(length),
26
+ // if length < 0 then at most this length
27
+ allowLess: length < 0,
28
+ func: callback
29
+ });
30
+ process.nextTick(
31
+ function() {
32
+ this._process();
33
+ if (this._paused && this._reads && this._reads.length > 0) {
34
+ this._paused = false;
35
+ this.emit("drain");
36
+ }
37
+ }.bind(this)
38
+ );
39
+ };
40
+ ChunkStream.prototype.write = function(data, encoding) {
41
+ if (!this.writable) {
42
+ this.emit("error", new Error("Stream not writable"));
43
+ return false;
44
+ }
45
+ let dataBuffer;
46
+ if (Buffer.isBuffer(data)) {
47
+ dataBuffer = data;
48
+ } else {
49
+ dataBuffer = Buffer.from(data, encoding || this._encoding);
50
+ }
51
+ this._buffers.push(dataBuffer);
52
+ this._buffered += dataBuffer.length;
53
+ this._process();
54
+ if (this._reads && this._reads.length === 0) {
55
+ this._paused = true;
56
+ }
57
+ return this.writable && !this._paused;
58
+ };
59
+ ChunkStream.prototype.end = function(data, encoding) {
60
+ if (data) {
61
+ this.write(data, encoding);
62
+ }
63
+ this.writable = false;
64
+ if (!this._buffers) {
65
+ return;
66
+ }
67
+ if (this._buffers.length === 0) {
68
+ this._end();
69
+ } else {
70
+ this._buffers.push(null);
71
+ this._process();
72
+ }
73
+ };
74
+ ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
75
+ ChunkStream.prototype._end = function() {
76
+ if (this._reads.length > 0) {
77
+ this.emit("error", new Error("Unexpected end of input"));
78
+ }
79
+ this.destroy();
80
+ };
81
+ ChunkStream.prototype.destroy = function() {
82
+ if (!this._buffers) {
83
+ return;
84
+ }
85
+ this.writable = false;
86
+ this._reads = null;
87
+ this._buffers = null;
88
+ this.emit("close");
89
+ };
90
+ ChunkStream.prototype._processReadAllowingLess = function(read) {
91
+ this._reads.shift();
92
+ let smallerBuf = this._buffers[0];
93
+ if (smallerBuf.length > read.length) {
94
+ this._buffered -= read.length;
95
+ this._buffers[0] = smallerBuf.slice(read.length);
96
+ read.func.call(this, smallerBuf.slice(0, read.length));
97
+ } else {
98
+ this._buffered -= smallerBuf.length;
99
+ this._buffers.shift();
100
+ read.func.call(this, smallerBuf);
101
+ }
102
+ };
103
+ ChunkStream.prototype._processRead = function(read) {
104
+ this._reads.shift();
105
+ let pos = 0;
106
+ let count = 0;
107
+ let data = Buffer.alloc(read.length);
108
+ while (pos < read.length) {
109
+ let buf = this._buffers[count++];
110
+ let len = Math.min(buf.length, read.length - pos);
111
+ buf.copy(data, pos, 0, len);
112
+ pos += len;
113
+ if (len !== buf.length) {
114
+ this._buffers[--count] = buf.slice(len);
115
+ }
116
+ }
117
+ if (count > 0) {
118
+ this._buffers.splice(0, count);
119
+ }
120
+ this._buffered -= read.length;
121
+ read.func.call(this, data);
122
+ };
123
+ ChunkStream.prototype._process = function() {
124
+ try {
125
+ while (this._buffered > 0 && this._reads && this._reads.length > 0) {
126
+ let read = this._reads[0];
127
+ if (read.allowLess) {
128
+ this._processReadAllowingLess(read);
129
+ } else if (this._buffered >= read.length) {
130
+ this._processRead(read);
131
+ } else {
132
+ break;
133
+ }
134
+ }
135
+ if (this._buffers && !this.writable) {
136
+ this._end();
137
+ }
138
+ } catch (ex) {
139
+ this.emit("error", ex);
140
+ }
141
+ };
142
+ }
143
+ });
144
+
145
+ // node_modules/pngjs/lib/interlace.js
146
+ var require_interlace = __commonJS({
147
+ "node_modules/pngjs/lib/interlace.js"(exports) {
148
+ "use strict";
149
+ var imagePasses = [
150
+ {
151
+ // pass 1 - 1px
152
+ x: [0],
153
+ y: [0]
154
+ },
155
+ {
156
+ // pass 2 - 1px
157
+ x: [4],
158
+ y: [0]
159
+ },
160
+ {
161
+ // pass 3 - 2px
162
+ x: [0, 4],
163
+ y: [4]
164
+ },
165
+ {
166
+ // pass 4 - 4px
167
+ x: [2, 6],
168
+ y: [0, 4]
169
+ },
170
+ {
171
+ // pass 5 - 8px
172
+ x: [0, 2, 4, 6],
173
+ y: [2, 6]
174
+ },
175
+ {
176
+ // pass 6 - 16px
177
+ x: [1, 3, 5, 7],
178
+ y: [0, 2, 4, 6]
179
+ },
180
+ {
181
+ // pass 7 - 32px
182
+ x: [0, 1, 2, 3, 4, 5, 6, 7],
183
+ y: [1, 3, 5, 7]
184
+ }
185
+ ];
186
+ exports.getImagePasses = function(width, height) {
187
+ let images = [];
188
+ let xLeftOver = width % 8;
189
+ let yLeftOver = height % 8;
190
+ let xRepeats = (width - xLeftOver) / 8;
191
+ let yRepeats = (height - yLeftOver) / 8;
192
+ for (let i = 0; i < imagePasses.length; i++) {
193
+ let pass = imagePasses[i];
194
+ let passWidth = xRepeats * pass.x.length;
195
+ let passHeight = yRepeats * pass.y.length;
196
+ for (let j = 0; j < pass.x.length; j++) {
197
+ if (pass.x[j] < xLeftOver) {
198
+ passWidth++;
199
+ } else {
200
+ break;
201
+ }
202
+ }
203
+ for (let j = 0; j < pass.y.length; j++) {
204
+ if (pass.y[j] < yLeftOver) {
205
+ passHeight++;
206
+ } else {
207
+ break;
208
+ }
209
+ }
210
+ if (passWidth > 0 && passHeight > 0) {
211
+ images.push({ width: passWidth, height: passHeight, index: i });
212
+ }
213
+ }
214
+ return images;
215
+ };
216
+ exports.getInterlaceIterator = function(width) {
217
+ return function(x, y, pass) {
218
+ let outerXLeftOver = x % imagePasses[pass].x.length;
219
+ let outerX = (x - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
220
+ let outerYLeftOver = y % imagePasses[pass].y.length;
221
+ let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
222
+ return outerX * 4 + outerY * width * 4;
223
+ };
224
+ };
225
+ }
226
+ });
227
+
228
+ // node_modules/pngjs/lib/paeth-predictor.js
229
+ var require_paeth_predictor = __commonJS({
230
+ "node_modules/pngjs/lib/paeth-predictor.js"(exports, module) {
231
+ "use strict";
232
+ module.exports = function paethPredictor(left, above, upLeft) {
233
+ let paeth = left + above - upLeft;
234
+ let pLeft = Math.abs(paeth - left);
235
+ let pAbove = Math.abs(paeth - above);
236
+ let pUpLeft = Math.abs(paeth - upLeft);
237
+ if (pLeft <= pAbove && pLeft <= pUpLeft) {
238
+ return left;
239
+ }
240
+ if (pAbove <= pUpLeft) {
241
+ return above;
242
+ }
243
+ return upLeft;
244
+ };
245
+ }
246
+ });
247
+
248
+ // node_modules/pngjs/lib/filter-parse.js
249
+ var require_filter_parse = __commonJS({
250
+ "node_modules/pngjs/lib/filter-parse.js"(exports, module) {
251
+ "use strict";
252
+ var interlaceUtils = require_interlace();
253
+ var paethPredictor = require_paeth_predictor();
254
+ function getByteWidth(width, bpp, depth) {
255
+ let byteWidth = width * bpp;
256
+ if (depth !== 8) {
257
+ byteWidth = Math.ceil(byteWidth / (8 / depth));
258
+ }
259
+ return byteWidth;
260
+ }
261
+ var Filter = module.exports = function(bitmapInfo, dependencies) {
262
+ let width = bitmapInfo.width;
263
+ let height = bitmapInfo.height;
264
+ let interlace = bitmapInfo.interlace;
265
+ let bpp = bitmapInfo.bpp;
266
+ let depth = bitmapInfo.depth;
267
+ this.read = dependencies.read;
268
+ this.write = dependencies.write;
269
+ this.complete = dependencies.complete;
270
+ this._imageIndex = 0;
271
+ this._images = [];
272
+ if (interlace) {
273
+ let passes = interlaceUtils.getImagePasses(width, height);
274
+ for (let i = 0; i < passes.length; i++) {
275
+ this._images.push({
276
+ byteWidth: getByteWidth(passes[i].width, bpp, depth),
277
+ height: passes[i].height,
278
+ lineIndex: 0
279
+ });
280
+ }
281
+ } else {
282
+ this._images.push({
283
+ byteWidth: getByteWidth(width, bpp, depth),
284
+ height,
285
+ lineIndex: 0
286
+ });
287
+ }
288
+ if (depth === 8) {
289
+ this._xComparison = bpp;
290
+ } else if (depth === 16) {
291
+ this._xComparison = bpp * 2;
292
+ } else {
293
+ this._xComparison = 1;
294
+ }
295
+ };
296
+ Filter.prototype.start = function() {
297
+ this.read(
298
+ this._images[this._imageIndex].byteWidth + 1,
299
+ this._reverseFilterLine.bind(this)
300
+ );
301
+ };
302
+ Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
303
+ let xComparison = this._xComparison;
304
+ let xBiggerThan = xComparison - 1;
305
+ for (let x = 0; x < byteWidth; x++) {
306
+ let rawByte = rawData[1 + x];
307
+ let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
308
+ unfilteredLine[x] = rawByte + f1Left;
309
+ }
310
+ };
311
+ Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
312
+ let lastLine = this._lastLine;
313
+ for (let x = 0; x < byteWidth; x++) {
314
+ let rawByte = rawData[1 + x];
315
+ let f2Up = lastLine ? lastLine[x] : 0;
316
+ unfilteredLine[x] = rawByte + f2Up;
317
+ }
318
+ };
319
+ Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
320
+ let xComparison = this._xComparison;
321
+ let xBiggerThan = xComparison - 1;
322
+ let lastLine = this._lastLine;
323
+ for (let x = 0; x < byteWidth; x++) {
324
+ let rawByte = rawData[1 + x];
325
+ let f3Up = lastLine ? lastLine[x] : 0;
326
+ let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
327
+ let f3Add = Math.floor((f3Left + f3Up) / 2);
328
+ unfilteredLine[x] = rawByte + f3Add;
329
+ }
330
+ };
331
+ Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
332
+ let xComparison = this._xComparison;
333
+ let xBiggerThan = xComparison - 1;
334
+ let lastLine = this._lastLine;
335
+ for (let x = 0; x < byteWidth; x++) {
336
+ let rawByte = rawData[1 + x];
337
+ let f4Up = lastLine ? lastLine[x] : 0;
338
+ let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
339
+ let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
340
+ let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
341
+ unfilteredLine[x] = rawByte + f4Add;
342
+ }
343
+ };
344
+ Filter.prototype._reverseFilterLine = function(rawData) {
345
+ let filter = rawData[0];
346
+ let unfilteredLine;
347
+ let currentImage = this._images[this._imageIndex];
348
+ let byteWidth = currentImage.byteWidth;
349
+ if (filter === 0) {
350
+ unfilteredLine = rawData.slice(1, byteWidth + 1);
351
+ } else {
352
+ unfilteredLine = Buffer.alloc(byteWidth);
353
+ switch (filter) {
354
+ case 1:
355
+ this._unFilterType1(rawData, unfilteredLine, byteWidth);
356
+ break;
357
+ case 2:
358
+ this._unFilterType2(rawData, unfilteredLine, byteWidth);
359
+ break;
360
+ case 3:
361
+ this._unFilterType3(rawData, unfilteredLine, byteWidth);
362
+ break;
363
+ case 4:
364
+ this._unFilterType4(rawData, unfilteredLine, byteWidth);
365
+ break;
366
+ default:
367
+ throw new Error("Unrecognised filter type - " + filter);
368
+ }
369
+ }
370
+ this.write(unfilteredLine);
371
+ currentImage.lineIndex++;
372
+ if (currentImage.lineIndex >= currentImage.height) {
373
+ this._lastLine = null;
374
+ this._imageIndex++;
375
+ currentImage = this._images[this._imageIndex];
376
+ } else {
377
+ this._lastLine = unfilteredLine;
378
+ }
379
+ if (currentImage) {
380
+ this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
381
+ } else {
382
+ this._lastLine = null;
383
+ this.complete();
384
+ }
385
+ };
386
+ }
387
+ });
388
+
389
+ // node_modules/pngjs/lib/filter-parse-async.js
390
+ var require_filter_parse_async = __commonJS({
391
+ "node_modules/pngjs/lib/filter-parse-async.js"(exports, module) {
392
+ "use strict";
393
+ var util = __require("util");
394
+ var ChunkStream = require_chunkstream();
395
+ var Filter = require_filter_parse();
396
+ var FilterAsync = module.exports = function(bitmapInfo) {
397
+ ChunkStream.call(this);
398
+ let buffers = [];
399
+ let that = this;
400
+ this._filter = new Filter(bitmapInfo, {
401
+ read: this.read.bind(this),
402
+ write: function(buffer) {
403
+ buffers.push(buffer);
404
+ },
405
+ complete: function() {
406
+ that.emit("complete", Buffer.concat(buffers));
407
+ }
408
+ });
409
+ this._filter.start();
410
+ };
411
+ util.inherits(FilterAsync, ChunkStream);
412
+ }
413
+ });
414
+
415
+ // node_modules/pngjs/lib/constants.js
416
+ var require_constants = __commonJS({
417
+ "node_modules/pngjs/lib/constants.js"(exports, module) {
418
+ "use strict";
419
+ module.exports = {
420
+ PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
421
+ TYPE_IHDR: 1229472850,
422
+ TYPE_IEND: 1229278788,
423
+ TYPE_IDAT: 1229209940,
424
+ TYPE_PLTE: 1347179589,
425
+ TYPE_tRNS: 1951551059,
426
+ // eslint-disable-line camelcase
427
+ TYPE_gAMA: 1732332865,
428
+ // eslint-disable-line camelcase
429
+ // color-type bits
430
+ COLORTYPE_GRAYSCALE: 0,
431
+ COLORTYPE_PALETTE: 1,
432
+ COLORTYPE_COLOR: 2,
433
+ COLORTYPE_ALPHA: 4,
434
+ // e.g. grayscale and alpha
435
+ // color-type combinations
436
+ COLORTYPE_PALETTE_COLOR: 3,
437
+ COLORTYPE_COLOR_ALPHA: 6,
438
+ COLORTYPE_TO_BPP_MAP: {
439
+ 0: 1,
440
+ 2: 3,
441
+ 3: 1,
442
+ 4: 2,
443
+ 6: 4
444
+ },
445
+ GAMMA_DIVISION: 1e5
446
+ };
447
+ }
448
+ });
449
+
450
+ // node_modules/pngjs/lib/crc.js
451
+ var require_crc = __commonJS({
452
+ "node_modules/pngjs/lib/crc.js"(exports, module) {
453
+ "use strict";
454
+ var crcTable = [];
455
+ (function() {
456
+ for (let i = 0; i < 256; i++) {
457
+ let currentCrc = i;
458
+ for (let j = 0; j < 8; j++) {
459
+ if (currentCrc & 1) {
460
+ currentCrc = 3988292384 ^ currentCrc >>> 1;
461
+ } else {
462
+ currentCrc = currentCrc >>> 1;
463
+ }
464
+ }
465
+ crcTable[i] = currentCrc;
466
+ }
467
+ })();
468
+ var CrcCalculator = module.exports = function() {
469
+ this._crc = -1;
470
+ };
471
+ CrcCalculator.prototype.write = function(data) {
472
+ for (let i = 0; i < data.length; i++) {
473
+ this._crc = crcTable[(this._crc ^ data[i]) & 255] ^ this._crc >>> 8;
474
+ }
475
+ return true;
476
+ };
477
+ CrcCalculator.prototype.crc32 = function() {
478
+ return this._crc ^ -1;
479
+ };
480
+ CrcCalculator.crc32 = function(buf) {
481
+ let crc = -1;
482
+ for (let i = 0; i < buf.length; i++) {
483
+ crc = crcTable[(crc ^ buf[i]) & 255] ^ crc >>> 8;
484
+ }
485
+ return crc ^ -1;
486
+ };
487
+ }
488
+ });
489
+
490
+ // node_modules/pngjs/lib/parser.js
491
+ var require_parser = __commonJS({
492
+ "node_modules/pngjs/lib/parser.js"(exports, module) {
493
+ "use strict";
494
+ var constants = require_constants();
495
+ var CrcCalculator = require_crc();
496
+ var Parser = module.exports = function(options, dependencies) {
497
+ this._options = options;
498
+ options.checkCRC = options.checkCRC !== false;
499
+ this._hasIHDR = false;
500
+ this._hasIEND = false;
501
+ this._emittedHeadersFinished = false;
502
+ this._palette = [];
503
+ this._colorType = 0;
504
+ this._chunks = {};
505
+ this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
506
+ this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
507
+ this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
508
+ this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
509
+ this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
510
+ this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
511
+ this.read = dependencies.read;
512
+ this.error = dependencies.error;
513
+ this.metadata = dependencies.metadata;
514
+ this.gamma = dependencies.gamma;
515
+ this.transColor = dependencies.transColor;
516
+ this.palette = dependencies.palette;
517
+ this.parsed = dependencies.parsed;
518
+ this.inflateData = dependencies.inflateData;
519
+ this.finished = dependencies.finished;
520
+ this.simpleTransparency = dependencies.simpleTransparency;
521
+ this.headersFinished = dependencies.headersFinished || function() {
522
+ };
523
+ };
524
+ Parser.prototype.start = function() {
525
+ this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
526
+ };
527
+ Parser.prototype._parseSignature = function(data) {
528
+ let signature = constants.PNG_SIGNATURE;
529
+ for (let i = 0; i < signature.length; i++) {
530
+ if (data[i] !== signature[i]) {
531
+ this.error(new Error("Invalid file signature"));
532
+ return;
533
+ }
534
+ }
535
+ this.read(8, this._parseChunkBegin.bind(this));
536
+ };
537
+ Parser.prototype._parseChunkBegin = function(data) {
538
+ let length = data.readUInt32BE(0);
539
+ let type = data.readUInt32BE(4);
540
+ let name = "";
541
+ for (let i = 4; i < 8; i++) {
542
+ name += String.fromCharCode(data[i]);
543
+ }
544
+ let ancillary = Boolean(data[4] & 32);
545
+ if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
546
+ this.error(new Error("Expected IHDR on beggining"));
547
+ return;
548
+ }
549
+ this._crc = new CrcCalculator();
550
+ this._crc.write(Buffer.from(name));
551
+ if (this._chunks[type]) {
552
+ return this._chunks[type](length);
553
+ }
554
+ if (!ancillary) {
555
+ this.error(new Error("Unsupported critical chunk type " + name));
556
+ return;
557
+ }
558
+ this.read(length + 4, this._skipChunk.bind(this));
559
+ };
560
+ Parser.prototype._skipChunk = function() {
561
+ this.read(8, this._parseChunkBegin.bind(this));
562
+ };
563
+ Parser.prototype._handleChunkEnd = function() {
564
+ this.read(4, this._parseChunkEnd.bind(this));
565
+ };
566
+ Parser.prototype._parseChunkEnd = function(data) {
567
+ let fileCrc = data.readInt32BE(0);
568
+ let calcCrc = this._crc.crc32();
569
+ if (this._options.checkCRC && calcCrc !== fileCrc) {
570
+ this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
571
+ return;
572
+ }
573
+ if (!this._hasIEND) {
574
+ this.read(8, this._parseChunkBegin.bind(this));
575
+ }
576
+ };
577
+ Parser.prototype._handleIHDR = function(length) {
578
+ this.read(length, this._parseIHDR.bind(this));
579
+ };
580
+ Parser.prototype._parseIHDR = function(data) {
581
+ this._crc.write(data);
582
+ let width = data.readUInt32BE(0);
583
+ let height = data.readUInt32BE(4);
584
+ let depth = data[8];
585
+ let colorType = data[9];
586
+ let compr = data[10];
587
+ let filter = data[11];
588
+ let interlace = data[12];
589
+ if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
590
+ this.error(new Error("Unsupported bit depth " + depth));
591
+ return;
592
+ }
593
+ if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
594
+ this.error(new Error("Unsupported color type"));
595
+ return;
596
+ }
597
+ if (compr !== 0) {
598
+ this.error(new Error("Unsupported compression method"));
599
+ return;
600
+ }
601
+ if (filter !== 0) {
602
+ this.error(new Error("Unsupported filter method"));
603
+ return;
604
+ }
605
+ if (interlace !== 0 && interlace !== 1) {
606
+ this.error(new Error("Unsupported interlace method"));
607
+ return;
608
+ }
609
+ this._colorType = colorType;
610
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
611
+ this._hasIHDR = true;
612
+ this.metadata({
613
+ width,
614
+ height,
615
+ depth,
616
+ interlace: Boolean(interlace),
617
+ palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
618
+ color: Boolean(colorType & constants.COLORTYPE_COLOR),
619
+ alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
620
+ bpp,
621
+ colorType
622
+ });
623
+ this._handleChunkEnd();
624
+ };
625
+ Parser.prototype._handlePLTE = function(length) {
626
+ this.read(length, this._parsePLTE.bind(this));
627
+ };
628
+ Parser.prototype._parsePLTE = function(data) {
629
+ this._crc.write(data);
630
+ let entries = Math.floor(data.length / 3);
631
+ for (let i = 0; i < entries; i++) {
632
+ this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 255]);
633
+ }
634
+ this.palette(this._palette);
635
+ this._handleChunkEnd();
636
+ };
637
+ Parser.prototype._handleTRNS = function(length) {
638
+ this.simpleTransparency();
639
+ this.read(length, this._parseTRNS.bind(this));
640
+ };
641
+ Parser.prototype._parseTRNS = function(data) {
642
+ this._crc.write(data);
643
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
644
+ if (this._palette.length === 0) {
645
+ this.error(new Error("Transparency chunk must be after palette"));
646
+ return;
647
+ }
648
+ if (data.length > this._palette.length) {
649
+ this.error(new Error("More transparent colors than palette size"));
650
+ return;
651
+ }
652
+ for (let i = 0; i < data.length; i++) {
653
+ this._palette[i][3] = data[i];
654
+ }
655
+ this.palette(this._palette);
656
+ }
657
+ if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
658
+ this.transColor([data.readUInt16BE(0)]);
659
+ }
660
+ if (this._colorType === constants.COLORTYPE_COLOR) {
661
+ this.transColor([
662
+ data.readUInt16BE(0),
663
+ data.readUInt16BE(2),
664
+ data.readUInt16BE(4)
665
+ ]);
666
+ }
667
+ this._handleChunkEnd();
668
+ };
669
+ Parser.prototype._handleGAMA = function(length) {
670
+ this.read(length, this._parseGAMA.bind(this));
671
+ };
672
+ Parser.prototype._parseGAMA = function(data) {
673
+ this._crc.write(data);
674
+ this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
675
+ this._handleChunkEnd();
676
+ };
677
+ Parser.prototype._handleIDAT = function(length) {
678
+ if (!this._emittedHeadersFinished) {
679
+ this._emittedHeadersFinished = true;
680
+ this.headersFinished();
681
+ }
682
+ this.read(-length, this._parseIDAT.bind(this, length));
683
+ };
684
+ Parser.prototype._parseIDAT = function(length, data) {
685
+ this._crc.write(data);
686
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
687
+ throw new Error("Expected palette not found");
688
+ }
689
+ this.inflateData(data);
690
+ let leftOverLength = length - data.length;
691
+ if (leftOverLength > 0) {
692
+ this._handleIDAT(leftOverLength);
693
+ } else {
694
+ this._handleChunkEnd();
695
+ }
696
+ };
697
+ Parser.prototype._handleIEND = function(length) {
698
+ this.read(length, this._parseIEND.bind(this));
699
+ };
700
+ Parser.prototype._parseIEND = function(data) {
701
+ this._crc.write(data);
702
+ this._hasIEND = true;
703
+ this._handleChunkEnd();
704
+ if (this.finished) {
705
+ this.finished();
706
+ }
707
+ };
708
+ }
709
+ });
710
+
711
+ // node_modules/pngjs/lib/bitmapper.js
712
+ var require_bitmapper = __commonJS({
713
+ "node_modules/pngjs/lib/bitmapper.js"(exports) {
714
+ "use strict";
715
+ var interlaceUtils = require_interlace();
716
+ var pixelBppMapper = [
717
+ // 0 - dummy entry
718
+ function() {
719
+ },
720
+ // 1 - L
721
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
722
+ function(pxData, data, pxPos, rawPos) {
723
+ if (rawPos === data.length) {
724
+ throw new Error("Ran out of data");
725
+ }
726
+ let pixel = data[rawPos];
727
+ pxData[pxPos] = pixel;
728
+ pxData[pxPos + 1] = pixel;
729
+ pxData[pxPos + 2] = pixel;
730
+ pxData[pxPos + 3] = 255;
731
+ },
732
+ // 2 - LA
733
+ // 0: 0, 1: 0, 2: 0, 3: 1
734
+ function(pxData, data, pxPos, rawPos) {
735
+ if (rawPos + 1 >= data.length) {
736
+ throw new Error("Ran out of data");
737
+ }
738
+ let pixel = data[rawPos];
739
+ pxData[pxPos] = pixel;
740
+ pxData[pxPos + 1] = pixel;
741
+ pxData[pxPos + 2] = pixel;
742
+ pxData[pxPos + 3] = data[rawPos + 1];
743
+ },
744
+ // 3 - RGB
745
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
746
+ function(pxData, data, pxPos, rawPos) {
747
+ if (rawPos + 2 >= data.length) {
748
+ throw new Error("Ran out of data");
749
+ }
750
+ pxData[pxPos] = data[rawPos];
751
+ pxData[pxPos + 1] = data[rawPos + 1];
752
+ pxData[pxPos + 2] = data[rawPos + 2];
753
+ pxData[pxPos + 3] = 255;
754
+ },
755
+ // 4 - RGBA
756
+ // 0: 0, 1: 1, 2: 2, 3: 3
757
+ function(pxData, data, pxPos, rawPos) {
758
+ if (rawPos + 3 >= data.length) {
759
+ throw new Error("Ran out of data");
760
+ }
761
+ pxData[pxPos] = data[rawPos];
762
+ pxData[pxPos + 1] = data[rawPos + 1];
763
+ pxData[pxPos + 2] = data[rawPos + 2];
764
+ pxData[pxPos + 3] = data[rawPos + 3];
765
+ }
766
+ ];
767
+ var pixelBppCustomMapper = [
768
+ // 0 - dummy entry
769
+ function() {
770
+ },
771
+ // 1 - L
772
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
773
+ function(pxData, pixelData, pxPos, maxBit) {
774
+ let pixel = pixelData[0];
775
+ pxData[pxPos] = pixel;
776
+ pxData[pxPos + 1] = pixel;
777
+ pxData[pxPos + 2] = pixel;
778
+ pxData[pxPos + 3] = maxBit;
779
+ },
780
+ // 2 - LA
781
+ // 0: 0, 1: 0, 2: 0, 3: 1
782
+ function(pxData, pixelData, pxPos) {
783
+ let pixel = pixelData[0];
784
+ pxData[pxPos] = pixel;
785
+ pxData[pxPos + 1] = pixel;
786
+ pxData[pxPos + 2] = pixel;
787
+ pxData[pxPos + 3] = pixelData[1];
788
+ },
789
+ // 3 - RGB
790
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
791
+ function(pxData, pixelData, pxPos, maxBit) {
792
+ pxData[pxPos] = pixelData[0];
793
+ pxData[pxPos + 1] = pixelData[1];
794
+ pxData[pxPos + 2] = pixelData[2];
795
+ pxData[pxPos + 3] = maxBit;
796
+ },
797
+ // 4 - RGBA
798
+ // 0: 0, 1: 1, 2: 2, 3: 3
799
+ function(pxData, pixelData, pxPos) {
800
+ pxData[pxPos] = pixelData[0];
801
+ pxData[pxPos + 1] = pixelData[1];
802
+ pxData[pxPos + 2] = pixelData[2];
803
+ pxData[pxPos + 3] = pixelData[3];
804
+ }
805
+ ];
806
+ function bitRetriever(data, depth) {
807
+ let leftOver = [];
808
+ let i = 0;
809
+ function split() {
810
+ if (i === data.length) {
811
+ throw new Error("Ran out of data");
812
+ }
813
+ let byte = data[i];
814
+ i++;
815
+ let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
816
+ switch (depth) {
817
+ default:
818
+ throw new Error("unrecognised depth");
819
+ case 16:
820
+ byte2 = data[i];
821
+ i++;
822
+ leftOver.push((byte << 8) + byte2);
823
+ break;
824
+ case 4:
825
+ byte2 = byte & 15;
826
+ byte1 = byte >> 4;
827
+ leftOver.push(byte1, byte2);
828
+ break;
829
+ case 2:
830
+ byte4 = byte & 3;
831
+ byte3 = byte >> 2 & 3;
832
+ byte2 = byte >> 4 & 3;
833
+ byte1 = byte >> 6 & 3;
834
+ leftOver.push(byte1, byte2, byte3, byte4);
835
+ break;
836
+ case 1:
837
+ byte8 = byte & 1;
838
+ byte7 = byte >> 1 & 1;
839
+ byte6 = byte >> 2 & 1;
840
+ byte5 = byte >> 3 & 1;
841
+ byte4 = byte >> 4 & 1;
842
+ byte3 = byte >> 5 & 1;
843
+ byte2 = byte >> 6 & 1;
844
+ byte1 = byte >> 7 & 1;
845
+ leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
846
+ break;
847
+ }
848
+ }
849
+ return {
850
+ get: function(count) {
851
+ while (leftOver.length < count) {
852
+ split();
853
+ }
854
+ let returner = leftOver.slice(0, count);
855
+ leftOver = leftOver.slice(count);
856
+ return returner;
857
+ },
858
+ resetAfterLine: function() {
859
+ leftOver.length = 0;
860
+ },
861
+ end: function() {
862
+ if (i !== data.length) {
863
+ throw new Error("extra data found");
864
+ }
865
+ }
866
+ };
867
+ }
868
+ function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
869
+ let imageWidth = image.width;
870
+ let imageHeight = image.height;
871
+ let imagePass = image.index;
872
+ for (let y = 0; y < imageHeight; y++) {
873
+ for (let x = 0; x < imageWidth; x++) {
874
+ let pxPos = getPxPos(x, y, imagePass);
875
+ pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
876
+ rawPos += bpp;
877
+ }
878
+ }
879
+ return rawPos;
880
+ }
881
+ function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
882
+ let imageWidth = image.width;
883
+ let imageHeight = image.height;
884
+ let imagePass = image.index;
885
+ for (let y = 0; y < imageHeight; y++) {
886
+ for (let x = 0; x < imageWidth; x++) {
887
+ let pixelData = bits.get(bpp);
888
+ let pxPos = getPxPos(x, y, imagePass);
889
+ pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
890
+ }
891
+ bits.resetAfterLine();
892
+ }
893
+ }
894
+ exports.dataToBitMap = function(data, bitmapInfo) {
895
+ let width = bitmapInfo.width;
896
+ let height = bitmapInfo.height;
897
+ let depth = bitmapInfo.depth;
898
+ let bpp = bitmapInfo.bpp;
899
+ let interlace = bitmapInfo.interlace;
900
+ let bits;
901
+ if (depth !== 8) {
902
+ bits = bitRetriever(data, depth);
903
+ }
904
+ let pxData;
905
+ if (depth <= 8) {
906
+ pxData = Buffer.alloc(width * height * 4);
907
+ } else {
908
+ pxData = new Uint16Array(width * height * 4);
909
+ }
910
+ let maxBit = Math.pow(2, depth) - 1;
911
+ let rawPos = 0;
912
+ let images;
913
+ let getPxPos;
914
+ if (interlace) {
915
+ images = interlaceUtils.getImagePasses(width, height);
916
+ getPxPos = interlaceUtils.getInterlaceIterator(width, height);
917
+ } else {
918
+ let nonInterlacedPxPos = 0;
919
+ getPxPos = function() {
920
+ let returner = nonInterlacedPxPos;
921
+ nonInterlacedPxPos += 4;
922
+ return returner;
923
+ };
924
+ images = [{ width, height }];
925
+ }
926
+ for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
927
+ if (depth === 8) {
928
+ rawPos = mapImage8Bit(
929
+ images[imageIndex],
930
+ pxData,
931
+ getPxPos,
932
+ bpp,
933
+ data,
934
+ rawPos
935
+ );
936
+ } else {
937
+ mapImageCustomBit(
938
+ images[imageIndex],
939
+ pxData,
940
+ getPxPos,
941
+ bpp,
942
+ bits,
943
+ maxBit
944
+ );
945
+ }
946
+ }
947
+ if (depth === 8) {
948
+ if (rawPos !== data.length) {
949
+ throw new Error("extra data found");
950
+ }
951
+ } else {
952
+ bits.end();
953
+ }
954
+ return pxData;
955
+ };
956
+ }
957
+ });
958
+
959
+ // node_modules/pngjs/lib/format-normaliser.js
960
+ var require_format_normaliser = __commonJS({
961
+ "node_modules/pngjs/lib/format-normaliser.js"(exports, module) {
962
+ "use strict";
963
+ function dePalette(indata, outdata, width, height, palette) {
964
+ let pxPos = 0;
965
+ for (let y = 0; y < height; y++) {
966
+ for (let x = 0; x < width; x++) {
967
+ let color = palette[indata[pxPos]];
968
+ if (!color) {
969
+ throw new Error("index " + indata[pxPos] + " not in palette");
970
+ }
971
+ for (let i = 0; i < 4; i++) {
972
+ outdata[pxPos + i] = color[i];
973
+ }
974
+ pxPos += 4;
975
+ }
976
+ }
977
+ }
978
+ function replaceTransparentColor(indata, outdata, width, height, transColor) {
979
+ let pxPos = 0;
980
+ for (let y = 0; y < height; y++) {
981
+ for (let x = 0; x < width; x++) {
982
+ let makeTrans = false;
983
+ if (transColor.length === 1) {
984
+ if (transColor[0] === indata[pxPos]) {
985
+ makeTrans = true;
986
+ }
987
+ } else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
988
+ makeTrans = true;
989
+ }
990
+ if (makeTrans) {
991
+ for (let i = 0; i < 4; i++) {
992
+ outdata[pxPos + i] = 0;
993
+ }
994
+ }
995
+ pxPos += 4;
996
+ }
997
+ }
998
+ }
999
+ function scaleDepth(indata, outdata, width, height, depth) {
1000
+ let maxOutSample = 255;
1001
+ let maxInSample = Math.pow(2, depth) - 1;
1002
+ let pxPos = 0;
1003
+ for (let y = 0; y < height; y++) {
1004
+ for (let x = 0; x < width; x++) {
1005
+ for (let i = 0; i < 4; i++) {
1006
+ outdata[pxPos + i] = Math.floor(
1007
+ indata[pxPos + i] * maxOutSample / maxInSample + 0.5
1008
+ );
1009
+ }
1010
+ pxPos += 4;
1011
+ }
1012
+ }
1013
+ }
1014
+ module.exports = function(indata, imageData, skipRescale = false) {
1015
+ let depth = imageData.depth;
1016
+ let width = imageData.width;
1017
+ let height = imageData.height;
1018
+ let colorType = imageData.colorType;
1019
+ let transColor = imageData.transColor;
1020
+ let palette = imageData.palette;
1021
+ let outdata = indata;
1022
+ if (colorType === 3) {
1023
+ dePalette(indata, outdata, width, height, palette);
1024
+ } else {
1025
+ if (transColor) {
1026
+ replaceTransparentColor(indata, outdata, width, height, transColor);
1027
+ }
1028
+ if (depth !== 8 && !skipRescale) {
1029
+ if (depth === 16) {
1030
+ outdata = Buffer.alloc(width * height * 4);
1031
+ }
1032
+ scaleDepth(indata, outdata, width, height, depth);
1033
+ }
1034
+ }
1035
+ return outdata;
1036
+ };
1037
+ }
1038
+ });
1039
+
1040
+ // node_modules/pngjs/lib/parser-async.js
1041
+ var require_parser_async = __commonJS({
1042
+ "node_modules/pngjs/lib/parser-async.js"(exports, module) {
1043
+ "use strict";
1044
+ var util = __require("util");
1045
+ var zlib = __require("zlib");
1046
+ var ChunkStream = require_chunkstream();
1047
+ var FilterAsync = require_filter_parse_async();
1048
+ var Parser = require_parser();
1049
+ var bitmapper = require_bitmapper();
1050
+ var formatNormaliser = require_format_normaliser();
1051
+ var ParserAsync = module.exports = function(options) {
1052
+ ChunkStream.call(this);
1053
+ this._parser = new Parser(options, {
1054
+ read: this.read.bind(this),
1055
+ error: this._handleError.bind(this),
1056
+ metadata: this._handleMetaData.bind(this),
1057
+ gamma: this.emit.bind(this, "gamma"),
1058
+ palette: this._handlePalette.bind(this),
1059
+ transColor: this._handleTransColor.bind(this),
1060
+ finished: this._finished.bind(this),
1061
+ inflateData: this._inflateData.bind(this),
1062
+ simpleTransparency: this._simpleTransparency.bind(this),
1063
+ headersFinished: this._headersFinished.bind(this)
1064
+ });
1065
+ this._options = options;
1066
+ this.writable = true;
1067
+ this._parser.start();
1068
+ };
1069
+ util.inherits(ParserAsync, ChunkStream);
1070
+ ParserAsync.prototype._handleError = function(err) {
1071
+ this.emit("error", err);
1072
+ this.writable = false;
1073
+ this.destroy();
1074
+ if (this._inflate && this._inflate.destroy) {
1075
+ this._inflate.destroy();
1076
+ }
1077
+ if (this._filter) {
1078
+ this._filter.destroy();
1079
+ this._filter.on("error", function() {
1080
+ });
1081
+ }
1082
+ this.errord = true;
1083
+ };
1084
+ ParserAsync.prototype._inflateData = function(data) {
1085
+ if (!this._inflate) {
1086
+ if (this._bitmapInfo.interlace) {
1087
+ this._inflate = zlib.createInflate();
1088
+ this._inflate.on("error", this.emit.bind(this, "error"));
1089
+ this._filter.on("complete", this._complete.bind(this));
1090
+ this._inflate.pipe(this._filter);
1091
+ } else {
1092
+ let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
1093
+ let imageSize = rowSize * this._bitmapInfo.height;
1094
+ let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
1095
+ this._inflate = zlib.createInflate({ chunkSize });
1096
+ let leftToInflate = imageSize;
1097
+ let emitError = this.emit.bind(this, "error");
1098
+ this._inflate.on("error", function(err) {
1099
+ if (!leftToInflate) {
1100
+ return;
1101
+ }
1102
+ emitError(err);
1103
+ });
1104
+ this._filter.on("complete", this._complete.bind(this));
1105
+ let filterWrite = this._filter.write.bind(this._filter);
1106
+ this._inflate.on("data", function(chunk) {
1107
+ if (!leftToInflate) {
1108
+ return;
1109
+ }
1110
+ if (chunk.length > leftToInflate) {
1111
+ chunk = chunk.slice(0, leftToInflate);
1112
+ }
1113
+ leftToInflate -= chunk.length;
1114
+ filterWrite(chunk);
1115
+ });
1116
+ this._inflate.on("end", this._filter.end.bind(this._filter));
1117
+ }
1118
+ }
1119
+ this._inflate.write(data);
1120
+ };
1121
+ ParserAsync.prototype._handleMetaData = function(metaData) {
1122
+ this._metaData = metaData;
1123
+ this._bitmapInfo = Object.create(metaData);
1124
+ this._filter = new FilterAsync(this._bitmapInfo);
1125
+ };
1126
+ ParserAsync.prototype._handleTransColor = function(transColor) {
1127
+ this._bitmapInfo.transColor = transColor;
1128
+ };
1129
+ ParserAsync.prototype._handlePalette = function(palette) {
1130
+ this._bitmapInfo.palette = palette;
1131
+ };
1132
+ ParserAsync.prototype._simpleTransparency = function() {
1133
+ this._metaData.alpha = true;
1134
+ };
1135
+ ParserAsync.prototype._headersFinished = function() {
1136
+ this.emit("metadata", this._metaData);
1137
+ };
1138
+ ParserAsync.prototype._finished = function() {
1139
+ if (this.errord) {
1140
+ return;
1141
+ }
1142
+ if (!this._inflate) {
1143
+ this.emit("error", "No Inflate block");
1144
+ } else {
1145
+ this._inflate.end();
1146
+ }
1147
+ };
1148
+ ParserAsync.prototype._complete = function(filteredData) {
1149
+ if (this.errord) {
1150
+ return;
1151
+ }
1152
+ let normalisedBitmapData;
1153
+ try {
1154
+ let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
1155
+ normalisedBitmapData = formatNormaliser(
1156
+ bitmapData,
1157
+ this._bitmapInfo,
1158
+ this._options.skipRescale
1159
+ );
1160
+ bitmapData = null;
1161
+ } catch (ex) {
1162
+ this._handleError(ex);
1163
+ return;
1164
+ }
1165
+ this.emit("parsed", normalisedBitmapData);
1166
+ };
1167
+ }
1168
+ });
1169
+
1170
+ // node_modules/pngjs/lib/bitpacker.js
1171
+ var require_bitpacker = __commonJS({
1172
+ "node_modules/pngjs/lib/bitpacker.js"(exports, module) {
1173
+ "use strict";
1174
+ var constants = require_constants();
1175
+ module.exports = function(dataIn, width, height, options) {
1176
+ let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(
1177
+ options.colorType
1178
+ ) !== -1;
1179
+ if (options.colorType === options.inputColorType) {
1180
+ let bigEndian = (function() {
1181
+ let buffer = new ArrayBuffer(2);
1182
+ new DataView(buffer).setInt16(
1183
+ 0,
1184
+ 256,
1185
+ true
1186
+ /* littleEndian */
1187
+ );
1188
+ return new Int16Array(buffer)[0] !== 256;
1189
+ })();
1190
+ if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
1191
+ return dataIn;
1192
+ }
1193
+ }
1194
+ let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
1195
+ let maxValue = 255;
1196
+ let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
1197
+ if (inBpp === 4 && !options.inputHasAlpha) {
1198
+ inBpp = 3;
1199
+ }
1200
+ let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
1201
+ if (options.bitDepth === 16) {
1202
+ maxValue = 65535;
1203
+ outBpp *= 2;
1204
+ }
1205
+ let outData = Buffer.alloc(width * height * outBpp);
1206
+ let inIndex = 0;
1207
+ let outIndex = 0;
1208
+ let bgColor = options.bgColor || {};
1209
+ if (bgColor.red === void 0) {
1210
+ bgColor.red = maxValue;
1211
+ }
1212
+ if (bgColor.green === void 0) {
1213
+ bgColor.green = maxValue;
1214
+ }
1215
+ if (bgColor.blue === void 0) {
1216
+ bgColor.blue = maxValue;
1217
+ }
1218
+ function getRGBA() {
1219
+ let red;
1220
+ let green;
1221
+ let blue;
1222
+ let alpha = maxValue;
1223
+ switch (options.inputColorType) {
1224
+ case constants.COLORTYPE_COLOR_ALPHA:
1225
+ alpha = data[inIndex + 3];
1226
+ red = data[inIndex];
1227
+ green = data[inIndex + 1];
1228
+ blue = data[inIndex + 2];
1229
+ break;
1230
+ case constants.COLORTYPE_COLOR:
1231
+ red = data[inIndex];
1232
+ green = data[inIndex + 1];
1233
+ blue = data[inIndex + 2];
1234
+ break;
1235
+ case constants.COLORTYPE_ALPHA:
1236
+ alpha = data[inIndex + 1];
1237
+ red = data[inIndex];
1238
+ green = red;
1239
+ blue = red;
1240
+ break;
1241
+ case constants.COLORTYPE_GRAYSCALE:
1242
+ red = data[inIndex];
1243
+ green = red;
1244
+ blue = red;
1245
+ break;
1246
+ default:
1247
+ throw new Error(
1248
+ "input color type:" + options.inputColorType + " is not supported at present"
1249
+ );
1250
+ }
1251
+ if (options.inputHasAlpha) {
1252
+ if (!outHasAlpha) {
1253
+ alpha /= maxValue;
1254
+ red = Math.min(
1255
+ Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
1256
+ maxValue
1257
+ );
1258
+ green = Math.min(
1259
+ Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
1260
+ maxValue
1261
+ );
1262
+ blue = Math.min(
1263
+ Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
1264
+ maxValue
1265
+ );
1266
+ }
1267
+ }
1268
+ return { red, green, blue, alpha };
1269
+ }
1270
+ for (let y = 0; y < height; y++) {
1271
+ for (let x = 0; x < width; x++) {
1272
+ let rgba = getRGBA(data, inIndex);
1273
+ switch (options.colorType) {
1274
+ case constants.COLORTYPE_COLOR_ALPHA:
1275
+ case constants.COLORTYPE_COLOR:
1276
+ if (options.bitDepth === 8) {
1277
+ outData[outIndex] = rgba.red;
1278
+ outData[outIndex + 1] = rgba.green;
1279
+ outData[outIndex + 2] = rgba.blue;
1280
+ if (outHasAlpha) {
1281
+ outData[outIndex + 3] = rgba.alpha;
1282
+ }
1283
+ } else {
1284
+ outData.writeUInt16BE(rgba.red, outIndex);
1285
+ outData.writeUInt16BE(rgba.green, outIndex + 2);
1286
+ outData.writeUInt16BE(rgba.blue, outIndex + 4);
1287
+ if (outHasAlpha) {
1288
+ outData.writeUInt16BE(rgba.alpha, outIndex + 6);
1289
+ }
1290
+ }
1291
+ break;
1292
+ case constants.COLORTYPE_ALPHA:
1293
+ case constants.COLORTYPE_GRAYSCALE: {
1294
+ let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
1295
+ if (options.bitDepth === 8) {
1296
+ outData[outIndex] = grayscale;
1297
+ if (outHasAlpha) {
1298
+ outData[outIndex + 1] = rgba.alpha;
1299
+ }
1300
+ } else {
1301
+ outData.writeUInt16BE(grayscale, outIndex);
1302
+ if (outHasAlpha) {
1303
+ outData.writeUInt16BE(rgba.alpha, outIndex + 2);
1304
+ }
1305
+ }
1306
+ break;
1307
+ }
1308
+ default:
1309
+ throw new Error("unrecognised color Type " + options.colorType);
1310
+ }
1311
+ inIndex += inBpp;
1312
+ outIndex += outBpp;
1313
+ }
1314
+ }
1315
+ return outData;
1316
+ };
1317
+ }
1318
+ });
1319
+
1320
+ // node_modules/pngjs/lib/filter-pack.js
1321
+ var require_filter_pack = __commonJS({
1322
+ "node_modules/pngjs/lib/filter-pack.js"(exports, module) {
1323
+ "use strict";
1324
+ var paethPredictor = require_paeth_predictor();
1325
+ function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
1326
+ for (let x = 0; x < byteWidth; x++) {
1327
+ rawData[rawPos + x] = pxData[pxPos + x];
1328
+ }
1329
+ }
1330
+ function filterSumNone(pxData, pxPos, byteWidth) {
1331
+ let sum = 0;
1332
+ let length = pxPos + byteWidth;
1333
+ for (let i = pxPos; i < length; i++) {
1334
+ sum += Math.abs(pxData[i]);
1335
+ }
1336
+ return sum;
1337
+ }
1338
+ function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1339
+ for (let x = 0; x < byteWidth; x++) {
1340
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1341
+ let val = pxData[pxPos + x] - left;
1342
+ rawData[rawPos + x] = val;
1343
+ }
1344
+ }
1345
+ function filterSumSub(pxData, pxPos, byteWidth, bpp) {
1346
+ let sum = 0;
1347
+ for (let x = 0; x < byteWidth; x++) {
1348
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1349
+ let val = pxData[pxPos + x] - left;
1350
+ sum += Math.abs(val);
1351
+ }
1352
+ return sum;
1353
+ }
1354
+ function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
1355
+ for (let x = 0; x < byteWidth; x++) {
1356
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1357
+ let val = pxData[pxPos + x] - up;
1358
+ rawData[rawPos + x] = val;
1359
+ }
1360
+ }
1361
+ function filterSumUp(pxData, pxPos, byteWidth) {
1362
+ let sum = 0;
1363
+ let length = pxPos + byteWidth;
1364
+ for (let x = pxPos; x < length; x++) {
1365
+ let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
1366
+ let val = pxData[x] - up;
1367
+ sum += Math.abs(val);
1368
+ }
1369
+ return sum;
1370
+ }
1371
+ function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1372
+ for (let x = 0; x < byteWidth; x++) {
1373
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1374
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1375
+ let val = pxData[pxPos + x] - (left + up >> 1);
1376
+ rawData[rawPos + x] = val;
1377
+ }
1378
+ }
1379
+ function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
1380
+ let sum = 0;
1381
+ for (let x = 0; x < byteWidth; x++) {
1382
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1383
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1384
+ let val = pxData[pxPos + x] - (left + up >> 1);
1385
+ sum += Math.abs(val);
1386
+ }
1387
+ return sum;
1388
+ }
1389
+ function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1390
+ for (let x = 0; x < byteWidth; x++) {
1391
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1392
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1393
+ let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1394
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1395
+ rawData[rawPos + x] = val;
1396
+ }
1397
+ }
1398
+ function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
1399
+ let sum = 0;
1400
+ for (let x = 0; x < byteWidth; x++) {
1401
+ let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1402
+ let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1403
+ let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1404
+ let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1405
+ sum += Math.abs(val);
1406
+ }
1407
+ return sum;
1408
+ }
1409
+ var filters = {
1410
+ 0: filterNone,
1411
+ 1: filterSub,
1412
+ 2: filterUp,
1413
+ 3: filterAvg,
1414
+ 4: filterPaeth
1415
+ };
1416
+ var filterSums = {
1417
+ 0: filterSumNone,
1418
+ 1: filterSumSub,
1419
+ 2: filterSumUp,
1420
+ 3: filterSumAvg,
1421
+ 4: filterSumPaeth
1422
+ };
1423
+ module.exports = function(pxData, width, height, options, bpp) {
1424
+ let filterTypes;
1425
+ if (!("filterType" in options) || options.filterType === -1) {
1426
+ filterTypes = [0, 1, 2, 3, 4];
1427
+ } else if (typeof options.filterType === "number") {
1428
+ filterTypes = [options.filterType];
1429
+ } else {
1430
+ throw new Error("unrecognised filter types");
1431
+ }
1432
+ if (options.bitDepth === 16) {
1433
+ bpp *= 2;
1434
+ }
1435
+ let byteWidth = width * bpp;
1436
+ let rawPos = 0;
1437
+ let pxPos = 0;
1438
+ let rawData = Buffer.alloc((byteWidth + 1) * height);
1439
+ let sel = filterTypes[0];
1440
+ for (let y = 0; y < height; y++) {
1441
+ if (filterTypes.length > 1) {
1442
+ let min = Infinity;
1443
+ for (let i = 0; i < filterTypes.length; i++) {
1444
+ let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
1445
+ if (sum < min) {
1446
+ sel = filterTypes[i];
1447
+ min = sum;
1448
+ }
1449
+ }
1450
+ }
1451
+ rawData[rawPos] = sel;
1452
+ rawPos++;
1453
+ filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
1454
+ rawPos += byteWidth;
1455
+ pxPos += byteWidth;
1456
+ }
1457
+ return rawData;
1458
+ };
1459
+ }
1460
+ });
1461
+
1462
+ // node_modules/pngjs/lib/packer.js
1463
+ var require_packer = __commonJS({
1464
+ "node_modules/pngjs/lib/packer.js"(exports, module) {
1465
+ "use strict";
1466
+ var constants = require_constants();
1467
+ var CrcStream = require_crc();
1468
+ var bitPacker = require_bitpacker();
1469
+ var filter = require_filter_pack();
1470
+ var zlib = __require("zlib");
1471
+ var Packer = module.exports = function(options) {
1472
+ this._options = options;
1473
+ options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
1474
+ options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
1475
+ options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
1476
+ options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
1477
+ options.deflateFactory = options.deflateFactory || zlib.createDeflate;
1478
+ options.bitDepth = options.bitDepth || 8;
1479
+ options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
1480
+ options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
1481
+ if ([
1482
+ constants.COLORTYPE_GRAYSCALE,
1483
+ constants.COLORTYPE_COLOR,
1484
+ constants.COLORTYPE_COLOR_ALPHA,
1485
+ constants.COLORTYPE_ALPHA
1486
+ ].indexOf(options.colorType) === -1) {
1487
+ throw new Error(
1488
+ "option color type:" + options.colorType + " is not supported at present"
1489
+ );
1490
+ }
1491
+ if ([
1492
+ constants.COLORTYPE_GRAYSCALE,
1493
+ constants.COLORTYPE_COLOR,
1494
+ constants.COLORTYPE_COLOR_ALPHA,
1495
+ constants.COLORTYPE_ALPHA
1496
+ ].indexOf(options.inputColorType) === -1) {
1497
+ throw new Error(
1498
+ "option input color type:" + options.inputColorType + " is not supported at present"
1499
+ );
1500
+ }
1501
+ if (options.bitDepth !== 8 && options.bitDepth !== 16) {
1502
+ throw new Error(
1503
+ "option bit depth:" + options.bitDepth + " is not supported at present"
1504
+ );
1505
+ }
1506
+ };
1507
+ Packer.prototype.getDeflateOptions = function() {
1508
+ return {
1509
+ chunkSize: this._options.deflateChunkSize,
1510
+ level: this._options.deflateLevel,
1511
+ strategy: this._options.deflateStrategy
1512
+ };
1513
+ };
1514
+ Packer.prototype.createDeflate = function() {
1515
+ return this._options.deflateFactory(this.getDeflateOptions());
1516
+ };
1517
+ Packer.prototype.filterData = function(data, width, height) {
1518
+ let packedData = bitPacker(data, width, height, this._options);
1519
+ let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
1520
+ let filteredData = filter(packedData, width, height, this._options, bpp);
1521
+ return filteredData;
1522
+ };
1523
+ Packer.prototype._packChunk = function(type, data) {
1524
+ let len = data ? data.length : 0;
1525
+ let buf = Buffer.alloc(len + 12);
1526
+ buf.writeUInt32BE(len, 0);
1527
+ buf.writeUInt32BE(type, 4);
1528
+ if (data) {
1529
+ data.copy(buf, 8);
1530
+ }
1531
+ buf.writeInt32BE(
1532
+ CrcStream.crc32(buf.slice(4, buf.length - 4)),
1533
+ buf.length - 4
1534
+ );
1535
+ return buf;
1536
+ };
1537
+ Packer.prototype.packGAMA = function(gamma) {
1538
+ let buf = Buffer.alloc(4);
1539
+ buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
1540
+ return this._packChunk(constants.TYPE_gAMA, buf);
1541
+ };
1542
+ Packer.prototype.packIHDR = function(width, height) {
1543
+ let buf = Buffer.alloc(13);
1544
+ buf.writeUInt32BE(width, 0);
1545
+ buf.writeUInt32BE(height, 4);
1546
+ buf[8] = this._options.bitDepth;
1547
+ buf[9] = this._options.colorType;
1548
+ buf[10] = 0;
1549
+ buf[11] = 0;
1550
+ buf[12] = 0;
1551
+ return this._packChunk(constants.TYPE_IHDR, buf);
1552
+ };
1553
+ Packer.prototype.packIDAT = function(data) {
1554
+ return this._packChunk(constants.TYPE_IDAT, data);
1555
+ };
1556
+ Packer.prototype.packIEND = function() {
1557
+ return this._packChunk(constants.TYPE_IEND, null);
1558
+ };
1559
+ }
1560
+ });
1561
+
1562
+ // node_modules/pngjs/lib/packer-async.js
1563
+ var require_packer_async = __commonJS({
1564
+ "node_modules/pngjs/lib/packer-async.js"(exports, module) {
1565
+ "use strict";
1566
+ var util = __require("util");
1567
+ var Stream = __require("stream");
1568
+ var constants = require_constants();
1569
+ var Packer = require_packer();
1570
+ var PackerAsync = module.exports = function(opt) {
1571
+ Stream.call(this);
1572
+ let options = opt || {};
1573
+ this._packer = new Packer(options);
1574
+ this._deflate = this._packer.createDeflate();
1575
+ this.readable = true;
1576
+ };
1577
+ util.inherits(PackerAsync, Stream);
1578
+ PackerAsync.prototype.pack = function(data, width, height, gamma) {
1579
+ this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
1580
+ this.emit("data", this._packer.packIHDR(width, height));
1581
+ if (gamma) {
1582
+ this.emit("data", this._packer.packGAMA(gamma));
1583
+ }
1584
+ let filteredData = this._packer.filterData(data, width, height);
1585
+ this._deflate.on("error", this.emit.bind(this, "error"));
1586
+ this._deflate.on(
1587
+ "data",
1588
+ function(compressedData) {
1589
+ this.emit("data", this._packer.packIDAT(compressedData));
1590
+ }.bind(this)
1591
+ );
1592
+ this._deflate.on(
1593
+ "end",
1594
+ function() {
1595
+ this.emit("data", this._packer.packIEND());
1596
+ this.emit("end");
1597
+ }.bind(this)
1598
+ );
1599
+ this._deflate.end(filteredData);
1600
+ };
1601
+ }
1602
+ });
1603
+
1604
+ // node_modules/pngjs/lib/sync-inflate.js
1605
+ var require_sync_inflate = __commonJS({
1606
+ "node_modules/pngjs/lib/sync-inflate.js"(exports, module) {
1607
+ "use strict";
1608
+ var assert = __require("assert").ok;
1609
+ var zlib = __require("zlib");
1610
+ var util = __require("util");
1611
+ var kMaxLength = __require("buffer").kMaxLength;
1612
+ function Inflate(opts) {
1613
+ if (!(this instanceof Inflate)) {
1614
+ return new Inflate(opts);
1615
+ }
1616
+ if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
1617
+ opts.chunkSize = zlib.Z_MIN_CHUNK;
1618
+ }
1619
+ zlib.Inflate.call(this, opts);
1620
+ this._offset = this._offset === void 0 ? this._outOffset : this._offset;
1621
+ this._buffer = this._buffer || this._outBuffer;
1622
+ if (opts && opts.maxLength != null) {
1623
+ this._maxLength = opts.maxLength;
1624
+ }
1625
+ }
1626
+ function createInflate(opts) {
1627
+ return new Inflate(opts);
1628
+ }
1629
+ function _close(engine, callback) {
1630
+ if (callback) {
1631
+ process.nextTick(callback);
1632
+ }
1633
+ if (!engine._handle) {
1634
+ return;
1635
+ }
1636
+ engine._handle.close();
1637
+ engine._handle = null;
1638
+ }
1639
+ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
1640
+ if (typeof asyncCb === "function") {
1641
+ return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
1642
+ }
1643
+ let self = this;
1644
+ let availInBefore = chunk && chunk.length;
1645
+ let availOutBefore = this._chunkSize - this._offset;
1646
+ let leftToInflate = this._maxLength;
1647
+ let inOff = 0;
1648
+ let buffers = [];
1649
+ let nread = 0;
1650
+ let error;
1651
+ this.on("error", function(err) {
1652
+ error = err;
1653
+ });
1654
+ function handleChunk(availInAfter, availOutAfter) {
1655
+ if (self._hadError) {
1656
+ return;
1657
+ }
1658
+ let have = availOutBefore - availOutAfter;
1659
+ assert(have >= 0, "have should not go down");
1660
+ if (have > 0) {
1661
+ let out = self._buffer.slice(self._offset, self._offset + have);
1662
+ self._offset += have;
1663
+ if (out.length > leftToInflate) {
1664
+ out = out.slice(0, leftToInflate);
1665
+ }
1666
+ buffers.push(out);
1667
+ nread += out.length;
1668
+ leftToInflate -= out.length;
1669
+ if (leftToInflate === 0) {
1670
+ return false;
1671
+ }
1672
+ }
1673
+ if (availOutAfter === 0 || self._offset >= self._chunkSize) {
1674
+ availOutBefore = self._chunkSize;
1675
+ self._offset = 0;
1676
+ self._buffer = Buffer.allocUnsafe(self._chunkSize);
1677
+ }
1678
+ if (availOutAfter === 0) {
1679
+ inOff += availInBefore - availInAfter;
1680
+ availInBefore = availInAfter;
1681
+ return true;
1682
+ }
1683
+ return false;
1684
+ }
1685
+ assert(this._handle, "zlib binding closed");
1686
+ let res;
1687
+ do {
1688
+ res = this._handle.writeSync(
1689
+ flushFlag,
1690
+ chunk,
1691
+ // in
1692
+ inOff,
1693
+ // in_off
1694
+ availInBefore,
1695
+ // in_len
1696
+ this._buffer,
1697
+ // out
1698
+ this._offset,
1699
+ //out_off
1700
+ availOutBefore
1701
+ );
1702
+ res = res || this._writeState;
1703
+ } while (!this._hadError && handleChunk(res[0], res[1]));
1704
+ if (this._hadError) {
1705
+ throw error;
1706
+ }
1707
+ if (nread >= kMaxLength) {
1708
+ _close(this);
1709
+ throw new RangeError(
1710
+ "Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes"
1711
+ );
1712
+ }
1713
+ let buf = Buffer.concat(buffers, nread);
1714
+ _close(this);
1715
+ return buf;
1716
+ };
1717
+ util.inherits(Inflate, zlib.Inflate);
1718
+ function zlibBufferSync(engine, buffer) {
1719
+ if (typeof buffer === "string") {
1720
+ buffer = Buffer.from(buffer);
1721
+ }
1722
+ if (!(buffer instanceof Buffer)) {
1723
+ throw new TypeError("Not a string or buffer");
1724
+ }
1725
+ let flushFlag = engine._finishFlushFlag;
1726
+ if (flushFlag == null) {
1727
+ flushFlag = zlib.Z_FINISH;
1728
+ }
1729
+ return engine._processChunk(buffer, flushFlag);
1730
+ }
1731
+ function inflateSync(buffer, opts) {
1732
+ return zlibBufferSync(new Inflate(opts), buffer);
1733
+ }
1734
+ module.exports = exports = inflateSync;
1735
+ exports.Inflate = Inflate;
1736
+ exports.createInflate = createInflate;
1737
+ exports.inflateSync = inflateSync;
1738
+ }
1739
+ });
1740
+
1741
+ // node_modules/pngjs/lib/sync-reader.js
1742
+ var require_sync_reader = __commonJS({
1743
+ "node_modules/pngjs/lib/sync-reader.js"(exports, module) {
1744
+ "use strict";
1745
+ var SyncReader = module.exports = function(buffer) {
1746
+ this._buffer = buffer;
1747
+ this._reads = [];
1748
+ };
1749
+ SyncReader.prototype.read = function(length, callback) {
1750
+ this._reads.push({
1751
+ length: Math.abs(length),
1752
+ // if length < 0 then at most this length
1753
+ allowLess: length < 0,
1754
+ func: callback
1755
+ });
1756
+ };
1757
+ SyncReader.prototype.process = function() {
1758
+ while (this._reads.length > 0 && this._buffer.length) {
1759
+ let read = this._reads[0];
1760
+ if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
1761
+ this._reads.shift();
1762
+ let buf = this._buffer;
1763
+ this._buffer = buf.slice(read.length);
1764
+ read.func.call(this, buf.slice(0, read.length));
1765
+ } else {
1766
+ break;
1767
+ }
1768
+ }
1769
+ if (this._reads.length > 0) {
1770
+ throw new Error("There are some read requests waitng on finished stream");
1771
+ }
1772
+ if (this._buffer.length > 0) {
1773
+ throw new Error("unrecognised content at end of stream");
1774
+ }
1775
+ };
1776
+ }
1777
+ });
1778
+
1779
+ // node_modules/pngjs/lib/filter-parse-sync.js
1780
+ var require_filter_parse_sync = __commonJS({
1781
+ "node_modules/pngjs/lib/filter-parse-sync.js"(exports) {
1782
+ "use strict";
1783
+ var SyncReader = require_sync_reader();
1784
+ var Filter = require_filter_parse();
1785
+ exports.process = function(inBuffer, bitmapInfo) {
1786
+ let outBuffers = [];
1787
+ let reader = new SyncReader(inBuffer);
1788
+ let filter = new Filter(bitmapInfo, {
1789
+ read: reader.read.bind(reader),
1790
+ write: function(bufferPart) {
1791
+ outBuffers.push(bufferPart);
1792
+ },
1793
+ complete: function() {
1794
+ }
1795
+ });
1796
+ filter.start();
1797
+ reader.process();
1798
+ return Buffer.concat(outBuffers);
1799
+ };
1800
+ }
1801
+ });
1802
+
1803
+ // node_modules/pngjs/lib/parser-sync.js
1804
+ var require_parser_sync = __commonJS({
1805
+ "node_modules/pngjs/lib/parser-sync.js"(exports, module) {
1806
+ "use strict";
1807
+ var hasSyncZlib = true;
1808
+ var zlib = __require("zlib");
1809
+ var inflateSync = require_sync_inflate();
1810
+ if (!zlib.deflateSync) {
1811
+ hasSyncZlib = false;
1812
+ }
1813
+ var SyncReader = require_sync_reader();
1814
+ var FilterSync = require_filter_parse_sync();
1815
+ var Parser = require_parser();
1816
+ var bitmapper = require_bitmapper();
1817
+ var formatNormaliser = require_format_normaliser();
1818
+ module.exports = function(buffer, options) {
1819
+ if (!hasSyncZlib) {
1820
+ throw new Error(
1821
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
1822
+ );
1823
+ }
1824
+ let err;
1825
+ function handleError(_err_) {
1826
+ err = _err_;
1827
+ }
1828
+ let metaData;
1829
+ function handleMetaData(_metaData_) {
1830
+ metaData = _metaData_;
1831
+ }
1832
+ function handleTransColor(transColor) {
1833
+ metaData.transColor = transColor;
1834
+ }
1835
+ function handlePalette(palette) {
1836
+ metaData.palette = palette;
1837
+ }
1838
+ function handleSimpleTransparency() {
1839
+ metaData.alpha = true;
1840
+ }
1841
+ let gamma;
1842
+ function handleGamma(_gamma_) {
1843
+ gamma = _gamma_;
1844
+ }
1845
+ let inflateDataList = [];
1846
+ function handleInflateData(inflatedData2) {
1847
+ inflateDataList.push(inflatedData2);
1848
+ }
1849
+ let reader = new SyncReader(buffer);
1850
+ let parser = new Parser(options, {
1851
+ read: reader.read.bind(reader),
1852
+ error: handleError,
1853
+ metadata: handleMetaData,
1854
+ gamma: handleGamma,
1855
+ palette: handlePalette,
1856
+ transColor: handleTransColor,
1857
+ inflateData: handleInflateData,
1858
+ simpleTransparency: handleSimpleTransparency
1859
+ });
1860
+ parser.start();
1861
+ reader.process();
1862
+ if (err) {
1863
+ throw err;
1864
+ }
1865
+ let inflateData = Buffer.concat(inflateDataList);
1866
+ inflateDataList.length = 0;
1867
+ let inflatedData;
1868
+ if (metaData.interlace) {
1869
+ inflatedData = zlib.inflateSync(inflateData);
1870
+ } else {
1871
+ let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
1872
+ let imageSize = rowSize * metaData.height;
1873
+ inflatedData = inflateSync(inflateData, {
1874
+ chunkSize: imageSize,
1875
+ maxLength: imageSize
1876
+ });
1877
+ }
1878
+ inflateData = null;
1879
+ if (!inflatedData || !inflatedData.length) {
1880
+ throw new Error("bad png - invalid inflate data response");
1881
+ }
1882
+ let unfilteredData = FilterSync.process(inflatedData, metaData);
1883
+ inflateData = null;
1884
+ let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
1885
+ unfilteredData = null;
1886
+ let normalisedBitmapData = formatNormaliser(
1887
+ bitmapData,
1888
+ metaData,
1889
+ options.skipRescale
1890
+ );
1891
+ metaData.data = normalisedBitmapData;
1892
+ metaData.gamma = gamma || 0;
1893
+ return metaData;
1894
+ };
1895
+ }
1896
+ });
1897
+
1898
+ // node_modules/pngjs/lib/packer-sync.js
1899
+ var require_packer_sync = __commonJS({
1900
+ "node_modules/pngjs/lib/packer-sync.js"(exports, module) {
1901
+ "use strict";
1902
+ var hasSyncZlib = true;
1903
+ var zlib = __require("zlib");
1904
+ if (!zlib.deflateSync) {
1905
+ hasSyncZlib = false;
1906
+ }
1907
+ var constants = require_constants();
1908
+ var Packer = require_packer();
1909
+ module.exports = function(metaData, opt) {
1910
+ if (!hasSyncZlib) {
1911
+ throw new Error(
1912
+ "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
1913
+ );
1914
+ }
1915
+ let options = opt || {};
1916
+ let packer = new Packer(options);
1917
+ let chunks = [];
1918
+ chunks.push(Buffer.from(constants.PNG_SIGNATURE));
1919
+ chunks.push(packer.packIHDR(metaData.width, metaData.height));
1920
+ if (metaData.gamma) {
1921
+ chunks.push(packer.packGAMA(metaData.gamma));
1922
+ }
1923
+ let filteredData = packer.filterData(
1924
+ metaData.data,
1925
+ metaData.width,
1926
+ metaData.height
1927
+ );
1928
+ let compressedData = zlib.deflateSync(
1929
+ filteredData,
1930
+ packer.getDeflateOptions()
1931
+ );
1932
+ filteredData = null;
1933
+ if (!compressedData || !compressedData.length) {
1934
+ throw new Error("bad png - invalid compressed data response");
1935
+ }
1936
+ chunks.push(packer.packIDAT(compressedData));
1937
+ chunks.push(packer.packIEND());
1938
+ return Buffer.concat(chunks);
1939
+ };
1940
+ }
1941
+ });
1942
+
1943
+ // node_modules/pngjs/lib/png-sync.js
1944
+ var require_png_sync = __commonJS({
1945
+ "node_modules/pngjs/lib/png-sync.js"(exports) {
1946
+ "use strict";
1947
+ var parse = require_parser_sync();
1948
+ var pack = require_packer_sync();
1949
+ exports.read = function(buffer, options) {
1950
+ return parse(buffer, options || {});
1951
+ };
1952
+ exports.write = function(png, options) {
1953
+ return pack(png, options);
1954
+ };
1955
+ }
1956
+ });
1957
+
1958
+ // node_modules/pngjs/lib/png.js
1959
+ var require_png = __commonJS({
1960
+ "node_modules/pngjs/lib/png.js"(exports) {
1961
+ var util = __require("util");
1962
+ var Stream = __require("stream");
1963
+ var Parser = require_parser_async();
1964
+ var Packer = require_packer_async();
1965
+ var PNGSync = require_png_sync();
1966
+ var PNG = exports.PNG = function(options) {
1967
+ Stream.call(this);
1968
+ options = options || {};
1969
+ this.width = options.width | 0;
1970
+ this.height = options.height | 0;
1971
+ this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
1972
+ if (options.fill && this.data) {
1973
+ this.data.fill(0);
1974
+ }
1975
+ this.gamma = 0;
1976
+ this.readable = this.writable = true;
1977
+ this._parser = new Parser(options);
1978
+ this._parser.on("error", this.emit.bind(this, "error"));
1979
+ this._parser.on("close", this._handleClose.bind(this));
1980
+ this._parser.on("metadata", this._metadata.bind(this));
1981
+ this._parser.on("gamma", this._gamma.bind(this));
1982
+ this._parser.on(
1983
+ "parsed",
1984
+ function(data) {
1985
+ this.data = data;
1986
+ this.emit("parsed", data);
1987
+ }.bind(this)
1988
+ );
1989
+ this._packer = new Packer(options);
1990
+ this._packer.on("data", this.emit.bind(this, "data"));
1991
+ this._packer.on("end", this.emit.bind(this, "end"));
1992
+ this._parser.on("close", this._handleClose.bind(this));
1993
+ this._packer.on("error", this.emit.bind(this, "error"));
1994
+ };
1995
+ util.inherits(PNG, Stream);
1996
+ PNG.sync = PNGSync;
1997
+ PNG.prototype.pack = function() {
1998
+ if (!this.data || !this.data.length) {
1999
+ this.emit("error", "No data provided");
2000
+ return this;
2001
+ }
2002
+ process.nextTick(
2003
+ function() {
2004
+ this._packer.pack(this.data, this.width, this.height, this.gamma);
2005
+ }.bind(this)
2006
+ );
2007
+ return this;
2008
+ };
2009
+ PNG.prototype.parse = function(data, callback) {
2010
+ if (callback) {
2011
+ let onParsed, onError;
2012
+ onParsed = function(parsedData) {
2013
+ this.removeListener("error", onError);
2014
+ this.data = parsedData;
2015
+ callback(null, this);
2016
+ }.bind(this);
2017
+ onError = function(err) {
2018
+ this.removeListener("parsed", onParsed);
2019
+ callback(err, null);
2020
+ }.bind(this);
2021
+ this.once("parsed", onParsed);
2022
+ this.once("error", onError);
2023
+ }
2024
+ this.end(data);
2025
+ return this;
2026
+ };
2027
+ PNG.prototype.write = function(data) {
2028
+ this._parser.write(data);
2029
+ return true;
2030
+ };
2031
+ PNG.prototype.end = function(data) {
2032
+ this._parser.end(data);
2033
+ };
2034
+ PNG.prototype._metadata = function(metadata) {
2035
+ this.width = metadata.width;
2036
+ this.height = metadata.height;
2037
+ this.emit("metadata", metadata);
2038
+ };
2039
+ PNG.prototype._gamma = function(gamma) {
2040
+ this.gamma = gamma;
2041
+ };
2042
+ PNG.prototype._handleClose = function() {
2043
+ if (!this._parser.writable && !this._packer.readable) {
2044
+ this.emit("close");
2045
+ }
2046
+ };
2047
+ PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
2048
+ srcX |= 0;
2049
+ srcY |= 0;
2050
+ width |= 0;
2051
+ height |= 0;
2052
+ deltaX |= 0;
2053
+ deltaY |= 0;
2054
+ if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
2055
+ throw new Error("bitblt reading outside image");
2056
+ }
2057
+ if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
2058
+ throw new Error("bitblt writing outside image");
2059
+ }
2060
+ for (let y = 0; y < height; y++) {
2061
+ src.data.copy(
2062
+ dst.data,
2063
+ (deltaY + y) * dst.width + deltaX << 2,
2064
+ (srcY + y) * src.width + srcX << 2,
2065
+ (srcY + y) * src.width + srcX + width << 2
2066
+ );
2067
+ }
2068
+ };
2069
+ PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
2070
+ PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
2071
+ return this;
2072
+ };
2073
+ PNG.adjustGamma = function(src) {
2074
+ if (src.gamma) {
2075
+ for (let y = 0; y < src.height; y++) {
2076
+ for (let x = 0; x < src.width; x++) {
2077
+ let idx = src.width * y + x << 2;
2078
+ for (let i = 0; i < 3; i++) {
2079
+ let sample = src.data[idx + i] / 255;
2080
+ sample = Math.pow(sample, 1 / 2.2 / src.gamma);
2081
+ src.data[idx + i] = Math.round(sample * 255);
2082
+ }
2083
+ }
2084
+ }
2085
+ src.gamma = 0;
2086
+ }
2087
+ };
2088
+ PNG.prototype.adjustGamma = function() {
2089
+ PNG.adjustGamma(this);
2090
+ };
2091
+ }
2092
+ });
2093
+ export default require_png();