我想用RGB转换成HLS或者HSV的格式 但是一开始怎么把RGB565的像素点转换成值域为0-255的三原色值 求一个算法程序 最好有注释
在线等 着急啊
下面是我把RGB转成HLS的程序 可参考
int r, g, b;
int h, l, s;
int max, min, dif;
r = color_rgb->Red; //红色
g = color_rgb->Green;//绿色
b = color_rgb->Blue; //蓝色
max = maxOf3Values( r, g, b );
min = minOf3Values( r, g, b );
dif = max - min;
//计算l,亮度
l = ( max + min ) * 240 / 255 / 2;
//计算h,色度
if( max == min )//无定义
{
s = 0;
h = 0;
}
else
{
//计算色度
if( max == r )
{
if( min == b )//h介于0到40
{
h = 40 * ( g - b ) / dif;
}
else if( min == g )//h介于200到240
{
h = 40 * ( g - b ) / dif + 240;
}
}
else if( max == g )
{
h = 40 * ( b - r ) / dif + 80;
}
else if( max == b )
{
h = 40 * ( r - g ) / dif + 160;
}
//计算饱和度
if( l == 0 )
{
s = 0;
}
else if( l <= 120 )
{
s = dif * 240 / ( max + min );
}
else
{
s = dif * 240 / ( 480 - ( max + min ) );
}
}
color_hls->Hue = h; //色度
color_hls->Lightness = l; //亮度
color_hls->Saturation = s; //饱和度
注:程序来自网上资料
|