Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-invert/src/index.js
1126 views
1
import { isNodePattern } from '@jimp/utils';
2
3
/**
4
* Inverts the image
5
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
6
* @returns {Jimp} this for chaining of methods
7
*/
8
export default () => ({
9
invert(cb) {
10
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
11
x,
12
y,
13
idx
14
) {
15
this.bitmap.data[idx] = 255 - this.bitmap.data[idx];
16
this.bitmap.data[idx + 1] = 255 - this.bitmap.data[idx + 1];
17
this.bitmap.data[idx + 2] = 255 - this.bitmap.data[idx + 2];
18
});
19
20
if (isNodePattern(cb)) {
21
cb.call(this, null, this);
22
}
23
24
return this;
25
}
26
});
27
28