2015-04-07 02:48:20 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Javelin {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class ColorRgb {
|
|
|
|
public:
|
|
|
|
T b;
|
|
|
|
T g;
|
|
|
|
T r;
|
|
|
|
|
|
|
|
|
|
|
|
ColorRgb()
|
2015-05-06 01:03:05 +02:00
|
|
|
: b(0)
|
2015-04-07 02:48:20 +02:00
|
|
|
, g(0)
|
2015-05-06 01:03:05 +02:00
|
|
|
, r(0) {
|
2015-04-07 02:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgb(T red, T green, T blue)
|
2015-05-06 01:03:05 +02:00
|
|
|
: b(blue)
|
2015-04-07 02:48:20 +02:00
|
|
|
, g(green)
|
2015-05-06 01:03:05 +02:00
|
|
|
, r(red) {
|
2015-04-07 02:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgb(const ColorRgb<T> &x)
|
2015-05-06 01:03:05 +02:00
|
|
|
: b(x.b)
|
2015-04-07 02:48:20 +02:00
|
|
|
, g(x.g)
|
2015-05-06 01:03:05 +02:00
|
|
|
, r(x.r) {
|
2015-04-07 02:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgb<int> operator *(int x) {
|
|
|
|
return ColorRgb<int>(r * x, g * x, b * x);
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgb<int> operator +(const ColorRgb<T> &x) const {
|
|
|
|
return ColorRgb<int>(r + (int)x.r, g + (int)x.g, b + (int)x.b);
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgb<int> operator -(const ColorRgb<T> &x) const {
|
|
|
|
return ColorRgb<int>(r - (int)x.r, g - (int)x.g, b - (int)x.b);
|
|
|
|
}
|
|
|
|
|
|
|
|
int operator %(const ColorRgb<T> &x) const {
|
|
|
|
return r * (int)x.r + g * (int)x.g + b * (int)x.b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator ==(const ColorRgb<T> &x) const {
|
|
|
|
return r == x.r && g == x.g && b == x.b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator !=(const ColorRgb<T> &x) const {
|
|
|
|
return r != x.r || g != x.g || b != x.b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMin(const ColorRgb<T> &x) {
|
|
|
|
if (x.r < r) {
|
|
|
|
r = x.r;
|
|
|
|
}
|
|
|
|
if (x.g < g) {
|
|
|
|
g = x.g;
|
|
|
|
}
|
|
|
|
if (x.b < b) {
|
|
|
|
b = x.b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMax(const ColorRgb<T> &x) {
|
|
|
|
if (x.r > r) {
|
|
|
|
r = x.r;
|
|
|
|
}
|
|
|
|
if (x.g > g) {
|
|
|
|
g = x.g;
|
|
|
|
}
|
|
|
|
if (x.b > b) {
|
|
|
|
b = x.b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class ColorRgba : public ColorRgb<T> {
|
|
|
|
public:
|
|
|
|
T a;
|
|
|
|
|
|
|
|
ColorRgba() :
|
|
|
|
a(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgba(T red, T green, T blue, T alpha)
|
|
|
|
: ColorRgb<T>(red, green, blue)
|
|
|
|
, a(alpha) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgba(const ColorRgba<T> &x)
|
|
|
|
: ColorRgb<T>(x.r, x.g, x.b)
|
|
|
|
, a(x.a) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgba<int> operator *(int x) {
|
|
|
|
return ColorRgba<T>(ColorRgb<T>::r * x,
|
|
|
|
ColorRgb<T>::g * x,
|
|
|
|
ColorRgb<T>::b * x,
|
|
|
|
a * x);
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgba<int> operator +(const ColorRgba<T> &x) {
|
|
|
|
return ColorRgba<T>(ColorRgb<T>::r + (int)x.r,
|
|
|
|
ColorRgb<T>::g + (int)x.g,
|
|
|
|
ColorRgb<T>::b + (int)x.b,
|
|
|
|
a + (int)x.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorRgba<int> operator -(const ColorRgba<T> &x) {
|
|
|
|
return ColorRgba<T>(ColorRgb<T>::r - (int)x.r,
|
|
|
|
ColorRgb<T>::g - (int)x.g,
|
|
|
|
ColorRgb<T>::b - (int)x.b,
|
|
|
|
a - (int)x.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
int operator %(const ColorRgba<T> &x) {
|
|
|
|
return ColorRgb<T>::r * (int)x.r +
|
|
|
|
ColorRgb<T>::g * (int)x.g +
|
|
|
|
ColorRgb<T>::b * (int)x.b +
|
|
|
|
a * (int)x.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator ==(const ColorRgba<T> &x) {
|
|
|
|
return ColorRgb<T>::r == x.r && ColorRgb<T>::g == x.g &&
|
|
|
|
ColorRgb<T>::b == x.b && a == x.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator !=(const ColorRgba<T> &x) {
|
|
|
|
return ColorRgb<T>::r != x.r || ColorRgb<T>::g != x.g ||
|
|
|
|
ColorRgb<T>::b != x.b || a != x.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMin(const ColorRgba<T> &x) {
|
|
|
|
ColorRgb<T>::SetMin(x);
|
|
|
|
if (x.a < a) {
|
|
|
|
a = x.a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMax(const ColorRgba<T> &x) {
|
|
|
|
ColorRgb<T>::SetMax(x);
|
|
|
|
if (x.a > a) {
|
|
|
|
a = x.a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|