PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ rt_util_rgb_to_hsv()

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

Definition at line 507 of file rt_util.c.

507  {
508  int i;
509 
510  double minc;
511  double maxc;
512 
513  double h = 0.;
514  double s = 0.;
515  double v = 0.;
516 
517  minc = rgb[0];
518  maxc = rgb[0];
519 
520  /* get min and max values from RGB */
521  for (i = 1; i < 3; i++) {
522  if (rgb[i] > maxc)
523  maxc = rgb[i];
524  if (rgb[i] < minc)
525  minc = rgb[i];
526  }
527  v = maxc;
528 
529  if (maxc != minc) {
530  double diff = 0.;
531  double rc = 0.;
532  double gc = 0.;
533  double bc = 0.;
534  double junk = 0.;
535 
536  diff = maxc - minc;
537  s = diff / maxc;
538  rc = (maxc - rgb[0]) / diff;
539  gc = (maxc - rgb[1]) / diff;
540  bc = (maxc - rgb[2]) / diff;
541 
542  if (DBL_EQ(rgb[0], maxc))
543  h = bc - gc;
544  else if (DBL_EQ(rgb[1], maxc))
545  h = 2.0 + rc - bc;
546  else
547  h = 4.0 + gc - rc;
548 
549  h = modf((h / 6.0), &junk);
550  }
551 
552  hsv[0] = h;
553  hsv[1] = s;
554  hsv[2] = v;
555 
556  return ES_NONE;
557 }
char * s
Definition: cu_in_wkt.c:23
@ ES_NONE
Definition: librtcore.h:180
#define DBL_EQ(x, y)
Definition: librtcore.h:2237

References DBL_EQ, ES_NONE, and s.

Referenced by test_rgb_to_hsv().

Here is the caller graph for this function: