]> git.eshelyaron.com Git - emacs.git/commitdiff
Define the dark luminance limit as a named constant
authorMattias Engdegård <mattiase@acm.org>
Thu, 18 Jun 2020 19:16:42 +0000 (21:16 +0200)
committerMattias Engdegård <mattiase@acm.org>
Thu, 18 Jun 2020 19:16:42 +0000 (21:16 +0200)
To make the meaning of the color-dark-p cutoff luminance clear,
define it as a named constant.  (We no longer use the somewhat
obscure 0.6^2.2 definition since it doesn't really make sense
to define the limit in gamma-compressed space.)

* lisp/faces.el (color-luminance-dark-limit): New constant.
(color-dark-p): Use color-luminance-dark-limit.

lisp/faces.el

index f6b9593b9df10e0465ba07d0732f556f13b38b62..2480aaaf14611a8d8b1829f7542aa88b25e1053f 100644 (file)
@@ -1794,6 +1794,11 @@ on which one provides better contrast with COLOR."
                             (color-values color)))
       "#ffffff" "black"))
 
+(defconst color-luminance-dark-limit 0.325
+  "The relative luminance below which a color is considered 'dark',
+in the sense that white text is more readable than black with the
+color as background.  This value was determined experimentally.")
+
 (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].
@@ -1814,7 +1819,7 @@ contrast colour with RGB as background and as foreground."
          (g (expt sg 2.2))
          (b (expt sb 2.2))
          (y (+ (* r 0.2126) (* g 0.7152) (* b 0.0722))))
-    (< y (eval-when-compile (expt 0.6 2.2)))))
+    (< y color-luminance-dark-limit)))
 
 (declare-function xw-color-defined-p "xfns.c" (color &optional frame))