{"version":3,"sources":["../src/index.js"],"names":["throwError","isNodePattern","blit","src","x","y","srcx","srcy","srcw","srch","cb","constructor","call","bitmap","width","height","Math","round","maxWidth","maxHeight","baseImage","scanQuiet","sx","sy","idx","xOffset","yOffset","dstIdx","getPixelIndex","r","data","g","b","a","dst","limit255"],"mappings":";;AAAA,SAASA,UAAT,EAAqBC,aAArB,QAA0C,aAA1C;AAEA,gBAAe;AAAA,SAAO;AACpB;;;;;;;;;;;;AAYAC,IAAAA,IAboB,gBAafC,GAbe,EAaVC,CAbU,EAaPC,CAbO,EAaJC,IAbI,EAaEC,IAbF,EAaQC,IAbR,EAacC,IAbd,EAaoBC,EAbpB,EAawB;AAC1C,UAAI,EAAEP,GAAG,YAAY,KAAKQ,WAAtB,CAAJ,EAAwC;AACtC,eAAOX,UAAU,CAACY,IAAX,CAAgB,IAAhB,EAAsB,iCAAtB,EAAyDF,EAAzD,CAAP;AACD;;AAED,UAAI,OAAON,CAAP,KAAa,QAAb,IAAyB,OAAOC,CAAP,KAAa,QAA1C,EAAoD;AAClD,eAAOL,UAAU,CAACY,IAAX,CAAgB,IAAhB,EAAsB,yBAAtB,EAAiDF,EAAjD,CAAP;AACD;;AAED,UAAI,OAAOJ,IAAP,KAAgB,UAApB,EAAgC;AAC9BI,QAAAA,EAAE,GAAGJ,IAAL;AACAA,QAAAA,IAAI,GAAG,CAAP;AACAC,QAAAA,IAAI,GAAG,CAAP;AACAC,QAAAA,IAAI,GAAGL,GAAG,CAACU,MAAJ,CAAWC,KAAlB;AACAL,QAAAA,IAAI,GAAGN,GAAG,CAACU,MAAJ,CAAWE,MAAlB;AACD,OAND,MAMO,IACL,QAAOT,IAAP,cAAuBC,IAAvB,KACA,QAAOA,IAAP,cAAuBC,IAAvB,CADA,IAEA,QAAOA,IAAP,cAAuBC,IAAvB,CAHK,EAIL;AACAH,QAAAA,IAAI,GAAGA,IAAI,IAAI,CAAf;AACAC,QAAAA,IAAI,GAAGA,IAAI,IAAI,CAAf;AACAC,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GAAQG,GAAG,CAACH,CAArB,IAA0BG,GAAG,CAACH,CAA9B,GAAkC,GAAnC,IAA2C,CAA5C,IAAiDG,GAAG,CAACH,CADvD;AAEAX,UAAAA,SAAS,CAACP,MAAV,CAAiBiB,IAAjB,CAAsBH,MAAM,GAAG,CAA/B,IACE,CAAExB,IAAG,CAAC8B,CAAJ,IAAS9B,IAAG,CAAC6B,CAAJ,GAAQE,GAAG,CAACF,CAArB,IAA0BE,GAAG,CAACF,CAA9B,GAAkC,GAAnC,IAA2C,CAA5C,IAAiDE,GAAG,CAACF,CADvD;AAEAZ,UAAAA,SAAS,CAACP,MAAV,CAAiBiB,IAAjB,CAAsBH,MAAM,GAAG,CAA/B,IAAoC,KAAKhB,WAAL,CAAiBwB,QAAjB,CAClCD,GAAG,CAACD,CAAJ,GAAQ9B,IAAG,CAAC8B,CADsB,CAApC;AAGD;AACF,OAnCD;;AAqCA,UAAIhC,aAAa,CAACS,EAAD,CAAjB,EAAuB;AACrBA,QAAAA,EAAE,CAACE,IAAH,CAAQ,IAAR,EAAc,IAAd,EAAoB,IAApB;AACD;;AAED,aAAO,IAAP;AACD;AArGmB,GAAP;AAAA,CAAf","sourcesContent":["import { throwError, isNodePattern } from '@jimp/utils';\n\nexport default () => ({\n /**\n * Blits a source image on to this image\n * @param {Jimp} src the source Jimp instance\n * @param {number} x the x position to blit the image\n * @param {number} y the y position to blit the image\n * @param {number} srcx (optional) the x position from which to crop the source image\n * @param {number} srcy (optional) the y position from which to crop the source image\n * @param {number} srcw (optional) the width to which to crop the source image\n * @param {number} srch (optional) the height to which to crop the source image\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\n blit(src, x, y, srcx, srcy, srcw, srch, cb) {\n if (!(src instanceof this.constructor)) {\n return throwError.call(this, 'The source must be a Jimp image', cb);\n }\n\n if (typeof x !== 'number' || typeof y !== 'number') {\n return throwError.call(this, 'x and y must be numbers', cb);\n }\n\n if (typeof srcx === 'function') {\n cb = srcx;\n srcx = 0;\n srcy = 0;\n srcw = src.bitmap.width;\n srch = src.bitmap.height;\n } else if (\n typeof srcx === typeof srcy &&\n typeof srcy === typeof srcw &&\n typeof srcw === typeof srch\n ) {\n srcx = srcx || 0;\n srcy = srcy || 0;\n srcw = srcw || src.bitmap.width;\n srch = srch || src.bitmap.height;\n } else {\n return throwError.call(\n this,\n 'srcx, srcy, srcw, srch must be numbers',\n cb\n );\n }\n\n // round input\n x = Math.round(x);\n y = Math.round(y);\n\n // round input\n srcx = Math.round(srcx);\n srcy = Math.round(srcy);\n srcw = Math.round(srcw);\n srch = Math.round(srch);\n\n const maxWidth = this.bitmap.width;\n const maxHeight = this.bitmap.height;\n const baseImage = this;\n\n src.scanQuiet(srcx, srcy, srcw, srch, function(sx, sy, idx) {\n const xOffset = x + sx - srcx;\n const yOffset = y + sy - srcy;\n\n if (\n xOffset >= 0 &&\n yOffset >= 0 &&\n maxWidth - xOffset > 0 &&\n maxHeight - yOffset > 0\n ) {\n const dstIdx = baseImage.getPixelIndex(xOffset, yOffset);\n const src = {\n r: this.bitmap.data[idx],\n g: this.bitmap.data[idx + 1],\n b: this.bitmap.data[idx + 2],\n a: this.bitmap.data[idx + 3]\n };\n\n const dst = {\n r: baseImage.bitmap.data[dstIdx],\n g: baseImage.bitmap.data[dstIdx + 1],\n b: baseImage.bitmap.data[dstIdx + 2],\n a: baseImage.bitmap.data[dstIdx + 3]\n };\n\n baseImage.bitmap.data[dstIdx] =\n ((src.a * (src.r - dst.r) - dst.r + 255) >> 8) + dst.r;\n baseImage.bitmap.data[dstIdx + 1] =\n ((src.a * (src.g - dst.g) - dst.g + 255) >> 8) + dst.g;\n baseImage.bitmap.data[dstIdx + 2] =\n ((src.a * (src.b - dst.b) - dst.b + 255) >> 8) + dst.b;\n baseImage.bitmap.data[dstIdx + 3] = this.constructor.limit255(\n dst.a + src.a\n );\n }\n });\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n }\n});\n"],"file":"index.js"}