TAChart: More speedup of TADrawerSVG.ColorToHex. Issue #40967. Patch by Alexey Torgashin.

This commit is contained in:
wp_xyz 2024-05-23 15:27:20 +02:00
parent 71526ba83e
commit 3d6170cf9e

View File

@ -128,8 +128,10 @@ begin
end; end;
function ColorToHex(AColor: TFPColor): String; function ColorToHex(AColor: TFPColor): String;
const
SHexDigits: PChar = '0123456789ABCDEF'; // PChar for indices to begin with 0
var var
r, g, b: String[2]; r, g, b: byte;
begin begin
if AColor = colBlack then if AColor = colBlack then
Result := 'black' Result := 'black'
@ -137,14 +139,17 @@ begin
Result := 'white' Result := 'white'
else else
begin begin
r := IntToHex(AColor.Red shr 8, 2); r:= AColor.Red shr 8;
g := IntToHex(AColor.Green shr 8, 2); g:= AColor.Green shr 8;
b := IntToHex(AColor.Blue shr 8, 2); b:= AColor.Blue shr 8;
SetLength(Result, 7); SetLength(Result, 7);
Result[1]:= '#'; // #rrggbb Result[1]:= '#'; // #rrggbb
Move(r[1], Result[2], 2); Result[2]:= SHexDigits[Hi(r)];
Move(g[1], Result[4], 2); Result[3]:= SHexDigits[Lo(r)];
Move(b[1], Result[6], 2); Result[4]:= SHexDigits[Hi(g)];
Result[5]:= SHexDigits[Lo(g)];
Result[6]:= SHexDigits[Hi(b)];
Result[7]:= SHexDigits[Lo(b)];
end; end;
end; end;