PostGIS  3.1.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 508 of file rt_util.c.

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