PostGIS  3.4.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 554 of file rt_util.c.

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

References DBL_EQ, ES_NONE, and s.

Referenced by test_rgb_to_hsv().

Here is the caller graph for this function: