Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-blit/es/index.js
1126 views
1
"use strict";
2
3
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5
Object.defineProperty(exports, "__esModule", {
6
value: true
7
});
8
exports["default"] = void 0;
9
10
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
12
var _utils = require("@jimp/utils");
13
14
var _default = function _default() {
15
return {
16
/**
17
* Blits a source image on to this image
18
* @param {Jimp} src the source Jimp instance
19
* @param {number} x the x position to blit the image
20
* @param {number} y the y position to blit the image
21
* @param {number} srcx (optional) the x position from which to crop the source image
22
* @param {number} srcy (optional) the y position from which to crop the source image
23
* @param {number} srcw (optional) the width to which to crop the source image
24
* @param {number} srch (optional) the height to which to crop the source image
25
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
26
* @returns {Jimp} this for chaining of methods
27
*/
28
blit: function blit(src, x, y, srcx, srcy, srcw, srch, cb) {
29
if (!(src instanceof this.constructor)) {
30
return _utils.throwError.call(this, 'The source must be a Jimp image', cb);
31
}
32
33
if (typeof x !== 'number' || typeof y !== 'number') {
34
return _utils.throwError.call(this, 'x and y must be numbers', cb);
35
}
36
37
if (typeof srcx === 'function') {
38
cb = srcx;
39
srcx = 0;
40
srcy = 0;
41
srcw = src.bitmap.width;
42
srch = src.bitmap.height;
43
} 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)) {
44
srcx = srcx || 0;
45
srcy = srcy || 0;
46
srcw = srcw || src.bitmap.width;
47
srch = srch || src.bitmap.height;
48
} else {
49
return _utils.throwError.call(this, 'srcx, srcy, srcw, srch must be numbers', cb);
50
} // round input
51
52
53
x = Math.round(x);
54
y = Math.round(y); // round input
55
56
srcx = Math.round(srcx);
57
srcy = Math.round(srcy);
58
srcw = Math.round(srcw);
59
srch = Math.round(srch);
60
var maxWidth = this.bitmap.width;
61
var maxHeight = this.bitmap.height;
62
var baseImage = this;
63
src.scanQuiet(srcx, srcy, srcw, srch, function (sx, sy, idx) {
64
var xOffset = x + sx - srcx;
65
var yOffset = y + sy - srcy;
66
67
if (xOffset >= 0 && yOffset >= 0 && maxWidth - xOffset > 0 && maxHeight - yOffset > 0) {
68
var dstIdx = baseImage.getPixelIndex(xOffset, yOffset);
69
var _src = {
70
r: this.bitmap.data[idx],
71
g: this.bitmap.data[idx + 1],
72
b: this.bitmap.data[idx + 2],
73
a: this.bitmap.data[idx + 3]
74
};
75
var dst = {
76
r: baseImage.bitmap.data[dstIdx],
77
g: baseImage.bitmap.data[dstIdx + 1],
78
b: baseImage.bitmap.data[dstIdx + 2],
79
a: baseImage.bitmap.data[dstIdx + 3]
80
};
81
baseImage.bitmap.data[dstIdx] = (_src.a * (_src.r - dst.r) - dst.r + 255 >> 8) + dst.r;
82
baseImage.bitmap.data[dstIdx + 1] = (_src.a * (_src.g - dst.g) - dst.g + 255 >> 8) + dst.g;
83
baseImage.bitmap.data[dstIdx + 2] = (_src.a * (_src.b - dst.b) - dst.b + 255 >> 8) + dst.b;
84
baseImage.bitmap.data[dstIdx + 3] = this.constructor.limit255(dst.a + _src.a);
85
}
86
});
87
88
if ((0, _utils.isNodePattern)(cb)) {
89
cb.call(this, null, this);
90
}
91
92
return this;
93
}
94
};
95
};
96
97
exports["default"] = _default;
98
//# sourceMappingURL=index.js.map
99