Image noise: Difference between revisions

Content added Content deleted
(Added Delphi example)
Line 863: Line 863:


Generating random bits with the C core.stdc.stdlib.rand the performance becomes about the same of the C version.
Generating random bits with the C core.stdc.stdlib.rand the performance becomes about the same of the C version.
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
{{libheader| System.SysUtils}}
{{libheader| Vcl.Forms}}
{{libheader| Vcl.Graphics}}
{{libheader| Vcl.Controls}}
{{libheader| System.Classes}}
{{libheader| Vcl.ExtCtrls}}
<lang Delphi>
unit Main;


interface

uses
Winapi.Windows, System.SysUtils, Vcl.Forms, Vcl.Graphics, Vcl.Controls,
System.Classes, Vcl.ExtCtrls;

type
TfmNoise = class(TForm)
tmr1sec: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure tmr1secTimer(Sender: TObject);
end;

var
fmNoise: TfmNoise;
Surface: TBitmap;
FrameCount: Cardinal = 0;

implementation

{$R *.dfm}

procedure TfmNoise.FormCreate(Sender: TObject);
begin
Surface := TBitmap.Create;
Surface.SetSize(320, 240);
Surface.PixelFormat := pf1bit;
Randomize;
end;

procedure TfmNoise.FormDestroy(Sender: TObject);
begin
Surface.Free;
end;

type
PDWordArray = ^TDWordArray;

TDWordArray = array[0..16383] of DWord;

procedure TfmNoise.FormPaint(Sender: TObject);
var
x, y: Integer;
line: PWordArray;
begin
with Surface do
for y := 0 to Height - 1 do
begin
line := Surface.ScanLine[y];
for x := 0 to (Width div 16) - 1 do
line[x] := Random($FFFF);
// Fill 16 pixels at same time
end;

Canvas.Draw(0, 0, Surface);
Inc(FrameCount);
Application.ProcessMessages;
Invalidate;
end;

procedure TfmNoise.tmr1secTimer(Sender: TObject);
begin
Caption := 'FPS: ' + FrameCount.ToString;
FrameCount := 0;
end;

end.</lang>
Resources form:
<lang Delphi>
object fmNoise: TfmNoise
Left = 0
Top = 0
BorderIcons = [biSystemMenu]
BorderStyle = bsSingle
Caption = 'fmNoise'
ClientHeight = 240
ClientWidth = 320
OnCreate = FormCreate
OnDestroy = FormDestroy
OnPaint = FormPaint
object tmr1sec: TTimer
Interval = 2000
OnTimer = tmr1secTimer
end
end
</lang>
{{out}}
<pre>
1400 to 1600 FPS
</pre>
=={{header|Euler Math Toolbox}}==
=={{header|Euler Math Toolbox}}==