-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathColor.h
More file actions
82 lines (69 loc) · 1.65 KB
/
Copy pathColor.h
File metadata and controls
82 lines (69 loc) · 1.65 KB
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
#pragma once
#include <stdint.h>
typedef uint8_t color_t;
struct Color {
color_t r;
color_t g;
color_t b;
Color() : r(0), g(0), b(0) {
}
Color(color_t r, color_t g, color_t b) : r(r), g(g), b(b) {
}
Color(uint32_t p) {
r = (p >> 16) & 0xff;
g = (p >> 8) & 0xff;
b = p & 0xff;
}
Color operator-(const Color c) {
return Color(r - c.r, g - c.g, b - c.b);
//color_t newR = (short)r - (short)c.r >= 0 ? r - c.r : 0;
//color_t newG = (short)g - (short)c.g >= 0 ? g - c.g : 0;
//color_t newB = (short)b - (short)c.b >= 0 ? b - c.b : 0;
//return Color(newR, newG, newB);
}
Color operator+(const Color c) {
//color_t newR = (short)r + (short)c.r < 256 ? r + c.r : 255;
//color_t newG = (short)g + (short)c.g < 256 ? g + c.g : 255;
//color_t newB = (short)b + (short)c.b < 256 ? b + c.b : 255;
//return Color(newR, newG, newB);
return Color(r + c.r, g + c.g, b + c.b);
}
Color operator+(const uint32_t c) {
color_t cr = (c >> 16) & 0xff;
color_t cg = (c >> 8) & 0xff;
color_t cb = c & 0xff;
return Color(r + cr, g + cg, b + cb);
}
void operator-=(const Color c) {
r -= c.r;
g -= c.g;
b -= c.b;
}
void operator+=(const Color c) {
r += c.r;
g += c.g;
b += c.b;
}
Color operator*(const float f) {
color_t tR = r * f;
color_t tG = g * f;
color_t tB = b * f;
if (tR == 0 && r != 0)
tR = 1;
if (tG == 0 && g != 0)
tG = 1;
if (tB == 0 && b != 0)
tB = 1;
return Color(tR, tG, tB);
}
Color operator/(const int f) {
return Color(r / f, g / f, b / f);
}
};
struct Colors {
static const Color red;
static const Color green;
static const Color blue;
static const Color black;
static const Color white;
};