Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-dither/src/index.js
1126 views
1
import { isNodePattern } from '@jimp/utils';
2
3
/**
4
* Apply a ordered dithering effect
5
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
6
* @returns {Jimp} this for chaining of methods
7
*/
8
function dither(cb) {
9
const rgb565Matrix = [1, 9, 3, 11, 13, 5, 15, 7, 4, 12, 2, 10, 16, 8, 14, 6];
10
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
11
x,
12
y,
13
idx
14
) {
15
const thresholdId = ((y & 3) << 2) + (x % 4);
16
const dither = rgb565Matrix[thresholdId];
17
this.bitmap.data[idx] = Math.min(this.bitmap.data[idx] + dither, 0xff);
18
this.bitmap.data[idx + 1] = Math.min(
19
this.bitmap.data[idx + 1] + dither,
20
0xff
21
);
22
this.bitmap.data[idx + 2] = Math.min(
23
this.bitmap.data[idx + 2] + dither,
24
0xff
25
);
26
});
27
28
if (isNodePattern(cb)) {
29
cb.call(this, null, this);
30
}
31
32
return this;
33
}
34
35
export default () => ({
36
dither565: dither,
37
dither16: dither
38
});
39
40