PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ rt_util_rgb_to_hsv()

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

Definition at line 559 of file rt_util.c.

559  {
560  int i;
561 
562  double minc;
563  double maxc;
564 
565  double h = 0.;
566  double s = 0.;
567  double v = 0.;
568 
569  minc = rgb[0];
570  maxc = rgb[0];
571 
572  /* get min and max values from RGB */
573  for (i = 1; i < 3; i++) {
574  if (rgb[i] > maxc)
575  maxc = rgb[i];
576  if (rgb[i] < minc)
577  minc = rgb[i];
578  }
579  v = maxc;
580 
581  if (maxc != minc) {
582  double diff = 0.;
583  double rc = 0.;
584  double gc = 0.;
585  double bc = 0.;
586  double junk = 0.;
587 
588  diff = maxc - minc;
589  s = diff / maxc;
590  rc = (maxc - rgb[0]) / diff;
591  gc = (maxc - rgb[1]) / diff;
592  bc = (maxc - rgb[2]) / diff;
593 
594  if (DBL_EQ(rgb[0], maxc))
595  h = bc - gc;
596  else if (DBL_EQ(rgb[1], maxc))
597  h = 2.0 + rc - bc;
598  else
599  h = 4.0 + gc - rc;
600 
601  h = modf((h / 6.0), &junk);
602  }
603 
604  hsv[0] = h;
605  hsv[1] = s;
606  hsv[2] = v;
607 
608  return ES_NONE;
609 }
char * s
Definition: cu_in_wkt.c:23
@ ES_NONE
Definition: librtcore.h:182
#define DBL_EQ(x, y)
Definition: librtcore.h:2426

References DBL_EQ, ES_NONE, and s.

Referenced by test_rgb_to_hsv().

Here is the caller graph for this function: