RGB TO HSV Color Model Color Model Source Code Algorithm C Programming CS1355-Graphics And Multimedia Lab

This is reverse programming for the HSV to RGB. It is use the mathematical algorithm for performing color model conversion ant there all the value are represent as Float data types.
Source code for RGB TO HSV Color Modelin C language programming
#define MIN(a,b)(a<b?a:b)
#define MAX(a,b)(a>b?a:b)
#define NO_HUE-1
void rgbtohsv(float r,float g,float b)
{
float *h;
float *s;
float *v;
float max=MAX(r,MAX(g,b));
float min=MIN(r,MIN(g,b));
float delta=max-min;
*v=max;
if(max!=0.0)
{
*s=delta/max;
}
else
{
*s=0.0;
}
if (*s==0.0)
{
*h=NO_HUE;
}
else
{
if(r==max)
{
*h=(g-b)/delta;
}
else if(g==max)
{
*h=2+(b-r)/delta;
}
else if(b==max)
{
*h=4+(r-g)/delta;
*h*=60.0;
if(*h<0)*h+=360.0;
*h/=360.0;
}
}
printf("The HSV values are:\nH=%f\nS=%f\nV=%f",*h,*s,*v);
}
void main()
{
float a,b,c;
clrscr();
printf("Enter the RGB Values");
scanf("%f%f%f",&a,&b,&c);
printf(“The HSV Values are:”);
rgbtohsv(a,b,c);
getch();
}

Related post