From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: master 68ae6fa: Improved light/dark colour predicate (bug#41544) Date: Wed, 10 Jun 2020 15:20:05 -0400 Message-ID: References: <20200610181238.9796.44750@vcs0.savannah.gnu.org> <20200610181239.947C4204DF@vcs0.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="101707"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Mattias =?windows-1252?Q?Engdeg=E5rd?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jun 10 21:21:05 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jj6HY-000QLL-EC for ged-emacs-devel@m.gmane-mx.org; Wed, 10 Jun 2020 21:21:04 +0200 Original-Received: from localhost ([::1]:51960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj6HX-0004Pv-BN for ged-emacs-devel@m.gmane-mx.org; Wed, 10 Jun 2020 15:21:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj6Gk-0003rd-Lb for emacs-devel@gnu.org; Wed, 10 Jun 2020 15:20:14 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:8838) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj6Gj-0000bc-44 for emacs-devel@gnu.org; Wed, 10 Jun 2020 15:20:13 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 6B89510033A; Wed, 10 Jun 2020 15:20:10 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 77167100091; Wed, 10 Jun 2020 15:20:08 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1591816808; bh=RacnLTTQr2C85a0YPlFBVsT41sLG+vdFAEDsiiTFSPs=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=nQbR+UW6e11UdHMNHuVBPEy4ydbkjfRbHx9j5K4jNIKyooELHrlU10rDlALJBhv1v NagIgBtLKYM8PSvAhPIdLjoN1BuCNPH0DGqqoYvMOcGIPnA5PKSDtwHFyF/NC/edsd /bjBk0Iej4GsOhFL0mT0eIa9IAZulgZTYo8HeeuukvPfV/ftow2D7HAdNN8a8kEjV8 9g+5UE6AHfF32JDZjze1IjNCNDlHB+MyDoshzoCvwUETxJbF5fQspttXoGTMj62V8i JN+JvdGmzVE1YfEnGFQpADZYVQUainJKC5vy4nFtRQ38wp3g4NPI5UlifIUltMKyjT mBXhc3tAU0SKQ== Original-Received: from alfajor (unknown [216.154.55.41]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2C4741203AD; Wed, 10 Jun 2020 15:20:08 -0400 (EDT) In-Reply-To: <20200610181239.947C4204DF@vcs0.savannah.gnu.org> ("Mattias =?windows-1252?Q?Engdeg=E5rd=22's?= message of "Wed, 10 Jun 2020 14:12:39 -0400 (EDT)") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 15:11:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:252085 Archived-At: > +(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