Some color manipulation issues seem to regularly pop up:
- RGB <-> HSV conversion
- map, lerp, normalize colors
- floating point vs 8-byte colors
- color matching in HSV or RGB space
- color math and blending
- being able to do fast per-pixel operations, but also
- being able to manage more abstract palettes of colors with sorting operations
OpenCV can do a lot of the above, but ofxColor is working towards an OF-style color library that stands on its own.
It’s a work in progress, and I currently only have the basic architecture and core functions laid out. ofBaseColor (the OOP-interface to the routines) needs the most work. I’m not in the middle of a color-intensive project right now, so I can’t test everything… but I wanted to get a basic structure that will work in the future.
It’s available via SVN with a C::B example here.
Any help/suggestions/criticism/etc. would be hugely appreciated!
Here’s output from the demo app, to give a feeling for how it works:
ofxColorf myColor(.1, .2, .3);
(0.1, 0.2, 0.3, 1)
myColor.setRange(255);
(25.5, 51, 76.5, 255)
myColor.setMode(OF_COLOR_HSV);
(148.75, 170, 76.5, 255)
myColor.normalize();
(0.583333, 0.666667, 0.3, 255)
myColor.setMode(OF_COLOR_RGB);
(0.1, 0.2, 0.3, 255)
myColor.reset();
(0, 0, 0, 1)
myColor.set(.1, .2, .3).setRange(255).setMode(OF_COLOR_HSV).normalize().setMode(OF_COLOR_RGB);
(0.1, 0.2, 0.3, 255)
myColor.setRed(1.1).clamp();
(1, 0.2, 0.3, 255)
target.set(0, 1, 0).setRange(255);
myColor.lerp(target, .8);
(0.2, 0.84, 0.06, 255)
myColor.set(0, 1, 0).distance(target.set(255, 0, 0);
1.41421