Function: color-rgb-to-hsv

color-rgb-to-hsv is a byte-compiled function defined in color.el.gz.

Signature

(color-rgb-to-hsv RED GREEN BLUE)

Documentation

Convert RGB color components to HSV.

RED, GREEN, and BLUE should each be numbers between 0.0 and 1.0, inclusive. Return a list (HUE SATURATION VALUE), where HUE is in radians and both SATURATION and VALUE are between 0.0 and 1.0, inclusive.

Source Code

;; Defined in /usr/src/emacs/lisp/color.el.gz
(defun color-rgb-to-hsv (red green blue)
  "Convert RGB color components to HSV.
RED, GREEN, and BLUE should each be numbers between 0.0 and 1.0,
inclusive.  Return a list (HUE SATURATION VALUE), where HUE is
in radians and both SATURATION and VALUE are between 0.0 and 1.0,
inclusive."
  (let* ((r (float red))
	 (g (float green))
	 (b (float blue))
	 (max (max r g b))
	 (min (min r g b)))
    (if (< (- max min) 1e-8)
	(list 0.0 0.0 min)
      (list
       (/ (* 2 float-pi
	     (cond ((and (= r g) (= g b)) 0)
		   ((and (= r max)
			 (>= g b))
		    (* 60 (/ (- g b) (- max min))))
		   ((and (= r max)
			 (< g b))
		    (+ 360 (* 60 (/ (- g b) (- max min)))))
		   ((= max g)
		    (+ 120 (* 60 (/ (- b r) (- max min)))))
		   ((= max b)
		    (+ 240 (* 60 (/ (- r g) (- max min)))))))
	  360)
       (if (= max 0) 0 (- 1 (/ min max)))
       max))))