redefined include files of Color,half float

This commit is contained in:
2023-02-07 22:42:42 +08:00
parent d07f9d0392
commit 54b6ac3b7c
17 changed files with 535 additions and 245 deletions

View File

@@ -1,34 +1,10 @@
#ifndef HGL_COLOR_TABLE_INCLUDE
#define HGL_COLOR_TABLE_INCLUDE
#include<hgl/platform/Platform.h>
#include<hgl/TypeFunc.h>
#include<hgl/type/Color4f.h>
#include<hgl/color/Color4f.h>
namespace hgl
{
#define DEF_RGB_U8_TO_F(r,g,b) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f}
#define DEF_RGBA_U8_TO_F(r,g,b,a) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f,float(a)/255.0f}
#define HEXColor3(value) (0x##value>>16),((0x##value&0xFF00)>>8),(0x##value&0xFF)
#define HEXColor3f(value) float(0x##value>>16)/255.0f,float((0x##value&0xFF00)>>8)/255.0f,float(0x##value&0xFF)/255.0f
const Color3f GetSpectralColor(const double l); ///<根据光谱值获取对应的RGB值
/**
*
*/
struct COLOR_DEF ///颜色数据定义
{
int red,green,blue; ///<三原色
int yum; ///<亮度
float r,g,b; ///<三原色浮点值
float y; ///<亮度浮点值
char eng_name[32]; ///<英文名称
u16char chs_name[16]; ///<中文名称
};
/**
*
*/
@@ -281,20 +257,19 @@ namespace hgl
ENUM_CLASS_RANGE(AliceBlue,YellowGreen)
};//enum COLOR_ENUM
extern COLOR_DEF prv_color[size_t(COLOR::RANGE_SIZE)];
const uint32 GetRGBA(const enum class COLOR &ce,const uint8 &alpha);
const uint32 GetABGR(const enum class COLOR &ce,const uint8 &alpha);
inline const Color3f GetColor3f(const enum class COLOR &ce)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
const Color3f GetColor3f(const enum class COLOR &ce);
const Color4f GetColor4f(const enum class COLOR &ce,const float &alpha);
return Color3f(c.r,c.g,c.b);
}
const Color3f GetYCbCrColor3f(const enum class COLOR &ce);
const Color4f GetYCbCrColor4f(const enum class COLOR &ce,const float &alpha);
inline const Color4f GetColor4f(const enum class COLOR &ce,const float &alpha)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
return Color4f(c.r,c.g,c.b,alpha);
}
/**
* RGB值
* @param l (400700)
*/
const Color3f GetSpectralColor(const double l);
}//namespace hgl
#endif//HGL_COLOR_TABLE_INCLUDE

View File

@@ -1,6 +1,7 @@
#ifndef HGL_COLOR_3_FLOAT_INCLUDE
#define HGL_COLOR_3_FLOAT_INCLUDE
#include<hgl/color/Lum.h>
namespace hgl
{
/**
@@ -53,8 +54,7 @@ namespace hgl
void Yellow(){r=1,g=1,b=0;} ///<黄色
void Purple(){r=1,g=0,b=1;} ///<紫色
void Grey(float v){r=v,g=v,b=v;Clamp();} ///<灰色
void Grey(float,float,float); ///<指彩色变成灰色
float ToGrey(){return RGB2Lum(r,g,b);}
void Grey(); ///<将当前色彩变成灰色
//操作符重载

View File

@@ -1,8 +1,7 @@
#ifndef HGL_COLOR_4_FLOAT_INCLUDE
#define HGL_COLOR_4_FLOAT_INCLUDE
#include<hgl/type/Color3f.h>
#include<hgl/type/DataType.h>
#include<hgl/color/Color3f.h>
namespace hgl
{
#define HGL_FLOAT_TO_U32(c1,c2,c3,c4) uint32( \
@@ -65,6 +64,7 @@ namespace hgl
uint32 ToARGB8()const{ return HGL_FLOAT_TO_ARGB8(r, g, b, a); } ///<输出一个argb8格式的颜色数据
uint32 ToABGR8()const{ return HGL_FLOAT_TO_ABGR8(r, g, b, a); } ///<输出一个abgr8格式的颜色数据
float ToGrey(){return RGB2Lum(r,g,b);}
void Grey(); ///<将当前色彩变成灰色
//操作符重载

142
inc/hgl/color/ColorFormat.h Normal file
View File

@@ -0,0 +1,142 @@
#ifndef HGL_COLOR_FORMAT_INCLUDE
#define HGL_COLOR_FORMAT_INCLUDE
#include<hgl/math/HalfFloat.h>
namespace hgl
{
constexpr uint16 RGB8toRGB565(const uint8 r,const uint8 g,const uint8 b)
{
return ((r<<8)&0xF800)
|((g<<3)&0x7E0)
| (b>>3);
}
inline void RGB8toRGB565(uint16 *target,uint8 *src,uint size)
{
for(uint i=0;i<size;i++)
{
*target=((src[0]<<8)&0xF800)
|((src[1]<<3)&0x7E0)
| (src[2]>>3);
++target;
src+=3;
}
}
// Bit depth Sign bit present Exponent bits Mantissa bits
// 32 Yes 8 23
// 16 Yes 5 10
// 11 No 5 6
// 10 No 5 5
constexpr uint32 RGB16FtoB10GR11UF(const half_float r, const half_float g, const half_float b)
{
return ((b&0x7FE0)<<17)
|((g&0x7FF0)<<7)
| (r&0x7FF0)>>4;
}
inline void RGB16FtoB10GR11UF(uint32 *target,half_float *src,uint size)
{
for(uint i=0;i<size;i++)
{
*target=((src[2]&0x7FE0)<<17)
|((src[1]&0x7FF0)<<7)
| (src[0]&0x7FF0)>>4;
++target;
src+=3;
}
}
constexpr uint16 RGBA8toBGRA4(const uint8 r, const uint8 g, const uint8 b, const uint8 a)
{
return ((b<<8)&0xF000)
|((g<<4)&0xF00)
|((r )&0xF0)
| (a>>4);
}
inline void RGBA8toBGRA4(uint16 *target,uint8 *src,uint size)
{
for(uint i=0;i<size;i++)
{
*target=((src[2]<<8)&0xF000)
|((src[1]<<4)&0xF00)
|((src[0] )&0xF0)
| (src[3]>>4);
++target;
src+=4;
}
}
constexpr uint16 RGBA8toRGBA4(const uint8 r, const uint8 g, const uint8 b, const uint8 a)
{
return ((r<<8)&0xF000)
|((g<<4)&0xF00)
|((b )&0xF0)
| (a>>4);
}
inline void RGBA8toRGBA4(uint16 *target,uint8 *src,uint size)
{
for(uint i=0;i<size;i++)
{
*target=((src[0]<<8)&0xF000)
|((src[1]<<4)&0xF00)
|((src[2] )&0xF0)
| (src[3]>>4);
++target;
src+=4;
}
}
constexpr uint16 RGBA8toA1RGB5(const uint8 r,const uint8 g,const uint8 b,const uint8 a)
{
return ((a<<8)&0x8000)
|((r<<7)&0x7C00)
|((g<<2)&0x3E0)
| (b>>3);
}
inline void RGBA8toA1RGB5(uint16 *target,uint8 *src,uint size)
{
for(uint i=0;i<size;i++)
{
*target=((src[3]<<8)&0x8000)
|((src[0]<<7)&0x7C00)
|((src[1]<<2)&0x3E0)
| (src[2]>>3);
++target;
src+=4;
}
}
constexpr uint32 RGBA16toA2BGR10(const uint16 r,const uint16 g,const uint16 b,const uint16 a)
{
return ((a<<16)&0xC0000000)
|((b<<14)&0x3FF00000)
|((g<< 4)&0xFFC00)
|(a>> 6);
}
inline void RGBA16toA2BGR10(uint32 *target,uint16 *src,uint size)
{
for(uint i=0;i<size;i++)
{
*target=((src[3]<<16)&0xC0000000)
|((src[2]<<14)&0x3FF00000)
|((src[1]<< 4)&0xFFC00)
| (src[0]>> 6);
++target;
src+=4;
}
}
}//namespace hgl
#endif//HGL_COLOR_FORMAT_INCLUDE

118
inc/hgl/color/Gamma.h Normal file
View File

@@ -0,0 +1,118 @@
#ifndef HGL_GAMMA_INCLUDE
#define HGL_GAMMA_INCLUDE
#include<hgl/math/Math.h>
namespace hgl
{
constexpr double GAMMA =2.4f;
constexpr double INV_GAMMA =1.0f/GAMMA;
constexpr double SRGB_ALPHA =0.055f;
template<typename T>
inline constexpr T sRGB2Linear(const T &in)
{
if(in<=0.04045f)
return (double)in/12.92f;
else
return pow((double(in)+SRGB_ALPHA)/(1.0f+SRGB_ALPHA), GAMMA);
}
template<>
inline constexpr uint8 sRGB2Linear(const uint8 &in)
{
if(in<=0x0A)
return in/12.92f;
else
return pow((double(in)+SRGB_ALPHA)/(1.0f+SRGB_ALPHA), GAMMA);
}
template<typename T>
inline constexpr T sRGB2Linear(const T &in,const double &gamma,const double &srgb_alpha)
{
if(in<=0.04045f)
return (double)in/12.92f;
else
return pow((double(in)+srgb_alpha)/(1.0f+srgb_alpha),gamma);
}
template<>
inline constexpr uint8 sRGB2Linear(const uint8 &in,const double &gamma,const double &srgb_alpha)
{
if(in<=0x0A)
return in/12.92f;
else
return pow((double(in)+srgb_alpha)/(1.0f+srgb_alpha), gamma);
}
template<typename T>
inline constexpr T Linear2sRGB(const T &in)
{
if(in<=0.0031308f)
return double(in)*12.92f;
else
return pow(double(in), INV_GAMMA)*(1.0f+SRGB_ALPHA)-SRGB_ALPHA;
}
template<>
inline constexpr uint8 Linear2sRGB(const uint8 &in)
{
if(in<=0x03)
return double(in)*12.92f;
else
return pow(double(in), INV_GAMMA)*(1.0f+SRGB_ALPHA)-SRGB_ALPHA;
}
template<typename T>
inline constexpr T Linear2sRGB(const T &in,const double &inv_gamma,const double &srgb_alpha)
{
if(in<=0.0031308f)
return double(in)*12.92f;
else
return pow(double(in),inv_gamma)*(1.0f+srgb_alpha)-srgb_alpha;
}
template<>
inline constexpr uint8 Linear2sRGB(const uint8 &in,const double &inv_gamma,const double &srgb_alpha)
{
if(in<=0x03)
return double(in)*12.92f;
else
return pow(double(in), inv_gamma)*(1.0f+srgb_alpha)-srgb_alpha;
}
template<typename T>
inline constexpr T sRGB2LinearCheaper(const T &in,const double &gamma=GAMMA)
{
return (T)pow(double(in),gamma);
}
template<typename T>
inline constexpr T Linear2sRGBCheaper(const T &in,const double &inv_gamma=INV_GAMMA)
{
return (T)pow((double)in,inv_gamma);
}
template<typename T>
inline constexpr T sRGB2LinearCheapest(const T &in)
{
return in*in;
}
template<typename T>
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<typename T>
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 hgl
#endif//HGL_GAMMA_INCLUDE

18
inc/hgl/color/Lum.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef HGL_COLOR_LUM_INCLUDE
#define HGL_COLOR_LUM_INCLUDE
#include<hgl/platform/Platform.h>
namespace hgl
{
template<typename T> 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;
}
}//namespace hgl
#endif//HGL_COLOR_LUM_INCLUDE

62
inc/hgl/color/YCbCr.h Normal file
View File

@@ -0,0 +1,62 @@
#ifndef HGL_COLOR_YCbCr_INCLUDE
#define HGL_COLOR_YCbCr_INCLUDE
#include<hgl/math/Math.h>
namespace hgl
{
template<typename T>
inline void RGB2YCbCr(T &y,T &cb,T &cr,const T &r,const T &g,const T &b)
{
y=0.299f*r+0.587f*g+0.114f*b;
cb=0.5f-0.168736f*r-0.331264f*g+0.5f*b;
cr=0.5f+0.5f*r-0.418688f*g-0.081312f*b;
}
template<typename T>
inline void YCbCr2RGB(T &r,T &g,T &b,const T &y,const T &cb,const T &cr)
{
r=y+1.402f*(cr-0.5f);
g=y-0.344136f*(cb-0.5f)-0.714136f*(cr-0.5f);
b=y+1.772f*(cb-0.5f);
}
inline void RGB2YCbCr(uint8 &y,uint8 &cb,uint8 &cr,const uint8 &r,const uint8 &g,const uint8 &b)
{
y =uint8(Clamp(0.299f*r+0.587f*g+0.114f*b));
cb=uint8(Clamp(0.5f-0.168736f*r-0.331264f*g+0.5f*b));
cr=uint8(Clamp(0.5f+0.5f*r-0.418688f*g-0.081312f*b));
}
inline void YCbCr2RGB(uint8 &r,uint8 &g,uint8 &b,const uint8 &y,const uint8 &cb,const uint8 &cr)
{
r=uint8(Clamp(y+1.402f*(cr-0.5f)));
g=uint8(Clamp(y-0.344136f*(cb-0.5f)-0.714136f*(cr-0.5f)));
b=uint8(Clamp(y+1.772f*(cb-0.5f)));
}
template<typename T>
inline constexpr T RGB2Cb(const T &r, const T &g, const T &b)
{
return 0.5f-0.168736f*r-0.331264f*g+0.5f*b;
}
template<>
inline constexpr uint8 RGB2Cb(const uint8 &r, const uint8 &g, const uint8 &b)
{
return uint8(Clamp(0.5f-0.168736f*r-0.331264f*g+0.5f*b));
}
template<typename T>
inline constexpr T RGB2Cr(const T &r, const T &g, const T &b)
{
return 0.5f+0.5f*r-0.418688f*g-0.081312f*b;
}
template<>
inline constexpr uint8 RGB2Cr(const uint8 &r, const uint8 &g, const uint8 &b)
{
return uint8(Clamp(0.5f+0.5f*r-0.418688f*g-0.081312f*b));
}
}//namespace hgl
#endif//HGL_COLOR_YCbCr_INCLUDE

View File

@@ -13,7 +13,7 @@ namespace hgl
* Approximates acos(x) with a max absolute error of 9.0x10^-3.
* Valid in the range -1..1.
*/
inline float Lacos(float x)
inline const float Lacos(float x)
{
// Lagarde 2014, "Inverse trigonometric functions GPU optimization for AMD GCN architecture"
// This is the approximation of degree 1, with a max absolute error of 9.0x10^-3
@@ -27,16 +27,35 @@ namespace hgl
* Approximates acos(x) with a max absolute error of 9.0x10^-3.
* Valid only in the range 0..1.
*/
inline float LacosPositive(float x)
inline const float LacosPositive(float x)
{
float p = -0.1565827 * x + 1.570796;
return p * sqrt(1.0 - x);
return (-0.1565827 * x + 1.570796) * sqrt(1.0 - x);
}
inline constexpr double ApproxSin(double angle)
{
return angle*(1.27323954f-angle*angle*(0.405284735f-angle*angle*(0.075133f-angle*angle*0.0078f)));
}
inline constexpr double ApproxCos(double angle)
{
return 1.27323954f-angle*angle*(0.405284735f-angle*angle*(0.075133f-angle*angle*0.0078f));
}
inline constexpr double ApproxAtan2(double x,double y)
{
return x/(1.27323954f+y*y*(0.405284735f+y*y*(0.075133f+y*y*0.0078f)));
}
inline constexpr double ApproxAtan(double z)
{
return z*(1.27323954f-z*z*(0.405284735f-z*z*(0.075133f-z*z*0.0078f)));
}
/**
* 低精度atan函数
*/
inline double Latan(double z)
inline constexpr double Latan(double z)
{
constexpr double n1 = 0.97239411f;
constexpr double n2 = -0.19194795f;
@@ -49,7 +68,7 @@ namespace hgl
/**
* 近似Pow2.2使用此函数等于pow(x,2.2)
*/
inline double LPow22(double x)
inline constexpr double LPow22(double x)
{
return x*(1.12*x - 0.12);
}

50
inc/hgl/math/HalfFloat.h Normal file
View File

@@ -0,0 +1,50 @@
#ifndef HGL_HALF_FLOAT_INCLUDE
#define HGL_HALF_FLOAT_INCLUDE
#include<hgl/platform/Platform.h>
namespace hgl
{
using half_float=uint16;
inline const half_float float2half(const float &f)
{
const uint32 x = *((uint32 *)&f);
return ((x>>16)&0x8000)|((((x&0x7f800000)-0x38000000)>>13)&0x7c00)|((x>>13)&0x03ff);
}
inline const float half2float(const half_float &hf)
{
union
{
float f;
uint32 u;
}x;
x.u=(((hf&0x8000)<<16) | (((hf&0x7c00)+0x1C000)<<13) | ((hf&0x03FF)<<13));
return x.f;
}
inline void half_to_float(uint32 *target,const half_float *source,uint32 count)
{
while (count--)
{
*target = (((*source & 0x8000) << 16) | (((*source & 0x7c00) + 0x1C000) << 13) | ((*source & 0x03FF) << 13));
++target;
++source;
}
}
inline void float_to_half(half_float *target,const float *source,uint32 count)
{
while (count--)
{
*target = float2half(*source);
++target;
++source;
}
}
}//namespace hgl
#endif//HGL_HALF_FLOAT_INCLUDE

View File

@@ -77,55 +77,6 @@ namespace hgl
return double(floor(value*per))/per;
}
inline const float half_to_float(const uint16 &h)
{
union
{
float f;
uint32 u;
}x;
x.u=(((h&0x8000)<<16) | (((h&0x7c00)+0x1C000)<<13) | ((h&0x03FF)<<13));
return x.f;
}
inline void half_to_float(uint32 *target,const uint16 *source,uint32 count)
{
while (count--)
{
*target = (((*source & 0x8000) << 16) | (((*source & 0x7c00) + 0x1C000) << 13) | ((*source & 0x03FF) << 13));
++target;
++source;
}
}
inline void half_to_uint16(uint16 *target, const uint16 *source, uint32 count)
{
union
{
float f;
uint32 u;
}x;
while (count--)
{
x.u = (((*source & 0x8000) << 16) | (((*source & 0x7c00) + 0x1C000) << 13) | ((*source & 0x03FF) << 13));
*target=x.f*65535;
++target;
++source;
}
}
inline constexpr uint16 float_to_half(const float &f)
{
const uint32 x = *((uint32 *)&f);
return ((x>>16)&0x8000)|((((x&0x7f800000)-0x38000000)>>13)&0x7c00)|((x>>13)&0x03ff);
}
/**
* 正圆面积计算
* @param radius 半径

View File

@@ -35,5 +35,20 @@ namespace hgl
return result;
}
template<typename T,typename T2>
inline constexpr T Clamp(const T &value,const T2 &min_value,const T2 &max_value)
{
if(value<min_value)return min_value;
if(value>max_value)return max_value;
return value;
}
template<typename T>
inline constexpr T Clamp(const T &value)
{
return Clamp<T>(value,0,1);
}
}//namespace hgl
#endif//HGL_Primary_Mathematics_INCLUDE

View File

@@ -1,105 +0,0 @@
#ifndef HGL_COLOR_SPACE_INCLUDE
#define HGL_COLOR_SPACE_INCLUDE
#include<math.h>
namespace hgl
{
constexpr double GAMMA =2.4f;
constexpr double INV_GAMMA =1.0f/GAMMA;
constexpr double SRGB_ALPHA =0.055f;
template<typename T>
inline constexpr T sRGB2Linear(const T &in,const T &gamma=GAMMA,const T &srgb_alpha=SRGB_ALPHA)
{
if(in<=0.4045)
return (double)in/12.92;
else
return pow((double(in)+srgb_alpha)/(1.0f+srgb_alpha),gamma);
}
template<typename T>
inline constexpr T Linear2sRGB(const T &in,const T &inv_gamma=INV_GAMMA,const T &srgb_alpha=SRGB_ALPHA)
{
if(in<=0.0031308f)
return double(in)*12.92f;
else
return pow(double(in),inv_gamma)*(1.0f+srgb_alpha)-srgb_alpha;
}
template<typename T>
inline constexpr T sRGB2LinearCheaper(const T &in,const T &gamma=GAMMA)
{
return (T)pow(double(in),gamma);
}
template<typename T>
inline constexpr T Linear2sRGBCheaper(const T &in,const T &inv_gamma=INV_GAMMA)
{
return (T)pow((double)in,inv_gamma);
}
template<typename T>
inline constexpr T sRGB2LinearCheapest(const T &in)
{
return in*in;
}
template<typename T>
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<typename T>
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;
}
template<typename T>
inline constexpr T Clamp(const T &value,const T &min_value,const T &max_value)
{
if(value<min_value)return min_value;
if(value>max_value)return max_value;
return value;
}
template<typename T>
inline constexpr T Clamp(const T &value)
{
return Clamp<T>(value,T(0),T(1));
}
template<typename T>
inline constexpr T RGB2Lum(const T &r,const T &g,const T &b)
{
return 0.299f*r+0.587f*g+0.114f*b;
}
template<typename T>
inline constexpr T RGB2Cb(const T &r,const T &g,const T &b)
{
return -0.168736f*r-0.331264f*g+0.5f*b;
}
template<typename T>
inline constexpr T RGB2Cr(const T &r,const T &g,const T &b)
{
return 0.5f*r-0.418688f*g-0.081312f*b;
}
template<typename T>
inline void RGB2YCbCr(T &y,T &cb,T &cr,const T &r,const T &g,const T &b)
{
y =RGB2Lum(r,g,b);
cb=RGB2Cb(r,g,b);
cr=RGB2Cr(r,g,b);
}
}//namespace hgl
#endif//HGL_COLOR_SPACE_INCLUDE

View File

@@ -42,14 +42,8 @@ SOURCE_GROUP("Math\\Header Files" FILES ${MATH_HEADER_FILES})
SOURCE_GROUP("Math\\Source Files" FILES ${MATH_SOURCE_FILES})
##Color--------------------------------------------------------
SET(COLOR_HEADER_FILES ${TYPE_INCLUDE_PATH}/Color.h
${TYPE_INCLUDE_PATH}/ColorSpace.h
${TYPE_INCLUDE_PATH}/Color3f.h
${TYPE_INCLUDE_PATH}/Color4f.h)
SET(COLOR_SOURCE_FILES Color/Color.cpp
Color/Color3f.cpp
Color/Color4f.cpp)
FILE(GLOB COLOR_HEADER_FILES ${CMCORE_ROOT_INCLUDE_PATH}/hgl/color/*.h)
FILE(GLOB COLOR_SOURCE_FILES Color/*.cpp)
SOURCE_GROUP("Datatype\\Color\\Header Files" FILES ${COLOR_HEADER_FILES})
SOURCE_GROUP("Datatype\\Color\\Source Files" FILES ${COLOR_SOURCE_FILES})

View File

@@ -1,18 +1,38 @@
#include<hgl/type/Color.h>
#include<hgl/color/Color.h>
#include<hgl/color/YCbCr.h>
namespace hgl
{
#define DEF_RGB_U8_TO_F(r,g,b) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f}
#define DEF_RGBA_U8_TO_F(r,g,b,a) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f,float(a)/255.0f}
#define HEXColor3(value) (0x##value>>16),((0x##value&0xFF00)>>8),(0x##value&0xFF)
#define HEXColor3f(value) float(0x##value>>16)/255.0f,float((0x##value&0xFF00)>>8)/255.0f,float(0x##value&0xFF)/255.0f
struct COLOR_DEF
{
uint8 red,green,blue;
uint32 rgba;
uint32 abgr;
float r,g,b;
float y,cb,cr;
char eng_name[32];
u16char chs_name[16];
};
#undef DEF_COLOR
#define DEF_COLOR(eng_name,red,green,blue,chs_name) { \
red, \
green, \
blue, \
int(double(red)*0.299+double(green)*0.587+double(blue)*0.114), \
\
red,green,blue, \
(red<<24)|(green<<16)|(blue<<8), \
(blue<<16)|(green<<8)|red, \
float(double(red)/255.0f), \
float(double(green)/255.0f), \
float(double(blue)/255.0f), \
float((double(red)*0.299+double(green)*0.587+double(blue)*0.114)/255.0f),\
float(RGB2Lum(double(red)/255.0f,double(green)/255.0f,double(blue)/255.0f)),\
float(RGB2Cb(double(red)/255.0f,double(green)/255.0f,double(blue)/255.0f)),\
float(RGB2Cr(double(red)/255.0f,double(green)/255.0f,double(blue)/255.0f)),\
\
#eng_name, \
U16_TEXT(chs_name) \
@@ -278,6 +298,48 @@ namespace hgl
#undef DEF_COLOR
const uint32 GetRGBA(const enum class COLOR &ce,const uint8 &alpha)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
return c.rgba|alpha;
}
const uint32 GetABGR(const enum class COLOR &ce,const uint8 &alpha)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
return c.abgr|(alpha<<24);
}
const Color3f GetColor3f(const enum class COLOR &ce)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
return Color3f(c.r,c.g,c.b);
}
const Color4f GetColor4f(const enum class COLOR &ce,const float &alpha)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
return Color4f(c.r,c.g,c.b,alpha);
}
const Color3f GetYCbCrColor3f(const enum class COLOR &ce)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
return Color3f(c.y,c.cb,c.cr);
}
const Color4f GetYCbCrColor4f(const enum class COLOR &ce,const float &alpha)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
return Color4f(c.y,c.cb,c.cr,alpha);
}
/**
* 根据光谱值获取对应的RGB值
* @param l 光谱值(从400到700)

View File

@@ -1,6 +1,5 @@
#include<hgl/type/Color3f.h>
#include<hgl/type/Color.h>
#include<hgl/type/ColorSpace.h>
#include<hgl/color/Color3f.h>
#include<hgl/color/Color.h>
namespace hgl
{
void Color3f::Clamp()
@@ -31,15 +30,6 @@ namespace hgl
b+=(nb-b)*pos;
}
//--------------------------------------------------------------------------------------------------
void Color3f::Grey(float v1,float v2,float v3)
{
float lum=RGB2Lum(v1,v2,v3);
r=lum;
g=lum;
b=lum;
}
//--------------------------------------------------------------------------------------------------
void Color3f::Grey()
{
float lum=RGB2Lum(r,g,b);

View File

@@ -1,6 +1,5 @@
#include<hgl/type/Color4f.h>
#include<hgl/type/Color.h>
#include<hgl/type/ColorSpace.h>
#include<hgl/color/Color4f.h>
#include<hgl/color/Color.h>
namespace hgl
{
void Color4f::Clamp()

View File

@@ -23,15 +23,15 @@ namespace hgl
const int64 total=is->Available();
if(size)
*size=total;
if(total<=0)
return(nullptr);
void *result=new char[total];
*size=is->ReadFully(result,total);
int64 read_size=is->ReadFully(result,total);
if(size)
*size=read_size;
return result;
}
}//namespace io