convert RGB to HLS
来源:互联网 发布:erp数据库设计 编辑:程序博客网 时间:2024/04/30 18:36
double hue2rgb( float p, float q, float rgb )
{
double color;
if ( rgb < 0.f ){
rgb = rgb + 1.f;
}
if ( rgb > 1.f ){
rgb = rgb - 1.f;
}
if ( 6.f * rgb < 1 )
{
color = p + ( q - p ) * 6.0 * rgb;
}
else if ( 2.0 * rgb < 1 )
{
color = q;
}
else if ( 3.0 * rgb < 2 )
{
color = p + ( q - p ) * ( ( 2.0 / 3.0 ) - rgb ) * 6.0;
}
else
{
color = p;
}
return color;
}
void rgb2hls(DWORD rgb, float &hue, float &lum, float &sat)
{
float r, g, b;
float rgb_min, rgb_max, delta;
r = GetRValue( rgb ) / 255.0; //Where RGB values = 0 / 255
g = GetGValue( rgb ) / 255.0;
b = GetBValue( rgb ) / 255.0;
rgb_max = max( r, max( g, b ) );
rgb_min = min( r, min( g, b ) );
delta = rgb_max - rgb_min;
if ( !delta ){
hue = 0.f;
sat = 0.f;
}
else if ( rgb_max == r ){
if ( g >= b ){
hue = 60 * ( g - b ) / delta;
}
else {
hue = 60 * ( g - b ) / delta + 360;
}
}
else if ( rgb_max == g){
hue = 60 * ( b - r ) / delta + 120;
}
else /*if ( rgb_max == b )*/{
hue = 60 * ( r - g ) / delta + 240;
}
lum = ( rgb_max + rgb_min ) / 2.f;
if ( lum == 0.f ){
sat = 0.f;
}
else if ( lum <= 0.5f ){
sat = delta / ( 2 * lum );
}
else {
sat = delta / ( 2 - 2 * lum );
}
}
void hls2rgb(float hue, float lum, float sat, DWORD &rgb)
{
float q, p;
float r, g, b;
float h;
float tr, tg, tb;
if ( sat == 0.f ){
r = hue * 255.f;
g = hue * 255.f;
b = hue * 255.f;
}
else {
if ( lum < 0.5f ){
q = lum * ( 1.f + sat );
}
else {
q = lum + sat - ( lum * sat );
}
p = 2.f * lum - q;
h = hue / 360.f;
//h = hue;
tr = h + 1.f / 3.0f;
tg = h;
tb = h - 1.f / 3.0f;
r = hue2rgb( p, q, tr );
g = hue2rgb( p, q, tg );
b = hue2rgb( p, q, tb );
r *= 255.f;
g *= 255.f;
b *= 255.f;
rgb = RGB( (BYTE)r, (BYTE)g, (BYTE)b );
}
}
Reference:
http://zh.wikipedia.org/wiki/HSL和HSV色彩空间
- convert RGB to HLS
- HLS实现bayer to RGB 转换
- Matrix to convert between HSL and RGB
- Matrix to convert between HSV and RGB
- Convert jQuery RGB output to Hex Color
- Convert ARGB to RGB without losing information
- Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both
- RGB HLS HSV
- ITU601 Matrix to convert between YCbCr and RGB
- ITU709 Matrix to convert between YCbCr and RGB
- EBU Matrix to convert between YCbCr and RGB
- MS Matrix to convert between YCbCr and RGB
- YUVtoRGB RGB to YUV color convert formulas - ITU 601
- Android OpenGL es GPUImage convert YUV to RGB
- How to Convert Temperature (K) to RGB: Algorithm and Sample Code
- convert RGB image to a 2x2 [GR;BG] Bayer pattern
- Convert RGB to L*a*b* (Lab Color space) in OpenCV
- Csharp: Winform 顏色選擇器 Color convert RGB and RGB convert Color
- WinCE下重新设置IP地址无需重新启动
- 我的同事们(五): Liang Chen
- Key-Value Coding (KVC) and Generic Programming
- 去掉你的书呆子气 (摘自《青年怎样适应社会》)
- 非有序全排列生成算法集锦
- convert RGB to HLS
- Global.asax sql防注入
- .Net多线程总结
- 非有序全排列生成算法
- 两种方法改变信号的值【只是两种语法】
- 书呆子气
- PowerDesigner教程系列
- fedora 8 named.conf文件配置
- IP Networking Control Files