PDA

View Full Version : HSV to RGB

KeatonMill
16th November 2002, 13:14
Hey guys, I'm working on some presets which I would like to use the HSV colorspace instead of RGB. However, AVS doesn't support HSV in the superscope code. I have searched on Google for an AVS-friendly algorithm, but I haven't been able to find one.

Does anyone know of a (relatively) easy way to convert between colorspaces?

Thanks

Montana
16th November 2002, 14:57
i use this, it's a method that unconed posted here in the forums:

hue=var; // (0..2PI)
sat=var; // (0..1)
lum=var; //
use any value to light/darken the color, recomended value (-1..1)
red=(sin(hue)+1)*sat*0.5+lum;
green=(sin(hue+2.09)+1)*sat*0.5+lum;
blue=(sin(hue+4.18)+1)*sat*0.5+lum;

dirkdeftly
17th November 2002, 05:21
Assuming red, green, blue, hue, luminosity, and saturation are all values from 0 to 1:

red=|sin hue*pi*2)|*saturation/2+luminosity;
green=|sin hue*pi*2+pi/3)|*saturation/2+luminosity;
blue=|sin hue*pi*2+pi/3*2)|*saturation/2+luminosity;

Fast version for AVS:

init: tpi=acos(-1)*2; pit=tpi/6; tpit=pit*2;

pixel:
sat2=sat/2;
red=abs(sin(hue*tpi))*sat2+lum;
green=abs(sin(hue*tpi+pit))*sat2+lum;
blue=abs(sin(hue*tpi+tpit))*sat2+lum;

jheriko
17th November 2002, 16:10
For a slightly faster version use sat2=sat*0.5;

dirkdeftly
17th November 2002, 20:51
Oh, and hue2=hue*tpi;

Zevensoft
18th November 2002, 09:12
Here's what I use (I don't think it's accurate, but it does the job).

Init
pi=acos(-1);tt=2/3;

Point
red=((.5+sin((h+tt)*pi)*.5)*s+(.5+sin(h*pi)*.5)*(1-s)+(.5+sin((h-tt)*pi)*.5)*(1-s))*br;
green=((.5+sin(h*pi)*.5)*s+(.5+sin((h+tt)*pi)*.5)*(1-s)+(.5+sin((h-tt)*pi)*.5)*(1-s))*br;
blue=((.5+sin((h-tt)*pi)*.5)*s+(.5+sin(h*pi)*.5)*(1-s)+(.5+sin((h+tt)*pi)*.5)*(1-s))*br;

h = hue, s = saturation, br = brightness.

Note: This can be optimized further by creating varibles for things like (h-tt)*pi. Also can be optimized if hue or saturation is fixed.