added GetSpectralColor function.

This commit is contained in:
2021-05-06 16:43:50 +08:00
parent 0a7b1ff3af
commit 6d0547ca13
2 changed files with 29 additions and 0 deletions

View File

@@ -4,6 +4,8 @@
#include<hgl/platform/Platform.h>
namespace hgl
{
void GetSpectralColor(double &r,double &g,double &b,const double l); ///<根据光谱值获取对应的RGB值
/**
* 颜色数据定义
*/

View File

@@ -227,4 +227,31 @@ namespace hgl
};
#undef DEF_COLOR
/**
* 根据光谱值获取对应的RGB值
* @param l 光谱值(从400到700)
* @return r/g/b 该光谱对应的RGB(0至1)
*/
void GetSpectralColor(double &r,double &g,double &b,const double l)
{
double t;
r=0.0;
g=0.0;
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); }
else if ((l>=545.0)&&(l<595.0)) { t=(l-545.0)/(595.0-545.0); r= +(1.98*t)-( t*t); }
else if ((l>=595.0)&&(l<650.0)) { t=(l-595.0)/(650.0-595.0); r=0.98+(0.06*t)-(0.40*t*t); }
else if ((l>=650.0)&&(l<700.0)) { t=(l-650.0)/(700.0-650.0); r=0.65-(0.84*t)+(0.20*t*t); }
if ((l>=415.0)&&(l<475.0)) { t=(l-415.0)/(475.0-415.0); g= +(0.80*t*t); }
else if ((l>=475.0)&&(l<590.0)) { t=(l-475.0)/(590.0-475.0); g=0.8 +(0.76*t)-(0.80*t*t); }
else if ((l>=585.0)&&(l<639.0)) { t=(l-585.0)/(639.0-585.0); g=0.84-(0.84*t) ; }
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); }
}
}//namespace hgl