From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Simon Pugnet Newsgroups: gmane.emacs.bugs Subject: bug#41544: 26.3; Possible incorrect results from color-distance Date: Tue, 26 May 2020 17:29:16 +0100 Message-ID: <874ks2vew3.fsf@polaris64.net> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="607"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.2.0; emacs 26.3 To: 41544@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 26 18:34:25 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 1jdcX3-00007S-PS for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 May 2020 18:34:25 +0200 Original-Received: from localhost ([::1]:60692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdcX2-0007BK-NG for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 May 2020 12:34:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdcWg-0007AX-Ip for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 12:34:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34739) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdcWg-0005SR-9A for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 12:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jdcWg-00075E-1i for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 12:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Simon Pugnet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 May 2020 16:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41544 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.159051083327211 (code B ref -1); Tue, 26 May 2020 16:34:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 May 2020 16:33:53 +0000 Original-Received: from localhost ([127.0.0.1]:46285 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jdcWW-00074o-7o for submit@debbugs.gnu.org; Tue, 26 May 2020 12:33:53 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:56180) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jdcSB-0006xQ-Vo for submit@debbugs.gnu.org; Tue, 26 May 2020 12:29:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdcSB-0003Ri-OL for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 12:29:23 -0400 Original-Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]:41656) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdcSA-0002AM-OF for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 12:29:23 -0400 Original-Received: by mail-ed1-x52e.google.com with SMTP id g9so18157508edr.8 for ; Tue, 26 May 2020 09:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:user-agent:from:to:subject:date:message-id:mime-version; bh=Ygv0y36F2M0o2eiv0rVcXfxE2lsx9jISFI1OTaZl6Js=; b=BTsOnbiozsnmsJU5tNQOjCJHLK4LJ8Peew+OsCBHIVSo3HUlVcWmJJebPXEMsCpjHF YSdaOT67FEJuTpx+ZpUaIambA9X72CHkHkKzbyAuvSVjSySGXWml/HgD+dOEZht6qMN6 WQZW1gP+soFOWjtxedCE8Tl1lubaRWCGsqq6dOBF2w5UjAtkrikI2xjO6WUojikVpKh5 dmRQv9kSYmZGeByxCvBzk1sA0FqWAlIk4vA2jklGa+L2nIUKGAjIwqMN+1dyZ4sx7+tL VJWT5tMbBzyTBokMOj483oNgrD8NvPuLepLcOrD84OjsEFqzBB8YvaxtrcxAW5DJYJwv iH3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:user-agent:from:to:subject:date :message-id:mime-version; bh=Ygv0y36F2M0o2eiv0rVcXfxE2lsx9jISFI1OTaZl6Js=; b=oZWzz9pjjLRnehcYNiFkFfNQV+SKM/jwTbByYVUQe/oAq9PbylRFHOHMdPpvTVgjtR juWCBfBWWwNLG0ngyquQ4/+lHgSqtlC0vyoxl5mLLz92u7+xbhFE5udWf3zr8tNTMLbx NRdCiOw1FsbgDl9LLUT1zQBH7JmrqFmVTa1Uw1f3fRu2QWv41B2ZHlLKiHVyWVQEP+gx OyH8uB6eB4V3Yqx5Mdqh8laLFEGAuJZ462f2vt9/KTKX7eB+MG4GhX0C3hjASrYwZsnP lhlJot4V/bDyG285Mv06FnbdEBaC+rqsy9j8ynYKsZsYb3JZhd10+6mVNyZpXE/xcZXl D1ag== X-Gm-Message-State: AOAM530tteDcmRNDjUs8Cg/8y/pI8iMXQk8HGy8e0gtEv6iS8ZXYOIA0 kc0lr7oUHDfi8x96o5kehhL3Nh3w X-Google-Smtp-Source: ABdhPJx7pm/cfc3tF/8VIw/OQaqWZCn8+FVGpOwf7cvXL1Z3Fr641hmKgFaYVNXmEuXn9buuLNmymQ== X-Received: by 2002:a05:6402:2058:: with SMTP id bc24mr21034906edb.134.1590510559854; Tue, 26 May 2020 09:29:19 -0700 (PDT) Original-Received: from karnak (25-56.dsl.iskon.hr. [89.164.25.56]) by smtp.gmail.com with ESMTPSA id a3sm303413edv.70.2020.05.26.09.29.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 09:29:18 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::52e; envelope-from=simon.pugnet@gmail.com; helo=mail-ed1-x52e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Mailman-Approved-At: Tue, 26 May 2020 12:33:51 -0400 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:181054 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Hello, I have noticed some potentially incorrect behaviour from the `color-distance` elisp function. As an example, take the following elisp: - (list (color-distance '(0 0 0) '(65535 65535 65535)) (color-distance '(65535 65535 65535) '(0 0 0)) (color-distance '(1 2 3) '(4 5 6)) (color-distance '(4 5 6) '(1 2 3))) Result: (589568 584970 8 0) Here, I would expect the first two elements to have the same=20 result as well as the third and fourth. This is because conceptually the=20 distance between colour (1 2 3) and (4 5 6) is the same as the distance=20 between (4 5 6) and (1 2 3), etc. The problem comes from the `color_distance()` C function. In this function, values are calculated via bit shifts to perform integer divisions of 256 (>>8) and 512 (>>9). Take for example the 3rd and=20 4th items above (red channel): - 1 - 4 =3D -3 4 - 1 =3D 3 but: - (1 - 4) >> 8 =3D -1 (4 - 1) >> 8 =3D 0 Therefore for negative values, there is a difference of 1 every=20 time the bit shift is performed, which is what leads to the discrepancy=20 mentioned above. Modifying the function to remove these discrepancies causes the=20 results above to become (584970 584970 0 0) which appear to be more=20 sensible. My apologies in advance if this is in fact the correct behaviour=20 of this function. Kind regards, =2D- Simon Pugnet https://www.polaris64.net/ =2D-- In GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version=20 3.24.14) of 2020-03-26, modified by Debian built on lcy01-amd64-020 Windowing system distributor 'The X.Org Foundation', version=20 11.0.12008000 System Description: Ubuntu 20.04 LTS Recent messages: For information about GNU Emacs and the GNU system, type C-h C-a. Mark set (589568 584970 8 0) You can run the command =E2=80=98eval-print-last-sexp=E2=80=99 with C-j Mark activated kill-line: End of buffer Making completion list... You can run the command =E2=80=98kill-region=E2=80=99 with C-w Configured using: 'configure --build x86_64-linux-gnu --prefix=3D/usr --sharedstatedir=3D/var/lib --libexecdir=3D/usr/lib --localstatedir=3D/var/lib --infodir=3D/usr/share/info --mandir=3D/usr/share/man --enable-libsystemd --with-pop=3Dyes --enable-locallisppath=3D/etc/emacs:/usr/local/share/emacs/26.3/site-lisp:= /usr/local/share/emacs/site-lisp:/usr/share/emacs/26.3/site-lisp:/usr/share= /emacs/site-lisp --with-sound=3Dalsa --without-gconf --with-mailutils --build x86_64-linux-gnu --prefix=3D/usr --sharedstatedir=3D/var/lib --libexecdir=3D/usr/lib --localstatedir=3D/var/lib --infodir=3D/usr/share/info --mandir=3D/usr/share/man=20 --enable-libsystemd --with-pop=3Dyes --enable-locallisppath=3D/etc/emacs:/usr/local/share/emacs/26.3/site-lisp:= /usr/local/share/emacs/site-lisp:/usr/share/emacs/26.3/site-lisp:/usr/share= /emacs/site-lisp --with-sound=3Dalsa --without-gconf --with-mailutils --with-x=3Dyes --with-x-toolkit=3Dgtk3 --with-toolkit-scroll-bars 'CFLAGS=3D-g -O2 -fdebug-prefix-map=3D/build/emacs-mEZBk7/emacs-26.3+1=3D.=20 -fstack-protector-strong -Wformat -Werror=3Dformat-security -Wall' 'CPPFLAGS=3D-Wdate-time -D_FORTIFY_SOURCE=3D2' 'LDFLAGS=3D-Wl,-Bsymbolic-functions=20 -Wl,-z,relro'' Configured features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS=20 GLIB NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT=20 ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM THREADS LIBSYSTEMD LCMS2 Important settings: value of $LANG: en_GB.UTF-8 value of $XMODIFIERS: @im=3Dnone locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message rmc puny seq byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib dired=20 dired-loaddefs format-spec rfc822 mml easymenu mml-sec password-cache epa derived=20 epg epg-config gnus-util rmail rmail-loaddefs mm-decode mm-bodies=20 mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail=20 rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils elec-pair=20 time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win term/common-win x-dnd=20 tool-bar dnd fontset image regexp-opt fringe tabulated-list replace=20 newcomment text-mode elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock=20 font-lock syntax facemenu font-core term/tty-colors frame cl-generic cham=20 georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech=20 european ethiopic indian cyrillic chinese composite charscript charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray=20 minibuffer cl-preloaded nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote threads dbusbind inotify lcms2 dynamic-setting system-font-setting=20 font-render-setting move-toolbar gtk x-toolkit x multi-tty make-network-process emacs) Memory information: ((conses 16 95338 8459) (symbols 48 20386 1) (miscs 40 50 168) (strings 32 28445 1160) (string-bytes 1 747812) (vectors 16 13900) (vector-slots 8 500980 11290) (floats 8 51 264) (intervals 56 301 25) (buffers 992 12)) --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO/eF3hYsAMj7Tab9uhNZqCwLPvkFAl7NQ9wACgkQuhNZqCwL PvnI3g//fDYKiUcyxn3W/fHed3y3cjPc1HkkB/0o5pnwfe+zK2W7Ldp2Q/xZwpE3 P2mPXDMIUzxP8XgIUR/IgyMWJytTKE68ifUuy9WT8iRPjoNSq7U7JtbM/1xUUzlJ 3735l1X4MPcrX2MwV27oqVb52a2UZLVlL5+9GYu1Wr5UeTTx9Mzm5RmcI009dtp5 C8QkP4/uls+U/hEsk0tNKocMROMzDX3K3J7tFe4KlIkIktjU8A9Fc0cmCfOnKsR3 SjHeyKhfRnFAmarrrAXhTduFN3lCfBh2HK+MpeoZ5ba4f+RQpjRPmuBdwWeuGMtQ Oy0Bhx4Q3iMyd1zezDy2p3ax/qyhyiHgWk9EPo7T5T0ILEvpA3XuPRyStux4gEX8 Fxcaf9r8va/n++if4hY/oJmATMmWNfjFM1p3gPM4CMDUPdd1tORqvDvUdKFeCs/7 dYYQ0keUuGDNyBkqvxrZT1dpvrGky2pg+YSOy2tVNdDQjC3x1N8kXMDn3LMlAmp+ ZEXzdMqrHyodIzLf3eIaejqmnNb/wWmpOcD9O1StQGS81AvFL89qc0cqPqEAUScl FG9Ot3EF5tAKap/TxScgLdSpJjEDrh7zvWAXMRsikXSCsVPgybXM0Ju1INLXWveR cEn6kKpc574TqroYYqnse6rmrAamh+ev3xGg9ukvw+kYFCSou/4= =HoyA -----END PGP SIGNATURE----- --=-=-=--