这是 Delphi 的 C 代码翻译,在这里找到:http://www.cs.rit.edu/~ncs/color/t_convert.html http://www.cs.rit.edu/~ncs/color/t_convert.html
function RGBFP(R, G, B: Double): TColor;
const
RGBmax = 255;
begin
Result := RGB(Round(RGBmax * R), Round(RGBmax * G), Round(RGBmax * B));
end;
function HSVtoRGB(H, S, V: Double): TColor;
var
i: Integer;
f, p, q, t: Double;
begin
Assert(InRange(H, 0.0, 1.0));
Assert(InRange(S, 0.0, 1.0));
Assert(InRange(V, 0.0, 1.0));
if S = 0.0 then
begin
// achromatic (grey)
Result := RGBFP(V, V, V);
exit;
end;
H := H * 6.0; // sector 0 to 5
i := floor(H);
f := H - i; // fractional part of H
p := V * (1.0 - S);
q := V * (1.0 - S * f);
t := V * (1.0 - S * (1.0 - f));
case i of
0:
Result := RGBFP(V, t, p);
1:
Result := RGBFP(q, V, p);
2:
Result := RGBFP(p, V, t);
3:
Result := RGBFP(p, q, V);
4:
Result := RGBFP(t, p, V);
else
Result := RGBFP(V, p, q);
end;
end;
我已经进行了最低限度的测试。请随时仔细检查。