PostGIS  2.4.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 503 of file rt_util.c.

References DBL_EQ, ES_NONE, and s.

Referenced by test_rgb_to_hsv().

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