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