?

Log in

No account? Create an account
the coproduct of doom [userpic]

hsv2rgb function wanted

October 17th, 2006 (01:20 pm)

with radians not degrees. in c. and brief.

Comments

Posted by: Joe (blimix)
Posted at: October 17th, 2006 05:53 pm (UTC)

Care to share with me, if you get one?

Posted by: An anonymous kitty (some_kitten)
Posted at: October 17th, 2006 07:06 pm (UTC)

Don't think I can write one for you off the top of my head, but I'm very curious as to why.

Too much of my professional life lately has involved video encoding and different color schema. :-P

Posted by: the coproduct of doom (oonh)
Posted at: October 18th, 2006 12:31 am (UTC)

Look at the movies in my recent lj entries. I've decided it's time to add color to them. They consist of long linear sequences of points dribbled onto an array much as one would dribble syrup on pancakes. The color information will come from the angle at a point -- last point/this point/next point -> angle, then all angles in a slice of the object normal to the viewer added mod pi (I think group theoretically is more interesting than just averaging them).

Posted by: Matt McIrvin (mmcirvin)
Posted at: October 17th, 2006 08:47 pm (UTC)

Looking at the Wikipedia article, since the definition of HSV is this weird piecewise thing, I'm not sure you're going to get brief; the function will have to involve conditionals. But you can convert a function expressed in degrees to one expressed in radians by just multiplying the H value by 180/pi at the outset.

Posted by: the coproduct of doom (oonh)
Posted at: October 18th, 2006 12:28 am (UTC)

I tried very hard to implement the one on wikipedia (which I suspect is wrong). I'd rather have something that I don't have to fiddle too much with.

Posted by: Matt McIrvin (mmcirvin)
Posted at: October 18th, 2006 02:54 am (UTC)

Reading your previous comment on intended purpose: If all you want is a way to convert something like HSV to RGB so you can represent hue as an angle, instead of representing the standard hexcone precisely, that's much easier.

Something like this (which I just pulled out of my butt--optimize and debug to taste) might do:

R = cos (0.75*theta);
if (R < 0.0) R = 0.0;
G = cos (0.75*(theta - 2 * PI/3));
if (G < 0.0) G = 0.0;
B = cos (0.75*(theta + 2 * PI/3));
if (B < 0.0) B = 0.0;

(The idea here is to arrange all the constants so that each cosine function reaches zero exactly at the maximum of the next one, and they're evenly spaced in thirds around the unit circle; then clamp all the negative values to zero. If my math is wrong, i apologize in advance.)

Since you've already got brightness information, you'd then use all those as factors that you multiply by the brightness.

Posted by: Matt McIrvin (mmcirvin)
Posted at: October 18th, 2006 02:57 am (UTC)

...and by the way, if you then replace those trig functions with linear triangular ones that reach zero precisely at the maximum of the next function, then you've got something more like standard HSV. But the trigonometric version is easier to write down.

Posted by: the coproduct of doom (oonh)
Posted at: October 23rd, 2006 05:27 am (UTC)

Okay, the state so far:

the test program is wonky
(this one uses your algorithm)
the real program remains incomplete.

8 Read Comments