From 5e64222c4880fb345d78b5c3cf5d7d005b5b241e Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 7 Jan 2020 22:35:19 +0800 Subject: [PATCH] update ColorSpace.h --- inc/hgl/graph/ColorSpace.h | 30 ++++++++++++++++++++++++++---- inc/hgl/graph/vulkan/VKFormat.h | 24 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/inc/hgl/graph/ColorSpace.h b/inc/hgl/graph/ColorSpace.h index 319d6186..43aea9e4 100644 --- a/inc/hgl/graph/ColorSpace.h +++ b/inc/hgl/graph/ColorSpace.h @@ -1,6 +1,8 @@ #ifndef HGL_GRAPH_COLOR_SPACE_INCLUDE #define HGL_GRAPH_COLOR_SPACE_INCLUDE +#include + namespace hgl { namespace graph @@ -16,13 +18,17 @@ namespace hgl RANGE_SIZE =(END_RANGE-BEGIN_RANGE)+1 };//enum class ColorSpace + constexpr double SRGB_GAMMA =1.0f/2.2f; + constexpr double SRGB_INVERSE_GAMMA =2.2f; + constexpr double SRGB_ALPHA =0.055f; + 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); + return pow((in+SRGB_ALPHA)/(1+SRGB_ALPHA),2.4); } template @@ -31,19 +37,19 @@ namespace hgl if(in<=0.0031308f) return in*12.92f; else - return pow((in*1.055f),1.0f/2.4f)-0.055f; + return (1+SRGB_ALPHA)*pow(in,1.0f/2.4f)-SRGB_ALPHA; } template inline const T sRGB2LinearApprox(const T &in) { - return pow(in,2.2f); + return pow(in,T(SRGB_INVERSE_GAMMA)); } template inline const T Linear2sRGBApprox(const T &in) { - return pow(in,1.0f/2.2f); + return pow(in,SRGB_GAMMA); } template @@ -61,6 +67,22 @@ namespace hgl g=-0.9689f*x+1.8758f*y+0.0416f*z; b= 0.0557f*x-0.2040f*y+1.0570f*z; } + + template + inline void RGB2YCbCr(T &Y,T &Cb,T &Cr,const T &r,const T &g,const T &b + { + Y = 0.299 * r + 0.587 * g + 0.114 * b; + Cb = (b - Y) * 0.565; + Cr = (r - Y) * 0.713; + } + + template + inline void YCbCr2RGB(T &r,T &g,T &b,const T &Y,const T &Cb,const T &Cr) + { + r=Y+1.403*Cr; + g=Y-0.344*Cb-0.714*Cr; + b=Y+1.770*Cb; + } }//namespace graph }//namespace hgl #endif//HGL_GRAPH_COLOR_SPACE_INCLUDE diff --git a/inc/hgl/graph/vulkan/VKFormat.h b/inc/hgl/graph/vulkan/VKFormat.h index 0aa39abf..cb901ae6 100644 --- a/inc/hgl/graph/vulkan/VKFormat.h +++ b/inc/hgl/graph/vulkan/VKFormat.h @@ -162,6 +162,30 @@ VK_NAMESPACE_BEGIN #define FMT_D24UN_S8U VK_FORMAT_D24_UNORM_S8_UINT #define FMT_D32F_S8U VK_FORMAT_D32_SFLOAT_S8_UINT +/** + * Type of data bytes/pixel Palette size Line Segments User For Compressed components/Description + * ----------------+----------------+--------------+-----------------+--------------------+----------------------------------------------------+-------------------------------------- + * BC1(S3TC1) RGB5/RGB5A1 0.5 4 1 Color maps,Normal maps + * BC2(S3TC3) RGBA4 1 4 1 BC1+uncompress 4-bit alpha + * BC3(S3TC5) RGBA4 1 4 1Color+1Alpha Color maps BC1+BC4 compress alpha + * BC4(ATI1/3Dc+) Grayscale 0.5 8 1 + * BC5(ATI2/3Dc) 2xGrayscale 1 8 per channel 1 per channel Tangent-space normal maps + * BC6H FloatRGB 1 8-16 1-2 HDR images + * BC7 RGB/RGBA 1 4-16 1-3 High-quality color maps + * + * ETC RGB + * ETC2 RGB/RGBA1 Color maps,Normals + * EAC Grayscale + * 2xEAC RG + * ETC2+EAC RGBA + * + * PVRTC RGB/RGBA1/RGBA + * PVRTC2 RGB/RGBA1/RGBA + * + * ASTC R/RG/RGB/RGBA + * ----------------+----------------+--------------+-----------------+--------------------+----------------------------------------------------+ + */ + #define FMT_BC1_RGBUN VK_FORMAT_BC1_RGB_UNORM_BLOCK #define FMT_BC1_RGBs VK_FORMAT_BC1_RGB_SRGB_BLOCK #define FMT_BC1_RGBAUN VK_FORMAT_BC1_RGBA_UNORM_BLOCK