#ifndef COLOR_H #include "util.h" #include // STRUCTURES struct ColorU32 { union { struct { uint8_t b, g, r, a; }; uint32_t u32; }; }; struct ColorF32 { float b, g, r, a; }; // OPERATORS // c1 + c2 inline ColorF32 operator+(ColorF32 const &c1, ColorF32 const &c2) { ColorF32 result; result.b = c1.b + c2.b; result.g = c1.g + c2.g; result.r = c1.r + c2.r; result.a = c1.a + c2.a; return result; } // c1 += c2 inline ColorF32 &operator+=(ColorF32 &c1, ColorF32 const &c2) { c1 = c1 + c2; return c1; } // c * f inline ColorF32 operator*(ColorF32 const &c, float f) { ColorF32 result; result.b = f * c.b; result.g = f * c.g; result.r = f * c.r; result.a = f * c.a; return result; } // f * c inline ColorF32 operator*(float f, ColorF32 const &c) { ColorF32 result; result = c * f; return result; } // c1 * c2 inline ColorF32 operator*(ColorF32 const &c1, ColorF32 const &c2) { ColorF32 result; result.b = c1.b * c2.b; result.g = c1.g * c2.g; result.r = c1.r * c2.r; result.a = c1.a * c2.a; return result; } // c / f inline ColorF32 operator/(ColorF32 const &c, float f) { ColorF32 result; float invF = 1.0f / f; result.b = c.b * invF; result.g = c.g * invF; result.r = c.r * invF; result.a = c.a * invF; return result; } // c /= f inline ColorF32 &operator/=(ColorF32 &c, float f) { c = c / f; return c; } // PUBLIC FUNCTIONS void ScaleColor(ColorF32 &c); #define COLOR_H #endif