@reshotdev/screenshot 0.0.1-beta.23 → 0.0.1-beta.25

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.
@@ -1,3880 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
-
33
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/chunkstream.js
34
- var require_chunkstream = __commonJS({
35
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/chunkstream.js"(exports2, module2) {
36
- "use strict";
37
- var util = require("util");
38
- var Stream = require("stream");
39
- var ChunkStream = module2.exports = function() {
40
- Stream.call(this);
41
- this._buffers = [];
42
- this._buffered = 0;
43
- this._reads = [];
44
- this._paused = false;
45
- this._encoding = "utf8";
46
- this.writable = true;
47
- };
48
- util.inherits(ChunkStream, Stream);
49
- ChunkStream.prototype.read = function(length, callback) {
50
- this._reads.push({
51
- length: Math.abs(length),
52
- // if length < 0 then at most this length
53
- allowLess: length < 0,
54
- func: callback
55
- });
56
- process.nextTick(
57
- function() {
58
- this._process();
59
- if (this._paused && this._reads && this._reads.length > 0) {
60
- this._paused = false;
61
- this.emit("drain");
62
- }
63
- }.bind(this)
64
- );
65
- };
66
- ChunkStream.prototype.write = function(data, encoding) {
67
- if (!this.writable) {
68
- this.emit("error", new Error("Stream not writable"));
69
- return false;
70
- }
71
- let dataBuffer;
72
- if (Buffer.isBuffer(data)) {
73
- dataBuffer = data;
74
- } else {
75
- dataBuffer = Buffer.from(data, encoding || this._encoding);
76
- }
77
- this._buffers.push(dataBuffer);
78
- this._buffered += dataBuffer.length;
79
- this._process();
80
- if (this._reads && this._reads.length === 0) {
81
- this._paused = true;
82
- }
83
- return this.writable && !this._paused;
84
- };
85
- ChunkStream.prototype.end = function(data, encoding) {
86
- if (data) {
87
- this.write(data, encoding);
88
- }
89
- this.writable = false;
90
- if (!this._buffers) {
91
- return;
92
- }
93
- if (this._buffers.length === 0) {
94
- this._end();
95
- } else {
96
- this._buffers.push(null);
97
- this._process();
98
- }
99
- };
100
- ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
101
- ChunkStream.prototype._end = function() {
102
- if (this._reads.length > 0) {
103
- this.emit("error", new Error("Unexpected end of input"));
104
- }
105
- this.destroy();
106
- };
107
- ChunkStream.prototype.destroy = function() {
108
- if (!this._buffers) {
109
- return;
110
- }
111
- this.writable = false;
112
- this._reads = null;
113
- this._buffers = null;
114
- this.emit("close");
115
- };
116
- ChunkStream.prototype._processReadAllowingLess = function(read) {
117
- this._reads.shift();
118
- let smallerBuf = this._buffers[0];
119
- if (smallerBuf.length > read.length) {
120
- this._buffered -= read.length;
121
- this._buffers[0] = smallerBuf.slice(read.length);
122
- read.func.call(this, smallerBuf.slice(0, read.length));
123
- } else {
124
- this._buffered -= smallerBuf.length;
125
- this._buffers.shift();
126
- read.func.call(this, smallerBuf);
127
- }
128
- };
129
- ChunkStream.prototype._processRead = function(read) {
130
- this._reads.shift();
131
- let pos = 0;
132
- let count = 0;
133
- let data = Buffer.alloc(read.length);
134
- while (pos < read.length) {
135
- let buf = this._buffers[count++];
136
- let len = Math.min(buf.length, read.length - pos);
137
- buf.copy(data, pos, 0, len);
138
- pos += len;
139
- if (len !== buf.length) {
140
- this._buffers[--count] = buf.slice(len);
141
- }
142
- }
143
- if (count > 0) {
144
- this._buffers.splice(0, count);
145
- }
146
- this._buffered -= read.length;
147
- read.func.call(this, data);
148
- };
149
- ChunkStream.prototype._process = function() {
150
- try {
151
- while (this._buffered > 0 && this._reads && this._reads.length > 0) {
152
- let read = this._reads[0];
153
- if (read.allowLess) {
154
- this._processReadAllowingLess(read);
155
- } else if (this._buffered >= read.length) {
156
- this._processRead(read);
157
- } else {
158
- break;
159
- }
160
- }
161
- if (this._buffers && !this.writable) {
162
- this._end();
163
- }
164
- } catch (ex) {
165
- this.emit("error", ex);
166
- }
167
- };
168
- }
169
- });
170
-
171
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/interlace.js
172
- var require_interlace = __commonJS({
173
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/interlace.js"(exports2) {
174
- "use strict";
175
- var imagePasses = [
176
- {
177
- // pass 1 - 1px
178
- x: [0],
179
- y: [0]
180
- },
181
- {
182
- // pass 2 - 1px
183
- x: [4],
184
- y: [0]
185
- },
186
- {
187
- // pass 3 - 2px
188
- x: [0, 4],
189
- y: [4]
190
- },
191
- {
192
- // pass 4 - 4px
193
- x: [2, 6],
194
- y: [0, 4]
195
- },
196
- {
197
- // pass 5 - 8px
198
- x: [0, 2, 4, 6],
199
- y: [2, 6]
200
- },
201
- {
202
- // pass 6 - 16px
203
- x: [1, 3, 5, 7],
204
- y: [0, 2, 4, 6]
205
- },
206
- {
207
- // pass 7 - 32px
208
- x: [0, 1, 2, 3, 4, 5, 6, 7],
209
- y: [1, 3, 5, 7]
210
- }
211
- ];
212
- exports2.getImagePasses = function(width, height) {
213
- let images = [];
214
- let xLeftOver = width % 8;
215
- let yLeftOver = height % 8;
216
- let xRepeats = (width - xLeftOver) / 8;
217
- let yRepeats = (height - yLeftOver) / 8;
218
- for (let i = 0; i < imagePasses.length; i++) {
219
- let pass = imagePasses[i];
220
- let passWidth = xRepeats * pass.x.length;
221
- let passHeight = yRepeats * pass.y.length;
222
- for (let j = 0; j < pass.x.length; j++) {
223
- if (pass.x[j] < xLeftOver) {
224
- passWidth++;
225
- } else {
226
- break;
227
- }
228
- }
229
- for (let j = 0; j < pass.y.length; j++) {
230
- if (pass.y[j] < yLeftOver) {
231
- passHeight++;
232
- } else {
233
- break;
234
- }
235
- }
236
- if (passWidth > 0 && passHeight > 0) {
237
- images.push({ width: passWidth, height: passHeight, index: i });
238
- }
239
- }
240
- return images;
241
- };
242
- exports2.getInterlaceIterator = function(width) {
243
- return function(x, y, pass) {
244
- let outerXLeftOver = x % imagePasses[pass].x.length;
245
- let outerX = (x - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
246
- let outerYLeftOver = y % imagePasses[pass].y.length;
247
- let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
248
- return outerX * 4 + outerY * width * 4;
249
- };
250
- };
251
- }
252
- });
253
-
254
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/paeth-predictor.js
255
- var require_paeth_predictor = __commonJS({
256
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/paeth-predictor.js"(exports2, module2) {
257
- "use strict";
258
- module2.exports = function paethPredictor(left, above, upLeft) {
259
- let paeth = left + above - upLeft;
260
- let pLeft = Math.abs(paeth - left);
261
- let pAbove = Math.abs(paeth - above);
262
- let pUpLeft = Math.abs(paeth - upLeft);
263
- if (pLeft <= pAbove && pLeft <= pUpLeft) {
264
- return left;
265
- }
266
- if (pAbove <= pUpLeft) {
267
- return above;
268
- }
269
- return upLeft;
270
- };
271
- }
272
- });
273
-
274
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-parse.js
275
- var require_filter_parse = __commonJS({
276
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-parse.js"(exports2, module2) {
277
- "use strict";
278
- var interlaceUtils = require_interlace();
279
- var paethPredictor = require_paeth_predictor();
280
- function getByteWidth(width, bpp, depth) {
281
- let byteWidth = width * bpp;
282
- if (depth !== 8) {
283
- byteWidth = Math.ceil(byteWidth / (8 / depth));
284
- }
285
- return byteWidth;
286
- }
287
- var Filter = module2.exports = function(bitmapInfo, dependencies) {
288
- let width = bitmapInfo.width;
289
- let height = bitmapInfo.height;
290
- let interlace = bitmapInfo.interlace;
291
- let bpp = bitmapInfo.bpp;
292
- let depth = bitmapInfo.depth;
293
- this.read = dependencies.read;
294
- this.write = dependencies.write;
295
- this.complete = dependencies.complete;
296
- this._imageIndex = 0;
297
- this._images = [];
298
- if (interlace) {
299
- let passes = interlaceUtils.getImagePasses(width, height);
300
- for (let i = 0; i < passes.length; i++) {
301
- this._images.push({
302
- byteWidth: getByteWidth(passes[i].width, bpp, depth),
303
- height: passes[i].height,
304
- lineIndex: 0
305
- });
306
- }
307
- } else {
308
- this._images.push({
309
- byteWidth: getByteWidth(width, bpp, depth),
310
- height,
311
- lineIndex: 0
312
- });
313
- }
314
- if (depth === 8) {
315
- this._xComparison = bpp;
316
- } else if (depth === 16) {
317
- this._xComparison = bpp * 2;
318
- } else {
319
- this._xComparison = 1;
320
- }
321
- };
322
- Filter.prototype.start = function() {
323
- this.read(
324
- this._images[this._imageIndex].byteWidth + 1,
325
- this._reverseFilterLine.bind(this)
326
- );
327
- };
328
- Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
329
- let xComparison = this._xComparison;
330
- let xBiggerThan = xComparison - 1;
331
- for (let x = 0; x < byteWidth; x++) {
332
- let rawByte = rawData[1 + x];
333
- let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
334
- unfilteredLine[x] = rawByte + f1Left;
335
- }
336
- };
337
- Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
338
- let lastLine = this._lastLine;
339
- for (let x = 0; x < byteWidth; x++) {
340
- let rawByte = rawData[1 + x];
341
- let f2Up = lastLine ? lastLine[x] : 0;
342
- unfilteredLine[x] = rawByte + f2Up;
343
- }
344
- };
345
- Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
346
- let xComparison = this._xComparison;
347
- let xBiggerThan = xComparison - 1;
348
- let lastLine = this._lastLine;
349
- for (let x = 0; x < byteWidth; x++) {
350
- let rawByte = rawData[1 + x];
351
- let f3Up = lastLine ? lastLine[x] : 0;
352
- let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
353
- let f3Add = Math.floor((f3Left + f3Up) / 2);
354
- unfilteredLine[x] = rawByte + f3Add;
355
- }
356
- };
357
- Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
358
- let xComparison = this._xComparison;
359
- let xBiggerThan = xComparison - 1;
360
- let lastLine = this._lastLine;
361
- for (let x = 0; x < byteWidth; x++) {
362
- let rawByte = rawData[1 + x];
363
- let f4Up = lastLine ? lastLine[x] : 0;
364
- let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
365
- let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
366
- let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
367
- unfilteredLine[x] = rawByte + f4Add;
368
- }
369
- };
370
- Filter.prototype._reverseFilterLine = function(rawData) {
371
- let filter = rawData[0];
372
- let unfilteredLine;
373
- let currentImage = this._images[this._imageIndex];
374
- let byteWidth = currentImage.byteWidth;
375
- if (filter === 0) {
376
- unfilteredLine = rawData.slice(1, byteWidth + 1);
377
- } else {
378
- unfilteredLine = Buffer.alloc(byteWidth);
379
- switch (filter) {
380
- case 1:
381
- this._unFilterType1(rawData, unfilteredLine, byteWidth);
382
- break;
383
- case 2:
384
- this._unFilterType2(rawData, unfilteredLine, byteWidth);
385
- break;
386
- case 3:
387
- this._unFilterType3(rawData, unfilteredLine, byteWidth);
388
- break;
389
- case 4:
390
- this._unFilterType4(rawData, unfilteredLine, byteWidth);
391
- break;
392
- default:
393
- throw new Error("Unrecognised filter type - " + filter);
394
- }
395
- }
396
- this.write(unfilteredLine);
397
- currentImage.lineIndex++;
398
- if (currentImage.lineIndex >= currentImage.height) {
399
- this._lastLine = null;
400
- this._imageIndex++;
401
- currentImage = this._images[this._imageIndex];
402
- } else {
403
- this._lastLine = unfilteredLine;
404
- }
405
- if (currentImage) {
406
- this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
407
- } else {
408
- this._lastLine = null;
409
- this.complete();
410
- }
411
- };
412
- }
413
- });
414
-
415
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-parse-async.js
416
- var require_filter_parse_async = __commonJS({
417
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-parse-async.js"(exports2, module2) {
418
- "use strict";
419
- var util = require("util");
420
- var ChunkStream = require_chunkstream();
421
- var Filter = require_filter_parse();
422
- var FilterAsync = module2.exports = function(bitmapInfo) {
423
- ChunkStream.call(this);
424
- let buffers = [];
425
- let that = this;
426
- this._filter = new Filter(bitmapInfo, {
427
- read: this.read.bind(this),
428
- write: function(buffer) {
429
- buffers.push(buffer);
430
- },
431
- complete: function() {
432
- that.emit("complete", Buffer.concat(buffers));
433
- }
434
- });
435
- this._filter.start();
436
- };
437
- util.inherits(FilterAsync, ChunkStream);
438
- }
439
- });
440
-
441
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/constants.js
442
- var require_constants = __commonJS({
443
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/constants.js"(exports2, module2) {
444
- "use strict";
445
- module2.exports = {
446
- PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
447
- TYPE_IHDR: 1229472850,
448
- TYPE_IEND: 1229278788,
449
- TYPE_IDAT: 1229209940,
450
- TYPE_PLTE: 1347179589,
451
- TYPE_tRNS: 1951551059,
452
- // eslint-disable-line camelcase
453
- TYPE_gAMA: 1732332865,
454
- // eslint-disable-line camelcase
455
- // color-type bits
456
- COLORTYPE_GRAYSCALE: 0,
457
- COLORTYPE_PALETTE: 1,
458
- COLORTYPE_COLOR: 2,
459
- COLORTYPE_ALPHA: 4,
460
- // e.g. grayscale and alpha
461
- // color-type combinations
462
- COLORTYPE_PALETTE_COLOR: 3,
463
- COLORTYPE_COLOR_ALPHA: 6,
464
- COLORTYPE_TO_BPP_MAP: {
465
- 0: 1,
466
- 2: 3,
467
- 3: 1,
468
- 4: 2,
469
- 6: 4
470
- },
471
- GAMMA_DIVISION: 1e5
472
- };
473
- }
474
- });
475
-
476
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/crc.js
477
- var require_crc = __commonJS({
478
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/crc.js"(exports2, module2) {
479
- "use strict";
480
- var crcTable = [];
481
- (function() {
482
- for (let i = 0; i < 256; i++) {
483
- let currentCrc = i;
484
- for (let j = 0; j < 8; j++) {
485
- if (currentCrc & 1) {
486
- currentCrc = 3988292384 ^ currentCrc >>> 1;
487
- } else {
488
- currentCrc = currentCrc >>> 1;
489
- }
490
- }
491
- crcTable[i] = currentCrc;
492
- }
493
- })();
494
- var CrcCalculator = module2.exports = function() {
495
- this._crc = -1;
496
- };
497
- CrcCalculator.prototype.write = function(data) {
498
- for (let i = 0; i < data.length; i++) {
499
- this._crc = crcTable[(this._crc ^ data[i]) & 255] ^ this._crc >>> 8;
500
- }
501
- return true;
502
- };
503
- CrcCalculator.prototype.crc32 = function() {
504
- return this._crc ^ -1;
505
- };
506
- CrcCalculator.crc32 = function(buf) {
507
- let crc = -1;
508
- for (let i = 0; i < buf.length; i++) {
509
- crc = crcTable[(crc ^ buf[i]) & 255] ^ crc >>> 8;
510
- }
511
- return crc ^ -1;
512
- };
513
- }
514
- });
515
-
516
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/parser.js
517
- var require_parser = __commonJS({
518
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/parser.js"(exports2, module2) {
519
- "use strict";
520
- var constants = require_constants();
521
- var CrcCalculator = require_crc();
522
- var Parser = module2.exports = function(options, dependencies) {
523
- this._options = options;
524
- options.checkCRC = options.checkCRC !== false;
525
- this._hasIHDR = false;
526
- this._hasIEND = false;
527
- this._emittedHeadersFinished = false;
528
- this._palette = [];
529
- this._colorType = 0;
530
- this._chunks = {};
531
- this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
532
- this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
533
- this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
534
- this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
535
- this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
536
- this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
537
- this.read = dependencies.read;
538
- this.error = dependencies.error;
539
- this.metadata = dependencies.metadata;
540
- this.gamma = dependencies.gamma;
541
- this.transColor = dependencies.transColor;
542
- this.palette = dependencies.palette;
543
- this.parsed = dependencies.parsed;
544
- this.inflateData = dependencies.inflateData;
545
- this.finished = dependencies.finished;
546
- this.simpleTransparency = dependencies.simpleTransparency;
547
- this.headersFinished = dependencies.headersFinished || function() {
548
- };
549
- };
550
- Parser.prototype.start = function() {
551
- this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
552
- };
553
- Parser.prototype._parseSignature = function(data) {
554
- let signature = constants.PNG_SIGNATURE;
555
- for (let i = 0; i < signature.length; i++) {
556
- if (data[i] !== signature[i]) {
557
- this.error(new Error("Invalid file signature"));
558
- return;
559
- }
560
- }
561
- this.read(8, this._parseChunkBegin.bind(this));
562
- };
563
- Parser.prototype._parseChunkBegin = function(data) {
564
- let length = data.readUInt32BE(0);
565
- let type = data.readUInt32BE(4);
566
- let name = "";
567
- for (let i = 4; i < 8; i++) {
568
- name += String.fromCharCode(data[i]);
569
- }
570
- let ancillary = Boolean(data[4] & 32);
571
- if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
572
- this.error(new Error("Expected IHDR on beggining"));
573
- return;
574
- }
575
- this._crc = new CrcCalculator();
576
- this._crc.write(Buffer.from(name));
577
- if (this._chunks[type]) {
578
- return this._chunks[type](length);
579
- }
580
- if (!ancillary) {
581
- this.error(new Error("Unsupported critical chunk type " + name));
582
- return;
583
- }
584
- this.read(length + 4, this._skipChunk.bind(this));
585
- };
586
- Parser.prototype._skipChunk = function() {
587
- this.read(8, this._parseChunkBegin.bind(this));
588
- };
589
- Parser.prototype._handleChunkEnd = function() {
590
- this.read(4, this._parseChunkEnd.bind(this));
591
- };
592
- Parser.prototype._parseChunkEnd = function(data) {
593
- let fileCrc = data.readInt32BE(0);
594
- let calcCrc = this._crc.crc32();
595
- if (this._options.checkCRC && calcCrc !== fileCrc) {
596
- this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
597
- return;
598
- }
599
- if (!this._hasIEND) {
600
- this.read(8, this._parseChunkBegin.bind(this));
601
- }
602
- };
603
- Parser.prototype._handleIHDR = function(length) {
604
- this.read(length, this._parseIHDR.bind(this));
605
- };
606
- Parser.prototype._parseIHDR = function(data) {
607
- this._crc.write(data);
608
- let width = data.readUInt32BE(0);
609
- let height = data.readUInt32BE(4);
610
- let depth = data[8];
611
- let colorType = data[9];
612
- let compr = data[10];
613
- let filter = data[11];
614
- let interlace = data[12];
615
- if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
616
- this.error(new Error("Unsupported bit depth " + depth));
617
- return;
618
- }
619
- if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
620
- this.error(new Error("Unsupported color type"));
621
- return;
622
- }
623
- if (compr !== 0) {
624
- this.error(new Error("Unsupported compression method"));
625
- return;
626
- }
627
- if (filter !== 0) {
628
- this.error(new Error("Unsupported filter method"));
629
- return;
630
- }
631
- if (interlace !== 0 && interlace !== 1) {
632
- this.error(new Error("Unsupported interlace method"));
633
- return;
634
- }
635
- this._colorType = colorType;
636
- let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
637
- this._hasIHDR = true;
638
- this.metadata({
639
- width,
640
- height,
641
- depth,
642
- interlace: Boolean(interlace),
643
- palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
644
- color: Boolean(colorType & constants.COLORTYPE_COLOR),
645
- alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
646
- bpp,
647
- colorType
648
- });
649
- this._handleChunkEnd();
650
- };
651
- Parser.prototype._handlePLTE = function(length) {
652
- this.read(length, this._parsePLTE.bind(this));
653
- };
654
- Parser.prototype._parsePLTE = function(data) {
655
- this._crc.write(data);
656
- let entries = Math.floor(data.length / 3);
657
- for (let i = 0; i < entries; i++) {
658
- this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 255]);
659
- }
660
- this.palette(this._palette);
661
- this._handleChunkEnd();
662
- };
663
- Parser.prototype._handleTRNS = function(length) {
664
- this.simpleTransparency();
665
- this.read(length, this._parseTRNS.bind(this));
666
- };
667
- Parser.prototype._parseTRNS = function(data) {
668
- this._crc.write(data);
669
- if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
670
- if (this._palette.length === 0) {
671
- this.error(new Error("Transparency chunk must be after palette"));
672
- return;
673
- }
674
- if (data.length > this._palette.length) {
675
- this.error(new Error("More transparent colors than palette size"));
676
- return;
677
- }
678
- for (let i = 0; i < data.length; i++) {
679
- this._palette[i][3] = data[i];
680
- }
681
- this.palette(this._palette);
682
- }
683
- if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
684
- this.transColor([data.readUInt16BE(0)]);
685
- }
686
- if (this._colorType === constants.COLORTYPE_COLOR) {
687
- this.transColor([
688
- data.readUInt16BE(0),
689
- data.readUInt16BE(2),
690
- data.readUInt16BE(4)
691
- ]);
692
- }
693
- this._handleChunkEnd();
694
- };
695
- Parser.prototype._handleGAMA = function(length) {
696
- this.read(length, this._parseGAMA.bind(this));
697
- };
698
- Parser.prototype._parseGAMA = function(data) {
699
- this._crc.write(data);
700
- this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
701
- this._handleChunkEnd();
702
- };
703
- Parser.prototype._handleIDAT = function(length) {
704
- if (!this._emittedHeadersFinished) {
705
- this._emittedHeadersFinished = true;
706
- this.headersFinished();
707
- }
708
- this.read(-length, this._parseIDAT.bind(this, length));
709
- };
710
- Parser.prototype._parseIDAT = function(length, data) {
711
- this._crc.write(data);
712
- if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
713
- throw new Error("Expected palette not found");
714
- }
715
- this.inflateData(data);
716
- let leftOverLength = length - data.length;
717
- if (leftOverLength > 0) {
718
- this._handleIDAT(leftOverLength);
719
- } else {
720
- this._handleChunkEnd();
721
- }
722
- };
723
- Parser.prototype._handleIEND = function(length) {
724
- this.read(length, this._parseIEND.bind(this));
725
- };
726
- Parser.prototype._parseIEND = function(data) {
727
- this._crc.write(data);
728
- this._hasIEND = true;
729
- this._handleChunkEnd();
730
- if (this.finished) {
731
- this.finished();
732
- }
733
- };
734
- }
735
- });
736
-
737
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/bitmapper.js
738
- var require_bitmapper = __commonJS({
739
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/bitmapper.js"(exports2) {
740
- "use strict";
741
- var interlaceUtils = require_interlace();
742
- var pixelBppMapper = [
743
- // 0 - dummy entry
744
- function() {
745
- },
746
- // 1 - L
747
- // 0: 0, 1: 0, 2: 0, 3: 0xff
748
- function(pxData, data, pxPos, rawPos) {
749
- if (rawPos === data.length) {
750
- throw new Error("Ran out of data");
751
- }
752
- let pixel = data[rawPos];
753
- pxData[pxPos] = pixel;
754
- pxData[pxPos + 1] = pixel;
755
- pxData[pxPos + 2] = pixel;
756
- pxData[pxPos + 3] = 255;
757
- },
758
- // 2 - LA
759
- // 0: 0, 1: 0, 2: 0, 3: 1
760
- function(pxData, data, pxPos, rawPos) {
761
- if (rawPos + 1 >= data.length) {
762
- throw new Error("Ran out of data");
763
- }
764
- let pixel = data[rawPos];
765
- pxData[pxPos] = pixel;
766
- pxData[pxPos + 1] = pixel;
767
- pxData[pxPos + 2] = pixel;
768
- pxData[pxPos + 3] = data[rawPos + 1];
769
- },
770
- // 3 - RGB
771
- // 0: 0, 1: 1, 2: 2, 3: 0xff
772
- function(pxData, data, pxPos, rawPos) {
773
- if (rawPos + 2 >= data.length) {
774
- throw new Error("Ran out of data");
775
- }
776
- pxData[pxPos] = data[rawPos];
777
- pxData[pxPos + 1] = data[rawPos + 1];
778
- pxData[pxPos + 2] = data[rawPos + 2];
779
- pxData[pxPos + 3] = 255;
780
- },
781
- // 4 - RGBA
782
- // 0: 0, 1: 1, 2: 2, 3: 3
783
- function(pxData, data, pxPos, rawPos) {
784
- if (rawPos + 3 >= data.length) {
785
- throw new Error("Ran out of data");
786
- }
787
- pxData[pxPos] = data[rawPos];
788
- pxData[pxPos + 1] = data[rawPos + 1];
789
- pxData[pxPos + 2] = data[rawPos + 2];
790
- pxData[pxPos + 3] = data[rawPos + 3];
791
- }
792
- ];
793
- var pixelBppCustomMapper = [
794
- // 0 - dummy entry
795
- function() {
796
- },
797
- // 1 - L
798
- // 0: 0, 1: 0, 2: 0, 3: 0xff
799
- function(pxData, pixelData, pxPos, maxBit) {
800
- let pixel = pixelData[0];
801
- pxData[pxPos] = pixel;
802
- pxData[pxPos + 1] = pixel;
803
- pxData[pxPos + 2] = pixel;
804
- pxData[pxPos + 3] = maxBit;
805
- },
806
- // 2 - LA
807
- // 0: 0, 1: 0, 2: 0, 3: 1
808
- function(pxData, pixelData, pxPos) {
809
- let pixel = pixelData[0];
810
- pxData[pxPos] = pixel;
811
- pxData[pxPos + 1] = pixel;
812
- pxData[pxPos + 2] = pixel;
813
- pxData[pxPos + 3] = pixelData[1];
814
- },
815
- // 3 - RGB
816
- // 0: 0, 1: 1, 2: 2, 3: 0xff
817
- function(pxData, pixelData, pxPos, maxBit) {
818
- pxData[pxPos] = pixelData[0];
819
- pxData[pxPos + 1] = pixelData[1];
820
- pxData[pxPos + 2] = pixelData[2];
821
- pxData[pxPos + 3] = maxBit;
822
- },
823
- // 4 - RGBA
824
- // 0: 0, 1: 1, 2: 2, 3: 3
825
- function(pxData, pixelData, pxPos) {
826
- pxData[pxPos] = pixelData[0];
827
- pxData[pxPos + 1] = pixelData[1];
828
- pxData[pxPos + 2] = pixelData[2];
829
- pxData[pxPos + 3] = pixelData[3];
830
- }
831
- ];
832
- function bitRetriever(data, depth) {
833
- let leftOver = [];
834
- let i = 0;
835
- function split() {
836
- if (i === data.length) {
837
- throw new Error("Ran out of data");
838
- }
839
- let byte = data[i];
840
- i++;
841
- let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
842
- switch (depth) {
843
- default:
844
- throw new Error("unrecognised depth");
845
- case 16:
846
- byte2 = data[i];
847
- i++;
848
- leftOver.push((byte << 8) + byte2);
849
- break;
850
- case 4:
851
- byte2 = byte & 15;
852
- byte1 = byte >> 4;
853
- leftOver.push(byte1, byte2);
854
- break;
855
- case 2:
856
- byte4 = byte & 3;
857
- byte3 = byte >> 2 & 3;
858
- byte2 = byte >> 4 & 3;
859
- byte1 = byte >> 6 & 3;
860
- leftOver.push(byte1, byte2, byte3, byte4);
861
- break;
862
- case 1:
863
- byte8 = byte & 1;
864
- byte7 = byte >> 1 & 1;
865
- byte6 = byte >> 2 & 1;
866
- byte5 = byte >> 3 & 1;
867
- byte4 = byte >> 4 & 1;
868
- byte3 = byte >> 5 & 1;
869
- byte2 = byte >> 6 & 1;
870
- byte1 = byte >> 7 & 1;
871
- leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
872
- break;
873
- }
874
- }
875
- return {
876
- get: function(count) {
877
- while (leftOver.length < count) {
878
- split();
879
- }
880
- let returner = leftOver.slice(0, count);
881
- leftOver = leftOver.slice(count);
882
- return returner;
883
- },
884
- resetAfterLine: function() {
885
- leftOver.length = 0;
886
- },
887
- end: function() {
888
- if (i !== data.length) {
889
- throw new Error("extra data found");
890
- }
891
- }
892
- };
893
- }
894
- function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
895
- let imageWidth = image.width;
896
- let imageHeight = image.height;
897
- let imagePass = image.index;
898
- for (let y = 0; y < imageHeight; y++) {
899
- for (let x = 0; x < imageWidth; x++) {
900
- let pxPos = getPxPos(x, y, imagePass);
901
- pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
902
- rawPos += bpp;
903
- }
904
- }
905
- return rawPos;
906
- }
907
- function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
908
- let imageWidth = image.width;
909
- let imageHeight = image.height;
910
- let imagePass = image.index;
911
- for (let y = 0; y < imageHeight; y++) {
912
- for (let x = 0; x < imageWidth; x++) {
913
- let pixelData = bits.get(bpp);
914
- let pxPos = getPxPos(x, y, imagePass);
915
- pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
916
- }
917
- bits.resetAfterLine();
918
- }
919
- }
920
- exports2.dataToBitMap = function(data, bitmapInfo) {
921
- let width = bitmapInfo.width;
922
- let height = bitmapInfo.height;
923
- let depth = bitmapInfo.depth;
924
- let bpp = bitmapInfo.bpp;
925
- let interlace = bitmapInfo.interlace;
926
- let bits;
927
- if (depth !== 8) {
928
- bits = bitRetriever(data, depth);
929
- }
930
- let pxData;
931
- if (depth <= 8) {
932
- pxData = Buffer.alloc(width * height * 4);
933
- } else {
934
- pxData = new Uint16Array(width * height * 4);
935
- }
936
- let maxBit = Math.pow(2, depth) - 1;
937
- let rawPos = 0;
938
- let images;
939
- let getPxPos;
940
- if (interlace) {
941
- images = interlaceUtils.getImagePasses(width, height);
942
- getPxPos = interlaceUtils.getInterlaceIterator(width, height);
943
- } else {
944
- let nonInterlacedPxPos = 0;
945
- getPxPos = function() {
946
- let returner = nonInterlacedPxPos;
947
- nonInterlacedPxPos += 4;
948
- return returner;
949
- };
950
- images = [{ width, height }];
951
- }
952
- for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
953
- if (depth === 8) {
954
- rawPos = mapImage8Bit(
955
- images[imageIndex],
956
- pxData,
957
- getPxPos,
958
- bpp,
959
- data,
960
- rawPos
961
- );
962
- } else {
963
- mapImageCustomBit(
964
- images[imageIndex],
965
- pxData,
966
- getPxPos,
967
- bpp,
968
- bits,
969
- maxBit
970
- );
971
- }
972
- }
973
- if (depth === 8) {
974
- if (rawPos !== data.length) {
975
- throw new Error("extra data found");
976
- }
977
- } else {
978
- bits.end();
979
- }
980
- return pxData;
981
- };
982
- }
983
- });
984
-
985
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/format-normaliser.js
986
- var require_format_normaliser = __commonJS({
987
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/format-normaliser.js"(exports2, module2) {
988
- "use strict";
989
- function dePalette(indata, outdata, width, height, palette) {
990
- let pxPos = 0;
991
- for (let y = 0; y < height; y++) {
992
- for (let x = 0; x < width; x++) {
993
- let color = palette[indata[pxPos]];
994
- if (!color) {
995
- throw new Error("index " + indata[pxPos] + " not in palette");
996
- }
997
- for (let i = 0; i < 4; i++) {
998
- outdata[pxPos + i] = color[i];
999
- }
1000
- pxPos += 4;
1001
- }
1002
- }
1003
- }
1004
- function replaceTransparentColor(indata, outdata, width, height, transColor) {
1005
- let pxPos = 0;
1006
- for (let y = 0; y < height; y++) {
1007
- for (let x = 0; x < width; x++) {
1008
- let makeTrans = false;
1009
- if (transColor.length === 1) {
1010
- if (transColor[0] === indata[pxPos]) {
1011
- makeTrans = true;
1012
- }
1013
- } else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
1014
- makeTrans = true;
1015
- }
1016
- if (makeTrans) {
1017
- for (let i = 0; i < 4; i++) {
1018
- outdata[pxPos + i] = 0;
1019
- }
1020
- }
1021
- pxPos += 4;
1022
- }
1023
- }
1024
- }
1025
- function scaleDepth(indata, outdata, width, height, depth) {
1026
- let maxOutSample = 255;
1027
- let maxInSample = Math.pow(2, depth) - 1;
1028
- let pxPos = 0;
1029
- for (let y = 0; y < height; y++) {
1030
- for (let x = 0; x < width; x++) {
1031
- for (let i = 0; i < 4; i++) {
1032
- outdata[pxPos + i] = Math.floor(
1033
- indata[pxPos + i] * maxOutSample / maxInSample + 0.5
1034
- );
1035
- }
1036
- pxPos += 4;
1037
- }
1038
- }
1039
- }
1040
- module2.exports = function(indata, imageData, skipRescale = false) {
1041
- let depth = imageData.depth;
1042
- let width = imageData.width;
1043
- let height = imageData.height;
1044
- let colorType = imageData.colorType;
1045
- let transColor = imageData.transColor;
1046
- let palette = imageData.palette;
1047
- let outdata = indata;
1048
- if (colorType === 3) {
1049
- dePalette(indata, outdata, width, height, palette);
1050
- } else {
1051
- if (transColor) {
1052
- replaceTransparentColor(indata, outdata, width, height, transColor);
1053
- }
1054
- if (depth !== 8 && !skipRescale) {
1055
- if (depth === 16) {
1056
- outdata = Buffer.alloc(width * height * 4);
1057
- }
1058
- scaleDepth(indata, outdata, width, height, depth);
1059
- }
1060
- }
1061
- return outdata;
1062
- };
1063
- }
1064
- });
1065
-
1066
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/parser-async.js
1067
- var require_parser_async = __commonJS({
1068
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/parser-async.js"(exports2, module2) {
1069
- "use strict";
1070
- var util = require("util");
1071
- var zlib = require("zlib");
1072
- var ChunkStream = require_chunkstream();
1073
- var FilterAsync = require_filter_parse_async();
1074
- var Parser = require_parser();
1075
- var bitmapper = require_bitmapper();
1076
- var formatNormaliser = require_format_normaliser();
1077
- var ParserAsync = module2.exports = function(options) {
1078
- ChunkStream.call(this);
1079
- this._parser = new Parser(options, {
1080
- read: this.read.bind(this),
1081
- error: this._handleError.bind(this),
1082
- metadata: this._handleMetaData.bind(this),
1083
- gamma: this.emit.bind(this, "gamma"),
1084
- palette: this._handlePalette.bind(this),
1085
- transColor: this._handleTransColor.bind(this),
1086
- finished: this._finished.bind(this),
1087
- inflateData: this._inflateData.bind(this),
1088
- simpleTransparency: this._simpleTransparency.bind(this),
1089
- headersFinished: this._headersFinished.bind(this)
1090
- });
1091
- this._options = options;
1092
- this.writable = true;
1093
- this._parser.start();
1094
- };
1095
- util.inherits(ParserAsync, ChunkStream);
1096
- ParserAsync.prototype._handleError = function(err) {
1097
- this.emit("error", err);
1098
- this.writable = false;
1099
- this.destroy();
1100
- if (this._inflate && this._inflate.destroy) {
1101
- this._inflate.destroy();
1102
- }
1103
- if (this._filter) {
1104
- this._filter.destroy();
1105
- this._filter.on("error", function() {
1106
- });
1107
- }
1108
- this.errord = true;
1109
- };
1110
- ParserAsync.prototype._inflateData = function(data) {
1111
- if (!this._inflate) {
1112
- if (this._bitmapInfo.interlace) {
1113
- this._inflate = zlib.createInflate();
1114
- this._inflate.on("error", this.emit.bind(this, "error"));
1115
- this._filter.on("complete", this._complete.bind(this));
1116
- this._inflate.pipe(this._filter);
1117
- } else {
1118
- let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
1119
- let imageSize = rowSize * this._bitmapInfo.height;
1120
- let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
1121
- this._inflate = zlib.createInflate({ chunkSize });
1122
- let leftToInflate = imageSize;
1123
- let emitError = this.emit.bind(this, "error");
1124
- this._inflate.on("error", function(err) {
1125
- if (!leftToInflate) {
1126
- return;
1127
- }
1128
- emitError(err);
1129
- });
1130
- this._filter.on("complete", this._complete.bind(this));
1131
- let filterWrite = this._filter.write.bind(this._filter);
1132
- this._inflate.on("data", function(chunk) {
1133
- if (!leftToInflate) {
1134
- return;
1135
- }
1136
- if (chunk.length > leftToInflate) {
1137
- chunk = chunk.slice(0, leftToInflate);
1138
- }
1139
- leftToInflate -= chunk.length;
1140
- filterWrite(chunk);
1141
- });
1142
- this._inflate.on("end", this._filter.end.bind(this._filter));
1143
- }
1144
- }
1145
- this._inflate.write(data);
1146
- };
1147
- ParserAsync.prototype._handleMetaData = function(metaData) {
1148
- this._metaData = metaData;
1149
- this._bitmapInfo = Object.create(metaData);
1150
- this._filter = new FilterAsync(this._bitmapInfo);
1151
- };
1152
- ParserAsync.prototype._handleTransColor = function(transColor) {
1153
- this._bitmapInfo.transColor = transColor;
1154
- };
1155
- ParserAsync.prototype._handlePalette = function(palette) {
1156
- this._bitmapInfo.palette = palette;
1157
- };
1158
- ParserAsync.prototype._simpleTransparency = function() {
1159
- this._metaData.alpha = true;
1160
- };
1161
- ParserAsync.prototype._headersFinished = function() {
1162
- this.emit("metadata", this._metaData);
1163
- };
1164
- ParserAsync.prototype._finished = function() {
1165
- if (this.errord) {
1166
- return;
1167
- }
1168
- if (!this._inflate) {
1169
- this.emit("error", "No Inflate block");
1170
- } else {
1171
- this._inflate.end();
1172
- }
1173
- };
1174
- ParserAsync.prototype._complete = function(filteredData) {
1175
- if (this.errord) {
1176
- return;
1177
- }
1178
- let normalisedBitmapData;
1179
- try {
1180
- let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
1181
- normalisedBitmapData = formatNormaliser(
1182
- bitmapData,
1183
- this._bitmapInfo,
1184
- this._options.skipRescale
1185
- );
1186
- bitmapData = null;
1187
- } catch (ex) {
1188
- this._handleError(ex);
1189
- return;
1190
- }
1191
- this.emit("parsed", normalisedBitmapData);
1192
- };
1193
- }
1194
- });
1195
-
1196
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/bitpacker.js
1197
- var require_bitpacker = __commonJS({
1198
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/bitpacker.js"(exports2, module2) {
1199
- "use strict";
1200
- var constants = require_constants();
1201
- module2.exports = function(dataIn, width, height, options) {
1202
- let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(
1203
- options.colorType
1204
- ) !== -1;
1205
- if (options.colorType === options.inputColorType) {
1206
- let bigEndian = (function() {
1207
- let buffer = new ArrayBuffer(2);
1208
- new DataView(buffer).setInt16(
1209
- 0,
1210
- 256,
1211
- true
1212
- /* littleEndian */
1213
- );
1214
- return new Int16Array(buffer)[0] !== 256;
1215
- })();
1216
- if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
1217
- return dataIn;
1218
- }
1219
- }
1220
- let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
1221
- let maxValue = 255;
1222
- let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
1223
- if (inBpp === 4 && !options.inputHasAlpha) {
1224
- inBpp = 3;
1225
- }
1226
- let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
1227
- if (options.bitDepth === 16) {
1228
- maxValue = 65535;
1229
- outBpp *= 2;
1230
- }
1231
- let outData = Buffer.alloc(width * height * outBpp);
1232
- let inIndex = 0;
1233
- let outIndex = 0;
1234
- let bgColor = options.bgColor || {};
1235
- if (bgColor.red === void 0) {
1236
- bgColor.red = maxValue;
1237
- }
1238
- if (bgColor.green === void 0) {
1239
- bgColor.green = maxValue;
1240
- }
1241
- if (bgColor.blue === void 0) {
1242
- bgColor.blue = maxValue;
1243
- }
1244
- function getRGBA() {
1245
- let red;
1246
- let green;
1247
- let blue;
1248
- let alpha = maxValue;
1249
- switch (options.inputColorType) {
1250
- case constants.COLORTYPE_COLOR_ALPHA:
1251
- alpha = data[inIndex + 3];
1252
- red = data[inIndex];
1253
- green = data[inIndex + 1];
1254
- blue = data[inIndex + 2];
1255
- break;
1256
- case constants.COLORTYPE_COLOR:
1257
- red = data[inIndex];
1258
- green = data[inIndex + 1];
1259
- blue = data[inIndex + 2];
1260
- break;
1261
- case constants.COLORTYPE_ALPHA:
1262
- alpha = data[inIndex + 1];
1263
- red = data[inIndex];
1264
- green = red;
1265
- blue = red;
1266
- break;
1267
- case constants.COLORTYPE_GRAYSCALE:
1268
- red = data[inIndex];
1269
- green = red;
1270
- blue = red;
1271
- break;
1272
- default:
1273
- throw new Error(
1274
- "input color type:" + options.inputColorType + " is not supported at present"
1275
- );
1276
- }
1277
- if (options.inputHasAlpha) {
1278
- if (!outHasAlpha) {
1279
- alpha /= maxValue;
1280
- red = Math.min(
1281
- Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
1282
- maxValue
1283
- );
1284
- green = Math.min(
1285
- Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
1286
- maxValue
1287
- );
1288
- blue = Math.min(
1289
- Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
1290
- maxValue
1291
- );
1292
- }
1293
- }
1294
- return { red, green, blue, alpha };
1295
- }
1296
- for (let y = 0; y < height; y++) {
1297
- for (let x = 0; x < width; x++) {
1298
- let rgba = getRGBA(data, inIndex);
1299
- switch (options.colorType) {
1300
- case constants.COLORTYPE_COLOR_ALPHA:
1301
- case constants.COLORTYPE_COLOR:
1302
- if (options.bitDepth === 8) {
1303
- outData[outIndex] = rgba.red;
1304
- outData[outIndex + 1] = rgba.green;
1305
- outData[outIndex + 2] = rgba.blue;
1306
- if (outHasAlpha) {
1307
- outData[outIndex + 3] = rgba.alpha;
1308
- }
1309
- } else {
1310
- outData.writeUInt16BE(rgba.red, outIndex);
1311
- outData.writeUInt16BE(rgba.green, outIndex + 2);
1312
- outData.writeUInt16BE(rgba.blue, outIndex + 4);
1313
- if (outHasAlpha) {
1314
- outData.writeUInt16BE(rgba.alpha, outIndex + 6);
1315
- }
1316
- }
1317
- break;
1318
- case constants.COLORTYPE_ALPHA:
1319
- case constants.COLORTYPE_GRAYSCALE: {
1320
- let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
1321
- if (options.bitDepth === 8) {
1322
- outData[outIndex] = grayscale;
1323
- if (outHasAlpha) {
1324
- outData[outIndex + 1] = rgba.alpha;
1325
- }
1326
- } else {
1327
- outData.writeUInt16BE(grayscale, outIndex);
1328
- if (outHasAlpha) {
1329
- outData.writeUInt16BE(rgba.alpha, outIndex + 2);
1330
- }
1331
- }
1332
- break;
1333
- }
1334
- default:
1335
- throw new Error("unrecognised color Type " + options.colorType);
1336
- }
1337
- inIndex += inBpp;
1338
- outIndex += outBpp;
1339
- }
1340
- }
1341
- return outData;
1342
- };
1343
- }
1344
- });
1345
-
1346
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-pack.js
1347
- var require_filter_pack = __commonJS({
1348
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-pack.js"(exports2, module2) {
1349
- "use strict";
1350
- var paethPredictor = require_paeth_predictor();
1351
- function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
1352
- for (let x = 0; x < byteWidth; x++) {
1353
- rawData[rawPos + x] = pxData[pxPos + x];
1354
- }
1355
- }
1356
- function filterSumNone(pxData, pxPos, byteWidth) {
1357
- let sum = 0;
1358
- let length = pxPos + byteWidth;
1359
- for (let i = pxPos; i < length; i++) {
1360
- sum += Math.abs(pxData[i]);
1361
- }
1362
- return sum;
1363
- }
1364
- function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1365
- for (let x = 0; x < byteWidth; x++) {
1366
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1367
- let val = pxData[pxPos + x] - left;
1368
- rawData[rawPos + x] = val;
1369
- }
1370
- }
1371
- function filterSumSub(pxData, pxPos, byteWidth, bpp) {
1372
- let sum = 0;
1373
- for (let x = 0; x < byteWidth; x++) {
1374
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1375
- let val = pxData[pxPos + x] - left;
1376
- sum += Math.abs(val);
1377
- }
1378
- return sum;
1379
- }
1380
- function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
1381
- for (let x = 0; x < byteWidth; x++) {
1382
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1383
- let val = pxData[pxPos + x] - up;
1384
- rawData[rawPos + x] = val;
1385
- }
1386
- }
1387
- function filterSumUp(pxData, pxPos, byteWidth) {
1388
- let sum = 0;
1389
- let length = pxPos + byteWidth;
1390
- for (let x = pxPos; x < length; x++) {
1391
- let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
1392
- let val = pxData[x] - up;
1393
- sum += Math.abs(val);
1394
- }
1395
- return sum;
1396
- }
1397
- function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1398
- for (let x = 0; x < byteWidth; x++) {
1399
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1400
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1401
- let val = pxData[pxPos + x] - (left + up >> 1);
1402
- rawData[rawPos + x] = val;
1403
- }
1404
- }
1405
- function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
1406
- let sum = 0;
1407
- for (let x = 0; x < byteWidth; x++) {
1408
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1409
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1410
- let val = pxData[pxPos + x] - (left + up >> 1);
1411
- sum += Math.abs(val);
1412
- }
1413
- return sum;
1414
- }
1415
- function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1416
- for (let x = 0; x < byteWidth; x++) {
1417
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1418
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1419
- let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1420
- let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1421
- rawData[rawPos + x] = val;
1422
- }
1423
- }
1424
- function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
1425
- let sum = 0;
1426
- for (let x = 0; x < byteWidth; x++) {
1427
- let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1428
- let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1429
- let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1430
- let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1431
- sum += Math.abs(val);
1432
- }
1433
- return sum;
1434
- }
1435
- var filters = {
1436
- 0: filterNone,
1437
- 1: filterSub,
1438
- 2: filterUp,
1439
- 3: filterAvg,
1440
- 4: filterPaeth
1441
- };
1442
- var filterSums = {
1443
- 0: filterSumNone,
1444
- 1: filterSumSub,
1445
- 2: filterSumUp,
1446
- 3: filterSumAvg,
1447
- 4: filterSumPaeth
1448
- };
1449
- module2.exports = function(pxData, width, height, options, bpp) {
1450
- let filterTypes;
1451
- if (!("filterType" in options) || options.filterType === -1) {
1452
- filterTypes = [0, 1, 2, 3, 4];
1453
- } else if (typeof options.filterType === "number") {
1454
- filterTypes = [options.filterType];
1455
- } else {
1456
- throw new Error("unrecognised filter types");
1457
- }
1458
- if (options.bitDepth === 16) {
1459
- bpp *= 2;
1460
- }
1461
- let byteWidth = width * bpp;
1462
- let rawPos = 0;
1463
- let pxPos = 0;
1464
- let rawData = Buffer.alloc((byteWidth + 1) * height);
1465
- let sel = filterTypes[0];
1466
- for (let y = 0; y < height; y++) {
1467
- if (filterTypes.length > 1) {
1468
- let min = Infinity;
1469
- for (let i = 0; i < filterTypes.length; i++) {
1470
- let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
1471
- if (sum < min) {
1472
- sel = filterTypes[i];
1473
- min = sum;
1474
- }
1475
- }
1476
- }
1477
- rawData[rawPos] = sel;
1478
- rawPos++;
1479
- filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
1480
- rawPos += byteWidth;
1481
- pxPos += byteWidth;
1482
- }
1483
- return rawData;
1484
- };
1485
- }
1486
- });
1487
-
1488
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/packer.js
1489
- var require_packer = __commonJS({
1490
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/packer.js"(exports2, module2) {
1491
- "use strict";
1492
- var constants = require_constants();
1493
- var CrcStream = require_crc();
1494
- var bitPacker = require_bitpacker();
1495
- var filter = require_filter_pack();
1496
- var zlib = require("zlib");
1497
- var Packer = module2.exports = function(options) {
1498
- this._options = options;
1499
- options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
1500
- options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
1501
- options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
1502
- options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
1503
- options.deflateFactory = options.deflateFactory || zlib.createDeflate;
1504
- options.bitDepth = options.bitDepth || 8;
1505
- options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
1506
- options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
1507
- if ([
1508
- constants.COLORTYPE_GRAYSCALE,
1509
- constants.COLORTYPE_COLOR,
1510
- constants.COLORTYPE_COLOR_ALPHA,
1511
- constants.COLORTYPE_ALPHA
1512
- ].indexOf(options.colorType) === -1) {
1513
- throw new Error(
1514
- "option color type:" + options.colorType + " is not supported at present"
1515
- );
1516
- }
1517
- if ([
1518
- constants.COLORTYPE_GRAYSCALE,
1519
- constants.COLORTYPE_COLOR,
1520
- constants.COLORTYPE_COLOR_ALPHA,
1521
- constants.COLORTYPE_ALPHA
1522
- ].indexOf(options.inputColorType) === -1) {
1523
- throw new Error(
1524
- "option input color type:" + options.inputColorType + " is not supported at present"
1525
- );
1526
- }
1527
- if (options.bitDepth !== 8 && options.bitDepth !== 16) {
1528
- throw new Error(
1529
- "option bit depth:" + options.bitDepth + " is not supported at present"
1530
- );
1531
- }
1532
- };
1533
- Packer.prototype.getDeflateOptions = function() {
1534
- return {
1535
- chunkSize: this._options.deflateChunkSize,
1536
- level: this._options.deflateLevel,
1537
- strategy: this._options.deflateStrategy
1538
- };
1539
- };
1540
- Packer.prototype.createDeflate = function() {
1541
- return this._options.deflateFactory(this.getDeflateOptions());
1542
- };
1543
- Packer.prototype.filterData = function(data, width, height) {
1544
- let packedData = bitPacker(data, width, height, this._options);
1545
- let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
1546
- let filteredData = filter(packedData, width, height, this._options, bpp);
1547
- return filteredData;
1548
- };
1549
- Packer.prototype._packChunk = function(type, data) {
1550
- let len = data ? data.length : 0;
1551
- let buf = Buffer.alloc(len + 12);
1552
- buf.writeUInt32BE(len, 0);
1553
- buf.writeUInt32BE(type, 4);
1554
- if (data) {
1555
- data.copy(buf, 8);
1556
- }
1557
- buf.writeInt32BE(
1558
- CrcStream.crc32(buf.slice(4, buf.length - 4)),
1559
- buf.length - 4
1560
- );
1561
- return buf;
1562
- };
1563
- Packer.prototype.packGAMA = function(gamma) {
1564
- let buf = Buffer.alloc(4);
1565
- buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
1566
- return this._packChunk(constants.TYPE_gAMA, buf);
1567
- };
1568
- Packer.prototype.packIHDR = function(width, height) {
1569
- let buf = Buffer.alloc(13);
1570
- buf.writeUInt32BE(width, 0);
1571
- buf.writeUInt32BE(height, 4);
1572
- buf[8] = this._options.bitDepth;
1573
- buf[9] = this._options.colorType;
1574
- buf[10] = 0;
1575
- buf[11] = 0;
1576
- buf[12] = 0;
1577
- return this._packChunk(constants.TYPE_IHDR, buf);
1578
- };
1579
- Packer.prototype.packIDAT = function(data) {
1580
- return this._packChunk(constants.TYPE_IDAT, data);
1581
- };
1582
- Packer.prototype.packIEND = function() {
1583
- return this._packChunk(constants.TYPE_IEND, null);
1584
- };
1585
- }
1586
- });
1587
-
1588
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/packer-async.js
1589
- var require_packer_async = __commonJS({
1590
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/packer-async.js"(exports2, module2) {
1591
- "use strict";
1592
- var util = require("util");
1593
- var Stream = require("stream");
1594
- var constants = require_constants();
1595
- var Packer = require_packer();
1596
- var PackerAsync = module2.exports = function(opt) {
1597
- Stream.call(this);
1598
- let options = opt || {};
1599
- this._packer = new Packer(options);
1600
- this._deflate = this._packer.createDeflate();
1601
- this.readable = true;
1602
- };
1603
- util.inherits(PackerAsync, Stream);
1604
- PackerAsync.prototype.pack = function(data, width, height, gamma) {
1605
- this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
1606
- this.emit("data", this._packer.packIHDR(width, height));
1607
- if (gamma) {
1608
- this.emit("data", this._packer.packGAMA(gamma));
1609
- }
1610
- let filteredData = this._packer.filterData(data, width, height);
1611
- this._deflate.on("error", this.emit.bind(this, "error"));
1612
- this._deflate.on(
1613
- "data",
1614
- function(compressedData) {
1615
- this.emit("data", this._packer.packIDAT(compressedData));
1616
- }.bind(this)
1617
- );
1618
- this._deflate.on(
1619
- "end",
1620
- function() {
1621
- this.emit("data", this._packer.packIEND());
1622
- this.emit("end");
1623
- }.bind(this)
1624
- );
1625
- this._deflate.end(filteredData);
1626
- };
1627
- }
1628
- });
1629
-
1630
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/sync-inflate.js
1631
- var require_sync_inflate = __commonJS({
1632
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/sync-inflate.js"(exports2, module2) {
1633
- "use strict";
1634
- var assert = require("assert").ok;
1635
- var zlib = require("zlib");
1636
- var util = require("util");
1637
- var kMaxLength = require("buffer").kMaxLength;
1638
- function Inflate(opts) {
1639
- if (!(this instanceof Inflate)) {
1640
- return new Inflate(opts);
1641
- }
1642
- if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
1643
- opts.chunkSize = zlib.Z_MIN_CHUNK;
1644
- }
1645
- zlib.Inflate.call(this, opts);
1646
- this._offset = this._offset === void 0 ? this._outOffset : this._offset;
1647
- this._buffer = this._buffer || this._outBuffer;
1648
- if (opts && opts.maxLength != null) {
1649
- this._maxLength = opts.maxLength;
1650
- }
1651
- }
1652
- function createInflate(opts) {
1653
- return new Inflate(opts);
1654
- }
1655
- function _close(engine, callback) {
1656
- if (callback) {
1657
- process.nextTick(callback);
1658
- }
1659
- if (!engine._handle) {
1660
- return;
1661
- }
1662
- engine._handle.close();
1663
- engine._handle = null;
1664
- }
1665
- Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
1666
- if (typeof asyncCb === "function") {
1667
- return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
1668
- }
1669
- let self = this;
1670
- let availInBefore = chunk && chunk.length;
1671
- let availOutBefore = this._chunkSize - this._offset;
1672
- let leftToInflate = this._maxLength;
1673
- let inOff = 0;
1674
- let buffers = [];
1675
- let nread = 0;
1676
- let error;
1677
- this.on("error", function(err) {
1678
- error = err;
1679
- });
1680
- function handleChunk(availInAfter, availOutAfter) {
1681
- if (self._hadError) {
1682
- return;
1683
- }
1684
- let have = availOutBefore - availOutAfter;
1685
- assert(have >= 0, "have should not go down");
1686
- if (have > 0) {
1687
- let out = self._buffer.slice(self._offset, self._offset + have);
1688
- self._offset += have;
1689
- if (out.length > leftToInflate) {
1690
- out = out.slice(0, leftToInflate);
1691
- }
1692
- buffers.push(out);
1693
- nread += out.length;
1694
- leftToInflate -= out.length;
1695
- if (leftToInflate === 0) {
1696
- return false;
1697
- }
1698
- }
1699
- if (availOutAfter === 0 || self._offset >= self._chunkSize) {
1700
- availOutBefore = self._chunkSize;
1701
- self._offset = 0;
1702
- self._buffer = Buffer.allocUnsafe(self._chunkSize);
1703
- }
1704
- if (availOutAfter === 0) {
1705
- inOff += availInBefore - availInAfter;
1706
- availInBefore = availInAfter;
1707
- return true;
1708
- }
1709
- return false;
1710
- }
1711
- assert(this._handle, "zlib binding closed");
1712
- let res;
1713
- do {
1714
- res = this._handle.writeSync(
1715
- flushFlag,
1716
- chunk,
1717
- // in
1718
- inOff,
1719
- // in_off
1720
- availInBefore,
1721
- // in_len
1722
- this._buffer,
1723
- // out
1724
- this._offset,
1725
- //out_off
1726
- availOutBefore
1727
- );
1728
- res = res || this._writeState;
1729
- } while (!this._hadError && handleChunk(res[0], res[1]));
1730
- if (this._hadError) {
1731
- throw error;
1732
- }
1733
- if (nread >= kMaxLength) {
1734
- _close(this);
1735
- throw new RangeError(
1736
- "Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes"
1737
- );
1738
- }
1739
- let buf = Buffer.concat(buffers, nread);
1740
- _close(this);
1741
- return buf;
1742
- };
1743
- util.inherits(Inflate, zlib.Inflate);
1744
- function zlibBufferSync(engine, buffer) {
1745
- if (typeof buffer === "string") {
1746
- buffer = Buffer.from(buffer);
1747
- }
1748
- if (!(buffer instanceof Buffer)) {
1749
- throw new TypeError("Not a string or buffer");
1750
- }
1751
- let flushFlag = engine._finishFlushFlag;
1752
- if (flushFlag == null) {
1753
- flushFlag = zlib.Z_FINISH;
1754
- }
1755
- return engine._processChunk(buffer, flushFlag);
1756
- }
1757
- function inflateSync(buffer, opts) {
1758
- return zlibBufferSync(new Inflate(opts), buffer);
1759
- }
1760
- module2.exports = exports2 = inflateSync;
1761
- exports2.Inflate = Inflate;
1762
- exports2.createInflate = createInflate;
1763
- exports2.inflateSync = inflateSync;
1764
- }
1765
- });
1766
-
1767
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/sync-reader.js
1768
- var require_sync_reader = __commonJS({
1769
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/sync-reader.js"(exports2, module2) {
1770
- "use strict";
1771
- var SyncReader = module2.exports = function(buffer) {
1772
- this._buffer = buffer;
1773
- this._reads = [];
1774
- };
1775
- SyncReader.prototype.read = function(length, callback) {
1776
- this._reads.push({
1777
- length: Math.abs(length),
1778
- // if length < 0 then at most this length
1779
- allowLess: length < 0,
1780
- func: callback
1781
- });
1782
- };
1783
- SyncReader.prototype.process = function() {
1784
- while (this._reads.length > 0 && this._buffer.length) {
1785
- let read = this._reads[0];
1786
- if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
1787
- this._reads.shift();
1788
- let buf = this._buffer;
1789
- this._buffer = buf.slice(read.length);
1790
- read.func.call(this, buf.slice(0, read.length));
1791
- } else {
1792
- break;
1793
- }
1794
- }
1795
- if (this._reads.length > 0) {
1796
- throw new Error("There are some read requests waitng on finished stream");
1797
- }
1798
- if (this._buffer.length > 0) {
1799
- throw new Error("unrecognised content at end of stream");
1800
- }
1801
- };
1802
- }
1803
- });
1804
-
1805
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-parse-sync.js
1806
- var require_filter_parse_sync = __commonJS({
1807
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/filter-parse-sync.js"(exports2) {
1808
- "use strict";
1809
- var SyncReader = require_sync_reader();
1810
- var Filter = require_filter_parse();
1811
- exports2.process = function(inBuffer, bitmapInfo) {
1812
- let outBuffers = [];
1813
- let reader = new SyncReader(inBuffer);
1814
- let filter = new Filter(bitmapInfo, {
1815
- read: reader.read.bind(reader),
1816
- write: function(bufferPart) {
1817
- outBuffers.push(bufferPart);
1818
- },
1819
- complete: function() {
1820
- }
1821
- });
1822
- filter.start();
1823
- reader.process();
1824
- return Buffer.concat(outBuffers);
1825
- };
1826
- }
1827
- });
1828
-
1829
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/parser-sync.js
1830
- var require_parser_sync = __commonJS({
1831
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/parser-sync.js"(exports2, module2) {
1832
- "use strict";
1833
- var hasSyncZlib = true;
1834
- var zlib = require("zlib");
1835
- var inflateSync = require_sync_inflate();
1836
- if (!zlib.deflateSync) {
1837
- hasSyncZlib = false;
1838
- }
1839
- var SyncReader = require_sync_reader();
1840
- var FilterSync = require_filter_parse_sync();
1841
- var Parser = require_parser();
1842
- var bitmapper = require_bitmapper();
1843
- var formatNormaliser = require_format_normaliser();
1844
- module2.exports = function(buffer, options) {
1845
- if (!hasSyncZlib) {
1846
- throw new Error(
1847
- "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
1848
- );
1849
- }
1850
- let err;
1851
- function handleError(_err_) {
1852
- err = _err_;
1853
- }
1854
- let metaData;
1855
- function handleMetaData(_metaData_) {
1856
- metaData = _metaData_;
1857
- }
1858
- function handleTransColor(transColor) {
1859
- metaData.transColor = transColor;
1860
- }
1861
- function handlePalette(palette) {
1862
- metaData.palette = palette;
1863
- }
1864
- function handleSimpleTransparency() {
1865
- metaData.alpha = true;
1866
- }
1867
- let gamma;
1868
- function handleGamma(_gamma_) {
1869
- gamma = _gamma_;
1870
- }
1871
- let inflateDataList = [];
1872
- function handleInflateData(inflatedData2) {
1873
- inflateDataList.push(inflatedData2);
1874
- }
1875
- let reader = new SyncReader(buffer);
1876
- let parser = new Parser(options, {
1877
- read: reader.read.bind(reader),
1878
- error: handleError,
1879
- metadata: handleMetaData,
1880
- gamma: handleGamma,
1881
- palette: handlePalette,
1882
- transColor: handleTransColor,
1883
- inflateData: handleInflateData,
1884
- simpleTransparency: handleSimpleTransparency
1885
- });
1886
- parser.start();
1887
- reader.process();
1888
- if (err) {
1889
- throw err;
1890
- }
1891
- let inflateData = Buffer.concat(inflateDataList);
1892
- inflateDataList.length = 0;
1893
- let inflatedData;
1894
- if (metaData.interlace) {
1895
- inflatedData = zlib.inflateSync(inflateData);
1896
- } else {
1897
- let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
1898
- let imageSize = rowSize * metaData.height;
1899
- inflatedData = inflateSync(inflateData, {
1900
- chunkSize: imageSize,
1901
- maxLength: imageSize
1902
- });
1903
- }
1904
- inflateData = null;
1905
- if (!inflatedData || !inflatedData.length) {
1906
- throw new Error("bad png - invalid inflate data response");
1907
- }
1908
- let unfilteredData = FilterSync.process(inflatedData, metaData);
1909
- inflateData = null;
1910
- let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
1911
- unfilteredData = null;
1912
- let normalisedBitmapData = formatNormaliser(
1913
- bitmapData,
1914
- metaData,
1915
- options.skipRescale
1916
- );
1917
- metaData.data = normalisedBitmapData;
1918
- metaData.gamma = gamma || 0;
1919
- return metaData;
1920
- };
1921
- }
1922
- });
1923
-
1924
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/packer-sync.js
1925
- var require_packer_sync = __commonJS({
1926
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/packer-sync.js"(exports2, module2) {
1927
- "use strict";
1928
- var hasSyncZlib = true;
1929
- var zlib = require("zlib");
1930
- if (!zlib.deflateSync) {
1931
- hasSyncZlib = false;
1932
- }
1933
- var constants = require_constants();
1934
- var Packer = require_packer();
1935
- module2.exports = function(metaData, opt) {
1936
- if (!hasSyncZlib) {
1937
- throw new Error(
1938
- "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
1939
- );
1940
- }
1941
- let options = opt || {};
1942
- let packer = new Packer(options);
1943
- let chunks = [];
1944
- chunks.push(Buffer.from(constants.PNG_SIGNATURE));
1945
- chunks.push(packer.packIHDR(metaData.width, metaData.height));
1946
- if (metaData.gamma) {
1947
- chunks.push(packer.packGAMA(metaData.gamma));
1948
- }
1949
- let filteredData = packer.filterData(
1950
- metaData.data,
1951
- metaData.width,
1952
- metaData.height
1953
- );
1954
- let compressedData = zlib.deflateSync(
1955
- filteredData,
1956
- packer.getDeflateOptions()
1957
- );
1958
- filteredData = null;
1959
- if (!compressedData || !compressedData.length) {
1960
- throw new Error("bad png - invalid compressed data response");
1961
- }
1962
- chunks.push(packer.packIDAT(compressedData));
1963
- chunks.push(packer.packIEND());
1964
- return Buffer.concat(chunks);
1965
- };
1966
- }
1967
- });
1968
-
1969
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/png-sync.js
1970
- var require_png_sync = __commonJS({
1971
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/png-sync.js"(exports2) {
1972
- "use strict";
1973
- var parse = require_parser_sync();
1974
- var pack = require_packer_sync();
1975
- exports2.read = function(buffer, options) {
1976
- return parse(buffer, options || {});
1977
- };
1978
- exports2.write = function(png, options) {
1979
- return pack(png, options);
1980
- };
1981
- }
1982
- });
1983
-
1984
- // ../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/png.js
1985
- var require_png = __commonJS({
1986
- "../../node_modules/.pnpm/pngjs@7.0.0/node_modules/pngjs/lib/png.js"(exports2) {
1987
- "use strict";
1988
- var util = require("util");
1989
- var Stream = require("stream");
1990
- var Parser = require_parser_async();
1991
- var Packer = require_packer_async();
1992
- var PNGSync = require_png_sync();
1993
- var PNG3 = exports2.PNG = function(options) {
1994
- Stream.call(this);
1995
- options = options || {};
1996
- this.width = options.width | 0;
1997
- this.height = options.height | 0;
1998
- this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
1999
- if (options.fill && this.data) {
2000
- this.data.fill(0);
2001
- }
2002
- this.gamma = 0;
2003
- this.readable = this.writable = true;
2004
- this._parser = new Parser(options);
2005
- this._parser.on("error", this.emit.bind(this, "error"));
2006
- this._parser.on("close", this._handleClose.bind(this));
2007
- this._parser.on("metadata", this._metadata.bind(this));
2008
- this._parser.on("gamma", this._gamma.bind(this));
2009
- this._parser.on(
2010
- "parsed",
2011
- function(data) {
2012
- this.data = data;
2013
- this.emit("parsed", data);
2014
- }.bind(this)
2015
- );
2016
- this._packer = new Packer(options);
2017
- this._packer.on("data", this.emit.bind(this, "data"));
2018
- this._packer.on("end", this.emit.bind(this, "end"));
2019
- this._parser.on("close", this._handleClose.bind(this));
2020
- this._packer.on("error", this.emit.bind(this, "error"));
2021
- };
2022
- util.inherits(PNG3, Stream);
2023
- PNG3.sync = PNGSync;
2024
- PNG3.prototype.pack = function() {
2025
- if (!this.data || !this.data.length) {
2026
- this.emit("error", "No data provided");
2027
- return this;
2028
- }
2029
- process.nextTick(
2030
- function() {
2031
- this._packer.pack(this.data, this.width, this.height, this.gamma);
2032
- }.bind(this)
2033
- );
2034
- return this;
2035
- };
2036
- PNG3.prototype.parse = function(data, callback) {
2037
- if (callback) {
2038
- let onParsed, onError;
2039
- onParsed = function(parsedData) {
2040
- this.removeListener("error", onError);
2041
- this.data = parsedData;
2042
- callback(null, this);
2043
- }.bind(this);
2044
- onError = function(err) {
2045
- this.removeListener("parsed", onParsed);
2046
- callback(err, null);
2047
- }.bind(this);
2048
- this.once("parsed", onParsed);
2049
- this.once("error", onError);
2050
- }
2051
- this.end(data);
2052
- return this;
2053
- };
2054
- PNG3.prototype.write = function(data) {
2055
- this._parser.write(data);
2056
- return true;
2057
- };
2058
- PNG3.prototype.end = function(data) {
2059
- this._parser.end(data);
2060
- };
2061
- PNG3.prototype._metadata = function(metadata) {
2062
- this.width = metadata.width;
2063
- this.height = metadata.height;
2064
- this.emit("metadata", metadata);
2065
- };
2066
- PNG3.prototype._gamma = function(gamma) {
2067
- this.gamma = gamma;
2068
- };
2069
- PNG3.prototype._handleClose = function() {
2070
- if (!this._parser.writable && !this._packer.readable) {
2071
- this.emit("close");
2072
- }
2073
- };
2074
- PNG3.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
2075
- srcX |= 0;
2076
- srcY |= 0;
2077
- width |= 0;
2078
- height |= 0;
2079
- deltaX |= 0;
2080
- deltaY |= 0;
2081
- if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
2082
- throw new Error("bitblt reading outside image");
2083
- }
2084
- if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
2085
- throw new Error("bitblt writing outside image");
2086
- }
2087
- for (let y = 0; y < height; y++) {
2088
- src.data.copy(
2089
- dst.data,
2090
- (deltaY + y) * dst.width + deltaX << 2,
2091
- (srcY + y) * src.width + srcX << 2,
2092
- (srcY + y) * src.width + srcX + width << 2
2093
- );
2094
- }
2095
- };
2096
- PNG3.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
2097
- PNG3.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
2098
- return this;
2099
- };
2100
- PNG3.adjustGamma = function(src) {
2101
- if (src.gamma) {
2102
- for (let y = 0; y < src.height; y++) {
2103
- for (let x = 0; x < src.width; x++) {
2104
- let idx = src.width * y + x << 2;
2105
- for (let i = 0; i < 3; i++) {
2106
- let sample = src.data[idx + i] / 255;
2107
- sample = Math.pow(sample, 1 / 2.2 / src.gamma);
2108
- src.data[idx + i] = Math.round(sample * 255);
2109
- }
2110
- }
2111
- }
2112
- src.gamma = 0;
2113
- }
2114
- };
2115
- PNG3.prototype.adjustGamma = function() {
2116
- PNG3.adjustGamma(this);
2117
- };
2118
- }
2119
- });
2120
-
2121
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/math.js
2122
- var require_math = __commonJS({
2123
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/math.js"(exports2) {
2124
- "use strict";
2125
- Object.defineProperty(exports2, "__esModule", { value: true });
2126
- exports2.covariance = exports2.variance = exports2.mean2d = exports2.square2d = exports2.multiply2d = exports2.divide2d = exports2.subtract2d = exports2.add2d = exports2.sum2d = exports2.floor = exports2.sum = exports2.average = void 0;
2127
- function average(xn) {
2128
- return sum(xn) / xn.length;
2129
- }
2130
- exports2.average = average;
2131
- function sum(xn) {
2132
- var out = 0;
2133
- for (var x = 0; x < xn.length; x++) {
2134
- out += xn[x];
2135
- }
2136
- return out;
2137
- }
2138
- exports2.sum = sum;
2139
- function floor(xn) {
2140
- var out = new Array(xn.length);
2141
- for (var x = 0; x < xn.length; x++) {
2142
- out[x] = Math.floor(xn[x]);
2143
- }
2144
- return out;
2145
- }
2146
- exports2.floor = floor;
2147
- function sum2d(_a) {
2148
- var data = _a.data;
2149
- var out = 0;
2150
- for (var x = 0; x < data.length; x++) {
2151
- out += data[x];
2152
- }
2153
- return out;
2154
- }
2155
- exports2.sum2d = sum2d;
2156
- function add2dMx(_a, _b) {
2157
- var ref1 = _a.data, width = _a.width, height = _a.height;
2158
- var ref2 = _b.data;
2159
- var data = new Array(ref1.length);
2160
- for (var x = 0; x < height; x++) {
2161
- var offset = x * width;
2162
- for (var y = 0; y < width; y++) {
2163
- data[offset + y] = ref1[offset + y] + ref2[offset + y];
2164
- }
2165
- }
2166
- return {
2167
- data,
2168
- width,
2169
- height
2170
- };
2171
- }
2172
- function subtract2dMx(_a, _b) {
2173
- var ref1 = _a.data, width = _a.width, height = _a.height;
2174
- var ref2 = _b.data;
2175
- var data = new Array(ref1.length);
2176
- for (var x = 0; x < height; x++) {
2177
- var offset = x * width;
2178
- for (var y = 0; y < width; y++) {
2179
- data[offset + y] = ref1[offset + y] - ref2[offset + y];
2180
- }
2181
- }
2182
- return {
2183
- data,
2184
- width,
2185
- height
2186
- };
2187
- }
2188
- function add2dScalar(_a, increase) {
2189
- var ref = _a.data, width = _a.width, height = _a.height;
2190
- var data = new Array(ref.length);
2191
- for (var x = 0; x < ref.length; x++) {
2192
- data[x] = ref[x] + increase;
2193
- }
2194
- return {
2195
- data,
2196
- width,
2197
- height
2198
- };
2199
- }
2200
- function add2d(A, increase) {
2201
- if (typeof increase === "number") {
2202
- return add2dScalar(A, increase);
2203
- }
2204
- return add2dMx(A, increase);
2205
- }
2206
- exports2.add2d = add2d;
2207
- function subtract2d(A, decrease) {
2208
- if (typeof decrease === "number") {
2209
- return add2dScalar(A, -decrease);
2210
- }
2211
- return subtract2dMx(A, decrease);
2212
- }
2213
- exports2.subtract2d = subtract2d;
2214
- function divide2dScalar(_a, divisor) {
2215
- var ref = _a.data, width = _a.width, height = _a.height;
2216
- var data = new Array(ref.length);
2217
- for (var x = 0; x < ref.length; x++) {
2218
- data[x] = ref[x] / divisor;
2219
- }
2220
- return {
2221
- data,
2222
- width,
2223
- height
2224
- };
2225
- }
2226
- function divide2dMx(_a, _b) {
2227
- var ref1 = _a.data, width = _a.width, height = _a.height;
2228
- var ref2 = _b.data;
2229
- var data = new Array(ref1.length);
2230
- for (var x = 0; x < ref1.length; x++) {
2231
- data[x] = ref1[x] / ref2[x];
2232
- }
2233
- return {
2234
- data,
2235
- width,
2236
- height
2237
- };
2238
- }
2239
- function divide2d(A, divisor) {
2240
- if (typeof divisor === "number") {
2241
- return divide2dScalar(A, divisor);
2242
- }
2243
- return divide2dMx(A, divisor);
2244
- }
2245
- exports2.divide2d = divide2d;
2246
- function multiply2dScalar(_a, multiplier) {
2247
- var ref = _a.data, width = _a.width, height = _a.height;
2248
- var data = new Array(ref.length);
2249
- for (var x = 0; x < ref.length; x++) {
2250
- data[x] = ref[x] * multiplier;
2251
- }
2252
- return {
2253
- data,
2254
- width,
2255
- height
2256
- };
2257
- }
2258
- function multiply2dMx(_a, _b) {
2259
- var ref1 = _a.data, width = _a.width, height = _a.height;
2260
- var ref2 = _b.data;
2261
- var data = new Array(ref1.length);
2262
- for (var x = 0; x < ref1.length; x++) {
2263
- data[x] = ref1[x] * ref2[x];
2264
- }
2265
- return {
2266
- data,
2267
- width,
2268
- height
2269
- };
2270
- }
2271
- function multiply2d(A, multiplier) {
2272
- if (typeof multiplier === "number") {
2273
- return multiply2dScalar(A, multiplier);
2274
- }
2275
- return multiply2dMx(A, multiplier);
2276
- }
2277
- exports2.multiply2d = multiply2d;
2278
- function square2d(A) {
2279
- return multiply2d(A, A);
2280
- }
2281
- exports2.square2d = square2d;
2282
- function mean2d(A) {
2283
- return sum2d(A) / A.data.length;
2284
- }
2285
- exports2.mean2d = mean2d;
2286
- function variance(values, avg) {
2287
- if (avg === void 0) {
2288
- avg = average(values);
2289
- }
2290
- var varx = 0;
2291
- var i = values.length;
2292
- while (i--) {
2293
- varx += Math.pow(values[i] - avg, 2);
2294
- }
2295
- return varx / values.length;
2296
- }
2297
- exports2.variance = variance;
2298
- function covariance(values1, values2, average1, average2) {
2299
- if (average1 === void 0) {
2300
- average1 = average(values1);
2301
- }
2302
- if (average2 === void 0) {
2303
- average2 = average(values2);
2304
- }
2305
- var cov = 0;
2306
- var i = values1.length;
2307
- while (i--) {
2308
- cov += (values1[i] - average1) * (values2[i] - average2);
2309
- }
2310
- return cov / values1.length;
2311
- }
2312
- exports2.covariance = covariance;
2313
- }
2314
- });
2315
-
2316
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/internal/numbers.js
2317
- var require_numbers = __commonJS({
2318
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/internal/numbers.js"(exports2) {
2319
- "use strict";
2320
- Object.defineProperty(exports2, "__esModule", { value: true });
2321
- exports2.numbers = void 0;
2322
- function numbers(height, width, num) {
2323
- var size = width * height;
2324
- var data = new Array(size);
2325
- for (var x = 0; x < size; x++) {
2326
- data[x] = num;
2327
- }
2328
- return {
2329
- data,
2330
- width,
2331
- height
2332
- };
2333
- }
2334
- exports2.numbers = numbers;
2335
- }
2336
- });
2337
-
2338
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/ones.js
2339
- var require_ones = __commonJS({
2340
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/ones.js"(exports2) {
2341
- "use strict";
2342
- Object.defineProperty(exports2, "__esModule", { value: true });
2343
- exports2.ones = void 0;
2344
- var numbers_1 = require_numbers();
2345
- function ones(height, width) {
2346
- if (width === void 0) {
2347
- width = height;
2348
- }
2349
- return numbers_1.numbers(height, width, 1);
2350
- }
2351
- exports2.ones = ones;
2352
- }
2353
- });
2354
-
2355
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/sub.js
2356
- var require_sub = __commonJS({
2357
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/sub.js"(exports2) {
2358
- "use strict";
2359
- Object.defineProperty(exports2, "__esModule", { value: true });
2360
- exports2.sub = void 0;
2361
- function sub(_a, x, height, y, width) {
2362
- var ref = _a.data, refWidth = _a.width;
2363
- var data = new Array(width * height);
2364
- for (var i = 0; i < height; i++) {
2365
- for (var j = 0; j < width; j++) {
2366
- data[i * width + j] = ref[(y + i) * refWidth + x + j];
2367
- }
2368
- }
2369
- return {
2370
- data,
2371
- width,
2372
- height
2373
- };
2374
- }
2375
- exports2.sub = sub;
2376
- }
2377
- });
2378
-
2379
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/zeros.js
2380
- var require_zeros = __commonJS({
2381
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/zeros.js"(exports2) {
2382
- "use strict";
2383
- Object.defineProperty(exports2, "__esModule", { value: true });
2384
- exports2.zeros = void 0;
2385
- var numbers_1 = require_numbers();
2386
- function zeros(height, width) {
2387
- if (width === void 0) {
2388
- width = height;
2389
- }
2390
- return numbers_1.numbers(height, width, 0);
2391
- }
2392
- exports2.zeros = zeros;
2393
- }
2394
- });
2395
-
2396
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/conv2.js
2397
- var require_conv2 = __commonJS({
2398
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/conv2.js"(exports2) {
2399
- "use strict";
2400
- Object.defineProperty(exports2, "__esModule", { value: true });
2401
- exports2.conv2 = void 0;
2402
- var math_1 = require_math();
2403
- var ones_1 = require_ones();
2404
- var sub_1 = require_sub();
2405
- var zeros_1 = require_zeros();
2406
- function mxConv2(_a, b, shape) {
2407
- var ref = _a.data, refWidth = _a.width, refHeight = _a.height;
2408
- if (shape === void 0) {
2409
- shape = "full";
2410
- }
2411
- var cWidth = refWidth + b.width - 1;
2412
- var cHeight = refHeight + b.height - 1;
2413
- var data = zeros_1.zeros(cHeight, cWidth).data;
2414
- for (var r1 = 0; r1 < b.height; r1++) {
2415
- for (var c1 = 0; c1 < b.width; c1++) {
2416
- var br1c1 = b.data[r1 * b.width + c1];
2417
- if (br1c1) {
2418
- for (var i = 0; i < refHeight; i++) {
2419
- for (var j = 0; j < refWidth; j++) {
2420
- data[(i + r1) * cWidth + j + c1] += ref[i * refWidth + j] * br1c1;
2421
- }
2422
- }
2423
- }
2424
- }
2425
- }
2426
- var c = {
2427
- data,
2428
- width: cWidth,
2429
- height: cHeight
2430
- };
2431
- return reshape(c, shape, refHeight, b.height, refWidth, b.width);
2432
- }
2433
- function boxConv(a, _a, shape) {
2434
- var data = _a.data, width = _a.width, height = _a.height;
2435
- if (shape === void 0) {
2436
- shape = "full";
2437
- }
2438
- var b1 = ones_1.ones(height, 1);
2439
- var b2 = ones_1.ones(1, width);
2440
- var out = convn(a, b1, b2, shape);
2441
- return math_1.multiply2d(out, data[0]);
2442
- }
2443
- function isBoxKernel(_a) {
2444
- var data = _a.data;
2445
- var expected = data[0];
2446
- for (var i = 1; i < data.length; i++) {
2447
- if (data[i] !== expected) {
2448
- return false;
2449
- }
2450
- }
2451
- return true;
2452
- }
2453
- function convn(a, b1, b2, shape) {
2454
- if (shape === void 0) {
2455
- shape = "full";
2456
- }
2457
- var mb = Math.max(b1.height, b1.width);
2458
- var nb = Math.max(b2.height, b2.width);
2459
- var temp = mxConv2(a, b1, "full");
2460
- var c = mxConv2(temp, b2, "full");
2461
- return reshape(c, shape, a.height, mb, a.width, nb);
2462
- }
2463
- function reshape(c, shape, ma, mb, na, nb) {
2464
- if (shape === "full") {
2465
- return c;
2466
- } else if (shape === "same") {
2467
- var rowStart = Math.ceil((c.height - ma) / 2);
2468
- var colStart = Math.ceil((c.width - na) / 2);
2469
- return sub_1.sub(c, rowStart, ma, colStart, na);
2470
- }
2471
- return sub_1.sub(c, mb - 1, ma - mb + 1, nb - 1, na - nb + 1);
2472
- }
2473
- function conv2() {
2474
- var args = [];
2475
- for (var _i = 0; _i < arguments.length; _i++) {
2476
- args[_i] = arguments[_i];
2477
- }
2478
- if (args[2] && args[2].data) {
2479
- return convn.apply(void 0, args);
2480
- } else if (isBoxKernel(args[1])) {
2481
- return boxConv.apply(void 0, args);
2482
- }
2483
- return mxConv2.apply(void 0, args);
2484
- }
2485
- exports2.conv2 = conv2;
2486
- }
2487
- });
2488
-
2489
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/filter2.js
2490
- var require_filter2 = __commonJS({
2491
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/filter2.js"(exports2) {
2492
- "use strict";
2493
- Object.defineProperty(exports2, "__esModule", { value: true });
2494
- exports2.filter2 = void 0;
2495
- var conv2_1 = require_conv2();
2496
- function rotate1802d(_a) {
2497
- var ref = _a.data, width = _a.width, height = _a.height;
2498
- var data = new Array(ref.length);
2499
- for (var i = 0; i < height; i++) {
2500
- for (var j = 0; j < width; j++) {
2501
- data[i * width + j] = ref[(height - 1 - i) * width + width - 1 - j];
2502
- }
2503
- }
2504
- return {
2505
- data,
2506
- width,
2507
- height
2508
- };
2509
- }
2510
- function filter2(h, X, shape) {
2511
- if (shape === void 0) {
2512
- shape = "same";
2513
- }
2514
- return conv2_1.conv2(X, rotate1802d(h), shape);
2515
- }
2516
- exports2.filter2 = filter2;
2517
- }
2518
- });
2519
-
2520
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/fspecial.js
2521
- var require_fspecial = __commonJS({
2522
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/fspecial.js"(exports2) {
2523
- "use strict";
2524
- Object.defineProperty(exports2, "__esModule", { value: true });
2525
- exports2.fspecial = void 0;
2526
- var math_1 = require_math();
2527
- function rangeSquare2d(length) {
2528
- var size = length * 2 + 1;
2529
- var data = new Array(Math.pow(size, 2));
2530
- for (var x = 0; x < size; x++) {
2531
- for (var y = 0; y < size; y++) {
2532
- data[x * size + y] = Math.pow(x - length, 2) + Math.pow(y - length, 2);
2533
- }
2534
- }
2535
- return {
2536
- data,
2537
- width: size,
2538
- height: size
2539
- };
2540
- }
2541
- function gaussianFilter2d(_a, \u03C3) {
2542
- var ref = _a.data, width = _a.width, height = _a.height;
2543
- var data = new Array(ref.length);
2544
- for (var x = 0; x < ref.length; x++) {
2545
- data[x] = Math.exp(-ref[x] / (2 * Math.pow(\u03C3, 2)));
2546
- }
2547
- return {
2548
- data,
2549
- width,
2550
- height
2551
- };
2552
- }
2553
- function fspecial(_type, hsize, \u03C3) {
2554
- if (hsize === void 0) {
2555
- hsize = 3;
2556
- }
2557
- if (\u03C3 === void 0) {
2558
- \u03C3 = 1.5;
2559
- }
2560
- hsize = (hsize - 1) / 2;
2561
- var pos = rangeSquare2d(hsize);
2562
- var gauss = gaussianFilter2d(pos, \u03C3);
2563
- var total = math_1.sum2d(gauss);
2564
- return math_1.divide2d(gauss, total);
2565
- }
2566
- exports2.fspecial = fspecial;
2567
- }
2568
- });
2569
-
2570
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/mod.js
2571
- var require_mod = __commonJS({
2572
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/mod.js"(exports2) {
2573
- "use strict";
2574
- Object.defineProperty(exports2, "__esModule", { value: true });
2575
- exports2.mod = void 0;
2576
- function mod(x, y) {
2577
- return x - y * Math.floor(x / y);
2578
- }
2579
- exports2.mod = mod;
2580
- }
2581
- });
2582
-
2583
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/padarray.js
2584
- var require_padarray = __commonJS({
2585
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/padarray.js"(exports2) {
2586
- "use strict";
2587
- Object.defineProperty(exports2, "__esModule", { value: true });
2588
- exports2.padarray = void 0;
2589
- var mod_1 = require_mod();
2590
- function mirrorHorizonal(_a) {
2591
- var ref = _a.data, width = _a.width, height = _a.height;
2592
- var data = new Array(ref.length);
2593
- for (var x = 0; x < height; x++) {
2594
- for (var y = 0; y < width; y++) {
2595
- data[x * width + y] = ref[x * width + width - 1 - y];
2596
- }
2597
- }
2598
- return {
2599
- data,
2600
- width,
2601
- height
2602
- };
2603
- }
2604
- function mirrorVertical(_a) {
2605
- var ref = _a.data, width = _a.width, height = _a.height;
2606
- var data = new Array(ref.length);
2607
- for (var x = 0; x < height; x++) {
2608
- for (var y = 0; y < width; y++) {
2609
- data[x * width + y] = ref[(height - 1 - x) * width + y];
2610
- }
2611
- }
2612
- return {
2613
- data,
2614
- width,
2615
- height
2616
- };
2617
- }
2618
- function concatHorizontal(A, B) {
2619
- var width = A.width + B.width;
2620
- var data = new Array(A.height * width);
2621
- for (var x = 0; x < A.height; x++) {
2622
- for (var y = 0; y < A.width; y++) {
2623
- data[x * width + y] = A.data[x * A.width + y];
2624
- }
2625
- for (var y = 0; y < B.width; y++) {
2626
- data[x * width + y + A.width] = B.data[x * B.width + y];
2627
- }
2628
- }
2629
- return {
2630
- data,
2631
- width,
2632
- height: A.height
2633
- };
2634
- }
2635
- function concatVertical(A, B) {
2636
- return {
2637
- data: A.data.concat(B.data),
2638
- height: A.height + B.height,
2639
- width: A.width
2640
- };
2641
- }
2642
- function padHorizontal(A, pad) {
2643
- var width = A.width + 2 * pad;
2644
- var data = new Array(width * A.height);
2645
- var mirrored = concatHorizontal(A, mirrorHorizonal(A));
2646
- for (var x = 0; x < A.height; x++) {
2647
- for (var y = -pad; y < A.width + pad; y++) {
2648
- data[x * width + y + pad] = mirrored.data[x * mirrored.width + mod_1.mod(y, mirrored.width)];
2649
- }
2650
- }
2651
- return {
2652
- data,
2653
- width,
2654
- height: A.height
2655
- };
2656
- }
2657
- function padVertical(A, pad) {
2658
- var mirrored = concatVertical(A, mirrorVertical(A));
2659
- var height = A.height + pad * 2;
2660
- var data = new Array(A.width * height);
2661
- for (var x = -pad; x < A.height + pad; x++) {
2662
- for (var y = 0; y < A.width; y++) {
2663
- data[(x + pad) * A.width + y] = mirrored.data[mod_1.mod(x, mirrored.height) * A.width + y];
2664
- }
2665
- }
2666
- return {
2667
- data,
2668
- width: A.width,
2669
- height
2670
- };
2671
- }
2672
- function fastPadding(A, _a) {
2673
- var padHeight = _a[0], padWidth = _a[1];
2674
- var width = A.width + padWidth * 2;
2675
- var height = A.height + padHeight * 2;
2676
- var data = new Array(width * height);
2677
- for (var x = -padHeight; x < 0; x++) {
2678
- for (var y = -padWidth; y < 0; y++) {
2679
- data[(x + padHeight) * width + y + padWidth] = A.data[(Math.abs(x) - 1) * A.width + Math.abs(y) - 1];
2680
- }
2681
- for (var y = 0; y < A.width; y++) {
2682
- data[(x + padHeight) * width + y + padWidth] = A.data[(Math.abs(x) - 1) * A.width + y];
2683
- }
2684
- for (var y = A.width; y < A.width + padWidth; y++) {
2685
- data[(x + padHeight) * width + y + padWidth] = A.data[(Math.abs(x) - 1) * A.width + 2 * A.width - y - 1];
2686
- }
2687
- }
2688
- for (var x = 0; x < A.height; x++) {
2689
- for (var y = -padWidth; y < 0; y++) {
2690
- data[(x + padHeight) * width + y + padWidth] = A.data[x * A.width + Math.abs(y) - 1];
2691
- }
2692
- for (var y = 0; y < A.width; y++) {
2693
- data[(x + padHeight) * width + y + padWidth] = A.data[x * A.width + y];
2694
- }
2695
- for (var y = A.width; y < A.width + padWidth; y++) {
2696
- data[(x + padHeight) * width + y + padWidth] = A.data[x * A.width + 2 * A.width - y - 1];
2697
- }
2698
- }
2699
- for (var x = A.height; x < A.height + padHeight; x++) {
2700
- for (var y = -padWidth; y < 0; y++) {
2701
- data[(x + padHeight) * width + y + padWidth] = A.data[(2 * A.height - x - 1) * A.width + Math.abs(y) - 1];
2702
- }
2703
- for (var y = 0; y < A.width; y++) {
2704
- data[(x + padHeight) * width + y + padWidth] = A.data[(2 * A.height - x - 1) * A.width + y];
2705
- }
2706
- for (var y = A.width; y < A.width + padWidth; y++) {
2707
- data[(x + padHeight) * width + y + padWidth] = A.data[(2 * A.height - x - 1) * A.width + 2 * A.width - y - 1];
2708
- }
2709
- }
2710
- return {
2711
- data,
2712
- width,
2713
- height
2714
- };
2715
- }
2716
- function padarray(A, _a, _padval, _direction) {
2717
- var padHeight = _a[0], padWidth = _a[1];
2718
- if (A.height >= padHeight && A.width >= padWidth) {
2719
- return fastPadding(A, [padHeight, padWidth]);
2720
- }
2721
- return padVertical(padHorizontal(A, padWidth), padHeight);
2722
- }
2723
- exports2.padarray = padarray;
2724
- }
2725
- });
2726
-
2727
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/imfilter.js
2728
- var require_imfilter = __commonJS({
2729
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/imfilter.js"(exports2) {
2730
- "use strict";
2731
- Object.defineProperty(exports2, "__esModule", { value: true });
2732
- exports2.imfilter = void 0;
2733
- var mod_1 = require_mod();
2734
- var padarray_1 = require_padarray();
2735
- var math_1 = require_math();
2736
- var filter2_1 = require_filter2();
2737
- function padMatrix(A, frows, fcols, pad) {
2738
- A = padarray_1.padarray(A, math_1.floor([frows / 2, fcols / 2]), pad);
2739
- if (mod_1.mod(frows, 2) === 0) {
2740
- A.data = A.data.slice(0, -A.width);
2741
- A.height--;
2742
- }
2743
- if (mod_1.mod(fcols, 2) === 0) {
2744
- var data = [];
2745
- for (var x = 0; x < A.data.length; x++) {
2746
- if ((x + 1) % A.width !== 0) {
2747
- data.push(A.data[x]);
2748
- }
2749
- }
2750
- A.data = data;
2751
- A.width--;
2752
- }
2753
- return A;
2754
- }
2755
- function getConv2Size(resSize) {
2756
- if (resSize === "same") {
2757
- resSize = "valid";
2758
- }
2759
- return resSize;
2760
- }
2761
- function imfilter(A, f, pad, resSize) {
2762
- if (pad === void 0) {
2763
- pad = "symmetric";
2764
- }
2765
- if (resSize === void 0) {
2766
- resSize = "same";
2767
- }
2768
- A = padMatrix(A, f.width, f.height, pad);
2769
- resSize = getConv2Size(resSize);
2770
- return filter2_1.filter2(f, A, resSize);
2771
- }
2772
- exports2.imfilter = imfilter;
2773
- }
2774
- });
2775
-
2776
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/normpdf.js
2777
- var require_normpdf = __commonJS({
2778
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/normpdf.js"(exports2) {
2779
- "use strict";
2780
- Object.defineProperty(exports2, "__esModule", { value: true });
2781
- exports2.normpdf = void 0;
2782
- function normpdf(_a, \u00B5, \u03C3) {
2783
- var ref = _a.data, width = _a.width, height = _a.height;
2784
- if (\u00B5 === void 0) {
2785
- \u00B5 = 0;
2786
- }
2787
- if (\u03C3 === void 0) {
2788
- \u03C3 = 1;
2789
- }
2790
- var SQ2PI = 2.5066282746310007;
2791
- var data = new Array(ref.length);
2792
- for (var i = 0; i < ref.length; i++) {
2793
- var z = (ref[i] - \u00B5) / \u03C3;
2794
- data[i] = Math.exp(-Math.pow(z, 2) / 2) / (\u03C3 * SQ2PI);
2795
- }
2796
- return {
2797
- data,
2798
- width,
2799
- height
2800
- };
2801
- }
2802
- exports2.normpdf = normpdf;
2803
- }
2804
- });
2805
-
2806
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/rgb2gray.js
2807
- var require_rgb2gray = __commonJS({
2808
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/rgb2gray.js"(exports2) {
2809
- "use strict";
2810
- Object.defineProperty(exports2, "__esModule", { value: true });
2811
- exports2.rgb2grayInteger = exports2.rgb2gray = void 0;
2812
- function rgb2gray(_a) {
2813
- var d = _a.data, width = _a.width, height = _a.height;
2814
- var uint8Array = new Uint8Array(width * height);
2815
- for (var i = 0; i < d.length; i += 4) {
2816
- var grayIndex = i / 4;
2817
- uint8Array[grayIndex] = 0.29894 * d[i] + 0.58704 * d[i + 1] + 0.11402 * d[i + 2] + 0.5;
2818
- }
2819
- return {
2820
- data: Array.from(uint8Array),
2821
- width,
2822
- height
2823
- };
2824
- }
2825
- exports2.rgb2gray = rgb2gray;
2826
- function rgb2grayInteger(_a) {
2827
- var d = _a.data, width = _a.width, height = _a.height;
2828
- var array = new Array(width * height);
2829
- for (var i = 0; i < d.length; i += 4) {
2830
- var grayIndex = i / 4;
2831
- array[grayIndex] = 77 * d[i] + 150 * d[i + 1] + 29 * d[i + 2] + 128 >> 8;
2832
- }
2833
- return {
2834
- data: array,
2835
- width,
2836
- height
2837
- };
2838
- }
2839
- exports2.rgb2grayInteger = rgb2grayInteger;
2840
- }
2841
- });
2842
-
2843
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/skip2d.js
2844
- var require_skip2d = __commonJS({
2845
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/skip2d.js"(exports2) {
2846
- "use strict";
2847
- Object.defineProperty(exports2, "__esModule", { value: true });
2848
- exports2.skip2d = void 0;
2849
- function skip2d(A, _a, _b) {
2850
- var startRow = _a[0], everyRow = _a[1], endRow = _a[2];
2851
- var startCol = _b[0], everyCol = _b[1], endCol = _b[2];
2852
- var width = Math.ceil((endCol - startCol) / everyCol);
2853
- var height = Math.ceil((endRow - startRow) / everyRow);
2854
- var data = new Array(width * height);
2855
- for (var i = 0; i < height; i++) {
2856
- for (var j = 0; j < width; j++) {
2857
- var Ai = startRow + i * everyRow;
2858
- var Aj = startCol + j * everyCol;
2859
- data[i * width + j] = A.data[Ai * A.width + Aj];
2860
- }
2861
- }
2862
- return {
2863
- data,
2864
- width,
2865
- height
2866
- };
2867
- }
2868
- exports2.skip2d = skip2d;
2869
- }
2870
- });
2871
-
2872
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/transpose.js
2873
- var require_transpose = __commonJS({
2874
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/transpose.js"(exports2) {
2875
- "use strict";
2876
- Object.defineProperty(exports2, "__esModule", { value: true });
2877
- exports2.transpose = void 0;
2878
- function transpose(_a) {
2879
- var ref = _a.data, width = _a.width, height = _a.height;
2880
- var data = new Array(width * height);
2881
- for (var i = 0; i < height; i++) {
2882
- for (var j = 0; j < width; j++) {
2883
- data[j * height + i] = ref[i * width + j];
2884
- }
2885
- }
2886
- return {
2887
- data,
2888
- height: width,
2889
- width: height
2890
- };
2891
- }
2892
- exports2.transpose = transpose;
2893
- }
2894
- });
2895
-
2896
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/index.js
2897
- var require_matlab = __commonJS({
2898
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/matlab/index.js"(exports2) {
2899
- "use strict";
2900
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
2901
- if (k2 === void 0) k2 = k;
2902
- Object.defineProperty(o, k2, { enumerable: true, get: function() {
2903
- return m[k];
2904
- } });
2905
- }) : (function(o, m, k, k2) {
2906
- if (k2 === void 0) k2 = k;
2907
- o[k2] = m[k];
2908
- }));
2909
- var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
2910
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
2911
- };
2912
- Object.defineProperty(exports2, "__esModule", { value: true });
2913
- __exportStar(require_conv2(), exports2);
2914
- __exportStar(require_filter2(), exports2);
2915
- __exportStar(require_fspecial(), exports2);
2916
- __exportStar(require_imfilter(), exports2);
2917
- __exportStar(require_normpdf(), exports2);
2918
- __exportStar(require_ones(), exports2);
2919
- __exportStar(require_padarray(), exports2);
2920
- __exportStar(require_rgb2gray(), exports2);
2921
- __exportStar(require_skip2d(), exports2);
2922
- __exportStar(require_sub(), exports2);
2923
- __exportStar(require_transpose(), exports2);
2924
- __exportStar(require_zeros(), exports2);
2925
- }
2926
- });
2927
-
2928
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/ssim.js
2929
- var require_ssim = __commonJS({
2930
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/ssim.js"(exports2) {
2931
- "use strict";
2932
- Object.defineProperty(exports2, "__esModule", { value: true });
2933
- exports2.ssim = void 0;
2934
- var math_1 = require_math();
2935
- var matlab_1 = require_matlab();
2936
- function ssim(pixels1, pixels2, options) {
2937
- var w = matlab_1.normpdf(getRange(options.windowSize), 0, 1.5);
2938
- var L = Math.pow(2, options.bitDepth) - 1;
2939
- var c1 = Math.pow(options.k1 * L, 2);
2940
- var c2 = Math.pow(options.k2 * L, 2);
2941
- w = math_1.divide2d(w, math_1.sum2d(w));
2942
- var wt = matlab_1.transpose(w);
2943
- var \u03BC1 = matlab_1.conv2(pixels1, w, wt, "valid");
2944
- var \u03BC2 = matlab_1.conv2(pixels2, w, wt, "valid");
2945
- var \u03BC1Sq = math_1.square2d(\u03BC1);
2946
- var \u03BC2Sq = math_1.square2d(\u03BC2);
2947
- var \u03BC12 = math_1.multiply2d(\u03BC1, \u03BC2);
2948
- var pixels1Sq = math_1.square2d(pixels1);
2949
- var pixels2Sq = math_1.square2d(pixels2);
2950
- var \u03C31Sq = math_1.subtract2d(matlab_1.conv2(pixels1Sq, w, wt, "valid"), \u03BC1Sq);
2951
- var \u03C32Sq = math_1.subtract2d(matlab_1.conv2(pixels2Sq, w, wt, "valid"), \u03BC2Sq);
2952
- var \u03C312 = math_1.subtract2d(matlab_1.conv2(math_1.multiply2d(pixels1, pixels2), w, wt, "valid"), \u03BC12);
2953
- if (c1 > 0 && c2 > 0) {
2954
- return genSSIM(\u03BC12, \u03C312, \u03BC1Sq, \u03BC2Sq, \u03C31Sq, \u03C32Sq, c1, c2);
2955
- }
2956
- return genUQI(\u03BC12, \u03C312, \u03BC1Sq, \u03BC2Sq, \u03C31Sq, \u03C32Sq);
2957
- }
2958
- exports2.ssim = ssim;
2959
- function getRange(size) {
2960
- var offset = Math.floor(size / 2);
2961
- var data = new Array(offset * 2 + 1);
2962
- for (var x = -offset; x <= offset; x++) {
2963
- data[x + offset] = Math.abs(x);
2964
- }
2965
- return {
2966
- data,
2967
- width: data.length,
2968
- height: 1
2969
- };
2970
- }
2971
- function genSSIM(\u03BC12, \u03C312, \u03BC1Sq, \u03BC2Sq, \u03C31Sq, \u03C32Sq, c1, c2) {
2972
- var num1 = math_1.add2d(math_1.multiply2d(\u03BC12, 2), c1);
2973
- var num2 = math_1.add2d(math_1.multiply2d(\u03C312, 2), c2);
2974
- var denom1 = math_1.add2d(math_1.add2d(\u03BC1Sq, \u03BC2Sq), c1);
2975
- var denom2 = math_1.add2d(math_1.add2d(\u03C31Sq, \u03C32Sq), c2);
2976
- return math_1.divide2d(math_1.multiply2d(num1, num2), math_1.multiply2d(denom1, denom2));
2977
- }
2978
- function genUQI(\u03BC12, \u03C312, \u03BC1Sq, \u03BC2Sq, \u03C31Sq, \u03C32Sq) {
2979
- var numerator1 = math_1.multiply2d(\u03BC12, 2);
2980
- var numerator2 = math_1.multiply2d(\u03C312, 2);
2981
- var denominator1 = math_1.add2d(\u03BC1Sq, \u03BC2Sq);
2982
- var denominator2 = math_1.add2d(\u03C31Sq, \u03C32Sq);
2983
- return math_1.divide2d(math_1.multiply2d(numerator1, numerator2), math_1.multiply2d(denominator1, denominator2));
2984
- }
2985
- }
2986
- });
2987
-
2988
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/originalSsim.js
2989
- var require_originalSsim = __commonJS({
2990
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/originalSsim.js"(exports2) {
2991
- "use strict";
2992
- Object.defineProperty(exports2, "__esModule", { value: true });
2993
- exports2.originalSsim = void 0;
2994
- var math_1 = require_math();
2995
- var matlab_1 = require_matlab();
2996
- function originalSsim(pixels1, pixels2, options) {
2997
- var w = matlab_1.fspecial("gaussian", options.windowSize, 1.5);
2998
- var L = Math.pow(2, options.bitDepth) - 1;
2999
- var c1 = Math.pow(options.k1 * L, 2);
3000
- var c2 = Math.pow(options.k2 * L, 2);
3001
- w = math_1.divide2d(w, math_1.sum2d(w));
3002
- var \u03BC1 = matlab_1.filter2(w, pixels1, "valid");
3003
- var \u03BC2 = matlab_1.filter2(w, pixels2, "valid");
3004
- var \u03BC1Sq = math_1.square2d(\u03BC1);
3005
- var \u03BC2Sq = math_1.square2d(\u03BC2);
3006
- var \u03BC12 = math_1.multiply2d(\u03BC1, \u03BC2);
3007
- var pixels1Sq = math_1.square2d(pixels1);
3008
- var pixels2Sq = math_1.square2d(pixels2);
3009
- var \u03C31Sq = math_1.subtract2d(matlab_1.filter2(w, pixels1Sq, "valid"), \u03BC1Sq);
3010
- var \u03C32Sq = math_1.subtract2d(matlab_1.filter2(w, pixels2Sq, "valid"), \u03BC2Sq);
3011
- var \u03C312 = math_1.subtract2d(matlab_1.filter2(w, math_1.multiply2d(pixels1, pixels2), "valid"), \u03BC12);
3012
- if (c1 > 0 && c2 > 0) {
3013
- var num1 = math_1.add2d(math_1.multiply2d(\u03BC12, 2), c1);
3014
- var num2 = math_1.add2d(math_1.multiply2d(\u03C312, 2), c2);
3015
- var denom1 = math_1.add2d(math_1.add2d(\u03BC1Sq, \u03BC2Sq), c1);
3016
- var denom2 = math_1.add2d(math_1.add2d(\u03C31Sq, \u03C32Sq), c2);
3017
- return math_1.divide2d(math_1.multiply2d(num1, num2), math_1.multiply2d(denom1, denom2));
3018
- }
3019
- var numerator1 = math_1.multiply2d(\u03BC12, 2);
3020
- var numerator2 = math_1.multiply2d(\u03C312, 2);
3021
- var denominator1 = math_1.add2d(\u03BC1Sq, \u03BC2Sq);
3022
- var denominator2 = math_1.add2d(\u03C31Sq, \u03C32Sq);
3023
- return math_1.divide2d(math_1.multiply2d(numerator1, numerator2), math_1.multiply2d(denominator1, denominator2));
3024
- }
3025
- exports2.originalSsim = originalSsim;
3026
- }
3027
- });
3028
-
3029
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/bezkrovnySsim.js
3030
- var require_bezkrovnySsim = __commonJS({
3031
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/bezkrovnySsim.js"(exports2) {
3032
- "use strict";
3033
- Object.defineProperty(exports2, "__esModule", { value: true });
3034
- exports2.bezkrovnySsim = void 0;
3035
- var math_1 = require_math();
3036
- var matlab_1 = require_matlab();
3037
- function bezkrovnySsim(pixels1, pixels2, options) {
3038
- var windowSize = options.windowSize;
3039
- var width = Math.ceil(pixels1.width / windowSize);
3040
- var height = Math.ceil(pixels1.height / windowSize);
3041
- var data = new Array(width * height);
3042
- var counter = 0;
3043
- for (var y = 0; y < pixels1.height; y += windowSize) {
3044
- for (var x = 0; x < pixels1.width; x += windowSize) {
3045
- var windowWidth = Math.min(windowSize, pixels1.width - x);
3046
- var windowHeight = Math.min(windowSize, pixels1.height - y);
3047
- var values1 = matlab_1.sub(pixels1, x, windowHeight, y, windowWidth);
3048
- var values2 = matlab_1.sub(pixels2, x, windowHeight, y, windowWidth);
3049
- data[counter++] = windowSsim(values1, values2, options);
3050
- }
3051
- }
3052
- return { data, width, height };
3053
- }
3054
- exports2.bezkrovnySsim = bezkrovnySsim;
3055
- function windowSsim(_a, _b, _c) {
3056
- var values1 = _a.data;
3057
- var values2 = _b.data;
3058
- var bitDepth = _c.bitDepth, k1 = _c.k1, k2 = _c.k2;
3059
- var L = Math.pow(2, bitDepth) - 1;
3060
- var c1 = Math.pow(k1 * L, 2);
3061
- var c2 = Math.pow(k2 * L, 2);
3062
- var average1 = math_1.average(values1);
3063
- var average2 = math_1.average(values2);
3064
- var \u03C3Sqx = math_1.variance(values1, average1);
3065
- var \u03C3Sqy = math_1.variance(values2, average2);
3066
- var \u03C3xy = math_1.covariance(values1, values2, average1, average2);
3067
- var numerator = (2 * average1 * average2 + c1) * (2 * \u03C3xy + c2);
3068
- var denom1 = Math.pow(average1, 2) + Math.pow(average2, 2) + c1;
3069
- var denom2 = \u03C3Sqx + \u03C3Sqy + c2;
3070
- return numerator / (denom1 * denom2);
3071
- }
3072
- }
3073
- });
3074
-
3075
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/downsample.js
3076
- var require_downsample = __commonJS({
3077
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/downsample.js"(exports2) {
3078
- "use strict";
3079
- Object.defineProperty(exports2, "__esModule", { value: true });
3080
- exports2.downsample = void 0;
3081
- var math_1 = require_math();
3082
- var matlab_1 = require_matlab();
3083
- function imageDownsample(pixels, filter, f) {
3084
- var imdown = matlab_1.imfilter(pixels, filter, "symmetric", "same");
3085
- return matlab_1.skip2d(imdown, [0, f, imdown.height], [0, f, imdown.width]);
3086
- }
3087
- function originalDownsample(pixels1, pixels2, maxSize) {
3088
- if (maxSize === void 0) {
3089
- maxSize = 256;
3090
- }
3091
- var factor = Math.min(pixels1.width, pixels2.height) / maxSize;
3092
- var f = Math.round(factor);
3093
- if (f > 1) {
3094
- var lpf = matlab_1.ones(f);
3095
- lpf = math_1.divide2d(lpf, math_1.sum2d(lpf));
3096
- pixels1 = imageDownsample(pixels1, lpf, f);
3097
- pixels2 = imageDownsample(pixels2, lpf, f);
3098
- }
3099
- return [pixels1, pixels2];
3100
- }
3101
- function downsample(pixels, options) {
3102
- if (options.downsample === "original") {
3103
- return originalDownsample(pixels[0], pixels[1], options.maxSize);
3104
- }
3105
- return pixels;
3106
- }
3107
- exports2.downsample = downsample;
3108
- }
3109
- });
3110
-
3111
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/defaults.js
3112
- var require_defaults = __commonJS({
3113
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/defaults.js"(exports2) {
3114
- "use strict";
3115
- Object.defineProperty(exports2, "__esModule", { value: true });
3116
- exports2.defaults = void 0;
3117
- exports2.defaults = {
3118
- windowSize: 11,
3119
- k1: 0.01,
3120
- k2: 0.03,
3121
- bitDepth: 8,
3122
- downsample: "original",
3123
- ssim: "weber",
3124
- maxSize: 256,
3125
- rgb2grayVersion: "integer"
3126
- };
3127
- }
3128
- });
3129
-
3130
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/weberSsim.js
3131
- var require_weberSsim = __commonJS({
3132
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/weberSsim.js"(exports2) {
3133
- "use strict";
3134
- var __assign = exports2 && exports2.__assign || function() {
3135
- __assign = Object.assign || function(t) {
3136
- for (var s, i = 1, n = arguments.length; i < n; i++) {
3137
- s = arguments[i];
3138
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3139
- t[p] = s[p];
3140
- }
3141
- return t;
3142
- };
3143
- return __assign.apply(this, arguments);
3144
- };
3145
- Object.defineProperty(exports2, "__esModule", { value: true });
3146
- exports2.weberSsim = exports2.windowCovariance = exports2.windowVariance = exports2.windowSums = exports2.windowMatrix = exports2.partialSumMatrix2 = exports2.partialSumMatrix1 = void 0;
3147
- function edgeHandler(w, h, sumArray, matrixWidth) {
3148
- var rightEdge = sumArray[h * matrixWidth + w + 1];
3149
- var bottomEdge = sumArray[(h + 1) * matrixWidth + w];
3150
- var bottomRightEdge = sumArray[(h + 1) * matrixWidth + w + 1];
3151
- return { rightEdge, bottomEdge, bottomRightEdge };
3152
- }
3153
- function partialSumMatrix1(pixels, f) {
3154
- var width = pixels.width, height = pixels.height, data = pixels.data;
3155
- var matrixWidth = width + 1;
3156
- var matrixHeight = height + 1;
3157
- var sumArray = new Int32Array(matrixWidth * matrixHeight);
3158
- for (var h = height - 1; h >= 0; --h) {
3159
- for (var w = width - 1; w >= 0; --w) {
3160
- var _a = edgeHandler(w, h, sumArray, matrixWidth), rightEdge = _a.rightEdge, bottomEdge = _a.bottomEdge, bottomRightEdge = _a.bottomRightEdge;
3161
- sumArray[h * matrixWidth + w] = f(data[h * width + w], w, h) + rightEdge + bottomEdge - bottomRightEdge;
3162
- }
3163
- }
3164
- return { data: sumArray, height: matrixHeight, width: matrixWidth };
3165
- }
3166
- exports2.partialSumMatrix1 = partialSumMatrix1;
3167
- function partialSumMatrix2(pixels1, pixels2, f) {
3168
- var width = pixels1.width, height = pixels1.height, data1 = pixels1.data;
3169
- var data2 = pixels2.data;
3170
- var matrixWidth = width + 1;
3171
- var matrixHeight = height + 1;
3172
- var sumArray = new Int32Array(matrixWidth * matrixHeight);
3173
- for (var h = height - 1; h >= 0; --h) {
3174
- for (var w = width - 1; w >= 0; --w) {
3175
- var _a = edgeHandler(w, h, sumArray, matrixWidth), rightEdge = _a.rightEdge, bottomEdge = _a.bottomEdge, bottomRightEdge = _a.bottomRightEdge;
3176
- var offset = h * width + w;
3177
- sumArray[h * matrixWidth + w] = f(data1[offset], data2[offset], w, h) + rightEdge + bottomEdge - bottomRightEdge;
3178
- }
3179
- }
3180
- return { data: sumArray, height: matrixHeight, width: matrixWidth };
3181
- }
3182
- exports2.partialSumMatrix2 = partialSumMatrix2;
3183
- function windowMatrix(sumMatrix, windowSize, divisor) {
3184
- var matrixWidth = sumMatrix.width, matrixHeight = sumMatrix.height, sumArray = sumMatrix.data;
3185
- var imageWidth = matrixWidth - 1;
3186
- var imageHeight = matrixHeight - 1;
3187
- var windowWidth = imageWidth - windowSize + 1;
3188
- var windowHeight = imageHeight - windowSize + 1;
3189
- var windows = new Int32Array(windowWidth * windowHeight);
3190
- for (var h = 0; h < imageHeight; ++h) {
3191
- for (var w = 0; w < imageWidth; ++w) {
3192
- if (w < windowWidth && h < windowHeight) {
3193
- var sum = (
3194
- // value at (w,h)
3195
- sumArray[matrixWidth * h + w] - // value at (w+windowSize,h) == right side
3196
- sumArray[matrixWidth * h + w + windowSize] - // value at (w,h+windowSize) == bottom side
3197
- sumArray[matrixWidth * (h + windowSize) + w] + // value at (w+windowSize, h+windowSize) == bottomRight corner
3198
- sumArray[matrixWidth * (h + windowSize) + w + windowSize]
3199
- );
3200
- windows[h * windowWidth + w] = sum / divisor;
3201
- }
3202
- }
3203
- }
3204
- return { height: windowHeight, width: windowWidth, data: windows };
3205
- }
3206
- exports2.windowMatrix = windowMatrix;
3207
- function windowSums(pixels, windowSize) {
3208
- return windowMatrix(partialSumMatrix1(pixels, function(a) {
3209
- return a;
3210
- }), windowSize, 1);
3211
- }
3212
- exports2.windowSums = windowSums;
3213
- function windowVariance(pixels, sums, windowSize) {
3214
- var varianceCalculation = function(v) {
3215
- return v * v;
3216
- };
3217
- var windowSquared = windowSize * windowSize;
3218
- var varX = windowMatrix(partialSumMatrix1(pixels, varianceCalculation), windowSize, 1);
3219
- for (var i = 0; i < sums.data.length; ++i) {
3220
- var mean = sums.data[i] / windowSquared;
3221
- var sumSquares = varX.data[i] / windowSquared;
3222
- var squareMeans = mean * mean;
3223
- varX.data[i] = 1024 * (sumSquares - squareMeans);
3224
- }
3225
- return varX;
3226
- }
3227
- exports2.windowVariance = windowVariance;
3228
- function windowCovariance(pixels1, pixels2, sums1, sums2, windowSize) {
3229
- var covarianceCalculation = function(a, b) {
3230
- return a * b;
3231
- };
3232
- var windowSquared = windowSize * windowSize;
3233
- var covXY = windowMatrix(partialSumMatrix2(pixels1, pixels2, covarianceCalculation), windowSize, 1);
3234
- for (var i = 0; i < sums1.data.length; ++i) {
3235
- covXY.data[i] = 1024 * (covXY.data[i] / windowSquared - sums1.data[i] / windowSquared * (sums2.data[i] / windowSquared));
3236
- }
3237
- return covXY;
3238
- }
3239
- exports2.windowCovariance = windowCovariance;
3240
- function weberSsim(pixels1, pixels2, options) {
3241
- var bitDepth = options.bitDepth, k1 = options.k1, k2 = options.k2, windowSize = options.windowSize;
3242
- var L = Math.pow(2, bitDepth) - 1;
3243
- var c1 = k1 * L * (k1 * L);
3244
- var c2 = k2 * L * (k2 * L);
3245
- var windowSquared = windowSize * windowSize;
3246
- var pixels1Rounded = __assign(__assign({}, pixels1), { data: Int32Array.from(pixels1.data, function(v) {
3247
- return v + 0.5;
3248
- }) });
3249
- var pixels2Rounded = __assign(__assign({}, pixels2), { data: Int32Array.from(pixels2.data, function(v) {
3250
- return v + 0.5;
3251
- }) });
3252
- var sums1 = windowSums(pixels1Rounded, windowSize);
3253
- var variance1 = windowVariance(pixels1Rounded, sums1, windowSize);
3254
- var sums2 = windowSums(pixels2Rounded, windowSize);
3255
- var variance2 = windowVariance(pixels2Rounded, sums2, windowSize);
3256
- var covariance = windowCovariance(pixels1Rounded, pixels2Rounded, sums1, sums2, windowSize);
3257
- var size = sums1.data.length;
3258
- var mssim = 0;
3259
- var ssims = new Array(size);
3260
- for (var i = 0; i < size; ++i) {
3261
- var meanx = sums1.data[i] / windowSquared;
3262
- var meany = sums2.data[i] / windowSquared;
3263
- var varx = variance1.data[i] / 1024;
3264
- var vary = variance2.data[i] / 1024;
3265
- var cov = covariance.data[i] / 1024;
3266
- var na = 2 * meanx * meany + c1;
3267
- var nb = 2 * cov + c2;
3268
- var da = meanx * meanx + meany * meany + c1;
3269
- var db = varx + vary + c2;
3270
- var ssim = na * nb / da / db;
3271
- ssims[i] = ssim;
3272
- if (i == 0) {
3273
- mssim = ssim;
3274
- } else {
3275
- mssim = mssim + (ssim - mssim) / (i + 1);
3276
- }
3277
- }
3278
- return { data: ssims, width: sums1.width, height: sums1.height, mssim };
3279
- }
3280
- exports2.weberSsim = weberSsim;
3281
- }
3282
- });
3283
-
3284
- // ../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/index.js
3285
- var require_dist = __commonJS({
3286
- "../../node_modules/.pnpm/ssim.js@3.5.0/node_modules/ssim.js/dist/index.js"(exports2) {
3287
- "use strict";
3288
- var __assign = exports2 && exports2.__assign || function() {
3289
- __assign = Object.assign || function(t) {
3290
- for (var s, i = 1, n = arguments.length; i < n; i++) {
3291
- s = arguments[i];
3292
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3293
- t[p] = s[p];
3294
- }
3295
- return t;
3296
- };
3297
- return __assign.apply(this, arguments);
3298
- };
3299
- Object.defineProperty(exports2, "__esModule", { value: true });
3300
- exports2.ssim = exports2.getOptions = void 0;
3301
- var matlab_1 = require_matlab();
3302
- var math_1 = require_math();
3303
- var ssim_1 = require_ssim();
3304
- var originalSsim_1 = require_originalSsim();
3305
- var bezkrovnySsim_1 = require_bezkrovnySsim();
3306
- var downsample_1 = require_downsample();
3307
- var defaults_1 = require_defaults();
3308
- var weberSsim_1 = require_weberSsim();
3309
- var ssimTargets = {
3310
- fast: ssim_1.ssim,
3311
- original: originalSsim_1.originalSsim,
3312
- bezkrovny: bezkrovnySsim_1.bezkrovnySsim,
3313
- weber: weberSsim_1.weberSsim
3314
- };
3315
- function validateOptions(options) {
3316
- Object.keys(options).forEach(function(option) {
3317
- if (!(option in defaults_1.defaults)) {
3318
- throw new Error('"' + option + '" is not a valid option');
3319
- }
3320
- });
3321
- if ("k1" in options && (typeof options.k1 !== "number" || options.k1 < 0)) {
3322
- throw new Error("Invalid k1 value. Default is " + defaults_1.defaults.k1);
3323
- }
3324
- if ("k2" in options && (typeof options.k2 !== "number" || options.k2 < 0)) {
3325
- throw new Error("Invalid k2 value. Default is " + defaults_1.defaults.k2);
3326
- }
3327
- if (!(options.ssim in ssimTargets)) {
3328
- throw new Error("Invalid ssim option (use: " + Object.keys(ssimTargets).join(", ") + ")");
3329
- }
3330
- }
3331
- function getOptions(userOptions) {
3332
- var options = __assign(__assign({}, defaults_1.defaults), userOptions);
3333
- validateOptions(options);
3334
- return options;
3335
- }
3336
- exports2.getOptions = getOptions;
3337
- function validateDimensions(_a) {
3338
- var pixels1 = _a[0], pixels2 = _a[1], options = _a[2];
3339
- if (pixels1.width !== pixels2.width || pixels1.height !== pixels2.height) {
3340
- throw new Error("Image dimensions do not match");
3341
- }
3342
- return [pixels1, pixels2, options];
3343
- }
3344
- function toGrayScale(_a) {
3345
- var pixels1 = _a[0], pixels2 = _a[1], options = _a[2];
3346
- if (options.rgb2grayVersion === "original") {
3347
- return [matlab_1.rgb2gray(pixels1), matlab_1.rgb2gray(pixels2), options];
3348
- } else {
3349
- return [matlab_1.rgb2grayInteger(pixels1), matlab_1.rgb2grayInteger(pixels2), options];
3350
- }
3351
- }
3352
- function toResize(_a) {
3353
- var pixels1 = _a[0], pixels2 = _a[1], options = _a[2];
3354
- var pixels = downsample_1.downsample([pixels1, pixels2], options);
3355
- return [pixels[0], pixels[1], options];
3356
- }
3357
- function comparison(_a) {
3358
- var pixels1 = _a[0], pixels2 = _a[1], options = _a[2];
3359
- return ssimTargets[options.ssim](pixels1, pixels2, options);
3360
- }
3361
- function ssim(image1, image2, userOptions) {
3362
- var start = (/* @__PURE__ */ new Date()).getTime();
3363
- var options = getOptions(userOptions);
3364
- var ssimMap = comparison(toResize(toGrayScale(validateDimensions([image1, image2, options]))));
3365
- var mssim = ssimMap.mssim !== void 0 ? ssimMap.mssim : math_1.mean2d(ssimMap);
3366
- return {
3367
- mssim,
3368
- ssim_map: ssimMap,
3369
- performance: (/* @__PURE__ */ new Date()).getTime() - start
3370
- };
3371
- }
3372
- exports2.ssim = ssim;
3373
- exports2.default = ssim;
3374
- }
3375
- });
3376
-
3377
- // src/verify/index.ts
3378
- var verify_exports = {};
3379
- __export(verify_exports, {
3380
- CALIBRATION_PROVENANCE: () => CALIBRATION_PROVENANCE,
3381
- PIXELMATCH_THRESHOLD: () => PIXELMATCH_THRESHOLD,
3382
- PIXEL_DIFF_MAX: () => PIXEL_DIFF_MAX,
3383
- SSIM_MIN: () => SSIM_MIN,
3384
- assertDeterministic: () => assertDeterministic,
3385
- checkDeterminism: () => checkDeterminism,
3386
- computeSsim: () => computeSsim,
3387
- cropPng: () => cropPng,
3388
- decodePng: () => decodePng,
3389
- diffFiles: () => diffFiles,
3390
- diffImages: () => diffImages,
3391
- laplacianVariance: () => laplacianVariance,
3392
- loadPng: () => loadPng,
3393
- renderProofHtml: () => renderProofHtml,
3394
- verdict: () => verdict,
3395
- writeProof: () => writeProof
3396
- });
3397
- module.exports = __toCommonJS(verify_exports);
3398
-
3399
- // src/verify/diff.ts
3400
- var import_promises = require("fs/promises");
3401
- var import_node_path = require("path");
3402
-
3403
- // ../../node_modules/.pnpm/pixelmatch@7.2.0/node_modules/pixelmatch/index.js
3404
- function pixelmatch(img1, img2, output, width, height, options = {}) {
3405
- const {
3406
- threshold = 0.1,
3407
- alpha = 0.1,
3408
- aaColor = [255, 255, 0],
3409
- diffColor = [255, 0, 0],
3410
- checkerboard = true,
3411
- includeAA,
3412
- diffColorAlt,
3413
- diffMask
3414
- } = options;
3415
- if (!isPixelData(img1) || !isPixelData(img2) || output && !isPixelData(output))
3416
- throw new Error("Image data: Uint8Array, Uint8ClampedArray or Buffer expected.");
3417
- if (img1.length !== img2.length || output && output.length !== img1.length)
3418
- throw new Error(`Image sizes do not match. Image 1 size: ${img1.length}, image 2 size: ${img2.length}`);
3419
- if (img1.length !== width * height * 4) throw new Error(`Image data size does not match width/height. Expecting ${width * height * 4}. Got ${img1.length}`);
3420
- const len = width * height;
3421
- const a32 = new Uint32Array(img1.buffer, img1.byteOffset, len);
3422
- const b32 = new Uint32Array(img2.buffer, img2.byteOffset, len);
3423
- let identical = true;
3424
- for (let i = 0; i < len; i++) {
3425
- if (a32[i] !== b32[i]) {
3426
- identical = false;
3427
- break;
3428
- }
3429
- }
3430
- if (identical) {
3431
- if (output && !diffMask) {
3432
- for (let i = 0, pos = 0; i < len; i++, pos += 4) drawGrayPixel(img1, pos, alpha, output);
3433
- }
3434
- return 0;
3435
- }
3436
- const maxDelta = 35215 * threshold * threshold;
3437
- const [aaR, aaG, aaB] = aaColor;
3438
- const [diffR, diffG, diffB] = diffColor;
3439
- const [altR, altG, altB] = diffColorAlt || diffColor;
3440
- let diff = 0;
3441
- for (let i = 0, pos = 0; i < len; i++, pos += 4) {
3442
- const delta = a32[i] === b32[i] ? 0 : colorDelta(img1, img2, pos, pos, checkerboard);
3443
- if (Math.abs(delta) > maxDelta) {
3444
- const x = i % width;
3445
- const y = i / width | 0;
3446
- const isExcludedAA = !includeAA && (antialiased(img1, x, y, width, height, a32, b32, checkerboard) || antialiased(img2, x, y, width, height, b32, a32, checkerboard));
3447
- if (isExcludedAA) {
3448
- if (output && !diffMask) drawPixel(output, pos, aaR, aaG, aaB);
3449
- } else {
3450
- if (output) {
3451
- if (delta < 0) {
3452
- drawPixel(output, pos, altR, altG, altB);
3453
- } else {
3454
- drawPixel(output, pos, diffR, diffG, diffB);
3455
- }
3456
- }
3457
- diff++;
3458
- }
3459
- } else if (output && !diffMask) {
3460
- drawGrayPixel(img1, pos, alpha, output);
3461
- }
3462
- }
3463
- return diff;
3464
- }
3465
- function isPixelData(arr) {
3466
- return ArrayBuffer.isView(arr) && arr.BYTES_PER_ELEMENT === 1;
3467
- }
3468
- function antialiased(img, x1, y1, width, height, a32, b32, checkerboard) {
3469
- const x0 = Math.max(x1 - 1, 0);
3470
- const y0 = Math.max(y1 - 1, 0);
3471
- const x2 = Math.min(x1 + 1, width - 1);
3472
- const y2 = Math.min(y1 + 1, height - 1);
3473
- const pos4 = (y1 * width + x1) * 4;
3474
- const cr = img[pos4];
3475
- const cg = img[pos4 + 1];
3476
- const cb = img[pos4 + 2];
3477
- const ca = img[pos4 + 3];
3478
- let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
3479
- let min = 0;
3480
- let max = 0;
3481
- let minX = 0;
3482
- let minY = 0;
3483
- let maxX = 0;
3484
- let maxY = 0;
3485
- for (let x = x0; x <= x2; x++) {
3486
- for (let y = y0; y <= y2; y++) {
3487
- if (x === x1 && y === y1) continue;
3488
- const delta = brightnessDelta(img, pos4, (y * width + x) * 4, cr, cg, cb, ca, checkerboard);
3489
- if (delta === 0) {
3490
- zeroes++;
3491
- if (zeroes > 2) return false;
3492
- } else if (delta < min) {
3493
- min = delta;
3494
- minX = x;
3495
- minY = y;
3496
- } else if (delta > max) {
3497
- max = delta;
3498
- maxX = x;
3499
- maxY = y;
3500
- }
3501
- }
3502
- }
3503
- if (min === 0 || max === 0) return false;
3504
- return hasManySiblings(a32, minX, minY, width, height) && hasManySiblings(b32, minX, minY, width, height) || hasManySiblings(a32, maxX, maxY, width, height) && hasManySiblings(b32, maxX, maxY, width, height);
3505
- }
3506
- function hasManySiblings(img, x1, y1, width, height) {
3507
- const x0 = Math.max(x1 - 1, 0);
3508
- const y0 = Math.max(y1 - 1, 0);
3509
- const x2 = Math.min(x1 + 1, width - 1);
3510
- const y2 = Math.min(y1 + 1, height - 1);
3511
- const val = img[y1 * width + x1];
3512
- let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
3513
- for (let x = x0; x <= x2; x++) {
3514
- for (let y = y0; y <= y2; y++) {
3515
- if (x === x1 && y === y1) continue;
3516
- zeroes += +(val === img[y * width + x]);
3517
- if (zeroes > 2) return true;
3518
- }
3519
- }
3520
- return false;
3521
- }
3522
- function colorDelta(img1, img2, k, m, checkerboard) {
3523
- const r1 = img1[k];
3524
- const g1 = img1[k + 1];
3525
- const b1 = img1[k + 2];
3526
- const a1 = img1[k + 3];
3527
- const r2 = img2[m];
3528
- const g2 = img2[m + 1];
3529
- const b2 = img2[m + 2];
3530
- const a2 = img2[m + 3];
3531
- let dr = r1 - r2;
3532
- let dg = g1 - g2;
3533
- let db = b1 - b2;
3534
- const da = a1 - a2;
3535
- if (a1 < 255 || a2 < 255) {
3536
- let rb = 255, gb = 255, bb = 255;
3537
- if (checkerboard) {
3538
- rb = 48 + 159 * (k % 2);
3539
- gb = 48 + 159 * ((k / 1.618033988749895 | 0) % 2);
3540
- bb = 48 + 159 * ((k / 2.618033988749895 | 0) % 2);
3541
- }
3542
- dr = (r1 * a1 - r2 * a2 - rb * da) / 255;
3543
- dg = (g1 * a1 - g2 * a2 - gb * da) / 255;
3544
- db = (b1 * a1 - b2 * a2 - bb * da) / 255;
3545
- }
3546
- const y = dr * 0.29889531 + dg * 0.58662247 + db * 0.11448223;
3547
- const i = dr * 0.59597799 - dg * 0.2741761 - db * 0.32180189;
3548
- const q = dr * 0.21147017 - dg * 0.52261711 + db * 0.31114694;
3549
- const delta = 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q;
3550
- return y > 0 ? -delta : delta;
3551
- }
3552
- function brightnessDelta(img, k, m, r1, g1, b1, a1, checkerboard) {
3553
- const r2 = img[m];
3554
- const g2 = img[m + 1];
3555
- const b2 = img[m + 2];
3556
- const a2 = img[m + 3];
3557
- let dr = r1 - r2;
3558
- let dg = g1 - g2;
3559
- let db = b1 - b2;
3560
- const da = a1 - a2;
3561
- if (!dr && !dg && !db && !da) return 0;
3562
- if (a1 < 255 || a2 < 255) {
3563
- let rb = 255, gb = 255, bb = 255;
3564
- if (checkerboard) {
3565
- rb = 48 + 159 * (k % 2);
3566
- gb = 48 + 159 * ((k / 1.618033988749895 | 0) % 2);
3567
- bb = 48 + 159 * ((k / 2.618033988749895 | 0) % 2);
3568
- }
3569
- dr = (r1 * a1 - r2 * a2 - rb * da) / 255;
3570
- dg = (g1 * a1 - g2 * a2 - gb * da) / 255;
3571
- db = (b1 * a1 - b2 * a2 - bb * da) / 255;
3572
- }
3573
- return dr * 0.29889531 + dg * 0.58662247 + db * 0.11448223;
3574
- }
3575
- function drawPixel(output, pos, r, g, b) {
3576
- output[pos] = r;
3577
- output[pos + 1] = g;
3578
- output[pos + 2] = b;
3579
- output[pos + 3] = 255;
3580
- }
3581
- function drawGrayPixel(img, i, alpha, output) {
3582
- const val = 255 + (img[i] * 0.29889531 + img[i + 1] * 0.58662247 + img[i + 2] * 0.11448223 - 255) * alpha * img[i + 3] / 255;
3583
- drawPixel(output, i, val, val, val);
3584
- }
3585
-
3586
- // src/verify/diff.ts
3587
- var import_pngjs = __toESM(require_png(), 1);
3588
- var import_ssim = __toESM(require_dist(), 1);
3589
- var PIXELMATCH_THRESHOLD = 0.1;
3590
- function toRgba(png) {
3591
- return {
3592
- data: new Uint8ClampedArray(png.data.buffer, png.data.byteOffset, png.data.length),
3593
- width: png.width,
3594
- height: png.height
3595
- };
3596
- }
3597
- async function loadPng(path) {
3598
- return toRgba(import_pngjs.PNG.sync.read(await (0, import_promises.readFile)(path)));
3599
- }
3600
- function decodePng(buffer) {
3601
- return toRgba(import_pngjs.PNG.sync.read(buffer));
3602
- }
3603
- function assertSameSize(a, b) {
3604
- if (a.width !== b.width || a.height !== b.height) {
3605
- throw new Error(
3606
- `Image dimensions differ: ${a.width}x${a.height} vs ${b.width}x${b.height}. The calibrated diff requires same-settings captures; resize upstream before diffing.`
3607
- );
3608
- }
3609
- }
3610
- function computeSsim(a, b) {
3611
- const result = (0, import_ssim.ssim)(
3612
- { data: a.data, width: a.width, height: a.height },
3613
- { data: b.data, width: b.width, height: b.height },
3614
- { ssim: "fast" }
3615
- );
3616
- return roundTo(result.mssim, 4);
3617
- }
3618
- function diffImages(a, b) {
3619
- assertSameSize(a, b);
3620
- const { width, height } = a;
3621
- const heatmap = new import_pngjs.PNG({ width, height });
3622
- const diffPixels = pixelmatch(a.data, b.data, heatmap.data, width, height, {
3623
- threshold: PIXELMATCH_THRESHOLD,
3624
- includeAA: false,
3625
- alpha: 0.3,
3626
- diffColor: [255, 0, 0]
3627
- });
3628
- const pixelDiffPct = roundTo(diffPixels / (width * height) * 100, 4);
3629
- return {
3630
- pixelDiffPct,
3631
- ssim: computeSsim(a, b),
3632
- width,
3633
- height,
3634
- diffPixels,
3635
- heatmapPng: import_pngjs.PNG.sync.write(heatmap)
3636
- };
3637
- }
3638
- async function diffFiles(refPath, recPath, opts = {}) {
3639
- const [ref, rec] = await Promise.all([loadPng(refPath), loadPng(recPath)]);
3640
- const result = diffImages(ref, rec);
3641
- if (opts.heatmapPath) {
3642
- await (0, import_promises.mkdir)((0, import_node_path.dirname)(opts.heatmapPath), { recursive: true });
3643
- await (0, import_promises.writeFile)(opts.heatmapPath, result.heatmapPng);
3644
- }
3645
- return result;
3646
- }
3647
- function roundTo(value, places) {
3648
- if (!Number.isFinite(value)) return value;
3649
- const factor = 10 ** places;
3650
- return Math.round(value * factor) / factor;
3651
- }
3652
-
3653
- // src/verify/thresholds.ts
3654
- var CALIBRATION_PROVENANCE = "single-rater (jake), provisional \u2014 70 pairs, honesty 3/3, kappa n/a (n=1)";
3655
- var PIXEL_DIFF_MAX = 1.82335;
3656
- var SSIM_MIN = 0.9905;
3657
- function verdict(metrics) {
3658
- const pixelOk = metrics.pixelDiffPct <= PIXEL_DIFF_MAX;
3659
- const ssimOk = metrics.ssim >= SSIM_MIN;
3660
- const reason = pixelOk && ssimOk ? "both" : pixelOk ? "pixelDiff" : ssimOk ? "ssim" : "neither";
3661
- return {
3662
- pass: pixelOk || ssimOk,
3663
- reason,
3664
- primaryMetric: "pixelDiff",
3665
- pixelDiffPct: metrics.pixelDiffPct,
3666
- ssim: metrics.ssim,
3667
- thresholds: { pixelDiffMax: PIXEL_DIFF_MAX, ssimMin: SSIM_MIN },
3668
- provenance: CALIBRATION_PROVENANCE
3669
- };
3670
- }
3671
-
3672
- // src/verify/determinism.ts
3673
- var import_node_crypto = require("crypto");
3674
- function sha256(buffers) {
3675
- const hash = (0, import_node_crypto.createHash)("sha256");
3676
- for (const buffer of buffers) hash.update(buffer);
3677
- return hash.digest("hex");
3678
- }
3679
- async function checkDeterminism(produce, runs = 2) {
3680
- if (runs < 2) throw new Error("Determinism check needs at least 2 runs.");
3681
- const allRuns = [];
3682
- for (let i = 0; i < runs; i += 1) {
3683
- allRuns.push(await produce());
3684
- }
3685
- const frameCount = allRuns[0]?.length ?? 0;
3686
- for (const run of allRuns) {
3687
- if (run.length !== frameCount) {
3688
- throw new Error(
3689
- `Non-determinism: runs produced different frame counts (${run.length} vs ${frameCount}).`
3690
- );
3691
- }
3692
- }
3693
- const runHashes = allRuns.map(sha256);
3694
- const byteIdentical = runHashes.every((h) => h === runHashes[0]);
3695
- let maxFramePixelDiff = 0;
3696
- if (!byteIdentical) {
3697
- const base = allRuns[0];
3698
- for (let r = 1; r < allRuns.length; r += 1) {
3699
- const other = allRuns[r];
3700
- for (let f = 0; f < frameCount; f += 1) {
3701
- const a = base[f];
3702
- const b = other[f];
3703
- if (a.equals(b)) continue;
3704
- const { pixelDiffPct } = diffImages(decodePng(a), decodePng(b));
3705
- if (pixelDiffPct > maxFramePixelDiff) maxFramePixelDiff = pixelDiffPct;
3706
- }
3707
- }
3708
- }
3709
- return { runs, frameCount, byteIdentical, maxFramePixelDiff, runHashes };
3710
- }
3711
- async function assertDeterministic(produce, runs = 2) {
3712
- const result = await checkDeterminism(produce, runs);
3713
- if (!result.byteIdentical) {
3714
- throw new Error(
3715
- `Render is non-deterministic: maxFramePixelDiff=${result.maxFramePixelDiff}% over ${result.frameCount} frames (hashes: ${result.runHashes.join(", ")}).`
3716
- );
3717
- }
3718
- return result;
3719
- }
3720
-
3721
- // src/verify/proof.ts
3722
- var import_promises2 = require("fs/promises");
3723
- var import_node_path2 = require("path");
3724
- var STYLE = `
3725
- :root{color-scheme:light dark}
3726
- body{font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:0;padding:24px;background:#0b0d10;color:#e6e9ef}
3727
- h1{font-size:20px;margin:0 0 4px}h2{font-size:15px;margin:28px 0 10px;color:#9aa4b2}
3728
- .sub{color:#9aa4b2;margin:0 0 16px}
3729
- .verdict{display:inline-block;padding:6px 14px;border-radius:8px;font-weight:600;letter-spacing:.02em}
3730
- .pass{background:#0f3d23;color:#5ee08f;border:1px solid #1d6b3f}
3731
- .fail{background:#3d0f14;color:#ff7a85;border:1px solid #6b1d27}
3732
- table{border-collapse:collapse;width:100%;margin:8px 0}
3733
- td,th{border:1px solid #1f2630;padding:8px 10px;text-align:left;vertical-align:top}
3734
- th{color:#9aa4b2;font-weight:600}
3735
- .grid{display:grid;grid-template-columns:1fr 1fr 1fr;gap:10px;margin:10px 0}
3736
- .cell{border:1px solid #1f2630;border-radius:8px;padding:8px;background:#11151b}
3737
- .cell h3{margin:0 0 6px;font-size:12px;color:#9aa4b2;font-weight:600}
3738
- img{max-width:100%;height:auto;display:block;border-radius:4px;background:#000}
3739
- .contact{display:flex;flex-wrap:wrap;gap:4px}.contact img{width:120px}
3740
- video{max-width:100%;border-radius:8px;background:#000}
3741
- .m{font-variant-numeric:tabular-nums}
3742
- .ok{color:#5ee08f}.no{color:#ff7a85}
3743
- .note{color:#6b7686;font-size:12px;margin-top:24px;border-top:1px solid #1f2630;padding-top:12px}
3744
- .fail-box{background:#1a0e10;border:1px solid #6b1d27;border-radius:8px;padding:12px;margin:10px 0}
3745
- `;
3746
- var escape = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
3747
- var dataUri = (buffer, mime = "image/png") => `data:${mime};base64,${buffer.toString("base64")}`;
3748
- function pairBlock(pair) {
3749
- const metric = pair.pixelDiffPct === void 0 && pair.ssim === void 0 ? "" : `<p class="m">pixelDiff <b class="${pair.pass === false ? "no" : "ok"}">${pair.pixelDiffPct ?? "\u2014"}%</b> &nbsp; SSIM <b>${pair.ssim ?? "\u2014"}</b>` + (pair.pass === void 0 ? "" : ` &nbsp; ${pair.pass ? '<span class="ok">PASS</span>' : '<span class="no">FAIL</span>'}`) + `</p>`;
3750
- const heatmapCell = pair.heatmap ? `<div class="cell"><h3>diff heatmap</h3><img src="${dataUri(pair.heatmap)}"/></div>` : "";
3751
- return `<h2>${escape(pair.label)}</h2>${metric}<div class="grid">
3752
- <div class="cell"><h3>${escape(pair.aCaption ?? "reconstruction")}</h3><img src="${dataUri(pair.a)}"/></div>
3753
- <div class="cell"><h3>${escape(pair.bCaption ?? "ground truth")}</h3><img src="${dataUri(pair.b)}"/></div>
3754
- ${heatmapCell}
3755
- </div>`;
3756
- }
3757
- function renderProofHtml(opts) {
3758
- const parts = [];
3759
- parts.push(`<h1>${escape(opts.title)}</h1>`);
3760
- if (opts.subtitle) parts.push(`<p class="sub">${escape(opts.subtitle)}</p>`);
3761
- if (opts.verdict) {
3762
- const v = opts.verdict;
3763
- parts.push(
3764
- `<span class="verdict ${v.pass ? "pass" : "fail"}">${v.pass ? "INDISTINGUISHABLE" : "DISTINGUISHABLE"} \u2014 pixelDiff ${v.pixelDiffPct}% (max ${v.thresholds.pixelDiffMax}%), SSIM ${v.ssim} (min ${v.thresholds.ssimMin}), via ${v.reason}</span>`
3765
- );
3766
- }
3767
- if (opts.failure) {
3768
- const f = opts.failure;
3769
- parts.push(
3770
- `<div class="fail-box"><b>Failure detail.</b> ` + [
3771
- f.frameIndex !== void 0 ? `frame #${f.frameIndex}` : "",
3772
- f.selector ? `selector <code>${escape(f.selector)}</code>` : "",
3773
- f.note ? escape(f.note) : ""
3774
- ].filter(Boolean).join(" \xB7 ") + `</div>`
3775
- );
3776
- }
3777
- if (opts.metrics?.length) {
3778
- parts.push(
3779
- `<h2>metrics</h2><table><tr><th>metric</th><th>value</th></tr>` + opts.metrics.map(
3780
- (m) => `<tr><td>${escape(m.label)}</td><td class="m ${m.pass === void 0 ? "" : m.pass ? "ok" : "no"}">${escape(m.value)}</td></tr>`
3781
- ).join("") + `</table>`
3782
- );
3783
- }
3784
- for (const chart of opts.charts ?? []) parts.push(chart);
3785
- for (const pair of opts.pairs ?? []) parts.push(pairBlock(pair));
3786
- if (opts.video) {
3787
- parts.push(
3788
- `<h2>render</h2><video controls autoplay loop muted src="${dataUri(opts.video.data, opts.video.mime)}"></video>`
3789
- );
3790
- }
3791
- if (opts.frames?.length) {
3792
- parts.push(
3793
- `<h2>frame contact-sheet (${opts.frames.length})</h2><div class="contact">` + opts.frames.map((f) => `<img src="${dataUri(f)}"/>`).join("") + `</div>`
3794
- );
3795
- }
3796
- if (opts.note) parts.push(`<p class="note">${escape(opts.note)}</p>`);
3797
- return `<!doctype html><html><head><meta charset="utf-8"><title>${escape(opts.title)}</title><style>${STYLE}</style></head><body>${parts.join("\n")}</body></html>`;
3798
- }
3799
- async function writeProof(opts) {
3800
- await (0, import_promises2.mkdir)(opts.outDir, { recursive: true });
3801
- const htmlPath = (0, import_node_path2.join)(opts.outDir, "index.html");
3802
- await (0, import_promises2.writeFile)(htmlPath, renderProofHtml(opts), "utf8");
3803
- return htmlPath;
3804
- }
3805
-
3806
- // src/verify/sharpness.ts
3807
- var import_pngjs2 = __toESM(require_png(), 1);
3808
- function decode(buffer) {
3809
- const png = import_pngjs2.PNG.sync.read(buffer);
3810
- return { data: png.data, width: png.width, height: png.height };
3811
- }
3812
- function lumaAt(data, idx) {
3813
- return 0.299 * data[idx] + 0.587 * data[idx + 1] + 0.114 * data[idx + 2];
3814
- }
3815
- function laplacianVariance(pngBuffer, region) {
3816
- const { data, width, height } = decode(pngBuffer);
3817
- const x0 = Math.max(1, Math.floor(region.x));
3818
- const y0 = Math.max(1, Math.floor(region.y));
3819
- const x1 = Math.min(width - 1, Math.floor(region.x + region.width));
3820
- const y1 = Math.min(height - 1, Math.floor(region.y + region.height));
3821
- if (x1 <= x0 || y1 <= y0) return 0;
3822
- const lap = [];
3823
- for (let y = y0; y < y1; y++) {
3824
- for (let x = x0; x < x1; x++) {
3825
- const c = (y * width + x) * 4;
3826
- const up = ((y - 1) * width + x) * 4;
3827
- const down = ((y + 1) * width + x) * 4;
3828
- const left = (y * width + (x - 1)) * 4;
3829
- const right = (y * width + (x + 1)) * 4;
3830
- const value = 4 * lumaAt(data, c) - lumaAt(data, up) - lumaAt(data, down) - lumaAt(data, left) - lumaAt(data, right);
3831
- lap.push(value);
3832
- }
3833
- }
3834
- if (lap.length === 0) return 0;
3835
- let mean = 0;
3836
- for (const v of lap) mean += v;
3837
- mean /= lap.length;
3838
- let variance = 0;
3839
- for (const v of lap) variance += (v - mean) * (v - mean);
3840
- variance /= lap.length;
3841
- return variance;
3842
- }
3843
- function cropPng(pngBuffer, region) {
3844
- const png = import_pngjs2.PNG.sync.read(pngBuffer);
3845
- const x0 = Math.max(0, Math.floor(region.x));
3846
- const y0 = Math.max(0, Math.floor(region.y));
3847
- const w = Math.min(png.width - x0, Math.floor(region.width));
3848
- const h = Math.min(png.height - y0, Math.floor(region.height));
3849
- const out = new import_pngjs2.PNG({ width: w, height: h });
3850
- for (let y = 0; y < h; y++) {
3851
- for (let x = 0; x < w; x++) {
3852
- const src = ((y + y0) * png.width + (x + x0)) * 4;
3853
- const dst = (y * w + x) * 4;
3854
- out.data[dst] = png.data[src];
3855
- out.data[dst + 1] = png.data[src + 1];
3856
- out.data[dst + 2] = png.data[src + 2];
3857
- out.data[dst + 3] = png.data[src + 3];
3858
- }
3859
- }
3860
- return import_pngjs2.PNG.sync.write(out);
3861
- }
3862
- // Annotate the CommonJS export names for ESM import in node:
3863
- 0 && (module.exports = {
3864
- CALIBRATION_PROVENANCE,
3865
- PIXELMATCH_THRESHOLD,
3866
- PIXEL_DIFF_MAX,
3867
- SSIM_MIN,
3868
- assertDeterministic,
3869
- checkDeterminism,
3870
- computeSsim,
3871
- cropPng,
3872
- decodePng,
3873
- diffFiles,
3874
- diffImages,
3875
- laplacianVariance,
3876
- loadPng,
3877
- renderProofHtml,
3878
- verdict,
3879
- writeProof
3880
- });