diff options
author | Stijn Buys <ingar@osirion.org> | 2008-03-24 20:40:57 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-03-24 20:40:57 +0000 |
commit | 78572764acf68b94b9992f488a725bc4be96a5b3 (patch) | |
tree | 03d4c6b55b413b8f147b2b8d62028bca9bf7c6cb /src/math/color.h | |
parent | bd647ce0f411c1a78407762e0a01511694e76e6f (diff) |
libmath optimizations and cleanups
Diffstat (limited to 'src/math/color.h')
-rw-r--r-- | src/math/color.h | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/math/color.h b/src/math/color.h index 51b415f..5684770 100644 --- a/src/math/color.h +++ b/src/math/color.h @@ -16,43 +16,55 @@ namespace math class Color { public: + /// create the default color, white Color(); - Color(const float, float const, const float, const float=1.0f); - Color(const float, const float=1.0f); - Color(const Color &); + /// create a color from float RGBA value + Color(float red, float green, float blue, float alpha=1.0f); + /// create a greyscale color + Color(const float grey, const float=1.0f); + /// create a copy from an existing color + Color(Color const & other); + /// red channel value float red() const; + /// green channel value float green() const; + /// blue channel value float blue() const; + /// alpha channel value float alpha() const; - const Color &operator=(const Color &); + /// assignment + void assign(Color const & other); + /// assignment + void assign(float red, float green, float blue, float alpha=1.0f); + /// assignment + void assign(float grey, float alpha=1.0f); + /// assignment operator + Color const &operator=(Color const & other); + /// multiply rgb values with scalar value. Color operator*(const float scalar) const; - // Some default colors - static const Color Black() { return Color(0.0f); }; - static const Color White() { return Color(1.0f); }; - static const Color Red() { return Color(1.0f,0.0f,0.0f); }; - static const Color Green() { return Color(0.0f,1.0f,0.0f); }; - static const Color Blue() { return Color(0.0f, 0.0f, 1.0f); }; - static const Color Yellow() { return Color(1.0f, 1.0f, 0.0f); }; - + /// clam color values to the 0-1 range + void clamp(); + float &r; float &g; float &b; float &a; -private: - void normalize(); - float _r, _g, _b, _a; + float rgba_data[4]; }; -std::ostream &operator<<(std::ostream &os, const Color &c); +/// write color RGB values to stream +std::ostream &operator<<(std::ostream &os, Color const & color); +/// read color RGB values from stream, alpha is set to 1.0 std::istream &operator>>(std::istream & is, Color & color); -Color operator*(const float scalar, const Color& color); +/// scalar-with-color multiplication +Color const operator*(float scalar, Color const & color); } // namespace math |