bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#25890: `color-values` gives wrong value


From: Drew Adams
Subject: bug#25890: `color-values` gives wrong value
Date: Fri, 3 Mar 2017 07:49:33 -0800 (PST)

> > > >  (defun color-rgb-to-hex  (red green blue)
> >
> > The function should accept an optional arg NB-DIGITS, which
> > specifies the number of hex digits for each of R, G, B.  And
> > yes, it should default to 4 digits: #RRRRGGGGBBBB.
> >
> > (That's what the original function in hexrgb.el does, from
> > which color.el was supposedly derived.)
> 
> The code in hexrgb.el produces strange results in this regard (e.g.,
> it produces "#FFFFFFFFE0E0" instead of "#FFFFFFFFE000" for the color
> mentioned by the OP).

Not clear what you are saying.  What color mentioned by the OP?
Do you mean "light yellow"?  What sexp using hexrgb.el did you try?  

If I do (hexrgb-color-name-to-hex "light yellow") I do get
"#FFFFFFFFE0E0".  That comes from `x-color-values' returning
(65535 65535 57568) and `hexrgb-int-to-hex' converting 57568
to "E0E0".  That's from (format "%04X" 57568).  Hex conversion
of decimal 57568 _should_ be E0E0, AFAIK.  Where is the bug?

Or are you saying that the bug is from `x-color-values'
(`color-values') and not from hexrgb.el?  Is 57568 the
wrong blue color value for "light yellow"?

> I believe that's because it interprets the
> conversion between 2 and 4 hex digits incorrectly: the 2 hex digits
> are the _most_ significant bits of the 4-digit version, not the LSB.

See above.  I'm missing what you are trying to say, I guess.
Are you saying that color value 57568 should not be expressed
in hex as E0E0?

> But I did add such an optional argument to color-rgb-to-hex,

Good.

> with the difference that its value can only be either 4 or 2,
> as I see no reason for anyone to want a 12-bit per component
> color notations.

(I see no reason for the function not to be general.  Sure,
for current applications of such a function to colors there
is no real need for such generality.  But why prevent it?)

Anyway, thanks for adding the optional arg.

I'm interested in your reply to my questions above,
especially in the case that might have located a bug in
hexrgb.el.  It's not clear to me, so far.  Thx.






reply via email to

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