This particular background is taken from the XTerm's 256-colour palette used by Emacs, and there are many more in that set exhibiting similar problems. Obviously, with 24-bit colour terminals, there is a large number of colours that cause trouble for the old heuristics. > IMO, the commentary here doesn't explain enough, and actually begs > more questions than it answers. What is "gamma-correction", and why > is it pertinent here? Why is the power 2.2 a "good enough" > approximation here? What are the other constants, and what is the > meaning of each one of them? And pointing to the bug number for > rationale of the cut-off value doesn't really help, since the > discussion is very long, so I doubt people will easily find that > rationale. Fair enough -- I thought that the programmers who don't already know the theory would immediately look it up, but I've added a link to Wikipedia. > I still don't understand why we need this function. Did you see any > practical problems with using color-name-to-rgb? Why does it matter > that it needs the display to be initialized? Would it be enough to > document that it needs the display to be initialized? If we use color-name-to-rgb then we get a crash on start-up with TERM=xterm (for example), as explained before. I agree it's a somewhat artificial function; I've eliminated it in the attached patch. > As I said before, I don't want to change the default value of > frame-background-mode. This code has been relatively stable for quite > some time, and the result is customizable if the user doesn't like the > default. Changing the default value in subtle ways simply risks > annoying users. There's nothing to gain here, only potential losses. Quite the contrary: the new predicate is more robust than the old one, which I have argued with both concrete examples and theory. If you disagree, please supply both: why the AVG predicate is better, and specifically for what colours. There is nothing to lose here, only potential gains. Here is another screenshot: it compares the three old predicates with the new one for all colours in an Xterm with TERM=xterm-16color. The left-hand columns show the contrasting decision with each colour as background, the right-hand columns with the same colour as foreground. max, avg and dist refer to the old predicates as per previous message; new is color-dark-p of the patch.