solarized-emacs

a fork of Bozhidar Batsov's solarized-emacs
git clone https://git.trogloxene.org/solarized-emacs.git
Log | Files | Refs | README

commit 4c3ffe2caf73dc5aae7607adc4ef15ef0bd37020
parent 11a3b72c2143477153397eeaea1d6ac06029c140
Author: Thomas Frössman <thomasf@jossystem.se>
Date:   Tue, 12 Jan 2021 11:48:37 +0100

add solarized-color-rgb-to-hex

closes #378

Diffstat:
Msolarized.el | 17+++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/solarized.el b/solarized.el @@ -120,6 +120,19 @@ Related discussion: https://github.com/bbatsov/solarized-emacs/issues/158" (min (max (nth 1 lab) -128) 127) (min (max (nth 2 lab) -128) 127))) +(defun solarized-color-rgb-to-hex (red green blue &optional digits-per-component round) + "Return hexadecimal #RGB notation for the color specified by RED GREEN BLUE. +RED, GREEN, and BLUE should be numbers between 0.0 and 1.0, inclusive. +Optional argument DIGITS-PER-COMPONENT can be either 4 (the default) +or 2; use the latter if you need a 24-bit specification of a color. +Optional argument ROUND rounds values which probably is what you usually want." + (or digits-per-component (setq digits-per-component 4)) + (let* ((maxval (if (= digits-per-component 2) 255 65535)) + (fmt (if (= digits-per-component 2) "#%02x%02x%02x" "#%04x%04x%04x"))) + (if round + (format fmt (+ 0.5 (* red maxval)) (+ 0.5 (* green maxval)) (+ 0.5(* blue maxval))) + (format fmt (* red maxval) (* green maxval) (* blue maxval))))) + ;;;###autoload (defun solarized-color-blend (color1 color2 alpha &optional digits-per-component) "Blends COLOR1 onto COLOR2 with ALPHA. @@ -139,8 +152,8 @@ use the latter if you need a 24-bit specification of a color." (apply 'color-srgb-to-lab (color-name-to-rgb color2)) (apply 'color-srgb-to-lab (color-name-to-rgb color1)))))))) (if (version< emacs-version "26") - (apply 'color-rgb-to-hex `(,@args)) - (apply 'color-rgb-to-hex `(,@args ,digits-per-component))))) + (apply 'solarized-color-rgb-to-hex `(,@args t)) + (apply 'solarized-color-rgb-to-hex `(,@args ,digits-per-component t))))) ;;;###autoload (defun solarized-create-color-palette (core-palette)