emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Frame background mode


From: Juri Linkov
Subject: Frame background mode
Date: Sun, 26 Dec 2004 21:52:54 +0200
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

I suggest to improve the formula used to determine whether the
background is light or dark.  The new formula uses the optimal
weighting coefficients for RGB color components to reflect the
perception of color luminance.

Index: lisp/faces.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/faces.el,v
retrieving revision 1.297
diff -u -r1.297 faces.el
--- lisp/faces.el       23 Dec 2004 18:28:13 -0000      1.297
+++ lisp/faces.el       26 Dec 2004 18:44:06 -0000
@@ -1536,11 +1536,15 @@
                 'dark)
                ((equal bg-color "unspecified-fg") ; inverted colors
                 'light)
-               ((>= (apply '+ (x-color-values bg-color frame))
-                   ;; Just looking at the screen, colors whose
-                   ;; values add up to .6 of the white total
-                   ;; still look dark to me.
-                   (* (apply '+ (x-color-values "white" frame)) .6))
+               ((let ((bg-color-values (x-color-values bg-color frame))
+                      (white-values (x-color-values "white" frame)))
+                  (>= (+ (* (nth 0 bg-color-values) 0.30)
+                         (* (nth 1 bg-color-values) 0.59)
+                         (* (nth 2 bg-color-values) 0.11))
+                      (* (+ (* (nth 0 white-values) 0.30)
+                            (* (nth 1 white-values) 0.59)
+                            (* (nth 2 white-values) 0.11))
+                         .5)))
                 'light)
                (t 'dark)))
         (display-type

The most noticeable consequence of such change is that many green
colors (which really look like light colors) are moved to `light'
category.

Here is the code that displays the color changes between old and new
formulas (it needs the patch to facemenu.el I sent earlier):

(let ((frame (selected-frame)) diff-list new-dark-list new-light-list)
  (dolist (color (list-colors-duplicates))
    (let* ((bg-color (car color))
           (old (if (>= (apply '+ (x-color-values bg-color frame))
                        (* (apply '+ (x-color-values "white" frame)) .6))
                    'light 'dark))
           (new (if (let ((bg-color-values (x-color-values bg-color frame))
                          (white-values (x-color-values "white" frame)))
                      (>= (+ (* (nth 0 bg-color-values) 0.30)
                             (* (nth 1 bg-color-values) 0.59)
                             (* (nth 2 bg-color-values) 0.11))
                          (* (+ (* (nth 0 white-values) 0.30)
                                (* (nth 1 white-values) 0.59)
                                (* (nth 2 white-values) 0.11))
                             .5)))
                    'light 'dark)))
      (if (eq new 'light)
          (setq new-light-list (cons color new-light-list))
        (setq new-dark-list (cons color new-dark-list)))
      (unless (eq old new)
        (insert (format "%-22s %-5s %s\n" bg-color old new))
        (setq diff-list (cons color diff-list)))))
  (list-colors-display (reverse diff-list) "*Colors-Diff*")
  (list-colors-display (reverse new-dark-list) "*Colors-Dark*")
  (list-colors-display (reverse new-light-list) "*Colors-Light*"))

The changes in color mode it computes are the following (the second
column shows the mode computed by the old formula, the third column
by the new formula):

light slate gray       dark  light
medium slate blue      light dark
deep sky blue          dark  light
dark turquoise         dark  light
cadet blue             dark  light
medium sea green       dark  light
light sea green        dark  light
spring green           dark  light
lawn green             dark  light
green                  dark  light
chartreuse             dark  light
medium spring green    dark  light
lime green             dark  light
yellow green           dark  light
goldenrod              dark  light
dark goldenrod         dark  light
peru                   dark  light
chocolate              dark  light
orange                 dark  light
dark orange            dark  light
tomato                 dark  light
magenta                light dark
snow4                  dark  light
seashell4              dark  light
AntiqueWhite4          dark  light
LemonChiffon4          dark  light
cornsilk4              dark  light
ivory4                 dark  light
honeydew4              dark  light
LavenderBlush4         dark  light
MistyRose4             dark  light
azure4                 dark  light
SlateBlue2             light dark
SteelBlue3             dark  light
DeepSkyBlue1           dark  light
DeepSkyBlue2           dark  light
LightCyan4             dark  light
PaleTurquoise4         dark  light
turquoise3             dark  light
cyan3                  dark  light
SeaGreen3              dark  light
PaleGreen3             dark  light
SpringGreen1           dark  light
SpringGreen2           dark  light
SpringGreen3           dark  light
green1                 dark  light
green2                 dark  light
chartreuse1            dark  light
chartreuse2            dark  light
chartreuse3            dark  light
OliveDrab3             dark  light
DarkOliveGreen3        dark  light
khaki4                 dark  light
LightYellow4           dark  light
yellow3                dark  light
gold2                  dark  light
gold3                  dark  light
goldenrod2             dark  light
goldenrod3             dark  light
DarkGoldenrod1         dark  light
DarkGoldenrod2         dark  light
DarkGoldenrod3         dark  light
IndianRed2             dark  light
sienna1                dark  light
sienna2                dark  light
sienna3                dark  light
tan3                   dark  light
chocolate1             dark  light
chocolate2             dark  light
salmon3                dark  light
LightSalmon3           dark  light
orange1                dark  light
orange2                dark  light
orange3                dark  light
DarkOrange1            dark  light
DarkOrange2            dark  light
coral1                 dark  light
coral2                 dark  light
tomato1                dark  light
tomato2                dark  light
HotPink3               dark  light
PaleVioletRed3         dark  light
maroon1                light dark
magenta1               light dark
magenta2               light dark
MediumOrchid3          light dark
DarkOrchid1            light dark
DarkOrchid2            light dark
thistle4               dark  light
gray51                 dark  light
gray52                 dark  light
gray53                 dark  light
gray54                 dark  light
gray55                 dark  light
gray56                 dark  light
gray57                 dark  light
gray58                 dark  light
gray59                 dark  light

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]