text selection consistency

Germain Garand germain at ebooksfrance.org
Sun Sep 28 18:14:27 BST 2003


Hi Leo,

Le Dimanche 28 Septembre 2003 16:04, Leo Savernik a écrit :
> Am Samstag, 27. September 2003 01:39 schrieb David Faure:
> > On Saturday 27 September 2003 01:34, Max Howell wrote:
>
> inline bool hasSufficientContrast(const QColor &c1, const QColor &c2)
> {
> // ### arbitrary value, to be adapted if necessary (LS)
> #define CONTRAST_DISTANCE 5
>
>   if (QABS(c1.red() - c2.red()) > CONTRAST_DISTANCE) return true;
>   if (QABS(c1.green() - c2.green()) > CONTRAST_DISTANCE) return true;
>   if (QABS(c1.blue() - c2.blue()) > CONTRAST_DISTANCE) return true;
>
>   return false;
>
> #undef CONTRAST_DISTANCE
> }
>
> It's very primitive, and I don't know if it's "right", but I needed a very
> fast solution, and it works for all the cases I tested.

AFAIK, the 3 characteristics that are relevant for differentiating colors from 
a human POV are hue, saturation and light (they are intended just for that).
You'd probably be much more effective by using 
c1.hsv(x1,y1,z1)/c2.hsv(x2,y2,z2) and comparing the delta for those.
A delta of 20 for combined s and v (out of 255), and 15 for h alone (out of 
360) looks like the bear minimum to me.
e.g
{
#define HUE_DISTANCE 15
#define CONTRAST_DISTANCE 10
int h1, s1, v1, h2, s2, v2;
c1.hsv(&h1,&s1,&v1);
c2.hsv(&h2,&s2,&v2);
return QABS(h1-h2) > HUE_DISTANCE &&
       QABS(s1-s2) + QABS(v1-v2) > CONTRAST_DISTANCE*2;
#undef CONTRAST_DISTANCE
#undef HUE_DISTANCE
}

Might be overkill in this context though 8)
Germain

>
> mfg
> 	Leo





More information about the kfm-devel mailing list