Skip to content

Instantly share code, notes, and snippets.

@rc1
Last active December 16, 2015 16:49
Show Gist options
  • Select an option

  • Save rc1/5466427 to your computer and use it in GitHub Desktop.

Select an option

Save rc1/5466427 to your computer and use it in GitHub Desktop.
How openFrameworks handles
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;
}
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