Inverting Colour

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Inverting Colour

Post by KungFooMasta »

Something small and easy to implement, and useful in certain situations. I have an Ogre::ColourValue, and I want its inverse color, for example: White -> Black, or vice versa.

I think I know how to implement this, but wanted to throw it out there, since having an invert function specific to my own class doesn't really help anybody else (nor does it really fit into my "Text" class..). Would be nice if there was a function Ogre::ColourValue Ogre::ColourValue::invertedColour();

Code: Select all

Ogre::ColourValue c = myColourValue.invertedColour();
Or something like that. :)

(I want to use the term "inverse", but not sure if that is correct terminology, or what the correct terminology is. :P )

Haven't tested this, but I think the code would look something like:

Code: Select all

	Ogre::ColourValue Text::getInverseColor(const Ogre::ColourValue& c)
	{
		return Ogre::ColourValue(
			1.0 - c.r,
			1.0 - c.g,
			1.0 - c.b,
			c.a);
	}
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58
Contact:

Post by betajaen »

I was just looking up some code for you and you pasted it in. Tsk.

Shouldn't negative be a better word, since it looks like a photograph negative?
User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Post by Praetor »

The only problem I see is that nothing explicitly clamps colo(u)rs to 0.0-1.0 range. While this may be true in practice for the final output, I wouldn't want it assumed in the rest of the pipeline. We're in a stage now where programs might be dealing with brighter-than-white colors. This doesn't mean the feature can't be implemented, just that we'd need a more complicated algorithm for doing it.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Post by sinbad »

Colours are mostly in the 0-1 range, except when talking about HDR. ColourValue can store HDR values too.
Post Reply