-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHSV_to_RGB.cpp
More file actions
56 lines (47 loc) · 1.22 KB
/
Copy pathHSV_to_RGB.cpp
File metadata and controls
56 lines (47 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Shabbir Mahmood ID: 14015439 Part-3 Even Computer Graphics Lab HSV to RGB Conversion Date: 01-02-2017*/
#include<bits/stdc++.h>
using namespace std;
float r,g,b;
void hsvToRgb(float h,float s,float v) // Input of HSV Color Model
{
int i;
float aa,bb,cc,f;
if(s==0) // GrayScale
{
r=g=b=v;
}
else
{
if(h==1.0)
{
h=0;
}
h = h*6.0;
i = floor(h);
f = h-i;
aa = v*(1-s);
bb = v*(1-(s*f));
cc = v*(1-(s*(1-f)));
switch (i)
{
case 0: r = v; g = cc; b = aa; break;
case 1: r = bb; g = v; b = aa; break;
case 2: r = aa; g = v; b = cc; break;
case 3: r = aa; g = bb; b = v; break;
case 4: r = cc; g = aa; b = v; break;
case 5: r = v; g = aa; b = bb; break;
}
}
}
int main()
{
float h,s,v;
cout<<"Enter the Values(H S V):"<<endl;
cin>>h>>s>>v;
hsvToRgb(h,s,v);
cout<<"Conversion from HSV to RGB"<<endl;
cout<<"R = "<<r<<endl;
cout<<"G = "<<g<<endl;
cout<<"B = "<<b<<endl;
return 0;
}