If you're referring to this question: implementing a trackbar that will change background color of form, the HSVtoRGB procedure expects:
- a saturation value between 0.0 and 1.0
- a value value between 0.0 and 1.0
- a hue value between 0 and 360
This is in-line with the intent of the algorithm, as it points to the wikipedia version as its reference, at http://www.xtremevbtalk.com/showthread.php?t=302304. I didn't proofread the implementation to check for correctness though.
Dividing the saturation value you get from the tbSaturation textbox by 50 allows you to interpret values between 0 and 50 entered by the user. You might actually want to divide by 100 instead to allow a 0-100 range.
I've reverse-engineered the computation for when the "Colorize" checkbox is checked. All of the code below is pseudo-code.
The inputs are:
- hueRGB, which is an RGB color for
HSV(photoshop_hue, 100, 100).ToRGB()
- saturation, which is
photoshop_saturation / 100.0
(i.e. 0..1)
- lightness, which is
photoshop_lightness / 100.0
(i.e. -1..1)
- value, which is the
pixel.ToHSV().Value
, scaled into 0..1 range.
The method to colorize a single pixel:
color = blend2(rgb(128, 128, 128), hueRGB, saturation);
if (lightness <= -1)
return black;
else if (lightness >= 1)
return white;
else if (lightness >= 0)
return blend3(black, color, white, 2 * (1 - lightness) * (value - 1) + 1)
else
return blend3(black, color, white, 2 * (1 + lightness) * (value) - 1)
Where blend2
and blend3
are:
blend2(left, right, pos):
return rgb(left.R * (1-pos) + right.R * pos, same for green, same for blue)
blend3(left, main, right, pos):
if (pos < 0)
return blend2(left, main, pos + 1)
else if (pos > 0)
return blend2(main, right, pos)
else
return main
Best Answer
"In Windows, the HSL and HSV spaces are usually remapped to a scale between 0 to 240 so that colors can be represented with a 32-bit value."
See http://msdn.microsoft.com/en-us/library/aa511283.aspx
Hue is expressed as an angle around the color wheel, in this case multiplied by 2/3 to stay under 240 degrees. The highest value is 239 because 240 = 0 just as 360 degrees = 0 degrees on a compass.