1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| function jpTSVToColor(t,s,v: float): TColor; inline;
var
r, g, b: Integer;
procedure TSVtoRGB(T, S, V: Double; out R, G, B: Integer);
var
i: Integer;
f: Double;
p, q, u: Double;
procedure MakeRgb(rr, gg, bb: Double);
begin
R := Round(rr * 255);
G := Round(gg * 255);
B := Round(bb * 255);
end;
begin
i := floor(T * 6);
f := T * 6 - i;
p := V * (1 - S);
q := V * (1 - f*S);
u := V * (1 - (1 - f) * S);
case i mod 6 of
0: MakeRGB(V, u, p);
1: MakeRGB(q, V, p);
2: MakeRGB(p, V, u);
3: MakeRGB(p, q, V);
4: MakeRGB(u, p, V);
5: MakeRGB(V, p, q);
else MakeRGB(0, 0, 0);
end;
end;
begin
TSVtoRGB(T, S, V, r, g, b);
Result := RgbToColor(r, g, b);
{pas glop ce truc...
var // http://www.delphipraxis.net/157099-fast-integer-rgb-hsl.html
hi: integer;
f,p,q,u: float;
cn: TColor;
function jpRGBtoColor(const R,G,B: Byte): TColor;
begin
Result := (B shl 16) or (G shl 8) or R;
end;
begin
hi := Floor(t/60);
f := t/60 - hi;
p := (v*(1-s))*255;
q := (v*(1-s*f))*255;
u := (v*(1-s*(1-f)))*255;
v := v*255;
case hi of
0: cn := jpRGBtoColor( byte(round(v)), byte(round(u)), byte(round(p)) );
1: cn := jpRGBtoColor( byte(round(q)), byte(round(v)), byte(round(p)) );
2: cn := jpRGBtoColor( byte(round(p)), byte(round(v)), byte(round(u)) );
3: cn := jpRGBtoColor( byte(round(p)), byte(round(q)), byte(round(v)) );
4: cn := jpRGBtoColor( byte(round(u)), byte(round(p)), byte(round(v)) );
5: cn := jpRGBtoColor( byte(round(v)), byte(round(p)), byte(round(q)) );
6: cn := jpRGBtoColor( byte(round(v)), byte(round(u)), byte(round(p)) );
end;
Result := cn; }
{// résultats faux selon la couleur passée...
// dessous, copie adaptée de jpHSVtoColor
var
var_t,var_r,var_g,var_b,var_1,var_2,var_3: float;
var_i: integer;
R,G,B: byte;
begin
if S = 0 then
begin
R := round(V * 255);
G := round(V * 255);
B := round(V * 255);
end else
begin
var_t := T * 6;
if ( var_t = 6 ) then var_t := 0; //T must be < 1
var_i := round( var_t ); //Or ... var_i = floor( var_t )
var_1 := V * ( 1 - S );
var_2 := V * ( 1 - S * ( var_t - var_i ) );
var_3 := V * ( 1 - S * ( 1 - ( var_t - var_i ) ) );
if ( var_i = 0 ) then begin var_r := V; var_g := var_3; var_b := var_1; end
else if ( var_i = 1 ) then begin var_r := var_2; var_g := V; var_b := var_1; end
else if ( var_i = 2 ) then begin var_r := var_1; var_g := V; var_b := var_3; end
else if ( var_i = 3 ) then begin var_r := var_1; var_g := var_2; var_b := V; end
else if ( var_i = 4 ) then begin var_r := var_3; var_g := var_1; var_b := V; end
else begin var_r := V; var_g := var_1; var_b := var_2; end;
R := round(var_r * 255); //RGB results from 0 to 255
G := round(var_g * 255);
B := round(var_b * 255);
end;
Result := R or (G shl 8) or (B shl 16);
}
end; |
Partager