41 explicit Color(
float aR = 0.0f,
float aG = 0.0f,
float aB = 0.0f,
float aA = 0.0f)
42 :
r(aR), g(aG), b(aB), a(aA) {}
44 inline Color Inverse()
const
46 return Color(1.0f -
r, 1.0f - g, 1.0f - b, 1.0f - a);
52 return reinterpret_cast<float*
>(
this);
56 inline const float*
Array()
const
58 return reinterpret_cast<const float*
>(
this);
66 s <<
"(" <<
r <<
", " << g <<
", " << b <<
", " << a <<
")";
70 inline bool operator==(
const Color &other)
const
72 return r == other.
r && g == other.g && b == other.b && a == other.a;
75 inline bool operator!=(
const Color &other)
const
77 return ! this->operator==(other);
80 inline Color operator*(
float scale)
const
100 unsigned char r, g, b, a;
103 explicit IntColor(
unsigned char aR = 0,
unsigned char aG = 0,
unsigned char aB = 0,
unsigned char aA = 0)
104 :
r(aR), g(aG), b(aB), a(aA) {}
107 inline Color IntColorToColor(IntColor color)
109 return Color(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
112 inline IntColor ColorToIntColor(Color color)
114 return IntColor(static_cast<unsigned char>(color.r * 255.0f),
115 static_cast<unsigned char>(color.g * 255.0f),
116 static_cast<unsigned char>(color.b * 255.0f),
117 static_cast<unsigned char>(color.a * 255.0f));
120 inline Color IntensityToColor(
float intensity)
122 if (intensity <= 0.0f)
return Color(0.0f, 0.0f, 0.0f, 0.0f);
123 if (intensity >= 1.0f)
return Color(1.0f, 1.0f, 1.0f, 1.0f);
125 return Color(intensity, intensity, intensity, intensity);
136 ColorHSV(
float aH = 0.0f,
float aS = 0.0f,
float aV = 0.0f)
137 : h(aH), s(aS), v(aV) {}
142 std::stringstream str;
144 str <<
"(" << h <<
", " << s <<
", " << v <<
")";
float r
Red, green, blue and alpha components.
Definition: color.h:38
Color(float aR=0.0f, float aG=0.0f, float aB=0.0f, float aA=0.0f)
Constructor; default values are (0,0,0,0) = black.
Definition: color.h:41
Color HSV2RGB(ColorHSV color)
Converts a HSV color to RGB color.
Definition: color.cpp:67
std::string ToString() const
Returns a string "(h, s, v)".
Definition: color.h:140
std::string ToString() const
Returns a string (r, g, b, a)
Definition: color.h:62
Color with integer values.
Definition: color.h:97
IntColor(unsigned char aR=0, unsigned char aG=0, unsigned char aB=0, unsigned char aA=0)
Constructor; default values are (0,0,0,0) = black.
Definition: color.h:103
ColorHSV RGB2HSV(Color color)
Converts a RGB color to HSV color.
Definition: color.cpp:27
float * Array()
Returns the struct cast to float* array; use with care!
Definition: color.h:50
RGBA color.
Definition: color.h:35
HSV color.
Definition: color.h:132
unsigned char r
Red, green, blue and alpha components.
Definition: color.h:100
const float * Array() const
Returns the struct cast to const float* array; use with care!
Definition: color.h:56