GNU bug report logs - #12559
color-hsl-to-rgb doesn't handle hue range overflow

Previous Next

Package: emacs;

Reported by: Julian Scheid <julians37 <at> gmail.com>

Date: Tue, 2 Oct 2012 16:27:04 UTC

Severity: normal

Tags: patch

Merged with 13047

Found in version 24.2

Fixed in version 24.3

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Julian Scheid <julians37 <at> gmail.com>
To: 12559 <at> debbugs.gnu.org
Subject: bug#12559: 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  <julians37 <at> gmail.com>

	* 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."





This bug report was last modified 12 years and 237 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.