cleared "COLOR enum class" at Color3f/4f
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include<hgl/platform/Platform.h>
|
||||
#include<hgl/TypeFunc.h>
|
||||
#include<hgl/type/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}
|
||||
@@ -18,7 +19,7 @@ namespace hgl
|
||||
return red*0.299+green*0.587+blue*0.114;
|
||||
}
|
||||
|
||||
void GetSpectralColor(double &r,double &g,double &b,const double l); ///<根据光谱值获取对应的RGB值
|
||||
const Color3f GetSpectralColor(const double l); ///<根据光谱值获取对应的RGB值
|
||||
|
||||
/**
|
||||
* 颜色数据定义
|
||||
@@ -288,5 +289,19 @@ namespace hgl
|
||||
};//enum COLOR_ENUM
|
||||
|
||||
extern COLOR_DEF prv_color[size_t(COLOR::RANGE_SIZE)];
|
||||
|
||||
inline 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}//namespace hgl
|
||||
#endif//HGL_COLOR_TABLE_INCLUDE
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#ifndef HGL_COLOR_3_FLOAT_INCLUDE
|
||||
#define HGL_COLOR_3_FLOAT_INCLUDE
|
||||
|
||||
#include<hgl/type/Color.h>
|
||||
namespace hgl
|
||||
{
|
||||
/**
|
||||
@@ -18,12 +17,10 @@ namespace hgl
|
||||
public:
|
||||
|
||||
Color3f(){r=0,g=0,b=0;} ///<本类构造函数
|
||||
Color3f(COLOR ce){Use(ce);} ///<本类构造函数
|
||||
Color3f(float l){r=l,g=l,b=l;Clamp();} ///<本类构造函数
|
||||
Color3f(float vr,float vg,float vb){r=vr,g=vg,b=vb;Clamp();} ///<本类构造函数
|
||||
Color3f(const Color3f &v){r=v.r;g=v.g;b=v.b;Clamp();} ///<本类构造函数
|
||||
|
||||
void Use(COLOR);
|
||||
void Zero(){r=0,g=0,b=0;} ///<全清为0
|
||||
void One() {r=1,g=1,b=1;} ///<全清为1
|
||||
void Rand(); ///<全随机
|
||||
@@ -54,7 +51,6 @@ namespace hgl
|
||||
|
||||
//操作符重载
|
||||
void operator = (const float *v){r=*v++;g=*v++;b=*v;}
|
||||
void operator = (COLOR ce){Use(ce);}
|
||||
|
||||
bool operator == (const Color3f &);
|
||||
bool operator != (const Color3f &);
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define HGL_COLOR_4_FLOAT_INCLUDE
|
||||
|
||||
#include<hgl/type/Color3f.h>
|
||||
#include<hgl/type/DataType.h>
|
||||
namespace hgl
|
||||
{
|
||||
#define HGL_FLOAT_TO_U32(c1,c2,c3,c4) uint32( \
|
||||
@@ -29,13 +30,10 @@ namespace hgl
|
||||
public:
|
||||
|
||||
Color4f(){r=0,g=0,b=0,a=1;} ///<本类构造函数
|
||||
Color4f(COLOR ce){Use(ce,1);} ///<本类构造函数
|
||||
Color4f(COLOR ce,float ta){Use(ce,ta);} ///<本类构造函数
|
||||
Color4f(float v){r=v,g=v,b=v,a=1;Clamp();} ///<本类构造函数
|
||||
Color4f(float vr,float vg,float vb,float va){r=vr,g=vg,b=vb;a=va;Clamp();} ///<本类构造函数
|
||||
Color4f(const Color3f &v,float va=1){Set(v,va);} ///<本类构造函数
|
||||
|
||||
void Use(COLOR,float);
|
||||
void Zero(){r=0,g=0,b=0,a=0;} ///<全清为0
|
||||
void One() {r=1,g=1,b=1,a=1;} ///<全清为1
|
||||
|
||||
@@ -65,7 +63,6 @@ namespace hgl
|
||||
void operator = (const float *v){r=*v++;g=*v++;b=*v++;a=*v;}
|
||||
void operator = (const Color3f &v){r=v.r;g=v.g;b=v.b;a=1;}
|
||||
void operator = (const Color4f &v){r=v.r;g=v.g;b=v.b;a=v.a;}
|
||||
void operator = (COLOR ce){Use(ce,a);}
|
||||
|
||||
bool operator == (const Color4f &);
|
||||
bool operator != (const Color4f &);
|
||||
|
@@ -281,15 +281,14 @@ namespace hgl
|
||||
/**
|
||||
* 根据光谱值获取对应的RGB值
|
||||
* @param l 光谱值(从400到700)
|
||||
* @return r/g/b 该光谱对应的RGB(0至1)
|
||||
*/
|
||||
void GetSpectralColor(double &r,double &g,double &b,const double l)
|
||||
const Color3f GetSpectralColor(const double l)
|
||||
{
|
||||
double t;
|
||||
|
||||
r=0.0;
|
||||
g=0.0;
|
||||
b=0.0;
|
||||
double r=0.0;
|
||||
double g=0.0;
|
||||
double b=0.0;
|
||||
|
||||
if ((l>=400.0)&&(l<410.0)) { t=(l-400.0)/(410.0-400.0); r= +(0.33*t)-(0.20*t*t); }
|
||||
else if ((l>=410.0)&&(l<475.0)) { t=(l-410.0)/(475.0-410.0); r=0.14 -(0.13*t*t); }
|
||||
@@ -303,5 +302,7 @@ namespace hgl
|
||||
|
||||
if ((l>=400.0)&&(l<475.0)) { t=(l-400.0)/(475.0-400.0); b= +(2.20*t)-(1.50*t*t); }
|
||||
else if ((l>=475.0)&&(l<560.0)) { t=(l-475.0)/(560.0-475.0); b=0.7 -( t)+(0.30*t*t); }
|
||||
|
||||
return Color3f(r,g,b);
|
||||
}
|
||||
}//namespace hgl
|
||||
|
@@ -1,15 +1,7 @@
|
||||
#include<hgl/type/Color3f.h>
|
||||
#include<hgl/type/Color.h>
|
||||
namespace hgl
|
||||
{
|
||||
void Color3f::Use(COLOR ce)
|
||||
{
|
||||
const COLOR_DEF *pc=prv_color+size_t(ce);
|
||||
|
||||
r=pc->r;
|
||||
g=pc->g;
|
||||
b=pc->b;
|
||||
}
|
||||
|
||||
void Color3f::Clamp()
|
||||
{
|
||||
if(r<0)r=0;if(r>1)r=1;
|
||||
@@ -40,7 +32,7 @@ namespace hgl
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Color3f::Grey(float v1,float v2,float v3)
|
||||
{
|
||||
float lum=v1*0.299+v2*0.587+v3*0.114;
|
||||
float lum=RGB2Lum(v1,v2,v3);
|
||||
|
||||
r=lum;
|
||||
g=lum;
|
||||
@@ -49,7 +41,7 @@ namespace hgl
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Color3f::Grey()
|
||||
{
|
||||
float lum=r*0.299+g*0.587+b*0.114;
|
||||
float lum=RGB2Lum(r,g,b);
|
||||
|
||||
r=lum;
|
||||
g=lum;
|
||||
|
@@ -1,16 +1,7 @@
|
||||
#include<hgl/type/Color4f.h>
|
||||
#include<hgl/type/Color.h>
|
||||
namespace hgl
|
||||
{
|
||||
void Color4f::Use(COLOR ce,float ta)
|
||||
{
|
||||
const COLOR_DEF *pc=prv_color+size_t(ce);
|
||||
|
||||
r=pc->r;
|
||||
g=pc->g;
|
||||
b=pc->b;
|
||||
a=ta;
|
||||
}
|
||||
|
||||
void Color4f::Clamp()
|
||||
{
|
||||
if(r<0)r=0;if(r>1)r=1;
|
||||
@@ -42,7 +33,7 @@ namespace hgl
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Color4f::Grey()
|
||||
{
|
||||
float lum=r*0.299+g*0.587+b*0.114;
|
||||
float lum=RGB2Lum(r,g,b);
|
||||
|
||||
r=lum;
|
||||
g=lum;
|
||||
|
Reference in New Issue
Block a user