Path: blob/master/node_modules/@jimp/plugin-blit/es/index.js
1126 views
"use strict";12var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");34Object.defineProperty(exports, "__esModule", {5value: true6});7exports["default"] = void 0;89var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));1011var _utils = require("@jimp/utils");1213var _default = function _default() {14return {15/**16* Blits a source image on to this image17* @param {Jimp} src the source Jimp instance18* @param {number} x the x position to blit the image19* @param {number} y the y position to blit the image20* @param {number} srcx (optional) the x position from which to crop the source image21* @param {number} srcy (optional) the y position from which to crop the source image22* @param {number} srcw (optional) the width to which to crop the source image23* @param {number} srch (optional) the height to which to crop the source image24* @param {function(Error, Jimp)} cb (optional) a callback for when complete25* @returns {Jimp} this for chaining of methods26*/27blit: function blit(src, x, y, srcx, srcy, srcw, srch, cb) {28if (!(src instanceof this.constructor)) {29return _utils.throwError.call(this, 'The source must be a Jimp image', cb);30}3132if (typeof x !== 'number' || typeof y !== 'number') {33return _utils.throwError.call(this, 'x and y must be numbers', cb);34}3536if (typeof srcx === 'function') {37cb = srcx;38srcx = 0;39srcy = 0;40srcw = src.bitmap.width;41srch = src.bitmap.height;42} else if ((0, _typeof2["default"])(srcx) === (0, _typeof2["default"])(srcy) && (0, _typeof2["default"])(srcy) === (0, _typeof2["default"])(srcw) && (0, _typeof2["default"])(srcw) === (0, _typeof2["default"])(srch)) {43srcx = srcx || 0;44srcy = srcy || 0;45srcw = srcw || src.bitmap.width;46srch = srch || src.bitmap.height;47} else {48return _utils.throwError.call(this, 'srcx, srcy, srcw, srch must be numbers', cb);49} // round input505152x = Math.round(x);53y = Math.round(y); // round input5455srcx = Math.round(srcx);56srcy = Math.round(srcy);57srcw = Math.round(srcw);58srch = Math.round(srch);59var maxWidth = this.bitmap.width;60var maxHeight = this.bitmap.height;61var baseImage = this;62src.scanQuiet(srcx, srcy, srcw, srch, function (sx, sy, idx) {63var xOffset = x + sx - srcx;64var yOffset = y + sy - srcy;6566if (xOffset >= 0 && yOffset >= 0 && maxWidth - xOffset > 0 && maxHeight - yOffset > 0) {67var dstIdx = baseImage.getPixelIndex(xOffset, yOffset);68var _src = {69r: this.bitmap.data[idx],70g: this.bitmap.data[idx + 1],71b: this.bitmap.data[idx + 2],72a: this.bitmap.data[idx + 3]73};74var dst = {75r: baseImage.bitmap.data[dstIdx],76g: baseImage.bitmap.data[dstIdx + 1],77b: baseImage.bitmap.data[dstIdx + 2],78a: baseImage.bitmap.data[dstIdx + 3]79};80baseImage.bitmap.data[dstIdx] = (_src.a * (_src.r - dst.r) - dst.r + 255 >> 8) + dst.r;81baseImage.bitmap.data[dstIdx + 1] = (_src.a * (_src.g - dst.g) - dst.g + 255 >> 8) + dst.g;82baseImage.bitmap.data[dstIdx + 2] = (_src.a * (_src.b - dst.b) - dst.b + 255 >> 8) + dst.b;83baseImage.bitmap.data[dstIdx + 3] = this.constructor.limit255(dst.a + _src.a);84}85});8687if ((0, _utils.isNodePattern)(cb)) {88cb.call(this, null, this);89}9091return this;92}93};94};9596exports["default"] = _default;97//# sourceMappingURL=index.js.map9899