From 1141f37cc4ae98441e0e75809a8757851c836408 Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Wed, 1 Nov 2023 19:13:54 +0800 Subject: [PATCH] used BT601 instead of BT709 in RGB2Lum --- inc/hgl/color/Lum.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/inc/hgl/color/Lum.h b/inc/hgl/color/Lum.h index e021980..feac820 100644 --- a/inc/hgl/color/Lum.h +++ b/inc/hgl/color/Lum.h @@ -5,19 +5,24 @@ namespace hgl { - template constexpr T RGB2Lum(const T &r, const T &g, const T &b) + template constexpr T RGB2Lum(const T &r,const T &g,const T &b) { - return 0.2126f*r+0.7152f*g+0.0722f*b; - } - - template<> constexpr uint8 RGB2Lum(const uint8 &r, const uint8 &g, const uint8 &b) - { - return (r*54+g*183+b*19)>>8; + return T(0.299f*r+0.587f*g+0.114f*b); } + template<> constexpr uint8 RGB2Lum(const uint8 &r,const uint8 &g,const uint8 &b) + { + return uint8((r*77+g*151+b*28)>>8); + } + + template constexpr T RGB2LumBT709(const T &r, const T &g, const T &b) + { + return T(0.2126f*r+0.7152f*g+0.0722f*b); + } + template constexpr T RGB2LumBT2020(const T &r,const T &g,const T &b) { - return 0.2627f*r+0.6780f*g+0.0593f*b; + return T(0.2627f*r+0.6780f*g+0.0593f*b); } }//namespace hgl #endif//HGL_COLOR_LUM_INCLUDE