Subject: Re: bug#70941: 30.0.50; Low RGB color values use the terminal palette in TUI

From: Eli Zaretskii <[email-masked]>
Date: Sat, 18 May 2024 13:23:30 +0300

> From: Gerry Agbobada <[email-masked]>
> Date: Tue, 14 May 2024 21:45:13 +0200
> Cc: [email-masked]
> 
> > Emacs doesn't have a lisp/term/wezterm.el file, so the question is
> > what is your TERM environment variable set to?
> 
> My bad, the TERM environment variable is set to xterm-256color
> there. But infocmp -x still does not show any setf24 or setb24,
> only setab and setaf again, this time (it seems to be the exact same)
> 
> #+begin_src
> setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
> setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
> #+end_src

Might be a problem with infocmp, perhaps?

> > You expect the terminal to obey the X RGB color specification
> > directly, but that is not how TTY color support works in Emacs.  Emacs
> > approximates each X color using the colors that the terminal actually
> > supports.  So we should start by looking at the color setup and how
> > many colors that yields.  What does "M-x list-colors-display" produce?
> 
> What bothers me is that there seems to be an inconsistency there. I expect
> Emacs in a terminal that supports 24-bit to show the colour `#000000` as
> pitch black. Instead it’s the 0th colour of the terminal emulator palette. All
> the colours seems to be displayed exactly as they should, except the
> first 8 ones.

That's because you use #RGB with 2 hex digits per color component.
Emacs, by contrast, uses 16-bit color components, i.e. 4 hex digits
per component.  When you use 2 hex digits, Emacs scales them to 16-bit
values, and that causes the effect you see, because 01 is not scaled
to 0001, but to 0100 instead.  So try with "#000000000001" etc. in
your recipe, and I think you should see what you expect.

> To answer your question, `M-x list-colors-display` seems to show the
> maximum amount possible (all the colours are named like « goldenrod » 
> etc.), but the first 8 ones definitely don’t look right.

Why do you think the first 8 are not right?  list-colors-display does
not show the colors in the numerical order, it shows first the
standard colors, and then the rest.  This order is unrelated to the
issue at hand.