Posts Tagged graphics

Announcing libcontrast

A while back, I devised a method of pro­vid­ing named col­ors which could be adapted to any given back­ground color, with a rea­son­able guar­an­tee of read­abil­ity. Any­one inter­ested in the details can check out my pre­vi­ous two entries about it:

There’s been some inter­est in this approach from a vari­ety of peo­ple for dif­fer­ent projects. I even went so far as to cre­ate a patch to put this inside GTK+. Unsur­pris­ingly, this patch hasn’t even been looked at due to the main­tainer shortage.

So, I’m try­ing a dif­fer­ent approach. I’ve cleaned up the code, slapped the MIT/X11 license on it, and put it in a sep­a­rate direc­tory to make it easy to cherry-pick. This is kind of libegg-ish right now, though I’d like to make it eas­ier to have an “upstream”. If any­one has any ideas about mak­ing 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/

Tags: ,

Color optimization, take two

An anony­mous com­menter sug­gested I use CIE L*a*b* instead of HSV. I’ll let the results speak for themselves:

color_optimization_lab.png

And that’s with­out any tweaks, fancy dis­tance met­rics, or push­ing out­side the region when the vec­tor is too short. Who­ever you were, thanks for the sug­ges­tion! Also, thanks to Madeleine Ball, whose sug­ges­tion I mis­un­der­stood, but is basi­cally the same.

Update: with some vec­tor exten­sion code (slightly more con­trast when col­ors are really close). The code is in xchat-gnome SVN for every­one to play with now.
77-225.77.png

Tags: ,

Overengineering beyond all reasonable limits: automatic color palette optimization

A while ago, it was sug­gested that GTK+ themes pro­vide an abil­ity to define cer­tain col­ors. The rea­son­ing behind this was that if a theme had a red back­ground for some­thing, just defin­ing red as #ff0000 could result in unread­able text. As usual, some objec­tions were raised, and IIRC noth­ing has yet hap­pened with it.I was inter­ested in this, because xchat-gnome is one of the very few things where it actu­ally makes sense to define col­ors by name. It’s all well and good if a theme pro­vides defined col­ors for head­ing and alert, but IRC allows peo­ple to mark text as red or aqua. Theme based col­ors weren’t an issue yet, because xchat-gnome worked on purely pre-defined color schemes for the con­ver­sa­tion panel. Until now.

Per­haps it’s just been too long since I did any graph­ics pro­gram­ming, but when I thought this idea up in the shower (as an aside: I have, in the past, been known to take show­ers for the sole pur­pose of think­ing up ideas), I just had to imple­ment it.

Basi­cally, instead of defin­ing a color as a spe­cific 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 col­ors. It’s a cylin­dri­cal coor­di­nate sys­tem where the angle defines hue, the radius defines sat­u­ra­tion, and the ver­ti­cal axis defines “value” (basi­cally white to black). The col­ors within this cylin­dri­cal space fill a conic region.HSV_cone.png
The actual map­ping between RGB and HSV forms a hexa­cone, due to col­ors in HSV that can­not be rep­re­sented in RGB. Any­how, we’re defin­ing col­ors as a kind of wedge of this coor­di­nate sys­tem. That means that when we say blue, we’re not actu­ally defin­ing a color, but a range of col­ors. Blue can be dark, it can be light, and it can range from purpleish-blue to cyanish-blue.

When the back­ground color is not known a pri­ori, some col­ors within this region may be too low a con­trast to be read­able. The back­ground color is a point in HSV space, and by choos­ing the point within the region which is fur­thest from our back­ground point, we get a fore­ground blue which is readable.

Of course, there are still some prob­lems with this. The back­ground color may lie right in the mid­dle of a color region. In this case, even the fur­thest point within that region is going to have very low con­trast against the back­ground. To guard against this, if the hue of the fore­ground point is too close to the back­ground and the sat­u­ra­tion is high, the value gets pushed a lit­tle fur­ther out. Value (light­ness) is a pri­mary influ­ence on how we per­cieve con­trast, so by empha­siz­ing it, the text becomes (mostly) legible.

color_optimization.png As a result of this, col­ors against a white back­ground tend to be dark, while col­ors against a black back­ground tend to be light. By defin­ing white and black as regions which have some breadth in the value dimen­sion, white-on-white text and black-on-black text become read­able. When on a grey back­ground, text gets pushed in either direc­tion depend­ing on whichever is fur­thest away in the HSV color space. For the most part, this works very well (you can see the pur­ple color has some prob­lems on this par­tic­u­lar shade of grey). Because col­ors have some breadth in the H and S dimen­sions, even highly sat­u­rated col­ored back­grounds work well.

Of course, xchat-gnome allows image and trans­par­ent back­grounds, which are com­pletely ignored by this. Noth­ing can deal with high-frequency high-contrast back­grounds, so I’m just going to say if you’re fool­ish enough to try that, you get what you deserve :) . This code has landed in xchat-gnome SVN, and there’s been enough awe­some stuff since 0.11 that a new release should be com­ing soon.

Tags: ,

alpha blended windows in python

Here’s a ver­sion of Mike’s alpha demo, in a python imple­men­ta­tion that’s more pythoney (rather than a direct trans­la­tion from C). GTK+/pygtk folks, any chance we could get that compositing-manager detec­tion code out into the world before 2.10? :)

alphademo.py

Tags: ,

First SIGGRAPH reflection

One thing I never expected was that exhibits in the “emerg­ing tech­nolo­gies” instal­la­tion gallery would actu­ally be emerg­ing. I was pleas­antly sur­prised to see that two of the exhibits had been turned into actual prod­ucts on the exhi­bi­tion floor:

Last year Sun­ny­brook tech­nolo­gies showed off their HDR dis­play — an LCD screen with a low-resolution active back­light, result­ing in about a 1:200000 con­trast ratio. Truly amaz­ing to look at. This year, Sun­ny­brook had changed their name to “Bright­side” and was show­ing off an absolutely gor­geous 37″ HD+HDR flat panel dis­play at the expo. I didn’t ask, but I heard sec­ond­hand that it was going for $50000. Ouch. I’d love one of those in my liv­ing room, but unless they really take off, I doubt it’s going to hap­pen any time soon.

I don’t remem­ber the com­pany name (it was some Japan­ese research group), but there was another very cool dis­play tech­nol­ogy last year — a 6-color pri­mary pro­jec­tion sys­tem. I remem­ber think­ing that it looked almost like it was show­ing col­ors I’d never seen before — of course, I’d seen them in real life, but it was shock­ing to see bright magen­tas and yel­lows com­ing from a com­puter screen. Their exhibit on the show floor was a bit under­whelm­ing — they had shrunk it down into a mon­i­tor (which hap­pened to be about 6′ long), but the images they were show­ing didn’t really take advan­tage of it. Kind of a shame — the tra­di­tional RGB gamut is really lim­ited, and I think that once peo­ple real­ize what they’re miss­ing out on, they’ll start demand­ing it.

I can’t really think of any­thing I saw at this year’s emerg­ing tech­nolo­gies show that I’ll see at the expo next year. The dig­i­tal kalei­do­scope and hap­tic row­ing sim­u­la­tor were kind of cool, but cer­tainly noth­ing mind-blowing. Prob­a­bly the most likely “emerg­ing tech­nol­ogy” was a neat game they had. There was a floor with a child’s draw­ings taped down with RFID tags under them, and mov­able obelisks with LCD screens and speak­ers. The game itself was to solve a mur­der mys­tery — you saw short clips of the action, and moved the screens around to the draw­ings based on what you saw.

Murder!

The game was sur­pris­ingly fun, espe­cially for how child­ish they made the story and the puz­zle. The cool part was that the posi­tion 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 tele­vi­sion set, while the other two showed two peo­ple on a couch watch­ing it — very cool.

The game itself was easy (except for all the peo­ple who didn’t know what we were up to and kept mov­ing the screens around, mess­ing up the arrange­ment), but the pos­si­bil­i­ties seemed pretty cool — def­i­nitely a fun way to spend 15 min­utes, and I imag­ine it could be a very pop­u­lar activ­ity, espe­cially if the puz­zles were made harder.

More thoughts on this year com­ing when I think of them.

Tags: ,

Bad Behavior has blocked 97 access attempts in the last 7 days.