From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark Oteiza Newsgroups: gmane.emacs.devel Subject: Re: Doc string and operation of color-distance Date: Thu, 14 Sep 2017 15:43:28 -0400 Message-ID: <874ls5xdzz.fsf@udel.edu> References: <83mv5xm84m.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1505418248 18825 195.159.176.226 (14 Sep 2017 19:44:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 14 Sep 2017 19:44:08 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 14 21:44:04 2017 Return-path: Envelope-to: ged-emacs-devel@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 1dsa3O-0004ho-9h for ged-emacs-devel@m.gmane.org; Thu, 14 Sep 2017 21:44:02 +0200 Original-Received: from localhost ([::1]:49739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsa3V-0002gD-EF for ged-emacs-devel@m.gmane.org; Thu, 14 Sep 2017 15:44:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsa2w-0002fn-5m for emacs-devel@gnu.org; Thu, 14 Sep 2017 15:43:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsa2s-00063F-Vo for emacs-devel@gnu.org; Thu, 14 Sep 2017 15:43:34 -0400 Original-Received: from mail-qk0-x229.google.com ([2607:f8b0:400d:c09::229]:51614) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dsa2s-00062m-Kg for emacs-devel@gnu.org; Thu, 14 Sep 2017 15:43:30 -0400 Original-Received: by mail-qk0-x229.google.com with SMTP id c69so360207qke.8 for ; Thu, 14 Sep 2017 12:43:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=udel-edu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=XI4upPDYwZY3gHKWbhkUrSDKo2wNZ8ucmyGYqiqLuB8=; b=FNfAQtt80JZlSDdcNQD7jrBTBkVW5cD6rW0KTeazaXSNfBGcD2U7TlVj2WIPjIjLOS pkx3SLq40+W8BE5w/WqcS4na2JQNPtLkMZAN4X+sAfFzOLjGHdTDjyHp8kgybqvULrIs pLXbbZCj9C3Oo0Agz/tICST+MgQr8L97aoxRbJagfGh8i75PJLEsM36iTup+Hi07g5uh Zm+dtt09ube0pm9oOkcikh68525Y9msh6cZiEYd5Lhnf5OBZJpwquUE5HyCsQYs50+Op rXrezZRtkigzOVZbDoZx7jMjM/GMAa3hTymSOQL9IXDwIetQsFiZ3uMzoUIsH2Qqjxcs dinQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=XI4upPDYwZY3gHKWbhkUrSDKo2wNZ8ucmyGYqiqLuB8=; b=Zejj88ADqAO+LruZ6lpSOtB1YxP7aASW4HShH9rYJnx+aCAEZU2pRBZX3ODqOfLFw1 mopPZ2m9REh9N+VU1rlBrHXFZ/fIAA9K0s/ROKnMn/X72yjxp2IQuQzNoDOormYYhpiO pD12++MapSb6+nQGSkQZXp/6NGcq0a1oHmoQMT161bJOgMKh2vkdU0FI+G/zgBSVvdAl pO6aleiS+rM76ImQQWC+sp5whJnclVfXf1X4PvBzEsGY/eSvxgXQ7P92jxmeQZYX0k8u gR0QxDgiaeu2RXCDpCxbsAslXCXpMb/tdn5v2krXp5rlGUJOXEkAOlUe/ir0L5HqA4VE DJPA== X-Gm-Message-State: AHPjjUhV2LVbJzfA/mOmIptJx69MNSav/OlOOPjwas3PajUuThiitBKc 45FKn1i3t4ssU6F7 X-Google-Smtp-Source: AOwi7QCSc7GjHxBxU8L2pUyc1NGOv4qkNdMoDpvhx8w64YYwj/JcnErylB2yYd/7FyQd7DpctMKV7A== X-Received: by 10.55.23.86 with SMTP id i83mr4224130qkh.332.1505418209931; Thu, 14 Sep 2017 12:43:29 -0700 (PDT) Original-Received: from holos.localdomain (pool-173-67-36-61.bltmmd.fios.verizon.net. [173.67.36.61]) by smtp.gmail.com with ESMTPSA id k2sm11342609qkc.36.2017.09.14.12.43.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Sep 2017 12:43:29 -0700 (PDT) Original-Received: by holos.localdomain (Postfix, from userid 1000) id 0A89669FAF; Thu, 14 Sep 2017 15:43:29 -0400 (EDT) In-Reply-To: <83mv5xm84m.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::229 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:218291 Archived-At: Eli Zaretskii writes: > Mark, the new color-distance says something strange in its doc string: > > (color-distance COLOR1 COLOR2 &optional FRAME METRIC) > > Return an integer distance between COLOR1 and COLOR2 on FRAME. > COLOR1 and COLOR2 may be either strings containing the color name, > or lists of the form (RED GREEN BLUE), each in the range 0 to 65535 inclusive. > If FRAME is unspecified or nil, the current frame is used. > If METRIC is unspecified or nil, a modified L*u*v* metric is used. > > The last sentence should say "non-nil", I think, and it should > document that METRIC is supposed to be a function of 2 colors. > > Also, this is unexpected: > > (color-distance "red" "blue" nil 'lcms-cam02-ucs) > => (error "Invalid color" "red") > > I think the new lcms2 functions should support colors specified as > strings, because all the other color-related functions do. At the very least we should feed metrics the translated RGBs. Beyond that, in order to use (for example) lcms2-cam02-ucs with color-distance, one has to translate RGB to XYZ, so the metric would be (lambda (a b) (lcms2-cam02-ucs (color-srgb-to-xyz a) (color-srgb-to-xyz b)) diff --git a/src/xfaces.c b/src/xfaces.c index 012de4e7af..9804c96c39 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -4093,7 +4093,9 @@ DEFUN ("color-distance", Fcolor_distance, Scolor_distance, 2, 4, 0, COLOR1 and COLOR2 may be either strings containing the color name, or lists of the form (RED GREEN BLUE), each in the range 0 to 65535 inclusive. If FRAME is unspecified or nil, the current frame is used. -If METRIC is unspecified or nil, a modified L*u*v* metric is used. */) +If METRIC is specified, it should be a function that accepts two +lists of the form (RED GREEN BLUE). The default metric uses a +modified L*u*v* space. */) (Lisp_Object color1, Lisp_Object color2, Lisp_Object frame, Lisp_Object metric) { @@ -4112,7 +4114,15 @@ If METRIC is unspecified or nil, a modified L*u*v* metric is used. */) if (NILP (metric)) return make_number (color_distance (&cdef1, &cdef2)); else - return call2 (metric, color1, color2); + { + Lisp_Object rgb1 = list3 (make_number (&cdef1.red), + make_number (&cdef1.green), + make_number (&cdef1.blue)); + Lisp_Object rgb2 = list3 (make_number (&cdef2.red), + make_number (&cdef2.green), + make_number (&cdef2.blue)); + return call2 (metric, rgb1, rgb2); + } }