@peakpay/excalidraw
Version:
Excalidraw as a React component
17 lines (15 loc) • 529 kB
JavaScript
/*
* ATTENTION: An "eval-source-map" devtool has been used.
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
(globalThis["webpackChunkExcalidrawLib"] = globalThis["webpackChunkExcalidrawLib"] || []).push([["vendor"],{
/***/ "../../../node_modules/pica/dist/pica.js":
/*!***********************************************!*\
!*** ../../../node_modules/pica/dist/pica.js ***!
\***********************************************/
/***/ ((module) => {
eval("/*!\n\npica\nhttps://github.com/nodeca/pica\n\n*/\n\n(function(f){if(true){module.exports=f()}else { var g; }})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=undefined;if(!f&&c)return require(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=undefined,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){\n// Collection of math functions\n//\n// 1. Combine components together\n// 2. Has async init to load wasm modules\n//\n'use strict';\n\nvar inherits = _dereq_('inherits');\n\nvar Multimath = _dereq_('multimath');\n\nvar mm_unsharp_mask = _dereq_('./mm_unsharp_mask');\n\nvar mm_resize = _dereq_('./mm_resize');\n\nfunction MathLib(requested_features) {\n var __requested_features = requested_features || [];\n\n var features = {\n js: __requested_features.indexOf('js') >= 0,\n wasm: __requested_features.indexOf('wasm') >= 0\n };\n Multimath.call(this, features);\n this.features = {\n js: features.js,\n wasm: features.wasm && this.has_wasm()\n };\n this.use(mm_unsharp_mask);\n this.use(mm_resize);\n}\n\ninherits(MathLib, Multimath);\n\nMathLib.prototype.resizeAndUnsharp = function resizeAndUnsharp(options, cache) {\n var result = this.resize(options, cache);\n\n if (options.unsharpAmount) {\n this.unsharp_mask(result, options.toWidth, options.toHeight, options.unsharpAmount, options.unsharpRadius, options.unsharpThreshold);\n }\n\n return result;\n};\n\nmodule.exports = MathLib;\n\n},{\"./mm_resize\":4,\"./mm_unsharp_mask\":9,\"inherits\":19,\"multimath\":20}],2:[function(_dereq_,module,exports){\n// Resize convolvers, pure JS implementation\n//\n'use strict'; // Precision of fixed FP values\n//var FIXED_FRAC_BITS = 14;\n\nfunction clampTo8(i) {\n return i < 0 ? 0 : i > 255 ? 255 : i;\n} // Convolve image in horizontal directions and transpose output. In theory,\n// transpose allow:\n//\n// - use the same convolver for both passes (this fails due different\n// types of input array and temporary buffer)\n// - making vertical pass by horisonltal lines inprove CPU cache use.\n//\n// But in real life this doesn't work :)\n//\n\n\nfunction convolveHorizontally(src, dest, srcW, srcH, destW, filters) {\n var r, g, b, a;\n var filterPtr, filterShift, filterSize;\n var srcPtr, srcY, destX, filterVal;\n var srcOffset = 0,\n destOffset = 0; // For each row\n\n for (srcY = 0; srcY < srcH; srcY++) {\n filterPtr = 0; // Apply precomputed filters to each destination row point\n\n for (destX = 0; destX < destW; destX++) {\n // Get the filter that determines the current output pixel.\n filterShift = filters[filterPtr++];\n filterSize = filters[filterPtr++];\n srcPtr = srcOffset + filterShift * 4 | 0;\n r = g = b = a = 0; // Apply the filter to the row to get the destination pixel r, g, b, a\n\n for (; filterSize > 0; filterSize--) {\n filterVal = filters[filterPtr++]; // Use reverse order to workaround deopts in old v8 (node v.10)\n // Big thanks to @mraleph (Vyacheslav Egorov) for the tip.\n\n a = a + filterVal * src[srcPtr + 3] | 0;\n b = b + filterVal * src[srcPtr + 2] | 0;\n g = g + filterVal * src[srcPtr + 1] | 0;\n r = r + filterVal * src[srcPtr] | 0;\n srcPtr = srcPtr + 4 | 0;\n } // Bring this value back in range. All of the filter scaling factors\n // are in fixed point with FIXED_FRAC_BITS bits of fractional part.\n //\n // (!) Add 1/2 of value before clamping to get proper rounding. In other\n // case brightness loss will be noticeable if you resize image with white\n // border and place it on white background.\n //\n\n\n dest[destOffset + 3] = clampTo8(a + (1 << 13) >> 14\n /*FIXED_FRAC_BITS*/\n );\n dest[destOffset + 2] = clampTo8(b + (1 << 13) >> 14\n /*FIXED_FRAC_BITS*/\n );\n dest[destOffset + 1] = clampTo8(g + (1 << 13) >> 14\n /*FIXED_FRAC_BITS*/\n );\n dest[destOffset] = clampTo8(r + (1 << 13) >> 14\n /*FIXED_FRAC_BITS*/\n );\n destOffset = destOffset + srcH * 4 | 0;\n }\n\n destOffset = (srcY + 1) * 4 | 0;\n srcOffset = (srcY + 1) * srcW * 4 | 0;\n }\n} // Technically, convolvers are the same. But input array and temporary\n// buffer can be of different type (especially, in old browsers). So,\n// keep code in separate functions to avoid deoptimizations & speed loss.\n\n\nfunction convolveVertically(src, dest, srcW, srcH, destW, filters) {\n var r, g, b, a;\n var filterPtr, filterShift, filterSize;\n var srcPtr, srcY, destX, filterVal;\n var srcOffset = 0,\n destOffset = 0; // For each row\n\n for (srcY = 0; srcY < srcH; srcY++) {\n filterPtr = 0; // Apply precomputed filters to each destination row point\n\n for (destX = 0; destX < destW; destX++) {\n // Get the filter that determines the current output pixel.\n filterShift = filters[filterPtr++];\n filterSize = filters[filterPtr++];\n srcPtr = srcOffset + filterShift * 4 | 0;\n r = g = b = a = 0; // Apply the filter to the row to get the destination pixel r, g, b, a\n\n for (; filterSize > 0; filterSize--) {\n filterVal = filters[filterPtr++]; // Use reverse order to workaround deopts in old v8 (node v.10)\n // Big thanks to @mraleph (Vyacheslav Egorov) for the tip.\n\n a = a + filterVal * src[srcPtr + 3] | 0;\n b = b + filterVal * src[srcPtr + 2] | 0;\n g = g + filterVal * src[srcPtr + 1] | 0;\n r = r + filterVal * src[srcPtr] | 0;\n srcPtr = srcPtr + 4 | 0;\n } // Bring this value back in range. All of the filter scaling factors\n // are in fixed point with FIXED_FRAC_BITS bits of fractional part.\n //\n // (!) Add 1/2 of value before clamping to get proper rounding. In other\n // case brightness loss will be noticeable if you resize image with white\n // border and place it on white background.\n //\n\n\n dest[destOffset + 3] = clampTo8(a + (1 << 13) >> 14\n /*FIXED_FRAC_BITS*/\n );\n dest[destOffset + 2] = clampTo8(b + (1 << 13) >> 14\n /*FIXED_FRAC_BITS*/\n );\n dest[destOffset + 1] = clampTo8(g + (1 << 13) >> 14\n /*FIXED_FRAC_BITS*/\n );\n dest[destOffset] = clampTo8(r + (1 << 13) >> 14\n /*FIXED_FRAC_BITS*/\n );\n destOffset = destOffset + srcH * 4 | 0;\n }\n\n destOffset = (srcY + 1) * 4 | 0;\n srcOffset = (srcY + 1) * srcW * 4 | 0;\n }\n}\n\nmodule.exports = {\n convolveHorizontally: convolveHorizontally,\n convolveVertically: convolveVertically\n};\n\n},{}],3:[function(_dereq_,module,exports){\n// This is autogenerated file from math.wasm, don't edit.\n//\n'use strict';\n/* eslint-disable max-len */\n\nmodule.exports = 'AGFzbQEAAAAADAZkeWxpbmsAAAAAAAEXA2AAAGAGf39/f39/AGAHf39/f39/fwACDwEDZW52Bm1lbW9yeQIAAAMEAwABAgYGAX8AQQALB1cFEV9fd2FzbV9jYWxsX2N0b3JzAAAIY29udm9sdmUAAQpjb252b2x2ZUhWAAIMX19kc29faGFuZGxlAwAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAK7AMDAwABC8YDAQ9/AkAgA0UNACAERQ0AA0AgDCENQQAhE0EAIQcDQCAHQQJqIQYCfyAHQQF0IAVqIgcuAQIiFEUEQEGAwAAhCEGAwAAhCUGAwAAhCkGAwAAhCyAGDAELIBIgBy4BAGohCEEAIQsgFCEHQQAhDiAGIQlBACEPQQAhEANAIAUgCUEBdGouAQAiESAAIAhBAnRqKAIAIgpBGHZsIBBqIRAgCkH/AXEgEWwgC2ohCyAKQRB2Qf8BcSARbCAPaiEPIApBCHZB/wFxIBFsIA5qIQ4gCEEBaiEIIAlBAWohCSAHQQFrIgcNAAsgC0GAQGshCCAOQYBAayEJIA9BgEBrIQogEEGAQGshCyAGIBRqCyEHIAEgDUECdGogCUEOdSIGQf8BIAZB/wFIGyIGQQAgBkEAShtBCHRBgP4DcSAKQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EQdEGAgPwHcSALQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EYdHJyIAhBDnUiBkH/ASAGQf8BSBsiBkEAIAZBAEobcjYCACADIA1qIQ0gE0EBaiITIARHDQALIAxBAWoiDCACbCESIAMgDEcNAAsLCx4AQQAgAiADIAQgBSAAEAEgAkEAIAQgBSAGIAEQAQs=';\n\n},{}],4:[function(_dereq_,module,exports){\n'use strict';\n\nmodule.exports = {\n name: 'resize',\n fn: _dereq_('./resize'),\n wasm_fn: _dereq_('./resize_wasm'),\n wasm_src: _dereq_('./convolve_wasm_base64')\n};\n\n},{\"./convolve_wasm_base64\":3,\"./resize\":5,\"./resize_wasm\":8}],5:[function(_dereq_,module,exports){\n'use strict';\n\nvar createFilters = _dereq_('./resize_filter_gen');\n\nvar convolveHorizontally = _dereq_('./convolve').convolveHorizontally;\n\nvar convolveVertically = _dereq_('./convolve').convolveVertically;\n\nfunction resetAlpha(dst, width, height) {\n var ptr = 3,\n len = width * height * 4 | 0;\n\n while (ptr < len) {\n dst[ptr] = 0xFF;\n ptr = ptr + 4 | 0;\n }\n}\n\nmodule.exports = function resize(options) {\n var src = options.src;\n var srcW = options.width;\n var srcH = options.height;\n var destW = options.toWidth;\n var destH = options.toHeight;\n var scaleX = options.scaleX || options.toWidth / options.width;\n var scaleY = options.scaleY || options.toHeight / options.height;\n var offsetX = options.offsetX || 0;\n var offsetY = options.offsetY || 0;\n var dest = options.dest || new Uint8Array(destW * destH * 4);\n var quality = typeof options.quality === 'undefined' ? 3 : options.quality;\n var alpha = options.alpha || false;\n var filtersX = createFilters(quality, srcW, destW, scaleX, offsetX),\n filtersY = createFilters(quality, srcH, destH, scaleY, offsetY);\n var tmp = new Uint8Array(destW * srcH * 4); // To use single function we need src & tmp of the same type.\n // But src can be CanvasPixelArray, and tmp - Uint8Array. So, keep\n // vertical and horizontal passes separately to avoid deoptimization.\n\n convolveHorizontally(src, tmp, srcW, srcH, destW, filtersX);\n convolveVertically(tmp, dest, srcH, destW, destH, filtersY); // That's faster than doing checks in convolver.\n // !!! Note, canvas data is not premultipled. We don't need other\n // alpha corrections.\n\n if (!alpha) resetAlpha(dest, destW, destH);\n return dest;\n};\n\n},{\"./convolve\":2,\"./resize_filter_gen\":6}],6:[function(_dereq_,module,exports){\n// Calculate convolution filters for each destination point,\n// and pack data to Int16Array:\n//\n// [ shift, length, data..., shift2, length2, data..., ... ]\n//\n// - shift - offset in src image\n// - length - filter length (in src points)\n// - data - filter values sequence\n//\n'use strict';\n\nvar FILTER_INFO = _dereq_('./resize_filter_info'); // Precision of fixed FP values\n\n\nvar FIXED_FRAC_BITS = 14;\n\nfunction toFixedPoint(num) {\n return Math.round(num * ((1 << FIXED_FRAC_BITS) - 1));\n}\n\nmodule.exports = function resizeFilterGen(quality, srcSize, destSize, scale, offset) {\n var filterFunction = FILTER_INFO[quality].filter;\n var scaleInverted = 1.0 / scale;\n var scaleClamped = Math.min(1.0, scale); // For upscale\n // Filter window (averaging interval), scaled to src image\n\n var srcWindow = FILTER_INFO[quality].win / scaleClamped;\n var destPixel, srcPixel, srcFirst, srcLast, filterElementSize, floatFilter, fxpFilter, total, pxl, idx, floatVal, filterTotal, filterVal;\n var leftNotEmpty, rightNotEmpty, filterShift, filterSize;\n var maxFilterElementSize = Math.floor((srcWindow + 1) * 2);\n var packedFilter = new Int16Array((maxFilterElementSize + 2) * destSize);\n var packedFilterPtr = 0;\n var slowCopy = !packedFilter.subarray || !packedFilter.set; // For each destination pixel calculate source range and built filter values\n\n for (destPixel = 0; destPixel < destSize; destPixel++) {\n // Scaling should be done relative to central pixel point\n srcPixel = (destPixel + 0.5) * scaleInverted + offset;\n srcFirst = Math.max(0, Math.floor(srcPixel - srcWindow));\n srcLast = Math.min(srcSize - 1, Math.ceil(srcPixel + srcWindow));\n filterElementSize = srcLast - srcFirst + 1;\n floatFilter = new Float32Array(filterElementSize);\n fxpFilter = new Int16Array(filterElementSize);\n total = 0.0; // Fill filter values for calculated range\n\n for (pxl = srcFirst, idx = 0; pxl <= srcLast; pxl++, idx++) {\n floatVal = filterFunction((pxl + 0.5 - srcPixel) * scaleClamped);\n total += floatVal;\n floatFilter[idx] = floatVal;\n } // Normalize filter, convert to fixed point and accumulate conversion error\n\n\n filterTotal = 0;\n\n for (idx = 0; idx < floatFilter.length; idx++) {\n filterVal = floatFilter[idx] / total;\n filterTotal += filterVal;\n fxpFilter[idx] = toFixedPoint(filterVal);\n } // Compensate normalization error, to minimize brightness drift\n\n\n fxpFilter[destSize >> 1] += toFixedPoint(1.0 - filterTotal); //\n // Now pack filter to useable form\n //\n // 1. Trim heading and tailing zero values, and compensate shitf/length\n // 2. Put all to single array in this format:\n //\n // [ pos shift, data length, value1, value2, value3, ... ]\n //\n\n leftNotEmpty = 0;\n\n while (leftNotEmpty < fxpFilter.length && fxpFilter[leftNotEmpty] === 0) {\n leftNotEmpty++;\n }\n\n if (leftNotEmpty < fxpFilter.length) {\n rightNotEmpty = fxpFilter.length - 1;\n\n while (rightNotEmpty > 0 && fxpFilter[rightNotEmpty] === 0) {\n rightNotEmpty--;\n }\n\n filterShift = srcFirst + leftNotEmpty;\n filterSize = rightNotEmpty - leftNotEmpty + 1;\n packedFilter[packedFilterPtr++] = filterShift; // shift\n\n packedFilter[packedFilterPtr++] = filterSize; // size\n\n if (!slowCopy) {\n packedFilter.set(fxpFilter.subarray(leftNotEmpty, rightNotEmpty + 1), packedFilterPtr);\n packedFilterPtr += filterSize;\n } else {\n // fallback for old IE < 11, without subarray/set methods\n for (idx = leftNotEmpty; idx <= rightNotEmpty; idx++) {\n packedFilter[packedFilterPtr++] = fxpFilter[idx];\n }\n }\n } else {\n // zero data, write header only\n packedFilter[packedFilterPtr++] = 0; // shift\n\n packedFilter[packedFilterPtr++] = 0; // size\n }\n }\n\n return packedFilter;\n};\n\n},{\"./resize_filter_info\":7}],7:[function(_dereq_,module,exports){\n// Filter definitions to build tables for\n// resizing convolvers.\n//\n// Presets for quality 0..3. Filter functions + window size\n//\n'use strict';\n\nmodule.exports = [{\n // Nearest neibor (Box)\n win: 0.5,\n filter: function filter(x) {\n return x >= -0.5 && x < 0.5 ? 1.0 : 0.0;\n }\n}, {\n // Hamming\n win: 1.0,\n filter: function filter(x) {\n if (x <= -1.0 || x >= 1.0) {\n return 0.0;\n }\n\n if (x > -1.19209290E-07 && x < 1.19209290E-07) {\n return 1.0;\n }\n\n var xpi = x * Math.PI;\n return Math.sin(xpi) / xpi * (0.54 + 0.46 * Math.cos(xpi / 1.0));\n }\n}, {\n // Lanczos, win = 2\n win: 2.0,\n filter: function filter(x) {\n if (x <= -2.0 || x >= 2.0) {\n return 0.0;\n }\n\n if (x > -1.19209290E-07 && x < 1.19209290E-07) {\n return 1.0;\n }\n\n var xpi = x * Math.PI;\n return Math.sin(xpi) / xpi * Math.sin(xpi / 2.0) / (xpi / 2.0);\n }\n}, {\n // Lanczos, win = 3\n win: 3.0,\n filter: function filter(x) {\n if (x <= -3.0 || x >= 3.0) {\n return 0.0;\n }\n\n if (x > -1.19209290E-07 && x < 1.19209290E-07) {\n return 1.0;\n }\n\n var xpi = x * Math.PI;\n return Math.sin(xpi) / xpi * Math.sin(xpi / 3.0) / (xpi / 3.0);\n }\n}];\n\n},{}],8:[function(_dereq_,module,exports){\n'use strict';\n\nvar createFilters = _dereq_('./resize_filter_gen');\n\nfunction resetAlpha(dst, width, height) {\n var ptr = 3,\n len = width * height * 4 | 0;\n\n while (ptr < len) {\n dst[ptr] = 0xFF;\n ptr = ptr + 4 | 0;\n }\n}\n\nfunction asUint8Array(src) {\n return new Uint8Array(src.buffer, 0, src.byteLength);\n}\n\nvar IS_LE = true; // should not crash everything on module load in old browsers\n\ntry {\n IS_LE = new Uint32Array(new Uint8Array([1, 0, 0, 0]).buffer)[0] === 1;\n} catch (__) {}\n\nfunction copyInt16asLE(src, target, target_offset) {\n if (IS_LE) {\n target.set(asUint8Array(src), target_offset);\n return;\n }\n\n for (var ptr = target_offset, i = 0; i < src.length; i++) {\n var data = src[i];\n target[ptr++] = data & 0xFF;\n target[ptr++] = data >> 8 & 0xFF;\n }\n}\n\nmodule.exports = function resize_wasm(options) {\n var src = options.src;\n var srcW = options.width;\n var srcH = options.height;\n var destW = options.toWidth;\n var destH = options.toHeight;\n var scaleX = options.scaleX || options.toWidth / options.width;\n var scaleY = options.scaleY || options.toHeight / options.height;\n var offsetX = options.offsetX || 0.0;\n var offsetY = options.offsetY || 0.0;\n var dest = options.dest || new Uint8Array(destW * destH * 4);\n var quality = typeof options.quality === 'undefined' ? 3 : options.quality;\n var alpha = options.alpha || false;\n var filtersX = createFilters(quality, srcW, destW, scaleX, offsetX),\n filtersY = createFilters(quality, srcH, destH, scaleY, offsetY); // destination is 0 too.\n\n var src_offset = 0; // buffer between convolve passes\n\n var tmp_offset = this.__align(src_offset + Math.max(src.byteLength, dest.byteLength));\n\n var filtersX_offset = this.__align(tmp_offset + srcH * destW * 4);\n\n var filtersY_offset = this.__align(filtersX_offset + filtersX.byteLength);\n\n var alloc_bytes = filtersY_offset + filtersY.byteLength;\n\n var instance = this.__instance('resize', alloc_bytes); //\n // Fill memory block with data to process\n //\n\n\n var mem = new Uint8Array(this.__memory.buffer);\n var mem32 = new Uint32Array(this.__memory.buffer); // 32-bit copy is much faster in chrome\n\n var src32 = new Uint32Array(src.buffer);\n mem32.set(src32); // We should guarantee LE bytes order. Filters are not big, so\n // speed difference is not significant vs direct .set()\n\n copyInt16asLE(filtersX, mem, filtersX_offset);\n copyInt16asLE(filtersY, mem, filtersY_offset); //\n // Now call webassembly method\n // emsdk does method names with '_'\n\n var fn = instance.exports.convolveHV || instance.exports._convolveHV;\n fn(filtersX_offset, filtersY_offset, tmp_offset, srcW, srcH, destW, destH); //\n // Copy data back to typed array\n //\n // 32-bit copy is much faster in chrome\n\n var dest32 = new Uint32Array(dest.buffer);\n dest32.set(new Uint32Array(this.__memory.buffer, 0, destH * destW)); // That's faster than doing checks in convolver.\n // !!! Note, canvas data is not premultipled. We don't need other\n // alpha corrections.\n\n if (!alpha) resetAlpha(dest, destW, destH);\n return dest;\n};\n\n},{\"./resize_filter_gen\":6}],9:[function(_dereq_,module,exports){\n'use strict';\n\nmodule.exports = {\n name: 'unsharp_mask',\n fn: _dereq_('./unsharp_mask'),\n wasm_fn: _dereq_('./unsharp_mask_wasm'),\n wasm_src: _dereq_('./unsharp_mask_wasm_base64')\n};\n\n},{\"./unsharp_mask\":10,\"./unsharp_mask_wasm\":11,\"./unsharp_mask_wasm_base64\":12}],10:[function(_dereq_,module,exports){\n// Unsharp mask filter\n//\n// http://stackoverflow.com/a/23322820/1031804\n// USM(O) = O + (2 * (Amount / 100) * (O - GB))\n// GB - gaussian blur.\n//\n// Image is converted from RGB to HSV, unsharp mask is applied to the\n// brightness channel and then image is converted back to RGB.\n//\n'use strict';\n\nvar glur_mono16 = _dereq_('glur/mono16');\n\nfunction hsv_v16(img, width, height) {\n var size = width * height;\n var out = new Uint16Array(size);\n var r, g, b, max;\n\n for (var i = 0; i < size; i++) {\n r = img[4 * i];\n g = img[4 * i + 1];\n b = img[4 * i + 2];\n max = r >= g && r >= b ? r : g >= b && g >= r ? g : b;\n out[i] = max << 8;\n }\n\n return out;\n}\n\nmodule.exports = function unsharp(img, width, height, amount, radius, threshold) {\n var v1, v2, vmul;\n var diff, iTimes4;\n\n if (amount === 0 || radius < 0.5) {\n return;\n }\n\n if (radius > 2.0) {\n radius = 2.0;\n }\n\n var brightness = hsv_v16(img, width, height);\n var blured = new Uint16Array(brightness); // copy, because blur modify src\n\n glur_mono16(blured, width, height, radius);\n var amountFp = amount / 100 * 0x1000 + 0.5 | 0;\n var thresholdFp = threshold << 8;\n var size = width * height;\n /* eslint-disable indent */\n\n for (var i = 0; i < size; i++) {\n v1 = brightness[i];\n diff = v1 - blured[i];\n\n if (Math.abs(diff) >= thresholdFp) {\n // add unsharp mask to the brightness channel\n v2 = v1 + (amountFp * diff + 0x800 >> 12); // Both v1 and v2 are within [0.0 .. 255.0] (0000-FF00) range, never going into\n // [255.003 .. 255.996] (FF01-FFFF). This allows to round this value as (x+.5)|0\n // later without overflowing.\n\n v2 = v2 > 0xff00 ? 0xff00 : v2;\n v2 = v2 < 0x0000 ? 0x0000 : v2; // Avoid division by 0. V=0 means rgb(0,0,0), unsharp with unsharpAmount>0 cannot\n // change this value (because diff between colors gets inflated), so no need to verify correctness.\n\n v1 = v1 !== 0 ? v1 : 1; // Multiplying V in HSV model by a constant is equivalent to multiplying each component\n // in RGB by the same constant (same for HSL), see also:\n // https://beesbuzz.biz/code/16-hsv-color-transforms\n\n vmul = (v2 << 12) / v1 | 0; // Result will be in [0..255] range because:\n // - all numbers are positive\n // - r,g,b <= (v1/256)\n // - r,g,b,(v1/256),(v2/256) <= 255\n // So highest this number can get is X*255/X+0.5=255.5 which is < 256 and rounds down.\n\n iTimes4 = i * 4;\n img[iTimes4] = img[iTimes4] * vmul + 0x800 >> 12; // R\n\n img[iTimes4 + 1] = img[iTimes4 + 1] * vmul + 0x800 >> 12; // G\n\n img[iTimes4 + 2] = img[iTimes4 + 2] * vmul + 0x800 >> 12; // B\n }\n }\n};\n\n},{\"glur/mono16\":18}],11:[function(_dereq_,module,exports){\n'use strict';\n\nmodule.exports = function unsharp(img, width, height, amount, radius, threshold) {\n if (amount === 0 || radius < 0.5) {\n return;\n }\n\n if (radius > 2.0) {\n radius = 2.0;\n }\n\n var pixels = width * height;\n var img_bytes_cnt = pixels * 4;\n var hsv_bytes_cnt = pixels * 2;\n var blur_bytes_cnt = pixels * 2;\n var blur_line_byte_cnt = Math.max(width, height) * 4; // float32 array\n\n var blur_coeffs_byte_cnt = 8 * 4; // float32 array\n\n var img_offset = 0;\n var hsv_offset = img_bytes_cnt;\n var blur_offset = hsv_offset + hsv_bytes_cnt;\n var blur_tmp_offset = blur_offset + blur_bytes_cnt;\n var blur_line_offset = blur_tmp_offset + blur_bytes_cnt;\n var blur_coeffs_offset = blur_line_offset + blur_line_byte_cnt;\n\n var instance = this.__instance('unsharp_mask', img_bytes_cnt + hsv_bytes_cnt + blur_bytes_cnt * 2 + blur_line_byte_cnt + blur_coeffs_byte_cnt, {\n exp: Math.exp\n }); // 32-bit copy is much faster in chrome\n\n\n var img32 = new Uint32Array(img.buffer);\n var mem32 = new Uint32Array(this.__memory.buffer);\n mem32.set(img32); // HSL\n\n var fn = instance.exports.hsv_v16 || instance.exports._hsv_v16;\n fn(img_offset, hsv_offset, width, height); // BLUR\n\n fn = instance.exports.blurMono16 || instance.exports._blurMono16;\n fn(hsv_offset, blur_offset, blur_tmp_offset, blur_line_offset, blur_coeffs_offset, width, height, radius); // UNSHARP\n\n fn = instance.exports.unsharp || instance.exports._unsharp;\n fn(img_offset, img_offset, hsv_offset, blur_offset, width, height, amount, threshold); // 32-bit copy is much faster in chrome\n\n img32.set(new Uint32Array(this.__memory.buffer, 0, pixels));\n};\n\n},{}],12:[function(_dereq_,module,exports){\n// This is autogenerated file from math.wasm, don't edit.\n//\n'use strict';\n/* eslint-disable max-len */\n\nmodule.exports = 'AGFzbQEAAAAADAZkeWxpbmsAAAAAAAE0B2AAAGAEf39/fwBgBn9/f39/fwBgCH9/f39/f39/AGAIf39/f39/f30AYAJ9fwBgAXwBfAIZAgNlbnYDZXhwAAYDZW52Bm1lbW9yeQIAAAMHBgAFAgQBAwYGAX8AQQALB4oBCBFfX3dhc21fY2FsbF9jdG9ycwABFl9fYnVpbGRfZ2F1c3NpYW5fY29lZnMAAg5fX2dhdXNzMTZfbGluZQADCmJsdXJNb25vMTYABAdoc3ZfdjE2AAUHdW5zaGFycAAGDF9fZHNvX2hhbmRsZQMAGF9fd2FzbV9hcHBseV9kYXRhX3JlbG9jcwABCsUMBgMAAQvWAQEHfCABRNuGukOCGvs/IAC7oyICRAAAAAAAAADAohAAIgW2jDgCFCABIAKaEAAiAyADoCIGtjgCECABRAAAAAAAAPA/IAOhIgQgBKIgAyACIAKgokQAAAAAAADwP6AgBaGjIgS2OAIAIAEgBSAEmqIiB7Y4AgwgASADIAJEAAAAAAAA8D+gIASioiIItjgCCCABIAMgAkQAAAAAAADwv6AgBKKiIgK2OAIEIAEgByAIoCAFRAAAAAAAAPA/IAahoCIDo7Y4AhwgASAEIAKgIAOjtjgCGAuGBQMGfwl8An0gAyoCDCEVIAMqAgghFiADKgIUuyERIAMqAhC7IRACQCAEQQFrIghBAEgiCQRAIAIhByAAIQYMAQsgAiAALwEAuCIPIAMqAhi7oiIMIBGiIg0gDCAQoiAPIAMqAgS7IhOiIhQgAyoCALsiEiAPoqCgoCIOtjgCACACQQRqIQcgAEECaiEGIAhFDQAgCEEBIAhBAUgbIgpBf3MhCwJ/IAQgCmtBAXFFBEAgDiENIAgMAQsgAiANIA4gEKIgFCASIAAvAQK4Ig+ioKCgIg22OAIEIAJBCGohByAAQQRqIQYgDiEMIARBAmsLIQIgC0EAIARrRg0AA0AgByAMIBGiIA0gEKIgDyAToiASIAYvAQC4Ig6ioKCgIgy2OAIAIAcgDSARoiAMIBCiIA4gE6IgEiAGLwECuCIPoqCgoCINtjgCBCAHQQhqIQcgBkEEaiEGIAJBAkohACACQQJrIQIgAA0ACwsCQCAJDQAgASAFIAhsQQF0aiIAAn8gBkECay8BACICuCINIBW7IhKiIA0gFrsiE6KgIA0gAyoCHLuiIgwgEKKgIAwgEaKgIg8gB0EEayIHKgIAu6AiDkQAAAAAAADwQWMgDkQAAAAAAAAAAGZxBEAgDqsMAQtBAAs7AQAgCEUNACAGQQRrIQZBACAFa0EBdCEBA0ACfyANIBKiIAJB//8DcbgiDSAToqAgDyIOIBCioCAMIBGioCIPIAdBBGsiByoCALugIgxEAAAAAAAA8EFjIAxEAAAAAAAAAABmcQRAIAyrDAELQQALIQMgBi8BACECIAAgAWoiACADOwEAIAZBAmshBiAIQQFKIQMgDiEMIAhBAWshCCADDQALCwvRAgIBfwd8AkAgB0MAAAAAWw0AIARE24a6Q4Ia+z8gB0MAAAA/l7ujIglEAAAAAAAAAMCiEAAiDLaMOAIUIAQgCZoQACIKIAqgIg22OAIQIAREAAAAAAAA8D8gCqEiCyALoiAKIAkgCaCiRAAAAAAAAPA/oCAMoaMiC7Y4AgAgBCAMIAuaoiIOtjgCDCAEIAogCUQAAAAAAADwP6AgC6KiIg+2OAIIIAQgCiAJRAAAAAAAAPC/oCALoqIiCbY4AgQgBCAOIA+gIAxEAAAAAAAA8D8gDaGgIgqjtjgCHCAEIAsgCaAgCqO2OAIYIAYEQANAIAAgBSAIbEEBdGogAiAIQQF0aiADIAQgBSAGEAMgCEEBaiIIIAZHDQALCyAFRQ0AQQAhCANAIAIgBiAIbEEBdGogASAIQQF0aiADIAQgBiAFEAMgCEEBaiIIIAVHDQALCwtxAQN/IAIgA2wiBQRAA0AgASAAKAIAIgRBEHZB/wFxIgIgAiAEQQh2Qf8BcSIDIAMgBEH/AXEiBEkbIAIgA0sbIgYgBiAEIAIgBEsbIAMgBEsbQQh0OwEAIAFBAmohASAAQQRqIQAgBUEBayIFDQALCwuZAgIDfwF8IAQgBWwhBAJ/IAazQwAAgEWUQwAAyEKVu0QAAAAAAADgP6AiC5lEAAAAAAAA4EFjBEAgC6oMAQtBgICAgHgLIQUgBARAIAdBCHQhCUEAIQYDQCAJIAIgBkEBdCIHai8BACIBIAMgB2ovAQBrIgcgB0EfdSIIaiAIc00EQCAAIAZBAnQiCGoiCiAFIAdsQYAQakEMdSABaiIHQYD+AyAHQYD+A0gbIgdBACAHQQBKG0EMdCABQQEgARtuIgEgCi0AAGxBgBBqQQx2OgAAIAAgCEEBcmoiByABIActAABsQYAQakEMdjoAACAAIAhBAnJqIgcgASAHLQAAbEGAEGpBDHY6AAALIAZBAWoiBiAERw0ACwsL';\n\n},{}],13:[function(_dereq_,module,exports){\n'use strict';\n\nvar GC_INTERVAL = 100;\n\nfunction Pool(create, idle) {\n this.create = create;\n this.available = [];\n this.acquired = {};\n this.lastId = 1;\n this.timeoutId = 0;\n this.idle = idle || 2000;\n}\n\nPool.prototype.acquire = function () {\n var _this = this;\n\n var resource;\n\n if (this.available.length !== 0) {\n resource = this.available.pop();\n } else {\n resource = this.create();\n resource.id = this.lastId++;\n\n resource.release = function () {\n return _this.release(resource);\n };\n }\n\n this.acquired[resource.id] = resource;\n return resource;\n};\n\nPool.prototype.release = function (resource) {\n var _this2 = this;\n\n delete this.acquired[resource.id];\n resource.lastUsed = Date.now();\n this.available.push(resource);\n\n if (this.timeoutId === 0) {\n this.timeoutId = setTimeout(function () {\n return _this2.gc();\n }, GC_INTERVAL);\n }\n};\n\nPool.prototype.gc = function () {\n var _this3 = this;\n\n var now = Date.now();\n this.available = this.available.filter(function (resource) {\n if (now - resource.lastUsed > _this3.idle) {\n resource.destroy();\n return false;\n }\n\n return true;\n });\n\n if (this.available.length !== 0) {\n this.timeoutId = setTimeout(function () {\n return _this3.gc();\n }, GC_INTERVAL);\n } else {\n this.timeoutId = 0;\n }\n};\n\nmodule.exports = Pool;\n\n},{}],14:[function(_dereq_,module,exports){\n// Add intermediate resizing steps when scaling down by a very large factor.\n//\n// For example, when resizing 10000x10000 down to 10x10, it'll resize it to\n// 300x300 first.\n//\n// It's needed because tiler has issues when the entire tile is scaled down\n// to a few pixels (1024px source tile with border size 3 should result in\n// at least 3+3+2 = 8px target tile, so max scale factor is 128 here).\n//\n// Also, adding intermediate steps can speed up processing if we use lower\n// quality algorithms for first stages.\n//\n'use strict'; // min size = 0 results in infinite loop,\n// min size = 1 can consume large amount of memory\n\nvar MIN_INNER_TILE_SIZE = 2;\n\nmodule.exports = function createStages(fromWidth, fromHeight, toWidth, toHeight, srcTileSize, destTileBorder) {\n var scaleX = toWidth / fromWidth;\n var scaleY = toHeight / fromHeight; // derived from createRegions equation:\n // innerTileWidth = pixelFloor(srcTileSize * scaleX) - 2 * destTileBorder;\n\n var minScale = (2 * destTileBorder + MIN_INNER_TILE_SIZE + 1) / srcTileSize; // refuse to scale image multiple times by less than twice each time,\n // it could only happen because of invalid options\n\n if (minScale > 0.5) return [[toWidth, toHeight]];\n var stageCount = Math.ceil(Math.log(Math.min(scaleX, scaleY)) / Math.log(minScale)); // no additional resizes are necessary,\n // stageCount can be zero or be negative when enlarging the image\n\n if (stageCount <= 1) return [[toWidth, toHeight]];\n var result = [];\n\n for (var i = 0; i < stageCount; i++) {\n var width = Math.round(Math.pow(Math.pow(fromWidth, stageCount - i - 1) * Math.pow(toWidth, i + 1), 1 / stageCount));\n var height = Math.round(Math.pow(Math.pow(fromHeight, stageCount - i - 1) * Math.pow(toHeight, i + 1), 1 / stageCount));\n result.push([width, height]);\n }\n\n return result;\n};\n\n},{}],15:[function(_dereq_,module,exports){\n// Split original image into multiple 1024x1024 chunks to reduce memory usage\n// (images have to be unpacked into typed arrays for resizing) and allow\n// parallel processing of multiple tiles at a time.\n//\n'use strict';\n/*\n * pixelFloor and pixelCeil are modified versions of Math.floor and Math.ceil\n * functions which take into account floating point arithmetic errors.\n * Those errors can cause undesired increments/decrements of sizes and offsets:\n * Math.ceil(36 / (36 / 500)) = 501\n * pixelCeil(36 / (36 / 500)) = 500\n */\n\nvar PIXEL_EPSILON = 1e-5;\n\nfunction pixelFloor(x) {\n var nearest = Math.round(x);\n\n if (Math.abs(x - nearest) < PIXEL_EPSILON) {\n return nearest;\n }\n\n return Math.floor(x);\n}\n\nfunction pixelCeil(x) {\n var nearest = Math.round(x);\n\n if (Math.abs(x - nearest) < PIXEL_EPSILON) {\n return nearest;\n }\n\n return Math.ceil(x);\n}\n\nmodule.exports = function createRegions(options) {\n var scaleX = options.toWidth / options.width;\n var scaleY = options.toHeight / options.height;\n var innerTileWidth = pixelFloor(options.srcTileSize * scaleX) - 2 * options.destTileBorder;\n var innerTileHeight = pixelFloor(options.srcTileSize * scaleY) - 2 * options.destTileBorder; // prevent infinite loop, this should never happen\n\n if (innerTileWidth < 1 || innerTileHeight < 1) {\n throw new Error('Internal error in pica: target tile width/height is too small.');\n }\n\n var x, y;\n var innerX, innerY, toTileWidth, toTileHeight;\n var tiles = [];\n var tile; // we go top-to-down instead of left-to-right to make image displayed from top to\n // doesn in the browser\n\n for (innerY = 0; innerY < options.toHeight; innerY += innerTileHeight) {\n for (innerX = 0; innerX < options.toWidth; innerX += innerTileWidth) {\n x = innerX - options.destTileBorder;\n\n if (x < 0) {\n x = 0;\n }\n\n toTileWidth = innerX + innerTileWidth + options.destTileBorder - x;\n\n if (x + toTileWidth >= options.toWidth) {\n toTileWidth = options.toWidth - x;\n }\n\n y = innerY - options.destTileBorder;\n\n if (y < 0) {\n y = 0;\n }\n\n toTileHeight = innerY + innerTileHeight + options.destTileBorder - y;\n\n if (y + toTileHeight >= options.toHeight) {\n toTileHeight = options.toHeight - y;\n }\n\n tile = {\n toX: x,\n toY: y,\n toWidth: toTileWidth,\n toHeight: toTileHeight,\n toInnerX: innerX,\n toInnerY: innerY,\n toInnerWidth: innerTileWidth,\n toInnerHeight: innerTileHeight,\n offsetX: x / scaleX - pixelFloor(x / scaleX),\n offsetY: y / scaleY - pixelFloor(y / scaleY),\n scaleX: scaleX,\n scaleY: scaleY,\n x: pixelFloor(x / scaleX),\n y: pixelFloor(y / scaleY),\n width: pixelCeil(toTileWidth / scaleX),\n height: pixelCeil(toTileHeight / scaleY)\n };\n tiles.push(tile);\n }\n }\n\n return tiles;\n};\n\n},{}],16:[function(_dereq_,module,exports){\n'use strict';\n\nfunction objClass(obj) {\n return Object.prototype.toString.call(obj);\n}\n\nmodule.exports.isCanvas = function isCanvas(element) {\n var cname = objClass(element);\n return cname === '[object HTMLCanvasElement]'\n /* browser */\n || cname === '[object OffscreenCanvas]' || cname === '[object Canvas]'\n /* node-canvas */\n ;\n};\n\nmodule.exports.isImage = function isImage(element) {\n return objClass(element) === '[object HTMLImageElement]';\n};\n\nmodule.exports.isImageBitmap = function isImageBitmap(element) {\n return objClass(element) === '[object ImageBitmap]';\n};\n\nmodule.exports.limiter = function limiter(concurrency) {\n var active = 0,\n queue = [];\n\n function roll() {\n if (active < concurrency && queue.length) {\n active++;\n queue.shift()();\n }\n }\n\n return function limit(fn) {\n return new Promise(function (resolve, reject) {\n queue.push(function () {\n fn().then(function (result) {\n resolve(result);\n active--;\n roll();\n }, function (err) {\n reject(err);\n active--;\n roll();\n });\n });\n roll();\n });\n };\n};\n\nmodule.exports.cib_quality_name = function cib_quality_name(num) {\n switch (num) {\n case 0:\n return 'pixelated';\n\n case 1:\n return 'low';\n\n case 2:\n return 'medium';\n }\n\n return 'high';\n};\n\nmodule.exports.cib_support = function cib_support(createCanvas) {\n return Promise.resolve().then(function () {\n if (typeof createImageBitmap === 'undefined') {\n return false;\n }\n\n var c = createCanvas(100, 100);\n return createImageBitmap(c, 0, 0, 100, 100, {\n resizeWidth: 10,\n resizeHeight: 10,\n resizeQuality: 'high'\n }).then(function (bitmap) {\n var status = bitmap.width === 10; // Branch below is filtered on upper level. We do not call resize\n // detection for basic ImageBitmap.\n //\n // https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap\n // old Crome 51 has ImageBitmap without .close(). Then this code\n // will throw and return 'false' as expected.\n //\n\n bitmap.close();\n c = null;\n return status;\n });\n })[\"catch\"](function () {\n return false;\n });\n};\n\nmodule.exports.worker_offscreen_canvas_support = function worker_offscreen_canvas_support() {\n return new Promise(function (resolve, reject) {\n if (typeof OffscreenCanvas === 'undefined') {\n // if OffscreenCanvas is present, we assume browser supports Worker and built-in Promise as well\n resolve(false);\n return;\n }\n\n function workerPayload(self) {\n if (typeof createImageBitmap === 'undefined') {\n self.postMessage(false);\n return;\n }\n\n Promise.resolve().then(function () {\n var canvas = new OffscreenCanvas(10, 10); // test that 2d context can be used in worker\n\n var ctx = canvas.getContext('2d');\n ctx.rect(0, 0, 1, 1); // test that cib can be used to return image bitmap from worker\n\n return createImageBitmap(canvas, 0, 0, 1, 1);\n }).then(function () {\n return self.postMessage(true);\n }, function () {\n return self.postMessage(false);\n });\n }\n\n var code = btoa(\"(\".concat(workerPayload.toString(), \")(self);\"));\n var w = new Worker(\"data:text/javascript;base64,\".concat(code));\n\n w.onmessage = function (ev) {\n return resolve(ev.data);\n };\n\n w.onerror = reject;\n }).then(function (result) {\n return result;\n }, function () {\n return false;\n });\n}; // Check if canvas.getContext('2d').getImageData can be used,\n// FireFox randomizes the output of that function in `privacy.resistFingerprinting` mode\n\n\nmodule.exports.can_use_canvas = function can_use_canvas(createCanvas) {\n var usable = false;\n\n try {\n var canvas = createCanvas(2, 1);\n var ctx = canvas.getContext('2d');\n var d = ctx.createImageData(2, 1);\n d.data[0] = 12;\n d.data[1] = 23;\n d.data[2] = 34;\n d.data[3] = 255;\n d.data[4] = 45;\n d.data[5] = 56;\n d.data[6] = 67;\n d.data[7] = 255;\n ctx.putImageData(d, 0, 0);\n d = null;\n d = ctx.getImageData(0, 0, 2, 1);\n\n if (d.data[0] === 12 && d.data[1] === 23 && d.data[2] === 34 && d.data[3] === 255 && d.data[4] === 45 && d.data[5] === 56 && d.data[6] === 67 && d.data[7] === 255) {\n usable = true;\n }\n } catch (err) {}\n\n return usable;\n}; // Check if createImageBitmap(img, sx, sy, sw, sh) signature works correctly\n// with JPEG images oriented with Exif;\n// https://bugs.chromium.org/p/chromium/issues/detail?id=1220671\n// TODO: remove after it's fixed in chrome for at least 2 releases\n\n\nmodule.exports.cib_can_use_region = function cib_can_use_region() {\n return new Promise(function (resolve) {\n if (typeof createImageBitmap === 'undefined') {\n resolve(false);\n return;\n }\n\n var image = new Image();\n image.src = 'data:image/jpeg;base64,' + '/9j/4QBiRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAYAAAEaAAUAAAABAAAASgEbAAUAA' + 'AABAAAAUgEoAAMAAAABAAIAAAITAAMAAAABAAEAAAAAAAAAAABIAAAAAQAAAEgAAAAB/9' + 'sAQwAEAwMEAwMEBAMEBQQEBQYKBwYGBgYNCQoICg8NEBAPDQ8OERMYFBESFxIODxUcFRc' + 'ZGRsbGxAUHR8dGh8YGhsa/9sAQwEEBQUGBQYMBwcMGhEPERoaGhoaGhoaGhoaGhoaGhoa' + 'GhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoa/8IAEQgAAQACAwERAAIRAQMRA' + 'f/EABQAAQAAAAAAAAAAAAAAAAAAAAf/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAA' + 'IQAxAAAAF/P//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAA' + 'AAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIB' + 'AT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAA' + 'AAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQH//EABQRAQAAAAAAAAAAAAAAAA' + 'AAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQ' + 'QAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z';\n\n image.onload = function () {\n createImageBitmap(image, 0, 0, image.width, image.height).then(function (bitmap) {\n if (bitmap.width === image.width && bitmap.height === image.height) {\n resolve(true);\n } else {\n resolve(false);\n }\n }, function () {\n return resolve(false);\n });\n };\n\n image.onerror = function () {\n return resolve(false);\n };\n });\n};\n\n},{}],17:[function(_dereq_,module,exports){\n// Web Worker wrapper for image resize function\n'use strict';\n\nmodule.exports = function () {\n var MathLib = _dereq_('./mathlib');\n\n var mathLib;\n /* eslint-disable no-undef */\n\n onmessage = function onmessage(ev) {\n var tileOpts = ev.data.opts;\n var returnBitmap = false;\n\n if (!tileOpts.src && tileOpts.srcBitmap) {\n var canvas = new OffscreenCanvas(tileOpts.width, tileOpts.height);\n var ctx = canvas.getContext('2d', {\n alpha: Boolean(tileOpts.alpha)\n });\n ctx.drawImage(tileOpts.srcBitmap, 0, 0);\n tileOpts.src = ctx.getImageData(0, 0, tileOpts.width, tileOpts.height).data;\n canvas.width = canvas.height = 0;\n canvas = null;\n tileOpts.srcBitmap.close();\n tileOpts.srcBitmap = null; // Temporary force out data to typed array, because Chrome have artefacts\n // https://github.com/nodeca/pica/issues/223\n // returnBitmap = true;\n }\n\n if (!mathLib) mathLib = new MathLib(ev.data.features); // Use multimath's sync auto-init. Avoid Promise use in old browsers,\n // because polyfills are not propagated to webworker.\n\n var data = mathLib.resizeAndUnsharp(tileOpts);\n\n if (returnBitmap) {\n var toImageData = new ImageData(new Uint8ClampedArray(data), tileOpts.toWidth, tileOpts.toHeight);\n\n var _canvas = new OffscreenCanvas(tileOpts.toWidth, tileOpts.toHeight);\n\n var _ctx = _canvas.getContext('2d', {\n alpha: Boolean(tileOpts.alpha)\n });\n\n _ctx.putImageData(toImageData, 0, 0);\n\n createImageBitmap(_canvas).then(function (bitmap) {\n postMessage({\n bitmap: bitmap\n }, [bitmap]);\n });\n } else {\n postMessage({\n data: data\n }, [data.buffer]);\n }\n };\n};\n\n},{\"./mathlib\":1}],18:[function(_dereq_,module,exports){\n// Calculate Gaussian blur of an image using IIR filter\n// The method is taken from Intel's white paper and code example attached to it:\n// https://software.intel.com/en-us/articles/iir-gaussian-blur-filter\n// -implementation-using-intel-advanced-vector-extensions\n\nvar a0, a1, a2, a3, b1, b2, left_corner, right_corner;\n\nfunction gaussCoef(sigma) {\n if (sigma < 0.5) {\n sigma = 0.5;\n }\n\n var a = Math.exp(0.726 * 0.726) / sigma,\n g1 = Math.exp(-a),\n g2 = Math.exp(-2 * a),\n k = (1 - g1) * (1 - g1) / (1 + 2 * a * g1 - g2);\n\n a0 = k;\n a1 = k * (a - 1) * g1;\n a2 = k * (a + 1) * g1;\n a3 = -k * g2;\n b1 = 2 * g1;\n b2 = -g2;\n left_corner = (a0 + a1) / (1 - b1 - b2);\n right_corner = (a2 + a3) / (1 - b1 - b2);\n\n // Attempt to force type to FP32.\n return new Float32Array([ a0, a1, a2, a3, b1, b2, left_corner, right_corner ]);\n}\n\nfunction convolveMono16(src, out, line, coeff, width, height) {\n // takes src image and writes the blurred and transposed result into out\n\n var prev_src, curr_src, curr_out, prev_out, prev_prev_out;\n var src_index, out_index, line_index;\n var i, j;\n var coeff_a0, coeff_a1, coeff_b1, coeff_b2;\n\n for (i = 0; i < height; i++) {\n src_index = i * width;\n out_index = i;\n line_index = 0;\n\n // left to right\n prev_src = src[src_index];\n prev_prev_out = prev_src * coeff[6];\n prev_out = prev_prev_out;\n\n coeff_a0 = coeff[0];\n coeff_a1 = coeff[1];\n coeff_b1 = coeff[4];\n coeff_b2 = coeff[5];\n\n for (j = 0; j < width; j++) {\n curr_src = src[src_index];\n\n curr_out = curr_src * coeff_a0 +\n prev_src * coeff_a1 +\n prev_out * coeff_b1 +\n prev_prev_out * coeff_b2;\n\n prev_prev_out = prev_out;\n prev_out = curr_out;\n prev_src = curr_src;\n\n line[line_index] = prev_out;\n line_index++;\n src_index++;\n }\n\n src_index--;\n line_index--;\n out_index += height * (width - 1);\n\n // right to left\n prev_src = src[src_index];\n prev_prev_out = prev_src * coeff[7];\n prev_out = prev_prev_out;\n curr_src = prev_src;\n\n coeff_a0 = coeff[2];\n coeff_a1 = coeff[3];\n\n for (j = width - 1; j >= 0; j--) {\n curr_out = curr_src * coeff_a0 +\n prev_src * coeff_a1 +\n prev_out * coeff_b1 +\n prev_prev_out * coeff_b2;\n\n prev_prev_out = prev_out;\n prev_out = curr_out;\n\n prev_src = curr_src;\n curr_src = src[src_index];\n\n out[out_index] = line[line_index] + prev_out;\n\n src_index--;\n line_index--;\n out_index -= height;\n }\n }\n}\n\n\nfunction blurMono16(src, width, height, radius) {\n // Quick exit on zero radius\n if (!radius) { return; }\n\n var out = new Uint16Array(src.length),\n tmp_line = new Float32Array(Math.max(width, height));\n\n var coeff = gaussCoef(radius);\n\n convolveMono16(src, out, tmp_line, coeff, width, height, radius);\n convolveMono16(out, src, tmp_line, coeff, height, width, radius);\n}\n\nmodule.exports = blurMono16;\n\n},{}],19:[function(_dereq_,module,exports){\nif (typeof Object.create === 'function') {\n // implementation from standard node.js 'util' module\n module.exports = function inherits(ctor, superCtor) {\n if (superCtor) {\n ctor.super_ = superCtor\n ctor.prototype = Object.create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: false,\n writable: true,\n configurable: true\n }\n })\n }\n };\n} else {\n // old school shim for old browsers\n module.exports = function inherits(ctor, superCtor) {\n if (superCtor) {\n ctor.super_ = superCtor\n var TempCtor = function () {}\n TempCtor.prototype = superCtor.prototype\n ctor.prototype = new TempCtor()\n ctor.prototype.constructor = ctor\n }\n }\n}\n\n},{}],20:[function(_dereq_,module,exports){\n'use strict';\n\n\nvar assign = _dereq_('object-assign');\nvar base64decode = _dereq_('./lib/base64decode');\nvar hasWebAssembly = _dereq_('./lib/wa_detect');\n\n\nvar DEFAULT_OPTIONS = {\n js: true,\n wasm: true\n};\n\n\nfunction MultiMath(options) {\n if (!(this instanceof MultiMath)) return new MultiMath(options);\n\n var opts = assign({}, DEFAULT_OPTIONS, options || {});\n\n this.options = opts;\n\n this.__cache = {};\n\n this.__init_promise = null;\n this.__modules = opts.modules || {};\n this.__memory = null;\n this.__wasm = {};\n\n this.__isLE = ((new Uint32Array((new Uint8Array([ 1, 0, 0, 0 ])).buffer))[0] === 1);\n\n if (!this.options.js && !this.options.wasm) {\n throw new Error('mathlib: at least \"js\" or \"wasm\" should be enabled');\n }\n}\n\n\nMultiMath.prototype.has_wasm = hasWebAssembly;\n\n\nMultiMath.prototype.use = function (module) {\n this.__modules[module.name] = module;\n\n // Pin the best possible implementation\n if (this.options.wasm && this.has_wasm() && module.wasm_fn) {\n this[module.name] = module.wasm_fn;\n } else {\n this[module.name] = module.fn;\n }\n\n return this;\n};\n\n\nMultiMath.prototype.init = function () {\n if (this.__init_promise) return this.__init_promise;\n\n if (!this.options.js && this.options.wasm && !this.has_wasm()) {\n return Promise.reject(new Error('mathlib: only \"wasm\" was enabled, but it\\'s not supported'));\n }\n\n var self = this;\n\n this.__init_promise = Promise.all(Object.keys(self.__modules).map(function (name) {\n var module = self.__modules[name];\n\n if (!self.options.wasm || !self.has_wasm() || !module.wasm_fn) return null;\n\n // If already compiled - exit\n if (self.__wasm[name]) return null;\n\n // Compile wasm source\n return WebAssembly.compile(self.__base64decode(module.wasm_src))\n .then(function (m) { self.__wasm[name] = m; });\n }))\n .then(function () { return self; });\n\n return this.__init_promise;\n};\n\n\n////////////////////////////////////////////////////////////////////////////////\n// Methods below are for internal use from plugins\n\n\n// Simple decode base64 to typed array. Useful to load embedded webassembly\n// code. You probably don't need to call this method directly.\n//\nMultiMath.prototype.__base64decode = base64decode;\n\n\n// Increase current memory to include specified number of bytes. Do nothing if\n// size is already ok. You probably don't need to call this method directly,\n// because it will be invoked from `.__instance()`.\n//\nMultiMath.prototype.__reallocate = function mem_grow_to(bytes) {\n if (!this.__memory) {\n this.__memory = new WebAssembly.Memory({\n initial: Math.ceil(bytes / (64 * 1024))\n });\n return this.__memory;\n }\n\n var mem_size = this.__memory.buffer.byteLength;\n\n if (mem_size < bytes) {\n this.__memory.grow(Math.ceil((bytes - mem_size) / (64 * 1024)));\n }\n\n return this.__memory;\n};\n\n\n// Returns instantinated webassembly item by name, with specified memory size\n// and environment.\n// - use cache if available\n// - do sync module init, if async init was not called earlier\n// - allocate memory if not enougth\n// - can export functions to webassembly via \"env_extra\",\n// for example, { exp: Math.exp }\n//\nMultiMath.prototype.__instance = function instance(name, memsize, env_extra) {\n if (memsize) this.__reallocate(memsize);\n\n // If .init() was not called, do sync compile\n if (!this.__wasm[name]) {\n var module = this.__modules[name];\n this.__wasm[name] = new WebAssembly.Module(this.__base64decode(module.wasm_src));\n }\n\n if (!this.__cache[name]) {\n var env_base = {\n memoryBase: 0,\n memory: this.__memory,\n tableBase: 0,\n table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' })\n };\n\n this.__cache[name] = new WebAssembly.Instance(this.__wasm[name], {\n env: assign(env_base, env_extra || {})\n });\n }\n\n return this.__cache[name];\n};\n\n\n// Helper to calculate memory aligh fo