PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rt_util_rgb_to_hsv()

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

Definition at line 505 of file rt_util.c.

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

References DBL_EQ, ES_NONE, and s.

Referenced by test_rgb_to_hsv().

Here is the caller graph for this function: