unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: emacs-devel@gnu.org
Subject: Re: master 68ae6fa: Improved light/dark colour predicate (bug#41544)
Date: Wed, 10 Jun 2020 15:20:05 -0400	[thread overview]
Message-ID: <jwvtuzienns.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20200610181239.947C4204DF@vcs0.savannah.gnu.org> ("Mattias Engdegård"'s message of "Wed, 10 Jun 2020 14:12:39 -0400 (EDT)")

> +(defun color-dark-p (rgb)
> +  "Whether RGB is more readable against white than black.
> +RGB is a 3-element list (R G B), each component in the range [0,1].
> +This predicate can be used both for determining a suitable (black or white)
> +contrast colour with RGB as background and as foreground."
> +  (unless (<= 0 (apply #'min rgb) (apply #'max rgb) 1)
> +    (error "RGB components %S not in [0,1]" rgb))
> +  ;; Compute the relative luminance after gamma-correcting (assuming sRGB),
> +  ;; and compare to a cut-off value determined experimentally.
> +  ;; See https://en.wikipedia.org/wiki/Relative_luminance for details.
> +  (let* ((sr (nth 0 rgb))
> +         (sg (nth 1 rgb))
> +         (sb (nth 2 rgb))
> +         ;; Gamma-correct the RGB components to linear values.
> +         ;; Use the power 2.2 as an approximation to sRGB gamma;
> +         ;; it should be good enough for the purpose of this function.
> +         (r (expt sr 2.2))
> +         (g (expt sg 2.2))
> +         (b (expt sb 2.2))
> +         (y (+ (* r 0.2126) (* g 0.7152) (* b 0.0722))))

Could we arrange to share the code with `color-srgb-to-xyz` (in `color.el`)?

> +    (< 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
[ I don't doubt it's a good choice, but I think we should document
  where these thing come from.  ]


        Stefan




       reply	other threads:[~2020-06-10 19:20 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   ` Stefan Monnier [this message]
2020-06-10 19:34     ` master 68ae6fa: Improved light/dark colour predicate (bug#41544) Mattias Engdegård
2020-06-10 20:01       ` Stefan Monnier
2020-06-11  5:15     ` Yuri Khan
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=jwvtuzienns.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.org \
    /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).