1 line
3.4 KiB
Plaintext
1 line
3.4 KiB
Plaintext
|
{"version":3,"sources":["../src/index.js"],"names":["isNodePattern","throwError","mask","src","x","y","cb","constructor","call","Math","round","w","bitmap","width","h","height","baseImage","scanQuiet","sx","sy","idx","destX","destY","dstIdx","getPixelIndex","data","avg"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,aAA1C;AAEA;;;;;;;;;AAQA,gBAAe;AAAA,SAAO;AACpBC,IAAAA,IADoB,gBACfC,GADe,EACQ;AAAA,UAAlBC,CAAkB,uEAAd,CAAc;AAAA,UAAXC,CAAW,uEAAP,CAAO;AAAA,UAAJC,EAAI;;AAC1B,UAAI,EAAEH,GAAG,YAAY,KAAKI,WAAtB,CAAJ,EAAwC;AACtC,eAAON,UAAU,CAACO,IAAX,CAAgB,IAAhB,EAAsB,iCAAtB,EAAyDF,EAAzD,CAAP;AACD;;AAED,UAAI,OAAOF,CAAP,KAAa,QAAb,IAAyB,OAAOC,CAAP,KAAa,QAA1C,EAAoD;AAClD,eAAOJ,UAAU,CAACO,IAAX,CAAgB,IAAhB,EAAsB,yBAAtB,EAAiDF,EAAjD,CAAP;AACD,OAPyB,CAS1B;;;AACAF,MAAAA,CAAC,GAAGK,IAAI,CAACC,KAAL,CAAWN,CAAX,CAAJ;AACAC,MAAAA,CAAC,GAAGI,IAAI,CAACC,KAAL,CAAWL,CAAX,CAAJ;AAEA,UAAMM,CAAC,GAAG,KAAKC,MAAL,CAAYC,KAAtB;AACA,UAAMC,CAAC,GAAG,KAAKF,MAAL,CAAYG,MAAtB;AACA,UAAMC,SAAS,GAAG,IAAlB;AAEAb,MAAAA,GAAG,CAACc,SAAJ,CAAc,CAAd,EAAiB,CAAjB,EAAoBd,GAAG,CAACS,MAAJ,CAAWC,KAA/B,EAAsCV,GAAG,CAACS,MAAJ,CAAWG,MAAjD,EAAyD,UACvDG,EADuD,EAEvDC,EAFuD,EAGvDC,GAHuD,EAIvD;AACA,YAAMC,KAAK,GAAGjB,CAAC,GAAGc,EAAlB;AACA,YAAMI,KAAK,GAAGjB,CAAC,GAAGc,EAAlB;;AAEA,YAAIE,KAAK,IAAI,CAAT,IAAcC,KAAK,IAAI,CAAvB,IAA4BD,KAAK,GAAGV,CAApC,IAAyCW,KAAK,GAAGR,CAArD,EAAwD;AACtD,cAAMS,MAAM,GAAGP,SAAS,CAACQ,aAAV,CAAwBH,KAAxB,EAA+BC,KAA/B,CAAf;AADsD,cAE9CG,IAF8C,GAErC,KAAKb,MAFgC,CAE9Ca,IAF8C;AAGtD,cAAMC,GAAG,GAAG,CAACD,IAAI,CAACL,GAAG,GAAG,CAAP,CAAJ,GAAgBK,IAAI,CAACL,GAAG,GAAG,CAAP,CAApB,GAAgCK,IAAI,CAACL,GAAG,GAAG,CAAP,CAArC,IAAkD,CAA9D;AAEAJ,UAAAA,SAAS,CAACJ,MAAV,CAAiBa,IAAjB,CAAsBF,MAAM,GAAG,CAA/B,KAAqCG,GAAG,GAAG,GAA3C;AACD;AACF,OAfD;;AAiBA,UAAI1B,aAAa,CAACM,EAAD,CAAjB,EAAuB;AACrBA,QAAAA,EAAE,CAACE,IAAH,CAAQ,IAAR,EAAc,IAAd,EAAoB,IAApB;AACD;;AAED,aAAO,IAAP;AACD;AAxCmB,GAAP;AAAA,CAAf","sourcesContent":["import { isNodePattern, throwError } from '@jimp/utils';\n\n/**\n * Masks a source image on to this image using average pixel colour. A completely black pixel on the mask will turn a pixel in the image completely transparent.\n * @param {Jimp} src the source Jimp instance\n * @param {number} x the horizontal position to blit the image\n * @param {number} y the vertical position to blit the image\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\nexport default () => ({\n mask(src, x = 0, y = 0, 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 // round input\n x = Math.round(x);\n y = Math.round(y);\n\n const w = this.bitmap.width;\n const h = this.bitmap.height;\n const baseImage = this;\n\n src.scanQuiet(0, 0, src.bitmap.width, src.bitmap.height, function(\n sx,\n sy,\n idx\n ) {\n const destX = x + sx;\n const destY = y + sy;\n\n if (destX >= 0 && destY >= 0 && destX < w && destY < h) {\n const dstIdx = baseImage.getPixelIndex(destX, destY);\n const { data } = this.bitmap;\n const avg = (data[idx + 0] + data[idx + 1] + data[idx + 2]) / 3;\n\n baseImage.bitmap.data[dstIdx + 3] *= avg / 255;\n }\n });\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n }\n});\n"],"file":"index.js"}
|