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
|
{ TGHTopoColor }
procedure TGHTopoColor.setFrom(const R, G, B: byte; const A: byte);
begin
self.Red := R AND 255;
self.Green := G AND 255;
self.Blue := B AND 255;
self.Alpha := A AND 255;
end;
procedure TGHTopoColor.setFrom(const C: TColor; const A: byte);
begin
self.setFrom(Graphics.Red(C), Graphics.Green(C), Graphics.Blue(C), A);
end;
function TGHTopoColor.toTColor(): TColor;
begin
result := RGBToColor(self.Red, self.Green, self.Blue);
end;
// récupère les RGB depuis les représentations $RRRGGGBBB et #RRRGGGBBB
procedure TGHTopoColor.setFromStrGHTopoColor(const S: string; const qDefault: TColor);
begin
if (length(S) < 10) then // la notation Pascal exige 1 + 3*3 caractères
self.setFrom(clDefault, 255)
else
self.setFrom(StrToIntDef(Copy(S, 2, 3), Graphics.Red(qDefault)),
StrToIntDef(Copy(S, 5, 3), Graphics.Green(qDefault)),
StrToIntDef(Copy(S, 8, 3), Graphics.Blue(qDefault)),
255)
end;
function TGHTopoColor.toStrGHTopoColor(): string;
begin
Result := Format('$%.3d%.3d%.3d', [self.Red, self.Green, self.Blue]);
end;
procedure TGHTopoColor.setOpacity(const O: byte);
begin
self.Alpha := O and 255;
end;
function TGHTopoColor.toHTMLColor(): string;
begin
Result := format('#%.2X%.2X%.2X', [self.Red, self.Green, self.Blue]);
end;
function TGHTopoColor.toKMLColor(): string;
begin
Result := Format('<color>%.2X%.2X%.2X%.2X</color>',[self.Alpha, self.Blue, self.Green, self.Red]);
end;
function TGHTopoColor.toSVGColor(): string;
const m = 1 / 256.0;
begin
Result := Format(' rgb(%.2f%%, %.2f%%, %.2f%%)', [self.Red * m , self.Green * m , self.Blue * m]);
Result := StringReplace(Result, DefaultFormatSettings.DecimalSeparator, '.', [rfReplaceAll]);
end;
function TGHTopoColor.toGrayScale(): byte; //Convertit une couleur en niveaux de gris; méthode NTSC.
begin
Result := round(0.30 * self.Red + 0.59 * self.Green + 0.11 * self.Blue);
end;
function TGHTopoColor.getFloatRed(): double;
begin
Result := self.Red / 256.0;
end;
function TGHTopoColor.getFloatGreen(): double;
begin
Result := self.Green / 256.0;
end;
function TGHTopoColor.getFloatBlue(): double;
begin
Result := self.Blue / 256.0;
end;
function TGHTopoColor.getFloatAlpha(): double;
begin
Result := self.Alpha / 256.0;
end; |
Partager