【文件属性】:
文件名称:rgb转化为hsv
文件大小:1KB
文件格式:TXT
更新时间:2014-12-20 05:05:58
rgb、hsv
rgb转化为hsv的C++程序代码
#include "stdafx.h"
#include
void main(float R, float G, float B, float& H, float& S, float&V)
{
// r,g,b values are from 0 to 1
// h = [0,360], s = [0,1], v = [0,1]
// if s == 0, then h = -1 (undefined)
float min, max, delta,tmp;
tmp = R>G?G:R;
min = tmp>B?B:tmp;
tmp = R>G?R:G;
max = tmp>B?tmp:B;
V = max; // v
delta = max - min;
if( max != 0 )
S = delta / max; // s
else
{
// r = g = b = 0 // s = 0, v is undefined
S = 0;
H = 0;
return;
}
if (delta == 0){
H = 0;
return;
}
else if(R == max){
if (G >= B)
H = (G - B) / delta; // between yellow & magenta
else
H = (G - B) / delta + 6;
}
else if( G == max )
H = 2 + ( B - R ) / delta; // between cyan & yellow
else if (B == max)
H = 4 + ( R - G ) / delta; // between magenta & cyan
H *= 60; // degrees
}