PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_errorstate rt_util_rgb_to_hsv ( double  rgb[3],
double  hsv[3] 
)

Definition at line 611 of file rt_api.c.

References DBL_EQ, ES_NONE, and s.

Referenced by test_rgb_to_hsv().

611  {
612  int i;
613 
614  double minc;
615  double maxc;
616 
617  double h = 0.;
618  double s = 0.;
619  double v = 0.;
620 
621  minc = rgb[0];
622  maxc = rgb[0];
623 
624  /* get min and max values from RGB */
625  for (i = 1; i < 3; i++) {
626  if (rgb[i] > maxc)
627  maxc = rgb[i];
628  if (rgb[i] < minc)
629  minc = rgb[i];
630  }
631  v = maxc;
632 
633  if (maxc != minc) {
634  double diff = 0.;
635  double rc = 0.;
636  double gc = 0.;
637  double bc = 0.;
638  double junk = 0.;
639 
640  diff = maxc - minc;
641  s = diff / maxc;
642  rc = (maxc - rgb[0]) / diff;
643  gc = (maxc - rgb[1]) / diff;
644  bc = (maxc - rgb[2]) / diff;
645 
646  if (DBL_EQ(rgb[0], maxc))
647  h = bc - gc;
648  else if (DBL_EQ(rgb[1], maxc))
649  h = 2.0 + rc - bc;
650  else
651  h = 4.0 + gc - rc;
652 
653  h = modf((h / 6.0), &junk);
654  }
655 
656  hsv[0] = h;
657  hsv[1] = s;
658  hsv[2] = v;
659 
660  return ES_NONE;
661 }
#define DBL_EQ(x, y)
Definition: rt_api.h:2161
char * s
Definition: cu_in_wkt.c:24

Here is the caller graph for this function: