From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?q?Rami=20Ylim=C3=A4ki?= Newsgroups: gmane.emacs.devel Subject: [PATCH 2/3] Support 24-bit terminal colors. Date: Sun, 12 Feb 2017 12:05:29 +0200 Message-ID: <1486893930-6709-3-git-send-email-rami.ylimaki@vincit.fi> References: <1486893930-6709-1-git-send-email-rami.ylimaki@vincit.fi> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1486911292 24654 195.159.176.226 (12 Feb 2017 14:54:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 12 Feb 2017 14:54:52 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Feb 12 15:54:47 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 1ccvY6-0005yt-R3 for ged-emacs-devel@m.gmane.org; Sun, 12 Feb 2017 15:54:46 +0100 Original-Received: from localhost ([::1]:52311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ccvYC-0000E5-DT for ged-emacs-devel@m.gmane.org; Sun, 12 Feb 2017 09:54:52 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ccr2V-0002PX-77 for emacs-devel@gnu.org; Sun, 12 Feb 2017 05:05:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ccr2S-0004Vq-22 for emacs-devel@gnu.org; Sun, 12 Feb 2017 05:05:51 -0500 Original-Received: from mail.kapsi.fi ([217.30.184.167]:45080) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ccr2R-0004Uo-Qe for emacs-devel@gnu.org; Sun, 12 Feb 2017 05:05:47 -0500 Original-Received: from 91-158-222-159.elisa-laajakaista.fi ([91.158.222.159] helo=nopsakone.home) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1ccr2K-00028y-UA for emacs-devel@gnu.org; Sun, 12 Feb 2017 12:05:40 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486893930-6709-1-git-send-email-rami.ylimaki@vincit.fi> X-SA-Exim-Connect-IP: 91.158.222.159 X-SA-Exim-Mail-From: rami.ylimaki@vincit.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.30.184.167 X-Mailman-Approved-At: Sun, 12 Feb 2017 09:54:39 -0500 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:212278 Archived-At: From: Rami Ylimäki Assume that number of terminal colors has been set to 16777216 if terminal supports direct color mode. Detection of 24-bit color support is added in next commit. * lisp/term/tty-colors.el (tty-color-define): Convert color palette index to pixel value on 16.7M color terminals. (tty-color-24bit): Add new function to convert color palette index to pixel value on 16.7M color terminals. (tty-color-desc): Don't approximate colors on 16.7M color terminals. * lisp/term/xterm.el (xterm-register-default-colors): Define all named TTY colors on 16.7M color terminals. --- lisp/term/tty-colors.el | 19 +++++++++++++++++-- lisp/term/xterm.el | 8 ++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lisp/term/tty-colors.el b/lisp/term/tty-colors.el index 252a430..9cfe30a 100644 --- a/lisp/term/tty-colors.el +++ b/lisp/term/tty-colors.el @@ -824,6 +824,15 @@ A canonicalized color name is all-lower case, with any blanks removed." (replace-regexp-in-string " +" "" (downcase color)) color))) +(defun tty-color-24bit (rgb) + "Return pixel value on 24-bit terminals. Return nil if RGB is +nil or not on 24-bit terminal." + (when (and rgb (= (display-color-cells) 16777216)) + (let ((r (lsh (car rgb) -8)) + (g (lsh (cadr rgb) -8)) + (b (lsh (nth 2 rgb) -8))) + (logior (lsh r 16) (lsh g 8) b)))) + (defun tty-color-define (name index &optional rgb frame) "Specify a tty color by its NAME, terminal INDEX and RGB values. NAME is a string, INDEX is typically a small integer used to send to @@ -840,7 +849,10 @@ If FRAME is not specified or is nil, it defaults to the selected frame." (and rgb (or (not (listp rgb)) (/= (length rgb) 3)))) (error "Invalid specification for tty color \"%s\"" name)) (tty-modify-color-alist - (append (list (tty-color-canonicalize name) index) rgb) frame)) + (append (list (tty-color-canonicalize name) + (or (tty-color-24bit rgb) index)) + rgb) + frame)) (defun tty-color-clear (&optional _frame) "Clear the list of supported tty colors for frame FRAME. @@ -1013,7 +1025,10 @@ might need to be approximated if it is not supported directly." (let ((color (tty-color-canonicalize color))) (or (assoc color (tty-color-alist frame)) (let ((rgb (tty-color-standard-values color))) - (and rgb (tty-color-approximate rgb frame))))))) + (and rgb + (let ((pixel (tty-color-24bit rgb))) + (or (and pixel (cons color (cons pixel rgb))) + (tty-color-approximate rgb frame))))))))) (defun tty-color-gray-shades (&optional display) "Return the number of gray colors supported by DISPLAY's terminal. diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index 339d05d..e6d224d 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el @@ -930,6 +930,14 @@ versions of xterm." ;; are more colors to support, compute them now. (when (> ncolors 0) (cond + ((= ncolors 16777200) ; 24-bit xterm + ;; all named tty colors + (let ((idx (length xterm-standard-colors))) + (mapc (lambda (color) + (unless (assoc (car color) xterm-standard-colors) + (tty-color-define (car color) idx (cdr color)) + (setq idx (1+ idx)))) + color-name-rgb-alist))) ((= ncolors 240) ; 256-color xterm ;; 216 non-gray colors first (let ((r 0) (g 0) (b 0)) -- 2.7.4