Description: rgb to HSV,#include "stdafx.h"
#include <iostream.h>
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 == ma
To Search:
File list (Check if you may need any files):
成功程序.txt