{"version":3,"file":"index.js","names":["throwError","isNodePattern","mulTable","shgTable","blur","r","cb","call","rsum","gsum","bsum","asum","x","y","i","p","p1","p2","yp","yi","yw","pa","wm","bitmap","width","hm","height","rad1","mulSum","shgSum","red","green","blue","alpha","vmin","vmax","iterations","data"],"sources":["../src/index.js"],"sourcesContent":["import { throwError, isNodePattern } from \"@jimp/utils\";\nimport { mulTable, shgTable } from \"./blur-tables\";\n\n/*\n Superfast Blur (0.5)\n http://www.quasimondo.com/BoxBlurForCanvas/FastBlur.js\n\n Copyright (c) 2011 Mario Klingemann\n\n Permission is hereby granted, free of charge, to any person\n obtaining a copy of this software and associated documentation\n files (the \"Software\"), to deal in the Software without\n restriction, including without limitation the rights to use,\n copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the\n Software is furnished to do so, subject to the following\n conditions:\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n OTHER DEALINGS IN THE SOFTWARE.\n*/\n\nexport default () => ({\n /**\n * A fast blur algorithm that produces similar effect to a Gaussian blur - but MUCH quicker\n * @param {number} r the pixel radius of the blur\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\n blur(r, cb) {\n if (typeof r !== \"number\")\n return throwError.call(this, \"r must be a number\", cb);\n if (r < 1) return throwError.call(this, \"r must be greater than 0\", cb);\n\n let rsum;\n let gsum;\n let bsum;\n let asum;\n let x;\n let y;\n let i;\n let p;\n let p1;\n let p2;\n let yp;\n let yi;\n let yw;\n let pa;\n\n const wm = this.bitmap.width - 1;\n const hm = this.bitmap.height - 1;\n // const wh = this.bitmap.width * this.bitmap.height;\n const rad1 = r + 1;\n\n const mulSum = mulTable[r];\n const shgSum = shgTable[r];\n\n const red = [];\n const green = [];\n const blue = [];\n const alpha = [];\n\n const vmin = [];\n const vmax = [];\n\n let iterations = 2;\n\n while (iterations-- > 0) {\n yi = 0;\n yw = 0;\n\n for (y = 0; y < this.bitmap.height; y++) {\n rsum = this.bitmap.data[yw] * rad1;\n gsum = this.bitmap.data[yw + 1] * rad1;\n bsum = this.bitmap.data[yw + 2] * rad1;\n asum = this.bitmap.data[yw + 3] * rad1;\n\n for (i = 1; i <= r; i++) {\n p = yw + ((i > wm ? wm : i) << 2);\n rsum += this.bitmap.data[p++];\n gsum += this.bitmap.data[p++];\n bsum += this.bitmap.data[p++];\n asum += this.bitmap.data[p];\n }\n\n for (x = 0; x < this.bitmap.width; x++) {\n red[yi] = rsum;\n green[yi] = gsum;\n blue[yi] = bsum;\n alpha[yi] = asum;\n\n if (y === 0) {\n vmin[x] = ((p = x + rad1) < wm ? p : wm) << 2;\n vmax[x] = (p = x - r) > 0 ? p << 2 : 0;\n }\n\n p1 = yw + vmin[x];\n p2 = yw + vmax[x];\n\n rsum += this.bitmap.data[p1++] - this.bitmap.data[p2++];\n gsum += this.bitmap.data[p1++] - this.bitmap.data[p2++];\n bsum += this.bitmap.data[p1++] - this.bitmap.data[p2++];\n asum += this.bitmap.data[p1] - this.bitmap.data[p2];\n\n yi++;\n }\n\n yw += this.bitmap.width << 2;\n }\n\n for (x = 0; x < this.bitmap.width; x++) {\n yp = x;\n rsum = red[yp] * rad1;\n gsum = green[yp] * rad1;\n bsum = blue[yp] * rad1;\n asum = alpha[yp] * rad1;\n\n for (i = 1; i <= r; i++) {\n yp += i > hm ? 0 : this.bitmap.width;\n rsum += red[yp];\n gsum += green[yp];\n bsum += blue[yp];\n asum += alpha[yp];\n }\n\n yi = x << 2;\n\n for (y = 0; y < this.bitmap.height; y++) {\n pa = (asum * mulSum) >>> shgSum;\n this.bitmap.data[yi + 3] = pa;\n\n // normalize alpha\n if (pa > 255) {\n this.bitmap.data[yi + 3] = 255;\n }\n\n if (pa > 0) {\n pa = 255 / pa;\n this.bitmap.data[yi] = ((rsum * mulSum) >>> shgSum) * pa;\n this.bitmap.data[yi + 1] = ((gsum * mulSum) >>> shgSum) * pa;\n this.bitmap.data[yi + 2] = ((bsum * mulSum) >>> shgSum) * pa;\n } else {\n this.bitmap.data[yi + 2] = 0;\n this.bitmap.data[yi + 1] = 0;\n this.bitmap.data[yi] = 0;\n }\n\n if (x === 0) {\n vmin[y] = ((p = y + rad1) < hm ? p : hm) * this.bitmap.width;\n vmax[y] = (p = y - r) > 0 ? p * this.bitmap.width : 0;\n }\n\n p1 = x + vmin[y];\n p2 = x + vmax[y];\n\n rsum += red[p1] - red[p2];\n gsum += green[p1] - green[p2];\n bsum += blue[p1] - blue[p2];\n asum += alpha[p1] - alpha[p2];\n\n yi += this.bitmap.width << 2;\n }\n }\n }\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n },\n});\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,aAAa,QAAQ,aAAa;AACvD,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,eAAe;;AAElD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,gBAAe,OAAO;EACpB;AACF;AACA;AACA;AACA;AACA;EACEC,IAAI,CAACC,CAAC,EAAEC,EAAE,EAAE;IACV,IAAI,OAAOD,CAAC,KAAK,QAAQ,EACvB,OAAOL,UAAU,CAACO,IAAI,CAAC,IAAI,EAAE,oBAAoB,EAAED,EAAE,CAAC;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