From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#25890: `color-values` gives wrong value Date: Tue, 28 Feb 2017 17:50:30 +0200 Message-ID: <8337eypb5l.fsf@gnu.org> References: <87zih7n2yt.fsf@pank.eu> <83r32jpr8b.fsf@gnu.org> <87bmtnryqr.fsf@drachen> <87d1e2tzt5.fsf@pank.eu> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1488298831 6669 195.159.176.226 (28 Feb 2017 16:20:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 28 Feb 2017 16:20:31 +0000 (UTC) Cc: michael_heerdegen@web.de, 25890@debbugs.gnu.org To: Rasmus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Feb 28 17:20:27 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cikVk-0000zn-F4 for geb-bug-gnu-emacs@m.gmane.org; Tue, 28 Feb 2017 17:20:24 +0100 Original-Received: from localhost ([::1]:35222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cikVq-0000IR-EI for geb-bug-gnu-emacs@m.gmane.org; Tue, 28 Feb 2017 11:20:30 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cik4O-0000ds-96 for bug-gnu-emacs@gnu.org; Tue, 28 Feb 2017 10:52:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cik4I-0001uE-C9 for bug-gnu-emacs@gnu.org; Tue, 28 Feb 2017 10:52:08 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34008) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cik4I-0001u5-8i for bug-gnu-emacs@gnu.org; Tue, 28 Feb 2017 10:52:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cik4H-0002Ay-VR for bug-gnu-emacs@gnu.org; Tue, 28 Feb 2017 10:52:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 28 Feb 2017 15:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25890 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25890-submit@debbugs.gnu.org id=B25890.14882970678299 (code B ref 25890); Tue, 28 Feb 2017 15:52:01 +0000 Original-Received: (at 25890) by debbugs.gnu.org; 28 Feb 2017 15:51:07 +0000 Original-Received: from localhost ([127.0.0.1]:60440 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cik3O-00029m-RV for submit@debbugs.gnu.org; Tue, 28 Feb 2017 10:51:07 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:47584) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cik3M-00029I-9G for 25890@debbugs.gnu.org; Tue, 28 Feb 2017 10:51:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cik3D-0001Xx-U1 for 25890@debbugs.gnu.org; Tue, 28 Feb 2017 10:50:59 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:49245) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cik3D-0001Xs-Q0; Tue, 28 Feb 2017 10:50:55 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3421 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1cik3C-0005V1-WE; Tue, 28 Feb 2017 10:50:55 -0500 In-reply-to: <87d1e2tzt5.fsf@pank.eu> (message from Rasmus on Tue, 28 Feb 2017 10:44:22 +0100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:129947 Archived-At: > From: Rasmus > Cc: eliz@gnu.org, 25890@debbugs.gnu.org > Date: Tue, 28 Feb 2017 10:44:22 +0100 > > Michael Heerdegen writes: > > > Eli Zaretskii writes: > > > >> > (color-values "#ffffff") => (65280 65280 65280) ; The max values. > >> > >> Are you sure? > > > > FWIW, I see the same here; and we already have a bug report like this > > one: > > > > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24273 > > Oh thanks. (I didn't search as gmane search is still down). > > I guess this bug can be closed. I'd rather we fixed it. I think there's a bug in color.el: it assumes that the #RGB notation uses 24 bits, i.e. each component maxes out at 255. But Emacs does its color calculations based on 16-bit components, which max out at 65535, which is why #ffffff does NOT produce (65535 65535 65535), the white color. (We decided long ago to use 16-bit components because X APIs such as XParseColor on some systems, including yours, work with such components.) IOW, #ffffff is parsed as #ff00ff00ff00, and that is not "white". So I think the patch below is what is needed to fix this problem. Can you try it? (There's one user of the functions the patch changes, shr-color.el, which will need to be adapted to the change, if we decide to install it.) --- lisp/color.el~0 2017-01-02 06:25:09.000000000 +0200 +++ lisp/color.el 2017-02-28 17:35:43.570586100 +0200 @@ -52,14 +52,14 @@ If FRAME cannot display COLOR, return nil." ;; `colors-values' maximum value is either 65535 or 65280 depending on the ;; display system. So we use a white conversion to get the max value. - (let ((valmax (float (car (color-values "#ffffff"))))) + (let ((valmax (float (car (color-values "#ffffffffffff"))))) (mapcar (lambda (x) (/ x valmax)) (color-values color frame)))) (defun color-rgb-to-hex (red green blue) "Return hexadecimal notation for the color RED GREEN BLUE. RED, GREEN, and BLUE should be numbers between 0.0 and 1.0, inclusive." - (format "#%02x%02x%02x" - (* red 255) (* green 255) (* blue 255))) + (format "#%04x%04x%04x" + (* red 65535) (* green 65535) (* blue 65535))) (defun color-complement (color-name) "Return the color that is the complement of COLOR-NAME.