-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetColor.cpp
More file actions
43 lines (40 loc) · 820 Bytes
/
getColor.cpp
File metadata and controls
43 lines (40 loc) · 820 Bytes
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
#include "getColor.h"
static rgb24 colorTable[] = {
{0, 0, 0},
{0, 55, 218},
{19, 161, 14},
{58, 150, 221},
{197, 15, 31},
{136, 23, 152},
{193, 156, 0},
{204, 204, 204},
{118, 118, 118},
{59, 120, 255},
{22, 198, 12},
{97, 214, 214},
{231, 72, 86},
{180, 0, 158},
{249, 241, 165},
{255, 255, 255}
};
bool invalidColor = false;
rgb24 getColor(char ch){
invalidColor = false;
rgb24 color = (rgb24) {0, 0, 0};
if (ch >= '0' && ch <= '9'){
ch -= 48;
color = colorTable[(unsigned char) ch];
}
else if (ch >= 'A' && ch <= 'F'){
ch -= 55;
color = colorTable[(unsigned char) ch];
}
else if (ch >= 'a' && ch <= 'f'){
ch -= 87;
color = colorTable[(unsigned char) ch];
}
else{
invalidColor = true;
}
return color;
}