Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-threshold/es/index.js
1126 views
1
"use strict";
2
3
Object.defineProperty(exports, "__esModule", {
4
value: true
5
});
6
exports["default"] = void 0;
7
8
var _utils = require("@jimp/utils");
9
10
/**
11
* Applies a minimum color threshold to a greyscale image. Converts image to greyscale by default
12
* @param {number} options object
13
* max: A number auto limited between 0 - 255
14
* replace: (optional) A number auto limited between 0 - 255 (default 255)
15
* autoGreyscale: (optional) A boolean whether to apply greyscale beforehand (default true)
16
* @param {number} cb (optional) a callback for when complete
17
* @return {this} this for chaining of methods
18
*/
19
var _default = function _default() {
20
return {
21
threshold: function threshold(_ref, cb) {
22
var _this = this;
23
24
var max = _ref.max,
25
_ref$replace = _ref.replace,
26
replace = _ref$replace === void 0 ? 255 : _ref$replace,
27
_ref$autoGreyscale = _ref.autoGreyscale,
28
autoGreyscale = _ref$autoGreyscale === void 0 ? true : _ref$autoGreyscale;
29
30
if (typeof max !== 'number') {
31
return _utils.throwError.call(this, 'max must be a number', cb);
32
}
33
34
if (typeof replace !== 'number') {
35
return _utils.throwError.call(this, 'replace must be a number', cb);
36
}
37
38
if (typeof autoGreyscale !== 'boolean') {
39
return _utils.throwError.call(this, 'autoGreyscale must be a boolean', cb);
40
}
41
42
max = this.constructor.limit255(max);
43
replace = this.constructor.limit255(replace);
44
45
if (autoGreyscale) {
46
this.greyscale();
47
}
48
49
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
50
var grey = _this.bitmap.data[idx] < max ? _this.bitmap.data[idx] : replace;
51
_this.bitmap.data[idx] = grey;
52
_this.bitmap.data[idx + 1] = grey;
53
_this.bitmap.data[idx + 2] = grey;
54
});
55
56
if ((0, _utils.isNodePattern)(cb)) {
57
cb.call(this, null, this);
58
}
59
60
return this;
61
}
62
};
63
};
64
65
exports["default"] = _default;
66
//# sourceMappingURL=index.js.map
67