-
Notifications
You must be signed in to change notification settings - Fork 0
/
RGBData.hpp
48 lines (40 loc) · 1.08 KB
/
RGBData.hpp
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
#ifndef RGBDATA_HPP_
#define RGBDATA_HPP_
class RGBData {
public:
const static uchar MAXCOLORS = 3;
private:
uchar colors[MAXCOLORS]; // Variable made private, as set and get have safety checks
public:
const static uchar R = 0;
const static uchar G = 1;
const static uchar B = 2;
RGBData (uchar r, uchar g, uchar b) {
colors[R] = r;
colors[G] = g;
colors[B] = b;
}
uchar getColor (uchar index) {
if (index >= MAXCOLORS) return 0;
return colors[index];
}
bool setColor (uchar index, uchar data) {
if (index >= MAXCOLORS) return false;
colors [index] = data;
return true;
}
RGBData getAvg (RGBData altColor) {
RGBData avg (0, 0, 0);
for (uchar i = 0; i < MAXCOLORS; i++) {
uchar colorAvg = (altColor.getColor (i) + colors[i]) / 2;
avg.setColor (i, colorAvg);
}
return avg;
}
void getHex (uchar (&out)[MAXCOLORS]) {
// Loop done because we can't make direct assignments with arrays
for (int i = 0; i < MAXCOLORS; i++)
out[i] = colors[MAXCOLORS-1-i];
}
};
#endif