From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#41544: 26.3; Possible incorrect results from color-distance Date: Tue, 2 Jun 2020 22:41:03 +0200 Message-ID: References: <5C4A633D-8222-4439-BE37-9B8674F1DA6D@acm.org> <87r1v2aat3.fsf@tromey.com> <9902865C-01B4-4E50-A433-DBC8B8311234@acm.org> <83tuzueogo.fsf@gnu.org> <6272275C-560C-4437-90F1-2A8294D27019@acm.org> <83o8q2elja.fsf@gnu.org> <83mu5mel4o.fsf@gnu.org> <77F1DDD3-A69F-40ED-902D-74986D5E6596@acm.org> <83y2p5cumz.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.14\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_9A3622FA-6DF5-4FB7-9BFE-40A69D391DCB" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="38270"; mail-complaints-to="usenet@ciao.gmane.io" Cc: tom@tromey.com, simon@polaris64.net, 41544@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 02 22:42:10 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgDje-0009v7-57 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Jun 2020 22:42:10 +0200 Original-Received: from localhost ([::1]:49558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgDjc-0003GQ-W5 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 Jun 2020 16:42:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgDjW-0003CU-1a for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2020 16:42:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jgDjV-0003ZR-OD for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2020 16:42:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jgDjV-0003Ww-KO for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2020 16:42:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 Jun 2020 20:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41544 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 41544-submit@debbugs.gnu.org id=B41544.159113047313515 (code B ref 41544); Tue, 02 Jun 2020 20:42:01 +0000 Original-Received: (at 41544) by debbugs.gnu.org; 2 Jun 2020 20:41:13 +0000 Original-Received: from localhost ([127.0.0.1]:41069 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jgDii-0003Vv-Oi for submit@debbugs.gnu.org; Tue, 02 Jun 2020 16:41:12 -0400 Original-Received: from mail176c50.megamailservers.eu ([91.136.10.186]:59738 helo=mail37c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jgDig-0003Vl-7v for 41544@debbugs.gnu.org; Tue, 02 Jun 2020 16:41:11 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1591130467; bh=65fBZE1X9H5Z6AttrJGQrkXW74UtqfGVeugwwgZ3pZI=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=mmMiqm4hQr/KuDysapK1snlIrhNVfXM3iv2ntHvgTPj9oPKwRqpEIrhNWO58hQAFR 9Tlm3KuD8H54pG6NIz5Vri4r0alRgMLHjVi5BAORbkux8gosmnX7dCojfo+lpjED6g ZKdYSYyY9rElagC0x6rIvs3qwIalgkzAOMtgvW84= Feedback-ID: mattiase@acm.or Original-Received: from stanniol.lan (c-4e4ae655.032-75-73746f71.bbcust.telenor.se [85.230.74.78]) (authenticated bits=0) by mail37c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 052Kf3bL029641; Tue, 2 Jun 2020 20:41:05 +0000 In-Reply-To: <83y2p5cumz.fsf@gnu.org> X-Mailer: Apple Mail (2.3445.104.14) X-CTCH-RefID: str=0001.0A782F27.5ED6B909.0035:SCFSTAT68638221, ss=1, re=-4.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: -4.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=bJNo382Z c=1 sm=1 tr=0 a=klNLuyVZdLUgl+K5Uafb2A==:117 a=klNLuyVZdLUgl+K5Uafb2A==:17 a=M51BFTxLslgA:10 a=mDV3o1hIAAAA:8 a=bM8LWKgTAXqvqXeV2bUA:9 a=CjuIK1q_8ugA:10 a=p9XNr_QT056JWQCrFTgA:9 a=B2y7HmGcmWMA:10 a=_FVE-zBwftR9WsbkzFJk:22 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181426 Archived-At: --Apple-Mail=_9A3622FA-6DF5-4FB7-9BFE-40A69D391DCB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 2 juni 2020 kl. 18.14 skrev Eli Zaretskii : > I'd prefer to fix only the symmetry bug (which AFAIU happens because > we use bit shifts on signed integers), without introducing any other > effects on the function's behavior and return values. AFAIU, such a > fix should not require any changes outside of the function itself. Very well, it is obviously an improvement. The reason for the current = asymmetry was actually that the algorithm discarded the low bits; what = about fixing that as well? The improved accuracy amounts to less than 1 = % of difference in the return value; no other code needs changing, and = we get the symmetry for free. Proposed patch attached. --Apple-Mail=_9A3622FA-6DF5-4FB7-9BFE-40A69D391DCB Content-Disposition: attachment; filename=0001-Make-color-distance-symmetric-and-more-accurate.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Make-color-distance-symmetric-and-more-accurate.patch" Content-Transfer-Encoding: quoted-printable =46rom=20b40a56f8be6add33f7de634f0966887622063e43=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Tue,=202=20Jun=202020=2022:31:14=20+0200=0A= Subject:=20[PATCH]=20Make=20color-distance=20symmetric=20and=20more=20= accurate=0A=0A*=20src/xfaces.c=20(color_distance):=20Don't=20throw=20= away=20the=20low=208=20bits=20of=0Athe=20colours,=20and=20make=20the=20= function=20symmetric=20(bug41544)=0A(Fcolor_distance):=20Add=20caution=20= about=20this=20not=20being=20a=20true=20metric.=0A*=20= test/src/xfaces-tests.el:=20New=20file.=0A---=0A=20src/xfaces.c=20=20=20=20= =20=20=20=20=20=20=20=20=20|=2024=20+++++++++++++-----------=0A=20= test/src/xfaces-tests.el=20|=2027=20+++++++++++++++++++++++++++=0A=202=20= files=20changed,=2040=20insertions(+),=2011=20deletions(-)=0A=20create=20= mode=20100644=20test/src/xfaces-tests.el=0A=0Adiff=20--git=20= a/src/xfaces.c=20b/src/xfaces.c=0Aindex=207d7aff95c1..cf155288bd=20= 100644=0A---=20a/src/xfaces.c=0A+++=20b/src/xfaces.c=0A@@=20-4356,15=20= +4356,15=20@@=20color_distance=20(Emacs_Color=20*x,=20Emacs_Color=20*y)=0A= =20=0A=20=20=20=20=20=20See=20=20= for=20more=20info.=20=20*/=0A=20=0A-=20=20long=20r=20=3D=20(x->red=20=20=20= -=20y->red)=20=20=20>>=208;=0A-=20=20long=20g=20=3D=20(x->green=20-=20= y->green)=20>>=208;=0A-=20=20long=20b=20=3D=20(x->blue=20=20-=20y->blue)=20= =20>>=208;=0A-=20=20long=20r_mean=20=3D=20(x->red=20+=20y->red)=20>>=20= 9;=0A-=0A-=20=20return=0A-=20=20=20=20(((512=20+=20r_mean)=20*=20r=20*=20= r)=20>>=208)=0A-=20=20=20=20+=204=20*=20g=20*=20g=0A-=20=20=20=20+=20= (((767=20-=20r_mean)=20*=20b=20*=20b)=20>>=208);=0A+=20=20long=20long=20= r=20=3D=20x->red=20=20=20-=20y->red;=0A+=20=20long=20long=20g=20=3D=20= x->green=20-=20y->green;=0A+=20=20long=20long=20b=20=3D=20x->blue=20=20-=20= y->blue;=0A+=20=20long=20long=20r_mean=20=3D=20(x->red=20+=20y->red)=20= >>=201;=0A+=0A+=20=20return=20(((((2=20*=2065536=20+=20r_mean)=20*=20r=20= *=20r)=20>>=2016)=0A+=20=20=20=20=20=20=20=20=20=20=20+=204=20*=20g=20*=20= g=0A+=20=20=20=20=20=20=20=20=20=20=20+=20(((2=20*=2065536=20+=2065535=20= -=20r_mean)=20*=20b=20*=20b)=20>>=2016))=0A+=20=20=20=20=20=20=20=20=20=20= >>=2016);=0A=20}=0A=20=0A=20=0A@@=20-4374,7=20+4374,9=20@@=20DEFUN=20= ("color-distance",=20Fcolor_distance,=20Scolor_distance,=202,=204,=200,=0A= =20or=20lists=20of=20the=20form=20(RED=20GREEN=20BLUE),=20each=20in=20= the=20range=200=20to=2065535=20inclusive.=0A=20If=20FRAME=20is=20= unspecified=20or=20nil,=20the=20current=20frame=20is=20used.=0A=20If=20= METRIC=20is=20specified,=20it=20should=20be=20a=20function=20that=20= accepts=0A-two=20lists=20of=20the=20form=20(RED=20GREEN=20BLUE)=20= aforementioned.=20*/)=0A+two=20lists=20of=20the=20form=20(RED=20GREEN=20= BLUE)=20aforementioned.=0A+Despite=20the=20name,=20this=20is=20not=20a=20= true=20distance=20metric=20as=20it=20does=20not=20satisfy=0A+the=20= triangle=20inequality.=20=20*/)=0A=20=20=20(Lisp_Object=20color1,=20= Lisp_Object=20color2,=20Lisp_Object=20frame,=0A=20=20=20=20Lisp_Object=20= metric)=0A=20{=0A@@=20-4931,7=20+4933,7=20@@=20DEFUN=20= ("face-attributes-as-vector",=20Fface_attributes_as_vector,=0A=20=0A=20= /*=20If=20the=20distance=20(as=20returned=20by=20color_distance)=20= between=20two=20colors=20is=0A=20=20=20=20less=20than=20this,=20then=20= they=20are=20considered=20the=20same,=20for=20determining=0A-=20=20=20= whether=20a=20color=20is=20supported=20or=20not.=20=20The=20range=20of=20= values=20is=200-65535.=20=20*/=0A+=20=20=20whether=20a=20color=20is=20= supported=20or=20not.=20=20*/=0A=20=0A=20#define=20= TTY_SAME_COLOR_THRESHOLD=20=2010000=0A=20=0Adiff=20--git=20= a/test/src/xfaces-tests.el=20b/test/src/xfaces-tests.el=0Anew=20file=20= mode=20100644=0Aindex=200000000000..f08a87a518=0A---=20/dev/null=0A+++=20= b/test/src/xfaces-tests.el=0A@@=20-0,0=20+1,27=20@@=0A+;;;=20= xfaces-tests.el=20---=20tests=20for=20xfaces.c=20=20=20=20=20=20=20=20=20= =20=20-*-=20lexical-binding:=20t=20-*-=0A+=0A+;;=20Copyright=20(C)=20= 2020=20Free=20Software=20Foundation,=20Inc.=0A+=0A+;;=20This=20file=20is=20= part=20of=20GNU=20Emacs.=0A+=0A+;;=20GNU=20Emacs=20is=20free=20software:=20= you=20can=20redistribute=20it=20and/or=20modify=0A+;;=20it=20under=20the=20= terms=20of=20the=20GNU=20General=20Public=20License=20as=20published=20= by=0A+;;=20the=20Free=20Software=20Foundation,=20either=20version=203=20= of=20the=20License,=20or=0A+;;=20(at=20your=20option)=20any=20later=20= version.=0A+=0A+;;=20GNU=20Emacs=20is=20distributed=20in=20the=20hope=20= that=20it=20will=20be=20useful,=0A+;;=20but=20WITHOUT=20ANY=20WARRANTY;=20= without=20even=20the=20implied=20warranty=20of=0A+;;=20MERCHANTABILITY=20= or=20FITNESS=20FOR=20A=20PARTICULAR=20PURPOSE.=20=20See=20the=0A+;;=20= GNU=20General=20Public=20License=20for=20more=20details.=0A+=0A+;;=20You=20= should=20have=20received=20a=20copy=20of=20the=20GNU=20General=20Public=20= License=0A+;;=20along=20with=20GNU=20Emacs.=20=20If=20not,=20see=20= .=0A+=0A+(require=20'ert)=0A+=0A= +(ert-deftest=20xfaces-color-distance=20()=0A+=20=20;;=20Check=20= symmetry=20(bug#51455).=0A+=20=20(should=20(equal=20(color-distance=20= "#222222"=20"#ffffff")=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(color-distance=20"#ffffff"=20"#222222"))))=0A+=0A+(provide=20= 'xfaces-tests)=0A--=20=0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_9A3622FA-6DF5-4FB7-9BFE-40A69D391DCB--