18 Rgba(
const float r,
const float g,
const float b,
const float a = 1.f)
21 explicit Rgba(
const float gray,
const float a = 1.f)
27 explicit Rgba(
const wxColour& other)
28 : data(other.Red() / 255.f, other.Green() / 255.f, other.Blue() / 255.f, 1.f) {}
35 explicit operator wxColour()
const {
36 return wxColour(getByte(data[0]), getByte(data[1]), getByte(data[2]));
75 return preserveAlpha(data * value);
82 return preserveAlpha(data / value);
90 return preserveAlpha(data * other.data);
98 return preserveAlpha(data + other.data);
102 *
this = *
this + other;
107 return data == other.data;
111 return data != other.data;
116 return 0.2126f * data[0] + 0.7152f * data[1] + 0.0722f * data[2];
121 const float a1 = other.
a();
122 const float a2 = this->
a();
123 const float ar = a2 + a1 * (1.f - a2);
129 Rgba color = (data * a2 + other.data * a1 * (1.f - a2)) / ar;
139 return preserveAlpha(*
this * (1.f - amount));
147 return preserveAlpha(*
this * (1.f + amount));
159 return Rgba(
lerp(data, other.data, amount));
167 const float Pr = 0.299f;
168 const float Pg = 0.587f;
169 const float Pb = 0.114f;
170 const float P =
sqrt(
sqr(data[0]) * Pr +
sqr(data[1]) * Pg +
sqr(data[2]) * Pb);
172 result.
r() = P + (data[0] - P) * value;
173 result.
g() = P + (data[1] - P) * value;
174 result.
b() = P + (data[2] - P) * value;
179 return Rgba(1.f, 0.f, 0.f);
183 return Rgba(0.f, 1.f, 0.f);
187 return Rgba(0.f, 0.f, 1.f);
191 return Rgba(0.f, 0.f, 0.f);
195 return Rgba(1.f, 1.f, 1.f);
199 return Rgba(value, value, value);
203 return Rgba(0.f, 0.f, 0.f, 0.f);
207 Rgba preserveAlpha(
const Rgba& color)
const {
209 result.
a() = data[3];
213 int getByte(
const float f)
const {
214 return clamp(
int(f * 255.f), 0, 255);
223 Hsv(
const float h,
const float s,
const float v)
#define SPH_ASSERT(x,...)
constexpr INLINE T max(const T &f1, const T &f2)
constexpr INLINE T clamp(const T &f, const T &f1, const T &f2)
INLINE T lerp(const T v1, const T v2, const TAmount amount)
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
INLINE T sqrt(const T f)
Return a squared root of a value.
#define NAMESPACE_SPH_END
Basic vector algebra. Computations are accelerated using SIMD.
3-dimensional vector, float precision
Hsv(const float h, const float s, const float v)
float & operator[](const int index)
Rgba brighten(const float amount) const
Returns a color brighter by given factor.
static Rgba gray(const float value=0.5f)
Rgba inverse() const
Returns an inverse color.
Rgba saturate(const float value) const
Retuns a color with modified saturation.
float intensity() const
Returns the average intensity of the color.
Rgba(const float gray, const float a=1.f)
Rgba darken(const float amount) const
Returns a color darker by given factor.
static Rgba transparent()
Rgba operator*(const float value) const
Multiplies the intensity of the color by given factor.
Rgba(const wxColour &other)
Rgba operator/(const float value) const
Divides the intensity of the color by given factor.
Rgba(const float r, const float g, const float b, const float a=1.f)
bool operator!=(const Rgba &other) const
Rgba & operator=(const Rgba &other)
bool operator==(const Rgba &other) const
Rgba over(const Rgba &other) const
Blends two colors together using "over" operation.
Rgba & operator+=(const Rgba &other)
Rgba operator*(const Rgba &other) const
Multiplies the color by other color, component-wise.
Rgba operator+(const Rgba &other) const
Returns the sum of two colors, component-wise.
Rgba blend(const Rgba &other, const float amount) const
Computes a linear interpolation of two color.