Here's some code, written in Delphi but easy to read and translate (just scream if you can't get it to work ):

http://homepages.borland.com/efg2lab...Colors/HSV.htm