標(biāo)題:
C語言HSL轉(zhuǎn)RGB程序
[打印本頁]
作者:
艾爾之光tt
時(shí)間:
2021-9-7 12:27
標(biāo)題:
C語言HSL轉(zhuǎn)RGB程序
這樣的程序,隨機(jī)輸入一些,得出的結(jié)果都是b的值。r,g兩個(gè)的值都是b的值。輸入范圍是正常的HSL數(shù)值范圍。
float hue2rgb(float p,float q,float t){
if(t < 1/6)
{
return p + (q - p) * 6 * t;
}
if(1/6<=t&&t < 1/2)
{
return q;
}
if(1/2<=t&&t < 2/3) {
return p + (q - p) * (2/3 - t) * 6;
}
return p;
}
float hslToRgb(float h, float s, float l){
float q,p;
float r,g,b;
h=h/360;
s=s/100;
l=l/100;
if(s == 0){
r = g = b = l; // achromatic
}else{
if(l<0.5){
q=l * (1 + s);
}else{
q=l + s - l * s;
}
if(h < 0) h=h+ 1;
if(h > 1) h=h- 1;
p = 2 * l - q;
r = 255*hue2rgb(p, q, h+1/3);
g =255* hue2rgb(p, q, h);
b =255* hue2rgb(p, q, h-1/3);
}
return b;
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1