PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ rt_util_rgb_to_hsv()

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

Definition at line 551 of file rt_util.c.

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

References DBL_EQ, ES_NONE, and s.

Referenced by test_rgb_to_hsv().

Here is the caller graph for this function: