Implementation of Color Conversion from HSV to RGB [CS1255 - Graphics and Multimedia Lab]

AIM:
             To write a "C++" program for the Implementation of Color Conversion from HSV to RGB in CS1255 - Graphics and Multimedia Lab.

SOURCE CODE:

#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;
   printf("R=%f\tG=%f\tB=%f\n",*r,*g,*b);
  }
  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\nG=%f\nB=%f\n",*r,*g,*b);
    break;
    case 1:
    *r=bb;*g=v;*b=aa;
    printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
    break;
    case 2:
    *r=aa;*g=cc;*b=v;
    printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
    break;
    case 3:
    *r=aa;*g=bb;*b=v;
    printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
    break;
    case 4:
    *r=cc;*g=aa;*b=v;
    printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
    break;
    case 5:
    *r=v;*g=aa;*b=bb;
    printf("R=%f\nG=%f\nB=%f\n",*r,*g,*b);
    break;
   }
  }
}
void main()
{
  float a,b,c;
  clrscr();
  printf("\n Enter the HSV values:\n");
  scanf("%f%f%f",&a,&b,&c);
  printf("\nThe RGB values:\n");
  hsvtorgb(a,b,c);
  getch();
}

OUTPUT: 

Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: