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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure AfficherMessage(const str: string); forward;
const COLORS_TABLE_SIZE = 256;
type TArray256Colors = array of TColor;
type
{ TPalette256 }
TPalette256 = class
procedure GenerateWeb216Palette; deprecated;
// procedure GenerateACADPalette; deprecated;
// procedure GenerateGrayScalePalette; deprecated;
private
FColorArray : TArray256Colors;
procedure ViderTableCouleurs();
public
// procedure GenerateTOPOROBOTPalette();
function GetColorByIndex(const Idx: Integer):TColor;
end;
//------------------------------------------------------------------------------
procedure AfficherMessage(const str: string);
begin
ShowMessage(str);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm1.Button2Click(Sender: TObject);
var test: TPalette256;
var tt0, tt100, tt255: TColor;
begin
test:= TPalette256.Create();
test.GenerateWeb216Palette;
tt0 := test.GetColorByIndex(0);
tt100 := test.GetColorByIndex(100);
tt255 := test.GetColorByIndex(255);
AfficherMessage('tt='+IntToStr(integer(tt0))+' '+IntToStr(integer(tt100))+' '+IntToStr(integer(tt255)));
test.Free;
end;
procedure TPalette256.GenerateWeb216Palette;
var
i, j, k : integer;
r,g,b : byte;
IdxColor : integer;
begin
AfficherMessage(ClassName+'.GenerateWeb216Palette');
ViderTableCouleurs();
for i:=1 to 6 do
for j:=1 to 6 do
for k:=1 to 6 do
begin
IdxColor:=(i-1)*36+
(j-1)*6+
(k-1);
r:=255 - (i-1) * 51;
g:=255 - (j-1) * 51;
b:=255 - (k-1) * 51;
FColorArray[IdxColor]:=RGBToColor(r,g,b);
end;
end;
function TPalette256.GetColorByIndex(const Idx: Integer): TColor;
begin
try
Result := self.FColorArray[Idx]; // sous GDB, provoque un External SIGSEGV
except
Result := clSilver;
end;
end;
procedure TPalette256.ViderTableCouleurs;
var
i: Integer;
begin
SetLength(FColorArray, COLORS_TABLE_SIZE);
for i:= 0 to COLORS_TABLE_SIZE - 1 do FColorArray[i] := clSilver;
end;
end. |
Partager