A while back, I devised a method of providing named colors which could be adapted to any given background color, with a reasonable guarantee of readability. Anyone interested in the details can check out my previous two entries about it:
- Overengineering beyond all reasonable limits: automatic color palette optimization
- Color optimization, take two
There’s been some interest in this approach from a variety of people for different projects. I even went so far as to create a patch to put this inside GTK+. Unsurprisingly, this patch hasn’t even been looked at due to the maintainer shortage.
So, I’m trying a different approach. I’ve cleaned up the code, slapped the MIT/X11 license on it, and put it in a separate directory to make it easy to cherry-pick. This is kind of libegg-ish right now, though I’d like to make it easier to have an “upstream”. If anyone has any ideas about making this more friendly for svn:externals (viz. Makefile.am), I’d love to hear them!
Get it now from SVN at http://svn.gnome.org/svn/xchat-gnome/trunk/src/libcontrast/



As a result of this, colors against a white background tend to be dark, while colors against a black background tend to be light. By defining white and black as regions which have some breadth in the value dimension, white-on-white text and black-on-black text become readable. When on a grey background, text gets pushed in either direction depending on whichever is furthest away in the HSV color space. For the most part, this works very well (you can see the purple color has some problems on this particular shade of grey). Because colors have some breadth in the H and S dimensions, even highly saturated colored backgrounds work well.