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
| implementation
{$R *.lfm}
{ TForm1 }
uses
{$IFDEF LINUX}
BaseUnix, // timespec
Linux, // clock_gettime
{$ENDIF}
LCLIntf,
LCLtype;
const
//ONE_OVER_BILLION = 1E-9; // nano
ONE_OVER_MILLION = 1E-6; // micro
ONE_OVER_MILLIER = 1E-3; // milli
{$IFDEF LINUX}
function GetTickCount64: QWord; // vient de "4inline", liens dans GetTickCount64
var
tp: timespec; // timespec record tv_sec seconds tv_nsec nanoseconds
begin
//clock_gettime(CLOCK_MONOTONIC, @tp); // orig
clock_gettime(CLOCK_MONOTONIC_RAW, @tp);
Result := (Int64(tp.tv_sec) * 1000000000) + int64(tp.tv_nsec);
end;
{$ENDIF}
FUNCTION RGBtoRGBTriple(CONST red, green, blue: BYTE): TRGBTriple;
BEGIN
WITH RESULT DO
BEGIN
rgbtRed := red;
rgbtGreen := green;
rgbtBlue := blue
END
END {RGBtoRGBTriple};
FUNCTION RGBAtoRGBAQuad(CONST red, green, blue, reserved: BYTE): TRGBQuad;
BEGIN
WITH RESULT DO BEGIN
rgbRed := red;
rgbGreen := green;
rgbBlue := blue;
rgbReserved := reserved;
END
END {RGBAtoRGBAQuad};
procedure TForm1.FormCreate(Sender: TObject);
const
IMAGE_WIDTH = 256;
IMAGE_HEIGHT = 256;
var
StartTime, StopTime, Delta : QWord;
h,w: Integer;
aBmp: TBitmap;
{$IFDEF WINDOWS}
p : pRGBTriple;
{$ELSE}
p : pRGBQuad;
{$ENDIF}
begin
DoubleBuffered := True;
{$IFDEF LINUX}
StartTime := GetTickCount64;
{$ENDIF}
aBmp := TBitmap.Create;
with aBmp do begin
PixelFormat := pf24bit;
SetSize(IMAGE_WIDTH, IMAGE_HEIGHT);
BeginUpdate();
for h := 0 to IMAGE_HEIGHT-1 do begin
{$IFDEF WINDOWS}
p := pRGBTriple(RawImage.GetLineStart(h));
for w := 0 to IMAGE_WIDTH-1 do
p[w] := RGBtoRGBTriple(h, w, (h+w) div 2);
{$ELSE}
p := pRGBQuad(RawImage.GetLineStart(h));
for w := 0 to IMAGE_WIDTH-1 do
p[w] := RGBAtoRGBAQuad(h, w, (h+w) div 2, 255);
{$ENDIF}
end;
EndUpdate();
image1.Picture.Assign(aBmp);
Free;
end;
{$IFDEF LINUX}
StopTime := GetTickCount64;
Delta := StopTime - StartTime;
//Caption := IntToStr(Delta) + ' nanosecondes';
Caption := FloatToStr(Delta * ONE_OVER_MILLIER) + ' microsecondes';
//Caption := FloatToStr(Delta * ONE_OVER_MILLION) + ' millisecondes';
{$ENDIF}
end; |
Partager