Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-flip/src/index.js
1129 views
1
import { isNodePattern, throwError } from '@jimp/utils';
2
3
/**
4
* Flip the image horizontally
5
* @param {boolean} horizontal a Boolean, if true the image will be flipped horizontally
6
* @param {boolean} vertical a Boolean, if true the image will be flipped vertically
7
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
8
* @returns {Jimp} this for chaining of methods
9
*/
10
function flipFn(horizontal, vertical, cb) {
11
if (typeof horizontal !== 'boolean' || typeof vertical !== 'boolean')
12
return throwError.call(
13
this,
14
'horizontal and vertical must be Booleans',
15
cb
16
);
17
18
const bitmap = Buffer.alloc(this.bitmap.data.length);
19
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
20
x,
21
y,
22
idx
23
) {
24
const _x = horizontal ? this.bitmap.width - 1 - x : x;
25
const _y = vertical ? this.bitmap.height - 1 - y : y;
26
const _idx = (this.bitmap.width * _y + _x) << 2;
27
const data = this.bitmap.data.readUInt32BE(idx);
28
29
bitmap.writeUInt32BE(data, _idx);
30
});
31
32
this.bitmap.data = Buffer.from(bitmap);
33
34
if (isNodePattern(cb)) {
35
cb.call(this, null, this);
36
}
37
38
return this;
39
}
40
41
export default () => ({
42
flip: flipFn,
43
mirror: flipFn
44
});
45
46