I should also point out that HSV/HLS/HSB/etc is not a useful color space to deal with. Excellent details as to why are provided by Charles Poynton:
http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC36 http://www.poynton.com/notes/colour_and_gamma/GammaFAQ.html#HSI
If you need brightness or saturation then use YUV which properly accounts for non-linear aspects of color. The 'hue' part of HSV is worthless.