-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.js
146 lines (132 loc) · 4.5 KB
/
filters.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const Filters = {
invertColors(data) {
for (let i = 0; i < data.length; i += 4) {
data[i] = data[i] ^ 255;
data[i + 1] = data[i + 1] ^ 255;
data[i + 2] = data[i + 2] ^ 255;
}
return data;
},
rgbSplit(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i - 150] = pixels.data[i + 0]; // RED
pixels.data[i + 500] = pixels.data[i + 1]; // GREEN
pixels.data[i - 550] = pixels.data[i + 2]; // Blue
}
return pixels;
},
redEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] + 50; // RED
pixels.data[i + 1] = pixels.data[i + 1] - 10; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] * 0.5; // Blue
}
return pixels;
},
greenEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] - 50; // RED
pixels.data[i + 1] = pixels.data[i + 1] + 100; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] * 0.5; // Blue
}
return pixels;
},
blueEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] - 50; // RED
pixels.data[i + 1] = pixels.data[i + 1] + 50; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] + 150; // Blue
}
return pixels;
},
sepiaEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
const red = pixels.data[i];
const green = pixels.data[i + 1];
const blue = pixels.data[i + 2];
const alpha = pixels.data[i + 3];
const tRed = 0.393 * red + 0.769 * green + 0.189 * blue;
const tGreen = 0.394 * red + 0.686 * green + 0.168 * blue;
const tBlue = 0.272 * red + 0.543 * green + 0.131 * blue;
pixels.data[i] = tRed;
pixels.data[i + 1] = tGreen;
pixels.data[i + 2] = tBlue;
}
return pixels;
},
bwEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
const red = pixels.data[i];
const green = pixels.data[i + 1];
const blue = pixels.data[i + 2];
const alpha = pixels.data[i + 3];
const gray = (red + green + blue) / 3;
pixels.data[i] = pixels.data[i + 1] = pixels.data[i + 2] = gray;
}
return pixels;
},
greenEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] - 100; // RED
pixels.data[i + 1] = pixels.data[i + 1] - 1; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] - 5; // Blue
}
return pixels;
},
redEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] + 100; // RED
pixels.data[i + 1] = pixels.data[i + 1] - 1; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] - 5; // Blue
}
return pixels;
},
darkWarmEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] + 10; // RED
pixels.data[i + 1] = pixels.data[i + 1] - 1; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] - 50; // Blue
}
return pixels;
},
cyanEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] + 10; // RED
pixels.data[i + 1] = pixels.data[i + 1] + 50; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] + 50; // Blue
}
return pixels;
},
washedOutEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] + 50; // RED
pixels.data[i + 1] = pixels.data[i + 1] + 50; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] + 50; // Blue
}
return pixels;
},
yellowEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] + 50; // RED
pixels.data[i + 1] = pixels.data[i + 1] + 50; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] - 50; // Blue
}
return pixels;
},
warmEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] + 5; // RED
pixels.data[i + 1] = pixels.data[i + 1] + 10; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] - 20; // Blue
}
return pixels;
},
coldEffect(pixels) {
for (let i = 0; i < pixels.data.length; i += 4) {
pixels.data[i + 0] = pixels.data[i + 0] - 5; // RED
pixels.data[i + 1] = pixels.data[i + 1] + 10; // GREEN
pixels.data[i + 2] = pixels.data[i + 2] + 20; // Blue
}
return pixels;
}
};