From 64ee11dd46b931a4e3db860675bf970c36e9c7e6 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 25 Nov 2010 14:56:45 +0100 Subject: [PATCH] color: add more function, use them in shr-color Signed-off-by: Julien Danjou --- lisp/ChangeLog | 5 +++++ lisp/color.el | 27 ++++++++++++++++++++++----- lisp/shr-color.el | 2 +- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c4a922af2..c6e7108e0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,6 +1,11 @@ 2010-11-25 Julien Danjou + * shr-color.el (shr-color->hexadecimal): Use color-rgb->hex + * color.el: Rename from color-lab.el + (color-rgb->hex): Add. + (color-complement): Add. + (color-complement-hex): Add. * gnus-sum.el (gnus-summary-widget-forward): Add, and bind to [tab]. diff --git a/lisp/color.el b/lisp/color.el index e2eb1eb57..67ee9e79f 100644 --- a/lisp/color.el +++ b/lisp/color.el @@ -34,6 +34,23 @@ (unless (boundp 'float-pi) (defconst float-pi (* 4 (atan 1)) "The value of Pi (3.1415926...)."))) +(defun color-rgb->hex (red green blue) + "Return hexadecimal notation for RED GREEN BLUE color. +RED GREEN BLUE must be values between [0,1]." + (format "#%02x%02x%02x" + (* red 255) (* green 255) (* blue 255))) + +(defun color-complement (color) + "Return the color that is the complement of COLOR." + (let ((color (color-rgb->normalize color))) + (list (- 1.0 (car color)) + (- 1.0 (cadr color)) + (- 1.0 (caddr color))))) + +(defun color-complement-hex (color) + "Return the color that is the complement of COLOR, in hexadecimal format." + (apply 'color-rgb->hex (color-complement color))) + (defun color-rgb->hsv (red green blue) "Convert RED GREEN BLUE values to HSV representation. Hue is in radian. Saturation and values are between 0 and 1." @@ -63,10 +80,10 @@ Hue is in radian. Saturation and values are between 0 and 1." (defun color-rgb->hsl (red green blue) "Convert RED GREEN BLUE colors to their HSL representation. -RED, GREEN and BLUE must be between 0 and 255." - (let* ((r (/ red 255.0)) - (g (/ green 255.0)) - (b (/ blue 255.0)) +RED, GREEN and BLUE must be between [0,1]." + (let* ((r red) + (g green) + (b blue) (max (max r g b)) (min (min r g b)) (delta (- max min)) @@ -91,7 +108,7 @@ RED, GREEN and BLUE must be between 0 and 255." (defun color-rgb->xyz (red green blue) "Converts RED GREEN BLUE colors to CIE XYZ representation. -RED, BLUE and GREEN must be between 0 and 1." +RED, BLUE and GREEN must be between [0,1]." (let ((r (if (<= red 0.04045) (/ red 12.95) (expt (/ (+ red 0.055) 1.055) 2.4))) diff --git a/lisp/shr-color.el b/lisp/shr-color.el index 1c9790dec..3346b43d9 100644 --- a/lisp/shr-color.el +++ b/lisp/shr-color.el @@ -258,7 +258,7 @@ Like rgb() or hsl()." (l (/ (string-to-number (match-string-no-properties 3 color)) 100.0))) (destructuring-bind (r g b) (shr-color-hsl-to-rgb-fractions h s l) - (format "#%02X%02X%02X" (* r 255) (* g 255) (* b 255))))) + (color-rgb->hex r g b)))) ;; Color names ((cdr (assoc-string color shr-color-html-colors-alist t))) ;; Unrecognized color :( -- 2.34.1