unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] color-hsv-to-rgb
@ 2023-10-16  7:28 Dov Grobgeld
  2023-10-16  7:59 ` Stefan Kangas
  2023-10-16 12:05 ` Eli Zaretskii
  0 siblings, 2 replies; 12+ messages in thread
From: Dov Grobgeld @ 2023-10-16  7:28 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 246 bytes --]

Hello.

I would like to do my first(!) contribution to emacs with the attached
patch. Is there interest, or is it too trivial? Do I need to do a copyright
assignment? Is there a guide for dummies on how to do that?

With hope for better times...

[-- Attachment #1.2: Type: text/html, Size: 842 bytes --]

[-- Attachment #2: color-hsv-to-rgb.patch --]
[-- Type: text/x-patch, Size: 1110 bytes --]

diff --git a/lisp/color.el b/lisp/color.el
index f68cf5e6b17..37f11f23c7c 100644
--- a/lisp/color.el
+++ b/lisp/color.el
@@ -123,6 +123,26 @@ color-complement-hex
   "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 hue, saturation and value to their RGB representation.
+H, S, and V should each be numbers between 0.0 and 1.0, inclusive.
+Return a list (RED GREEN BLUE), where each element is between 0.0 and 1.0,
+inclusive."
+  (let* ((I (floor (* 6 H)))
+         (F (- (* H 6) I))
+         (P (* V (- 1.0 S)))
+         (Q (* V (- 1.0 (* F S))))
+         (T (* V (- 1.0 (* (- 1.0 F) S))))
+         (I (mod I 6)))
+    (cond
+     ((= I 0) (list V T P))
+     ((= I 1) (list Q V P))
+     ((= I 2) (list P V T))
+     ((= I 3) (list P Q V))
+     ((= I 4) (list T P V))
+     ((= I 5) (list V P Q))
+     (t (list 0 0 0)))))
+
 (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,

^ permalink raw reply related	[flat|nested] 12+ messages in thread
* RE: [External] : Re: [PATCH] color-hsv-to-rgb
@ 2023-10-20 21:04 Drew Adams
  0 siblings, 0 replies; 12+ messages in thread
From: Drew Adams @ 2023-10-20 21:04 UTC (permalink / raw)
  To: Eli Zaretskii
  Cc: stefankangas@gmail.com, jporterbugs@gmail.com,
	dov.grobgeld@gmail.com, emacs-devel@gnu.org

> It is hard for anyone but you to know what
> is your POV on this issue.

I don't have a POV on what else in `hexrgb.el'
might be missing from `color.el' and might want
to be added now by Emacs Dev.  And that's what
I said, at the outset of my reply to Stefan's
question:

  "Sorry, but I don't know"

All of hexrgb.el was considered when `color.el'
was being created, including `hexrgb-hsv-to-rgb'.
Whatever was wanted was used, and that didn't
include `hexrgb-hsv-to-rgb'.

I mentioned that function in this thread only
because of the thread Subject.  Would you have
preferred that I not mention it?  I figured
its code might help in some way, as well as
the fact that I (too) think such a function is
useful.  The latter was the main reason I wrote
to the thread: to say +1 to Jim's +1 to Dov's
request.  That's the main msg: it's useful.

There's no need for me to guess what else you
might be interested in.  If you're interested,
just take a look at the available functions.
It's not like there are zillions of them, and
they're all handily listed in one place, with
clear names.

As I said, I haven't looked at this code since
2018, and likewise `color.el'.  If someone is
interested in investigating the differences
they are as capable as I am for that.

And again, I have no POV about "main things 
besides `color-hsv-to-rgb'".
___

A quick look now at `color.el' shows it's
mostly about color conversion, not color
modification, HSL being the sole exception,
and only for S and L. `hexrgb.el' has eight
functions for incrementing/decrementing:

  +/- R, G, B individually and together
  +/- H, S, V individually
  +/- hex digits together

Why `color.el' has separate functions (8 of
them!) for the two directions to increment
only S and L is a mystery.  With `hexrgb.el',
just use a negative increment to decrement.

`hexrgb.el' also has functions to modify a
color by complementing only one component: red/green/blue/hue/saturation/value.  E.g.,
complementing hue doesn't change saturation
or value.

  (hexrgb-hue-complement "LightBlue")
    ; => "#E6E5BBBAADAC"

HTH.



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

end of thread, other threads:[~2023-10-20 21:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-16  7:28 [PATCH] color-hsv-to-rgb Dov Grobgeld
2023-10-16  7:59 ` Stefan Kangas
2023-10-19 19:58   ` Jim Porter
2023-10-19 20:12     ` [External] : " Drew Adams
2023-10-19 21:22       ` Stefan Kangas
2023-10-19 21:35         ` Drew Adams
2023-10-20  6:09           ` Eli Zaretskii
2023-10-20 15:04             ` Drew Adams
2023-10-20 17:59               ` Eli Zaretskii
2023-10-16 12:05 ` Eli Zaretskii
2023-10-17  6:12   ` Dov Grobgeld
  -- strict thread matches above, loose matches on Subject: below --
2023-10-20 21:04 [External] : " Drew Adams

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).