update ColorSpace.h

This commit is contained in:
hyzboy 2020-01-07 22:35:19 +08:00
parent a331286b30
commit 5e64222c48
2 changed files with 50 additions and 4 deletions

View File

@ -1,6 +1,8 @@
#ifndef HGL_GRAPH_COLOR_SPACE_INCLUDE #ifndef HGL_GRAPH_COLOR_SPACE_INCLUDE
#define HGL_GRAPH_COLOR_SPACE_INCLUDE #define HGL_GRAPH_COLOR_SPACE_INCLUDE
#include<math.h>
namespace hgl namespace hgl
{ {
namespace graph namespace graph
@ -16,13 +18,17 @@ namespace hgl
RANGE_SIZE =(END_RANGE-BEGIN_RANGE)+1 RANGE_SIZE =(END_RANGE-BEGIN_RANGE)+1
};//enum class ColorSpace };//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<typename T> template<typename T>
inline const T sRGB2Linear(const T &in) inline const T sRGB2Linear(const T &in)
{ {
if(in<=0.4045) if(in<=0.4045)
return in/12.92; return in/12.92;
else else
return pow((in+0.55)/1.055,2.4); return pow((in+SRGB_ALPHA)/(1+SRGB_ALPHA),2.4);
} }
template<typename T> template<typename T>
@ -31,19 +37,19 @@ namespace hgl
if(in<=0.0031308f) if(in<=0.0031308f)
return in*12.92f; return in*12.92f;
else 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<typename T> template<typename T>
inline const T sRGB2LinearApprox(const T &in) inline const T sRGB2LinearApprox(const T &in)
{ {
return pow(in,2.2f); return pow(in,T(SRGB_INVERSE_GAMMA));
} }
template<typename T> template<typename T>
inline const T Linear2sRGBApprox(const T &in) inline const T Linear2sRGBApprox(const T &in)
{ {
return pow(in,1.0f/2.2f); return pow(in,SRGB_GAMMA);
} }
template<typename T> template<typename T>
@ -61,6 +67,22 @@ namespace hgl
g=-0.9689f*x+1.8758f*y+0.0416f*z; g=-0.9689f*x+1.8758f*y+0.0416f*z;
b= 0.0557f*x-0.2040f*y+1.0570f*z; b= 0.0557f*x-0.2040f*y+1.0570f*z;
} }
template<typename T>
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<typename T>
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 graph
}//namespace hgl }//namespace hgl
#endif//HGL_GRAPH_COLOR_SPACE_INCLUDE #endif//HGL_GRAPH_COLOR_SPACE_INCLUDE

View File

@ -162,6 +162,30 @@ VK_NAMESPACE_BEGIN
#define FMT_D24UN_S8U VK_FORMAT_D24_UNORM_S8_UINT #define FMT_D24UN_S8U VK_FORMAT_D24_UNORM_S8_UINT
#define FMT_D32F_S8U VK_FORMAT_D32_SFLOAT_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_RGBUN VK_FORMAT_BC1_RGB_UNORM_BLOCK
#define FMT_BC1_RGBs VK_FORMAT_BC1_RGB_SRGB_BLOCK #define FMT_BC1_RGBs VK_FORMAT_BC1_RGB_SRGB_BLOCK
#define FMT_BC1_RGBAUN VK_FORMAT_BC1_RGBA_UNORM_BLOCK #define FMT_BC1_RGBAUN VK_FORMAT_BC1_RGBA_UNORM_BLOCK