From 4555f74ee33033514ac80ad3f7aa87fa94742faf Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 9 Jul 2008 15:18:08 +0000 Subject: [PATCH] added operator + between color with clamped specialization for unsigned chars --- vcg/space/color4.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/vcg/space/color4.h b/vcg/space/color4.h index 2cac1e5b..3a329aa8 100644 --- a/vcg/space/color4.h +++ b/vcg/space/color4.h @@ -148,6 +148,12 @@ public: //inline void Import(const Color4 &b); //inline void Import(const Color4 &b); + inline Color4 operator + ( const Color4 & p) const + { + return Color4( this->_v[0]+p._v[0], this->_v[1]+p._v[1], this->_v[2]+p._v[2], this->_v[3]+p._v[3] ); + } + + inline void lerp(const Color4 &c0, const Color4 &c1, const float x); inline void lerp(const Color4 &c0, const Color4 &c1, const Color4 &c2, const Point3f &ip); /// given a float and a range set the corresponding color in the well known red->green->blue color ramp. To reverse the direction of the ramp just swap minf and maxf. @@ -372,6 +378,18 @@ inline Color4 Clamp(Color4 &c) return c; } +template<> +inline Color4 Color4::operator + ( const Color4 & p) const +{ + return Color4( + math::Clamp(int(_v[0])+int(p._v[0]),0,255), + math::Clamp(int(_v[1])+int(p._v[1]),0,255), + math::Clamp(int(_v[2])+int(p._v[2]),0,255), + math::Clamp(int(_v[3])+int(p._v[3]),0,255) + ); +} + + typedef Color4 Color4b; typedef Color4 Color4f;