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.;
515 double v = 0.;
516
517 minc = rgb[0];
518 maxc = rgb[0];
519
520
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;
538 rc = (maxc - rgb[0]) / diff;
539 gc = (maxc - rgb[1]) / diff;
540 bc = (maxc - rgb[2]) / diff;
541
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;
554 hsv[2] = v;
555
557}
References DBL_EQ, ES_NONE, and s.
Referenced by test_rgb_to_hsv().