Juergen Spitzmueller wrote:

> Angus Leeming wrote:
>> <shrug>dunno</shrug>
>> You could perhaps parse /usr/lib/X11/rgb.txt (location may vary). It has
>> entries of the form:
>>         255 250 250 snow
>>         248 248 255 ghost white
>> but really, I think that that is overkill.
> 
> Don't get me wrong, I don't wanna do art. I'm just wondering if we could
> automagically decide if a user choses a button color whether we need a
> rather white or rather black label text. Let's say a user choses a
> 240,255,255 (dark blue) background, then white would be better for label
> text than black. But probably that's not possible.

Next to impossible in an RGB colourspace, but quite easy in an HSV one.

Eg:
RGBColor getConjugate(RGBColor const & rgb)
{
        HSVColor hsv = HSVColor(rgb);

        // Assume this color is red
        // changing hsv.s, "saturation", will take you from near white (hsv.s = 0)
        // to red (hsv.s = 1).
        // changing hsv.v, "value", will take you from black (hsv.v = 0) to
        // red (hsv.v = 1).

        // So, if 'v' is > 70% adjust 's', else adjust 'v' seems like a
        // reasonable strategy.
        if (hsv.v > 0.7)
                hsv.s = ...;
        else
                hsv.v -= 0.5;

        return RGBColor(hsv);
}

-- 
Angus

Reply via email to