hsv2rgb function wanted

Oct 17, 2006 13:20

with radians not degrees. in c. and brief.

Leave a comment

Comments 8

blimix October 17 2006, 17:53:24 UTC
Care to share with me, if you get one?

Reply


some_kitten October 17 2006, 19:06:05 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

Reply

oonh October 18 2006, 00:31:19 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).

Reply


mmcirvin October 17 2006, 20:47:47 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.

Reply

oonh October 18 2006, 00:28:51 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.

Reply

mmcirvin October 18 2006, 02:54:52 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.

Reply

mmcirvin October 18 2006, 02:57:26 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.

Reply


Leave a comment

Up