Posts Tagged graphics

Announcing libcontrast

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:

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., I’d love to hear them!

Get it now from SVN at

Tags: ,

Color optimization, take two

An anonymous commenter suggested I use CIE L*a*b* instead of HSV. I’ll let the results speak for themselves:


And that’s without any tweaks, fancy distance metrics, or pushing outside the region when the vector is too short. Whoever you were, thanks for the suggestion! Also, thanks to Madeleine Ball, whose suggestion I misunderstood, but is basically the same.

Update: with some vector extension code (slightly more contrast when colors are really close). The code is in xchat-gnome SVN for everyone to play with now.

Tags: ,

Overengineering beyond all reasonable limits: automatic color palette optimization

A while ago, it was suggested that GTK+ themes provide an ability to define certain colors. The reasoning behind this was that if a theme had a red background for something, just defining red as #ff0000 could result in unreadable text. As usual, some objections were raised, and IIRC nothing has yet happened with it.I was interested in this, because xchat-gnome is one of the very few things where it actually makes sense to define colors by name. It’s all well and good if a theme provides defined colors for heading and alert, but IRC allows people to mark text as red or aqua. Theme based colors weren’t an issue yet, because xchat-gnome worked on purely pre-defined color schemes for the conversation panel. Until now.

Perhaps it’s just been too long since I did any graphics programming, but when I thought this idea up in the shower (as an aside: I have, in the past, been known to take showers for the sole purpose of thinking up ideas), I just had to implement it.

Basically, instead of defining a color as a specific RGB triplet, we define it as a region in HSV space. HSV is a color space that matches more closely to how we as humans tend to define colors. It’s a cylindrical coordinate system where the angle defines hue, the radius defines saturation, and the vertical axis defines “value” (basically white to black). The colors within this cylindrical space fill a conic region.HSV_cone.png
The actual mapping between RGB and HSV forms a hexacone, due to colors in HSV that cannot be represented in RGB. Anyhow, we’re defining colors as a kind of wedge of this coordinate system. That means that when we say blue, we’re not actually defining a color, but a range of colors. Blue can be dark, it can be light, and it can range from purpleish-blue to cyanish-blue.

When the background color is not known a priori, some colors within this region may be too low a contrast to be readable. The background color is a point in HSV space, and by choosing the point within the region which is furthest from our background point, we get a foreground blue which is readable.

Of course, there are still some problems with this. The background color may lie right in the middle of a color region. In this case, even the furthest point within that region is going to have very low contrast against the background. To guard against this, if the hue of the foreground point is too close to the background and the saturation is high, the value gets pushed a little further out. Value (lightness) is a primary influence on how we percieve contrast, so by emphasizing it, the text becomes (mostly) legible.

color_optimization.png 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.

Of course, xchat-gnome allows image and transparent backgrounds, which are completely ignored by this. Nothing can deal with high-frequency high-contrast backgrounds, so I’m just going to say if you’re foolish enough to try that, you get what you deserve :). This code has landed in xchat-gnome SVN, and there’s been enough awesome stuff since 0.11 that a new release should be coming soon.

Tags: ,

alpha blended windows in python

Here’s a version of Mike’s alpha demo, in a python implementation that’s more pythoney (rather than a direct translation from C). GTK+/pygtk folks, any chance we could get that compositing-manager detection code out into the world before 2.10? :)

Tags: ,

First SIGGRAPH reflection

One thing I never expected was that exhibits in the “emerging technologies” installation gallery would actually be emerging. I was pleasantly surprised to see that two of the exhibits had been turned into actual products on the exhibition floor:

Last year Sunnybrook technologies showed off their HDR display – an LCD screen with a low-resolution active backlight, resulting in about a 1:200000 contrast ratio. Truly amazing to look at. This year, Sunnybrook had changed their name to “Brightside” and was showing off an absolutely gorgeous 37″ HD+HDR flat panel display at the expo. I didn’t ask, but I heard secondhand that it was going for $50000. Ouch. I’d love one of those in my living room, but unless they really take off, I doubt it’s going to happen any time soon.

I don’t remember the company name (it was some Japanese research group), but there was another very cool display technology last year – a 6-color primary projection system. I remember thinking that it looked almost like it was showing colors I’d never seen before – of course, I’d seen them in real life, but it was shocking to see bright magentas and yellows coming from a computer screen. Their exhibit on the show floor was a bit underwhelming – they had shrunk it down into a monitor (which happened to be about 6′ long), but the images they were showing didn’t really take advantage of it. Kind of a shame — the traditional RGB gamut is really limited, and I think that once people realize what they’re missing out on, they’ll start demanding it.

I can’t really think of anything I saw at this year’s emerging technologies show that I’ll see at the expo next year. The digital kaleidoscope and haptic rowing simulator were kind of cool, but certainly nothing mind-blowing. Probably the most likely “emerging technology” was a neat game they had. There was a floor with a child’s drawings taped down with RFID tags under them, and movable obelisks with LCD screens and speakers. The game itself was to solve a murder mystery – you saw short clips of the action, and moved the screens around to the drawings based on what you saw.


The game was surprisingly fun, especially for how childish they made the story and the puzzle. The cool part was that the position of the screens matched the way the shots were filmed – in one case, two screens were beside each other, while the other faced it from the other side of the floor. The lone screen showed a television set, while the other two showed two people on a couch watching it – very cool.

The game itself was easy (except for all the people who didn’t know what we were up to and kept moving the screens around, messing up the arrangement), but the possibilities seemed pretty cool – definitely a fun way to spend 15 minutes, and I imagine it could be a very popular activity, especially if the puzzles were made harder.

More thoughts on this year coming when I think of them.

Tags: ,