PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rt_util_hsv_to_rgb()

rt_errorstate rt_util_hsv_to_rgb ( double  hsv[3],
double  rgb[3] 
)

Definition at line 557 of file rt_util.c.

References DBL_EQ, ES_NONE, and r.

Referenced by test_hsv_to_rgb().

557  {
558  double r = 0;
559  double g = 0;
560  double b = 0;
561  double v = hsv[2];
562 
563  if (DBL_EQ(hsv[1], 0.))
564  r = g = b = v;
565  else {
566  double i;
567  double f;
568  double p;
569  double q;
570  double t;
571 
572  int a;
573 
574  i = floor(hsv[0] * 6.);
575  f = (hsv[0] * 6.0) - i;
576  p = v * (1. - hsv[1]);
577  q = v * (1. - hsv[1] * f);
578  t = v * (1. - hsv[1] * (1. - f));
579 
580  a = (int) i;
581  switch (a) {
582  case 1:
583  r = q;
584  g = v;
585  b = p;
586  break;
587  case 2:
588  r = p;
589  g = v;
590  b = t;
591  break;
592  case 3:
593  r = p;
594  g = q;
595  b = v;
596  break;
597  case 4:
598  r = t;
599  g = p;
600  b = v;
601  break;
602  case 5:
603  r = v;
604  g = p;
605  b = q;
606  break;
607  case 0:
608  case 6:
609  default:
610  r = v;
611  g = t;
612  b = p;
613  break;
614  }
615  }
616 
617  rgb[0] = r;
618  rgb[1] = g;
619  rgb[2] = b;
620 
621  return ES_NONE;
622 }
char * r
Definition: cu_in_wkt.c:24
#define DBL_EQ(x, y)
Definition: librtcore.h:2187
Here is the caller graph for this function: