emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master 68ae6fa: Improved light/dark colour predicate (bug#41544)


From: Yuri Khan
Subject: Re: master 68ae6fa: Improved light/dark colour predicate (bug#41544)
Date: Thu, 11 Jun 2020 12:15:03 +0700

On Thu, 11 Jun 2020 at 02:20, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> > +This predicate can be used both for determining a suitable (black or white)
> > +contrast colour with RGB as background and as foreground."

> > +  ;; and compare to a cut-off value determined experimentally.
> > +  ;; See https://en.wikipedia.org/wiki/Relative_luminance for details.

> > +    (< y (eval-when-compile (expt 0.6 2.2)))))
>
> Where does this 0.6 come from?
> I don't see it in https://en.wikipedia.org/wiki/Relative_luminance

Instead of comparing the relative luminance against an experimentally
determined cutoff, why not do the actual calculations of contrast
ratio against black and white?

The formula for contrast ratio is: C = (L1+0.05) / (L2+0.05) [1]
where L1 and L2 are relative luminances of the brighter and the darker colors.

So contrast against black is (L+0.05) / 0.05 and contrast against
white is 1.05 / (L+0.05). Solving for the middle ground L where these
give the same result:

(L+0.05) / 0.05 = 1.05 / (L+0.05)
(L+0.05)^2 = 1.05 * 0.05
L+0.05 = (1.05 * 0.05)^0.5
L = (1.05 * 0.05)^0.5 - 0.05 ≈ 0.18 corresponding to a gray around #767576

Experimentally, I find white and black over #767576 about equally easy
to read; over a light gray #cccbcc (L=0.6), black is much more
readable than white.

[1]: https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio



reply via email to

[Prev in Thread] Current Thread [Next in Thread]