I need to convert my RGB colors to HSB while I do some color interpolation and then back to RGB, I look at the ofColor class and can see a few set/get methods related to hsb but I cant work out how to use them.
Any help will be much appreciated
Hello. 007 have this functions to get HSB colors
float getHue () const;
float getSaturation () const;
float getBrightness () const; // brightest component
float getLightness () const; // average of the components
void getHsb(float& hue, float& saturation, float& brightness) const;
First start by setting a RGB color
color.set(0,255,0); //Green color
And then you can choose to ways of doing it.
// A way
h = color.getHue();
s = color.getSaturation();
b = color.getBrightness();
// B way
// For checking
cout << "Hue: " << h << endl;
cout << "Saturation: " << s << endl;
cout << "Brightness: " << b << endl;
Note that in the B way you are using reference operators http://www.cplusplus.com/doc/tutorial/pointers/
I almost got it, but struggle with the input values, HSB is usually H: 0 - 360, and S, B: 0 - 100 so I got confuse there.
What value range do I need to feed getHsb() for a more straight forward approach? can you provide an example?
You could just map them like:
brightness = color.getBrightness();
ofMap(brightness, 0, 255, 0, 100, true);
I noticed that doing
color.set(255, 255, 255);
color.getHsb(hue, saturation, brightness);
cout << " 1: " << hue << " " << saturation << " " << brightness << endl;
1: 0 0 65025
which seems off, b/c the getBrightness() method returns 255 for that.