Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/utils/src/index.js
1126 views
1
export function isNodePattern(cb) {
2
if (typeof cb === 'undefined') {
3
return false;
4
}
5
6
if (typeof cb !== 'function') {
7
throw new TypeError('Callback must be a function');
8
}
9
10
return true;
11
}
12
13
export function throwError(error, cb) {
14
if (typeof error === 'string') {
15
error = new Error(error);
16
}
17
18
if (typeof cb === 'function') {
19
return cb.call(this, error);
20
}
21
22
throw error;
23
}
24
25
export function scan(image, x, y, w, h, f) {
26
// round input
27
x = Math.round(x);
28
y = Math.round(y);
29
w = Math.round(w);
30
h = Math.round(h);
31
32
for (let _y = y; _y < y + h; _y++) {
33
for (let _x = x; _x < x + w; _x++) {
34
const idx = (image.bitmap.width * _y + _x) << 2;
35
f.call(image, _x, _y, idx);
36
}
37
}
38
39
return image;
40
}
41
42
export function* scanIterator(image, x, y, w, h) {
43
// round input
44
x = Math.round(x);
45
y = Math.round(y);
46
w = Math.round(w);
47
h = Math.round(h);
48
49
for (let _y = y; _y < y + h; _y++) {
50
for (let _x = x; _x < x + w; _x++) {
51
const idx = (image.bitmap.width * _y + _x) << 2;
52
yield { x: _x, y: _y, idx, image };
53
}
54
}
55
}
56
57