From: "Rami Ylimäki" <rami.ylimaki@vincit.fi>
To: emacs-devel@gnu.org
Subject: [PATCH v3 2/4] Support 24-bit terminal colors.
Date: Tue, 14 Feb 2017 17:58:20 +0200 [thread overview]
Message-ID: <1487087902-6661-3-git-send-email-rami.ylimaki@vincit.fi> (raw)
In-Reply-To: <1487087902-6661-1-git-send-email-rami.ylimaki@vincit.fi>
From: Rami Ylimäki <rjy@iki.fi>
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
next prev parent reply other threads:[~2017-02-14 15:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-14 15:58 [PATCH v3 0/4] Support 24-bit terminal colors Rami Ylimäki
2017-02-14 15:58 ` [PATCH v3 1/4] Remove unused terminal color pair count Rami Ylimäki
2017-02-14 15:58 ` Rami Ylimäki [this message]
2017-02-14 15:58 ` [PATCH v3 3/4] Let user turn 24-bit terminal colors on Rami Ylimäki
2017-02-14 15:58 ` [PATCH v3 4/4] Update documentation regarding 24-bit TTY colors Rami Ylimäki
2017-02-18 11:07 ` [PATCH v3 0/4] Support 24-bit terminal colors Eli Zaretskii
2017-02-19 2:22 ` Tino Calancha
2017-02-19 3:14 ` Black and white emacs -nw (WAS: Re: [PATCH v3 0/4] Support 24-bit terminal colors.) Kaushal Modi
2017-02-19 3:20 ` Kaushal Modi
2017-02-19 6:22 ` Tino Calancha
2017-02-19 7:33 ` Kaushal Modi
2017-02-19 12:43 ` Rami Ylimäki
2017-02-19 15:21 ` Kaushal Modi
2017-02-26 0:49 ` [PATCH v3 0/4] Support 24-bit terminal colors Charles Strahan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1487087902-6661-3-git-send-email-rami.ylimaki@vincit.fi \
--to=rami.ylimaki@vincit.fi \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.