-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubPixel.js
49 lines (49 loc) · 1.22 KB
/
subPixel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
data[2] = 254;
data[2 + 4] = 254;
data[streamCanvas.width + 2] = 254;
data[streamCanvas.width + 2 + 4] = 254;
data[1] = 254;
data[1 + 4] = 254;
data[streamCanvas.width + 1] = 254;
data[streamCanvas.width + 1 + 4] = 254;
data[0] = 254;
data[0 + 4] = 254;
data[streamCanvas.width + 0] = 254;
data[streamCanvas.width + 0 + 4] = 255;
for (let i = 0; i < length; i += 8) {
if (i % streamCanvas.width == 0) i += streamCanvas.width + 1;
if (i > length) break;
const red =
(data[i + 0] +
data[i + 4 + 0] +
data[i + streamCanvas.width + 0] +
data[i + streamCanvas.width + 4 + 0]) /
4;
const green =
(data[i + 1] +
data[i + 4 + 1] +
data[i + streamCanvas.width + 1] +
data[i + streamCanvas.width + 4 + 1]) /
4;
const blue =
(data[i + 2] +
data[i + 4 + 2] +
data[i + streamCanvas.width + 2] +
data[i + streamCanvas.width + 4 + 2]) /
4;
if (
green > greenLL &&
green < greenUL &&
red > redLL &&
red < redUL &&
blue > blueLL &&
blue < blueUL
) {
// if (i % 16 == 0)
// i += streamCanvas.width + 1;
data[i + 4] = 0;
data[i + 4 + 4] = 0;
data[i + streamCanvas.width + 4] = 0;
data[i + streamCanvas.width + 4 + 4] = 0;
}
}