pica 7.1.1 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -75,12 +75,8 @@ Use
75
75
  const pica = require('pica')();
76
76
 
77
77
  // Resize from Canvas/Image to another Canvas
78
- pica.resize(from, to, {
79
- unsharpAmount: 160,
80
- unsharpRadius: 0.6,
81
- unsharpThreshold: 1
82
- })
83
- .then(result => console.log('resize done!'));
78
+ pica.resize(from, to)
79
+ .then(result => console.log('resize done!'));
84
80
 
85
81
  // Resize & convert to blob
86
82
  pica.resize(from, to)
@@ -100,7 +96,8 @@ Create resizer instance with given config (optional):
100
96
  to restrict peak memory use. Default 1024.
101
97
  - __features__ - list of features to use. Default is
102
98
  `[ 'js', 'wasm', 'ww' ]`. Can be `[ 'js', 'wasm', 'cib', 'ww' ]`
103
- or `[ 'all' ]`.
99
+ or `[ 'all' ]`. Note, `cib` is buggy in Chrome and not supports default
100
+ `mks2013` filter.
104
101
  - __idle__ - cache timeout, ms. Webworkers create is not fast.
105
102
  This option allow reuse webworkers effectively. Default 2000.
106
103
  - __concurrency__ - max webworkers pool size. Default is autodetected
@@ -131,10 +128,12 @@ taken from source and destination objects.
131
128
  - __from__ - source, can be `Canvas`, `Image` or `ImageBitmap`.
132
129
  - __to__ - destination canvas, its size is supposed to be non-zero.
133
130
  - __options__ - quality (number) or object:
134
- - __quality__ - 0..3. Default = `3` (lanczos, win=3).
131
+ - __quality__ (deprecated, use `.filter` instead) - 0..3.
132
+ - __filter__ - filter name (Default - `mks2013`). See [resize_filter_info.js](https://github.com/nodeca/pica/blob/master/lib/mm_resize/resize_filter_info.js) for details. `mks2013` does both resize and sharpening, it's optimal and not recommended to change.
135
133
  - __alpha__ - use alpha channel. Default = `false`.
136
- - __unsharpAmount__ - >=0, in percents. Default = `0` (off). Usually
137
- between 100 to 200 is good.
134
+ - __unsharpAmount__ - >=0. Default = `0` (off). Usually
135
+ value between 100 to 200 is good. Note, `mks2013` filter already does
136
+ optimal sharpening.
138
137
  - __unsharpRadius__ - 0.5..2.0. By default it's not set. Radius of Gaussian
139
138
  blur. If it is less than 0.5, Unsharp Mask is off. Big values are clamped
140
139
  to 2.0.
@@ -170,10 +169,12 @@ binary data (for example, if you decode jpeg files "manually").
170
169
  - __height__ - src image height.
171
170
  - __toWidth__ - output width, >=0, in pixels.
172
171
  - __toHeight__ - output height, >=0, in pixels.
173
- - __quality__ - 0..3. Default = `3` (lanczos, win=3).
172
+ - __quality__ (deprecated, use `.filter` instead) - 0..3.
173
+ - __filter__ - filter name (Default - `mks2013`). See [resize_filter_info.js](https://github.com/nodeca/pica/blob/master/lib/mm_resize/resize_filter_info.js) for details. `mks2013` does both resize and sharpening, it's optimal and not recommended to change.
174
174
  - __alpha__ - use alpha channel. Default = `false`.
175
- - __unsharpAmount__ - >=0, in percents. Default = `0` (off).
176
- Usually between 50 to 100 is good.
175
+ - __unsharpAmount__ - >=0. Default = `0` (off). Usually
176
+ value between 100 to 200 is good. Note, `mks2013` filter already does
177
+ optimal sharpening.
177
178
  - __unsharpRadius__ - 0.5..2.0. Radius of Gaussian blur.
178
179
  If it is less than 0.5, Unsharp Mask is off. Big values are
179
180
  clamped to 2.0.
package/dist/pica.js CHANGED
@@ -236,10 +236,10 @@ module.exports = function resize(options) {
236
236
  var offsetX = options.offsetX || 0;
237
237
  var offsetY = options.offsetY || 0;
238
238
  var dest = options.dest || new Uint8Array(destW * destH * 4);
239
- var quality = typeof options.quality === 'undefined' ? 3 : options.quality;
240
239
  var alpha = options.alpha || false;
241
- var filtersX = createFilters(quality, srcW, destW, scaleX, offsetX),
242
- filtersY = createFilters(quality, srcH, destH, scaleY, offsetY);
240
+ var filter = typeof options.filter === 'undefined' ? 'mks2013' : options.filter;
241
+ var filtersX = createFilters(filter, srcW, destW, scaleX, offsetX),
242
+ filtersY = createFilters(filter, srcH, destH, scaleY, offsetY);
243
243
  var tmp = new Uint8Array(destW * srcH * 4); // To use single function we need src & tmp of the same type.
244
244
  // But src can be CanvasPixelArray, and tmp - Uint8Array. So, keep
245
245
  // vertical and horizontal passes separately to avoid deoptimization.
@@ -274,13 +274,13 @@ function toFixedPoint(num) {
274
274
  return Math.round(num * ((1 << FIXED_FRAC_BITS) - 1));
275
275
  }
276
276
 
277
- module.exports = function resizeFilterGen(quality, srcSize, destSize, scale, offset) {
278
- var filterFunction = FILTER_INFO[quality].filter;
277
+ module.exports = function resizeFilterGen(filter, srcSize, destSize, scale, offset) {
278
+ var filterFunction = FILTER_INFO.filter[filter].fn;
279
279
  var scaleInverted = 1.0 / scale;
280
280
  var scaleClamped = Math.min(1.0, scale); // For upscale
281
281
  // Filter window (averaging interval), scaled to src image
282
282
 
283
- var srcWindow = FILTER_INFO[quality].win / scaleClamped;
283
+ var srcWindow = FILTER_INFO.filter[filter].win / scaleClamped;
284
284
  var destPixel, srcPixel, srcFirst, srcLast, filterElementSize, floatFilter, fxpFilter, total, pxl, idx, floatVal, filterTotal, filterVal;
285
285
  var leftNotEmpty, rightNotEmpty, filterShift, filterSize;
286
286
  var maxFilterElementSize = Math.floor((srcWindow + 1) * 2);
@@ -370,58 +370,103 @@ module.exports = function resizeFilterGen(quality, srcSize, destSize, scale, off
370
370
  //
371
371
  'use strict';
372
372
 
373
- module.exports = [{
374
- // Nearest neibor (Box)
375
- win: 0.5,
376
- filter: function filter(x) {
377
- return x >= -0.5 && x < 0.5 ? 1.0 : 0.0;
378
- }
379
- }, {
380
- // Hamming
381
- win: 1.0,
382
- filter: function filter(x) {
383
- if (x <= -1.0 || x >= 1.0) {
384
- return 0.0;
373
+ var filter = {
374
+ // Nearest neibor
375
+ box: {
376
+ win: 0.5,
377
+ fn: function fn(x) {
378
+ if (x < 0) x = -x;
379
+ return x < 0.5 ? 1.0 : 0.0;
385
380
  }
381
+ },
382
+ // // Hamming
383
+ hamming: {
384
+ win: 1.0,
385
+ fn: function fn(x) {
386
+ if (x < 0) x = -x;
387
+
388
+ if (x >= 1.0) {
389
+ return 0.0;
390
+ }
386
391
 
387
- if (x > -1.19209290E-07 && x < 1.19209290E-07) {
388
- return 1.0;
389
- }
392
+ if (x < 1.19209290E-07) {
393
+ return 1.0;
394
+ }
390
395
 
391
- var xpi = x * Math.PI;
392
- return Math.sin(xpi) / xpi * (0.54 + 0.46 * Math.cos(xpi / 1.0));
393
- }
394
- }, {
395
- // Lanczos, win = 2
396
- win: 2.0,
397
- filter: function filter(x) {
398
- if (x <= -2.0 || x >= 2.0) {
399
- return 0.0;
396
+ var xpi = x * Math.PI;
397
+ return Math.sin(xpi) / xpi * (0.54 + 0.46 * Math.cos(xpi / 1.0));
400
398
  }
399
+ },
400
+ // Lanczos, win = 2
401
+ lanczos2: {
402
+ win: 2.0,
403
+ fn: function fn(x) {
404
+ if (x < 0) x = -x;
401
405
 
402
- if (x > -1.19209290E-07 && x < 1.19209290E-07) {
403
- return 1.0;
404
- }
406
+ if (x >= 2.0) {
407
+ return 0.0;
408
+ }
405
409
 
406
- var xpi = x * Math.PI;
407
- return Math.sin(xpi) / xpi * Math.sin(xpi / 2.0) / (xpi / 2.0);
408
- }
409
- }, {
410
- // Lanczos, win = 3
411
- win: 3.0,
412
- filter: function filter(x) {
413
- if (x <= -3.0 || x >= 3.0) {
414
- return 0.0;
410
+ if (x < 1.19209290E-07) {
411
+ return 1.0;
412
+ }
413
+
414
+ var xpi = x * Math.PI;
415
+ return Math.sin(xpi) / xpi * Math.sin(xpi / 2.0) / (xpi / 2.0);
415
416
  }
417
+ },
418
+ // Lanczos, win = 3
419
+ lanczos3: {
420
+ win: 3.0,
421
+ fn: function fn(x) {
422
+ if (x < 0) x = -x;
423
+
424
+ if (x >= 3.0) {
425
+ return 0.0;
426
+ }
416
427
 
417
- if (x > -1.19209290E-07 && x < 1.19209290E-07) {
418
- return 1.0;
428
+ if (x < 1.19209290E-07) {
429
+ return 1.0;
430
+ }
431
+
432
+ var xpi = x * Math.PI;
433
+ return Math.sin(xpi) / xpi * Math.sin(xpi / 3.0) / (xpi / 3.0);
419
434
  }
435
+ },
436
+ // Magic Kernel Sharp 2013, win = 2.5
437
+ // http://johncostella.com/magic/
438
+ mks2013: {
439
+ win: 2.5,
440
+ fn: function fn(x) {
441
+ if (x < 0) x = -x;
442
+
443
+ if (x >= 2.5) {
444
+ return 0.0;
445
+ }
446
+
447
+ if (x >= 1.5) {
448
+ return -0.125 * (x - 2.5) * (x - 2.5);
449
+ }
420
450
 
421
- var xpi = x * Math.PI;
422
- return Math.sin(xpi) / xpi * Math.sin(xpi / 3.0) / (xpi / 3.0);
451
+ if (x >= 0.5) {
452
+ return 0.25 * (4 * x * x - 11 * x + 7);
453
+ }
454
+
455
+ return 1.0625 - 1.75 * x * x;
456
+ }
423
457
  }
424
- }];
458
+ };
459
+ module.exports = {
460
+ filter: filter,
461
+ // Legacy mapping
462
+ f2q: {
463
+ box: 0,
464
+ hamming: 1,
465
+ lanczos2: 2,
466
+ lanczos3: 3
467
+ },
468
+ q2f: ['box', 'hamming', 'lanczos2', 'lanczos3']
469
+ };
425
470
 
426
471
  },{}],8:[function(_dereq_,module,exports){
427
472
  'use strict';
@@ -472,10 +517,10 @@ module.exports = function resize_wasm(options) {
472
517
  var offsetX = options.offsetX || 0.0;
473
518
  var offsetY = options.offsetY || 0.0;
474
519
  var dest = options.dest || new Uint8Array(destW * destH * 4);
475
- var quality = typeof options.quality === 'undefined' ? 3 : options.quality;
476
520
  var alpha = options.alpha || false;
477
- var filtersX = createFilters(quality, srcW, destW, scaleX, offsetX),
478
- filtersY = createFilters(quality, srcH, destH, scaleY, offsetY); // destination is 0 too.
521
+ var filter = typeof options.filter === 'undefined' ? 'mks2013' : options.filter;
522
+ var filtersX = createFilters(filter, srcW, destW, scaleX, offsetX),
523
+ filtersY = createFilters(filter, srcH, destH, scaleY, offsetY); // destination is 0 too.
479
524
 
480
525
  var src_offset = 0; // buffer between convolve passes
481
526
 
@@ -1745,7 +1790,9 @@ var worker = _dereq_('./lib/worker');
1745
1790
 
1746
1791
  var createStages = _dereq_('./lib/stepper');
1747
1792
 
1748
- var createRegions = _dereq_('./lib/tiler'); // Deduplicate pools & limiters with the same configs
1793
+ var createRegions = _dereq_('./lib/tiler');
1794
+
1795
+ var filter_info = _dereq_('./lib/mm_resize/resize_filter_info'); // Deduplicate pools & limiters with the same configs
1749
1796
  // when user creates multiple pica instances.
1750
1797
 
1751
1798
 
@@ -1777,7 +1824,7 @@ var DEFAULT_PICA_OPTS = {
1777
1824
  }
1778
1825
  };
1779
1826
  var DEFAULT_RESIZE_OPTS = {
1780
- quality: 3,
1827
+ filter: 'mks2013',
1781
1828
  alpha: false,
1782
1829
  unsharpAmount: 0,
1783
1830
  unsharpRadius: 0.0,
@@ -2088,7 +2135,7 @@ Pica.prototype.__tileAndResize = function (from, to, opts) {
2088
2135
  scaleY: tile.scaleY,
2089
2136
  offsetX: tile.offsetX,
2090
2137
  offsetY: tile.offsetY,
2091
- quality: opts.quality,
2138
+ filter: opts.filter,
2092
2139
  alpha: opts.alpha,
2093
2140
  unsharpAmount: opts.unsharpAmount,
2094
2141
  unsharpRadius: opts.unsharpRadius,
@@ -2196,14 +2243,20 @@ Pica.prototype.__processStages = function (stages, from, to, opts) {
2196
2243
  toWidth = _stages$shift2[0],
2197
2244
  toHeight = _stages$shift2[1];
2198
2245
 
2199
- var isLastStage = stages.length === 0;
2246
+ var isLastStage = stages.length === 0; // Optimization for legacy filters -
2247
+ // only use user-defined quality for the last stage,
2248
+ // use simpler (Hamming) filter for the first stages where
2249
+ // scale factor is large enough (more than 2-3)
2250
+ //
2251
+ // For advanced filters (mks2013 and custom) - skip optimization,
2252
+ // because need to apply sharpening every time
2253
+
2254
+ var filter;
2255
+ if (isLastStage || filter_info.q2f.indexOf(opts.filter) < 0) filter = opts.filter;else if (opts.filter === 'box') filter = 'box';else filter = 'hamming';
2200
2256
  opts = assign({}, opts, {
2201
2257
  toWidth: toWidth,
2202
2258
  toHeight: toHeight,
2203
- // only use user-defined quality for the last stage,
2204
- // use simpler (Hamming) filter for the first stages where
2205
- // scale factor is large enough (more than 2-3)
2206
- quality: isLastStage ? opts.quality : Math.min(1, opts.quality)
2259
+ filter: filter
2207
2260
  });
2208
2261
  var tmpCanvas;
2209
2262
 
@@ -2238,7 +2291,7 @@ Pica.prototype.__resizeViaCreateImageBitmap = function (from, to, opts) {
2238
2291
  return createImageBitmap(from, {
2239
2292
  resizeWidth: opts.toWidth,
2240
2293
  resizeHeight: opts.toHeight,
2241
- resizeQuality: utils.cib_quality_name(opts.quality)
2294
+ resizeQuality: utils.cib_quality_name(filter_info.f2q[opts.filter])
2242
2295
  }).then(function (imageBitmap) {
2243
2296
  if (opts.canceled) return opts.cancelToken; // if no unsharp - draw directly to output canvas
2244
2297
 
@@ -2294,7 +2347,16 @@ Pica.prototype.resize = function (from, to, options) {
2294
2347
  opts.toWidth = to.width;
2295
2348
  opts.toHeight = to.height;
2296
2349
  opts.width = from.naturalWidth || from.width;
2297
- opts.height = from.naturalHeight || from.height; // Prevent stepper from infinite loop
2350
+ opts.height = from.naturalHeight || from.height; // Legacy `.quality` option
2351
+
2352
+ if (Object.prototype.hasOwnProperty.call(opts, 'quality')) {
2353
+ if (opts.quality < 0 || opts.quality > 3) {
2354
+ throw new Error("Pica: .quality should be [0..3], got ".concat(opts.quality));
2355
+ }
2356
+
2357
+ opts.filter = filter_info.q2f[opts.quality];
2358
+ } // Prevent stepper from infinite loop
2359
+
2298
2360
 
2299
2361
  if (to.width === 0 || to.height === 0) {
2300
2362
  return Promise.reject(new Error("Invalid output size: ".concat(to.width, "x").concat(to.height)));
@@ -2321,7 +2383,11 @@ Pica.prototype.resize = function (from, to, options) {
2321
2383
  if (opts.canceled) return opts.cancelToken; // if createImageBitmap supports resize, just do it and return
2322
2384
 
2323
2385
  if (_this6.features.cib) {
2324
- return _this6.__resizeViaCreateImageBitmap(from, to, opts);
2386
+ if (filter_info.q2f.indexOf(opts.filter) >= 0) {
2387
+ return _this6.__resizeViaCreateImageBitmap(from, to, opts);
2388
+ }
2389
+
2390
+ _this6.debug('cib is enabled, but not supports provided filter, fallback to manual math');
2325
2391
  }
2326
2392
 
2327
2393
  if (!CAN_USE_CANVAS_GET_IMAGE_DATA) {
@@ -2343,7 +2409,16 @@ Pica.prototype.resize = function (from, to, options) {
2343
2409
  Pica.prototype.resizeBuffer = function (options) {
2344
2410
  var _this7 = this;
2345
2411
 
2346
- var opts = assign({}, DEFAULT_RESIZE_OPTS, options);
2412
+ var opts = assign({}, DEFAULT_RESIZE_OPTS, options); // Legacy `.quality` option
2413
+
2414
+ if (Object.prototype.hasOwnProperty.call(opts, 'quality')) {
2415
+ if (opts.quality < 0 || opts.quality > 3) {
2416
+ throw new Error("Pica: .quality should be [0..3], got ".concat(opts.quality));
2417
+ }
2418
+
2419
+ opts.filter = filter_info.q2f[opts.quality];
2420
+ }
2421
+
2347
2422
  return this.init().then(function () {
2348
2423
  return _this7.__mathlib.resizeAndUnsharp(opts);
2349
2424
  });
@@ -2386,5 +2461,5 @@ Pica.prototype.debug = function () {};
2386
2461
 
2387
2462
  module.exports = Pica;
2388
2463
 
2389
- },{"./lib/mathlib":1,"./lib/pool":13,"./lib/stepper":14,"./lib/tiler":15,"./lib/utils":16,"./lib/worker":17,"object-assign":23,"webworkify":24}]},{},[])("/index.js")
2464
+ },{"./lib/mathlib":1,"./lib/mm_resize/resize_filter_info":7,"./lib/pool":13,"./lib/stepper":14,"./lib/tiler":15,"./lib/utils":16,"./lib/worker":17,"object-assign":23,"webworkify":24}]},{},[])("/index.js")
2390
2465
  });
package/dist/pica.min.js CHANGED
@@ -4,10 +4,10 @@ pica
4
4
  https://github.com/nodeca/pica
5
5
 
6
6
  */
7
- !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).pica=t()}}((function(){return function t(e,r,i){function n(a,o){if(!r[a]){if(!e[a]){var s="function"==typeof require&&require;if(!o&&s)return s(a,!0);if(A)return A(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var h=r[a]={exports:{}};e[a][0].call(h.exports,(function(t){return n(e[a][1][t]||t)}),h,h.exports,t,e,r,i)}return r[a].exports}for(var A="function"==typeof require&&require,a=0;a<i.length;a++)n(i[a]);return n}({1:[function(t,e,r){"use strict";var i=t("inherits"),n=t("multimath"),A=t("./mm_unsharp_mask"),a=t("./mm_resize");function o(t){var e=t||[],r={js:e.indexOf("js")>=0,wasm:e.indexOf("wasm")>=0};n.call(this,r),this.features={js:r.js,wasm:r.wasm&&this.has_wasm()},this.use(A),this.use(a)}i(o,n),o.prototype.resizeAndUnsharp=function(t,e){var r=this.resize(t,e);return t.unsharpAmount&&this.unsharp_mask(r,t.toWidth,t.toHeight,t.unsharpAmount,t.unsharpRadius,t.unsharpThreshold),r},e.exports=o},{"./mm_resize":4,"./mm_unsharp_mask":9,inherits:19,multimath:20}],2:[function(t,e,r){"use strict";function i(t){return t<0?0:t>255?255:t}e.exports={convolveHorizontally:function(t,e,r,n,A,a){var o,s,u,h,c,f,l,g,d,p,m,I=0,w=0;for(d=0;d<n;d++){for(c=0,p=0;p<A;p++){for(f=a[c++],l=a[c++],g=I+4*f|0,o=s=u=h=0;l>0;l--)h=h+(m=a[c++])*t[g+3]|0,u=u+m*t[g+2]|0,s=s+m*t[g+1]|0,o=o+m*t[g]|0,g=g+4|0;e[w+3]=i(h+8192>>14),e[w+2]=i(u+8192>>14),e[w+1]=i(s+8192>>14),e[w]=i(o+8192>>14),w=w+4*n|0}w=4*(d+1)|0,I=(d+1)*r*4|0}},convolveVertically:function(t,e,r,n,A,a){var o,s,u,h,c,f,l,g,d,p,m,I=0,w=0;for(d=0;d<n;d++){for(c=0,p=0;p<A;p++){for(f=a[c++],l=a[c++],g=I+4*f|0,o=s=u=h=0;l>0;l--)h=h+(m=a[c++])*t[g+3]|0,u=u+m*t[g+2]|0,s=s+m*t[g+1]|0,o=o+m*t[g]|0,g=g+4|0;e[w+3]=i(h+8192>>14),e[w+2]=i(u+8192>>14),e[w+1]=i(s+8192>>14),e[w]=i(o+8192>>14),w=w+4*n|0}w=4*(d+1)|0,I=(d+1)*r*4|0}}}},{}],3:[function(t,e,r){"use strict";e.exports="AGFzbQEAAAAADAZkeWxpbmsAAAAAAAEXA2AAAGAGf39/f39/AGAHf39/f39/fwACDwEDZW52Bm1lbW9yeQIAAAMEAwABAgYGAX8AQQALB1cFEV9fd2FzbV9jYWxsX2N0b3JzAAAIY29udm9sdmUAAQpjb252b2x2ZUhWAAIMX19kc29faGFuZGxlAwAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAK7AMDAwABC8YDAQ9/AkAgA0UNACAERQ0AA0AgDCENQQAhE0EAIQcDQCAHQQJqIQYCfyAHQQF0IAVqIgcuAQIiFEUEQEGAwAAhCEGAwAAhCUGAwAAhCkGAwAAhCyAGDAELIBIgBy4BAGohCEEAIQsgFCEHQQAhDiAGIQlBACEPQQAhEANAIAUgCUEBdGouAQAiESAAIAhBAnRqKAIAIgpBGHZsIBBqIRAgCkH/AXEgEWwgC2ohCyAKQRB2Qf8BcSARbCAPaiEPIApBCHZB/wFxIBFsIA5qIQ4gCEEBaiEIIAlBAWohCSAHQQFrIgcNAAsgC0GAQGshCCAOQYBAayEJIA9BgEBrIQogEEGAQGshCyAGIBRqCyEHIAEgDUECdGogCUEOdSIGQf8BIAZB/wFIGyIGQQAgBkEAShtBCHRBgP4DcSAKQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EQdEGAgPwHcSALQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EYdHJyIAhBDnUiBkH/ASAGQf8BSBsiBkEAIAZBAEobcjYCACADIA1qIQ0gE0EBaiITIARHDQALIAxBAWoiDCACbCESIAMgDEcNAAsLCx4AQQAgAiADIAQgBSAAEAEgAkEAIAQgBSAGIAEQAQs="},{}],4:[function(t,e,r){"use strict";e.exports={name:"resize",fn:t("./resize"),wasm_fn:t("./resize_wasm"),wasm_src:t("./convolve_wasm_base64")}},{"./convolve_wasm_base64":3,"./resize":5,"./resize_wasm":8}],5:[function(t,e,r){"use strict";var i=t("./resize_filter_gen"),n=t("./convolve").convolveHorizontally,A=t("./convolve").convolveVertically;e.exports=function(t){var e=t.src,r=t.width,a=t.height,o=t.toWidth,s=t.toHeight,u=t.scaleX||t.toWidth/t.width,h=t.scaleY||t.toHeight/t.height,c=t.offsetX||0,f=t.offsetY||0,l=t.dest||new Uint8Array(o*s*4),g=void 0===t.quality?3:t.quality,d=t.alpha||!1,p=i(g,r,o,u,c),m=i(g,a,s,h,f),I=new Uint8Array(o*a*4);return n(e,I,r,a,o,p),A(I,l,a,o,s,m),d||function(t,e,r){for(var i=3,n=e*r*4|0;i<n;)t[i]=255,i=i+4|0}(l,o,s),l}},{"./convolve":2,"./resize_filter_gen":6}],6:[function(t,e,r){"use strict";var i=t("./resize_filter_info");function n(t){return Math.round(16383*t)}e.exports=function(t,e,r,A,a){var o,s,u,h,c,f,l,g,d,p,m,I,w,_,B,b,y,v=i[t].filter,Q=1/A,C=Math.min(1,A),E=i[t].win/C,M=Math.floor(2*(E+1)),x=new Int16Array((M+2)*r),D=0,G=!x.subarray||!x.set;for(o=0;o<r;o++){for(s=(o+.5)*Q+a,u=Math.max(0,Math.floor(s-E)),c=(h=Math.min(e-1,Math.ceil(s+E)))-u+1,f=new Float32Array(c),l=new Int16Array(c),g=0,d=u,p=0;d<=h;d++,p++)g+=m=v((d+.5-s)*C),f[p]=m;for(I=0,p=0;p<f.length;p++)I+=w=f[p]/g,l[p]=n(w);for(l[r>>1]+=n(1-I),_=0;_<l.length&&0===l[_];)_++;if(_<l.length){for(B=l.length-1;B>0&&0===l[B];)B--;if(b=u+_,y=B-_+1,x[D++]=b,x[D++]=y,G)for(p=_;p<=B;p++)x[D++]=l[p];else x.set(l.subarray(_,B+1),D),D+=y}else x[D++]=0,x[D++]=0}return x}},{"./resize_filter_info":7}],7:[function(t,e,r){"use strict";e.exports=[{win:.5,filter:function(t){return t>=-.5&&t<.5?1:0}},{win:1,filter:function(t){if(t<=-1||t>=1)return 0;if(t>-1.1920929e-7&&t<1.1920929e-7)return 1;var e=t*Math.PI;return Math.sin(e)/e*(.54+.46*Math.cos(e/1))}},{win:2,filter:function(t){if(t<=-2||t>=2)return 0;if(t>-1.1920929e-7&&t<1.1920929e-7)return 1;var e=t*Math.PI;return Math.sin(e)/e*Math.sin(e/2)/(e/2)}},{win:3,filter:function(t){if(t<=-3||t>=3)return 0;if(t>-1.1920929e-7&&t<1.1920929e-7)return 1;var e=t*Math.PI;return Math.sin(e)/e*Math.sin(e/3)/(e/3)}}]},{}],8:[function(t,e,r){"use strict";var i=t("./resize_filter_gen");var n=!0;try{n=1===new Uint32Array(new Uint8Array([1,0,0,0]).buffer)[0]}catch(t){}function A(t,e,r){if(n)e.set(function(t){return new Uint8Array(t.buffer,0,t.byteLength)}(t),r);else for(var i=r,A=0;A<t.length;A++){var a=t[A];e[i++]=255&a,e[i++]=a>>8&255}}e.exports=function(t){var e=t.src,r=t.width,n=t.height,a=t.toWidth,o=t.toHeight,s=t.scaleX||t.toWidth/t.width,u=t.scaleY||t.toHeight/t.height,h=t.offsetX||0,c=t.offsetY||0,f=t.dest||new Uint8Array(a*o*4),l=void 0===t.quality?3:t.quality,g=t.alpha||!1,d=i(l,r,a,s,h),p=i(l,n,o,u,c),m=this.__align(0+Math.max(e.byteLength,f.byteLength)),I=this.__align(m+n*a*4),w=this.__align(I+d.byteLength),_=w+p.byteLength,B=this.__instance("resize",_),b=new Uint8Array(this.__memory.buffer),y=new Uint32Array(this.__memory.buffer),v=new Uint32Array(e.buffer);return y.set(v),A(d,b,I),A(p,b,w),(B.exports.convolveHV||B.exports._convolveHV)(I,w,m,r,n,a,o),new Uint32Array(f.buffer).set(new Uint32Array(this.__memory.buffer,0,o*a)),g||function(t,e,r){for(var i=3,n=e*r*4|0;i<n;)t[i]=255,i=i+4|0}(f,a,o),f}},{"./resize_filter_gen":6}],9:[function(t,e,r){"use strict";e.exports={name:"unsharp_mask",fn:t("./unsharp_mask"),wasm_fn:t("./unsharp_mask_wasm"),wasm_src:t("./unsharp_mask_wasm_base64")}},{"./unsharp_mask":10,"./unsharp_mask_wasm":11,"./unsharp_mask_wasm_base64":12}],10:[function(t,e,r){"use strict";var i=t("glur/mono16");e.exports=function(t,e,r,n,A,a){var o,s,u,h,c;if(!(0===n||A<.5)){A>2&&(A=2);var f=function(t,e,r){for(var i,n,A,a,o=e*r,s=new Uint16Array(o),u=0;u<o;u++)i=t[4*u],n=t[4*u+1],A=t[4*u+2],a=i>=n&&i>=A?i:n>=A&&n>=i?n:A,s[u]=a<<8;return s}(t,e,r),l=new Uint16Array(f);i(l,e,r,A);for(var g=n/100*4096+.5|0,d=a<<8,p=e*r,m=0;m<p;m++)h=(o=f[m])-l[m],Math.abs(h)>=d&&(u=((s=(s=(s=o+(g*h+2048>>12))>65280?65280:s)<0?0:s)<<12)/(o=0!==o?o:1)|0,t[c=4*m]=t[c]*u+2048>>12,t[c+1]=t[c+1]*u+2048>>12,t[c+2]=t[c+2]*u+2048>>12)}}},{"glur/mono16":18}],11:[function(t,e,r){"use strict";e.exports=function(t,e,r,i,n,A){if(!(0===i||n<.5)){n>2&&(n=2);var a=e*r,o=4*a,s=2*a,u=2*a,h=4*Math.max(e,r),c=o,f=c+s,l=f+u,g=l+u,d=g+h,p=this.__instance("unsharp_mask",o+s+2*u+h+32,{exp:Math.exp}),m=new Uint32Array(t.buffer);new Uint32Array(this.__memory.buffer).set(m);var I=p.exports.hsv_v16||p.exports._hsv_v16;I(0,c,e,r),(I=p.exports.blurMono16||p.exports._blurMono16)(c,f,l,g,d,e,r,n),(I=p.exports.unsharp||p.exports._unsharp)(0,0,c,f,e,r,i,A),m.set(new Uint32Array(this.__memory.buffer,0,a))}}},{}],12:[function(t,e,r){"use strict";e.exports="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"},{}],13:[function(t,e,r){"use strict";function i(t,e){this.create=t,this.available=[],this.acquired={},this.lastId=1,this.timeoutId=0,this.idle=e||2e3}i.prototype.acquire=function(){var t,e=this;return 0!==this.available.length?t=this.available.pop():((t=this.create()).id=this.lastId++,t.release=function(){return e.release(t)}),this.acquired[t.id]=t,t},i.prototype.release=function(t){var e=this;delete this.acquired[t.id],t.lastUsed=Date.now(),this.available.push(t),0===this.timeoutId&&(this.timeoutId=setTimeout((function(){return e.gc()}),100))},i.prototype.gc=function(){var t=this,e=Date.now();this.available=this.available.filter((function(r){return!(e-r.lastUsed>t.idle)||(r.destroy(),!1)})),0!==this.available.length?this.timeoutId=setTimeout((function(){return t.gc()}),100):this.timeoutId=0},e.exports=i},{}],14:[function(t,e,r){"use strict";e.exports=function(t,e,r,i,n,A){var a=r/t,o=i/e,s=(2*A+2+1)/n;if(s>.5)return[[r,i]];var u=Math.ceil(Math.log(Math.min(a,o))/Math.log(s));if(u<=1)return[[r,i]];for(var h=[],c=0;c<u;c++){var f=Math.round(Math.pow(Math.pow(t,u-c-1)*Math.pow(r,c+1),1/u)),l=Math.round(Math.pow(Math.pow(e,u-c-1)*Math.pow(i,c+1),1/u));h.push([f,l])}return h}},{}],15:[function(t,e,r){"use strict";var i=1e-5;function n(t){var e=Math.round(t);return Math.abs(t-e)<i?e:Math.floor(t)}function A(t){var e=Math.round(t);return Math.abs(t-e)<i?e:Math.ceil(t)}e.exports=function(t){var e,r,i,a,o,s,u=t.toWidth/t.width,h=t.toHeight/t.height,c=n(t.srcTileSize*u)-2*t.destTileBorder,f=n(t.srcTileSize*h)-2*t.destTileBorder;if(c<1||f<1)throw new Error("Internal error in pica: target tile width/height is too small.");var l,g=[];for(a=0;a<t.toHeight;a+=f)for(i=0;i<t.toWidth;i+=c)(e=i-t.destTileBorder)<0&&(e=0),e+(o=i+c+t.destTileBorder-e)>=t.toWidth&&(o=t.toWidth-e),(r=a-t.destTileBorder)<0&&(r=0),r+(s=a+f+t.destTileBorder-r)>=t.toHeight&&(s=t.toHeight-r),l={toX:e,toY:r,toWidth:o,toHeight:s,toInnerX:i,toInnerY:a,toInnerWidth:c,toInnerHeight:f,offsetX:e/u-n(e/u),offsetY:r/h-n(r/h),scaleX:u,scaleY:h,x:n(e/u),y:n(r/h),width:A(o/u),height:A(s/h)},g.push(l);return g}},{}],16:[function(t,e,r){"use strict";function i(t){return Object.prototype.toString.call(t)}e.exports.isCanvas=function(t){var e=i(t);return"[object HTMLCanvasElement]"===e||"[object OffscreenCanvas]"===e||"[object Canvas]"===e},e.exports.isImage=function(t){return"[object HTMLImageElement]"===i(t)},e.exports.isImageBitmap=function(t){return"[object ImageBitmap]"===i(t)},e.exports.limiter=function(t){var e=0,r=[];function i(){e<t&&r.length&&(e++,r.shift()())}return function(t){return new Promise((function(n,A){r.push((function(){t().then((function(t){n(t),e--,i()}),(function(t){A(t),e--,i()}))})),i()}))}},e.exports.cib_quality_name=function(t){switch(t){case 0:return"pixelated";case 1:return"low";case 2:return"medium"}return"high"},e.exports.cib_support=function(t){return Promise.resolve().then((function(){if("undefined"==typeof createImageBitmap)return!1;var e=t(100,100);return createImageBitmap(e,0,0,100,100,{resizeWidth:10,resizeHeight:10,resizeQuality:"high"}).then((function(t){var r=10===t.width;return t.close(),e=null,r}))})).catch((function(){return!1}))},e.exports.worker_offscreen_canvas_support=function(){return new Promise((function(t,e){if("undefined"!=typeof OffscreenCanvas){var r=btoa("(".concat(function(t){"undefined"!=typeof createImageBitmap?Promise.resolve().then((function(){var t=new OffscreenCanvas(10,10);return t.getContext("2d").rect(0,0,1,1),createImageBitmap(t,0,0,1,1)})).then((function(){return t.postMessage(!0)}),(function(){return t.postMessage(!1)})):t.postMessage(!1)}.toString(),")(self);")),i=new Worker("data:text/javascript;base64,".concat(r));i.onmessage=function(e){return t(e.data)},i.onerror=e}else t(!1)})).then((function(t){return t}),(function(){return!1}))},e.exports.can_use_canvas=function(t){var e=!1;try{var r=t(2,1).getContext("2d"),i=r.createImageData(2,1);i.data[0]=12,i.data[1]=23,i.data[2]=34,i.data[3]=255,i.data[4]=45,i.data[5]=56,i.data[6]=67,i.data[7]=255,r.putImageData(i,0,0),i=null,12===(i=r.getImageData(0,0,2,1)).data[0]&&23===i.data[1]&&34===i.data[2]&&255===i.data[3]&&45===i.data[4]&&56===i.data[5]&&67===i.data[6]&&255===i.data[7]&&(e=!0)}catch(t){}return e},e.exports.cib_can_use_region=function(){return new Promise((function(t){if("undefined"!=typeof createImageBitmap){var e=new Image;e.src="data:image/jpeg;base64,/9j/4QBiRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAYAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAAITAAMAAAABAAEAAAAAAAAAAABIAAAAAQAAAEgAAAAB/9sAQwAEAwMEAwMEBAMEBQQEBQYKBwYGBgYNCQoICg8NEBAPDQ8OERMYFBESFxIODxUcFRcZGRsbGxAUHR8dGh8YGhsa/9sAQwEEBQUGBQYMBwcMGhEPERoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoa/8IAEQgAAQACAwERAAIRAQMRAf/EABQAAQAAAAAAAAAAAAAAAAAAAAf/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIQAxAAAAF/P//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQH//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z",e.onload=function(){createImageBitmap(e,0,0,e.width,e.height).then((function(r){r.width===e.width&&r.height===e.height?t(!0):t(!1)}),(function(){return t(!1)}))},e.onerror=function(){return t(!1)}}else t(!1)}))}},{}],17:[function(t,e,r){"use strict";e.exports=function(){var e,r=t("./mathlib");onmessage=function(t){var i=t.data.opts;if(!i.src&&i.srcBitmap){var n=new OffscreenCanvas(i.width,i.height),A=n.getContext("2d",{alpha:Boolean(i.alpha)});A.drawImage(i.srcBitmap,0,0),i.src=A.getImageData(0,0,i.width,i.height).data,n.width=n.height=0,n=null,i.srcBitmap.close(),i.srcBitmap=null}e||(e=new r(t.data.features));var a=e.resizeAndUnsharp(i);postMessage({data:a},[a.buffer])}}},{"./mathlib":1}],18:[function(t,e,r){var i,n,A,a,o,s;function u(t,e,r,i,n,A){var a,o,s,u,h,c,f,l,g,d,p,m,I,w;for(g=0;g<A;g++){for(f=g,l=0,u=h=(a=t[c=g*n])*i[6],p=i[0],m=i[1],I=i[4],w=i[5],d=0;d<n;d++)s=(o=t[c])*p+a*m+u*I+h*w,h=u,u=s,a=o,r[l]=u,l++,c++;for(l--,f+=A*(n-1),u=h=(a=t[--c])*i[7],o=a,p=i[2],m=i[3],d=n-1;d>=0;d--)s=o*p+a*m+u*I+h*w,h=u,u=s,a=o,o=t[c],e[f]=r[l]+u,c--,l--,f-=A}}e.exports=function(t,e,r,h){if(h){var c=new Uint16Array(t.length),f=new Float32Array(Math.max(e,r)),l=function(t){t<.5&&(t=.5);var e=Math.exp(.527076)/t,r=Math.exp(-e),u=Math.exp(-2*e),h=(1-r)*(1-r)/(1+2*e*r-u);return i=h,n=h*(e-1)*r,A=h*(e+1)*r,a=-h*u,o=2*r,s=-u,new Float32Array([i,n,A,a,o,s,(i+n)/(1-o-s),(A+a)/(1-o-s)])}(h);u(t,c,f,l,e,r),u(c,t,f,l,r,e)}}},{}],19:[function(t,e,r){"function"==typeof Object.create?e.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}}},{}],20:[function(t,e,r){"use strict";var i=t("object-assign"),n=t("./lib/base64decode"),A=t("./lib/wa_detect"),a={js:!0,wasm:!0};function o(t){if(!(this instanceof o))return new o(t);var e=i({},a,t||{});if(this.options=e,this.__cache={},this.__init_promise=null,this.__modules=e.modules||{},this.__memory=null,this.__wasm={},this.__isLE=1===new Uint32Array(new Uint8Array([1,0,0,0]).buffer)[0],!this.options.js&&!this.options.wasm)throw new Error('mathlib: at least "js" or "wasm" should be enabled')}o.prototype.has_wasm=A,o.prototype.use=function(t){return this.__modules[t.name]=t,this.options.wasm&&this.has_wasm()&&t.wasm_fn?this[t.name]=t.wasm_fn:this[t.name]=t.fn,this},o.prototype.init=function(){if(this.__init_promise)return this.__init_promise;if(!this.options.js&&this.options.wasm&&!this.has_wasm())return Promise.reject(new Error('mathlib: only "wasm" was enabled, but it\'s not supported'));var t=this;return this.__init_promise=Promise.all(Object.keys(t.__modules).map((function(e){var r=t.__modules[e];return t.options.wasm&&t.has_wasm()&&r.wasm_fn?t.__wasm[e]?null:WebAssembly.compile(t.__base64decode(r.wasm_src)).then((function(r){t.__wasm[e]=r})):null}))).then((function(){return t})),this.__init_promise},o.prototype.__base64decode=n,o.prototype.__reallocate=function(t){if(!this.__memory)return this.__memory=new WebAssembly.Memory({initial:Math.ceil(t/65536)}),this.__memory;var e=this.__memory.buffer.byteLength;return e<t&&this.__memory.grow(Math.ceil((t-e)/65536)),this.__memory},o.prototype.__instance=function(t,e,r){if(e&&this.__reallocate(e),!this.__wasm[t]){var n=this.__modules[t];this.__wasm[t]=new WebAssembly.Module(this.__base64decode(n.wasm_src))}if(!this.__cache[t]){var A={memoryBase:0,memory:this.__memory,tableBase:0,table:new WebAssembly.Table({initial:0,element:"anyfunc"})};this.__cache[t]=new WebAssembly.Instance(this.__wasm[t],{env:i(A,r||{})})}return this.__cache[t]},o.prototype.__align=function(t,e){var r=t%(e=e||8);return t+(r?e-r:0)},e.exports=o},{"./lib/base64decode":21,"./lib/wa_detect":22,"object-assign":23}],21:[function(t,e,r){"use strict";e.exports=function(t){for(var e=t.replace(/[\r\n=]/g,""),r=e.length,i=new Uint8Array(3*r>>2),n=0,A=0,a=0;a<r;a++)a%4==0&&a&&(i[A++]=n>>16&255,i[A++]=n>>8&255,i[A++]=255&n),n=n<<6|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(e.charAt(a));var o=r%4*6;return 0===o?(i[A++]=n>>16&255,i[A++]=n>>8&255,i[A++]=255&n):18===o?(i[A++]=n>>10&255,i[A++]=n>>2&255):12===o&&(i[A++]=n>>4&255),i}},{}],22:[function(t,e,r){"use strict";var i;e.exports=function(){if(void 0!==i)return i;if(i=!1,"undefined"==typeof WebAssembly)return i;try{var t=new Uint8Array([0,97,115,109,1,0,0,0,1,6,1,96,1,127,1,127,3,2,1,0,5,3,1,0,1,7,8,1,4,116,101,115,116,0,0,10,16,1,14,0,32,0,65,1,54,2,0,32,0,40,2,0,11]),e=new WebAssembly.Module(t);return 0!==new WebAssembly.Instance(e,{}).exports.test(4)&&(i=!0),i}catch(t){}return i}},{}],23:[function(t,e,r){
7
+ !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).pica=t()}}((function(){return function t(e,r,i){function n(A,o){if(!r[A]){if(!e[A]){var s="function"==typeof require&&require;if(!o&&s)return s(A,!0);if(a)return a(A,!0);var u=new Error("Cannot find module '"+A+"'");throw u.code="MODULE_NOT_FOUND",u}var h=r[A]={exports:{}};e[A][0].call(h.exports,(function(t){return n(e[A][1][t]||t)}),h,h.exports,t,e,r,i)}return r[A].exports}for(var a="function"==typeof require&&require,A=0;A<i.length;A++)n(i[A]);return n}({1:[function(t,e,r){"use strict";var i=t("inherits"),n=t("multimath"),a=t("./mm_unsharp_mask"),A=t("./mm_resize");function o(t){var e=t||[],r={js:e.indexOf("js")>=0,wasm:e.indexOf("wasm")>=0};n.call(this,r),this.features={js:r.js,wasm:r.wasm&&this.has_wasm()},this.use(a),this.use(A)}i(o,n),o.prototype.resizeAndUnsharp=function(t,e){var r=this.resize(t,e);return t.unsharpAmount&&this.unsharp_mask(r,t.toWidth,t.toHeight,t.unsharpAmount,t.unsharpRadius,t.unsharpThreshold),r},e.exports=o},{"./mm_resize":4,"./mm_unsharp_mask":9,inherits:19,multimath:20}],2:[function(t,e,r){"use strict";function i(t){return t<0?0:t>255?255:t}e.exports={convolveHorizontally:function(t,e,r,n,a,A){var o,s,u,h,c,f,l,g,d,m,p,I=0,w=0;for(d=0;d<n;d++){for(c=0,m=0;m<a;m++){for(f=A[c++],l=A[c++],g=I+4*f|0,o=s=u=h=0;l>0;l--)h=h+(p=A[c++])*t[g+3]|0,u=u+p*t[g+2]|0,s=s+p*t[g+1]|0,o=o+p*t[g]|0,g=g+4|0;e[w+3]=i(h+8192>>14),e[w+2]=i(u+8192>>14),e[w+1]=i(s+8192>>14),e[w]=i(o+8192>>14),w=w+4*n|0}w=4*(d+1)|0,I=(d+1)*r*4|0}},convolveVertically:function(t,e,r,n,a,A){var o,s,u,h,c,f,l,g,d,m,p,I=0,w=0;for(d=0;d<n;d++){for(c=0,m=0;m<a;m++){for(f=A[c++],l=A[c++],g=I+4*f|0,o=s=u=h=0;l>0;l--)h=h+(p=A[c++])*t[g+3]|0,u=u+p*t[g+2]|0,s=s+p*t[g+1]|0,o=o+p*t[g]|0,g=g+4|0;e[w+3]=i(h+8192>>14),e[w+2]=i(u+8192>>14),e[w+1]=i(s+8192>>14),e[w]=i(o+8192>>14),w=w+4*n|0}w=4*(d+1)|0,I=(d+1)*r*4|0}}}},{}],3:[function(t,e,r){"use strict";e.exports="AGFzbQEAAAAADAZkeWxpbmsAAAAAAAEXA2AAAGAGf39/f39/AGAHf39/f39/fwACDwEDZW52Bm1lbW9yeQIAAAMEAwABAgYGAX8AQQALB1cFEV9fd2FzbV9jYWxsX2N0b3JzAAAIY29udm9sdmUAAQpjb252b2x2ZUhWAAIMX19kc29faGFuZGxlAwAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAK7AMDAwABC8YDAQ9/AkAgA0UNACAERQ0AA0AgDCENQQAhE0EAIQcDQCAHQQJqIQYCfyAHQQF0IAVqIgcuAQIiFEUEQEGAwAAhCEGAwAAhCUGAwAAhCkGAwAAhCyAGDAELIBIgBy4BAGohCEEAIQsgFCEHQQAhDiAGIQlBACEPQQAhEANAIAUgCUEBdGouAQAiESAAIAhBAnRqKAIAIgpBGHZsIBBqIRAgCkH/AXEgEWwgC2ohCyAKQRB2Qf8BcSARbCAPaiEPIApBCHZB/wFxIBFsIA5qIQ4gCEEBaiEIIAlBAWohCSAHQQFrIgcNAAsgC0GAQGshCCAOQYBAayEJIA9BgEBrIQogEEGAQGshCyAGIBRqCyEHIAEgDUECdGogCUEOdSIGQf8BIAZB/wFIGyIGQQAgBkEAShtBCHRBgP4DcSAKQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EQdEGAgPwHcSALQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EYdHJyIAhBDnUiBkH/ASAGQf8BSBsiBkEAIAZBAEobcjYCACADIA1qIQ0gE0EBaiITIARHDQALIAxBAWoiDCACbCESIAMgDEcNAAsLCx4AQQAgAiADIAQgBSAAEAEgAkEAIAQgBSAGIAEQAQs="},{}],4:[function(t,e,r){"use strict";e.exports={name:"resize",fn:t("./resize"),wasm_fn:t("./resize_wasm"),wasm_src:t("./convolve_wasm_base64")}},{"./convolve_wasm_base64":3,"./resize":5,"./resize_wasm":8}],5:[function(t,e,r){"use strict";var i=t("./resize_filter_gen"),n=t("./convolve").convolveHorizontally,a=t("./convolve").convolveVertically;e.exports=function(t){var e=t.src,r=t.width,A=t.height,o=t.toWidth,s=t.toHeight,u=t.scaleX||t.toWidth/t.width,h=t.scaleY||t.toHeight/t.height,c=t.offsetX||0,f=t.offsetY||0,l=t.dest||new Uint8Array(o*s*4),g=t.alpha||!1,d=void 0===t.filter?"mks2013":t.filter,m=i(d,r,o,u,c),p=i(d,A,s,h,f),I=new Uint8Array(o*A*4);return n(e,I,r,A,o,m),a(I,l,A,o,s,p),g||function(t,e,r){for(var i=3,n=e*r*4|0;i<n;)t[i]=255,i=i+4|0}(l,o,s),l}},{"./convolve":2,"./resize_filter_gen":6}],6:[function(t,e,r){"use strict";var i=t("./resize_filter_info");function n(t){return Math.round(16383*t)}e.exports=function(t,e,r,a,A){var o,s,u,h,c,f,l,g,d,m,p,I,w,_,B,b,y,v=i.filter[t].fn,Q=1/a,C=Math.min(1,a),E=i.filter[t].win/C,x=Math.floor(2*(E+1)),M=new Int16Array((x+2)*r),D=0,G=!M.subarray||!M.set;for(o=0;o<r;o++){for(s=(o+.5)*Q+A,u=Math.max(0,Math.floor(s-E)),c=(h=Math.min(e-1,Math.ceil(s+E)))-u+1,f=new Float32Array(c),l=new Int16Array(c),g=0,d=u,m=0;d<=h;d++,m++)g+=p=v((d+.5-s)*C),f[m]=p;for(I=0,m=0;m<f.length;m++)I+=w=f[m]/g,l[m]=n(w);for(l[r>>1]+=n(1-I),_=0;_<l.length&&0===l[_];)_++;if(_<l.length){for(B=l.length-1;B>0&&0===l[B];)B--;if(b=u+_,y=B-_+1,M[D++]=b,M[D++]=y,G)for(m=_;m<=B;m++)M[D++]=l[m];else M.set(l.subarray(_,B+1),D),D+=y}else M[D++]=0,M[D++]=0}return M}},{"./resize_filter_info":7}],7:[function(t,e,r){"use strict";var i={box:{win:.5,fn:function(t){return t<0&&(t=-t),t<.5?1:0}},hamming:{win:1,fn:function(t){if(t<0&&(t=-t),t>=1)return 0;if(t<1.1920929e-7)return 1;var e=t*Math.PI;return Math.sin(e)/e*(.54+.46*Math.cos(e/1))}},lanczos2:{win:2,fn:function(t){if(t<0&&(t=-t),t>=2)return 0;if(t<1.1920929e-7)return 1;var e=t*Math.PI;return Math.sin(e)/e*Math.sin(e/2)/(e/2)}},lanczos3:{win:3,fn:function(t){if(t<0&&(t=-t),t>=3)return 0;if(t<1.1920929e-7)return 1;var e=t*Math.PI;return Math.sin(e)/e*Math.sin(e/3)/(e/3)}},mks2013:{win:2.5,fn:function(t){return t<0&&(t=-t),t>=2.5?0:t>=1.5?-.125*(t-2.5)*(t-2.5):t>=.5?.25*(4*t*t-11*t+7):1.0625-1.75*t*t}}};e.exports={filter:i,f2q:{box:0,hamming:1,lanczos2:2,lanczos3:3},q2f:["box","hamming","lanczos2","lanczos3"]}},{}],8:[function(t,e,r){"use strict";var i=t("./resize_filter_gen");var n=!0;try{n=1===new Uint32Array(new Uint8Array([1,0,0,0]).buffer)[0]}catch(t){}function a(t,e,r){if(n)e.set(function(t){return new Uint8Array(t.buffer,0,t.byteLength)}(t),r);else for(var i=r,a=0;a<t.length;a++){var A=t[a];e[i++]=255&A,e[i++]=A>>8&255}}e.exports=function(t){var e=t.src,r=t.width,n=t.height,A=t.toWidth,o=t.toHeight,s=t.scaleX||t.toWidth/t.width,u=t.scaleY||t.toHeight/t.height,h=t.offsetX||0,c=t.offsetY||0,f=t.dest||new Uint8Array(A*o*4),l=t.alpha||!1,g=void 0===t.filter?"mks2013":t.filter,d=i(g,r,A,s,h),m=i(g,n,o,u,c),p=this.__align(0+Math.max(e.byteLength,f.byteLength)),I=this.__align(p+n*A*4),w=this.__align(I+d.byteLength),_=w+m.byteLength,B=this.__instance("resize",_),b=new Uint8Array(this.__memory.buffer),y=new Uint32Array(this.__memory.buffer),v=new Uint32Array(e.buffer);return y.set(v),a(d,b,I),a(m,b,w),(B.exports.convolveHV||B.exports._convolveHV)(I,w,p,r,n,A,o),new Uint32Array(f.buffer).set(new Uint32Array(this.__memory.buffer,0,o*A)),l||function(t,e,r){for(var i=3,n=e*r*4|0;i<n;)t[i]=255,i=i+4|0}(f,A,o),f}},{"./resize_filter_gen":6}],9:[function(t,e,r){"use strict";e.exports={name:"unsharp_mask",fn:t("./unsharp_mask"),wasm_fn:t("./unsharp_mask_wasm"),wasm_src:t("./unsharp_mask_wasm_base64")}},{"./unsharp_mask":10,"./unsharp_mask_wasm":11,"./unsharp_mask_wasm_base64":12}],10:[function(t,e,r){"use strict";var i=t("glur/mono16");e.exports=function(t,e,r,n,a,A){var o,s,u,h,c;if(!(0===n||a<.5)){a>2&&(a=2);var f=function(t,e,r){for(var i,n,a,A,o=e*r,s=new Uint16Array(o),u=0;u<o;u++)i=t[4*u],n=t[4*u+1],a=t[4*u+2],A=i>=n&&i>=a?i:n>=a&&n>=i?n:a,s[u]=A<<8;return s}(t,e,r),l=new Uint16Array(f);i(l,e,r,a);for(var g=n/100*4096+.5|0,d=A<<8,m=e*r,p=0;p<m;p++)h=(o=f[p])-l[p],Math.abs(h)>=d&&(u=((s=(s=(s=o+(g*h+2048>>12))>65280?65280:s)<0?0:s)<<12)/(o=0!==o?o:1)|0,t[c=4*p]=t[c]*u+2048>>12,t[c+1]=t[c+1]*u+2048>>12,t[c+2]=t[c+2]*u+2048>>12)}}},{"glur/mono16":18}],11:[function(t,e,r){"use strict";e.exports=function(t,e,r,i,n,a){if(!(0===i||n<.5)){n>2&&(n=2);var A=e*r,o=4*A,s=2*A,u=2*A,h=4*Math.max(e,r),c=o,f=c+s,l=f+u,g=l+u,d=g+h,m=this.__instance("unsharp_mask",o+s+2*u+h+32,{exp:Math.exp}),p=new Uint32Array(t.buffer);new Uint32Array(this.__memory.buffer).set(p);var I=m.exports.hsv_v16||m.exports._hsv_v16;I(0,c,e,r),(I=m.exports.blurMono16||m.exports._blurMono16)(c,f,l,g,d,e,r,n),(I=m.exports.unsharp||m.exports._unsharp)(0,0,c,f,e,r,i,a),p.set(new Uint32Array(this.__memory.buffer,0,A))}}},{}],12:[function(t,e,r){"use strict";e.exports="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"},{}],13:[function(t,e,r){"use strict";function i(t,e){this.create=t,this.available=[],this.acquired={},this.lastId=1,this.timeoutId=0,this.idle=e||2e3}i.prototype.acquire=function(){var t,e=this;return 0!==this.available.length?t=this.available.pop():((t=this.create()).id=this.lastId++,t.release=function(){return e.release(t)}),this.acquired[t.id]=t,t},i.prototype.release=function(t){var e=this;delete this.acquired[t.id],t.lastUsed=Date.now(),this.available.push(t),0===this.timeoutId&&(this.timeoutId=setTimeout((function(){return e.gc()}),100))},i.prototype.gc=function(){var t=this,e=Date.now();this.available=this.available.filter((function(r){return!(e-r.lastUsed>t.idle)||(r.destroy(),!1)})),0!==this.available.length?this.timeoutId=setTimeout((function(){return t.gc()}),100):this.timeoutId=0},e.exports=i},{}],14:[function(t,e,r){"use strict";e.exports=function(t,e,r,i,n,a){var A=r/t,o=i/e,s=(2*a+2+1)/n;if(s>.5)return[[r,i]];var u=Math.ceil(Math.log(Math.min(A,o))/Math.log(s));if(u<=1)return[[r,i]];for(var h=[],c=0;c<u;c++){var f=Math.round(Math.pow(Math.pow(t,u-c-1)*Math.pow(r,c+1),1/u)),l=Math.round(Math.pow(Math.pow(e,u-c-1)*Math.pow(i,c+1),1/u));h.push([f,l])}return h}},{}],15:[function(t,e,r){"use strict";var i=1e-5;function n(t){var e=Math.round(t);return Math.abs(t-e)<i?e:Math.floor(t)}function a(t){var e=Math.round(t);return Math.abs(t-e)<i?e:Math.ceil(t)}e.exports=function(t){var e,r,i,A,o,s,u=t.toWidth/t.width,h=t.toHeight/t.height,c=n(t.srcTileSize*u)-2*t.destTileBorder,f=n(t.srcTileSize*h)-2*t.destTileBorder;if(c<1||f<1)throw new Error("Internal error in pica: target tile width/height is too small.");var l,g=[];for(A=0;A<t.toHeight;A+=f)for(i=0;i<t.toWidth;i+=c)(e=i-t.destTileBorder)<0&&(e=0),e+(o=i+c+t.destTileBorder-e)>=t.toWidth&&(o=t.toWidth-e),(r=A-t.destTileBorder)<0&&(r=0),r+(s=A+f+t.destTileBorder-r)>=t.toHeight&&(s=t.toHeight-r),l={toX:e,toY:r,toWidth:o,toHeight:s,toInnerX:i,toInnerY:A,toInnerWidth:c,toInnerHeight:f,offsetX:e/u-n(e/u),offsetY:r/h-n(r/h),scaleX:u,scaleY:h,x:n(e/u),y:n(r/h),width:a(o/u),height:a(s/h)},g.push(l);return g}},{}],16:[function(t,e,r){"use strict";function i(t){return Object.prototype.toString.call(t)}e.exports.isCanvas=function(t){var e=i(t);return"[object HTMLCanvasElement]"===e||"[object OffscreenCanvas]"===e||"[object Canvas]"===e},e.exports.isImage=function(t){return"[object HTMLImageElement]"===i(t)},e.exports.isImageBitmap=function(t){return"[object ImageBitmap]"===i(t)},e.exports.limiter=function(t){var e=0,r=[];function i(){e<t&&r.length&&(e++,r.shift()())}return function(t){return new Promise((function(n,a){r.push((function(){t().then((function(t){n(t),e--,i()}),(function(t){a(t),e--,i()}))})),i()}))}},e.exports.cib_quality_name=function(t){switch(t){case 0:return"pixelated";case 1:return"low";case 2:return"medium"}return"high"},e.exports.cib_support=function(t){return Promise.resolve().then((function(){if("undefined"==typeof createImageBitmap)return!1;var e=t(100,100);return createImageBitmap(e,0,0,100,100,{resizeWidth:10,resizeHeight:10,resizeQuality:"high"}).then((function(t){var r=10===t.width;return t.close(),e=null,r}))})).catch((function(){return!1}))},e.exports.worker_offscreen_canvas_support=function(){return new Promise((function(t,e){if("undefined"!=typeof OffscreenCanvas){var r=btoa("(".concat(function(t){"undefined"!=typeof createImageBitmap?Promise.resolve().then((function(){var t=new OffscreenCanvas(10,10);return t.getContext("2d").rect(0,0,1,1),createImageBitmap(t,0,0,1,1)})).then((function(){return t.postMessage(!0)}),(function(){return t.postMessage(!1)})):t.postMessage(!1)}.toString(),")(self);")),i=new Worker("data:text/javascript;base64,".concat(r));i.onmessage=function(e){return t(e.data)},i.onerror=e}else t(!1)})).then((function(t){return t}),(function(){return!1}))},e.exports.can_use_canvas=function(t){var e=!1;try{var r=t(2,1).getContext("2d"),i=r.createImageData(2,1);i.data[0]=12,i.data[1]=23,i.data[2]=34,i.data[3]=255,i.data[4]=45,i.data[5]=56,i.data[6]=67,i.data[7]=255,r.putImageData(i,0,0),i=null,12===(i=r.getImageData(0,0,2,1)).data[0]&&23===i.data[1]&&34===i.data[2]&&255===i.data[3]&&45===i.data[4]&&56===i.data[5]&&67===i.data[6]&&255===i.data[7]&&(e=!0)}catch(t){}return e},e.exports.cib_can_use_region=function(){return new Promise((function(t){if("undefined"!=typeof createImageBitmap){var e=new Image;e.src="data:image/jpeg;base64,/9j/4QBiRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAYAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAAITAAMAAAABAAEAAAAAAAAAAABIAAAAAQAAAEgAAAAB/9sAQwAEAwMEAwMEBAMEBQQEBQYKBwYGBgYNCQoICg8NEBAPDQ8OERMYFBESFxIODxUcFRcZGRsbGxAUHR8dGh8YGhsa/9sAQwEEBQUGBQYMBwcMGhEPERoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoa/8IAEQgAAQACAwERAAIRAQMRAf/EABQAAQAAAAAAAAAAAAAAAAAAAAf/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIQAxAAAAF/P//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQH//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z",e.onload=function(){createImageBitmap(e,0,0,e.width,e.height).then((function(r){r.width===e.width&&r.height===e.height?t(!0):t(!1)}),(function(){return t(!1)}))},e.onerror=function(){return t(!1)}}else t(!1)}))}},{}],17:[function(t,e,r){"use strict";e.exports=function(){var e,r=t("./mathlib");onmessage=function(t){var i=t.data.opts;if(!i.src&&i.srcBitmap){var n=new OffscreenCanvas(i.width,i.height),a=n.getContext("2d",{alpha:Boolean(i.alpha)});a.drawImage(i.srcBitmap,0,0),i.src=a.getImageData(0,0,i.width,i.height).data,n.width=n.height=0,n=null,i.srcBitmap.close(),i.srcBitmap=null}e||(e=new r(t.data.features));var A=e.resizeAndUnsharp(i);postMessage({data:A},[A.buffer])}}},{"./mathlib":1}],18:[function(t,e,r){var i,n,a,A,o,s;function u(t,e,r,i,n,a){var A,o,s,u,h,c,f,l,g,d,m,p,I,w;for(g=0;g<a;g++){for(f=g,l=0,u=h=(A=t[c=g*n])*i[6],m=i[0],p=i[1],I=i[4],w=i[5],d=0;d<n;d++)s=(o=t[c])*m+A*p+u*I+h*w,h=u,u=s,A=o,r[l]=u,l++,c++;for(l--,f+=a*(n-1),u=h=(A=t[--c])*i[7],o=A,m=i[2],p=i[3],d=n-1;d>=0;d--)s=o*m+A*p+u*I+h*w,h=u,u=s,A=o,o=t[c],e[f]=r[l]+u,c--,l--,f-=a}}e.exports=function(t,e,r,h){if(h){var c=new Uint16Array(t.length),f=new Float32Array(Math.max(e,r)),l=function(t){t<.5&&(t=.5);var e=Math.exp(.527076)/t,r=Math.exp(-e),u=Math.exp(-2*e),h=(1-r)*(1-r)/(1+2*e*r-u);return i=h,n=h*(e-1)*r,a=h*(e+1)*r,A=-h*u,o=2*r,s=-u,new Float32Array([i,n,a,A,o,s,(i+n)/(1-o-s),(a+A)/(1-o-s)])}(h);u(t,c,f,l,e,r),u(c,t,f,l,r,e)}}},{}],19:[function(t,e,r){"function"==typeof Object.create?e.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}}},{}],20:[function(t,e,r){"use strict";var i=t("object-assign"),n=t("./lib/base64decode"),a=t("./lib/wa_detect"),A={js:!0,wasm:!0};function o(t){if(!(this instanceof o))return new o(t);var e=i({},A,t||{});if(this.options=e,this.__cache={},this.__init_promise=null,this.__modules=e.modules||{},this.__memory=null,this.__wasm={},this.__isLE=1===new Uint32Array(new Uint8Array([1,0,0,0]).buffer)[0],!this.options.js&&!this.options.wasm)throw new Error('mathlib: at least "js" or "wasm" should be enabled')}o.prototype.has_wasm=a,o.prototype.use=function(t){return this.__modules[t.name]=t,this.options.wasm&&this.has_wasm()&&t.wasm_fn?this[t.name]=t.wasm_fn:this[t.name]=t.fn,this},o.prototype.init=function(){if(this.__init_promise)return this.__init_promise;if(!this.options.js&&this.options.wasm&&!this.has_wasm())return Promise.reject(new Error('mathlib: only "wasm" was enabled, but it\'s not supported'));var t=this;return this.__init_promise=Promise.all(Object.keys(t.__modules).map((function(e){var r=t.__modules[e];return t.options.wasm&&t.has_wasm()&&r.wasm_fn?t.__wasm[e]?null:WebAssembly.compile(t.__base64decode(r.wasm_src)).then((function(r){t.__wasm[e]=r})):null}))).then((function(){return t})),this.__init_promise},o.prototype.__base64decode=n,o.prototype.__reallocate=function(t){if(!this.__memory)return this.__memory=new WebAssembly.Memory({initial:Math.ceil(t/65536)}),this.__memory;var e=this.__memory.buffer.byteLength;return e<t&&this.__memory.grow(Math.ceil((t-e)/65536)),this.__memory},o.prototype.__instance=function(t,e,r){if(e&&this.__reallocate(e),!this.__wasm[t]){var n=this.__modules[t];this.__wasm[t]=new WebAssembly.Module(this.__base64decode(n.wasm_src))}if(!this.__cache[t]){var a={memoryBase:0,memory:this.__memory,tableBase:0,table:new WebAssembly.Table({initial:0,element:"anyfunc"})};this.__cache[t]=new WebAssembly.Instance(this.__wasm[t],{env:i(a,r||{})})}return this.__cache[t]},o.prototype.__align=function(t,e){var r=t%(e=e||8);return t+(r?e-r:0)},e.exports=o},{"./lib/base64decode":21,"./lib/wa_detect":22,"object-assign":23}],21:[function(t,e,r){"use strict";e.exports=function(t){for(var e=t.replace(/[\r\n=]/g,""),r=e.length,i=new Uint8Array(3*r>>2),n=0,a=0,A=0;A<r;A++)A%4==0&&A&&(i[a++]=n>>16&255,i[a++]=n>>8&255,i[a++]=255&n),n=n<<6|"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(e.charAt(A));var o=r%4*6;return 0===o?(i[a++]=n>>16&255,i[a++]=n>>8&255,i[a++]=255&n):18===o?(i[a++]=n>>10&255,i[a++]=n>>2&255):12===o&&(i[a++]=n>>4&255),i}},{}],22:[function(t,e,r){"use strict";var i;e.exports=function(){if(void 0!==i)return i;if(i=!1,"undefined"==typeof WebAssembly)return i;try{var t=new Uint8Array([0,97,115,109,1,0,0,0,1,6,1,96,1,127,1,127,3,2,1,0,5,3,1,0,1,7,8,1,4,116,101,115,116,0,0,10,16,1,14,0,32,0,65,1,54,2,0,32,0,40,2,0,11]),e=new WebAssembly.Module(t);return 0!==new WebAssembly.Instance(e,{}).exports.test(4)&&(i=!0),i}catch(t){}return i}},{}],23:[function(t,e,r){
8
8
  /*
9
9
  object-assign
10
10
  (c) Sindre Sorhus
11
11
  @license MIT
12
12
  */
13
- "use strict";var i=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;function a(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}e.exports=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(e).map((function(t){return e[t]})).join(""))return!1;var i={};return"abcdefghijklmnopqrst".split("").forEach((function(t){i[t]=t})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},i)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var r,o,s=a(t),u=1;u<arguments.length;u++){for(var h in r=Object(arguments[u]))n.call(r,h)&&(s[h]=r[h]);if(i){o=i(r);for(var c=0;c<o.length;c++)A.call(r,o[c])&&(s[o[c]]=r[o[c]])}}return s}},{}],24:[function(t,e,r){var i=arguments[3],n=arguments[4],A=arguments[5],a=JSON.stringify;e.exports=function(t,e){for(var r,o=Object.keys(A),s=0,u=o.length;s<u;s++){var h=o[s],c=A[h].exports;if(c===t||c&&c.default===t){r=h;break}}if(!r){r=Math.floor(Math.pow(16,8)*Math.random()).toString(16);var f={};for(s=0,u=o.length;s<u;s++){f[h=o[s]]=h}n[r]=["function(require,module,exports){"+t+"(self); }",f]}var l=Math.floor(Math.pow(16,8)*Math.random()).toString(16),g={};g[r]=r,n[l]=["function(require,module,exports){var f = require("+a(r)+");(f.default ? f.default : f)(self);}",g];var d={};!function t(e){for(var r in d[e]=!0,n[e][1]){var i=n[e][1][r];d[i]||t(i)}}(l);var p="("+i+")({"+Object.keys(d).map((function(t){return a(t)+":["+n[t][0]+","+a(n[t][1])+"]"})).join(",")+"},{},["+a(l)+"])",m=window.URL||window.webkitURL||window.mozURL||window.msURL,I=new Blob([p],{type:"text/javascript"});if(e&&e.bare)return I;var w=m.createObjectURL(I),_=new Worker(w);return _.objectURL=w,_}},{}],"/index.js":[function(t,e,r){"use strict";function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==r)return;var i,n,A=[],a=!0,o=!1;try{for(r=r.call(t);!(a=(i=r.next()).done)&&(A.push(i.value),!e||A.length!==e);a=!0);}catch(t){o=!0,n=t}finally{try{a||null==r.return||r.return()}finally{if(o)throw n}}return A}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}var A=t("object-assign"),a=t("webworkify"),o=t("./lib/mathlib"),s=t("./lib/pool"),u=t("./lib/utils"),h=t("./lib/worker"),c=t("./lib/stepper"),f=t("./lib/tiler"),l={},g=!1;try{"undefined"!=typeof navigator&&navigator.userAgent&&(g=navigator.userAgent.indexOf("Safari")>=0)}catch(t){}var d=1;"undefined"!=typeof navigator&&(d=Math.min(navigator.hardwareConcurrency||1,4));var p={tile:1024,concurrency:d,features:["js","wasm","ww"],idle:2e3,createCanvas:function(t,e){var r=document.createElement("canvas");return r.width=t,r.height=e,r}},m={quality:3,alpha:!1,unsharpAmount:0,unsharpRadius:0,unsharpThreshold:0},I=!1,w=!1,_=!1,B=!1,b=!1;function y(){return{value:a(h),destroy:function(){if(this.value.terminate(),"undefined"!=typeof window){var t=window.URL||window.webkitURL||window.mozURL||window.msURL;t&&t.revokeObjectURL&&this.value.objectURL&&t.revokeObjectURL(this.value.objectURL)}}}}function v(t){if(!(this instanceof v))return new v(t);this.options=A({},p,t||{});var e="lk_".concat(this.options.concurrency);this.__limit=l[e]||u.limiter(this.options.concurrency),l[e]||(l[e]=this.__limit),this.features={js:!1,wasm:!1,cib:!1,ww:!1},this.__workersPool=null,this.__requested_features=[],this.__mathlib=null}v.prototype.init=function(){var e=this;if(this.__initPromise)return this.__initPromise;if("undefined"!=typeof ImageData&&"undefined"!=typeof Uint8ClampedArray)try{new ImageData(new Uint8ClampedArray(400),10,10),I=!0}catch(t){}"undefined"!=typeof ImageBitmap&&(ImageBitmap.prototype&&ImageBitmap.prototype.close?w=!0:this.debug("ImageBitmap does not support .close(), disabled"));var r=this.options.features.slice();if(r.indexOf("all")>=0&&(r=["cib","wasm","js","ww"]),this.__requested_features=r,this.__mathlib=new o(r),r.indexOf("ww")>=0&&"undefined"!=typeof window&&"Worker"in window)try{t("webworkify")((function(){})).terminate(),this.features.ww=!0;var i="wp_".concat(JSON.stringify(this.options));l[i]?this.__workersPool=l[i]:(this.__workersPool=new s(y,this.options.idle),l[i]=this.__workersPool)}catch(t){}var n,a,h=this.__mathlib.init().then((function(t){A(e.features,t.features)}));n=w?u.cib_support(this.options.createCanvas).then((function(t){e.features.cib&&r.indexOf("cib")<0?e.debug("createImageBitmap() resize supported, but disabled by config"):r.indexOf("cib")>=0&&(e.features.cib=t)})):Promise.resolve(!1),_=u.can_use_canvas(this.options.createCanvas),a=(a=w&&I&&-1!==r.indexOf("ww")?u.worker_offscreen_canvas_support():Promise.resolve(!1)).then((function(t){B=t}));var c=u.cib_can_use_region().then((function(t){b=t}));return this.__initPromise=Promise.all([h,n,a,c]).then((function(){return e})),this.__initPromise},v.prototype.__invokeResize=function(t,e){var r=this;return e.__mathCache=e.__mathCache||{},Promise.resolve().then((function(){return r.features.ww?new Promise((function(i,n){var A=r.__workersPool.acquire();e.cancelToken&&e.cancelToken.catch((function(t){return n(t)})),A.value.onmessage=function(t){A.release(),t.data.err?n(t.data.err):i(t.data)};var a=[];t.src&&a.push(t.src.buffer),t.srcBitmap&&a.push(t.srcBitmap),A.value.postMessage({opts:t,features:r.__requested_features,preload:{wasm_nodule:r.__mathlib.__}},a)})):{data:r.__mathlib.resizeAndUnsharp(t,e.__mathCache)}}))},v.prototype.__extractTileData=function(t,e,r,i,n){if(this.features.ww&&B&&(u.isCanvas(e)||b))return this.debug("Create tile for OffscreenCanvas"),createImageBitmap(i.srcImageBitmap||e,t.x,t.y,t.width,t.height).then((function(t){return n.srcBitmap=t,n}));if(u.isCanvas(e))return i.srcCtx||(i.srcCtx=e.getContext("2d",{alpha:Boolean(r.alpha)})),this.debug("Get tile pixel data"),n.src=i.srcCtx.getImageData(t.x,t.y,t.width,t.height).data,n;this.debug("Draw tile imageBitmap/image to temporary canvas");var A=this.options.createCanvas(t.width,t.height),a=A.getContext("2d",{alpha:Boolean(r.alpha)});return a.globalCompositeOperation="copy",a.drawImage(i.srcImageBitmap||e,t.x,t.y,t.width,t.height,0,0,t.width,t.height),this.debug("Get tile pixel data"),n.src=a.getImageData(0,0,t.width,t.height).data,A.width=A.height=0,n},v.prototype.__landTileData=function(t,e,r){var i;if(this.debug("Convert raw rgba tile result to ImageData"),e.bitmap)return r.toCtx.drawImage(e.bitmap,t.toX,t.toY),null;if(I)i=new ImageData(new Uint8ClampedArray(e.data),t.toWidth,t.toHeight);else if((i=r.toCtx.createImageData(t.toWidth,t.toHeight)).data.set)i.data.set(e.data);else for(var n=i.data.length-1;n>=0;n--)i.data[n]=e.data[n];return this.debug("Draw tile"),g?r.toCtx.putImageData(i,t.toX,t.toY,t.toInnerX-t.toX,t.toInnerY-t.toY,t.toInnerWidth+1e-5,t.toInnerHeight+1e-5):r.toCtx.putImageData(i,t.toX,t.toY,t.toInnerX-t.toX,t.toInnerY-t.toY,t.toInnerWidth,t.toInnerHeight),null},v.prototype.__tileAndResize=function(t,e,r){var i=this,n={srcCtx:null,srcImageBitmap:null,isImageBitmapReused:!1,toCtx:null};return Promise.resolve().then((function(){if(n.toCtx=e.getContext("2d",{alpha:Boolean(r.alpha)}),u.isCanvas(t))return null;if(u.isImageBitmap(t))return n.srcImageBitmap=t,n.isImageBitmapReused=!0,null;if(u.isImage(t))return w?(i.debug("Decode image via createImageBitmap"),createImageBitmap(t).then((function(t){n.srcImageBitmap=t})).catch((function(t){return null}))):null;throw new Error('Pica: ".from" should be Image, Canvas or ImageBitmap')})).then((function(){if(r.canceled)return r.cancelToken;i.debug("Calculate tiles");var A=f({width:r.width,height:r.height,srcTileSize:i.options.tile,toWidth:r.toWidth,toHeight:r.toHeight,destTileBorder:r.__destTileBorder}).map((function(e){return function(e){return i.__limit((function(){if(r.canceled)return r.cancelToken;var A={width:e.width,height:e.height,toWidth:e.toWidth,toHeight:e.toHeight,scaleX:e.scaleX,scaleY:e.scaleY,offsetX:e.offsetX,offsetY:e.offsetY,quality:r.quality,alpha:r.alpha,unsharpAmount:r.unsharpAmount,unsharpRadius:r.unsharpRadius,unsharpThreshold:r.unsharpThreshold};return i.debug("Invoke resize math"),Promise.resolve(A).then((function(A){return i.__extractTileData(e,t,r,n,A)})).then((function(t){return i.debug("Invoke resize math"),i.__invokeResize(t,r)})).then((function(t){return r.canceled?r.cancelToken:(n.srcImageData=null,i.__landTileData(e,t,n))}))}))}(e)}));function a(t){t.srcImageBitmap&&(t.isImageBitmapReused||t.srcImageBitmap.close(),t.srcImageBitmap=null)}return i.debug("Process tiles"),Promise.all(A).then((function(){return i.debug("Finished!"),a(n),e}),(function(t){throw a(n),t}))}))},v.prototype.__processStages=function(t,e,r,n){var a=this;if(n.canceled)return n.cancelToken;var o,s=i(t.shift(),2),u=s[0],h=s[1],c=0===t.length;return n=A({},n,{toWidth:u,toHeight:h,quality:c?n.quality:Math.min(1,n.quality)}),c||(o=this.options.createCanvas(u,h)),this.__tileAndResize(e,c?r:o,n).then((function(){return c?r:(n.width=u,n.height=h,a.__processStages(t,o,r,n))})).then((function(t){return o&&(o.width=o.height=0),t}))},v.prototype.__resizeViaCreateImageBitmap=function(t,e,r){var i=this,n=e.getContext("2d",{alpha:Boolean(r.alpha)});return this.debug("Resize via createImageBitmap()"),createImageBitmap(t,{resizeWidth:r.toWidth,resizeHeight:r.toHeight,resizeQuality:u.cib_quality_name(r.quality)}).then((function(t){if(r.canceled)return r.cancelToken;if(!r.unsharpAmount)return n.drawImage(t,0,0),t.close(),n=null,i.debug("Finished!"),e;i.debug("Unsharp result");var A=i.options.createCanvas(r.toWidth,r.toHeight),a=A.getContext("2d",{alpha:Boolean(r.alpha)});a.drawImage(t,0,0),t.close();var o=a.getImageData(0,0,r.toWidth,r.toHeight);return i.__mathlib.unsharp_mask(o.data,r.toWidth,r.toHeight,r.unsharpAmount,r.unsharpRadius,r.unsharpThreshold),n.putImageData(o,0,0),A.width=A.height=0,o=a=A=n=null,i.debug("Finished!"),e}))},v.prototype.resize=function(t,e,r){var i=this;this.debug("Start resize...");var n=A({},m);if(isNaN(r)?r&&(n=A(n,r)):n=A(n,{quality:r}),n.toWidth=e.width,n.toHeight=e.height,n.width=t.naturalWidth||t.width,n.height=t.naturalHeight||t.height,0===e.width||0===e.height)return Promise.reject(new Error("Invalid output size: ".concat(e.width,"x").concat(e.height)));n.unsharpRadius>2&&(n.unsharpRadius=2),n.canceled=!1,n.cancelToken&&(n.cancelToken=n.cancelToken.then((function(t){throw n.canceled=!0,t}),(function(t){throw n.canceled=!0,t})));return n.__destTileBorder=Math.ceil(Math.max(3,2.5*n.unsharpRadius|0)),this.init().then((function(){if(n.canceled)return n.cancelToken;if(i.features.cib)return i.__resizeViaCreateImageBitmap(t,e,n);if(!_){var r=new Error("Pica: cannot use getImageData on canvas, make sure fingerprinting protection isn't enabled");throw r.code="ERR_GET_IMAGE_DATA",r}var A=c(n.width,n.height,n.toWidth,n.toHeight,i.options.tile,n.__destTileBorder);return i.__processStages(A,t,e,n)}))},v.prototype.resizeBuffer=function(t){var e=this,r=A({},m,t);return this.init().then((function(){return e.__mathlib.resizeAndUnsharp(r)}))},v.prototype.toBlob=function(t,e,r){return e=e||"image/png",new Promise((function(i){if(t.toBlob)t.toBlob((function(t){return i(t)}),e,r);else if(t.convertToBlob)i(t.convertToBlob({type:e,quality:r}));else{for(var n=atob(t.toDataURL(e,r).split(",")[1]),A=n.length,a=new Uint8Array(A),o=0;o<A;o++)a[o]=n.charCodeAt(o);i(new Blob([a],{type:e}))}}))},v.prototype.debug=function(){},e.exports=v},{"./lib/mathlib":1,"./lib/pool":13,"./lib/stepper":14,"./lib/tiler":15,"./lib/utils":16,"./lib/worker":17,"object-assign":23,webworkify:24}]},{},[])("/index.js")}));
13
+ "use strict";var i=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;function A(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}e.exports=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},r=0;r<10;r++)e["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(e).map((function(t){return e[t]})).join(""))return!1;var i={};return"abcdefghijklmnopqrst".split("").forEach((function(t){i[t]=t})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},i)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var r,o,s=A(t),u=1;u<arguments.length;u++){for(var h in r=Object(arguments[u]))n.call(r,h)&&(s[h]=r[h]);if(i){o=i(r);for(var c=0;c<o.length;c++)a.call(r,o[c])&&(s[o[c]]=r[o[c]])}}return s}},{}],24:[function(t,e,r){var i=arguments[3],n=arguments[4],a=arguments[5],A=JSON.stringify;e.exports=function(t,e){for(var r,o=Object.keys(a),s=0,u=o.length;s<u;s++){var h=o[s],c=a[h].exports;if(c===t||c&&c.default===t){r=h;break}}if(!r){r=Math.floor(Math.pow(16,8)*Math.random()).toString(16);var f={};for(s=0,u=o.length;s<u;s++){f[h=o[s]]=h}n[r]=["function(require,module,exports){"+t+"(self); }",f]}var l=Math.floor(Math.pow(16,8)*Math.random()).toString(16),g={};g[r]=r,n[l]=["function(require,module,exports){var f = require("+A(r)+");(f.default ? f.default : f)(self);}",g];var d={};!function t(e){for(var r in d[e]=!0,n[e][1]){var i=n[e][1][r];d[i]||t(i)}}(l);var m="("+i+")({"+Object.keys(d).map((function(t){return A(t)+":["+n[t][0]+","+A(n[t][1])+"]"})).join(",")+"},{},["+A(l)+"])",p=window.URL||window.webkitURL||window.mozURL||window.msURL,I=new Blob([m],{type:"text/javascript"});if(e&&e.bare)return I;var w=p.createObjectURL(I),_=new Worker(w);return _.objectURL=w,_}},{}],"/index.js":[function(t,e,r){"use strict";function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==r)return;var i,n,a=[],A=!0,o=!1;try{for(r=r.call(t);!(A=(i=r.next()).done)&&(a.push(i.value),!e||a.length!==e);A=!0);}catch(t){o=!0,n=t}finally{try{A||null==r.return||r.return()}finally{if(o)throw n}}return a}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}var a=t("object-assign"),A=t("webworkify"),o=t("./lib/mathlib"),s=t("./lib/pool"),u=t("./lib/utils"),h=t("./lib/worker"),c=t("./lib/stepper"),f=t("./lib/tiler"),l=t("./lib/mm_resize/resize_filter_info"),g={},d=!1;try{"undefined"!=typeof navigator&&navigator.userAgent&&(d=navigator.userAgent.indexOf("Safari")>=0)}catch(t){}var m=1;"undefined"!=typeof navigator&&(m=Math.min(navigator.hardwareConcurrency||1,4));var p={tile:1024,concurrency:m,features:["js","wasm","ww"],idle:2e3,createCanvas:function(t,e){var r=document.createElement("canvas");return r.width=t,r.height=e,r}},I={filter:"mks2013",alpha:!1,unsharpAmount:0,unsharpRadius:0,unsharpThreshold:0},w=!1,_=!1,B=!1,b=!1,y=!1;function v(){return{value:A(h),destroy:function(){if(this.value.terminate(),"undefined"!=typeof window){var t=window.URL||window.webkitURL||window.mozURL||window.msURL;t&&t.revokeObjectURL&&this.value.objectURL&&t.revokeObjectURL(this.value.objectURL)}}}}function Q(t){if(!(this instanceof Q))return new Q(t);this.options=a({},p,t||{});var e="lk_".concat(this.options.concurrency);this.__limit=g[e]||u.limiter(this.options.concurrency),g[e]||(g[e]=this.__limit),this.features={js:!1,wasm:!1,cib:!1,ww:!1},this.__workersPool=null,this.__requested_features=[],this.__mathlib=null}Q.prototype.init=function(){var e=this;if(this.__initPromise)return this.__initPromise;if("undefined"!=typeof ImageData&&"undefined"!=typeof Uint8ClampedArray)try{new ImageData(new Uint8ClampedArray(400),10,10),w=!0}catch(t){}"undefined"!=typeof ImageBitmap&&(ImageBitmap.prototype&&ImageBitmap.prototype.close?_=!0:this.debug("ImageBitmap does not support .close(), disabled"));var r=this.options.features.slice();if(r.indexOf("all")>=0&&(r=["cib","wasm","js","ww"]),this.__requested_features=r,this.__mathlib=new o(r),r.indexOf("ww")>=0&&"undefined"!=typeof window&&"Worker"in window)try{t("webworkify")((function(){})).terminate(),this.features.ww=!0;var i="wp_".concat(JSON.stringify(this.options));g[i]?this.__workersPool=g[i]:(this.__workersPool=new s(v,this.options.idle),g[i]=this.__workersPool)}catch(t){}var n,A,h=this.__mathlib.init().then((function(t){a(e.features,t.features)}));n=_?u.cib_support(this.options.createCanvas).then((function(t){e.features.cib&&r.indexOf("cib")<0?e.debug("createImageBitmap() resize supported, but disabled by config"):r.indexOf("cib")>=0&&(e.features.cib=t)})):Promise.resolve(!1),B=u.can_use_canvas(this.options.createCanvas),A=(A=_&&w&&-1!==r.indexOf("ww")?u.worker_offscreen_canvas_support():Promise.resolve(!1)).then((function(t){b=t}));var c=u.cib_can_use_region().then((function(t){y=t}));return this.__initPromise=Promise.all([h,n,A,c]).then((function(){return e})),this.__initPromise},Q.prototype.__invokeResize=function(t,e){var r=this;return e.__mathCache=e.__mathCache||{},Promise.resolve().then((function(){return r.features.ww?new Promise((function(i,n){var a=r.__workersPool.acquire();e.cancelToken&&e.cancelToken.catch((function(t){return n(t)})),a.value.onmessage=function(t){a.release(),t.data.err?n(t.data.err):i(t.data)};var A=[];t.src&&A.push(t.src.buffer),t.srcBitmap&&A.push(t.srcBitmap),a.value.postMessage({opts:t,features:r.__requested_features,preload:{wasm_nodule:r.__mathlib.__}},A)})):{data:r.__mathlib.resizeAndUnsharp(t,e.__mathCache)}}))},Q.prototype.__extractTileData=function(t,e,r,i,n){if(this.features.ww&&b&&(u.isCanvas(e)||y))return this.debug("Create tile for OffscreenCanvas"),createImageBitmap(i.srcImageBitmap||e,t.x,t.y,t.width,t.height).then((function(t){return n.srcBitmap=t,n}));if(u.isCanvas(e))return i.srcCtx||(i.srcCtx=e.getContext("2d",{alpha:Boolean(r.alpha)})),this.debug("Get tile pixel data"),n.src=i.srcCtx.getImageData(t.x,t.y,t.width,t.height).data,n;this.debug("Draw tile imageBitmap/image to temporary canvas");var a=this.options.createCanvas(t.width,t.height),A=a.getContext("2d",{alpha:Boolean(r.alpha)});return A.globalCompositeOperation="copy",A.drawImage(i.srcImageBitmap||e,t.x,t.y,t.width,t.height,0,0,t.width,t.height),this.debug("Get tile pixel data"),n.src=A.getImageData(0,0,t.width,t.height).data,a.width=a.height=0,n},Q.prototype.__landTileData=function(t,e,r){var i;if(this.debug("Convert raw rgba tile result to ImageData"),e.bitmap)return r.toCtx.drawImage(e.bitmap,t.toX,t.toY),null;if(w)i=new ImageData(new Uint8ClampedArray(e.data),t.toWidth,t.toHeight);else if((i=r.toCtx.createImageData(t.toWidth,t.toHeight)).data.set)i.data.set(e.data);else for(var n=i.data.length-1;n>=0;n--)i.data[n]=e.data[n];return this.debug("Draw tile"),d?r.toCtx.putImageData(i,t.toX,t.toY,t.toInnerX-t.toX,t.toInnerY-t.toY,t.toInnerWidth+1e-5,t.toInnerHeight+1e-5):r.toCtx.putImageData(i,t.toX,t.toY,t.toInnerX-t.toX,t.toInnerY-t.toY,t.toInnerWidth,t.toInnerHeight),null},Q.prototype.__tileAndResize=function(t,e,r){var i=this,n={srcCtx:null,srcImageBitmap:null,isImageBitmapReused:!1,toCtx:null};return Promise.resolve().then((function(){if(n.toCtx=e.getContext("2d",{alpha:Boolean(r.alpha)}),u.isCanvas(t))return null;if(u.isImageBitmap(t))return n.srcImageBitmap=t,n.isImageBitmapReused=!0,null;if(u.isImage(t))return _?(i.debug("Decode image via createImageBitmap"),createImageBitmap(t).then((function(t){n.srcImageBitmap=t})).catch((function(t){return null}))):null;throw new Error('Pica: ".from" should be Image, Canvas or ImageBitmap')})).then((function(){if(r.canceled)return r.cancelToken;i.debug("Calculate tiles");var a=f({width:r.width,height:r.height,srcTileSize:i.options.tile,toWidth:r.toWidth,toHeight:r.toHeight,destTileBorder:r.__destTileBorder}).map((function(e){return function(e){return i.__limit((function(){if(r.canceled)return r.cancelToken;var a={width:e.width,height:e.height,toWidth:e.toWidth,toHeight:e.toHeight,scaleX:e.scaleX,scaleY:e.scaleY,offsetX:e.offsetX,offsetY:e.offsetY,filter:r.filter,alpha:r.alpha,unsharpAmount:r.unsharpAmount,unsharpRadius:r.unsharpRadius,unsharpThreshold:r.unsharpThreshold};return i.debug("Invoke resize math"),Promise.resolve(a).then((function(a){return i.__extractTileData(e,t,r,n,a)})).then((function(t){return i.debug("Invoke resize math"),i.__invokeResize(t,r)})).then((function(t){return r.canceled?r.cancelToken:(n.srcImageData=null,i.__landTileData(e,t,n))}))}))}(e)}));function A(t){t.srcImageBitmap&&(t.isImageBitmapReused||t.srcImageBitmap.close(),t.srcImageBitmap=null)}return i.debug("Process tiles"),Promise.all(a).then((function(){return i.debug("Finished!"),A(n),e}),(function(t){throw A(n),t}))}))},Q.prototype.__processStages=function(t,e,r,n){var A=this;if(n.canceled)return n.cancelToken;var o,s,u=i(t.shift(),2),h=u[0],c=u[1],f=0===t.length;return o=f||l.q2f.indexOf(n.filter)<0?n.filter:"box"===n.filter?"box":"hamming",n=a({},n,{toWidth:h,toHeight:c,filter:o}),f||(s=this.options.createCanvas(h,c)),this.__tileAndResize(e,f?r:s,n).then((function(){return f?r:(n.width=h,n.height=c,A.__processStages(t,s,r,n))})).then((function(t){return s&&(s.width=s.height=0),t}))},Q.prototype.__resizeViaCreateImageBitmap=function(t,e,r){var i=this,n=e.getContext("2d",{alpha:Boolean(r.alpha)});return this.debug("Resize via createImageBitmap()"),createImageBitmap(t,{resizeWidth:r.toWidth,resizeHeight:r.toHeight,resizeQuality:u.cib_quality_name(l.f2q[r.filter])}).then((function(t){if(r.canceled)return r.cancelToken;if(!r.unsharpAmount)return n.drawImage(t,0,0),t.close(),n=null,i.debug("Finished!"),e;i.debug("Unsharp result");var a=i.options.createCanvas(r.toWidth,r.toHeight),A=a.getContext("2d",{alpha:Boolean(r.alpha)});A.drawImage(t,0,0),t.close();var o=A.getImageData(0,0,r.toWidth,r.toHeight);return i.__mathlib.unsharp_mask(o.data,r.toWidth,r.toHeight,r.unsharpAmount,r.unsharpRadius,r.unsharpThreshold),n.putImageData(o,0,0),a.width=a.height=0,o=A=a=n=null,i.debug("Finished!"),e}))},Q.prototype.resize=function(t,e,r){var i=this;this.debug("Start resize...");var n=a({},I);if(isNaN(r)?r&&(n=a(n,r)):n=a(n,{quality:r}),n.toWidth=e.width,n.toHeight=e.height,n.width=t.naturalWidth||t.width,n.height=t.naturalHeight||t.height,Object.prototype.hasOwnProperty.call(n,"quality")){if(n.quality<0||n.quality>3)throw new Error("Pica: .quality should be [0..3], got ".concat(n.quality));n.filter=l.q2f[n.quality]}if(0===e.width||0===e.height)return Promise.reject(new Error("Invalid output size: ".concat(e.width,"x").concat(e.height)));n.unsharpRadius>2&&(n.unsharpRadius=2),n.canceled=!1,n.cancelToken&&(n.cancelToken=n.cancelToken.then((function(t){throw n.canceled=!0,t}),(function(t){throw n.canceled=!0,t})));return n.__destTileBorder=Math.ceil(Math.max(3,2.5*n.unsharpRadius|0)),this.init().then((function(){if(n.canceled)return n.cancelToken;if(i.features.cib){if(l.q2f.indexOf(n.filter)>=0)return i.__resizeViaCreateImageBitmap(t,e,n);i.debug("cib is enabled, but not supports provided filter, fallback to manual math")}if(!B){var r=new Error("Pica: cannot use getImageData on canvas, make sure fingerprinting protection isn't enabled");throw r.code="ERR_GET_IMAGE_DATA",r}var a=c(n.width,n.height,n.toWidth,n.toHeight,i.options.tile,n.__destTileBorder);return i.__processStages(a,t,e,n)}))},Q.prototype.resizeBuffer=function(t){var e=this,r=a({},I,t);if(Object.prototype.hasOwnProperty.call(r,"quality")){if(r.quality<0||r.quality>3)throw new Error("Pica: .quality should be [0..3], got ".concat(r.quality));r.filter=l.q2f[r.quality]}return this.init().then((function(){return e.__mathlib.resizeAndUnsharp(r)}))},Q.prototype.toBlob=function(t,e,r){return e=e||"image/png",new Promise((function(i){if(t.toBlob)t.toBlob((function(t){return i(t)}),e,r);else if(t.convertToBlob)i(t.convertToBlob({type:e,quality:r}));else{for(var n=atob(t.toDataURL(e,r).split(",")[1]),a=n.length,A=new Uint8Array(a),o=0;o<a;o++)A[o]=n.charCodeAt(o);i(new Blob([A],{type:e}))}}))},Q.prototype.debug=function(){},e.exports=Q},{"./lib/mathlib":1,"./lib/mm_resize/resize_filter_info":7,"./lib/pool":13,"./lib/stepper":14,"./lib/tiler":15,"./lib/utils":16,"./lib/worker":17,"object-assign":23,webworkify:24}]},{},[])("/index.js")}));
package/index.js CHANGED
@@ -11,6 +11,7 @@ const utils = require('./lib/utils');
11
11
  const worker = require('./lib/worker');
12
12
  const createStages = require('./lib/stepper');
13
13
  const createRegions = require('./lib/tiler');
14
+ const filter_info = require('./lib/mm_resize/resize_filter_info');
14
15
 
15
16
 
16
17
  // Deduplicate pools & limiters with the same configs
@@ -47,7 +48,7 @@ const DEFAULT_PICA_OPTS = {
47
48
 
48
49
 
49
50
  const DEFAULT_RESIZE_OPTS = {
50
- quality: 3,
51
+ filter: 'mks2013',
51
52
  alpha: false,
52
53
  unsharpAmount: 0,
53
54
  unsharpRadius: 0.0,
@@ -386,7 +387,7 @@ Pica.prototype.__tileAndResize = function (from, to, opts) {
386
387
  scaleY: tile.scaleY,
387
388
  offsetX: tile.offsetX,
388
389
  offsetY: tile.offsetY,
389
- quality: opts.quality,
390
+ filter: opts.filter,
390
391
  alpha: opts.alpha,
391
392
  unsharpAmount: opts.unsharpAmount,
392
393
  unsharpRadius: opts.unsharpRadius,
@@ -489,13 +490,23 @@ Pica.prototype.__processStages = function (stages, from, to, opts) {
489
490
 
490
491
  let isLastStage = (stages.length === 0);
491
492
 
493
+ // Optimization for legacy filters -
494
+ // only use user-defined quality for the last stage,
495
+ // use simpler (Hamming) filter for the first stages where
496
+ // scale factor is large enough (more than 2-3)
497
+ //
498
+ // For advanced filters (mks2013 and custom) - skip optimization,
499
+ // because need to apply sharpening every time
500
+ let filter;
501
+
502
+ if (isLastStage || filter_info.q2f.indexOf(opts.filter) < 0) filter = opts.filter;
503
+ else if (opts.filter === 'box') filter = 'box';
504
+ else filter = 'hamming';
505
+
492
506
  opts = assign({}, opts, {
493
507
  toWidth,
494
508
  toHeight,
495
- // only use user-defined quality for the last stage,
496
- // use simpler (Hamming) filter for the first stages where
497
- // scale factor is large enough (more than 2-3)
498
- quality: isLastStage ? opts.quality : Math.min(1, opts.quality)
509
+ filter
499
510
  });
500
511
 
501
512
  let tmpCanvas;
@@ -533,7 +544,7 @@ Pica.prototype.__resizeViaCreateImageBitmap = function (from, to, opts) {
533
544
  return createImageBitmap(from, {
534
545
  resizeWidth: opts.toWidth,
535
546
  resizeHeight: opts.toHeight,
536
- resizeQuality: utils.cib_quality_name(opts.quality)
547
+ resizeQuality: utils.cib_quality_name(filter_info.f2q[opts.filter])
537
548
  })
538
549
  .then(imageBitmap => {
539
550
  if (opts.canceled) return opts.cancelToken;
@@ -601,6 +612,14 @@ Pica.prototype.resize = function (from, to, options) {
601
612
  opts.width = from.naturalWidth || from.width;
602
613
  opts.height = from.naturalHeight || from.height;
603
614
 
615
+ // Legacy `.quality` option
616
+ if (Object.prototype.hasOwnProperty.call(opts, 'quality')) {
617
+ if (opts.quality < 0 || opts.quality > 3) {
618
+ throw new Error(`Pica: .quality should be [0..3], got ${opts.quality}`);
619
+ }
620
+ opts.filter = filter_info.q2f[opts.quality];
621
+ }
622
+
604
623
  // Prevent stepper from infinite loop
605
624
  if (to.width === 0 || to.height === 0) {
606
625
  return Promise.reject(new Error(`Invalid output size: ${to.width}x${to.height}`));
@@ -626,7 +645,11 @@ Pica.prototype.resize = function (from, to, options) {
626
645
 
627
646
  // if createImageBitmap supports resize, just do it and return
628
647
  if (this.features.cib) {
629
- return this.__resizeViaCreateImageBitmap(from, to, opts);
648
+ if (filter_info.q2f.indexOf(opts.filter) >= 0) {
649
+ return this.__resizeViaCreateImageBitmap(from, to, opts);
650
+ }
651
+
652
+ this.debug('cib is enabled, but not supports provided filter, fallback to manual math');
630
653
  }
631
654
 
632
655
  if (!CAN_USE_CANVAS_GET_IMAGE_DATA) {
@@ -658,6 +681,14 @@ Pica.prototype.resize = function (from, to, options) {
658
681
  Pica.prototype.resizeBuffer = function (options) {
659
682
  const opts = assign({}, DEFAULT_RESIZE_OPTS, options);
660
683
 
684
+ // Legacy `.quality` option
685
+ if (Object.prototype.hasOwnProperty.call(opts, 'quality')) {
686
+ if (opts.quality < 0 || opts.quality > 3) {
687
+ throw new Error(`Pica: .quality should be [0..3], got ${opts.quality}`);
688
+ }
689
+ opts.filter = filter_info.q2f[opts.quality];
690
+ }
691
+
661
692
  return this.init()
662
693
  .then(() => this.__mathlib.resizeAndUnsharp(opts));
663
694
  };
@@ -23,11 +23,11 @@ module.exports = function resize(options) {
23
23
  const offsetX = options.offsetX || 0;
24
24
  const offsetY = options.offsetY || 0;
25
25
  const dest = options.dest || new Uint8Array(destW * destH * 4);
26
- const quality = typeof options.quality === 'undefined' ? 3 : options.quality;
27
26
  const alpha = options.alpha || false;
28
27
 
29
- const filtersX = createFilters(quality, srcW, destW, scaleX, offsetX),
30
- filtersY = createFilters(quality, srcH, destH, scaleY, offsetY);
28
+ const filter = typeof options.filter === 'undefined' ? 'mks2013' : options.filter;
29
+ const filtersX = createFilters(filter, srcW, destW, scaleX, offsetX),
30
+ filtersY = createFilters(filter, srcH, destH, scaleY, offsetY);
31
31
 
32
32
  const tmp = new Uint8Array(destW * srcH * 4);
33
33
 
@@ -21,15 +21,15 @@ function toFixedPoint(num) {
21
21
  }
22
22
 
23
23
 
24
- module.exports = function resizeFilterGen(quality, srcSize, destSize, scale, offset) {
24
+ module.exports = function resizeFilterGen(filter, srcSize, destSize, scale, offset) {
25
25
 
26
- var filterFunction = FILTER_INFO[quality].filter;
26
+ var filterFunction = FILTER_INFO.filter[filter].fn;
27
27
 
28
28
  var scaleInverted = 1.0 / scale;
29
29
  var scaleClamped = Math.min(1.0, scale); // For upscale
30
30
 
31
31
  // Filter window (averaging interval), scaled to src image
32
- var srcWindow = FILTER_INFO[quality].win / scaleClamped;
32
+ var srcWindow = FILTER_INFO.filter[filter].win / scaleClamped;
33
33
 
34
34
  var destPixel, srcPixel, srcFirst, srcLast, filterElementSize,
35
35
  floatFilter, fxpFilter, total, pxl, idx, floatVal, filterTotal, filterVal;
@@ -6,38 +6,65 @@
6
6
  'use strict';
7
7
 
8
8
 
9
- module.exports = [
10
- { // Nearest neibor (Box)
9
+ const filter = {
10
+ // Nearest neibor
11
+ box: {
11
12
  win: 0.5,
12
- filter: function (x) {
13
- return (x >= -0.5 && x < 0.5) ? 1.0 : 0.0;
13
+ fn: function (x) {
14
+ if (x < 0) x = -x;
15
+ return (x < 0.5) ? 1.0 : 0.0;
14
16
  }
15
17
  },
16
- { // Hamming
18
+ // // Hamming
19
+ hamming: {
17
20
  win: 1.0,
18
- filter: function (x) {
19
- if (x <= -1.0 || x >= 1.0) { return 0.0; }
20
- if (x > -1.19209290E-07 && x < 1.19209290E-07) { return 1.0; }
21
+ fn: function (x) {
22
+ if (x < 0) x = -x;
23
+ if (x >= 1.0) { return 0.0; }
24
+ if (x < 1.19209290E-07) { return 1.0; }
21
25
  var xpi = x * Math.PI;
22
26
  return ((Math.sin(xpi) / xpi) * (0.54 + 0.46 * Math.cos(xpi / 1.0)));
23
27
  }
24
28
  },
25
- { // Lanczos, win = 2
29
+ // Lanczos, win = 2
30
+ lanczos2: {
26
31
  win: 2.0,
27
- filter: function (x) {
28
- if (x <= -2.0 || x >= 2.0) { return 0.0; }
29
- if (x > -1.19209290E-07 && x < 1.19209290E-07) { return 1.0; }
32
+ fn: function (x) {
33
+ if (x < 0) x = -x;
34
+ if (x >= 2.0) { return 0.0; }
35
+ if (x < 1.19209290E-07) { return 1.0; }
30
36
  var xpi = x * Math.PI;
31
37
  return (Math.sin(xpi) / xpi) * Math.sin(xpi / 2.0) / (xpi / 2.0);
32
38
  }
33
39
  },
34
- { // Lanczos, win = 3
40
+ // Lanczos, win = 3
41
+ lanczos3: {
35
42
  win: 3.0,
36
- filter: function (x) {
37
- if (x <= -3.0 || x >= 3.0) { return 0.0; }
38
- if (x > -1.19209290E-07 && x < 1.19209290E-07) { return 1.0; }
43
+ fn: function (x) {
44
+ if (x < 0) x = -x;
45
+ if (x >= 3.0) { return 0.0; }
46
+ if (x < 1.19209290E-07) { return 1.0; }
39
47
  var xpi = x * Math.PI;
40
48
  return (Math.sin(xpi) / xpi) * Math.sin(xpi / 3.0) / (xpi / 3.0);
41
49
  }
50
+ },
51
+ // Magic Kernel Sharp 2013, win = 2.5
52
+ // http://johncostella.com/magic/
53
+ mks2013: {
54
+ win: 2.5,
55
+ fn: function (x) {
56
+ if (x < 0) x = -x;
57
+ if (x >= 2.5) { return 0.0; }
58
+ if (x >= 1.5) { return -0.125 * (x - 2.5) * (x - 2.5); }
59
+ if (x >= 0.5) { return 0.25 * (4 * x * x - 11 * x + 7); }
60
+ return 1.0625 - 1.75 * x * x;
61
+ }
42
62
  }
43
- ];
63
+ };
64
+
65
+ module.exports = {
66
+ filter: filter,
67
+ // Legacy mapping
68
+ f2q: { box: 0, hamming: 1, lanczos2: 2, lanczos3: 3 },
69
+ q2f: [ 'box', 'hamming', 'lanczos2', 'lanczos3' ]
70
+ };
@@ -46,11 +46,11 @@ module.exports = function resize_wasm(options) {
46
46
  const offsetX = options.offsetX || 0.0;
47
47
  const offsetY = options.offsetY || 0.0;
48
48
  const dest = options.dest || new Uint8Array(destW * destH * 4);
49
- const quality = typeof options.quality === 'undefined' ? 3 : options.quality;
50
49
  const alpha = options.alpha || false;
51
50
 
52
- const filtersX = createFilters(quality, srcW, destW, scaleX, offsetX),
53
- filtersY = createFilters(quality, srcH, destH, scaleY, offsetY);
51
+ const filter = typeof options.filter === 'undefined' ? 'mks2013' : options.filter;
52
+ const filtersX = createFilters(filter, srcW, destW, scaleX, offsetX),
53
+ filtersY = createFilters(filter, srcH, destH, scaleY, offsetY);
54
54
 
55
55
  // destination is 0 too.
56
56
  const src_offset = 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pica",
3
3
  "description": "High quality image resize in browser.",
4
- "version": "7.1.1",
4
+ "version": "8.0.0",
5
5
  "keywords": [
6
6
  "resize",
7
7
  "scale",