Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-displace/es/index.js
1129 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
/**
15
* Displaces the image based on the provided displacement map
16
* @param {object} map the source Jimp instance
17
* @param {number} offset the maximum displacement value
18
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
19
* @returns {Jimp} this for chaining of methods
20
*/
21
var _default = function _default() {
22
return {
23
displace: function displace(map, offset, cb) {
24
if ((0, _typeof2["default"])(map) !== 'object' || map.constructor !== this.constructor) {
25
return _utils.throwError.call(this, 'The source must be a Jimp image', cb);
26
}
27
28
if (typeof offset !== 'number') {
29
return _utils.throwError.call(this, 'factor must be a number', cb);
30
}
31
32
var source = this.cloneQuiet();
33
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
34
var displacement = map.bitmap.data[idx] / 256 * offset;
35
displacement = Math.round(displacement);
36
var ids = this.getPixelIndex(x + displacement, y);
37
this.bitmap.data[ids] = source.bitmap.data[idx];
38
this.bitmap.data[ids + 1] = source.bitmap.data[idx + 1];
39
this.bitmap.data[ids + 2] = source.bitmap.data[idx + 2];
40
});
41
42
if ((0, _utils.isNodePattern)(cb)) {
43
cb.call(this, null, this);
44
}
45
46
return this;
47
}
48
};
49
};
50
51
exports["default"] = _default;
52
//# sourceMappingURL=index.js.map
53