Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

ofColor clamp #1960

emmanuelgeoffray opened this Issue Mar 20, 2013 · 3 comments


None yet
3 participants

Running this:

ofColor c;
c +=  150;
cout << "c: " << c.getBrightness() << endl;                                    
c +=  150;                                                                     
cout << "c: " << c.getBrightness() << endl;

I got this output:

c: 150
c: 44

Which is obviously an overflow.
I expected:

c: 150
c: 255

Am I right to expect a clamping at 255?

I use ofFloatColor instead which doesn't have an overflow issue.
But as it was discussed in issue #728, it's a bit confusing.
I think a beginner would use ofColor, and should not face an overflow issue.
What do you think?

Thank you for your enlightenment!


kylemcdonald commented Mar 25, 2013

i'm going to take the position that clamping should work correctly on all colors, even the usual ofColor, so i'll say this is a bug.

how do other people feel about this? is there ever a situation where you would want an ofColor to overflow?

if not, let's get a fix for this bug that is as efficient and elegant as possible :)

This was referenced Jun 19, 2013


DomAmato commented Aug 10, 2015

I think this is fixed and can be closed as they are handled by a specific clamping function depending on the type of operation performed


kylemcdonald commented Aug 10, 2015

yes, this is fixed now. the output is:

c: 150
c: 255

closing. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment