From b5c66fe2cd440d15db54219404a2b4b44ce1018f Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Wed, 1 Nov 2023 18:33:27 +0800 Subject: [PATCH] append return value in Color3f/4f::operator = --- inc/hgl/color/Color3f.h | 7 ++++--- inc/hgl/color/Color4f.h | 10 +++++----- inc/hgl/color/Lum.h | 5 +++++ src/Color/Color3f.cpp | 4 ++-- src/Color/Color4f.cpp | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/inc/hgl/color/Color3f.h b/inc/hgl/color/Color3f.h index 7e4148f..956fdc3 100644 --- a/inc/hgl/color/Color3f.h +++ b/inc/hgl/color/Color3f.h @@ -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();} diff --git a/inc/hgl/color/Color4f.h b/inc/hgl/color/Color4f.h index 3dcce1c..97ddc4e 100644 --- a/inc/hgl/color/Color4f.h +++ b/inc/hgl/color/Color4f.h @@ -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();} diff --git a/inc/hgl/color/Lum.h b/inc/hgl/color/Lum.h index f5cdc8f..e021980 100644 --- a/inc/hgl/color/Lum.h +++ b/inc/hgl/color/Lum.h @@ -14,5 +14,10 @@ namespace hgl { return (r*54+g*183+b*19)>>8; } + + template 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 diff --git a/src/Color/Color3f.cpp b/src/Color/Color3f.cpp index 07ba0a6..66f7abb 100644 --- a/src/Color/Color3f.cpp +++ b/src/Color/Color3f.cpp @@ -39,7 +39,7 @@ namespace hgl b=lum; } //-------------------------------------------------------------------------------------------------- - bool Color3f::operator == (const Color3f &v) + bool Color3f::operator == (const Color3f &v) const { if(r!=v.r)return(false); if(g!=v.g)return(false); @@ -48,7 +48,7 @@ namespace hgl return(true); } //-------------------------------------------------------------------------------------------------- - bool Color3f::operator != (const Color3f &v) + bool Color3f::operator != (const Color3f &v) const { if(r!=v.r)return(true); if(g!=v.g)return(true); diff --git a/src/Color/Color4f.cpp b/src/Color/Color4f.cpp index 79e10c0..7bed7b5 100644 --- a/src/Color/Color4f.cpp +++ b/src/Color/Color4f.cpp @@ -40,7 +40,7 @@ namespace hgl b=lum; } //-------------------------------------------------------------------------------------------------- - bool Color4f::operator == (const Color4f &v) + bool Color4f::operator == (const Color4f &v) const { if(r!=v.r)return(false); if(g!=v.g)return(false); @@ -50,7 +50,7 @@ namespace hgl return(true); } //-------------------------------------------------------------------------------------------------- - bool Color4f::operator != (const Color4f &v) + bool Color4f::operator != (const Color4f &v) const { if(r!=v.r)return(true); if(g!=v.g)return(true);