unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Eli Zaretskii <eliz@gnu.org>, Drew Adams <drew.adams@oracle.com>
Cc: michael_heerdegen@web.de, 25890@debbugs.gnu.org, rasmus@gmx.us
Subject: bug#25890: `color-values` gives wrong value
Date: Sat, 4 Mar 2017 07:38:51 -0800 (PST)	[thread overview]
Message-ID: <59441882-425e-4962-8760-70c505d991dd@default> (raw)
In-Reply-To: <<83lgsll9ey.fsf@gnu.org>>

> the problem is in hexrgb-int-to-hex.  It does this:
> 
>   (substring (format (concat "%0" (int-to-string nb-digits) "X") int)
>              (- nb-digits))
> 
> which assumes that the digits to be produced, if n in the %0nX format
> is too small and doesn't allow to produce all of them, are the
> least-significant digits of the number.

Correct.  Which is just what its doc string says:

 If INT is too large to be represented with NB-DIGITS, then the result
 is truncated from the left.  So, for example, INT=256 and NB-DIGITS=2
 returns \"00\", since the hex equivalent of 256 decimal is 100, which
 is more than 2 digits.

That doesn't claim that the result faithfully represents the decimal
input value.  It doesn't.  But neither would truncating from the
right represent it correctly.  The doc string just describes the
behavior, letting you know what the (inaccurate) return value is
in such a case.

Is there an advantage in truncating from the right?  If so,
what?  Can you show how you would use such "corrected" behavior
advantageously?  To my mind, neither kind of truncation gives
you anything useful, if what you need is to represent the same
number faithfully.

> It should instead produce the most-significant digits.

Why?  How would that be better?  If the decimal number is too
big for the allotted number of hex digits then it is just too big.

> IOW, when #FFFFFF is converted to 16-bit per color component, it
> should yield #FF00FF00FF00, not #FFFFFFFFFFFF.

Where do you see `hexrgb-int-to-hex' being used as (I guess) you
suppose?  Where do you see #FFFFFF "converted" to #FFFFFFFFFFFF
(let alone to #FF00FF00FF00).

Sorry, but I just do not understand what you're trying to say.

Are you perhaps thinking of using `hexrgb-int-to-hex' together
with `hexrgb-hex-to-int', to "convert" from 6 hex digits to 12?
In that case, the "conversion" would be from "FFFFFF" to
"000000FFFFFF", which is correct, I think:

(hexrgb-int-to-hex (hexrgb-hex-to-int "FFFFFF") 12) => "000000FFFFFF"

Or from 2 to 4 hex digits (since the function is used on each
color component separately):

(hexrgb-int-to-hex (hexrgb-hex-to-int "FF") 4) => "00FF"

Or for your "E0" example:

(hexrgb-int-to-hex (hexrgb-hex-to-int "E0") 4) => "00E0"

I don't see any "conversion" from "E0" to "E0E0" (or to "E000",
which is apparently what you suggest is called for).

Can you please relate your message, whatever it might be, back
to your initial statement that hexrgb 'produces "#FFFFFFFFE0E0"
instead of "#FFFFFFFFE000" for the color mentioned by the OP'.

AFAIK, the color mentioned by the OP was "light yellow".  Do
we agree so far?  (I asked this once, but got no reply.)

(And I asked what sexp using the hexrgb code you tried, but I
got no answer there either.)

I said that if you use (hexrgb-color-name-to-hex "light yellow")
which is what I'd hope you would use, you do get "#FFFFFFFFE0E0".
And I said that that is, AFAIK, correct, not incorrect.

You say (I think) that the correct hex value for "light yellow"
is, or should be, "#FFFFFFFFE000".  But you haven't said why you
think that.

The color values for "light yellow" are: (65535 65535 57568).
I asked if you thought those values are correct, but I got no
reply.

Let's assume they are correct (they are not from hexrgb code,
anyway).  If so, the question is how each of those color values
should be represented using 4 hex digits.  `hexrgb-int-to-hex'
returns "FFFF" for each of the first two and "E0E0" for the third.

I asked if you agreed that that is correct, and you said yes.
To me, that means that it is correct for the 12-digit hex code
for "light yellow" to be "#FFFFFFFFE0E0", which you apparently
do not agree with.

I get the impression that you are perhaps thinking that it is
about "converting" FFFFE0 (not "light yellow") to FFFFFFFFE0E0
or to FFFFFFFFE000.  If so, why do you think that, and where
do you see the hexrgb code doing any such "conversion"?

Sorry, but I just do not get your message.  Could you perhaps
show some code that points out the bug you think you have found?
Could you show (with code) how using `hexrgb-int-to-hex' for
"light yellow" or whatever gives the wrong hex representation?

Saying that `hexrgb-int-to-hex' truncates from the left (i.e.,
drops the MSB) just repeats what its doc string says.  It's not
a bug but the declared behavior.

If you see a _use_ of `hexrgb-int-to-hex' in hexrgb.el that
leads to incorrect results because of that (intended) behavior,
please point to it.

I'd like to correct a bug in hexrgb, but so far I haven't been
able to see what it is.

You apparently think that `hexrgb-int-to-hex' should truncate
from the right, i.e., drop the LSB, not the MSB, when the number
is too large to be represented by the given number of hex digits.

I don't see the advantage of that.  If the number is too large
then it is too large.  For an integer value of 256 you would, I
guess, prefer to see the hex representation "10" returned instead
of "00".  I don't see how that would help anything.

I think the question is how code makes _use_ of `hexrgb-int-to-hex'.
If the number to convert is too big for the number of hex digits
allowed then there is no way to represent the decimal number with
those few hex digits.  I don't see an advantage to truncating from
the right instead of the left.

Can you give an actual example, where you would use a version of
`hexrgb-int-to-hex' that is corrected according to you (presumably
truncating at the right), where you can usefully make use of the
return value?  IOW, supposing a corrected `hexrgb-int-to-hex',
how would you use it in a sexp to take advantage of the correction?

AFAICS, if the decimal value cannot be represented with so few hex
digits there is no sense in trying to use the result as if it
represented the same number.  But perhaps I'm missing something.





       reply	other threads:[~2017-03-04 15:38 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <<<<<87zih7n2yt.fsf@pank.eu>
     [not found] ` <<<<<83r32jpr8b.fsf@gnu.org>
     [not found]   ` <<<<<87bmtnryqr.fsf@drachen>
     [not found]     ` <<<<<87d1e2tzt5.fsf@pank.eu>
     [not found]       ` <<<<<8337eypb5l.fsf@gnu.org>
     [not found]         ` <<<<<87vartx4qd.fsf@drachen>
     [not found]           ` <<<<<56bad9de-8111-4962-a9e9-2dbf0084e004@default>
     [not found]             ` <<<<<83wpc6la28.fsf@gnu.org>
     [not found]               ` <<<<2cfd6280-34de-4751-b35f-ec7d47a16595@default>
     [not found]                 ` <<<<83pohyky8i.fsf@gnu.org>
     [not found]                   ` <<<d73ecee8-1b1d-4739-b2b8-e3eb9ecc3ce0@default>
     [not found]                     ` <<<83o9xikvop.fsf@gnu.org>
     [not found]                       ` <<1b96dc61-19bb-486b-a408-c3b3c15e113b@default>
     [not found]                         ` <<83lgsll9ey.fsf@gnu.org>
2017-03-04 15:38                           ` Drew Adams [this message]
2017-03-04 16:10                             ` bug#25890: `color-values` gives wrong value Eli Zaretskii
     [not found] <<<<<<87zih7n2yt.fsf@pank.eu>
     [not found] ` <<<<<<83r32jpr8b.fsf@gnu.org>
     [not found]   ` <<<<<<87bmtnryqr.fsf@drachen>
     [not found]     ` <<<<<<87d1e2tzt5.fsf@pank.eu>
     [not found]       ` <<<<<<8337eypb5l.fsf@gnu.org>
     [not found]         ` <<<<<<87vartx4qd.fsf@drachen>
     [not found]           ` <<<<<<56bad9de-8111-4962-a9e9-2dbf0084e004@default>
     [not found]             ` <<<<<<83wpc6la28.fsf@gnu.org>
     [not found]               ` <<<<<2cfd6280-34de-4751-b35f-ec7d47a16595@default>
     [not found]                 ` <<<<<83pohyky8i.fsf@gnu.org>
     [not found]                   ` <<<<d73ecee8-1b1d-4739-b2b8-e3eb9ecc3ce0@default>
     [not found]                     ` <<<<83o9xikvop.fsf@gnu.org>
     [not found]                       ` <<<1b96dc61-19bb-486b-a408-c3b3c15e113b@default>
     [not found]                         ` <<<83lgsll9ey.fsf@gnu.org>
     [not found]                           ` <<59441882-425e-4962-8760-70c505d991dd@default>
     [not found]                             ` <<83lgslja4t.fsf@gnu.org>
2017-03-04 20:40                               ` Drew Adams
     [not found] <<<<87zih7n2yt.fsf@pank.eu>
     [not found] ` <<<<83r32jpr8b.fsf@gnu.org>
     [not found]   ` <<<<87bmtnryqr.fsf@drachen>
     [not found]     ` <<<<87d1e2tzt5.fsf@pank.eu>
     [not found]       ` <<<<8337eypb5l.fsf@gnu.org>
     [not found]         ` <<<<87vartx4qd.fsf@drachen>
     [not found]           ` <<<<56bad9de-8111-4962-a9e9-2dbf0084e004@default>
     [not found]             ` <<<<83wpc6la28.fsf@gnu.org>
     [not found]               ` <<<2cfd6280-34de-4751-b35f-ec7d47a16595@default>
     [not found]                 ` <<<83pohyky8i.fsf@gnu.org>
     [not found]                   ` <<d73ecee8-1b1d-4739-b2b8-e3eb9ecc3ce0@default>
     [not found]                     ` <<83o9xikvop.fsf@gnu.org>
2017-03-03 21:18                       ` Drew Adams
2017-03-04  8:43                         ` Eli Zaretskii
     [not found] <<<87zih7n2yt.fsf@pank.eu>
     [not found] ` <<<83r32jpr8b.fsf@gnu.org>
     [not found]   ` <<<87bmtnryqr.fsf@drachen>
     [not found]     ` <<<87d1e2tzt5.fsf@pank.eu>
     [not found]       ` <<<8337eypb5l.fsf@gnu.org>
     [not found]         ` <<<87vartx4qd.fsf@drachen>
     [not found]           ` <<<56bad9de-8111-4962-a9e9-2dbf0084e004@default>
     [not found]             ` <<<83wpc6la28.fsf@gnu.org>
     [not found]               ` <<2cfd6280-34de-4751-b35f-ec7d47a16595@default>
     [not found]                 ` <<83pohyky8i.fsf@gnu.org>
2017-03-03 19:20                   ` Drew Adams
2017-03-03 19:27                     ` Eli Zaretskii
     [not found] <<87zih7n2yt.fsf@pank.eu>
     [not found] ` <<83r32jpr8b.fsf@gnu.org>
     [not found]   ` <<87bmtnryqr.fsf@drachen>
     [not found]     ` <<87d1e2tzt5.fsf@pank.eu>
     [not found]       ` <<8337eypb5l.fsf@gnu.org>
     [not found]         ` <<87vartx4qd.fsf@drachen>
     [not found]           ` <<56bad9de-8111-4962-a9e9-2dbf0084e004@default>
     [not found]             ` <<83wpc6la28.fsf@gnu.org>
2017-03-03 15:49               ` Drew Adams
2017-03-03 18:32                 ` Eli Zaretskii
2017-02-27 14:05 bug#25890: 26.0.50; " Rasmus
2017-02-27 15:51 ` Eli Zaretskii
2017-02-27 17:09   ` bug#25890: " Rasmus
2017-02-27 23:36   ` bug#25890: 26.0.50; " Michael Heerdegen
2017-02-28  9:44     ` bug#25890: " Rasmus
2017-02-28 15:50       ` Eli Zaretskii
2017-02-28 23:42         ` Michael Heerdegen
2017-02-28 23:54           ` Drew Adams
2017-03-03 14:16             ` Eli Zaretskii
2017-03-01  3:43           ` Eli Zaretskii
2017-03-01  9:55         ` Rasmus
2017-03-03 14:08           ` Eli Zaretskii
2017-03-04 14:24             ` Simen Heggestøyl
2017-03-04 14:38               ` Eli Zaretskii
2017-03-04 15:44                 ` Lars Ingebrigtsen
2017-03-04 16:15                   ` Eli Zaretskii
2017-03-10  5:23 ` mail
2017-03-10  7:28   ` Eli Zaretskii
2017-03-10  8:13     ` mail
2017-03-10  8:33       ` mail
2017-03-10  9:28         ` Eli Zaretskii
2017-03-11 10:06           ` mail
2017-03-10  9:25       ` Eli Zaretskii
2017-03-10 11:07         ` Lars Ingebrigtsen
2017-03-10 13:32           ` Eli Zaretskii
2017-03-11 10:08             ` mail

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=59441882-425e-4962-8760-70c505d991dd@default \
    --to=drew.adams@oracle.com \
    --cc=25890@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=michael_heerdegen@web.de \
    --cc=rasmus@gmx.us \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).