nftychat-universe 0.1.8 → 0.1.10
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.
- package/dist/index.cjs.js +2210 -1918
- package/dist/index.esm.js +2204 -1918
- package/package.json +2 -1
package/dist/index.cjs.js
CHANGED
@@ -5,6 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
var React48 = require('react');
|
6
6
|
var wagmi = require('wagmi');
|
7
7
|
var reactDom = require('react-dom');
|
8
|
+
var require$$1$2 = require('fs');
|
9
|
+
var require$$0 = require('util');
|
10
|
+
var require$$1 = require('stream');
|
11
|
+
var require$$1$1 = require('zlib');
|
12
|
+
var require$$0$1 = require('assert');
|
13
|
+
var require$$3 = require('buffer');
|
8
14
|
var walletConnect$1 = require('wagmi/connectors/walletConnect');
|
9
15
|
var injected$1 = require('wagmi/connectors/injected');
|
10
16
|
var coinbaseWallet = require('wagmi/connectors/coinbaseWallet');
|
@@ -38,6 +44,12 @@ function _interopNamespace(e) {
|
|
38
44
|
|
39
45
|
var React48__namespace = /*#__PURE__*/_interopNamespace(React48);
|
40
46
|
var React48__default = /*#__PURE__*/_interopDefaultLegacy(React48);
|
47
|
+
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
48
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
49
|
+
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
50
|
+
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
51
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
52
|
+
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
41
53
|
var toast__default = /*#__PURE__*/_interopDefaultLegacy(toast);
|
42
54
|
var Popover__default = /*#__PURE__*/_interopDefaultLegacy(Popover);
|
43
55
|
|
@@ -265,232 +277,6 @@ function createMapValueFn(properties) {
|
|
265
277
|
});
|
266
278
|
}
|
267
279
|
|
268
|
-
var global$1 = (typeof global !== "undefined" ? global :
|
269
|
-
typeof self !== "undefined" ? self :
|
270
|
-
typeof window !== "undefined" ? window : {});
|
271
|
-
|
272
|
-
// shim for using process in browser
|
273
|
-
// based off https://github.com/defunctzombie/node-process/blob/master/browser.js
|
274
|
-
|
275
|
-
function defaultSetTimout() {
|
276
|
-
throw new Error('setTimeout has not been defined');
|
277
|
-
}
|
278
|
-
function defaultClearTimeout () {
|
279
|
-
throw new Error('clearTimeout has not been defined');
|
280
|
-
}
|
281
|
-
var cachedSetTimeout = defaultSetTimout;
|
282
|
-
var cachedClearTimeout = defaultClearTimeout;
|
283
|
-
if (typeof global$1.setTimeout === 'function') {
|
284
|
-
cachedSetTimeout = setTimeout;
|
285
|
-
}
|
286
|
-
if (typeof global$1.clearTimeout === 'function') {
|
287
|
-
cachedClearTimeout = clearTimeout;
|
288
|
-
}
|
289
|
-
|
290
|
-
function runTimeout(fun) {
|
291
|
-
if (cachedSetTimeout === setTimeout) {
|
292
|
-
//normal enviroments in sane situations
|
293
|
-
return setTimeout(fun, 0);
|
294
|
-
}
|
295
|
-
// if setTimeout wasn't available but was latter defined
|
296
|
-
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
297
|
-
cachedSetTimeout = setTimeout;
|
298
|
-
return setTimeout(fun, 0);
|
299
|
-
}
|
300
|
-
try {
|
301
|
-
// when when somebody has screwed with setTimeout but no I.E. maddness
|
302
|
-
return cachedSetTimeout(fun, 0);
|
303
|
-
} catch(e){
|
304
|
-
try {
|
305
|
-
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
306
|
-
return cachedSetTimeout.call(null, fun, 0);
|
307
|
-
} catch(e){
|
308
|
-
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
309
|
-
return cachedSetTimeout.call(this, fun, 0);
|
310
|
-
}
|
311
|
-
}
|
312
|
-
|
313
|
-
|
314
|
-
}
|
315
|
-
function runClearTimeout(marker) {
|
316
|
-
if (cachedClearTimeout === clearTimeout) {
|
317
|
-
//normal enviroments in sane situations
|
318
|
-
return clearTimeout(marker);
|
319
|
-
}
|
320
|
-
// if clearTimeout wasn't available but was latter defined
|
321
|
-
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
322
|
-
cachedClearTimeout = clearTimeout;
|
323
|
-
return clearTimeout(marker);
|
324
|
-
}
|
325
|
-
try {
|
326
|
-
// when when somebody has screwed with setTimeout but no I.E. maddness
|
327
|
-
return cachedClearTimeout(marker);
|
328
|
-
} catch (e){
|
329
|
-
try {
|
330
|
-
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
331
|
-
return cachedClearTimeout.call(null, marker);
|
332
|
-
} catch (e){
|
333
|
-
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
334
|
-
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
335
|
-
return cachedClearTimeout.call(this, marker);
|
336
|
-
}
|
337
|
-
}
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
}
|
342
|
-
var queue = [];
|
343
|
-
var draining = false;
|
344
|
-
var currentQueue;
|
345
|
-
var queueIndex = -1;
|
346
|
-
|
347
|
-
function cleanUpNextTick() {
|
348
|
-
if (!draining || !currentQueue) {
|
349
|
-
return;
|
350
|
-
}
|
351
|
-
draining = false;
|
352
|
-
if (currentQueue.length) {
|
353
|
-
queue = currentQueue.concat(queue);
|
354
|
-
} else {
|
355
|
-
queueIndex = -1;
|
356
|
-
}
|
357
|
-
if (queue.length) {
|
358
|
-
drainQueue();
|
359
|
-
}
|
360
|
-
}
|
361
|
-
|
362
|
-
function drainQueue() {
|
363
|
-
if (draining) {
|
364
|
-
return;
|
365
|
-
}
|
366
|
-
var timeout = runTimeout(cleanUpNextTick);
|
367
|
-
draining = true;
|
368
|
-
|
369
|
-
var len = queue.length;
|
370
|
-
while(len) {
|
371
|
-
currentQueue = queue;
|
372
|
-
queue = [];
|
373
|
-
while (++queueIndex < len) {
|
374
|
-
if (currentQueue) {
|
375
|
-
currentQueue[queueIndex].run();
|
376
|
-
}
|
377
|
-
}
|
378
|
-
queueIndex = -1;
|
379
|
-
len = queue.length;
|
380
|
-
}
|
381
|
-
currentQueue = null;
|
382
|
-
draining = false;
|
383
|
-
runClearTimeout(timeout);
|
384
|
-
}
|
385
|
-
function nextTick(fun) {
|
386
|
-
var args = new Array(arguments.length - 1);
|
387
|
-
if (arguments.length > 1) {
|
388
|
-
for (var i = 1; i < arguments.length; i++) {
|
389
|
-
args[i - 1] = arguments[i];
|
390
|
-
}
|
391
|
-
}
|
392
|
-
queue.push(new Item(fun, args));
|
393
|
-
if (queue.length === 1 && !draining) {
|
394
|
-
runTimeout(drainQueue);
|
395
|
-
}
|
396
|
-
}
|
397
|
-
// v8 likes predictible objects
|
398
|
-
function Item(fun, array) {
|
399
|
-
this.fun = fun;
|
400
|
-
this.array = array;
|
401
|
-
}
|
402
|
-
Item.prototype.run = function () {
|
403
|
-
this.fun.apply(null, this.array);
|
404
|
-
};
|
405
|
-
var title = 'browser';
|
406
|
-
var platform = 'browser';
|
407
|
-
var browser$1 = true;
|
408
|
-
var env = {};
|
409
|
-
var argv = [];
|
410
|
-
var version$1 = ''; // empty string to avoid regexp issues
|
411
|
-
var versions = {};
|
412
|
-
var release = {};
|
413
|
-
var config = {};
|
414
|
-
|
415
|
-
function noop$1() {}
|
416
|
-
|
417
|
-
var on = noop$1;
|
418
|
-
var addListener = noop$1;
|
419
|
-
var once = noop$1;
|
420
|
-
var off = noop$1;
|
421
|
-
var removeListener = noop$1;
|
422
|
-
var removeAllListeners = noop$1;
|
423
|
-
var emit = noop$1;
|
424
|
-
|
425
|
-
function binding(name) {
|
426
|
-
throw new Error('process.binding is not supported');
|
427
|
-
}
|
428
|
-
|
429
|
-
function cwd () { return '/' }
|
430
|
-
function chdir (dir) {
|
431
|
-
throw new Error('process.chdir is not supported');
|
432
|
-
}function umask() { return 0; }
|
433
|
-
|
434
|
-
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
|
435
|
-
var performance = global$1.performance || {};
|
436
|
-
var performanceNow =
|
437
|
-
performance.now ||
|
438
|
-
performance.mozNow ||
|
439
|
-
performance.msNow ||
|
440
|
-
performance.oNow ||
|
441
|
-
performance.webkitNow ||
|
442
|
-
function(){ return (new Date()).getTime() };
|
443
|
-
|
444
|
-
// generate timestamp or delta
|
445
|
-
// see http://nodejs.org/api/process.html#process_process_hrtime
|
446
|
-
function hrtime(previousTimestamp){
|
447
|
-
var clocktime = performanceNow.call(performance)*1e-3;
|
448
|
-
var seconds = Math.floor(clocktime);
|
449
|
-
var nanoseconds = Math.floor((clocktime%1)*1e9);
|
450
|
-
if (previousTimestamp) {
|
451
|
-
seconds = seconds - previousTimestamp[0];
|
452
|
-
nanoseconds = nanoseconds - previousTimestamp[1];
|
453
|
-
if (nanoseconds<0) {
|
454
|
-
seconds--;
|
455
|
-
nanoseconds += 1e9;
|
456
|
-
}
|
457
|
-
}
|
458
|
-
return [seconds,nanoseconds]
|
459
|
-
}
|
460
|
-
|
461
|
-
var startTime = new Date();
|
462
|
-
function uptime() {
|
463
|
-
var currentTime = new Date();
|
464
|
-
var dif = currentTime - startTime;
|
465
|
-
return dif / 1000;
|
466
|
-
}
|
467
|
-
|
468
|
-
var browser$1$1 = {
|
469
|
-
nextTick: nextTick,
|
470
|
-
title: title,
|
471
|
-
browser: browser$1,
|
472
|
-
env: env,
|
473
|
-
argv: argv,
|
474
|
-
version: version$1,
|
475
|
-
versions: versions,
|
476
|
-
on: on,
|
477
|
-
addListener: addListener,
|
478
|
-
once: once,
|
479
|
-
off: off,
|
480
|
-
removeListener: removeListener,
|
481
|
-
removeAllListeners: removeAllListeners,
|
482
|
-
emit: emit,
|
483
|
-
binding: binding,
|
484
|
-
cwd: cwd,
|
485
|
-
chdir: chdir,
|
486
|
-
umask: umask,
|
487
|
-
hrtime: hrtime,
|
488
|
-
platform: platform,
|
489
|
-
release: release,
|
490
|
-
config: config,
|
491
|
-
uptime: uptime
|
492
|
-
};
|
493
|
-
|
494
280
|
function _defineProperty(obj, key, value) {
|
495
281
|
if (key in obj) {
|
496
282
|
Object.defineProperty(obj, key, {
|
@@ -591,7 +377,7 @@ var createSprinkles$1 = composeStyles => function () {
|
|
591
377
|
}
|
592
378
|
|
593
379
|
if (typeof propValue === 'string' || typeof propValue === 'number') {
|
594
|
-
if (
|
380
|
+
if (process.env.NODE_ENV !== 'production') {
|
595
381
|
if (!_sprinkle.values[propValue].defaultClass) {
|
596
382
|
throw new Error();
|
597
383
|
}
|
@@ -605,7 +391,7 @@ var createSprinkles$1 = composeStyles => function () {
|
|
605
391
|
if (responsiveValue != null) {
|
606
392
|
var conditionName = _sprinkle.responsiveArray[responsiveIndex];
|
607
393
|
|
608
|
-
if (
|
394
|
+
if (process.env.NODE_ENV !== 'production') {
|
609
395
|
if (!_sprinkle.values[responsiveValue].conditions[conditionName]) {
|
610
396
|
throw new Error();
|
611
397
|
}
|
@@ -620,7 +406,7 @@ var createSprinkles$1 = composeStyles => function () {
|
|
620
406
|
var _value = propValue[_conditionName];
|
621
407
|
|
622
408
|
if (_value != null) {
|
623
|
-
if (
|
409
|
+
if (process.env.NODE_ENV !== 'production') {
|
624
410
|
if (!_sprinkle.values[_value].conditions[_conditionName]) {
|
625
411
|
throw new Error();
|
626
412
|
}
|
@@ -631,7 +417,7 @@ var createSprinkles$1 = composeStyles => function () {
|
|
631
417
|
}
|
632
418
|
}
|
633
419
|
} catch (e) {
|
634
|
-
if (
|
420
|
+
if (process.env.NODE_ENV !== 'production') {
|
635
421
|
(function () {
|
636
422
|
class SprinklesError extends Error {
|
637
423
|
constructor(message) {
|
@@ -1119,10 +905,10 @@ var zeroGap = {
|
|
1119
905
|
right: 0,
|
1120
906
|
gap: 0,
|
1121
907
|
};
|
1122
|
-
var parse = function (x) { return parseInt(x || '', 10) || 0; };
|
908
|
+
var parse$1 = function (x) { return parseInt(x || '', 10) || 0; };
|
1123
909
|
var getOffset = function (gapMode) {
|
1124
910
|
var cs = window.getComputedStyle(document.body);
|
1125
|
-
if (
|
911
|
+
if (process.env.NODE_ENV !== 'production') {
|
1126
912
|
if (cs.overflowY === 'hidden') {
|
1127
913
|
console.error('react-remove-scroll-bar: cannot calculate scrollbar size because it is removed (overflow:hidden on body');
|
1128
914
|
}
|
@@ -1130,7 +916,7 @@ var getOffset = function (gapMode) {
|
|
1130
916
|
var left = cs[gapMode === 'padding' ? 'paddingLeft' : 'marginLeft'];
|
1131
917
|
var top = cs[gapMode === 'padding' ? 'paddingTop' : 'marginTop'];
|
1132
918
|
var right = cs[gapMode === 'padding' ? 'paddingRight' : 'marginRight'];
|
1133
|
-
return [parse(left), parse(top), parse(right)];
|
919
|
+
return [parse$1(left), parse$1(top), parse$1(right)];
|
1134
920
|
};
|
1135
921
|
var getGapWidth = function (gapMode) {
|
1136
922
|
if (gapMode === void 0) { gapMode = 'margin'; }
|
@@ -1505,27 +1291,6 @@ function getDefaultExportFromCjs (x) {
|
|
1505
1291
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
1506
1292
|
}
|
1507
1293
|
|
1508
|
-
function getAugmentedNamespace(n) {
|
1509
|
-
var f = n.default;
|
1510
|
-
if (typeof f == "function") {
|
1511
|
-
var a = function () {
|
1512
|
-
return f.apply(this, arguments);
|
1513
|
-
};
|
1514
|
-
a.prototype = f.prototype;
|
1515
|
-
} else a = {};
|
1516
|
-
Object.defineProperty(a, '__esModule', {value: true});
|
1517
|
-
Object.keys(n).forEach(function (k) {
|
1518
|
-
var d = Object.getOwnPropertyDescriptor(n, k);
|
1519
|
-
Object.defineProperty(a, k, d.get ? d : {
|
1520
|
-
enumerable: true,
|
1521
|
-
get: function () {
|
1522
|
-
return n[k];
|
1523
|
-
}
|
1524
|
-
});
|
1525
|
-
});
|
1526
|
-
return a;
|
1527
|
-
}
|
1528
|
-
|
1529
1294
|
var lib = {exports: {}};
|
1530
1295
|
|
1531
1296
|
var server = {};
|
@@ -2842,11 +2607,11 @@ regex.testAlphanumeric = function testAlphanumeric (str) {
|
|
2842
2607
|
|
2843
2608
|
var formatInfo = {};
|
2844
2609
|
|
2845
|
-
const Utils$
|
2610
|
+
const Utils$3 = utils$1;
|
2846
2611
|
|
2847
2612
|
const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
|
2848
2613
|
const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
|
2849
|
-
const G15_BCH = Utils$
|
2614
|
+
const G15_BCH = Utils$3.getBCHDigit(G15);
|
2850
2615
|
|
2851
2616
|
/**
|
2852
2617
|
* Returns format information with relative error correction bits
|
@@ -2862,8 +2627,8 @@ formatInfo.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask)
|
|
2862
2627
|
const data = ((errorCorrectionLevel.bit << 3) | mask);
|
2863
2628
|
let d = data << 10;
|
2864
2629
|
|
2865
|
-
while (Utils$
|
2866
|
-
d ^= (G15 << (Utils$
|
2630
|
+
while (Utils$3.getBCHDigit(d) - G15_BCH >= 0) {
|
2631
|
+
d ^= (G15 << (Utils$3.getBCHDigit(d) - G15_BCH));
|
2867
2632
|
}
|
2868
2633
|
|
2869
2634
|
// xor final data with mask pattern in order to ensure that
|
@@ -3061,7 +2826,7 @@ ByteData.prototype.write = function (bitBuffer) {
|
|
3061
2826
|
var byteData = ByteData;
|
3062
2827
|
|
3063
2828
|
const Mode$1 = mode;
|
3064
|
-
const Utils$
|
2829
|
+
const Utils$2 = utils$1;
|
3065
2830
|
|
3066
2831
|
function KanjiData (data) {
|
3067
2832
|
this.mode = Mode$1.KANJI;
|
@@ -3087,7 +2852,7 @@ KanjiData.prototype.write = function (bitBuffer) {
|
|
3087
2852
|
// These byte values are shifted from the JIS X 0208 values.
|
3088
2853
|
// JIS X 0208 gives details of the shift coded representation.
|
3089
2854
|
for (i = 0; i < this.data.length; i++) {
|
3090
|
-
let value = Utils$
|
2855
|
+
let value = Utils$2.toSJIS(this.data[i]);
|
3091
2856
|
|
3092
2857
|
// For characters with Shift JIS values from 0x8140 to 0x9FFC:
|
3093
2858
|
if (value >= 0x8140 && value <= 0x9FFC) {
|
@@ -3616,7 +3381,7 @@ var dijkstra = {exports: {}};
|
|
3616
3381
|
};
|
3617
3382
|
} (segments));
|
3618
3383
|
|
3619
|
-
const Utils$
|
3384
|
+
const Utils$1 = utils$1;
|
3620
3385
|
const ECLevel = errorCorrectionLevel;
|
3621
3386
|
const BitBuffer = bitBuffer;
|
3622
3387
|
const BitMatrix = bitMatrix;
|
@@ -3868,7 +3633,7 @@ function createData (version, errorCorrectionLevel, segments) {
|
|
3868
3633
|
});
|
3869
3634
|
|
3870
3635
|
// Calculate required number of bits
|
3871
|
-
const totalCodewords = Utils$
|
3636
|
+
const totalCodewords = Utils$1.getSymbolTotalCodewords(version);
|
3872
3637
|
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
3873
3638
|
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
3874
3639
|
|
@@ -3913,7 +3678,7 @@ function createData (version, errorCorrectionLevel, segments) {
|
|
3913
3678
|
*/
|
3914
3679
|
function createCodewords (bitBuffer, version, errorCorrectionLevel) {
|
3915
3680
|
// Total codewords for this QR code version (Data + Error correction)
|
3916
|
-
const totalCodewords = Utils$
|
3681
|
+
const totalCodewords = Utils$1.getSymbolTotalCodewords(version);
|
3917
3682
|
|
3918
3683
|
// Total number of error correction codewords
|
3919
3684
|
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
@@ -4038,7 +3803,7 @@ function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
|
|
4038
3803
|
const dataBits = createData(version, errorCorrectionLevel, segments);
|
4039
3804
|
|
4040
3805
|
// Allocate matrix buffer
|
4041
|
-
const moduleCount = Utils$
|
3806
|
+
const moduleCount = Utils$1.getSymbolSize(version);
|
4042
3807
|
const modules = new BitMatrix(moduleCount);
|
4043
3808
|
|
4044
3809
|
// Add function modules
|
@@ -4105,2072 +3870,2525 @@ qrcode.create = function create (data, options) {
|
|
4105
3870
|
mask = MaskPattern.from(options.maskPattern);
|
4106
3871
|
|
4107
3872
|
if (options.toSJISFunc) {
|
4108
|
-
Utils$
|
3873
|
+
Utils$1.setToSJISFunction(options.toSJISFunc);
|
4109
3874
|
}
|
4110
3875
|
}
|
4111
3876
|
|
4112
3877
|
return createSymbol(data, version, errorCorrectionLevel, mask)
|
4113
3878
|
};
|
4114
3879
|
|
4115
|
-
var
|
4116
|
-
var revLookup = [];
|
4117
|
-
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
|
4118
|
-
var inited = false;
|
4119
|
-
function init () {
|
4120
|
-
inited = true;
|
4121
|
-
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
4122
|
-
for (var i = 0, len = code.length; i < len; ++i) {
|
4123
|
-
lookup[i] = code[i];
|
4124
|
-
revLookup[code.charCodeAt(i)] = i;
|
4125
|
-
}
|
3880
|
+
var png$1 = {};
|
4126
3881
|
|
4127
|
-
|
4128
|
-
revLookup['_'.charCodeAt(0)] = 63;
|
4129
|
-
}
|
3882
|
+
var png = {};
|
4130
3883
|
|
4131
|
-
|
4132
|
-
if (!inited) {
|
4133
|
-
init();
|
4134
|
-
}
|
4135
|
-
var i, j, l, tmp, placeHolders, arr;
|
4136
|
-
var len = b64.length;
|
3884
|
+
var parserAsync = {exports: {}};
|
4137
3885
|
|
4138
|
-
|
4139
|
-
throw new Error('Invalid string. Length must be a multiple of 4')
|
4140
|
-
}
|
3886
|
+
var chunkstream = {exports: {}};
|
4141
3887
|
|
4142
|
-
|
4143
|
-
|
4144
|
-
// represent one byte
|
4145
|
-
// if there is only one, then the three characters before it represent 2 bytes
|
4146
|
-
// this is just a cheap hack to not do indexOf twice
|
4147
|
-
placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
|
3888
|
+
let util$4 = require$$0__default["default"];
|
3889
|
+
let Stream$2 = require$$1__default["default"];
|
4148
3890
|
|
4149
|
-
|
4150
|
-
|
3891
|
+
let ChunkStream$2 = (chunkstream.exports = function () {
|
3892
|
+
Stream$2.call(this);
|
4151
3893
|
|
4152
|
-
|
4153
|
-
|
3894
|
+
this._buffers = [];
|
3895
|
+
this._buffered = 0;
|
4154
3896
|
|
4155
|
-
|
3897
|
+
this._reads = [];
|
3898
|
+
this._paused = false;
|
4156
3899
|
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
arr[L++] = tmp & 0xFF;
|
4162
|
-
}
|
3900
|
+
this._encoding = "utf8";
|
3901
|
+
this.writable = true;
|
3902
|
+
});
|
3903
|
+
util$4.inherits(ChunkStream$2, Stream$2);
|
4163
3904
|
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
|
4169
|
-
|
4170
|
-
arr[L++] = tmp & 0xFF;
|
4171
|
-
}
|
3905
|
+
ChunkStream$2.prototype.read = function (length, callback) {
|
3906
|
+
this._reads.push({
|
3907
|
+
length: Math.abs(length), // if length < 0 then at most this length
|
3908
|
+
allowLess: length < 0,
|
3909
|
+
func: callback,
|
3910
|
+
});
|
4172
3911
|
|
4173
|
-
|
4174
|
-
|
3912
|
+
process.nextTick(
|
3913
|
+
function () {
|
3914
|
+
this._process();
|
4175
3915
|
|
4176
|
-
|
4177
|
-
|
4178
|
-
|
3916
|
+
// its paused and there is not enought data then ask for more
|
3917
|
+
if (this._paused && this._reads && this._reads.length > 0) {
|
3918
|
+
this._paused = false;
|
4179
3919
|
|
4180
|
-
|
4181
|
-
|
4182
|
-
|
4183
|
-
|
4184
|
-
|
4185
|
-
output.push(tripletToBase64(tmp));
|
4186
|
-
}
|
4187
|
-
return output.join('')
|
4188
|
-
}
|
3920
|
+
this.emit("drain");
|
3921
|
+
}
|
3922
|
+
}.bind(this)
|
3923
|
+
);
|
3924
|
+
};
|
4189
3925
|
|
4190
|
-
function
|
4191
|
-
if (!
|
4192
|
-
|
3926
|
+
ChunkStream$2.prototype.write = function (data, encoding) {
|
3927
|
+
if (!this.writable) {
|
3928
|
+
this.emit("error", new Error("Stream not writable"));
|
3929
|
+
return false;
|
4193
3930
|
}
|
4194
|
-
var tmp;
|
4195
|
-
var len = uint8.length;
|
4196
|
-
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
4197
|
-
var output = '';
|
4198
|
-
var parts = [];
|
4199
|
-
var maxChunkLength = 16383; // must be multiple of 3
|
4200
3931
|
|
4201
|
-
|
4202
|
-
|
4203
|
-
|
3932
|
+
let dataBuffer;
|
3933
|
+
if (Buffer.isBuffer(data)) {
|
3934
|
+
dataBuffer = data;
|
3935
|
+
} else {
|
3936
|
+
dataBuffer = Buffer.from(data, encoding || this._encoding);
|
4204
3937
|
}
|
4205
3938
|
|
4206
|
-
|
4207
|
-
|
4208
|
-
tmp = uint8[len - 1];
|
4209
|
-
output += lookup[tmp >> 2];
|
4210
|
-
output += lookup[(tmp << 4) & 0x3F];
|
4211
|
-
output += '==';
|
4212
|
-
} else if (extraBytes === 2) {
|
4213
|
-
tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
|
4214
|
-
output += lookup[tmp >> 10];
|
4215
|
-
output += lookup[(tmp >> 4) & 0x3F];
|
4216
|
-
output += lookup[(tmp << 2) & 0x3F];
|
4217
|
-
output += '=';
|
4218
|
-
}
|
3939
|
+
this._buffers.push(dataBuffer);
|
3940
|
+
this._buffered += dataBuffer.length;
|
4219
3941
|
|
4220
|
-
|
3942
|
+
this._process();
|
4221
3943
|
|
4222
|
-
|
4223
|
-
|
3944
|
+
// ok if there are no more read requests
|
3945
|
+
if (this._reads && this._reads.length === 0) {
|
3946
|
+
this._paused = true;
|
3947
|
+
}
|
4224
3948
|
|
4225
|
-
|
4226
|
-
|
4227
|
-
var eLen = nBytes * 8 - mLen - 1;
|
4228
|
-
var eMax = (1 << eLen) - 1;
|
4229
|
-
var eBias = eMax >> 1;
|
4230
|
-
var nBits = -7;
|
4231
|
-
var i = isLE ? (nBytes - 1) : 0;
|
4232
|
-
var d = isLE ? -1 : 1;
|
4233
|
-
var s = buffer[offset + i];
|
3949
|
+
return this.writable && !this._paused;
|
3950
|
+
};
|
4234
3951
|
|
4235
|
-
|
3952
|
+
ChunkStream$2.prototype.end = function (data, encoding) {
|
3953
|
+
if (data) {
|
3954
|
+
this.write(data, encoding);
|
3955
|
+
}
|
4236
3956
|
|
4237
|
-
|
4238
|
-
s >>= (-nBits);
|
4239
|
-
nBits += eLen;
|
4240
|
-
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
3957
|
+
this.writable = false;
|
4241
3958
|
|
4242
|
-
|
4243
|
-
|
4244
|
-
|
4245
|
-
|
3959
|
+
// already destroyed
|
3960
|
+
if (!this._buffers) {
|
3961
|
+
return;
|
3962
|
+
}
|
4246
3963
|
|
4247
|
-
|
4248
|
-
|
4249
|
-
|
4250
|
-
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
3964
|
+
// enqueue or handle end
|
3965
|
+
if (this._buffers.length === 0) {
|
3966
|
+
this._end();
|
4251
3967
|
} else {
|
4252
|
-
|
4253
|
-
|
3968
|
+
this._buffers.push(null);
|
3969
|
+
this._process();
|
4254
3970
|
}
|
4255
|
-
|
4256
|
-
}
|
4257
|
-
|
4258
|
-
function write (buffer, value, offset, isLE, mLen, nBytes) {
|
4259
|
-
var e, m, c;
|
4260
|
-
var eLen = nBytes * 8 - mLen - 1;
|
4261
|
-
var eMax = (1 << eLen) - 1;
|
4262
|
-
var eBias = eMax >> 1;
|
4263
|
-
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
|
4264
|
-
var i = isLE ? 0 : (nBytes - 1);
|
4265
|
-
var d = isLE ? 1 : -1;
|
4266
|
-
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
4267
|
-
|
4268
|
-
value = Math.abs(value);
|
3971
|
+
};
|
4269
3972
|
|
4270
|
-
|
4271
|
-
m = isNaN(value) ? 1 : 0;
|
4272
|
-
e = eMax;
|
4273
|
-
} else {
|
4274
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
4275
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
4276
|
-
e--;
|
4277
|
-
c *= 2;
|
4278
|
-
}
|
4279
|
-
if (e + eBias >= 1) {
|
4280
|
-
value += rt / c;
|
4281
|
-
} else {
|
4282
|
-
value += rt * Math.pow(2, 1 - eBias);
|
4283
|
-
}
|
4284
|
-
if (value * c >= 2) {
|
4285
|
-
e++;
|
4286
|
-
c /= 2;
|
4287
|
-
}
|
3973
|
+
ChunkStream$2.prototype.destroySoon = ChunkStream$2.prototype.end;
|
4288
3974
|
|
4289
|
-
|
4290
|
-
|
4291
|
-
|
4292
|
-
} else if (e + eBias >= 1) {
|
4293
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
4294
|
-
e = e + eBias;
|
4295
|
-
} else {
|
4296
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
4297
|
-
e = 0;
|
4298
|
-
}
|
3975
|
+
ChunkStream$2.prototype._end = function () {
|
3976
|
+
if (this._reads.length > 0) {
|
3977
|
+
this.emit("error", new Error("Unexpected end of input"));
|
4299
3978
|
}
|
4300
3979
|
|
4301
|
-
|
4302
|
-
|
4303
|
-
e = (e << mLen) | m;
|
4304
|
-
eLen += mLen;
|
4305
|
-
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
3980
|
+
this.destroy();
|
3981
|
+
};
|
4306
3982
|
|
4307
|
-
|
4308
|
-
|
3983
|
+
ChunkStream$2.prototype.destroy = function () {
|
3984
|
+
if (!this._buffers) {
|
3985
|
+
return;
|
3986
|
+
}
|
4309
3987
|
|
4310
|
-
|
3988
|
+
this.writable = false;
|
3989
|
+
this._reads = null;
|
3990
|
+
this._buffers = null;
|
4311
3991
|
|
4312
|
-
|
4313
|
-
return toString.call(arr) == '[object Array]';
|
3992
|
+
this.emit("close");
|
4314
3993
|
};
|
4315
3994
|
|
4316
|
-
|
4317
|
-
|
4318
|
-
|
4319
|
-
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
4320
|
-
* @license MIT
|
4321
|
-
*/
|
3995
|
+
ChunkStream$2.prototype._processReadAllowingLess = function (read) {
|
3996
|
+
// ok there is any data so that we can satisfy this request
|
3997
|
+
this._reads.shift(); // == read
|
4322
3998
|
|
4323
|
-
|
3999
|
+
// first we need to peek into first buffer
|
4000
|
+
let smallerBuf = this._buffers[0];
|
4324
4001
|
|
4325
|
-
|
4326
|
-
|
4327
|
-
|
4328
|
-
|
4329
|
-
*
|
4330
|
-
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
4331
|
-
* Opera 11.6+, iOS 4.2+.
|
4332
|
-
*
|
4333
|
-
* Due to various browser bugs, sometimes the Object implementation will be used even
|
4334
|
-
* when the browser supports typed arrays.
|
4335
|
-
*
|
4336
|
-
* Note:
|
4337
|
-
*
|
4338
|
-
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
|
4339
|
-
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
|
4340
|
-
*
|
4341
|
-
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
|
4342
|
-
*
|
4343
|
-
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
|
4344
|
-
* incorrect length in some situations.
|
4002
|
+
// ok there is more data than we need
|
4003
|
+
if (smallerBuf.length > read.length) {
|
4004
|
+
this._buffered -= read.length;
|
4005
|
+
this._buffers[0] = smallerBuf.slice(read.length);
|
4345
4006
|
|
4346
|
-
|
4347
|
-
|
4348
|
-
|
4349
|
-
|
4350
|
-
|
4351
|
-
: true;
|
4007
|
+
read.func.call(this, smallerBuf.slice(0, read.length));
|
4008
|
+
} else {
|
4009
|
+
// ok this is less than maximum length so use it all
|
4010
|
+
this._buffered -= smallerBuf.length;
|
4011
|
+
this._buffers.shift(); // == smallerBuf
|
4352
4012
|
|
4353
|
-
|
4354
|
-
|
4355
|
-
|
4356
|
-
kMaxLength();
|
4013
|
+
read.func.call(this, smallerBuf);
|
4014
|
+
}
|
4015
|
+
};
|
4357
4016
|
|
4358
|
-
function
|
4359
|
-
|
4360
|
-
? 0x7fffffff
|
4361
|
-
: 0x3fffffff
|
4362
|
-
}
|
4017
|
+
ChunkStream$2.prototype._processRead = function (read) {
|
4018
|
+
this._reads.shift(); // == read
|
4363
4019
|
|
4364
|
-
|
4365
|
-
|
4366
|
-
|
4367
|
-
}
|
4368
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
4369
|
-
// Return an augmented `Uint8Array` instance, for best performance
|
4370
|
-
that = new Uint8Array(length);
|
4371
|
-
that.__proto__ = Buffer.prototype;
|
4372
|
-
} else {
|
4373
|
-
// Fallback: Return an object instance of the Buffer class
|
4374
|
-
if (that === null) {
|
4375
|
-
that = new Buffer(length);
|
4376
|
-
}
|
4377
|
-
that.length = length;
|
4378
|
-
}
|
4020
|
+
let pos = 0;
|
4021
|
+
let count = 0;
|
4022
|
+
let data = Buffer.alloc(read.length);
|
4379
4023
|
|
4380
|
-
|
4381
|
-
|
4024
|
+
// create buffer for all data
|
4025
|
+
while (pos < read.length) {
|
4026
|
+
let buf = this._buffers[count++];
|
4027
|
+
let len = Math.min(buf.length, read.length - pos);
|
4382
4028
|
|
4383
|
-
|
4384
|
-
|
4385
|
-
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
4386
|
-
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
4387
|
-
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
4388
|
-
* returns a single octet.
|
4389
|
-
*
|
4390
|
-
* The `Uint8Array` prototype remains unmodified.
|
4391
|
-
*/
|
4029
|
+
buf.copy(data, pos, 0, len);
|
4030
|
+
pos += len;
|
4392
4031
|
|
4393
|
-
|
4394
|
-
|
4395
|
-
|
4032
|
+
// last buffer wasn't used all so just slice it and leave
|
4033
|
+
if (len !== buf.length) {
|
4034
|
+
this._buffers[--count] = buf.slice(len);
|
4035
|
+
}
|
4396
4036
|
}
|
4397
4037
|
|
4398
|
-
//
|
4399
|
-
if (
|
4400
|
-
|
4401
|
-
throw new Error(
|
4402
|
-
'If encoding is specified then the first argument must be a string'
|
4403
|
-
)
|
4404
|
-
}
|
4405
|
-
return allocUnsafe(this, arg)
|
4038
|
+
// remove all used buffers
|
4039
|
+
if (count > 0) {
|
4040
|
+
this._buffers.splice(0, count);
|
4406
4041
|
}
|
4407
|
-
return from(this, arg, encodingOrOffset, length)
|
4408
|
-
}
|
4409
4042
|
|
4410
|
-
|
4043
|
+
this._buffered -= read.length;
|
4411
4044
|
|
4412
|
-
|
4413
|
-
Buffer._augment = function (arr) {
|
4414
|
-
arr.__proto__ = Buffer.prototype;
|
4415
|
-
return arr
|
4045
|
+
read.func.call(this, data);
|
4416
4046
|
};
|
4417
4047
|
|
4418
|
-
function
|
4419
|
-
|
4420
|
-
|
4421
|
-
|
4422
|
-
|
4423
|
-
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
|
4424
|
-
return fromArrayBuffer(that, value, encodingOrOffset, length)
|
4425
|
-
}
|
4048
|
+
ChunkStream$2.prototype._process = function () {
|
4049
|
+
try {
|
4050
|
+
// as long as there is any data and read requests
|
4051
|
+
while (this._buffered > 0 && this._reads && this._reads.length > 0) {
|
4052
|
+
let read = this._reads[0];
|
4426
4053
|
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4054
|
+
// read any data (but no more than length)
|
4055
|
+
if (read.allowLess) {
|
4056
|
+
this._processReadAllowingLess(read);
|
4057
|
+
} else if (this._buffered >= read.length) {
|
4058
|
+
// ok we can meet some expectations
|
4430
4059
|
|
4431
|
-
|
4432
|
-
}
|
4060
|
+
this._processRead(read);
|
4061
|
+
} else {
|
4062
|
+
// not enought data to satisfy first request in queue
|
4063
|
+
// so we need to wait for more
|
4064
|
+
break;
|
4065
|
+
}
|
4066
|
+
}
|
4433
4067
|
|
4434
|
-
|
4435
|
-
|
4436
|
-
|
4437
|
-
|
4438
|
-
|
4439
|
-
|
4440
|
-
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
4441
|
-
**/
|
4442
|
-
Buffer.from = function (value, encodingOrOffset, length) {
|
4443
|
-
return from(null, value, encodingOrOffset, length)
|
4068
|
+
if (this._buffers && !this.writable) {
|
4069
|
+
this._end();
|
4070
|
+
}
|
4071
|
+
} catch (ex) {
|
4072
|
+
this.emit("error", ex);
|
4073
|
+
}
|
4444
4074
|
};
|
4445
4075
|
|
4446
|
-
|
4447
|
-
Buffer.prototype.__proto__ = Uint8Array.prototype;
|
4448
|
-
Buffer.__proto__ = Uint8Array;
|
4449
|
-
}
|
4076
|
+
var filterParseAsync = {exports: {}};
|
4450
4077
|
|
4451
|
-
|
4452
|
-
if (typeof size !== 'number') {
|
4453
|
-
throw new TypeError('"size" argument must be a number')
|
4454
|
-
} else if (size < 0) {
|
4455
|
-
throw new RangeError('"size" argument must not be negative')
|
4456
|
-
}
|
4457
|
-
}
|
4078
|
+
var filterParse = {exports: {}};
|
4458
4079
|
|
4459
|
-
|
4460
|
-
assertSize(size);
|
4461
|
-
if (size <= 0) {
|
4462
|
-
return createBuffer(that, size)
|
4463
|
-
}
|
4464
|
-
if (fill !== undefined) {
|
4465
|
-
// Only pay attention to encoding if it's a string. This
|
4466
|
-
// prevents accidentally sending in a number that would
|
4467
|
-
// be interpretted as a start offset.
|
4468
|
-
return typeof encoding === 'string'
|
4469
|
-
? createBuffer(that, size).fill(fill, encoding)
|
4470
|
-
: createBuffer(that, size).fill(fill)
|
4471
|
-
}
|
4472
|
-
return createBuffer(that, size)
|
4473
|
-
}
|
4080
|
+
var interlace = {};
|
4474
4081
|
|
4475
|
-
|
4476
|
-
|
4477
|
-
|
4478
|
-
|
4479
|
-
|
4480
|
-
|
4481
|
-
|
4082
|
+
// Adam 7
|
4083
|
+
// 0 1 2 3 4 5 6 7
|
4084
|
+
// 0 x 6 4 6 x 6 4 6
|
4085
|
+
// 1 7 7 7 7 7 7 7 7
|
4086
|
+
// 2 5 6 5 6 5 6 5 6
|
4087
|
+
// 3 7 7 7 7 7 7 7 7
|
4088
|
+
// 4 3 6 4 6 3 6 4 6
|
4089
|
+
// 5 7 7 7 7 7 7 7 7
|
4090
|
+
// 6 5 6 5 6 5 6 5 6
|
4091
|
+
// 7 7 7 7 7 7 7 7 7
|
4092
|
+
|
4093
|
+
let imagePasses = [
|
4094
|
+
{
|
4095
|
+
// pass 1 - 1px
|
4096
|
+
x: [0],
|
4097
|
+
y: [0],
|
4098
|
+
},
|
4099
|
+
{
|
4100
|
+
// pass 2 - 1px
|
4101
|
+
x: [4],
|
4102
|
+
y: [0],
|
4103
|
+
},
|
4104
|
+
{
|
4105
|
+
// pass 3 - 2px
|
4106
|
+
x: [0, 4],
|
4107
|
+
y: [4],
|
4108
|
+
},
|
4109
|
+
{
|
4110
|
+
// pass 4 - 4px
|
4111
|
+
x: [2, 6],
|
4112
|
+
y: [0, 4],
|
4113
|
+
},
|
4114
|
+
{
|
4115
|
+
// pass 5 - 8px
|
4116
|
+
x: [0, 2, 4, 6],
|
4117
|
+
y: [2, 6],
|
4118
|
+
},
|
4119
|
+
{
|
4120
|
+
// pass 6 - 16px
|
4121
|
+
x: [1, 3, 5, 7],
|
4122
|
+
y: [0, 2, 4, 6],
|
4123
|
+
},
|
4124
|
+
{
|
4125
|
+
// pass 7 - 32px
|
4126
|
+
x: [0, 1, 2, 3, 4, 5, 6, 7],
|
4127
|
+
y: [1, 3, 5, 7],
|
4128
|
+
},
|
4129
|
+
];
|
4482
4130
|
|
4483
|
-
function
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
|
4488
|
-
|
4131
|
+
interlace.getImagePasses = function (width, height) {
|
4132
|
+
let images = [];
|
4133
|
+
let xLeftOver = width % 8;
|
4134
|
+
let yLeftOver = height % 8;
|
4135
|
+
let xRepeats = (width - xLeftOver) / 8;
|
4136
|
+
let yRepeats = (height - yLeftOver) / 8;
|
4137
|
+
for (let i = 0; i < imagePasses.length; i++) {
|
4138
|
+
let pass = imagePasses[i];
|
4139
|
+
let passWidth = xRepeats * pass.x.length;
|
4140
|
+
let passHeight = yRepeats * pass.y.length;
|
4141
|
+
for (let j = 0; j < pass.x.length; j++) {
|
4142
|
+
if (pass.x[j] < xLeftOver) {
|
4143
|
+
passWidth++;
|
4144
|
+
} else {
|
4145
|
+
break;
|
4146
|
+
}
|
4147
|
+
}
|
4148
|
+
for (let j = 0; j < pass.y.length; j++) {
|
4149
|
+
if (pass.y[j] < yLeftOver) {
|
4150
|
+
passHeight++;
|
4151
|
+
} else {
|
4152
|
+
break;
|
4153
|
+
}
|
4154
|
+
}
|
4155
|
+
if (passWidth > 0 && passHeight > 0) {
|
4156
|
+
images.push({ width: passWidth, height: passHeight, index: i });
|
4489
4157
|
}
|
4490
4158
|
}
|
4491
|
-
return
|
4492
|
-
}
|
4493
|
-
|
4494
|
-
/**
|
4495
|
-
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
4496
|
-
* */
|
4497
|
-
Buffer.allocUnsafe = function (size) {
|
4498
|
-
return allocUnsafe(null, size)
|
4159
|
+
return images;
|
4499
4160
|
};
|
4500
|
-
|
4501
|
-
|
4502
|
-
|
4503
|
-
|
4504
|
-
|
4161
|
+
|
4162
|
+
interlace.getInterlaceIterator = function (width) {
|
4163
|
+
return function (x, y, pass) {
|
4164
|
+
let outerXLeftOver = x % imagePasses[pass].x.length;
|
4165
|
+
let outerX =
|
4166
|
+
((x - outerXLeftOver) / imagePasses[pass].x.length) * 8 +
|
4167
|
+
imagePasses[pass].x[outerXLeftOver];
|
4168
|
+
let outerYLeftOver = y % imagePasses[pass].y.length;
|
4169
|
+
let outerY =
|
4170
|
+
((y - outerYLeftOver) / imagePasses[pass].y.length) * 8 +
|
4171
|
+
imagePasses[pass].y[outerYLeftOver];
|
4172
|
+
return outerX * 4 + outerY * width * 4;
|
4173
|
+
};
|
4505
4174
|
};
|
4506
4175
|
|
4507
|
-
function
|
4508
|
-
|
4509
|
-
|
4510
|
-
|
4176
|
+
var paethPredictor$2 = function paethPredictor(left, above, upLeft) {
|
4177
|
+
let paeth = left + above - upLeft;
|
4178
|
+
let pLeft = Math.abs(paeth - left);
|
4179
|
+
let pAbove = Math.abs(paeth - above);
|
4180
|
+
let pUpLeft = Math.abs(paeth - upLeft);
|
4511
4181
|
|
4512
|
-
if (
|
4513
|
-
|
4182
|
+
if (pLeft <= pAbove && pLeft <= pUpLeft) {
|
4183
|
+
return left;
|
4514
4184
|
}
|
4515
|
-
|
4516
|
-
|
4517
|
-
that = createBuffer(that, length);
|
4518
|
-
|
4519
|
-
var actual = that.write(string, encoding);
|
4520
|
-
|
4521
|
-
if (actual !== length) {
|
4522
|
-
// Writing a hex string, for example, that contains invalid characters will
|
4523
|
-
// cause everything after the first invalid character to be ignored. (e.g.
|
4524
|
-
// 'abxxcd' will be treated as 'ab')
|
4525
|
-
that = that.slice(0, actual);
|
4185
|
+
if (pAbove <= pUpLeft) {
|
4186
|
+
return above;
|
4526
4187
|
}
|
4188
|
+
return upLeft;
|
4189
|
+
};
|
4527
4190
|
|
4528
|
-
|
4529
|
-
|
4191
|
+
let interlaceUtils$1 = interlace;
|
4192
|
+
let paethPredictor$1 = paethPredictor$2;
|
4530
4193
|
|
4531
|
-
function
|
4532
|
-
|
4533
|
-
|
4534
|
-
|
4535
|
-
that[i] = array[i] & 255;
|
4194
|
+
function getByteWidth(width, bpp, depth) {
|
4195
|
+
let byteWidth = width * bpp;
|
4196
|
+
if (depth !== 8) {
|
4197
|
+
byteWidth = Math.ceil(byteWidth / (8 / depth));
|
4536
4198
|
}
|
4537
|
-
return
|
4199
|
+
return byteWidth;
|
4538
4200
|
}
|
4539
4201
|
|
4540
|
-
|
4541
|
-
|
4542
|
-
|
4543
|
-
|
4544
|
-
|
4545
|
-
|
4202
|
+
let Filter$2 = (filterParse.exports = function (bitmapInfo, dependencies) {
|
4203
|
+
let width = bitmapInfo.width;
|
4204
|
+
let height = bitmapInfo.height;
|
4205
|
+
let interlace = bitmapInfo.interlace;
|
4206
|
+
let bpp = bitmapInfo.bpp;
|
4207
|
+
let depth = bitmapInfo.depth;
|
4546
4208
|
|
4547
|
-
|
4548
|
-
|
4549
|
-
|
4209
|
+
this.read = dependencies.read;
|
4210
|
+
this.write = dependencies.write;
|
4211
|
+
this.complete = dependencies.complete;
|
4550
4212
|
|
4551
|
-
|
4552
|
-
|
4553
|
-
|
4554
|
-
|
4213
|
+
this._imageIndex = 0;
|
4214
|
+
this._images = [];
|
4215
|
+
if (interlace) {
|
4216
|
+
let passes = interlaceUtils$1.getImagePasses(width, height);
|
4217
|
+
for (let i = 0; i < passes.length; i++) {
|
4218
|
+
this._images.push({
|
4219
|
+
byteWidth: getByteWidth(passes[i].width, bpp, depth),
|
4220
|
+
height: passes[i].height,
|
4221
|
+
lineIndex: 0,
|
4222
|
+
});
|
4223
|
+
}
|
4555
4224
|
} else {
|
4556
|
-
|
4225
|
+
this._images.push({
|
4226
|
+
byteWidth: getByteWidth(width, bpp, depth),
|
4227
|
+
height: height,
|
4228
|
+
lineIndex: 0,
|
4229
|
+
});
|
4557
4230
|
}
|
4558
4231
|
|
4559
|
-
|
4560
|
-
|
4561
|
-
|
4562
|
-
|
4232
|
+
// when filtering the line we look at the pixel to the left
|
4233
|
+
// the spec also says it is done on a byte level regardless of the number of pixels
|
4234
|
+
// so if the depth is byte compatible (8 or 16) we subtract the bpp in order to compare back
|
4235
|
+
// a pixel rather than just a different byte part. However if we are sub byte, we ignore.
|
4236
|
+
if (depth === 8) {
|
4237
|
+
this._xComparison = bpp;
|
4238
|
+
} else if (depth === 16) {
|
4239
|
+
this._xComparison = bpp * 2;
|
4563
4240
|
} else {
|
4564
|
-
|
4565
|
-
that = fromArrayLike(that, array);
|
4241
|
+
this._xComparison = 1;
|
4566
4242
|
}
|
4567
|
-
|
4568
|
-
}
|
4243
|
+
});
|
4569
4244
|
|
4570
|
-
function
|
4571
|
-
|
4572
|
-
|
4573
|
-
|
4245
|
+
Filter$2.prototype.start = function () {
|
4246
|
+
this.read(
|
4247
|
+
this._images[this._imageIndex].byteWidth + 1,
|
4248
|
+
this._reverseFilterLine.bind(this)
|
4249
|
+
);
|
4250
|
+
};
|
4574
4251
|
|
4575
|
-
|
4576
|
-
|
4577
|
-
|
4252
|
+
Filter$2.prototype._unFilterType1 = function (
|
4253
|
+
rawData,
|
4254
|
+
unfilteredLine,
|
4255
|
+
byteWidth
|
4256
|
+
) {
|
4257
|
+
let xComparison = this._xComparison;
|
4258
|
+
let xBiggerThan = xComparison - 1;
|
4578
4259
|
|
4579
|
-
|
4580
|
-
|
4260
|
+
for (let x = 0; x < byteWidth; x++) {
|
4261
|
+
let rawByte = rawData[1 + x];
|
4262
|
+
let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
|
4263
|
+
unfilteredLine[x] = rawByte + f1Left;
|
4581
4264
|
}
|
4265
|
+
};
|
4582
4266
|
|
4583
|
-
|
4584
|
-
|
4585
|
-
|
4586
|
-
|
4587
|
-
|
4588
|
-
|
4589
|
-
return fromArrayLike(that, obj)
|
4590
|
-
}
|
4267
|
+
Filter$2.prototype._unFilterType2 = function (
|
4268
|
+
rawData,
|
4269
|
+
unfilteredLine,
|
4270
|
+
byteWidth
|
4271
|
+
) {
|
4272
|
+
let lastLine = this._lastLine;
|
4591
4273
|
|
4592
|
-
|
4593
|
-
|
4594
|
-
|
4274
|
+
for (let x = 0; x < byteWidth; x++) {
|
4275
|
+
let rawByte = rawData[1 + x];
|
4276
|
+
let f2Up = lastLine ? lastLine[x] : 0;
|
4277
|
+
unfilteredLine[x] = rawByte + f2Up;
|
4595
4278
|
}
|
4279
|
+
};
|
4596
4280
|
|
4597
|
-
|
4598
|
-
|
4281
|
+
Filter$2.prototype._unFilterType3 = function (
|
4282
|
+
rawData,
|
4283
|
+
unfilteredLine,
|
4284
|
+
byteWidth
|
4285
|
+
) {
|
4286
|
+
let xComparison = this._xComparison;
|
4287
|
+
let xBiggerThan = xComparison - 1;
|
4288
|
+
let lastLine = this._lastLine;
|
4599
4289
|
|
4600
|
-
|
4601
|
-
|
4602
|
-
|
4603
|
-
|
4604
|
-
|
4605
|
-
|
4290
|
+
for (let x = 0; x < byteWidth; x++) {
|
4291
|
+
let rawByte = rawData[1 + x];
|
4292
|
+
let f3Up = lastLine ? lastLine[x] : 0;
|
4293
|
+
let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
|
4294
|
+
let f3Add = Math.floor((f3Left + f3Up) / 2);
|
4295
|
+
unfilteredLine[x] = rawByte + f3Add;
|
4606
4296
|
}
|
4607
|
-
|
4608
|
-
}
|
4609
|
-
Buffer.isBuffer = isBuffer;
|
4610
|
-
function internalIsBuffer (b) {
|
4611
|
-
return !!(b != null && b._isBuffer)
|
4612
|
-
}
|
4297
|
+
};
|
4613
4298
|
|
4614
|
-
|
4615
|
-
|
4616
|
-
|
4617
|
-
|
4299
|
+
Filter$2.prototype._unFilterType4 = function (
|
4300
|
+
rawData,
|
4301
|
+
unfilteredLine,
|
4302
|
+
byteWidth
|
4303
|
+
) {
|
4304
|
+
let xComparison = this._xComparison;
|
4305
|
+
let xBiggerThan = xComparison - 1;
|
4306
|
+
let lastLine = this._lastLine;
|
4618
4307
|
|
4619
|
-
|
4308
|
+
for (let x = 0; x < byteWidth; x++) {
|
4309
|
+
let rawByte = rawData[1 + x];
|
4310
|
+
let f4Up = lastLine ? lastLine[x] : 0;
|
4311
|
+
let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
|
4312
|
+
let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
|
4313
|
+
let f4Add = paethPredictor$1(f4Left, f4Up, f4UpLeft);
|
4314
|
+
unfilteredLine[x] = rawByte + f4Add;
|
4315
|
+
}
|
4316
|
+
};
|
4620
4317
|
|
4621
|
-
|
4622
|
-
|
4318
|
+
Filter$2.prototype._reverseFilterLine = function (rawData) {
|
4319
|
+
let filter = rawData[0];
|
4320
|
+
let unfilteredLine;
|
4321
|
+
let currentImage = this._images[this._imageIndex];
|
4322
|
+
let byteWidth = currentImage.byteWidth;
|
4623
4323
|
|
4624
|
-
|
4625
|
-
|
4626
|
-
|
4627
|
-
|
4628
|
-
|
4324
|
+
if (filter === 0) {
|
4325
|
+
unfilteredLine = rawData.slice(1, byteWidth + 1);
|
4326
|
+
} else {
|
4327
|
+
unfilteredLine = Buffer.alloc(byteWidth);
|
4328
|
+
|
4329
|
+
switch (filter) {
|
4330
|
+
case 1:
|
4331
|
+
this._unFilterType1(rawData, unfilteredLine, byteWidth);
|
4332
|
+
break;
|
4333
|
+
case 2:
|
4334
|
+
this._unFilterType2(rawData, unfilteredLine, byteWidth);
|
4335
|
+
break;
|
4336
|
+
case 3:
|
4337
|
+
this._unFilterType3(rawData, unfilteredLine, byteWidth);
|
4338
|
+
break;
|
4339
|
+
case 4:
|
4340
|
+
this._unFilterType4(rawData, unfilteredLine, byteWidth);
|
4341
|
+
break;
|
4342
|
+
default:
|
4343
|
+
throw new Error("Unrecognised filter type - " + filter);
|
4629
4344
|
}
|
4630
4345
|
}
|
4631
4346
|
|
4632
|
-
|
4633
|
-
if (y < x) return 1
|
4634
|
-
return 0
|
4635
|
-
};
|
4347
|
+
this.write(unfilteredLine);
|
4636
4348
|
|
4637
|
-
|
4638
|
-
|
4639
|
-
|
4640
|
-
|
4641
|
-
|
4642
|
-
|
4643
|
-
|
4644
|
-
case 'binary':
|
4645
|
-
case 'base64':
|
4646
|
-
case 'ucs2':
|
4647
|
-
case 'ucs-2':
|
4648
|
-
case 'utf16le':
|
4649
|
-
case 'utf-16le':
|
4650
|
-
return true
|
4651
|
-
default:
|
4652
|
-
return false
|
4349
|
+
currentImage.lineIndex++;
|
4350
|
+
if (currentImage.lineIndex >= currentImage.height) {
|
4351
|
+
this._lastLine = null;
|
4352
|
+
this._imageIndex++;
|
4353
|
+
currentImage = this._images[this._imageIndex];
|
4354
|
+
} else {
|
4355
|
+
this._lastLine = unfilteredLine;
|
4653
4356
|
}
|
4654
|
-
};
|
4655
4357
|
|
4656
|
-
|
4657
|
-
|
4658
|
-
|
4358
|
+
if (currentImage) {
|
4359
|
+
// read, using the byte width that may be from the new current image
|
4360
|
+
this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
|
4361
|
+
} else {
|
4362
|
+
this._lastLine = null;
|
4363
|
+
this.complete();
|
4659
4364
|
}
|
4365
|
+
};
|
4660
4366
|
|
4661
|
-
|
4662
|
-
|
4663
|
-
|
4367
|
+
let util$3 = require$$0__default["default"];
|
4368
|
+
let ChunkStream$1 = chunkstream.exports;
|
4369
|
+
let Filter$1 = filterParse.exports;
|
4664
4370
|
|
4665
|
-
|
4666
|
-
|
4667
|
-
length = 0;
|
4668
|
-
for (i = 0; i < list.length; ++i) {
|
4669
|
-
length += list[i].length;
|
4670
|
-
}
|
4671
|
-
}
|
4371
|
+
let FilterAsync$1 = (filterParseAsync.exports = function (bitmapInfo) {
|
4372
|
+
ChunkStream$1.call(this);
|
4672
4373
|
|
4673
|
-
|
4674
|
-
|
4675
|
-
|
4676
|
-
|
4677
|
-
|
4678
|
-
|
4679
|
-
}
|
4680
|
-
|
4681
|
-
|
4682
|
-
|
4683
|
-
|
4374
|
+
let buffers = [];
|
4375
|
+
let that = this;
|
4376
|
+
this._filter = new Filter$1(bitmapInfo, {
|
4377
|
+
read: this.read.bind(this),
|
4378
|
+
write: function (buffer) {
|
4379
|
+
buffers.push(buffer);
|
4380
|
+
},
|
4381
|
+
complete: function () {
|
4382
|
+
that.emit("complete", Buffer.concat(buffers));
|
4383
|
+
},
|
4384
|
+
});
|
4385
|
+
|
4386
|
+
this._filter.start();
|
4387
|
+
});
|
4388
|
+
util$3.inherits(FilterAsync$1, ChunkStream$1);
|
4389
|
+
|
4390
|
+
var parser = {exports: {}};
|
4391
|
+
|
4392
|
+
var constants$5 = {
|
4393
|
+
PNG_SIGNATURE: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a],
|
4394
|
+
|
4395
|
+
TYPE_IHDR: 0x49484452,
|
4396
|
+
TYPE_IEND: 0x49454e44,
|
4397
|
+
TYPE_IDAT: 0x49444154,
|
4398
|
+
TYPE_PLTE: 0x504c5445,
|
4399
|
+
TYPE_tRNS: 0x74524e53, // eslint-disable-line camelcase
|
4400
|
+
TYPE_gAMA: 0x67414d41, // eslint-disable-line camelcase
|
4401
|
+
|
4402
|
+
// color-type bits
|
4403
|
+
COLORTYPE_GRAYSCALE: 0,
|
4404
|
+
COLORTYPE_PALETTE: 1,
|
4405
|
+
COLORTYPE_COLOR: 2,
|
4406
|
+
COLORTYPE_ALPHA: 4, // e.g. grayscale and alpha
|
4407
|
+
|
4408
|
+
// color-type combinations
|
4409
|
+
COLORTYPE_PALETTE_COLOR: 3,
|
4410
|
+
COLORTYPE_COLOR_ALPHA: 6,
|
4411
|
+
|
4412
|
+
COLORTYPE_TO_BPP_MAP: {
|
4413
|
+
0: 1,
|
4414
|
+
2: 3,
|
4415
|
+
3: 1,
|
4416
|
+
4: 2,
|
4417
|
+
6: 4,
|
4418
|
+
},
|
4419
|
+
|
4420
|
+
GAMMA_DIVISION: 100000,
|
4684
4421
|
};
|
4685
4422
|
|
4686
|
-
|
4687
|
-
if (internalIsBuffer(string)) {
|
4688
|
-
return string.length
|
4689
|
-
}
|
4690
|
-
if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
|
4691
|
-
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
|
4692
|
-
return string.byteLength
|
4693
|
-
}
|
4694
|
-
if (typeof string !== 'string') {
|
4695
|
-
string = '' + string;
|
4696
|
-
}
|
4423
|
+
var crc = {exports: {}};
|
4697
4424
|
|
4698
|
-
|
4699
|
-
if (len === 0) return 0
|
4425
|
+
let crcTable = [];
|
4700
4426
|
|
4701
|
-
|
4702
|
-
|
4703
|
-
|
4704
|
-
|
4705
|
-
|
4706
|
-
|
4707
|
-
|
4708
|
-
|
4709
|
-
|
4710
|
-
case 'utf-8':
|
4711
|
-
case undefined:
|
4712
|
-
return utf8ToBytes(string).length
|
4713
|
-
case 'ucs2':
|
4714
|
-
case 'ucs-2':
|
4715
|
-
case 'utf16le':
|
4716
|
-
case 'utf-16le':
|
4717
|
-
return len * 2
|
4718
|
-
case 'hex':
|
4719
|
-
return len >>> 1
|
4720
|
-
case 'base64':
|
4721
|
-
return base64ToBytes(string).length
|
4722
|
-
default:
|
4723
|
-
if (loweredCase) return utf8ToBytes(string).length // assume utf8
|
4724
|
-
encoding = ('' + encoding).toLowerCase();
|
4725
|
-
loweredCase = true;
|
4427
|
+
(function () {
|
4428
|
+
for (let i = 0; i < 256; i++) {
|
4429
|
+
let currentCrc = i;
|
4430
|
+
for (let j = 0; j < 8; j++) {
|
4431
|
+
if (currentCrc & 1) {
|
4432
|
+
currentCrc = 0xedb88320 ^ (currentCrc >>> 1);
|
4433
|
+
} else {
|
4434
|
+
currentCrc = currentCrc >>> 1;
|
4435
|
+
}
|
4726
4436
|
}
|
4437
|
+
crcTable[i] = currentCrc;
|
4727
4438
|
}
|
4728
|
-
}
|
4729
|
-
Buffer.byteLength = byteLength;
|
4730
|
-
|
4731
|
-
function slowToString (encoding, start, end) {
|
4732
|
-
var loweredCase = false;
|
4439
|
+
})();
|
4733
4440
|
|
4734
|
-
|
4735
|
-
|
4441
|
+
let CrcCalculator$1 = (crc.exports = function () {
|
4442
|
+
this._crc = -1;
|
4443
|
+
});
|
4736
4444
|
|
4737
|
-
|
4738
|
-
|
4739
|
-
|
4740
|
-
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
4741
|
-
if (start === undefined || start < 0) {
|
4742
|
-
start = 0;
|
4743
|
-
}
|
4744
|
-
// Return early if start > this.length. Done here to prevent potential uint32
|
4745
|
-
// coercion fail below.
|
4746
|
-
if (start > this.length) {
|
4747
|
-
return ''
|
4445
|
+
CrcCalculator$1.prototype.write = function (data) {
|
4446
|
+
for (let i = 0; i < data.length; i++) {
|
4447
|
+
this._crc = crcTable[(this._crc ^ data[i]) & 0xff] ^ (this._crc >>> 8);
|
4748
4448
|
}
|
4449
|
+
return true;
|
4450
|
+
};
|
4749
4451
|
|
4750
|
-
|
4751
|
-
|
4752
|
-
|
4452
|
+
CrcCalculator$1.prototype.crc32 = function () {
|
4453
|
+
return this._crc ^ -1;
|
4454
|
+
};
|
4753
4455
|
|
4754
|
-
|
4755
|
-
|
4456
|
+
CrcCalculator$1.crc32 = function (buf) {
|
4457
|
+
let crc = -1;
|
4458
|
+
for (let i = 0; i < buf.length; i++) {
|
4459
|
+
crc = crcTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
|
4756
4460
|
}
|
4461
|
+
return crc ^ -1;
|
4462
|
+
};
|
4757
4463
|
|
4758
|
-
|
4759
|
-
|
4760
|
-
start >>>= 0;
|
4761
|
-
|
4762
|
-
if (end <= start) {
|
4763
|
-
return ''
|
4764
|
-
}
|
4464
|
+
let constants$4 = constants$5;
|
4465
|
+
let CrcCalculator = crc.exports;
|
4765
4466
|
|
4766
|
-
|
4467
|
+
let Parser$3 = (parser.exports = function (options, dependencies) {
|
4468
|
+
this._options = options;
|
4469
|
+
options.checkCRC = options.checkCRC !== false;
|
4767
4470
|
|
4768
|
-
|
4769
|
-
|
4770
|
-
|
4771
|
-
return hexSlice(this, start, end)
|
4471
|
+
this._hasIHDR = false;
|
4472
|
+
this._hasIEND = false;
|
4473
|
+
this._emittedHeadersFinished = false;
|
4772
4474
|
|
4773
|
-
|
4774
|
-
|
4775
|
-
|
4475
|
+
// input flags/metadata
|
4476
|
+
this._palette = [];
|
4477
|
+
this._colorType = 0;
|
4776
4478
|
|
4777
|
-
|
4778
|
-
|
4479
|
+
this._chunks = {};
|
4480
|
+
this._chunks[constants$4.TYPE_IHDR] = this._handleIHDR.bind(this);
|
4481
|
+
this._chunks[constants$4.TYPE_IEND] = this._handleIEND.bind(this);
|
4482
|
+
this._chunks[constants$4.TYPE_IDAT] = this._handleIDAT.bind(this);
|
4483
|
+
this._chunks[constants$4.TYPE_PLTE] = this._handlePLTE.bind(this);
|
4484
|
+
this._chunks[constants$4.TYPE_tRNS] = this._handleTRNS.bind(this);
|
4485
|
+
this._chunks[constants$4.TYPE_gAMA] = this._handleGAMA.bind(this);
|
4779
4486
|
|
4780
|
-
|
4781
|
-
|
4782
|
-
|
4487
|
+
this.read = dependencies.read;
|
4488
|
+
this.error = dependencies.error;
|
4489
|
+
this.metadata = dependencies.metadata;
|
4490
|
+
this.gamma = dependencies.gamma;
|
4491
|
+
this.transColor = dependencies.transColor;
|
4492
|
+
this.palette = dependencies.palette;
|
4493
|
+
this.parsed = dependencies.parsed;
|
4494
|
+
this.inflateData = dependencies.inflateData;
|
4495
|
+
this.finished = dependencies.finished;
|
4496
|
+
this.simpleTransparency = dependencies.simpleTransparency;
|
4497
|
+
this.headersFinished = dependencies.headersFinished || function () {};
|
4498
|
+
});
|
4783
4499
|
|
4784
|
-
|
4785
|
-
|
4500
|
+
Parser$3.prototype.start = function () {
|
4501
|
+
this.read(constants$4.PNG_SIGNATURE.length, this._parseSignature.bind(this));
|
4502
|
+
};
|
4786
4503
|
|
4787
|
-
|
4788
|
-
|
4789
|
-
case 'utf16le':
|
4790
|
-
case 'utf-16le':
|
4791
|
-
return utf16leSlice(this, start, end)
|
4504
|
+
Parser$3.prototype._parseSignature = function (data) {
|
4505
|
+
let signature = constants$4.PNG_SIGNATURE;
|
4792
4506
|
|
4793
|
-
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
4507
|
+
for (let i = 0; i < signature.length; i++) {
|
4508
|
+
if (data[i] !== signature[i]) {
|
4509
|
+
this.error(new Error("Invalid file signature"));
|
4510
|
+
return;
|
4797
4511
|
}
|
4798
4512
|
}
|
4799
|
-
|
4800
|
-
|
4801
|
-
// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
|
4802
|
-
// Buffer instances.
|
4803
|
-
Buffer.prototype._isBuffer = true;
|
4513
|
+
this.read(8, this._parseChunkBegin.bind(this));
|
4514
|
+
};
|
4804
4515
|
|
4805
|
-
function
|
4806
|
-
|
4807
|
-
|
4808
|
-
b[m] = i;
|
4809
|
-
}
|
4516
|
+
Parser$3.prototype._parseChunkBegin = function (data) {
|
4517
|
+
// chunk content length
|
4518
|
+
let length = data.readUInt32BE(0);
|
4810
4519
|
|
4811
|
-
|
4812
|
-
|
4813
|
-
|
4814
|
-
|
4520
|
+
// chunk type
|
4521
|
+
let type = data.readUInt32BE(4);
|
4522
|
+
let name = "";
|
4523
|
+
for (let i = 4; i < 8; i++) {
|
4524
|
+
name += String.fromCharCode(data[i]);
|
4815
4525
|
}
|
4816
|
-
for (var i = 0; i < len; i += 2) {
|
4817
|
-
swap(this, i, i + 1);
|
4818
|
-
}
|
4819
|
-
return this
|
4820
|
-
};
|
4821
4526
|
|
4822
|
-
|
4823
|
-
|
4824
|
-
|
4825
|
-
|
4826
|
-
|
4827
|
-
|
4828
|
-
|
4829
|
-
|
4527
|
+
//console.log('chunk ', name, length);
|
4528
|
+
|
4529
|
+
// chunk flags
|
4530
|
+
let ancillary = Boolean(data[4] & 0x20); // or critical
|
4531
|
+
// priv = Boolean(data[5] & 0x20), // or public
|
4532
|
+
// safeToCopy = Boolean(data[7] & 0x20); // or unsafe
|
4533
|
+
|
4534
|
+
if (!this._hasIHDR && type !== constants$4.TYPE_IHDR) {
|
4535
|
+
this.error(new Error("Expected IHDR on beggining"));
|
4536
|
+
return;
|
4830
4537
|
}
|
4831
|
-
return this
|
4832
|
-
};
|
4833
4538
|
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4539
|
+
this._crc = new CrcCalculator();
|
4540
|
+
this._crc.write(Buffer.from(name));
|
4541
|
+
|
4542
|
+
if (this._chunks[type]) {
|
4543
|
+
return this._chunks[type](length);
|
4838
4544
|
}
|
4839
|
-
|
4840
|
-
|
4841
|
-
|
4842
|
-
|
4843
|
-
swap(this, i + 3, i + 4);
|
4545
|
+
|
4546
|
+
if (!ancillary) {
|
4547
|
+
this.error(new Error("Unsupported critical chunk type " + name));
|
4548
|
+
return;
|
4844
4549
|
}
|
4845
|
-
return this
|
4846
|
-
};
|
4847
4550
|
|
4848
|
-
|
4849
|
-
var length = this.length | 0;
|
4850
|
-
if (length === 0) return ''
|
4851
|
-
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
4852
|
-
return slowToString.apply(this, arguments)
|
4551
|
+
this.read(length + 4, this._skipChunk.bind(this));
|
4853
4552
|
};
|
4854
4553
|
|
4855
|
-
|
4856
|
-
|
4857
|
-
if (this === b) return true
|
4858
|
-
return Buffer.compare(this, b) === 0
|
4554
|
+
Parser$3.prototype._skipChunk = function (/*data*/) {
|
4555
|
+
this.read(8, this._parseChunkBegin.bind(this));
|
4859
4556
|
};
|
4860
4557
|
|
4861
|
-
|
4862
|
-
|
4863
|
-
var max = INSPECT_MAX_BYTES;
|
4864
|
-
if (this.length > 0) {
|
4865
|
-
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
|
4866
|
-
if (this.length > max) str += ' ... ';
|
4867
|
-
}
|
4868
|
-
return '<Buffer ' + str + '>'
|
4558
|
+
Parser$3.prototype._handleChunkEnd = function () {
|
4559
|
+
this.read(4, this._parseChunkEnd.bind(this));
|
4869
4560
|
};
|
4870
4561
|
|
4871
|
-
|
4872
|
-
|
4873
|
-
|
4874
|
-
}
|
4562
|
+
Parser$3.prototype._parseChunkEnd = function (data) {
|
4563
|
+
let fileCrc = data.readInt32BE(0);
|
4564
|
+
let calcCrc = this._crc.crc32();
|
4875
4565
|
|
4876
|
-
|
4877
|
-
|
4878
|
-
|
4879
|
-
|
4880
|
-
end = target ? target.length : 0;
|
4881
|
-
}
|
4882
|
-
if (thisStart === undefined) {
|
4883
|
-
thisStart = 0;
|
4884
|
-
}
|
4885
|
-
if (thisEnd === undefined) {
|
4886
|
-
thisEnd = this.length;
|
4566
|
+
// check CRC
|
4567
|
+
if (this._options.checkCRC && calcCrc !== fileCrc) {
|
4568
|
+
this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
|
4569
|
+
return;
|
4887
4570
|
}
|
4888
4571
|
|
4889
|
-
if (
|
4890
|
-
|
4572
|
+
if (!this._hasIEND) {
|
4573
|
+
this.read(8, this._parseChunkBegin.bind(this));
|
4891
4574
|
}
|
4575
|
+
};
|
4892
4576
|
|
4893
|
-
|
4894
|
-
|
4895
|
-
|
4896
|
-
|
4897
|
-
|
4898
|
-
|
4899
|
-
|
4900
|
-
|
4577
|
+
Parser$3.prototype._handleIHDR = function (length) {
|
4578
|
+
this.read(length, this._parseIHDR.bind(this));
|
4579
|
+
};
|
4580
|
+
Parser$3.prototype._parseIHDR = function (data) {
|
4581
|
+
this._crc.write(data);
|
4582
|
+
|
4583
|
+
let width = data.readUInt32BE(0);
|
4584
|
+
let height = data.readUInt32BE(4);
|
4585
|
+
let depth = data[8];
|
4586
|
+
let colorType = data[9]; // bits: 1 palette, 2 color, 4 alpha
|
4587
|
+
let compr = data[10];
|
4588
|
+
let filter = data[11];
|
4589
|
+
let interlace = data[12];
|
4590
|
+
|
4591
|
+
// console.log(' width', width, 'height', height,
|
4592
|
+
// 'depth', depth, 'colorType', colorType,
|
4593
|
+
// 'compr', compr, 'filter', filter, 'interlace', interlace
|
4594
|
+
// );
|
4595
|
+
|
4596
|
+
if (
|
4597
|
+
depth !== 8 &&
|
4598
|
+
depth !== 4 &&
|
4599
|
+
depth !== 2 &&
|
4600
|
+
depth !== 1 &&
|
4601
|
+
depth !== 16
|
4602
|
+
) {
|
4603
|
+
this.error(new Error("Unsupported bit depth " + depth));
|
4604
|
+
return;
|
4605
|
+
}
|
4606
|
+
if (!(colorType in constants$4.COLORTYPE_TO_BPP_MAP)) {
|
4607
|
+
this.error(new Error("Unsupported color type"));
|
4608
|
+
return;
|
4609
|
+
}
|
4610
|
+
if (compr !== 0) {
|
4611
|
+
this.error(new Error("Unsupported compression method"));
|
4612
|
+
return;
|
4613
|
+
}
|
4614
|
+
if (filter !== 0) {
|
4615
|
+
this.error(new Error("Unsupported filter method"));
|
4616
|
+
return;
|
4617
|
+
}
|
4618
|
+
if (interlace !== 0 && interlace !== 1) {
|
4619
|
+
this.error(new Error("Unsupported interlace method"));
|
4620
|
+
return;
|
4901
4621
|
}
|
4902
4622
|
|
4903
|
-
|
4904
|
-
end >>>= 0;
|
4905
|
-
thisStart >>>= 0;
|
4906
|
-
thisEnd >>>= 0;
|
4623
|
+
this._colorType = colorType;
|
4907
4624
|
|
4908
|
-
|
4625
|
+
let bpp = constants$4.COLORTYPE_TO_BPP_MAP[this._colorType];
|
4909
4626
|
|
4910
|
-
|
4911
|
-
var y = end - start;
|
4912
|
-
var len = Math.min(x, y);
|
4627
|
+
this._hasIHDR = true;
|
4913
4628
|
|
4914
|
-
|
4915
|
-
|
4629
|
+
this.metadata({
|
4630
|
+
width: width,
|
4631
|
+
height: height,
|
4632
|
+
depth: depth,
|
4633
|
+
interlace: Boolean(interlace),
|
4634
|
+
palette: Boolean(colorType & constants$4.COLORTYPE_PALETTE),
|
4635
|
+
color: Boolean(colorType & constants$4.COLORTYPE_COLOR),
|
4636
|
+
alpha: Boolean(colorType & constants$4.COLORTYPE_ALPHA),
|
4637
|
+
bpp: bpp,
|
4638
|
+
colorType: colorType,
|
4639
|
+
});
|
4916
4640
|
|
4917
|
-
|
4918
|
-
|
4919
|
-
x = thisCopy[i];
|
4920
|
-
y = targetCopy[i];
|
4921
|
-
break
|
4922
|
-
}
|
4923
|
-
}
|
4641
|
+
this._handleChunkEnd();
|
4642
|
+
};
|
4924
4643
|
|
4925
|
-
|
4926
|
-
|
4927
|
-
return 0
|
4644
|
+
Parser$3.prototype._handlePLTE = function (length) {
|
4645
|
+
this.read(length, this._parsePLTE.bind(this));
|
4928
4646
|
};
|
4647
|
+
Parser$3.prototype._parsePLTE = function (data) {
|
4648
|
+
this._crc.write(data);
|
4929
4649
|
|
4930
|
-
|
4931
|
-
//
|
4932
|
-
|
4933
|
-
|
4934
|
-
|
4935
|
-
// - val - a string, Buffer, or number
|
4936
|
-
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
4937
|
-
// - encoding - an optional encoding, relevant is val is a string
|
4938
|
-
// - dir - true for indexOf, false for lastIndexOf
|
4939
|
-
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
4940
|
-
// Empty buffer means no match
|
4941
|
-
if (buffer.length === 0) return -1
|
4942
|
-
|
4943
|
-
// Normalize byteOffset
|
4944
|
-
if (typeof byteOffset === 'string') {
|
4945
|
-
encoding = byteOffset;
|
4946
|
-
byteOffset = 0;
|
4947
|
-
} else if (byteOffset > 0x7fffffff) {
|
4948
|
-
byteOffset = 0x7fffffff;
|
4949
|
-
} else if (byteOffset < -0x80000000) {
|
4950
|
-
byteOffset = -0x80000000;
|
4951
|
-
}
|
4952
|
-
byteOffset = +byteOffset; // Coerce to Number.
|
4953
|
-
if (isNaN(byteOffset)) {
|
4954
|
-
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
4955
|
-
byteOffset = dir ? 0 : (buffer.length - 1);
|
4956
|
-
}
|
4957
|
-
|
4958
|
-
// Normalize byteOffset: negative offsets start from the end of the buffer
|
4959
|
-
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
4960
|
-
if (byteOffset >= buffer.length) {
|
4961
|
-
if (dir) return -1
|
4962
|
-
else byteOffset = buffer.length - 1;
|
4963
|
-
} else if (byteOffset < 0) {
|
4964
|
-
if (dir) byteOffset = 0;
|
4965
|
-
else return -1
|
4966
|
-
}
|
4967
|
-
|
4968
|
-
// Normalize val
|
4969
|
-
if (typeof val === 'string') {
|
4970
|
-
val = Buffer.from(val, encoding);
|
4971
|
-
}
|
4972
|
-
|
4973
|
-
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
4974
|
-
if (internalIsBuffer(val)) {
|
4975
|
-
// Special case: looking for empty string/buffer always fails
|
4976
|
-
if (val.length === 0) {
|
4977
|
-
return -1
|
4978
|
-
}
|
4979
|
-
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
4980
|
-
} else if (typeof val === 'number') {
|
4981
|
-
val = val & 0xFF; // Search for a byte value [0-255]
|
4982
|
-
if (Buffer.TYPED_ARRAY_SUPPORT &&
|
4983
|
-
typeof Uint8Array.prototype.indexOf === 'function') {
|
4984
|
-
if (dir) {
|
4985
|
-
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
4986
|
-
} else {
|
4987
|
-
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
4988
|
-
}
|
4989
|
-
}
|
4990
|
-
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
4650
|
+
let entries = Math.floor(data.length / 3);
|
4651
|
+
// console.log('Palette:', entries);
|
4652
|
+
|
4653
|
+
for (let i = 0; i < entries; i++) {
|
4654
|
+
this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 0xff]);
|
4991
4655
|
}
|
4992
4656
|
|
4993
|
-
|
4994
|
-
}
|
4657
|
+
this.palette(this._palette);
|
4995
4658
|
|
4996
|
-
|
4997
|
-
|
4998
|
-
var arrLength = arr.length;
|
4999
|
-
var valLength = val.length;
|
4659
|
+
this._handleChunkEnd();
|
4660
|
+
};
|
5000
4661
|
|
5001
|
-
|
5002
|
-
|
5003
|
-
|
5004
|
-
|
5005
|
-
|
5006
|
-
|
5007
|
-
}
|
5008
|
-
indexSize = 2;
|
5009
|
-
arrLength /= 2;
|
5010
|
-
valLength /= 2;
|
5011
|
-
byteOffset /= 2;
|
5012
|
-
}
|
5013
|
-
}
|
4662
|
+
Parser$3.prototype._handleTRNS = function (length) {
|
4663
|
+
this.simpleTransparency();
|
4664
|
+
this.read(length, this._parseTRNS.bind(this));
|
4665
|
+
};
|
4666
|
+
Parser$3.prototype._parseTRNS = function (data) {
|
4667
|
+
this._crc.write(data);
|
5014
4668
|
|
5015
|
-
|
5016
|
-
|
5017
|
-
|
5018
|
-
|
5019
|
-
return
|
4669
|
+
// palette
|
4670
|
+
if (this._colorType === constants$4.COLORTYPE_PALETTE_COLOR) {
|
4671
|
+
if (this._palette.length === 0) {
|
4672
|
+
this.error(new Error("Transparency chunk must be after palette"));
|
4673
|
+
return;
|
5020
4674
|
}
|
5021
|
-
|
5022
|
-
|
5023
|
-
|
5024
|
-
if (dir) {
|
5025
|
-
var foundIndex = -1;
|
5026
|
-
for (i = byteOffset; i < arrLength; i++) {
|
5027
|
-
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
5028
|
-
if (foundIndex === -1) foundIndex = i;
|
5029
|
-
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
5030
|
-
} else {
|
5031
|
-
if (foundIndex !== -1) i -= i - foundIndex;
|
5032
|
-
foundIndex = -1;
|
5033
|
-
}
|
4675
|
+
if (data.length > this._palette.length) {
|
4676
|
+
this.error(new Error("More transparent colors than palette size"));
|
4677
|
+
return;
|
5034
4678
|
}
|
5035
|
-
|
5036
|
-
|
5037
|
-
for (i = byteOffset; i >= 0; i--) {
|
5038
|
-
var found = true;
|
5039
|
-
for (var j = 0; j < valLength; j++) {
|
5040
|
-
if (read(arr, i + j) !== read(val, j)) {
|
5041
|
-
found = false;
|
5042
|
-
break
|
5043
|
-
}
|
5044
|
-
}
|
5045
|
-
if (found) return i
|
4679
|
+
for (let i = 0; i < data.length; i++) {
|
4680
|
+
this._palette[i][3] = data[i];
|
5046
4681
|
}
|
4682
|
+
this.palette(this._palette);
|
5047
4683
|
}
|
5048
4684
|
|
5049
|
-
|
5050
|
-
|
4685
|
+
// for colorType 0 (grayscale) and 2 (rgb)
|
4686
|
+
// there might be one gray/color defined as transparent
|
4687
|
+
if (this._colorType === constants$4.COLORTYPE_GRAYSCALE) {
|
4688
|
+
// grey, 2 bytes
|
4689
|
+
this.transColor([data.readUInt16BE(0)]);
|
4690
|
+
}
|
4691
|
+
if (this._colorType === constants$4.COLORTYPE_COLOR) {
|
4692
|
+
this.transColor([
|
4693
|
+
data.readUInt16BE(0),
|
4694
|
+
data.readUInt16BE(2),
|
4695
|
+
data.readUInt16BE(4),
|
4696
|
+
]);
|
4697
|
+
}
|
4698
|
+
|
4699
|
+
this._handleChunkEnd();
|
4700
|
+
};
|
5051
4701
|
|
5052
|
-
|
5053
|
-
|
4702
|
+
Parser$3.prototype._handleGAMA = function (length) {
|
4703
|
+
this.read(length, this._parseGAMA.bind(this));
|
5054
4704
|
};
|
4705
|
+
Parser$3.prototype._parseGAMA = function (data) {
|
4706
|
+
this._crc.write(data);
|
4707
|
+
this.gamma(data.readUInt32BE(0) / constants$4.GAMMA_DIVISION);
|
5055
4708
|
|
5056
|
-
|
5057
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
4709
|
+
this._handleChunkEnd();
|
5058
4710
|
};
|
5059
4711
|
|
5060
|
-
|
5061
|
-
|
4712
|
+
Parser$3.prototype._handleIDAT = function (length) {
|
4713
|
+
if (!this._emittedHeadersFinished) {
|
4714
|
+
this._emittedHeadersFinished = true;
|
4715
|
+
this.headersFinished();
|
4716
|
+
}
|
4717
|
+
this.read(-length, this._parseIDAT.bind(this, length));
|
5062
4718
|
};
|
4719
|
+
Parser$3.prototype._parseIDAT = function (length, data) {
|
4720
|
+
this._crc.write(data);
|
5063
4721
|
|
5064
|
-
|
5065
|
-
|
5066
|
-
|
5067
|
-
|
5068
|
-
|
4722
|
+
if (
|
4723
|
+
this._colorType === constants$4.COLORTYPE_PALETTE_COLOR &&
|
4724
|
+
this._palette.length === 0
|
4725
|
+
) {
|
4726
|
+
throw new Error("Expected palette not found");
|
4727
|
+
}
|
4728
|
+
|
4729
|
+
this.inflateData(data);
|
4730
|
+
let leftOverLength = length - data.length;
|
4731
|
+
|
4732
|
+
if (leftOverLength > 0) {
|
4733
|
+
this._handleIDAT(leftOverLength);
|
5069
4734
|
} else {
|
5070
|
-
|
5071
|
-
if (length > remaining) {
|
5072
|
-
length = remaining;
|
5073
|
-
}
|
4735
|
+
this._handleChunkEnd();
|
5074
4736
|
}
|
4737
|
+
};
|
4738
|
+
|
4739
|
+
Parser$3.prototype._handleIEND = function (length) {
|
4740
|
+
this.read(length, this._parseIEND.bind(this));
|
4741
|
+
};
|
4742
|
+
Parser$3.prototype._parseIEND = function (data) {
|
4743
|
+
this._crc.write(data);
|
5075
4744
|
|
5076
|
-
|
5077
|
-
|
5078
|
-
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
|
4745
|
+
this._hasIEND = true;
|
4746
|
+
this._handleChunkEnd();
|
5079
4747
|
|
5080
|
-
if (
|
5081
|
-
|
4748
|
+
if (this.finished) {
|
4749
|
+
this.finished();
|
5082
4750
|
}
|
5083
|
-
|
5084
|
-
|
5085
|
-
|
5086
|
-
|
4751
|
+
};
|
4752
|
+
|
4753
|
+
var bitmapper$2 = {};
|
4754
|
+
|
4755
|
+
let interlaceUtils = interlace;
|
4756
|
+
|
4757
|
+
let pixelBppMapper = [
|
4758
|
+
// 0 - dummy entry
|
4759
|
+
function () {},
|
4760
|
+
|
4761
|
+
// 1 - L
|
4762
|
+
// 0: 0, 1: 0, 2: 0, 3: 0xff
|
4763
|
+
function (pxData, data, pxPos, rawPos) {
|
4764
|
+
if (rawPos === data.length) {
|
4765
|
+
throw new Error("Ran out of data");
|
4766
|
+
}
|
4767
|
+
|
4768
|
+
let pixel = data[rawPos];
|
4769
|
+
pxData[pxPos] = pixel;
|
4770
|
+
pxData[pxPos + 1] = pixel;
|
4771
|
+
pxData[pxPos + 2] = pixel;
|
4772
|
+
pxData[pxPos + 3] = 0xff;
|
4773
|
+
},
|
4774
|
+
|
4775
|
+
// 2 - LA
|
4776
|
+
// 0: 0, 1: 0, 2: 0, 3: 1
|
4777
|
+
function (pxData, data, pxPos, rawPos) {
|
4778
|
+
if (rawPos + 1 >= data.length) {
|
4779
|
+
throw new Error("Ran out of data");
|
4780
|
+
}
|
4781
|
+
|
4782
|
+
let pixel = data[rawPos];
|
4783
|
+
pxData[pxPos] = pixel;
|
4784
|
+
pxData[pxPos + 1] = pixel;
|
4785
|
+
pxData[pxPos + 2] = pixel;
|
4786
|
+
pxData[pxPos + 3] = data[rawPos + 1];
|
4787
|
+
},
|
4788
|
+
|
4789
|
+
// 3 - RGB
|
4790
|
+
// 0: 0, 1: 1, 2: 2, 3: 0xff
|
4791
|
+
function (pxData, data, pxPos, rawPos) {
|
4792
|
+
if (rawPos + 2 >= data.length) {
|
4793
|
+
throw new Error("Ran out of data");
|
4794
|
+
}
|
4795
|
+
|
4796
|
+
pxData[pxPos] = data[rawPos];
|
4797
|
+
pxData[pxPos + 1] = data[rawPos + 1];
|
4798
|
+
pxData[pxPos + 2] = data[rawPos + 2];
|
4799
|
+
pxData[pxPos + 3] = 0xff;
|
4800
|
+
},
|
4801
|
+
|
4802
|
+
// 4 - RGBA
|
4803
|
+
// 0: 0, 1: 1, 2: 2, 3: 3
|
4804
|
+
function (pxData, data, pxPos, rawPos) {
|
4805
|
+
if (rawPos + 3 >= data.length) {
|
4806
|
+
throw new Error("Ran out of data");
|
4807
|
+
}
|
4808
|
+
|
4809
|
+
pxData[pxPos] = data[rawPos];
|
4810
|
+
pxData[pxPos + 1] = data[rawPos + 1];
|
4811
|
+
pxData[pxPos + 2] = data[rawPos + 2];
|
4812
|
+
pxData[pxPos + 3] = data[rawPos + 3];
|
4813
|
+
},
|
4814
|
+
];
|
4815
|
+
|
4816
|
+
let pixelBppCustomMapper = [
|
4817
|
+
// 0 - dummy entry
|
4818
|
+
function () {},
|
4819
|
+
|
4820
|
+
// 1 - L
|
4821
|
+
// 0: 0, 1: 0, 2: 0, 3: 0xff
|
4822
|
+
function (pxData, pixelData, pxPos, maxBit) {
|
4823
|
+
let pixel = pixelData[0];
|
4824
|
+
pxData[pxPos] = pixel;
|
4825
|
+
pxData[pxPos + 1] = pixel;
|
4826
|
+
pxData[pxPos + 2] = pixel;
|
4827
|
+
pxData[pxPos + 3] = maxBit;
|
4828
|
+
},
|
4829
|
+
|
4830
|
+
// 2 - LA
|
4831
|
+
// 0: 0, 1: 0, 2: 0, 3: 1
|
4832
|
+
function (pxData, pixelData, pxPos) {
|
4833
|
+
let pixel = pixelData[0];
|
4834
|
+
pxData[pxPos] = pixel;
|
4835
|
+
pxData[pxPos + 1] = pixel;
|
4836
|
+
pxData[pxPos + 2] = pixel;
|
4837
|
+
pxData[pxPos + 3] = pixelData[1];
|
4838
|
+
},
|
4839
|
+
|
4840
|
+
// 3 - RGB
|
4841
|
+
// 0: 0, 1: 1, 2: 2, 3: 0xff
|
4842
|
+
function (pxData, pixelData, pxPos, maxBit) {
|
4843
|
+
pxData[pxPos] = pixelData[0];
|
4844
|
+
pxData[pxPos + 1] = pixelData[1];
|
4845
|
+
pxData[pxPos + 2] = pixelData[2];
|
4846
|
+
pxData[pxPos + 3] = maxBit;
|
4847
|
+
},
|
4848
|
+
|
4849
|
+
// 4 - RGBA
|
4850
|
+
// 0: 0, 1: 1, 2: 2, 3: 3
|
4851
|
+
function (pxData, pixelData, pxPos) {
|
4852
|
+
pxData[pxPos] = pixelData[0];
|
4853
|
+
pxData[pxPos + 1] = pixelData[1];
|
4854
|
+
pxData[pxPos + 2] = pixelData[2];
|
4855
|
+
pxData[pxPos + 3] = pixelData[3];
|
4856
|
+
},
|
4857
|
+
];
|
4858
|
+
|
4859
|
+
function bitRetriever(data, depth) {
|
4860
|
+
let leftOver = [];
|
4861
|
+
let i = 0;
|
4862
|
+
|
4863
|
+
function split() {
|
4864
|
+
if (i === data.length) {
|
4865
|
+
throw new Error("Ran out of data");
|
4866
|
+
}
|
4867
|
+
let byte = data[i];
|
4868
|
+
i++;
|
4869
|
+
let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
|
4870
|
+
switch (depth) {
|
4871
|
+
default:
|
4872
|
+
throw new Error("unrecognised depth");
|
4873
|
+
case 16:
|
4874
|
+
byte2 = data[i];
|
4875
|
+
i++;
|
4876
|
+
leftOver.push((byte << 8) + byte2);
|
4877
|
+
break;
|
4878
|
+
case 4:
|
4879
|
+
byte2 = byte & 0x0f;
|
4880
|
+
byte1 = byte >> 4;
|
4881
|
+
leftOver.push(byte1, byte2);
|
4882
|
+
break;
|
4883
|
+
case 2:
|
4884
|
+
byte4 = byte & 3;
|
4885
|
+
byte3 = (byte >> 2) & 3;
|
4886
|
+
byte2 = (byte >> 4) & 3;
|
4887
|
+
byte1 = (byte >> 6) & 3;
|
4888
|
+
leftOver.push(byte1, byte2, byte3, byte4);
|
4889
|
+
break;
|
4890
|
+
case 1:
|
4891
|
+
byte8 = byte & 1;
|
4892
|
+
byte7 = (byte >> 1) & 1;
|
4893
|
+
byte6 = (byte >> 2) & 1;
|
4894
|
+
byte5 = (byte >> 3) & 1;
|
4895
|
+
byte4 = (byte >> 4) & 1;
|
4896
|
+
byte3 = (byte >> 5) & 1;
|
4897
|
+
byte2 = (byte >> 6) & 1;
|
4898
|
+
byte1 = (byte >> 7) & 1;
|
4899
|
+
leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
|
4900
|
+
break;
|
4901
|
+
}
|
5087
4902
|
}
|
5088
|
-
return i
|
5089
|
-
}
|
5090
4903
|
|
5091
|
-
|
5092
|
-
|
4904
|
+
return {
|
4905
|
+
get: function (count) {
|
4906
|
+
while (leftOver.length < count) {
|
4907
|
+
split();
|
4908
|
+
}
|
4909
|
+
let returner = leftOver.slice(0, count);
|
4910
|
+
leftOver = leftOver.slice(count);
|
4911
|
+
return returner;
|
4912
|
+
},
|
4913
|
+
resetAfterLine: function () {
|
4914
|
+
leftOver.length = 0;
|
4915
|
+
},
|
4916
|
+
end: function () {
|
4917
|
+
if (i !== data.length) {
|
4918
|
+
throw new Error("extra data found");
|
4919
|
+
}
|
4920
|
+
},
|
4921
|
+
};
|
5093
4922
|
}
|
5094
4923
|
|
5095
|
-
function
|
5096
|
-
|
4924
|
+
function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
|
4925
|
+
// eslint-disable-line max-params
|
4926
|
+
let imageWidth = image.width;
|
4927
|
+
let imageHeight = image.height;
|
4928
|
+
let imagePass = image.index;
|
4929
|
+
for (let y = 0; y < imageHeight; y++) {
|
4930
|
+
for (let x = 0; x < imageWidth; x++) {
|
4931
|
+
let pxPos = getPxPos(x, y, imagePass);
|
4932
|
+
pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
|
4933
|
+
rawPos += bpp; //eslint-disable-line no-param-reassign
|
4934
|
+
}
|
4935
|
+
}
|
4936
|
+
return rawPos;
|
5097
4937
|
}
|
5098
4938
|
|
5099
|
-
function
|
5100
|
-
|
4939
|
+
function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
|
4940
|
+
// eslint-disable-line max-params
|
4941
|
+
let imageWidth = image.width;
|
4942
|
+
let imageHeight = image.height;
|
4943
|
+
let imagePass = image.index;
|
4944
|
+
for (let y = 0; y < imageHeight; y++) {
|
4945
|
+
for (let x = 0; x < imageWidth; x++) {
|
4946
|
+
let pixelData = bits.get(bpp);
|
4947
|
+
let pxPos = getPxPos(x, y, imagePass);
|
4948
|
+
pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
|
4949
|
+
}
|
4950
|
+
bits.resetAfterLine();
|
4951
|
+
}
|
5101
4952
|
}
|
5102
4953
|
|
5103
|
-
function
|
5104
|
-
|
5105
|
-
|
4954
|
+
bitmapper$2.dataToBitMap = function (data, bitmapInfo) {
|
4955
|
+
let width = bitmapInfo.width;
|
4956
|
+
let height = bitmapInfo.height;
|
4957
|
+
let depth = bitmapInfo.depth;
|
4958
|
+
let bpp = bitmapInfo.bpp;
|
4959
|
+
let interlace = bitmapInfo.interlace;
|
4960
|
+
let bits;
|
5106
4961
|
|
5107
|
-
|
5108
|
-
|
5109
|
-
}
|
4962
|
+
if (depth !== 8) {
|
4963
|
+
bits = bitRetriever(data, depth);
|
4964
|
+
}
|
4965
|
+
let pxData;
|
4966
|
+
if (depth <= 8) {
|
4967
|
+
pxData = Buffer.alloc(width * height * 4);
|
4968
|
+
} else {
|
4969
|
+
pxData = new Uint16Array(width * height * 4);
|
4970
|
+
}
|
4971
|
+
let maxBit = Math.pow(2, depth) - 1;
|
4972
|
+
let rawPos = 0;
|
4973
|
+
let images;
|
4974
|
+
let getPxPos;
|
5110
4975
|
|
5111
|
-
|
5112
|
-
|
5113
|
-
|
5114
|
-
|
5115
|
-
|
5116
|
-
|
5117
|
-
|
5118
|
-
|
5119
|
-
|
5120
|
-
|
5121
|
-
|
5122
|
-
|
5123
|
-
|
5124
|
-
|
5125
|
-
if (
|
5126
|
-
|
5127
|
-
|
4976
|
+
if (interlace) {
|
4977
|
+
images = interlaceUtils.getImagePasses(width, height);
|
4978
|
+
getPxPos = interlaceUtils.getInterlaceIterator(width, height);
|
4979
|
+
} else {
|
4980
|
+
let nonInterlacedPxPos = 0;
|
4981
|
+
getPxPos = function () {
|
4982
|
+
let returner = nonInterlacedPxPos;
|
4983
|
+
nonInterlacedPxPos += 4;
|
4984
|
+
return returner;
|
4985
|
+
};
|
4986
|
+
images = [{ width: width, height: height }];
|
4987
|
+
}
|
4988
|
+
|
4989
|
+
for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
|
4990
|
+
if (depth === 8) {
|
4991
|
+
rawPos = mapImage8Bit(
|
4992
|
+
images[imageIndex],
|
4993
|
+
pxData,
|
4994
|
+
getPxPos,
|
4995
|
+
bpp,
|
4996
|
+
data,
|
4997
|
+
rawPos
|
4998
|
+
);
|
5128
4999
|
} else {
|
5129
|
-
|
5130
|
-
|
5000
|
+
mapImageCustomBit(
|
5001
|
+
images[imageIndex],
|
5002
|
+
pxData,
|
5003
|
+
getPxPos,
|
5004
|
+
bpp,
|
5005
|
+
bits,
|
5006
|
+
maxBit
|
5007
|
+
);
|
5008
|
+
}
|
5009
|
+
}
|
5010
|
+
if (depth === 8) {
|
5011
|
+
if (rawPos !== data.length) {
|
5012
|
+
throw new Error("extra data found");
|
5131
5013
|
}
|
5132
|
-
// legacy write(string, encoding, offset, length) - remove in v0.13
|
5133
5014
|
} else {
|
5134
|
-
|
5135
|
-
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
5136
|
-
)
|
5015
|
+
bits.end();
|
5137
5016
|
}
|
5138
5017
|
|
5139
|
-
|
5140
|
-
|
5018
|
+
return pxData;
|
5019
|
+
};
|
5020
|
+
|
5021
|
+
function dePalette(indata, outdata, width, height, palette) {
|
5022
|
+
let pxPos = 0;
|
5023
|
+
// use values from palette
|
5024
|
+
for (let y = 0; y < height; y++) {
|
5025
|
+
for (let x = 0; x < width; x++) {
|
5026
|
+
let color = palette[indata[pxPos]];
|
5027
|
+
|
5028
|
+
if (!color) {
|
5029
|
+
throw new Error("index " + indata[pxPos] + " not in palette");
|
5030
|
+
}
|
5141
5031
|
|
5142
|
-
|
5143
|
-
|
5032
|
+
for (let i = 0; i < 4; i++) {
|
5033
|
+
outdata[pxPos + i] = color[i];
|
5034
|
+
}
|
5035
|
+
pxPos += 4;
|
5036
|
+
}
|
5144
5037
|
}
|
5038
|
+
}
|
5145
5039
|
|
5146
|
-
|
5040
|
+
function replaceTransparentColor(indata, outdata, width, height, transColor) {
|
5041
|
+
let pxPos = 0;
|
5042
|
+
for (let y = 0; y < height; y++) {
|
5043
|
+
for (let x = 0; x < width; x++) {
|
5044
|
+
let makeTrans = false;
|
5147
5045
|
|
5148
|
-
|
5149
|
-
|
5150
|
-
|
5151
|
-
|
5152
|
-
|
5046
|
+
if (transColor.length === 1) {
|
5047
|
+
if (transColor[0] === indata[pxPos]) {
|
5048
|
+
makeTrans = true;
|
5049
|
+
}
|
5050
|
+
} else if (
|
5051
|
+
transColor[0] === indata[pxPos] &&
|
5052
|
+
transColor[1] === indata[pxPos + 1] &&
|
5053
|
+
transColor[2] === indata[pxPos + 2]
|
5054
|
+
) {
|
5055
|
+
makeTrans = true;
|
5056
|
+
}
|
5057
|
+
if (makeTrans) {
|
5058
|
+
for (let i = 0; i < 4; i++) {
|
5059
|
+
outdata[pxPos + i] = 0;
|
5060
|
+
}
|
5061
|
+
}
|
5062
|
+
pxPos += 4;
|
5063
|
+
}
|
5064
|
+
}
|
5065
|
+
}
|
5153
5066
|
|
5154
|
-
|
5155
|
-
|
5156
|
-
|
5067
|
+
function scaleDepth(indata, outdata, width, height, depth) {
|
5068
|
+
let maxOutSample = 255;
|
5069
|
+
let maxInSample = Math.pow(2, depth) - 1;
|
5070
|
+
let pxPos = 0;
|
5157
5071
|
|
5158
|
-
|
5159
|
-
|
5072
|
+
for (let y = 0; y < height; y++) {
|
5073
|
+
for (let x = 0; x < width; x++) {
|
5074
|
+
for (let i = 0; i < 4; i++) {
|
5075
|
+
outdata[pxPos + i] = Math.floor(
|
5076
|
+
(indata[pxPos + i] * maxOutSample) / maxInSample + 0.5
|
5077
|
+
);
|
5078
|
+
}
|
5079
|
+
pxPos += 4;
|
5080
|
+
}
|
5081
|
+
}
|
5082
|
+
}
|
5160
5083
|
|
5161
|
-
|
5162
|
-
|
5163
|
-
|
5084
|
+
var formatNormaliser$2 = function (indata, imageData) {
|
5085
|
+
let depth = imageData.depth;
|
5086
|
+
let width = imageData.width;
|
5087
|
+
let height = imageData.height;
|
5088
|
+
let colorType = imageData.colorType;
|
5089
|
+
let transColor = imageData.transColor;
|
5090
|
+
let palette = imageData.palette;
|
5164
5091
|
|
5165
|
-
|
5166
|
-
// Warning: maxLength not taken into account in base64Write
|
5167
|
-
return base64Write(this, string, offset, length)
|
5092
|
+
let outdata = indata; // only different for 16 bits
|
5168
5093
|
|
5169
|
-
|
5170
|
-
|
5171
|
-
|
5172
|
-
|
5173
|
-
|
5094
|
+
if (colorType === 3) {
|
5095
|
+
// paletted
|
5096
|
+
dePalette(indata, outdata, width, height, palette);
|
5097
|
+
} else {
|
5098
|
+
if (transColor) {
|
5099
|
+
replaceTransparentColor(indata, outdata, width, height, transColor);
|
5100
|
+
}
|
5101
|
+
// if it needs scaling
|
5102
|
+
if (depth !== 8) {
|
5103
|
+
// if we need to change the buffer size
|
5104
|
+
if (depth === 16) {
|
5105
|
+
outdata = Buffer.alloc(width * height * 4);
|
5106
|
+
}
|
5107
|
+
scaleDepth(indata, outdata, width, height, depth);
|
5108
|
+
}
|
5109
|
+
}
|
5110
|
+
return outdata;
|
5111
|
+
};
|
5112
|
+
|
5113
|
+
let util$2 = require$$0__default["default"];
|
5114
|
+
let zlib$3 = require$$1__default$1["default"];
|
5115
|
+
let ChunkStream = chunkstream.exports;
|
5116
|
+
let FilterAsync = filterParseAsync.exports;
|
5117
|
+
let Parser$2 = parser.exports;
|
5118
|
+
let bitmapper$1 = bitmapper$2;
|
5119
|
+
let formatNormaliser$1 = formatNormaliser$2;
|
5120
|
+
|
5121
|
+
let ParserAsync = (parserAsync.exports = function (options) {
|
5122
|
+
ChunkStream.call(this);
|
5123
|
+
|
5124
|
+
this._parser = new Parser$2(options, {
|
5125
|
+
read: this.read.bind(this),
|
5126
|
+
error: this._handleError.bind(this),
|
5127
|
+
metadata: this._handleMetaData.bind(this),
|
5128
|
+
gamma: this.emit.bind(this, "gamma"),
|
5129
|
+
palette: this._handlePalette.bind(this),
|
5130
|
+
transColor: this._handleTransColor.bind(this),
|
5131
|
+
finished: this._finished.bind(this),
|
5132
|
+
inflateData: this._inflateData.bind(this),
|
5133
|
+
simpleTransparency: this._simpleTransparency.bind(this),
|
5134
|
+
headersFinished: this._headersFinished.bind(this),
|
5135
|
+
});
|
5136
|
+
this._options = options;
|
5137
|
+
this.writable = true;
|
5174
5138
|
|
5175
|
-
|
5176
|
-
|
5177
|
-
|
5178
|
-
|
5179
|
-
|
5139
|
+
this._parser.start();
|
5140
|
+
});
|
5141
|
+
util$2.inherits(ParserAsync, ChunkStream);
|
5142
|
+
|
5143
|
+
ParserAsync.prototype._handleError = function (err) {
|
5144
|
+
this.emit("error", err);
|
5145
|
+
|
5146
|
+
this.writable = false;
|
5147
|
+
|
5148
|
+
this.destroy();
|
5149
|
+
|
5150
|
+
if (this._inflate && this._inflate.destroy) {
|
5151
|
+
this._inflate.destroy();
|
5152
|
+
}
|
5153
|
+
|
5154
|
+
if (this._filter) {
|
5155
|
+
this._filter.destroy();
|
5156
|
+
// For backward compatibility with Node 7 and below.
|
5157
|
+
// Suppress errors due to _inflate calling write() even after
|
5158
|
+
// it's destroy()'ed.
|
5159
|
+
this._filter.on("error", function () {});
|
5180
5160
|
}
|
5161
|
+
|
5162
|
+
this.errord = true;
|
5181
5163
|
};
|
5182
5164
|
|
5183
|
-
|
5184
|
-
|
5185
|
-
|
5186
|
-
|
5165
|
+
ParserAsync.prototype._inflateData = function (data) {
|
5166
|
+
if (!this._inflate) {
|
5167
|
+
if (this._bitmapInfo.interlace) {
|
5168
|
+
this._inflate = zlib$3.createInflate();
|
5169
|
+
|
5170
|
+
this._inflate.on("error", this.emit.bind(this, "error"));
|
5171
|
+
this._filter.on("complete", this._complete.bind(this));
|
5172
|
+
|
5173
|
+
this._inflate.pipe(this._filter);
|
5174
|
+
} else {
|
5175
|
+
let rowSize =
|
5176
|
+
((this._bitmapInfo.width *
|
5177
|
+
this._bitmapInfo.bpp *
|
5178
|
+
this._bitmapInfo.depth +
|
5179
|
+
7) >>
|
5180
|
+
3) +
|
5181
|
+
1;
|
5182
|
+
let imageSize = rowSize * this._bitmapInfo.height;
|
5183
|
+
let chunkSize = Math.max(imageSize, zlib$3.Z_MIN_CHUNK);
|
5184
|
+
|
5185
|
+
this._inflate = zlib$3.createInflate({ chunkSize: chunkSize });
|
5186
|
+
let leftToInflate = imageSize;
|
5187
|
+
|
5188
|
+
let emitError = this.emit.bind(this, "error");
|
5189
|
+
this._inflate.on("error", function (err) {
|
5190
|
+
if (!leftToInflate) {
|
5191
|
+
return;
|
5192
|
+
}
|
5193
|
+
|
5194
|
+
emitError(err);
|
5195
|
+
});
|
5196
|
+
this._filter.on("complete", this._complete.bind(this));
|
5197
|
+
|
5198
|
+
let filterWrite = this._filter.write.bind(this._filter);
|
5199
|
+
this._inflate.on("data", function (chunk) {
|
5200
|
+
if (!leftToInflate) {
|
5201
|
+
return;
|
5202
|
+
}
|
5203
|
+
|
5204
|
+
if (chunk.length > leftToInflate) {
|
5205
|
+
chunk = chunk.slice(0, leftToInflate);
|
5206
|
+
}
|
5207
|
+
|
5208
|
+
leftToInflate -= chunk.length;
|
5209
|
+
|
5210
|
+
filterWrite(chunk);
|
5211
|
+
});
|
5212
|
+
|
5213
|
+
this._inflate.on("end", this._filter.end.bind(this._filter));
|
5214
|
+
}
|
5187
5215
|
}
|
5216
|
+
this._inflate.write(data);
|
5217
|
+
};
|
5218
|
+
|
5219
|
+
ParserAsync.prototype._handleMetaData = function (metaData) {
|
5220
|
+
this._metaData = metaData;
|
5221
|
+
this._bitmapInfo = Object.create(metaData);
|
5222
|
+
|
5223
|
+
this._filter = new FilterAsync(this._bitmapInfo);
|
5224
|
+
};
|
5225
|
+
|
5226
|
+
ParserAsync.prototype._handleTransColor = function (transColor) {
|
5227
|
+
this._bitmapInfo.transColor = transColor;
|
5228
|
+
};
|
5229
|
+
|
5230
|
+
ParserAsync.prototype._handlePalette = function (palette) {
|
5231
|
+
this._bitmapInfo.palette = palette;
|
5232
|
+
};
|
5233
|
+
|
5234
|
+
ParserAsync.prototype._simpleTransparency = function () {
|
5235
|
+
this._metaData.alpha = true;
|
5236
|
+
};
|
5237
|
+
|
5238
|
+
ParserAsync.prototype._headersFinished = function () {
|
5239
|
+
// Up until this point, we don't know if we have a tRNS chunk (alpha)
|
5240
|
+
// so we can't emit metadata any earlier
|
5241
|
+
this.emit("metadata", this._metaData);
|
5188
5242
|
};
|
5189
5243
|
|
5190
|
-
function
|
5191
|
-
if (
|
5192
|
-
return
|
5244
|
+
ParserAsync.prototype._finished = function () {
|
5245
|
+
if (this.errord) {
|
5246
|
+
return;
|
5247
|
+
}
|
5248
|
+
|
5249
|
+
if (!this._inflate) {
|
5250
|
+
this.emit("error", "No Inflate block");
|
5193
5251
|
} else {
|
5194
|
-
|
5252
|
+
// no more data to inflate
|
5253
|
+
this._inflate.end();
|
5195
5254
|
}
|
5196
|
-
}
|
5255
|
+
};
|
5197
5256
|
|
5198
|
-
function
|
5199
|
-
|
5200
|
-
|
5257
|
+
ParserAsync.prototype._complete = function (filteredData) {
|
5258
|
+
if (this.errord) {
|
5259
|
+
return;
|
5260
|
+
}
|
5201
5261
|
|
5202
|
-
|
5203
|
-
while (i < end) {
|
5204
|
-
var firstByte = buf[i];
|
5205
|
-
var codePoint = null;
|
5206
|
-
var bytesPerSequence = (firstByte > 0xEF) ? 4
|
5207
|
-
: (firstByte > 0xDF) ? 3
|
5208
|
-
: (firstByte > 0xBF) ? 2
|
5209
|
-
: 1;
|
5262
|
+
let normalisedBitmapData;
|
5210
5263
|
|
5211
|
-
|
5212
|
-
|
5264
|
+
try {
|
5265
|
+
let bitmapData = bitmapper$1.dataToBitMap(filteredData, this._bitmapInfo);
|
5213
5266
|
|
5214
|
-
|
5215
|
-
|
5216
|
-
|
5217
|
-
|
5218
|
-
|
5219
|
-
|
5220
|
-
|
5221
|
-
|
5222
|
-
|
5223
|
-
|
5224
|
-
|
5225
|
-
|
5267
|
+
normalisedBitmapData = formatNormaliser$1(bitmapData, this._bitmapInfo);
|
5268
|
+
bitmapData = null;
|
5269
|
+
} catch (ex) {
|
5270
|
+
this._handleError(ex);
|
5271
|
+
return;
|
5272
|
+
}
|
5273
|
+
|
5274
|
+
this.emit("parsed", normalisedBitmapData);
|
5275
|
+
};
|
5276
|
+
|
5277
|
+
var packerAsync = {exports: {}};
|
5278
|
+
|
5279
|
+
var packer = {exports: {}};
|
5280
|
+
|
5281
|
+
let constants$3 = constants$5;
|
5282
|
+
|
5283
|
+
var bitpacker = function (dataIn, width, height, options) {
|
5284
|
+
let outHasAlpha =
|
5285
|
+
[constants$3.COLORTYPE_COLOR_ALPHA, constants$3.COLORTYPE_ALPHA].indexOf(
|
5286
|
+
options.colorType
|
5287
|
+
) !== -1;
|
5288
|
+
if (options.colorType === options.inputColorType) {
|
5289
|
+
let bigEndian = (function () {
|
5290
|
+
let buffer = new ArrayBuffer(2);
|
5291
|
+
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
|
5292
|
+
// Int16Array uses the platform's endianness.
|
5293
|
+
return new Int16Array(buffer)[0] !== 256;
|
5294
|
+
})();
|
5295
|
+
// If no need to convert to grayscale and alpha is present/absent in both, take a fast route
|
5296
|
+
if (options.bitDepth === 8 || (options.bitDepth === 16 && bigEndian)) {
|
5297
|
+
return dataIn;
|
5298
|
+
}
|
5299
|
+
}
|
5300
|
+
|
5301
|
+
// map to a UInt16 array if data is 16bit, fix endianness below
|
5302
|
+
let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
|
5303
|
+
|
5304
|
+
let maxValue = 255;
|
5305
|
+
let inBpp = constants$3.COLORTYPE_TO_BPP_MAP[options.inputColorType];
|
5306
|
+
if (inBpp === 4 && !options.inputHasAlpha) {
|
5307
|
+
inBpp = 3;
|
5308
|
+
}
|
5309
|
+
let outBpp = constants$3.COLORTYPE_TO_BPP_MAP[options.colorType];
|
5310
|
+
if (options.bitDepth === 16) {
|
5311
|
+
maxValue = 65535;
|
5312
|
+
outBpp *= 2;
|
5313
|
+
}
|
5314
|
+
let outData = Buffer.alloc(width * height * outBpp);
|
5315
|
+
|
5316
|
+
let inIndex = 0;
|
5317
|
+
let outIndex = 0;
|
5318
|
+
|
5319
|
+
let bgColor = options.bgColor || {};
|
5320
|
+
if (bgColor.red === undefined) {
|
5321
|
+
bgColor.red = maxValue;
|
5322
|
+
}
|
5323
|
+
if (bgColor.green === undefined) {
|
5324
|
+
bgColor.green = maxValue;
|
5325
|
+
}
|
5326
|
+
if (bgColor.blue === undefined) {
|
5327
|
+
bgColor.blue = maxValue;
|
5328
|
+
}
|
5329
|
+
|
5330
|
+
function getRGBA() {
|
5331
|
+
let red;
|
5332
|
+
let green;
|
5333
|
+
let blue;
|
5334
|
+
let alpha = maxValue;
|
5335
|
+
switch (options.inputColorType) {
|
5336
|
+
case constants$3.COLORTYPE_COLOR_ALPHA:
|
5337
|
+
alpha = data[inIndex + 3];
|
5338
|
+
red = data[inIndex];
|
5339
|
+
green = data[inIndex + 1];
|
5340
|
+
blue = data[inIndex + 2];
|
5341
|
+
break;
|
5342
|
+
case constants$3.COLORTYPE_COLOR:
|
5343
|
+
red = data[inIndex];
|
5344
|
+
green = data[inIndex + 1];
|
5345
|
+
blue = data[inIndex + 2];
|
5346
|
+
break;
|
5347
|
+
case constants$3.COLORTYPE_ALPHA:
|
5348
|
+
alpha = data[inIndex + 1];
|
5349
|
+
red = data[inIndex];
|
5350
|
+
green = red;
|
5351
|
+
blue = red;
|
5352
|
+
break;
|
5353
|
+
case constants$3.COLORTYPE_GRAYSCALE:
|
5354
|
+
red = data[inIndex];
|
5355
|
+
green = red;
|
5356
|
+
blue = red;
|
5357
|
+
break;
|
5358
|
+
default:
|
5359
|
+
throw new Error(
|
5360
|
+
"input color type:" +
|
5361
|
+
options.inputColorType +
|
5362
|
+
" is not supported at present"
|
5363
|
+
);
|
5364
|
+
}
|
5365
|
+
|
5366
|
+
if (options.inputHasAlpha) {
|
5367
|
+
if (!outHasAlpha) {
|
5368
|
+
alpha /= maxValue;
|
5369
|
+
red = Math.min(
|
5370
|
+
Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
|
5371
|
+
maxValue
|
5372
|
+
);
|
5373
|
+
green = Math.min(
|
5374
|
+
Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
|
5375
|
+
maxValue
|
5376
|
+
);
|
5377
|
+
blue = Math.min(
|
5378
|
+
Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
|
5379
|
+
maxValue
|
5380
|
+
);
|
5381
|
+
}
|
5382
|
+
}
|
5383
|
+
return { red: red, green: green, blue: blue, alpha: alpha };
|
5384
|
+
}
|
5385
|
+
|
5386
|
+
for (let y = 0; y < height; y++) {
|
5387
|
+
for (let x = 0; x < width; x++) {
|
5388
|
+
let rgba = getRGBA();
|
5389
|
+
|
5390
|
+
switch (options.colorType) {
|
5391
|
+
case constants$3.COLORTYPE_COLOR_ALPHA:
|
5392
|
+
case constants$3.COLORTYPE_COLOR:
|
5393
|
+
if (options.bitDepth === 8) {
|
5394
|
+
outData[outIndex] = rgba.red;
|
5395
|
+
outData[outIndex + 1] = rgba.green;
|
5396
|
+
outData[outIndex + 2] = rgba.blue;
|
5397
|
+
if (outHasAlpha) {
|
5398
|
+
outData[outIndex + 3] = rgba.alpha;
|
5226
5399
|
}
|
5227
|
-
}
|
5228
|
-
|
5229
|
-
|
5230
|
-
|
5231
|
-
|
5232
|
-
|
5233
|
-
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
5234
|
-
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
5235
|
-
codePoint = tempCodePoint;
|
5400
|
+
} else {
|
5401
|
+
outData.writeUInt16BE(rgba.red, outIndex);
|
5402
|
+
outData.writeUInt16BE(rgba.green, outIndex + 2);
|
5403
|
+
outData.writeUInt16BE(rgba.blue, outIndex + 4);
|
5404
|
+
if (outHasAlpha) {
|
5405
|
+
outData.writeUInt16BE(rgba.alpha, outIndex + 6);
|
5236
5406
|
}
|
5237
5407
|
}
|
5238
|
-
break
|
5239
|
-
case
|
5240
|
-
|
5241
|
-
|
5242
|
-
|
5243
|
-
if (
|
5244
|
-
|
5245
|
-
if (
|
5246
|
-
|
5408
|
+
break;
|
5409
|
+
case constants$3.COLORTYPE_ALPHA:
|
5410
|
+
case constants$3.COLORTYPE_GRAYSCALE: {
|
5411
|
+
// Convert to grayscale and alpha
|
5412
|
+
let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
|
5413
|
+
if (options.bitDepth === 8) {
|
5414
|
+
outData[outIndex] = grayscale;
|
5415
|
+
if (outHasAlpha) {
|
5416
|
+
outData[outIndex + 1] = rgba.alpha;
|
5417
|
+
}
|
5418
|
+
} else {
|
5419
|
+
outData.writeUInt16BE(grayscale, outIndex);
|
5420
|
+
if (outHasAlpha) {
|
5421
|
+
outData.writeUInt16BE(rgba.alpha, outIndex + 2);
|
5247
5422
|
}
|
5248
5423
|
}
|
5424
|
+
break;
|
5425
|
+
}
|
5426
|
+
default:
|
5427
|
+
throw new Error("unrecognised color Type " + options.colorType);
|
5249
5428
|
}
|
5250
|
-
}
|
5251
5429
|
|
5252
|
-
|
5253
|
-
|
5254
|
-
// replacement char (U+FFFD) and advance only 1 byte
|
5255
|
-
codePoint = 0xFFFD;
|
5256
|
-
bytesPerSequence = 1;
|
5257
|
-
} else if (codePoint > 0xFFFF) {
|
5258
|
-
// encode to utf16 (surrogate pair dance)
|
5259
|
-
codePoint -= 0x10000;
|
5260
|
-
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
5261
|
-
codePoint = 0xDC00 | codePoint & 0x3FF;
|
5430
|
+
inIndex += inBpp;
|
5431
|
+
outIndex += outBpp;
|
5262
5432
|
}
|
5263
|
-
|
5264
|
-
res.push(codePoint);
|
5265
|
-
i += bytesPerSequence;
|
5266
5433
|
}
|
5267
5434
|
|
5268
|
-
return
|
5269
|
-
}
|
5435
|
+
return outData;
|
5436
|
+
};
|
5270
5437
|
|
5271
|
-
|
5272
|
-
// the lowest limit is Chrome, with 0x10000 args.
|
5273
|
-
// We go 1 magnitude less, for safety
|
5274
|
-
var MAX_ARGUMENTS_LENGTH = 0x1000;
|
5438
|
+
let paethPredictor = paethPredictor$2;
|
5275
5439
|
|
5276
|
-
function
|
5277
|
-
|
5278
|
-
|
5279
|
-
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
5440
|
+
function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
|
5441
|
+
for (let x = 0; x < byteWidth; x++) {
|
5442
|
+
rawData[rawPos + x] = pxData[pxPos + x];
|
5280
5443
|
}
|
5444
|
+
}
|
5281
5445
|
|
5282
|
-
|
5283
|
-
|
5284
|
-
|
5285
|
-
|
5286
|
-
|
5287
|
-
|
5288
|
-
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
5289
|
-
);
|
5446
|
+
function filterSumNone(pxData, pxPos, byteWidth) {
|
5447
|
+
let sum = 0;
|
5448
|
+
let length = pxPos + byteWidth;
|
5449
|
+
|
5450
|
+
for (let i = pxPos; i < length; i++) {
|
5451
|
+
sum += Math.abs(pxData[i]);
|
5290
5452
|
}
|
5291
|
-
return
|
5453
|
+
return sum;
|
5292
5454
|
}
|
5293
5455
|
|
5294
|
-
function
|
5295
|
-
|
5296
|
-
|
5456
|
+
function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
5457
|
+
for (let x = 0; x < byteWidth; x++) {
|
5458
|
+
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
5459
|
+
let val = pxData[pxPos + x] - left;
|
5297
5460
|
|
5298
|
-
|
5299
|
-
ret += String.fromCharCode(buf[i] & 0x7F);
|
5461
|
+
rawData[rawPos + x] = val;
|
5300
5462
|
}
|
5301
|
-
return ret
|
5302
5463
|
}
|
5303
5464
|
|
5304
|
-
function
|
5305
|
-
|
5306
|
-
|
5465
|
+
function filterSumSub(pxData, pxPos, byteWidth, bpp) {
|
5466
|
+
let sum = 0;
|
5467
|
+
for (let x = 0; x < byteWidth; x++) {
|
5468
|
+
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
5469
|
+
let val = pxData[pxPos + x] - left;
|
5307
5470
|
|
5308
|
-
|
5309
|
-
ret += String.fromCharCode(buf[i]);
|
5471
|
+
sum += Math.abs(val);
|
5310
5472
|
}
|
5311
|
-
|
5473
|
+
|
5474
|
+
return sum;
|
5312
5475
|
}
|
5313
5476
|
|
5314
|
-
function
|
5315
|
-
|
5477
|
+
function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
|
5478
|
+
for (let x = 0; x < byteWidth; x++) {
|
5479
|
+
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
5480
|
+
let val = pxData[pxPos + x] - up;
|
5481
|
+
|
5482
|
+
rawData[rawPos + x] = val;
|
5483
|
+
}
|
5484
|
+
}
|
5316
5485
|
|
5317
|
-
|
5318
|
-
|
5486
|
+
function filterSumUp(pxData, pxPos, byteWidth) {
|
5487
|
+
let sum = 0;
|
5488
|
+
let length = pxPos + byteWidth;
|
5489
|
+
for (let x = pxPos; x < length; x++) {
|
5490
|
+
let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
|
5491
|
+
let val = pxData[x] - up;
|
5319
5492
|
|
5320
|
-
|
5321
|
-
for (var i = start; i < end; ++i) {
|
5322
|
-
out += toHex(buf[i]);
|
5493
|
+
sum += Math.abs(val);
|
5323
5494
|
}
|
5324
|
-
|
5495
|
+
|
5496
|
+
return sum;
|
5325
5497
|
}
|
5326
5498
|
|
5327
|
-
function
|
5328
|
-
|
5329
|
-
|
5330
|
-
|
5331
|
-
|
5499
|
+
function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
5500
|
+
for (let x = 0; x < byteWidth; x++) {
|
5501
|
+
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
5502
|
+
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
5503
|
+
let val = pxData[pxPos + x] - ((left + up) >> 1);
|
5504
|
+
|
5505
|
+
rawData[rawPos + x] = val;
|
5332
5506
|
}
|
5333
|
-
return res
|
5334
5507
|
}
|
5335
5508
|
|
5336
|
-
|
5337
|
-
|
5338
|
-
|
5339
|
-
|
5509
|
+
function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
|
5510
|
+
let sum = 0;
|
5511
|
+
for (let x = 0; x < byteWidth; x++) {
|
5512
|
+
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
5513
|
+
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
5514
|
+
let val = pxData[pxPos + x] - ((left + up) >> 1);
|
5340
5515
|
|
5341
|
-
|
5342
|
-
start += len;
|
5343
|
-
if (start < 0) start = 0;
|
5344
|
-
} else if (start > len) {
|
5345
|
-
start = len;
|
5516
|
+
sum += Math.abs(val);
|
5346
5517
|
}
|
5347
5518
|
|
5348
|
-
|
5349
|
-
|
5350
|
-
|
5351
|
-
|
5352
|
-
|
5519
|
+
return sum;
|
5520
|
+
}
|
5521
|
+
|
5522
|
+
function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
5523
|
+
for (let x = 0; x < byteWidth; x++) {
|
5524
|
+
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
5525
|
+
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
5526
|
+
let upleft =
|
5527
|
+
pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
|
5528
|
+
let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
|
5529
|
+
|
5530
|
+
rawData[rawPos + x] = val;
|
5353
5531
|
}
|
5532
|
+
}
|
5354
5533
|
|
5355
|
-
|
5534
|
+
function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
|
5535
|
+
let sum = 0;
|
5536
|
+
for (let x = 0; x < byteWidth; x++) {
|
5537
|
+
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
5538
|
+
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
5539
|
+
let upleft =
|
5540
|
+
pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
|
5541
|
+
let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
|
5356
5542
|
|
5357
|
-
|
5358
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
5359
|
-
newBuf = this.subarray(start, end);
|
5360
|
-
newBuf.__proto__ = Buffer.prototype;
|
5361
|
-
} else {
|
5362
|
-
var sliceLen = end - start;
|
5363
|
-
newBuf = new Buffer(sliceLen, undefined);
|
5364
|
-
for (var i = 0; i < sliceLen; ++i) {
|
5365
|
-
newBuf[i] = this[i + start];
|
5366
|
-
}
|
5543
|
+
sum += Math.abs(val);
|
5367
5544
|
}
|
5368
5545
|
|
5369
|
-
return
|
5546
|
+
return sum;
|
5547
|
+
}
|
5548
|
+
|
5549
|
+
let filters = {
|
5550
|
+
0: filterNone,
|
5551
|
+
1: filterSub,
|
5552
|
+
2: filterUp,
|
5553
|
+
3: filterAvg,
|
5554
|
+
4: filterPaeth,
|
5370
5555
|
};
|
5371
5556
|
|
5372
|
-
|
5373
|
-
|
5374
|
-
|
5375
|
-
|
5376
|
-
|
5377
|
-
|
5378
|
-
}
|
5557
|
+
let filterSums = {
|
5558
|
+
0: filterSumNone,
|
5559
|
+
1: filterSumSub,
|
5560
|
+
2: filterSumUp,
|
5561
|
+
3: filterSumAvg,
|
5562
|
+
4: filterSumPaeth,
|
5563
|
+
};
|
5379
5564
|
|
5380
|
-
|
5381
|
-
|
5382
|
-
|
5383
|
-
|
5565
|
+
var filterPack = function (pxData, width, height, options, bpp) {
|
5566
|
+
let filterTypes;
|
5567
|
+
if (!("filterType" in options) || options.filterType === -1) {
|
5568
|
+
filterTypes = [0, 1, 2, 3, 4];
|
5569
|
+
} else if (typeof options.filterType === "number") {
|
5570
|
+
filterTypes = [options.filterType];
|
5571
|
+
} else {
|
5572
|
+
throw new Error("unrecognised filter types");
|
5573
|
+
}
|
5384
5574
|
|
5385
|
-
|
5386
|
-
|
5387
|
-
var i = 0;
|
5388
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
5389
|
-
val += this[offset + i] * mul;
|
5575
|
+
if (options.bitDepth === 16) {
|
5576
|
+
bpp *= 2;
|
5390
5577
|
}
|
5578
|
+
let byteWidth = width * bpp;
|
5579
|
+
let rawPos = 0;
|
5580
|
+
let pxPos = 0;
|
5581
|
+
let rawData = Buffer.alloc((byteWidth + 1) * height);
|
5391
5582
|
|
5392
|
-
|
5393
|
-
};
|
5583
|
+
let sel = filterTypes[0];
|
5394
5584
|
|
5395
|
-
|
5396
|
-
|
5397
|
-
|
5398
|
-
|
5399
|
-
|
5400
|
-
|
5585
|
+
for (let y = 0; y < height; y++) {
|
5586
|
+
if (filterTypes.length > 1) {
|
5587
|
+
// find best filter for this line (with lowest sum of values)
|
5588
|
+
let min = Infinity;
|
5589
|
+
|
5590
|
+
for (let i = 0; i < filterTypes.length; i++) {
|
5591
|
+
let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
|
5592
|
+
if (sum < min) {
|
5593
|
+
sel = filterTypes[i];
|
5594
|
+
min = sum;
|
5595
|
+
}
|
5596
|
+
}
|
5597
|
+
}
|
5401
5598
|
|
5402
|
-
|
5403
|
-
|
5404
|
-
|
5405
|
-
|
5599
|
+
rawData[rawPos] = sel;
|
5600
|
+
rawPos++;
|
5601
|
+
filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
|
5602
|
+
rawPos += byteWidth;
|
5603
|
+
pxPos += byteWidth;
|
5604
|
+
}
|
5605
|
+
return rawData;
|
5606
|
+
};
|
5607
|
+
|
5608
|
+
let constants$2 = constants$5;
|
5609
|
+
let CrcStream = crc.exports;
|
5610
|
+
let bitPacker = bitpacker;
|
5611
|
+
let filter = filterPack;
|
5612
|
+
let zlib$2 = require$$1__default$1["default"];
|
5613
|
+
|
5614
|
+
let Packer$3 = (packer.exports = function (options) {
|
5615
|
+
this._options = options;
|
5616
|
+
|
5617
|
+
options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
|
5618
|
+
options.deflateLevel =
|
5619
|
+
options.deflateLevel != null ? options.deflateLevel : 9;
|
5620
|
+
options.deflateStrategy =
|
5621
|
+
options.deflateStrategy != null ? options.deflateStrategy : 3;
|
5622
|
+
options.inputHasAlpha =
|
5623
|
+
options.inputHasAlpha != null ? options.inputHasAlpha : true;
|
5624
|
+
options.deflateFactory = options.deflateFactory || zlib$2.createDeflate;
|
5625
|
+
options.bitDepth = options.bitDepth || 8;
|
5626
|
+
// This is outputColorType
|
5627
|
+
options.colorType =
|
5628
|
+
typeof options.colorType === "number"
|
5629
|
+
? options.colorType
|
5630
|
+
: constants$2.COLORTYPE_COLOR_ALPHA;
|
5631
|
+
options.inputColorType =
|
5632
|
+
typeof options.inputColorType === "number"
|
5633
|
+
? options.inputColorType
|
5634
|
+
: constants$2.COLORTYPE_COLOR_ALPHA;
|
5635
|
+
|
5636
|
+
if (
|
5637
|
+
[
|
5638
|
+
constants$2.COLORTYPE_GRAYSCALE,
|
5639
|
+
constants$2.COLORTYPE_COLOR,
|
5640
|
+
constants$2.COLORTYPE_COLOR_ALPHA,
|
5641
|
+
constants$2.COLORTYPE_ALPHA,
|
5642
|
+
].indexOf(options.colorType) === -1
|
5643
|
+
) {
|
5644
|
+
throw new Error(
|
5645
|
+
"option color type:" + options.colorType + " is not supported at present"
|
5646
|
+
);
|
5647
|
+
}
|
5648
|
+
if (
|
5649
|
+
[
|
5650
|
+
constants$2.COLORTYPE_GRAYSCALE,
|
5651
|
+
constants$2.COLORTYPE_COLOR,
|
5652
|
+
constants$2.COLORTYPE_COLOR_ALPHA,
|
5653
|
+
constants$2.COLORTYPE_ALPHA,
|
5654
|
+
].indexOf(options.inputColorType) === -1
|
5655
|
+
) {
|
5656
|
+
throw new Error(
|
5657
|
+
"option input color type:" +
|
5658
|
+
options.inputColorType +
|
5659
|
+
" is not supported at present"
|
5660
|
+
);
|
5406
5661
|
}
|
5662
|
+
if (options.bitDepth !== 8 && options.bitDepth !== 16) {
|
5663
|
+
throw new Error(
|
5664
|
+
"option bit depth:" + options.bitDepth + " is not supported at present"
|
5665
|
+
);
|
5666
|
+
}
|
5667
|
+
});
|
5407
5668
|
|
5408
|
-
|
5669
|
+
Packer$3.prototype.getDeflateOptions = function () {
|
5670
|
+
return {
|
5671
|
+
chunkSize: this._options.deflateChunkSize,
|
5672
|
+
level: this._options.deflateLevel,
|
5673
|
+
strategy: this._options.deflateStrategy,
|
5674
|
+
};
|
5409
5675
|
};
|
5410
5676
|
|
5411
|
-
|
5412
|
-
|
5413
|
-
return this[offset]
|
5677
|
+
Packer$3.prototype.createDeflate = function () {
|
5678
|
+
return this._options.deflateFactory(this.getDeflateOptions());
|
5414
5679
|
};
|
5415
5680
|
|
5416
|
-
|
5417
|
-
|
5418
|
-
|
5681
|
+
Packer$3.prototype.filterData = function (data, width, height) {
|
5682
|
+
// convert to correct format for filtering (e.g. right bpp and bit depth)
|
5683
|
+
let packedData = bitPacker(data, width, height, this._options);
|
5684
|
+
|
5685
|
+
// filter pixel data
|
5686
|
+
let bpp = constants$2.COLORTYPE_TO_BPP_MAP[this._options.colorType];
|
5687
|
+
let filteredData = filter(packedData, width, height, this._options, bpp);
|
5688
|
+
return filteredData;
|
5419
5689
|
};
|
5420
5690
|
|
5421
|
-
|
5422
|
-
|
5423
|
-
|
5691
|
+
Packer$3.prototype._packChunk = function (type, data) {
|
5692
|
+
let len = data ? data.length : 0;
|
5693
|
+
let buf = Buffer.alloc(len + 12);
|
5694
|
+
|
5695
|
+
buf.writeUInt32BE(len, 0);
|
5696
|
+
buf.writeUInt32BE(type, 4);
|
5697
|
+
|
5698
|
+
if (data) {
|
5699
|
+
data.copy(buf, 8);
|
5700
|
+
}
|
5701
|
+
|
5702
|
+
buf.writeInt32BE(
|
5703
|
+
CrcStream.crc32(buf.slice(4, buf.length - 4)),
|
5704
|
+
buf.length - 4
|
5705
|
+
);
|
5706
|
+
return buf;
|
5424
5707
|
};
|
5425
5708
|
|
5426
|
-
|
5427
|
-
|
5709
|
+
Packer$3.prototype.packGAMA = function (gamma) {
|
5710
|
+
let buf = Buffer.alloc(4);
|
5711
|
+
buf.writeUInt32BE(Math.floor(gamma * constants$2.GAMMA_DIVISION), 0);
|
5712
|
+
return this._packChunk(constants$2.TYPE_gAMA, buf);
|
5713
|
+
};
|
5428
5714
|
|
5429
|
-
|
5430
|
-
|
5431
|
-
|
5432
|
-
|
5715
|
+
Packer$3.prototype.packIHDR = function (width, height) {
|
5716
|
+
let buf = Buffer.alloc(13);
|
5717
|
+
buf.writeUInt32BE(width, 0);
|
5718
|
+
buf.writeUInt32BE(height, 4);
|
5719
|
+
buf[8] = this._options.bitDepth; // Bit depth
|
5720
|
+
buf[9] = this._options.colorType; // colorType
|
5721
|
+
buf[10] = 0; // compression
|
5722
|
+
buf[11] = 0; // filter
|
5723
|
+
buf[12] = 0; // interlace
|
5724
|
+
|
5725
|
+
return this._packChunk(constants$2.TYPE_IHDR, buf);
|
5433
5726
|
};
|
5434
5727
|
|
5435
|
-
|
5436
|
-
|
5728
|
+
Packer$3.prototype.packIDAT = function (data) {
|
5729
|
+
return this._packChunk(constants$2.TYPE_IDAT, data);
|
5730
|
+
};
|
5437
5731
|
|
5438
|
-
|
5439
|
-
|
5440
|
-
(this[offset + 2] << 8) |
|
5441
|
-
this[offset + 3])
|
5732
|
+
Packer$3.prototype.packIEND = function () {
|
5733
|
+
return this._packChunk(constants$2.TYPE_IEND, null);
|
5442
5734
|
};
|
5443
5735
|
|
5444
|
-
|
5445
|
-
|
5446
|
-
|
5447
|
-
|
5736
|
+
let util$1 = require$$0__default["default"];
|
5737
|
+
let Stream$1 = require$$1__default["default"];
|
5738
|
+
let constants$1 = constants$5;
|
5739
|
+
let Packer$2 = packer.exports;
|
5448
5740
|
|
5449
|
-
|
5450
|
-
|
5451
|
-
var i = 0;
|
5452
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
5453
|
-
val += this[offset + i] * mul;
|
5454
|
-
}
|
5455
|
-
mul *= 0x80;
|
5741
|
+
let PackerAsync = (packerAsync.exports = function (opt) {
|
5742
|
+
Stream$1.call(this);
|
5456
5743
|
|
5457
|
-
|
5744
|
+
let options = opt || {};
|
5458
5745
|
|
5459
|
-
|
5460
|
-
|
5746
|
+
this._packer = new Packer$2(options);
|
5747
|
+
this._deflate = this._packer.createDeflate();
|
5748
|
+
|
5749
|
+
this.readable = true;
|
5750
|
+
});
|
5751
|
+
util$1.inherits(PackerAsync, Stream$1);
|
5461
5752
|
|
5462
|
-
|
5463
|
-
|
5464
|
-
|
5465
|
-
|
5753
|
+
PackerAsync.prototype.pack = function (data, width, height, gamma) {
|
5754
|
+
// Signature
|
5755
|
+
this.emit("data", Buffer.from(constants$1.PNG_SIGNATURE));
|
5756
|
+
this.emit("data", this._packer.packIHDR(width, height));
|
5466
5757
|
|
5467
|
-
|
5468
|
-
|
5469
|
-
var val = this[offset + --i];
|
5470
|
-
while (i > 0 && (mul *= 0x100)) {
|
5471
|
-
val += this[offset + --i] * mul;
|
5758
|
+
if (gamma) {
|
5759
|
+
this.emit("data", this._packer.packGAMA(gamma));
|
5472
5760
|
}
|
5473
|
-
mul *= 0x80;
|
5474
5761
|
|
5475
|
-
|
5762
|
+
let filteredData = this._packer.filterData(data, width, height);
|
5476
5763
|
|
5477
|
-
|
5478
|
-
|
5764
|
+
// compress it
|
5765
|
+
this._deflate.on("error", this.emit.bind(this, "error"));
|
5479
5766
|
|
5480
|
-
|
5481
|
-
|
5482
|
-
|
5483
|
-
|
5484
|
-
}
|
5767
|
+
this._deflate.on(
|
5768
|
+
"data",
|
5769
|
+
function (compressedData) {
|
5770
|
+
this.emit("data", this._packer.packIDAT(compressedData));
|
5771
|
+
}.bind(this)
|
5772
|
+
);
|
5485
5773
|
|
5486
|
-
|
5487
|
-
|
5488
|
-
|
5489
|
-
|
5490
|
-
|
5774
|
+
this._deflate.on(
|
5775
|
+
"end",
|
5776
|
+
function () {
|
5777
|
+
this.emit("data", this._packer.packIEND());
|
5778
|
+
this.emit("end");
|
5779
|
+
}.bind(this)
|
5780
|
+
);
|
5491
5781
|
|
5492
|
-
|
5493
|
-
if (!noAssert) checkOffset(offset, 2, this.length);
|
5494
|
-
var val = this[offset + 1] | (this[offset] << 8);
|
5495
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
5782
|
+
this._deflate.end(filteredData);
|
5496
5783
|
};
|
5497
5784
|
|
5498
|
-
|
5499
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
5785
|
+
var pngSync = {};
|
5500
5786
|
|
5501
|
-
|
5502
|
-
(this[offset + 1] << 8) |
|
5503
|
-
(this[offset + 2] << 16) |
|
5504
|
-
(this[offset + 3] << 24)
|
5505
|
-
};
|
5787
|
+
var syncInflate = {exports: {}};
|
5506
5788
|
|
5507
|
-
|
5508
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
5789
|
+
(function (module, exports) {
|
5509
5790
|
|
5510
|
-
|
5511
|
-
|
5512
|
-
|
5513
|
-
(this[offset + 3])
|
5514
|
-
};
|
5791
|
+
let assert = require$$0__default$1["default"].ok;
|
5792
|
+
let zlib = require$$1__default$1["default"];
|
5793
|
+
let util = require$$0__default["default"];
|
5515
5794
|
|
5516
|
-
|
5517
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
5518
|
-
return read(this, offset, true, 23, 4)
|
5519
|
-
};
|
5795
|
+
let kMaxLength = require$$3__default["default"].kMaxLength;
|
5520
5796
|
|
5521
|
-
|
5522
|
-
|
5523
|
-
|
5524
|
-
}
|
5797
|
+
function Inflate(opts) {
|
5798
|
+
if (!(this instanceof Inflate)) {
|
5799
|
+
return new Inflate(opts);
|
5800
|
+
}
|
5525
5801
|
|
5526
|
-
|
5527
|
-
|
5528
|
-
|
5529
|
-
};
|
5802
|
+
if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
|
5803
|
+
opts.chunkSize = zlib.Z_MIN_CHUNK;
|
5804
|
+
}
|
5530
5805
|
|
5531
|
-
|
5532
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
5533
|
-
return read(this, offset, false, 52, 8)
|
5534
|
-
};
|
5806
|
+
zlib.Inflate.call(this, opts);
|
5535
5807
|
|
5536
|
-
|
5537
|
-
|
5538
|
-
|
5539
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
5540
|
-
}
|
5808
|
+
// Node 8 --> 9 compatibility check
|
5809
|
+
this._offset = this._offset === undefined ? this._outOffset : this._offset;
|
5810
|
+
this._buffer = this._buffer || this._outBuffer;
|
5541
5811
|
|
5542
|
-
|
5543
|
-
|
5544
|
-
|
5545
|
-
|
5546
|
-
if (!noAssert) {
|
5547
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
5548
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
5549
|
-
}
|
5812
|
+
if (opts && opts.maxLength != null) {
|
5813
|
+
this._maxLength = opts.maxLength;
|
5814
|
+
}
|
5815
|
+
}
|
5550
5816
|
|
5551
|
-
|
5552
|
-
|
5553
|
-
|
5554
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
5555
|
-
this[offset + i] = (value / mul) & 0xFF;
|
5556
|
-
}
|
5817
|
+
function createInflate(opts) {
|
5818
|
+
return new Inflate(opts);
|
5819
|
+
}
|
5557
5820
|
|
5558
|
-
|
5559
|
-
|
5821
|
+
function _close(engine, callback) {
|
5822
|
+
if (callback) {
|
5823
|
+
process.nextTick(callback);
|
5824
|
+
}
|
5560
5825
|
|
5561
|
-
|
5562
|
-
|
5563
|
-
|
5564
|
-
|
5565
|
-
if (!noAssert) {
|
5566
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
5567
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
5568
|
-
}
|
5826
|
+
// Caller may invoke .close after a zlib error (which will null _handle).
|
5827
|
+
if (!engine._handle) {
|
5828
|
+
return;
|
5829
|
+
}
|
5569
5830
|
|
5570
|
-
|
5571
|
-
|
5572
|
-
|
5573
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
5574
|
-
this[offset + i] = (value / mul) & 0xFF;
|
5575
|
-
}
|
5831
|
+
engine._handle.close();
|
5832
|
+
engine._handle = null;
|
5833
|
+
}
|
5576
5834
|
|
5577
|
-
|
5578
|
-
|
5835
|
+
Inflate.prototype._processChunk = function (chunk, flushFlag, asyncCb) {
|
5836
|
+
if (typeof asyncCb === "function") {
|
5837
|
+
return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
|
5838
|
+
}
|
5579
5839
|
|
5580
|
-
|
5581
|
-
value = +value;
|
5582
|
-
offset = offset | 0;
|
5583
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
5584
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
|
5585
|
-
this[offset] = (value & 0xff);
|
5586
|
-
return offset + 1
|
5587
|
-
};
|
5840
|
+
let self = this;
|
5588
5841
|
|
5589
|
-
|
5590
|
-
|
5591
|
-
|
5592
|
-
|
5593
|
-
(littleEndian ? i : 1 - i) * 8;
|
5594
|
-
}
|
5595
|
-
}
|
5842
|
+
let availInBefore = chunk && chunk.length;
|
5843
|
+
let availOutBefore = this._chunkSize - this._offset;
|
5844
|
+
let leftToInflate = this._maxLength;
|
5845
|
+
let inOff = 0;
|
5596
5846
|
|
5597
|
-
|
5598
|
-
|
5599
|
-
offset = offset | 0;
|
5600
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
5601
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
5602
|
-
this[offset] = (value & 0xff);
|
5603
|
-
this[offset + 1] = (value >>> 8);
|
5604
|
-
} else {
|
5605
|
-
objectWriteUInt16(this, value, offset, true);
|
5606
|
-
}
|
5607
|
-
return offset + 2
|
5608
|
-
};
|
5847
|
+
let buffers = [];
|
5848
|
+
let nread = 0;
|
5609
5849
|
|
5610
|
-
|
5611
|
-
|
5612
|
-
|
5613
|
-
|
5614
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
5615
|
-
this[offset] = (value >>> 8);
|
5616
|
-
this[offset + 1] = (value & 0xff);
|
5617
|
-
} else {
|
5618
|
-
objectWriteUInt16(this, value, offset, false);
|
5619
|
-
}
|
5620
|
-
return offset + 2
|
5621
|
-
};
|
5850
|
+
let error;
|
5851
|
+
this.on("error", function (err) {
|
5852
|
+
error = err;
|
5853
|
+
});
|
5622
5854
|
|
5623
|
-
function
|
5624
|
-
|
5625
|
-
|
5626
|
-
|
5627
|
-
}
|
5628
|
-
}
|
5855
|
+
function handleChunk(availInAfter, availOutAfter) {
|
5856
|
+
if (self._hadError) {
|
5857
|
+
return;
|
5858
|
+
}
|
5629
5859
|
|
5630
|
-
|
5631
|
-
|
5632
|
-
offset = offset | 0;
|
5633
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
5634
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
5635
|
-
this[offset + 3] = (value >>> 24);
|
5636
|
-
this[offset + 2] = (value >>> 16);
|
5637
|
-
this[offset + 1] = (value >>> 8);
|
5638
|
-
this[offset] = (value & 0xff);
|
5639
|
-
} else {
|
5640
|
-
objectWriteUInt32(this, value, offset, true);
|
5641
|
-
}
|
5642
|
-
return offset + 4
|
5643
|
-
};
|
5860
|
+
let have = availOutBefore - availOutAfter;
|
5861
|
+
assert(have >= 0, "have should not go down");
|
5644
5862
|
|
5645
|
-
|
5646
|
-
|
5647
|
-
|
5648
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
5649
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
5650
|
-
this[offset] = (value >>> 24);
|
5651
|
-
this[offset + 1] = (value >>> 16);
|
5652
|
-
this[offset + 2] = (value >>> 8);
|
5653
|
-
this[offset + 3] = (value & 0xff);
|
5654
|
-
} else {
|
5655
|
-
objectWriteUInt32(this, value, offset, false);
|
5656
|
-
}
|
5657
|
-
return offset + 4
|
5658
|
-
};
|
5863
|
+
if (have > 0) {
|
5864
|
+
let out = self._buffer.slice(self._offset, self._offset + have);
|
5865
|
+
self._offset += have;
|
5659
5866
|
|
5660
|
-
|
5661
|
-
|
5662
|
-
|
5663
|
-
if (!noAssert) {
|
5664
|
-
var limit = Math.pow(2, 8 * byteLength - 1);
|
5867
|
+
if (out.length > leftToInflate) {
|
5868
|
+
out = out.slice(0, leftToInflate);
|
5869
|
+
}
|
5665
5870
|
|
5666
|
-
|
5667
|
-
|
5871
|
+
buffers.push(out);
|
5872
|
+
nread += out.length;
|
5873
|
+
leftToInflate -= out.length;
|
5668
5874
|
|
5669
|
-
|
5670
|
-
|
5671
|
-
|
5672
|
-
|
5673
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
5674
|
-
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
5675
|
-
sub = 1;
|
5676
|
-
}
|
5677
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
5678
|
-
}
|
5875
|
+
if (leftToInflate === 0) {
|
5876
|
+
return false;
|
5877
|
+
}
|
5878
|
+
}
|
5679
5879
|
|
5680
|
-
|
5681
|
-
|
5880
|
+
if (availOutAfter === 0 || self._offset >= self._chunkSize) {
|
5881
|
+
availOutBefore = self._chunkSize;
|
5882
|
+
self._offset = 0;
|
5883
|
+
self._buffer = Buffer.allocUnsafe(self._chunkSize);
|
5884
|
+
}
|
5682
5885
|
|
5683
|
-
|
5684
|
-
|
5685
|
-
|
5686
|
-
if (!noAssert) {
|
5687
|
-
var limit = Math.pow(2, 8 * byteLength - 1);
|
5886
|
+
if (availOutAfter === 0) {
|
5887
|
+
inOff += availInBefore - availInAfter;
|
5888
|
+
availInBefore = availInAfter;
|
5688
5889
|
|
5689
|
-
|
5690
|
-
|
5890
|
+
return true;
|
5891
|
+
}
|
5691
5892
|
|
5692
|
-
|
5693
|
-
|
5694
|
-
var sub = 0;
|
5695
|
-
this[offset + i] = value & 0xFF;
|
5696
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
5697
|
-
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
5698
|
-
sub = 1;
|
5699
|
-
}
|
5700
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
5701
|
-
}
|
5893
|
+
return false;
|
5894
|
+
}
|
5702
5895
|
|
5703
|
-
|
5704
|
-
|
5896
|
+
assert(this._handle, "zlib binding closed");
|
5897
|
+
let res;
|
5898
|
+
do {
|
5899
|
+
res = this._handle.writeSync(
|
5900
|
+
flushFlag,
|
5901
|
+
chunk, // in
|
5902
|
+
inOff, // in_off
|
5903
|
+
availInBefore, // in_len
|
5904
|
+
this._buffer, // out
|
5905
|
+
this._offset, //out_off
|
5906
|
+
availOutBefore
|
5907
|
+
); // out_len
|
5908
|
+
// Node 8 --> 9 compatibility check
|
5909
|
+
res = res || this._writeState;
|
5910
|
+
} while (!this._hadError && handleChunk(res[0], res[1]));
|
5911
|
+
|
5912
|
+
if (this._hadError) {
|
5913
|
+
throw error;
|
5914
|
+
}
|
5705
5915
|
|
5706
|
-
|
5707
|
-
|
5708
|
-
|
5709
|
-
|
5710
|
-
|
5711
|
-
|
5712
|
-
|
5713
|
-
|
5714
|
-
};
|
5916
|
+
if (nread >= kMaxLength) {
|
5917
|
+
_close(this);
|
5918
|
+
throw new RangeError(
|
5919
|
+
"Cannot create final Buffer. It would be larger than 0x" +
|
5920
|
+
kMaxLength.toString(16) +
|
5921
|
+
" bytes"
|
5922
|
+
);
|
5923
|
+
}
|
5715
5924
|
|
5716
|
-
|
5717
|
-
|
5718
|
-
offset = offset | 0;
|
5719
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
5720
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
5721
|
-
this[offset] = (value & 0xff);
|
5722
|
-
this[offset + 1] = (value >>> 8);
|
5723
|
-
} else {
|
5724
|
-
objectWriteUInt16(this, value, offset, true);
|
5725
|
-
}
|
5726
|
-
return offset + 2
|
5727
|
-
};
|
5925
|
+
let buf = Buffer.concat(buffers, nread);
|
5926
|
+
_close(this);
|
5728
5927
|
|
5729
|
-
|
5730
|
-
|
5731
|
-
offset = offset | 0;
|
5732
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
5733
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
5734
|
-
this[offset] = (value >>> 8);
|
5735
|
-
this[offset + 1] = (value & 0xff);
|
5736
|
-
} else {
|
5737
|
-
objectWriteUInt16(this, value, offset, false);
|
5738
|
-
}
|
5739
|
-
return offset + 2
|
5740
|
-
};
|
5928
|
+
return buf;
|
5929
|
+
};
|
5741
5930
|
|
5742
|
-
|
5743
|
-
value = +value;
|
5744
|
-
offset = offset | 0;
|
5745
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
5746
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
5747
|
-
this[offset] = (value & 0xff);
|
5748
|
-
this[offset + 1] = (value >>> 8);
|
5749
|
-
this[offset + 2] = (value >>> 16);
|
5750
|
-
this[offset + 3] = (value >>> 24);
|
5751
|
-
} else {
|
5752
|
-
objectWriteUInt32(this, value, offset, true);
|
5753
|
-
}
|
5754
|
-
return offset + 4
|
5755
|
-
};
|
5931
|
+
util.inherits(Inflate, zlib.Inflate);
|
5756
5932
|
|
5757
|
-
|
5758
|
-
|
5759
|
-
|
5760
|
-
|
5761
|
-
|
5762
|
-
|
5763
|
-
|
5764
|
-
this[offset + 1] = (value >>> 16);
|
5765
|
-
this[offset + 2] = (value >>> 8);
|
5766
|
-
this[offset + 3] = (value & 0xff);
|
5767
|
-
} else {
|
5768
|
-
objectWriteUInt32(this, value, offset, false);
|
5769
|
-
}
|
5770
|
-
return offset + 4
|
5771
|
-
};
|
5933
|
+
function zlibBufferSync(engine, buffer) {
|
5934
|
+
if (typeof buffer === "string") {
|
5935
|
+
buffer = Buffer.from(buffer);
|
5936
|
+
}
|
5937
|
+
if (!(buffer instanceof Buffer)) {
|
5938
|
+
throw new TypeError("Not a string or buffer");
|
5939
|
+
}
|
5772
5940
|
|
5773
|
-
|
5774
|
-
|
5775
|
-
|
5776
|
-
}
|
5941
|
+
let flushFlag = engine._finishFlushFlag;
|
5942
|
+
if (flushFlag == null) {
|
5943
|
+
flushFlag = zlib.Z_FINISH;
|
5944
|
+
}
|
5777
5945
|
|
5778
|
-
|
5779
|
-
|
5780
|
-
checkIEEE754(buf, value, offset, 4);
|
5781
|
-
}
|
5782
|
-
write(buf, value, offset, littleEndian, 23, 4);
|
5783
|
-
return offset + 4
|
5784
|
-
}
|
5946
|
+
return engine._processChunk(buffer, flushFlag);
|
5947
|
+
}
|
5785
5948
|
|
5786
|
-
|
5787
|
-
|
5788
|
-
}
|
5949
|
+
function inflateSync(buffer, opts) {
|
5950
|
+
return zlibBufferSync(new Inflate(opts), buffer);
|
5951
|
+
}
|
5789
5952
|
|
5790
|
-
|
5791
|
-
|
5953
|
+
module.exports = exports = inflateSync;
|
5954
|
+
exports.Inflate = Inflate;
|
5955
|
+
exports.createInflate = createInflate;
|
5956
|
+
exports.inflateSync = inflateSync;
|
5957
|
+
} (syncInflate, syncInflate.exports));
|
5958
|
+
|
5959
|
+
var syncReader = {exports: {}};
|
5960
|
+
|
5961
|
+
let SyncReader$2 = (syncReader.exports = function (buffer) {
|
5962
|
+
this._buffer = buffer;
|
5963
|
+
this._reads = [];
|
5964
|
+
});
|
5965
|
+
|
5966
|
+
SyncReader$2.prototype.read = function (length, callback) {
|
5967
|
+
this._reads.push({
|
5968
|
+
length: Math.abs(length), // if length < 0 then at most this length
|
5969
|
+
allowLess: length < 0,
|
5970
|
+
func: callback,
|
5971
|
+
});
|
5792
5972
|
};
|
5793
5973
|
|
5794
|
-
function
|
5795
|
-
|
5796
|
-
|
5974
|
+
SyncReader$2.prototype.process = function () {
|
5975
|
+
// as long as there is any data and read requests
|
5976
|
+
while (this._reads.length > 0 && this._buffer.length) {
|
5977
|
+
let read = this._reads[0];
|
5978
|
+
|
5979
|
+
if (
|
5980
|
+
this._buffer.length &&
|
5981
|
+
(this._buffer.length >= read.length || read.allowLess)
|
5982
|
+
) {
|
5983
|
+
// ok there is any data so that we can satisfy this request
|
5984
|
+
this._reads.shift(); // == read
|
5985
|
+
|
5986
|
+
let buf = this._buffer;
|
5987
|
+
|
5988
|
+
this._buffer = buf.slice(read.length);
|
5989
|
+
|
5990
|
+
read.func.call(this, buf.slice(0, read.length));
|
5991
|
+
} else {
|
5992
|
+
break;
|
5993
|
+
}
|
5994
|
+
}
|
5995
|
+
|
5996
|
+
if (this._reads.length > 0) {
|
5997
|
+
return new Error("There are some read requests waitng on finished stream");
|
5797
5998
|
}
|
5798
|
-
write(buf, value, offset, littleEndian, 52, 8);
|
5799
|
-
return offset + 8
|
5800
|
-
}
|
5801
5999
|
|
5802
|
-
|
5803
|
-
|
6000
|
+
if (this._buffer.length > 0) {
|
6001
|
+
return new Error("unrecognised content at end of stream");
|
6002
|
+
}
|
5804
6003
|
};
|
5805
6004
|
|
5806
|
-
|
5807
|
-
|
6005
|
+
var filterParseSync = {};
|
6006
|
+
|
6007
|
+
let SyncReader$1 = syncReader.exports;
|
6008
|
+
let Filter = filterParse.exports;
|
6009
|
+
|
6010
|
+
filterParseSync.process = function (inBuffer, bitmapInfo) {
|
6011
|
+
let outBuffers = [];
|
6012
|
+
let reader = new SyncReader$1(inBuffer);
|
6013
|
+
let filter = new Filter(bitmapInfo, {
|
6014
|
+
read: reader.read.bind(reader),
|
6015
|
+
write: function (bufferPart) {
|
6016
|
+
outBuffers.push(bufferPart);
|
6017
|
+
},
|
6018
|
+
complete: function () {},
|
6019
|
+
});
|
6020
|
+
|
6021
|
+
filter.start();
|
6022
|
+
reader.process();
|
6023
|
+
|
6024
|
+
return Buffer.concat(outBuffers);
|
5808
6025
|
};
|
5809
6026
|
|
5810
|
-
|
5811
|
-
|
5812
|
-
|
5813
|
-
|
5814
|
-
|
5815
|
-
|
5816
|
-
|
6027
|
+
let hasSyncZlib$1 = true;
|
6028
|
+
let zlib$1 = require$$1__default$1["default"];
|
6029
|
+
let inflateSync = syncInflate.exports;
|
6030
|
+
if (!zlib$1.deflateSync) {
|
6031
|
+
hasSyncZlib$1 = false;
|
6032
|
+
}
|
6033
|
+
let SyncReader = syncReader.exports;
|
6034
|
+
let FilterSync = filterParseSync;
|
6035
|
+
let Parser$1 = parser.exports;
|
6036
|
+
let bitmapper = bitmapper$2;
|
6037
|
+
let formatNormaliser = formatNormaliser$2;
|
5817
6038
|
|
5818
|
-
|
5819
|
-
if (
|
5820
|
-
|
6039
|
+
var parserSync = function (buffer, options) {
|
6040
|
+
if (!hasSyncZlib$1) {
|
6041
|
+
throw new Error(
|
6042
|
+
"To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
|
6043
|
+
);
|
6044
|
+
}
|
5821
6045
|
|
5822
|
-
|
5823
|
-
|
5824
|
-
|
6046
|
+
let err;
|
6047
|
+
function handleError(_err_) {
|
6048
|
+
err = _err_;
|
5825
6049
|
}
|
5826
|
-
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
|
5827
|
-
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
5828
6050
|
|
5829
|
-
|
5830
|
-
|
5831
|
-
|
5832
|
-
end = target.length - targetStart + start;
|
6051
|
+
let metaData;
|
6052
|
+
function handleMetaData(_metaData_) {
|
6053
|
+
metaData = _metaData_;
|
5833
6054
|
}
|
5834
6055
|
|
5835
|
-
|
5836
|
-
|
6056
|
+
function handleTransColor(transColor) {
|
6057
|
+
metaData.transColor = transColor;
|
6058
|
+
}
|
5837
6059
|
|
5838
|
-
|
5839
|
-
|
5840
|
-
for (i = len - 1; i >= 0; --i) {
|
5841
|
-
target[i + targetStart] = this[i + start];
|
5842
|
-
}
|
5843
|
-
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
|
5844
|
-
// ascending copy from start
|
5845
|
-
for (i = 0; i < len; ++i) {
|
5846
|
-
target[i + targetStart] = this[i + start];
|
5847
|
-
}
|
5848
|
-
} else {
|
5849
|
-
Uint8Array.prototype.set.call(
|
5850
|
-
target,
|
5851
|
-
this.subarray(start, start + len),
|
5852
|
-
targetStart
|
5853
|
-
);
|
6060
|
+
function handlePalette(palette) {
|
6061
|
+
metaData.palette = palette;
|
5854
6062
|
}
|
5855
6063
|
|
5856
|
-
|
5857
|
-
|
5858
|
-
|
5859
|
-
// Usage:
|
5860
|
-
// buffer.fill(number[, offset[, end]])
|
5861
|
-
// buffer.fill(buffer[, offset[, end]])
|
5862
|
-
// buffer.fill(string[, offset[, end]][, encoding])
|
5863
|
-
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
5864
|
-
// Handle string cases:
|
5865
|
-
if (typeof val === 'string') {
|
5866
|
-
if (typeof start === 'string') {
|
5867
|
-
encoding = start;
|
5868
|
-
start = 0;
|
5869
|
-
end = this.length;
|
5870
|
-
} else if (typeof end === 'string') {
|
5871
|
-
encoding = end;
|
5872
|
-
end = this.length;
|
5873
|
-
}
|
5874
|
-
if (val.length === 1) {
|
5875
|
-
var code = val.charCodeAt(0);
|
5876
|
-
if (code < 256) {
|
5877
|
-
val = code;
|
5878
|
-
}
|
5879
|
-
}
|
5880
|
-
if (encoding !== undefined && typeof encoding !== 'string') {
|
5881
|
-
throw new TypeError('encoding must be a string')
|
5882
|
-
}
|
5883
|
-
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
5884
|
-
throw new TypeError('Unknown encoding: ' + encoding)
|
5885
|
-
}
|
5886
|
-
} else if (typeof val === 'number') {
|
5887
|
-
val = val & 255;
|
6064
|
+
function handleSimpleTransparency() {
|
6065
|
+
metaData.alpha = true;
|
5888
6066
|
}
|
5889
6067
|
|
5890
|
-
|
5891
|
-
|
5892
|
-
|
6068
|
+
let gamma;
|
6069
|
+
function handleGamma(_gamma_) {
|
6070
|
+
gamma = _gamma_;
|
5893
6071
|
}
|
5894
6072
|
|
5895
|
-
|
5896
|
-
|
6073
|
+
let inflateDataList = [];
|
6074
|
+
function handleInflateData(inflatedData) {
|
6075
|
+
inflateDataList.push(inflatedData);
|
5897
6076
|
}
|
5898
6077
|
|
5899
|
-
|
5900
|
-
end = end === undefined ? this.length : end >>> 0;
|
6078
|
+
let reader = new SyncReader(buffer);
|
5901
6079
|
|
5902
|
-
|
6080
|
+
let parser = new Parser$1(options, {
|
6081
|
+
read: reader.read.bind(reader),
|
6082
|
+
error: handleError,
|
6083
|
+
metadata: handleMetaData,
|
6084
|
+
gamma: handleGamma,
|
6085
|
+
palette: handlePalette,
|
6086
|
+
transColor: handleTransColor,
|
6087
|
+
inflateData: handleInflateData,
|
6088
|
+
simpleTransparency: handleSimpleTransparency,
|
6089
|
+
});
|
5903
6090
|
|
5904
|
-
|
5905
|
-
|
5906
|
-
for (i = start; i < end; ++i) {
|
5907
|
-
this[i] = val;
|
5908
|
-
}
|
5909
|
-
} else {
|
5910
|
-
var bytes = internalIsBuffer(val)
|
5911
|
-
? val
|
5912
|
-
: utf8ToBytes(new Buffer(val, encoding).toString());
|
5913
|
-
var len = bytes.length;
|
5914
|
-
for (i = 0; i < end - start; ++i) {
|
5915
|
-
this[i + start] = bytes[i % len];
|
5916
|
-
}
|
5917
|
-
}
|
6091
|
+
parser.start();
|
6092
|
+
reader.process();
|
5918
6093
|
|
5919
|
-
|
5920
|
-
|
6094
|
+
if (err) {
|
6095
|
+
throw err;
|
6096
|
+
}
|
5921
6097
|
|
5922
|
-
//
|
5923
|
-
|
6098
|
+
//join together the inflate datas
|
6099
|
+
let inflateData = Buffer.concat(inflateDataList);
|
6100
|
+
inflateDataList.length = 0;
|
5924
6101
|
|
5925
|
-
|
6102
|
+
let inflatedData;
|
6103
|
+
if (metaData.interlace) {
|
6104
|
+
inflatedData = zlib$1.inflateSync(inflateData);
|
6105
|
+
} else {
|
6106
|
+
let rowSize =
|
6107
|
+
((metaData.width * metaData.bpp * metaData.depth + 7) >> 3) + 1;
|
6108
|
+
let imageSize = rowSize * metaData.height;
|
6109
|
+
inflatedData = inflateSync(inflateData, {
|
6110
|
+
chunkSize: imageSize,
|
6111
|
+
maxLength: imageSize,
|
6112
|
+
});
|
6113
|
+
}
|
6114
|
+
inflateData = null;
|
5926
6115
|
|
5927
|
-
|
5928
|
-
|
5929
|
-
str = stringtrim(str).replace(INVALID_BASE64_RE, '');
|
5930
|
-
// Node converts strings with length < 2 to ''
|
5931
|
-
if (str.length < 2) return ''
|
5932
|
-
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
5933
|
-
while (str.length % 4 !== 0) {
|
5934
|
-
str = str + '=';
|
6116
|
+
if (!inflatedData || !inflatedData.length) {
|
6117
|
+
throw new Error("bad png - invalid inflate data response");
|
5935
6118
|
}
|
5936
|
-
return str
|
5937
|
-
}
|
5938
6119
|
|
5939
|
-
|
5940
|
-
|
5941
|
-
return str.replace(/^\s+|\s+$/g, '')
|
5942
|
-
}
|
6120
|
+
let unfilteredData = FilterSync.process(inflatedData, metaData);
|
6121
|
+
inflateData = null;
|
5943
6122
|
|
5944
|
-
|
5945
|
-
|
5946
|
-
return n.toString(16)
|
5947
|
-
}
|
6123
|
+
let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
|
6124
|
+
unfilteredData = null;
|
5948
6125
|
|
5949
|
-
|
5950
|
-
units = units || Infinity;
|
5951
|
-
var codePoint;
|
5952
|
-
var length = string.length;
|
5953
|
-
var leadSurrogate = null;
|
5954
|
-
var bytes = [];
|
6126
|
+
let normalisedBitmapData = formatNormaliser(bitmapData, metaData);
|
5955
6127
|
|
5956
|
-
|
5957
|
-
|
6128
|
+
metaData.data = normalisedBitmapData;
|
6129
|
+
metaData.gamma = gamma || 0;
|
5958
6130
|
|
5959
|
-
|
5960
|
-
|
5961
|
-
// last char was a lead
|
5962
|
-
if (!leadSurrogate) {
|
5963
|
-
// no lead yet
|
5964
|
-
if (codePoint > 0xDBFF) {
|
5965
|
-
// unexpected trail
|
5966
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
5967
|
-
continue
|
5968
|
-
} else if (i + 1 === length) {
|
5969
|
-
// unpaired lead
|
5970
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
5971
|
-
continue
|
5972
|
-
}
|
6131
|
+
return metaData;
|
6132
|
+
};
|
5973
6133
|
|
5974
|
-
|
5975
|
-
|
6134
|
+
let hasSyncZlib = true;
|
6135
|
+
let zlib = require$$1__default$1["default"];
|
6136
|
+
if (!zlib.deflateSync) {
|
6137
|
+
hasSyncZlib = false;
|
6138
|
+
}
|
6139
|
+
let constants = constants$5;
|
6140
|
+
let Packer$1 = packer.exports;
|
5976
6141
|
|
5977
|
-
|
5978
|
-
|
6142
|
+
var packerSync = function (metaData, opt) {
|
6143
|
+
if (!hasSyncZlib) {
|
6144
|
+
throw new Error(
|
6145
|
+
"To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
|
6146
|
+
);
|
6147
|
+
}
|
5979
6148
|
|
5980
|
-
|
5981
|
-
if (codePoint < 0xDC00) {
|
5982
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
5983
|
-
leadSurrogate = codePoint;
|
5984
|
-
continue
|
5985
|
-
}
|
6149
|
+
let options = opt || {};
|
5986
6150
|
|
5987
|
-
|
5988
|
-
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
5989
|
-
} else if (leadSurrogate) {
|
5990
|
-
// valid bmp char, but last char was a lead
|
5991
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
5992
|
-
}
|
6151
|
+
let packer = new Packer$1(options);
|
5993
6152
|
|
5994
|
-
|
6153
|
+
let chunks = [];
|
5995
6154
|
|
5996
|
-
|
5997
|
-
|
5998
|
-
if ((units -= 1) < 0) break
|
5999
|
-
bytes.push(codePoint);
|
6000
|
-
} else if (codePoint < 0x800) {
|
6001
|
-
if ((units -= 2) < 0) break
|
6002
|
-
bytes.push(
|
6003
|
-
codePoint >> 0x6 | 0xC0,
|
6004
|
-
codePoint & 0x3F | 0x80
|
6005
|
-
);
|
6006
|
-
} else if (codePoint < 0x10000) {
|
6007
|
-
if ((units -= 3) < 0) break
|
6008
|
-
bytes.push(
|
6009
|
-
codePoint >> 0xC | 0xE0,
|
6010
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
6011
|
-
codePoint & 0x3F | 0x80
|
6012
|
-
);
|
6013
|
-
} else if (codePoint < 0x110000) {
|
6014
|
-
if ((units -= 4) < 0) break
|
6015
|
-
bytes.push(
|
6016
|
-
codePoint >> 0x12 | 0xF0,
|
6017
|
-
codePoint >> 0xC & 0x3F | 0x80,
|
6018
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
6019
|
-
codePoint & 0x3F | 0x80
|
6020
|
-
);
|
6021
|
-
} else {
|
6022
|
-
throw new Error('Invalid code point')
|
6023
|
-
}
|
6024
|
-
}
|
6155
|
+
// Signature
|
6156
|
+
chunks.push(Buffer.from(constants.PNG_SIGNATURE));
|
6025
6157
|
|
6026
|
-
|
6027
|
-
|
6158
|
+
// Header
|
6159
|
+
chunks.push(packer.packIHDR(metaData.width, metaData.height));
|
6028
6160
|
|
6029
|
-
|
6030
|
-
|
6031
|
-
for (var i = 0; i < str.length; ++i) {
|
6032
|
-
// Node's code seems to be doing this and not & 0x7F..
|
6033
|
-
byteArray.push(str.charCodeAt(i) & 0xFF);
|
6161
|
+
if (metaData.gamma) {
|
6162
|
+
chunks.push(packer.packGAMA(metaData.gamma));
|
6034
6163
|
}
|
6035
|
-
return byteArray
|
6036
|
-
}
|
6037
6164
|
|
6038
|
-
|
6039
|
-
|
6040
|
-
|
6041
|
-
|
6042
|
-
|
6165
|
+
let filteredData = packer.filterData(
|
6166
|
+
metaData.data,
|
6167
|
+
metaData.width,
|
6168
|
+
metaData.height
|
6169
|
+
);
|
6043
6170
|
|
6044
|
-
|
6045
|
-
|
6046
|
-
|
6047
|
-
|
6048
|
-
|
6171
|
+
// compress it
|
6172
|
+
let compressedData = zlib.deflateSync(
|
6173
|
+
filteredData,
|
6174
|
+
packer.getDeflateOptions()
|
6175
|
+
);
|
6176
|
+
filteredData = null;
|
6177
|
+
|
6178
|
+
if (!compressedData || !compressedData.length) {
|
6179
|
+
throw new Error("bad png - invalid compressed data response");
|
6049
6180
|
}
|
6181
|
+
chunks.push(packer.packIDAT(compressedData));
|
6050
6182
|
|
6051
|
-
|
6052
|
-
|
6183
|
+
// End
|
6184
|
+
chunks.push(packer.packIEND());
|
6185
|
+
|
6186
|
+
return Buffer.concat(chunks);
|
6187
|
+
};
|
6053
6188
|
|
6189
|
+
let parse = parserSync;
|
6190
|
+
let pack = packerSync;
|
6054
6191
|
|
6055
|
-
function
|
6056
|
-
return
|
6057
|
-
}
|
6192
|
+
pngSync.read = function (buffer, options) {
|
6193
|
+
return parse(buffer, options || {});
|
6194
|
+
};
|
6058
6195
|
|
6059
|
-
function
|
6060
|
-
|
6061
|
-
|
6062
|
-
dst[i + offset] = src[i];
|
6063
|
-
}
|
6064
|
-
return i
|
6065
|
-
}
|
6196
|
+
pngSync.write = function (png, options) {
|
6197
|
+
return pack(png, options);
|
6198
|
+
};
|
6066
6199
|
|
6067
|
-
|
6068
|
-
|
6069
|
-
|
6200
|
+
let util = require$$0__default["default"];
|
6201
|
+
let Stream = require$$1__default["default"];
|
6202
|
+
let Parser = parserAsync.exports;
|
6203
|
+
let Packer = packerAsync.exports;
|
6204
|
+
let PNGSync = pngSync;
|
6070
6205
|
|
6206
|
+
let PNG = (png.PNG = function (options) {
|
6207
|
+
Stream.call(this);
|
6071
6208
|
|
6072
|
-
|
6073
|
-
// The _isBuffer check is for Safari 5-7 support, because it's missing
|
6074
|
-
// Object.prototype.constructor. Remove this eventually
|
6075
|
-
function isBuffer(obj) {
|
6076
|
-
return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
|
6077
|
-
}
|
6209
|
+
options = options || {}; // eslint-disable-line no-param-reassign
|
6078
6210
|
|
6079
|
-
|
6080
|
-
|
6081
|
-
|
6211
|
+
// coerce pixel dimensions to integers (also coerces undefined -> 0):
|
6212
|
+
this.width = options.width | 0;
|
6213
|
+
this.height = options.height | 0;
|
6082
6214
|
|
6083
|
-
|
6084
|
-
|
6085
|
-
|
6086
|
-
|
6215
|
+
this.data =
|
6216
|
+
this.width > 0 && this.height > 0
|
6217
|
+
? Buffer.alloc(4 * this.width * this.height)
|
6218
|
+
: null;
|
6087
6219
|
|
6088
|
-
|
6089
|
-
|
6090
|
-
|
6220
|
+
if (options.fill && this.data) {
|
6221
|
+
this.data.fill(0);
|
6222
|
+
}
|
6091
6223
|
|
6092
|
-
|
6093
|
-
|
6094
|
-
const pngOpts = opts.rendererOpts;
|
6095
|
-
const size = Utils$1.getImageWidth(qrData.modules.size, opts);
|
6224
|
+
this.gamma = 0;
|
6225
|
+
this.readable = this.writable = true;
|
6096
6226
|
|
6097
|
-
|
6098
|
-
pngOpts.height = size;
|
6227
|
+
this._parser = new Parser(options);
|
6099
6228
|
|
6100
|
-
|
6101
|
-
|
6229
|
+
this._parser.on("error", this.emit.bind(this, "error"));
|
6230
|
+
this._parser.on("close", this._handleClose.bind(this));
|
6231
|
+
this._parser.on("metadata", this._metadata.bind(this));
|
6232
|
+
this._parser.on("gamma", this._gamma.bind(this));
|
6233
|
+
this._parser.on(
|
6234
|
+
"parsed",
|
6235
|
+
function (data) {
|
6236
|
+
this.data = data;
|
6237
|
+
this.emit("parsed", data);
|
6238
|
+
}.bind(this)
|
6239
|
+
);
|
6102
6240
|
|
6103
|
-
|
6104
|
-
|
6241
|
+
this._packer = new Packer(options);
|
6242
|
+
this._packer.on("data", this.emit.bind(this, "data"));
|
6243
|
+
this._packer.on("end", this.emit.bind(this, "end"));
|
6244
|
+
this._parser.on("close", this._handleClose.bind(this));
|
6245
|
+
this._packer.on("error", this.emit.bind(this, "error"));
|
6246
|
+
});
|
6247
|
+
util.inherits(PNG, Stream);
|
6105
6248
|
|
6106
|
-
|
6107
|
-
|
6108
|
-
|
6109
|
-
|
6249
|
+
PNG.sync = PNGSync;
|
6250
|
+
|
6251
|
+
PNG.prototype.pack = function () {
|
6252
|
+
if (!this.data || !this.data.length) {
|
6253
|
+
this.emit("error", "No data provided");
|
6254
|
+
return this;
|
6110
6255
|
}
|
6111
6256
|
|
6112
|
-
|
6113
|
-
|
6114
|
-
|
6115
|
-
|
6116
|
-
|
6117
|
-
|
6257
|
+
process.nextTick(
|
6258
|
+
function () {
|
6259
|
+
this._packer.pack(this.data, this.width, this.height, this.gamma);
|
6260
|
+
}.bind(this)
|
6261
|
+
);
|
6262
|
+
|
6263
|
+
return this;
|
6118
6264
|
};
|
6119
6265
|
|
6120
|
-
|
6121
|
-
if (
|
6122
|
-
|
6123
|
-
|
6266
|
+
PNG.prototype.parse = function (data, callback) {
|
6267
|
+
if (callback) {
|
6268
|
+
let onParsed, onError;
|
6269
|
+
|
6270
|
+
onParsed = function (parsedData) {
|
6271
|
+
this.removeListener("error", onError);
|
6272
|
+
|
6273
|
+
this.data = parsedData;
|
6274
|
+
callback(null, this);
|
6275
|
+
}.bind(this);
|
6276
|
+
|
6277
|
+
onError = function (err) {
|
6278
|
+
this.removeListener("parsed", onParsed);
|
6279
|
+
|
6280
|
+
callback(err, null);
|
6281
|
+
}.bind(this);
|
6282
|
+
|
6283
|
+
this.once("parsed", onParsed);
|
6284
|
+
this.once("error", onError);
|
6124
6285
|
}
|
6125
6286
|
|
6126
|
-
|
6127
|
-
|
6287
|
+
this.end(data);
|
6288
|
+
return this;
|
6289
|
+
};
|
6128
6290
|
|
6129
|
-
|
6291
|
+
PNG.prototype.write = function (data) {
|
6292
|
+
this._parser.write(data);
|
6293
|
+
return true;
|
6294
|
+
};
|
6130
6295
|
|
6131
|
-
|
6132
|
-
|
6133
|
-
|
6296
|
+
PNG.prototype.end = function (data) {
|
6297
|
+
this._parser.end(data);
|
6298
|
+
};
|
6134
6299
|
|
6135
|
-
|
6136
|
-
|
6137
|
-
|
6300
|
+
PNG.prototype._metadata = function (metadata) {
|
6301
|
+
this.width = metadata.width;
|
6302
|
+
this.height = metadata.height;
|
6138
6303
|
|
6139
|
-
|
6304
|
+
this.emit("metadata", metadata);
|
6140
6305
|
};
|
6141
6306
|
|
6142
|
-
|
6143
|
-
|
6144
|
-
|
6145
|
-
|
6307
|
+
PNG.prototype._gamma = function (gamma) {
|
6308
|
+
this.gamma = gamma;
|
6309
|
+
};
|
6310
|
+
|
6311
|
+
PNG.prototype._handleClose = function () {
|
6312
|
+
if (!this._parser.writable && !this._packer.readable) {
|
6313
|
+
this.emit("close");
|
6146
6314
|
}
|
6315
|
+
};
|
6147
6316
|
|
6148
|
-
|
6149
|
-
|
6150
|
-
|
6151
|
-
|
6152
|
-
|
6153
|
-
|
6154
|
-
|
6317
|
+
PNG.bitblt = function (src, dst, srcX, srcY, width, height, deltaX, deltaY) {
|
6318
|
+
// eslint-disable-line max-params
|
6319
|
+
// coerce pixel dimensions to integers (also coerces undefined -> 0):
|
6320
|
+
/* eslint-disable no-param-reassign */
|
6321
|
+
srcX |= 0;
|
6322
|
+
srcY |= 0;
|
6323
|
+
width |= 0;
|
6324
|
+
height |= 0;
|
6325
|
+
deltaX |= 0;
|
6326
|
+
deltaY |= 0;
|
6327
|
+
/* eslint-enable no-param-reassign */
|
6155
6328
|
|
6156
|
-
|
6157
|
-
|
6329
|
+
if (
|
6330
|
+
srcX > src.width ||
|
6331
|
+
srcY > src.height ||
|
6332
|
+
srcX + width > src.width ||
|
6333
|
+
srcY + height > src.height
|
6334
|
+
) {
|
6335
|
+
throw new Error("bitblt reading outside image");
|
6336
|
+
}
|
6337
|
+
|
6338
|
+
if (
|
6339
|
+
deltaX > dst.width ||
|
6340
|
+
deltaY > dst.height ||
|
6341
|
+
deltaX + width > dst.width ||
|
6342
|
+
deltaY + height > dst.height
|
6343
|
+
) {
|
6344
|
+
throw new Error("bitblt writing outside image");
|
6345
|
+
}
|
6158
6346
|
|
6159
|
-
|
6347
|
+
for (let y = 0; y < height; y++) {
|
6348
|
+
src.data.copy(
|
6349
|
+
dst.data,
|
6350
|
+
((deltaY + y) * dst.width + deltaX) << 2,
|
6351
|
+
((srcY + y) * src.width + srcX) << 2,
|
6352
|
+
((srcY + y) * src.width + srcX + width) << 2
|
6353
|
+
);
|
6354
|
+
}
|
6160
6355
|
};
|
6161
6356
|
|
6162
|
-
|
6163
|
-
|
6164
|
-
|
6357
|
+
PNG.prototype.bitblt = function (
|
6358
|
+
dst,
|
6359
|
+
srcX,
|
6360
|
+
srcY,
|
6361
|
+
width,
|
6362
|
+
height,
|
6363
|
+
deltaX,
|
6364
|
+
deltaY
|
6365
|
+
) {
|
6366
|
+
// eslint-disable-line max-params
|
6367
|
+
|
6368
|
+
PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
|
6369
|
+
return this;
|
6165
6370
|
};
|
6166
6371
|
|
6167
|
-
|
6168
|
-
|
6169
|
-
|
6372
|
+
PNG.adjustGamma = function (src) {
|
6373
|
+
if (src.gamma) {
|
6374
|
+
for (let y = 0; y < src.height; y++) {
|
6375
|
+
for (let x = 0; x < src.width; x++) {
|
6376
|
+
let idx = (src.width * y + x) << 2;
|
6170
6377
|
|
6171
|
-
|
6378
|
+
for (let i = 0; i < 3; i++) {
|
6379
|
+
let sample = src.data[idx + i] / 255;
|
6380
|
+
sample = Math.pow(sample, 1 / 2.2 / src.gamma);
|
6381
|
+
src.data[idx + i] = Math.round(sample * 255);
|
6382
|
+
}
|
6383
|
+
}
|
6384
|
+
}
|
6385
|
+
src.gamma = 0;
|
6386
|
+
}
|
6387
|
+
};
|
6172
6388
|
|
6173
|
-
|
6389
|
+
PNG.prototype.adjustGamma = function () {
|
6390
|
+
PNG.adjustGamma(this);
|
6391
|
+
};
|
6174
6392
|
|
6175
6393
|
var utils = {};
|
6176
6394
|
|
@@ -6276,14 +6494,88 @@ var utils = {};
|
|
6276
6494
|
};
|
6277
6495
|
} (utils));
|
6278
6496
|
|
6279
|
-
|
6497
|
+
(function (exports) {
|
6498
|
+
const fs = require$$1__default$2["default"];
|
6499
|
+
const PNG = png.PNG;
|
6500
|
+
const Utils = utils;
|
6280
6501
|
|
6281
|
-
|
6282
|
-
|
6283
|
-
|
6284
|
-
|
6502
|
+
exports.render = function render (qrData, options) {
|
6503
|
+
const opts = Utils.getOptions(options);
|
6504
|
+
const pngOpts = opts.rendererOpts;
|
6505
|
+
const size = Utils.getImageWidth(qrData.modules.size, opts);
|
6506
|
+
|
6507
|
+
pngOpts.width = size;
|
6508
|
+
pngOpts.height = size;
|
6509
|
+
|
6510
|
+
const pngImage = new PNG(pngOpts);
|
6511
|
+
Utils.qrToImageData(pngImage.data, qrData, opts);
|
6512
|
+
|
6513
|
+
return pngImage
|
6514
|
+
};
|
6515
|
+
|
6516
|
+
exports.renderToDataURL = function renderToDataURL (qrData, options, cb) {
|
6517
|
+
if (typeof cb === 'undefined') {
|
6518
|
+
cb = options;
|
6519
|
+
options = undefined;
|
6520
|
+
}
|
6521
|
+
|
6522
|
+
exports.renderToBuffer(qrData, options, function (err, output) {
|
6523
|
+
if (err) cb(err);
|
6524
|
+
let url = 'data:image/png;base64,';
|
6525
|
+
url += output.toString('base64');
|
6526
|
+
cb(null, url);
|
6527
|
+
});
|
6528
|
+
};
|
6529
|
+
|
6530
|
+
exports.renderToBuffer = function renderToBuffer (qrData, options, cb) {
|
6531
|
+
if (typeof cb === 'undefined') {
|
6532
|
+
cb = options;
|
6533
|
+
options = undefined;
|
6534
|
+
}
|
6535
|
+
|
6536
|
+
const png = exports.render(qrData, options);
|
6537
|
+
const buffer = [];
|
6538
|
+
|
6539
|
+
png.on('error', cb);
|
6540
|
+
|
6541
|
+
png.on('data', function (data) {
|
6542
|
+
buffer.push(data);
|
6543
|
+
});
|
6544
|
+
|
6545
|
+
png.on('end', function () {
|
6546
|
+
cb(null, Buffer.concat(buffer));
|
6547
|
+
});
|
6285
6548
|
|
6286
|
-
|
6549
|
+
png.pack();
|
6550
|
+
};
|
6551
|
+
|
6552
|
+
exports.renderToFile = function renderToFile (path, qrData, options, cb) {
|
6553
|
+
if (typeof cb === 'undefined') {
|
6554
|
+
cb = options;
|
6555
|
+
options = undefined;
|
6556
|
+
}
|
6557
|
+
|
6558
|
+
let called = false;
|
6559
|
+
const done = (...args) => {
|
6560
|
+
if (called) return
|
6561
|
+
called = true;
|
6562
|
+
cb.apply(null, args);
|
6563
|
+
};
|
6564
|
+
const stream = fs.createWriteStream(path);
|
6565
|
+
|
6566
|
+
stream.on('error', done);
|
6567
|
+
stream.on('close', done);
|
6568
|
+
|
6569
|
+
exports.renderToFileStream(stream, qrData, options);
|
6570
|
+
};
|
6571
|
+
|
6572
|
+
exports.renderToFileStream = function renderToFileStream (stream, qrData, options) {
|
6573
|
+
const png = exports.render(qrData, options);
|
6574
|
+
png.pack().pipe(stream);
|
6575
|
+
};
|
6576
|
+
} (png$1));
|
6577
|
+
|
6578
|
+
var utf8 = {};
|
6287
6579
|
|
6288
6580
|
(function (exports) {
|
6289
6581
|
const Utils = utils;
|
@@ -6353,7 +6645,7 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(_polyfillNode_fs$1);
|
|
6353
6645
|
options = undefined;
|
6354
6646
|
}
|
6355
6647
|
|
6356
|
-
const fs = require$$
|
6648
|
+
const fs = require$$1__default$2["default"];
|
6357
6649
|
const utf8 = exports.render(qrData, options);
|
6358
6650
|
fs.writeFile(path, utf8, cb);
|
6359
6651
|
};
|
@@ -6596,7 +6888,7 @@ svgTag.render = function render (qrData, options, cb) {
|
|
6596
6888
|
options = undefined;
|
6597
6889
|
}
|
6598
6890
|
|
6599
|
-
const fs = require$$
|
6891
|
+
const fs = require$$1__default$2["default"];
|
6600
6892
|
const svgTag = exports.render(qrData, options);
|
6601
6893
|
|
6602
6894
|
const xmlStr = '<?xml version="1.0" encoding="utf-8"?>' +
|
@@ -6769,7 +7061,7 @@ function requireBrowser () {
|
|
6769
7061
|
|
6770
7062
|
const canPromise = canPromise$1;
|
6771
7063
|
const QRCode$1 = qrcode;
|
6772
|
-
const PngRenderer =
|
7064
|
+
const PngRenderer = png$1;
|
6773
7065
|
const Utf8Renderer = utf8;
|
6774
7066
|
const TerminalRenderer = terminal$1;
|
6775
7067
|
const SvgRenderer = svg;
|