aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2020-06-18 21:16:42 +0200
committerMattias EngdegÄrd2020-06-18 21:16:42 +0200
commitba450b6f462e278fcd3bc96c88f154fce219f5fc (patch)
treed0c2202bc4245378ab409be06c68ba988f0efcab
parent75babd073a0e00a5bd1a08dc2059742c1a145ea9 (diff)
downloademacs-ba450b6f462e278fcd3bc96c88f154fce219f5fc.tar.gz
emacs-ba450b6f462e278fcd3bc96c88f154fce219f5fc.zip
Define the dark luminance limit as a named constant
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.
-rw-r--r--lisp/faces.el7
1 files changed, 6 insertions, 1 deletions
diff --git a/lisp/faces.el b/lisp/faces.el
index f6b9593b9df..2480aaaf146 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -1794,6 +1794,11 @@ on which one provides better contrast with COLOR."
1794 (color-values color))) 1794 (color-values color)))
1795 "#ffffff" "black")) 1795 "#ffffff" "black"))
1796 1796
1797(defconst color-luminance-dark-limit 0.325
1798 "The relative luminance below which a color is considered 'dark',
1799in the sense that white text is more readable than black with the
1800color as background. This value was determined experimentally.")
1801
1797(defun color-dark-p (rgb) 1802(defun color-dark-p (rgb)
1798 "Whether RGB is more readable against white than black. 1803 "Whether RGB is more readable against white than black.
1799RGB is a 3-element list (R G B), each component in the range [0,1]. 1804RGB 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."
1814 (g (expt sg 2.2)) 1819 (g (expt sg 2.2))
1815 (b (expt sb 2.2)) 1820 (b (expt sb 2.2))
1816 (y (+ (* r 0.2126) (* g 0.7152) (* b 0.0722)))) 1821 (y (+ (* r 0.2126) (* g 0.7152) (* b 0.0722))))
1817 (< y (eval-when-compile (expt 0.6 2.2))))) 1822 (< y color-luminance-dark-limit)))
1818 1823
1819(declare-function xw-color-defined-p "xfns.c" (color &optional frame)) 1824(declare-function xw-color-defined-p "xfns.c" (color &optional frame))
1820 1825