--- Begin Message ---
Subject: |
color-hsl-to-rgb doesn't handle hue range overflow |
Date: |
Tue, 02 Oct 2012 15:40:54 +0200 |
`color-hsl-to-rgb' manipulates hue without dealing with range overflow
or underflow. This takes small and large hue values outside of the
range expected by `color-hue-to-rgb' and causes incorrect results for
such values:
(color-rgb-to-hsl 0.65 0.25 0.75)
;; -> (0.7999999999999999 0.5 0.5)
(apply 'color-hsl-to-rgb (color-rgb-to-hsl 0.65 0.25 0.75))
;; -> (0.25 0.25 0.75)
(color-rgb-to-hsl 0.65 0.75 0.25)
;; -> (0.20000000000000004 0.5 0.5)
(apply 'color-hsl-to-rgb (color-rgb-to-hsl 0.65 0.75 0.25))
;; -> (0.6499999999999999 0.75 -0.1499999999999998)
The patch below makes the conversion work as expected:
(apply 'color-hsl-to-rgb (color-rgb-to-hsl 0.65 0.25 0.75))
;; -> (0.6499999999999999 0.25 0.75)
(apply 'color-hsl-to-rgb (color-rgb-to-hsl 0.65 0.75 0.25))
;; -> (0.6499999999999999 0.75 0.25)
2012-10-02 Julian Scheid <address@hidden>
* color.el (color-hsl-to-rgb): Fix for incorrect results for
small and large hue values.
=== modified file 'lisp/color.el'
*** lisp/color.el 2012-08-13 19:10:35 +0000
--- lisp/color.el 2012-10-02 13:16:32 +0000
*************** Return a list (RED, GREEN, BLUE) which e
*** 116,124 ****
(- (+ L S) (* L S))))
(m1 (- (* 2.0 L) m2)))
(list
! (color-hue-to-rgb m1 m2 (+ H (/ 1.0 3)))
(color-hue-to-rgb m1 m2 H)
! (color-hue-to-rgb m1 m2 (- H (/ 1.0 3)))))))
(defun color-complement-hex (color)
"Return the color that is the complement of COLOR, in hexadecimal format."
--- 116,124 ----
(- (+ L S) (* L S))))
(m1 (- (* 2.0 L) m2)))
(list
! (color-hue-to-rgb m1 m2 (mod (+ H (/ 1.0 3)) 1))
(color-hue-to-rgb m1 m2 H)
! (color-hue-to-rgb m1 m2 (mod (- H (/ 1.0 3)) 1))))))
(defun color-complement-hex (color)
"Return the color that is the complement of COLOR, in hexadecimal format."
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#12559: color-hsl-to-rgb doesn't handle hue range overflow |
Date: |
Fri, 05 Oct 2012 22:21:51 -0400 |
User-agent: |
Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) |
Version: 24.3
Thanks; applied to trunk.
--- End Message ---