From a331286b303afd1bfbe73de77aaad5c4de365b18 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 7 Jan 2020 18:14:16 +0800 Subject: [PATCH] add ColorSpace.h --- CMCore | 2 +- inc/hgl/graph/ColorSpace.h | 66 ++++++++++++++++++++++++++ src/RenderDevice/Shader/CMakeLists.txt | 1 - 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 inc/hgl/graph/ColorSpace.h diff --git a/CMCore b/CMCore index 7152bd67..122c7add 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 7152bd677cfc4ea0b33b21b49895e5e049e1b0bd +Subproject commit 122c7addc294daa1d2c8c19ed08b1b50aa47571f diff --git a/inc/hgl/graph/ColorSpace.h b/inc/hgl/graph/ColorSpace.h new file mode 100644 index 00000000..319d6186 --- /dev/null +++ b/inc/hgl/graph/ColorSpace.h @@ -0,0 +1,66 @@ +#ifndef HGL_GRAPH_COLOR_SPACE_INCLUDE +#define HGL_GRAPH_COLOR_SPACE_INCLUDE + +namespace hgl +{ + namespace graph + { + enum class ColorSpace + { + Linear=0, + sRGB, + YCbCr, + + BEGIN_RANGE =Linear, + END_RANGE =YCbCr, + RANGE_SIZE =(END_RANGE-BEGIN_RANGE)+1 + };//enum class ColorSpace + + template + inline const T sRGB2Linear(const T &in) + { + if(in<=0.4045) + return in/12.92; + else + return pow((in+0.55)/1.055,2.4); + } + + template + inline const T Linear2sRGB(const T &in) + { + if(in<=0.0031308f) + return in*12.92f; + else + return pow((in*1.055f),1.0f/2.4f)-0.055f; + } + + template + inline const T sRGB2LinearApprox(const T &in) + { + return pow(in,2.2f); + } + + template + inline const T Linear2sRGBApprox(const T &in) + { + return pow(in,1.0f/2.2f); + } + + template + inline void sRGB2LinearFast(T &x,T &y,T &z,const T &r,const T &g,const T &b) + { + x=0.4124f*r+0.3576f*g+0.1805f*b; + y=0.2126f*r+0.7152f*g+0.0722f*b; + z=0.0193f*r+0.1192f*g+0.9505f*b; + } + + template + inline void Linear2sRGBFast(T &r,T &g,T &b,const T &x,const T &y,const T &z) + { + r= 3.2406f*x-1.5373f*y-0.4986f*z; + g=-0.9689f*x+1.8758f*y+0.0416f*z; + b= 0.0557f*x-0.2040f*y+1.0570f*z; + } + }//namespace graph +}//namespace hgl +#endif//HGL_GRAPH_COLOR_SPACE_INCLUDE diff --git a/src/RenderDevice/Shader/CMakeLists.txt b/src/RenderDevice/Shader/CMakeLists.txt index 594cdb52..7d57490d 100644 --- a/src/RenderDevice/Shader/CMakeLists.txt +++ b/src/RenderDevice/Shader/CMakeLists.txt @@ -34,4 +34,3 @@ add_cm_library(ULRE.Shader "ULRE" ${GRAPH_SHADER_HEADER_PATH}/common.h ${GRAPH_SHADER_PARAM_FILES} ${GRAPH_SHADER_MAKER_SOURCE} ${GRAPH_SPV_SOURCE}) -