append return value in Color3f/4f::operator =

This commit is contained in:
2023-11-01 18:33:27 +08:00
parent ac8565e338
commit b5c66fe2cd
5 changed files with 18 additions and 12 deletions

View File

@@ -58,10 +58,11 @@ namespace hgl
void Grey(); ///<将当前色彩变成灰色
//操作符重载
void operator = (const float *v){r=*v++;g=*v++;b=*v;}
const Color3f &operator = (const float *v){r=*v++;g=*v++;b=*v;return *this;}
const Color3f &operator = (const Color3f &v){r=v.r;g=v.g;b=v.b;return *this;}
bool operator == (const Color3f &);
bool operator != (const Color3f &);
bool operator == (const Color3f &)const;
bool operator != (const Color3f &)const;
void operator += (const Color3f &v){r+=v.r;g+=v.g;b+=v.b;Clamp();}
void operator -= (const Color3f &v){r-=v.r;g-=v.g;b-=v.b;Clamp();}

View File

@@ -68,12 +68,12 @@ namespace hgl
void Grey(); ///<将当前色彩变成灰色
//操作符重载
void operator = (const float *v){r=*v++;g=*v++;b=*v++;a=*v;}
void operator = (const Color3f &v){r=v.r;g=v.g;b=v.b;a=1;}
void operator = (const Color4f &v){r=v.r;g=v.g;b=v.b;a=v.a;}
const Color4f &operator = (const float *v){r=*v++;g=*v++;b=*v++;a=*v;return *this;}
const Color4f &operator = (const Color3f &v){r=v.r;g=v.g;b=v.b;a=1;;return *this;}
const Color4f &operator = (const Color4f &v){r=v.r;g=v.g;b=v.b;a=v.a;;return *this;}
bool operator == (const Color4f &);
bool operator != (const Color4f &);
bool operator == (const Color4f &)const;
bool operator != (const Color4f &)const;
void operator += (const Color4f &v){r+=v.r;g+=v.g;b+=v.b;a+=v.a;Clamp();}
void operator -= (const Color4f &v){r-=v.r;g-=v.g;b-=v.b;a-=v.a;Clamp();}

View File

@@ -14,5 +14,10 @@ namespace hgl
{
return (r*54+g*183+b*19)>>8;
}
template<typename T> constexpr T RGB2LumBT2020(const T &r,const T &g,const T &b)
{
return 0.2627f*r+0.6780f*g+0.0593f*b;
}
}//namespace hgl
#endif//HGL_COLOR_LUM_INCLUDE