The ofColor subtraction operator doesn’t work as I would expect: negative results aren’t clamped to 0, but to some positive value:
ofColor a(10, 40, 80);
ofColor b(20, 5, 30);
ofColor c = (a-b); // I get: (246, 45, 50), I would expect: (0, 45, 50)
Im a beginner, so maybe i’m missing something? Is it feature or bug?
And maybe there’s some other way to find a difference between two colors?
Thanks!
Pawe?
naus3a
April 3, 2012, 10:03am
#2
your red channel goes from 0 to 255; 10-20 = -10, but, since your lower limit is 0, your red channel resets to 255
I would consider this a bug. When subtracting some value from a color, the last thing you’d expect is the value to be higher afterwards.
naus3a
April 3, 2012, 2:35pm
#4
imho it depends on the scenario: sometimes something that behaves like a circular buffer could be handy
True, but I think that should really be the exception, not the rule. It’s not a complicated thing to implement so if you ask me we should let it be the task of the programmer.
Hue in HSV colour model is an example of a circular behaviour.
According to the documentation (http://www.openframeworks.cc/documentation/types/ofColor-.html#operator+ ) operator- should clamp, so this may be a genuine bug. please open an issue at https://github.com/openframeworks/openFrameworks/issues
Afaik ofColor only clamps on rgb, not hsv, which might cause some math problems. Definitely should be be an issue filed for that.
Thanks for all the replies, I’m opening an issue on github then.