Definition at line 656 of file rt_util.c.
656 {
657 int i;
658
659 double minc;
660 double maxc;
661
662 double h = 0.;
664 double v = 0.;
665
666 minc = rgb[0];
667 maxc = rgb[0];
668
669
670 for (i = 1; i < 3; i++) {
671 if (rgb[i] > maxc)
672 maxc = rgb[i];
673 if (rgb[i] < minc)
674 minc = rgb[i];
675 }
676 v = maxc;
677
678 if (maxc != minc) {
679 double diff = 0.;
680 double rc = 0.;
681 double gc = 0.;
682 double bc = 0.;
683 double junk = 0.;
684
685 diff = maxc - minc;
687 rc = (maxc - rgb[0]) / diff;
688 gc = (maxc - rgb[1]) / diff;
689 bc = (maxc - rgb[2]) / diff;
690
692 h = bc - gc;
693 else if (
DBL_EQ(rgb[1], maxc))
694 h = 2.0 + rc - bc;
695 else
696 h = 4.0 + gc - rc;
697
698 h = modf((h / 6.0), &junk);
699 }
700
701 hsv[0] = h;
703 hsv[2] = v;
704
706}
References DBL_EQ, ES_NONE, and s.
Referenced by test_rgb_to_hsv().