unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: 14074@debbugs.gnu.org
Subject: bug#14074: 24.3.50; Convert hsv to rgb
Date: Thu, 28 Mar 2013 20:26:15 +0530	[thread overview]
Message-ID: <87txnvshdc.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]


Convert hsv to rgb.

Here is a little test case.

    (let ((color-name (format "#%06x" (random #xffffff))))
      (format "color-name: %s  round-tripped: %s"
              color-name
              (apply 'color-rgb-to-hex 
                     (apply 'color-hsv-to-rgb 
                            (apply 'color-rgb-to-hsv 
                                   (color-name-to-rgb color-name))))))

    => "color-name: #01043d  round-tripped: #01033d"
    => "color-name: #1278e2  round-tripped: #1278e2"
    => "color-name: #ffb4bd  round-tripped: #ffb4bd"

One can use `color-hsv-to-rgb' for example in `vc-annotate-color-map'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: color.el.diff --]
[-- Type: text/x-diff, Size: 1666 bytes --]

=== modified file 'lisp/ChangeLog'
*** lisp/ChangeLog	2013-03-27 16:03:15 +0000
--- lisp/ChangeLog	2013-03-28 14:36:48 +0000
***************
*** 1,3 ****
--- 1,7 ----
+ 2013-03-28  Jambunathan K  <kjambunathan@gmail.com>
+ 
+ 	* color.el (color-hsv-to-rgb): New defun.
+ 
  2013-03-27  Eli Zaretskii  <eliz@gnu.org>
  
  	* facemenu.el (list-colors-callback): New defvar.

=== modified file 'lisp/color.el'
*** lisp/color.el	2013-01-11 15:04:24 +0000
--- lisp/color.el	2013-03-28 14:40:31 +0000
***************
*** 118,123 ****
--- 118,148 ----
    "Return the color that is the complement of COLOR, in hexadecimal format."
    (apply 'color-rgb-to-hex (color-complement color)))
  
+ (defun color-hsv-to-rgb (h s v)
+   "Convert HSV color components to RGB.
+ HUE should be in radians between 0 and 2*`float-pi', inclusive.
+ SATURATION and VALUE should be between 0.0 and 1.0, inclusive.
+ Return a list (RED GREEN BLUE) where each of the components is
+ between 0.0 and 1.0, inclusive."
+   ;; Convert h from radians to degrees
+   (setq h (/ (* 180.0 h) float-pi))
+   (when (>= h 360) (setq h 0.0))
+   (if (zerop s)
+       (list v v v)
+     (let* ((h (/ h 60.0))
+ 	   (i (floor h))
+ 	   (f (- h i))
+ 	   (l (* v (- 1 s)))
+ 	   (m (* v (- 1 (* s f))))
+ 	   (n (* v (- 1 (* s (- 1 f))))))
+       (cond
+        ((= i 0) (list v n l))
+        ((= i 1) (list m v l))
+        ((= i 2) (list l v n))
+        ((= i 3) (list l m v))
+        ((= i 4) (list n l v))
+        ((= i 5) (list v l m))))))
+ 
  (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,


[-- Attachment #3: Type: text/plain, Size: 366 bytes --]



In GNU Emacs 24.3.50.1 (i686-pc-linux-gnu, GTK+ Version 2.20.1)
 of 2013-03-28 on debian-6.05
Bzr revision: 112161 eliz@gnu.org-20130327160315-f4jh29xefzj11qgu
Windowing system distributor `The X.Org Foundation', version 11.0.10707000
Important settings:
  value of $LANG: en_IN
  locale-coding-system: iso-latin-1-unix
  default enable-multibyte-characters: t




             reply	other threads:[~2013-03-28 14:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-28 14:56 Jambunathan K [this message]
2002-01-01  0:41 ` bug#14074: 24.3.50; Convert hsv to rgb Jambunathan K
2013-04-07 13:37 ` Jambunathan K

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87txnvshdc.fsf@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=14074@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).