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
|
/**
* Some color operating here.
*/
#ifndef __JE_COLOR_H__
#define __JE_COLOR_H__
#include "../core/configuration.h"
#if defined(jin_graphics)
#include "../math/math.h"
#include "../common/types.h"
#include "../utils/endian.h"
namespace JinEngine
{
namespace Graphics
{
typedef uint8 Channel;
class Color
{
public:
// Built-in colors
static const Color WHITE;
static const Color BLACK;
static const Color RED;
static const Color GREEN;
static const Color BLUE;
static const Color MAGENTA;
static const Color YELLOW;
static const uint32 RMASK;
static const uint32 GMASK;
static const uint32 BMASK;
static const uint32 AMASK;
///
/// Get lerp color with given factor.
///
/// @param start Start color.
/// @param end End color.
/// @param t Factor of interplation.
/// @return Color after interplation.
///
static Color lerp(Color start, Color end, float t)
{
t = Math::clamp<float>(t, 0, 1);
Color c;
c.r = Math::lerp(start.r, end.r, t);
c.g = Math::lerp(start.g, end.g, t);
c.b = Math::lerp(start.b, end.b, t);
c.a = Math::lerp(start.a, end.a, t);
return c;
}
///
///
///
Color() { r = g = b = a = 0; };
///
///
///
Color(unsigned char _r
, unsigned char _g
, unsigned char _b
, unsigned char _a = 255)
{
r = _r;
g = _g;
b = _b;
a = _a;
}
Color(const Color& c)
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
}
void set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a)
{
r = _r;
g = _g;
b = _b;
a = _a;
}
void operator = (const Color& c)
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
}
bool operator == (const Color& c)
{
return r == c.r && g == c.g && b == c.b && a == c.a;
}
bool operator != (const Color& c)
{
return !(r == c.r && g == c.g && b == c.b && a == c.a);
}
Channel r, g, b, a;
};
} // namespace Graphics
} // namespace JinEngine
#endif // jin_graphics
#endif // __JE_COLOR_H__
|