diff --git a/include/CColor.hpp b/include/CColor.hpp index 62de34f..c8e9767 100644 --- a/include/CColor.hpp +++ b/include/CColor.hpp @@ -18,18 +18,19 @@ namespace Zeus { +typedef uint8_t Comp8; +typedef uint32_t Comp32; +constexpr float OneOver255 = 1.f/255.f; + typedef union { struct { - unsigned char r, g, b, a; + Comp8 r, g, b, a; }; - unsigned int rgba; + Comp32 rgba; } RGBA32; -typedef uint8_t Comp8; -typedef uint32_t Comp32; - class CVector4f; class alignas(16) CColor @@ -265,21 +266,36 @@ public: #endif }; - void fromRGBA8(unsigned char r, unsigned char g, unsigned char b, unsigned char a) + void fromRGBA8(Comp8 r, Comp8 g, Comp8 b, Comp8 a) { - this->r = r / 255.f; - this->g = g / 255.f; - this->b = b / 255.f; - this->a = a / 255.f; + this->r = r * OneOver255; + this->g = g * OneOver255; + this->b = b * OneOver255; + this->a = a * OneOver255; } - void fromRGBA32(unsigned int rgba) + void fromRGBA32(Comp32 rgba) { static RGBA32 tmp; tmp.rgba = COLOR(rgba); fromRGBA8(tmp.r, tmp.g, tmp.b, tmp.a); } + /*! + * \brief Converts a CColor to RGBA8 + * \param r + * \param g + * \param b + * \param a + */ + void toRGBA8(Comp8& r, Comp8& g, Comp8& b, Comp8& a) + { + r = this->r * 255; + g = this->g * 255; + b = this->b * 255; + a = this->a * 255; + } + /** * @brief Assigns rgba from hsv * @param h[0-1] The hue percentagee of the color.