HSV to RGB Color Model Source Code Algorithm C Programming CS1355-Graphics and Multimedia Lab

RGB it is refers to the Red , Green Blue, and HSV refers to the Hue Saturation and value, hue it represent angle it is vary from 0 to 360 degrees. There color model conversion program is simply done by mathematical algorithm so we are using math.h header file from C language.Following diagram it is illustrate HSV color model.Diagram origin stage when v is equal to zero it is become black and depends upon there degree it will change there color. HSV to RGB Color Model Source Code Algorithm C ProgrammingSource code HSV to RGB Programming
#include<stdio.h>
#include<conio.h>
#include<math.h>
void hsvtorgb(float h,float s,float v)
{
float *r,*g,*b;
int i;
float aa,bb,cc,f;
if(s==0)
{
*r=*g=*b=v;
}
else
{
if(h==1.0)
h=0;
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;
printf("R=%f,G=%f,B=%f",*r,*g,*b);
break;
}
case 1:
{
*r=bb;*g=v;*b=aa;
printf("R=%f,G=%f,B=%f",*r,*g,*b);
break;
}
case 2:
{
*r=aa;*g=cc;*b=v;
printf("R=%f,G=%f,B=%f",*r,*g,*b);
break;
}
case 3:
{
*r=aa;*g=bb;*b=v;
printf("R=%f,G=%f,C=%f",*r,*g,*b);
break;
}
case 4:
{
*r=cc;*g=aa;*b=v;
printf("R=%f,G=%f,B=%f",*r,*g,*b);
break;
}
case 5:
{
*r=v;*g=aa;*b=bb;
printf("R=%f,G=%f,B=%f",*r,*g,*b);
break;
}
}
}
}
void main()
{
float a,b,c;
clrscr();
printf("Enter the HSV values");
scanf("%f%f%f",&a,&b,&c);
printf(“The RGB Values are:”);
hsvtorgb(a,b,c);
getch();
}

Related post