unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuri Khan <yuri.v.khan@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "Mattias Engdegård" <mattiase@acm.org>,
	"Emacs developers" <emacs-devel@gnu.org>
Subject: Re: master 68ae6fa: Improved light/dark colour predicate (bug#41544)
Date: Thu, 11 Jun 2020 12:15:03 +0700	[thread overview]
Message-ID: <CAP_d_8W6h_naaLc7phSe=RM4ofoOsw8AQosf7=KF9RZWv5yqAg@mail.gmail.com> (raw)
In-Reply-To: <jwvtuzienns.fsf-monnier+emacs@gnu.org>

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



  parent reply	other threads:[~2020-06-11  5:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200610181238.9796.44750@vcs0.savannah.gnu.org>
     [not found] ` <20200610181239.947C4204DF@vcs0.savannah.gnu.org>
2020-06-10 19:20   ` master 68ae6fa: Improved light/dark colour predicate (bug#41544) Stefan Monnier
2020-06-10 19:34     ` Mattias Engdegård
2020-06-10 20:01       ` Stefan Monnier
2020-06-11  5:15     ` Yuri Khan [this message]
2020-06-11 16:15       ` Mattias Engdegård
2020-06-11 19:22         ` Yuri Khan
2020-06-12 15:50           ` Mattias Engdegård
2020-06-12 16:22             ` tomas
2020-06-12 18:36             ` Yuri Khan
2020-06-13 10:55               ` Mattias Engdegård
2020-06-12 19:02             ` Drew Adams
2020-06-12 19:09             ` Stephen Leake
2020-06-18 19:28               ` Mattias Engdegård
2020-06-18 19:35                 ` Drew Adams
2020-06-18 20:04                   ` Mattias Engdegård
2020-06-18 20:32                     ` Drew Adams
2020-06-21  7:51                       ` Mattias Engdegård
2020-06-18 19:40                 ` Basil L. Contovounesios
2020-06-18 19:58                   ` Mattias Engdegård
2020-06-13  4:05             ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAP_d_8W6h_naaLc7phSe=RM4ofoOsw8AQosf7=KF9RZWv5yqAg@mail.gmail.com' \
    --to=yuri.v.khan@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).