unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#12559: color-hsl-to-rgb doesn't handle hue range overflow
@ 2012-10-02 13:40 Julian Scheid
  2012-10-06  2:21 ` Glenn Morris
  0 siblings, 1 reply; 2+ messages in thread
From: Julian Scheid @ 2012-10-02 13:40 UTC (permalink / raw)
  To: 12559


`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@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."






^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#12559: color-hsl-to-rgb doesn't handle hue range overflow
  2012-10-02 13:40 bug#12559: color-hsl-to-rgb doesn't handle hue range overflow Julian Scheid
@ 2012-10-06  2:21 ` Glenn Morris
  0 siblings, 0 replies; 2+ messages in thread
From: Glenn Morris @ 2012-10-06  2:21 UTC (permalink / raw)
  To: 12559-done

Version: 24.3

Thanks; applied to trunk.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-10-06  2:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-02 13:40 bug#12559: color-hsl-to-rgb doesn't handle hue range overflow Julian Scheid
2012-10-06  2:21 ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).