Last active
December 16, 2015 16:49
-
-
Save rc1/5466427 to your computer and use it in GitHub Desktop.
How openFrameworks handles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename PixelType> | |
| void ofColor_<PixelType>::getHsb(float& hue, float& saturation, float& brightness) const { | |
| float max = getBrightness(); | |
| float min = r; | |
| if(g < min) { | |
| min = g; | |
| } | |
| if(b < min) { | |
| min = b; | |
| } | |
| if(max == min) { // grays | |
| hue = 0.f; | |
| saturation = 0.f; | |
| brightness = max; | |
| return; | |
| } | |
| float hueSixth; | |
| if(r == max) { | |
| hueSixth = (g - b) / (max - min); | |
| if(hueSixth < 0.f) | |
| hueSixth += 6.f; | |
| } else if (g == max) { | |
| hueSixth = 2.f + (b - r) / (max - min); | |
| } else { | |
| hueSixth = 4.f + (r - g) / (max - min); | |
| } | |
| hue = limit() * hueSixth / 6.f; | |
| saturation = limit() * (max - min) / max; | |
| brightness = max; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<> | |
| float ofColor_<float>::limit() { | |
| return 1.f; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment