Changeset 201 for GraphicTest/UMainForm.pas
- Timestamp:
- Mar 17, 2011, 7:40:35 AM (14 years ago)
- Location:
- GraphicTest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest
- Property svn:ignore
-
old new 1 1 lib 2 2 GraphicTest 3 GraphicTest.exe
-
- Property svn:ignore
-
GraphicTest/UMainForm.pas
r200 r201 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 9 ExtCtrls, StdCtrls, DateUtils, UPlatform, LCLType, IntfGraphics, fpImage, 10 Math, GraphType, Contnrs, LclIntf ;10 Math, GraphType, Contnrs, LclIntf, UFastBitmap, UDrawMethod; 11 11 12 12 const 13 SceneFrameCount = 20;13 SceneFrameCount = 100; 14 14 15 15 type 16 16 17 { TScene }18 19 TScene = class20 private21 function GetSize: TPoint;22 procedure SetSize(const AValue: TPoint);23 public24 Pixels: array of array of Byte;25 procedure RandomImage;26 property Size: TPoint read GetSize write SetSize;27 end;28 17 29 18 { TMainForm } 30 19 31 20 TMainForm = class(TForm) 32 Button 1: TButton;21 ButtonBenchmark: TButton; 33 22 ButtonStart: TButton; 34 23 ButtonStop: TButton; … … 46 35 TabSheet2: TTabSheet; 47 36 Timer1: TTimer; 48 procedure Button 1Click(Sender: TObject);37 procedure ButtonBenchmarkClick(Sender: TObject); 49 38 procedure ButtonStartClick(Sender: TObject); 50 39 procedure ButtonStopClick(Sender: TObject); 40 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 51 41 procedure FormCreate(Sender: TObject); 52 42 procedure FormDestroy(Sender: TObject); 53 43 procedure Timer1Timer(Sender: TObject); 54 44 private 55 procedure Draw1;56 procedure Draw2;57 procedure Draw3;58 procedure Draw4;59 procedure Draw5;60 procedure Draw6;61 { private declarations }62 45 public 46 DrawMethod: TDrawMethod; 63 47 Bitmap: TBitmap; 64 Frames: Integer; 65 Scenes: TObjectList; // TObjectList<TScene> 48 Scenes: TObjectList; // TObjectList<TFastBitmap> 66 49 SceneIndex: Integer; 67 StartTime: TDateTime;68 FrameDuration: TDateTime;69 50 end; 70 51 … … 74 55 implementation 75 56 76 { TScene }77 78 function TScene.GetSize: TPoint;79 begin80 Result.X := Length(Pixels);81 if Result.X > 0 then Result.Y := Length(Pixels[0])82 else Result.Y := 0;83 end;84 85 procedure TScene.SetSize(const AValue: TPoint);86 begin87 SetLength(Pixels, AValue.X, AValue.Y);88 end;89 90 procedure TScene.RandomImage;91 var92 X, Y: Integer;93 begin94 for Y := 0 to Size.Y - 1 do95 for X := 0 to Size.X - 1 do96 Pixels[X, Y] := Random(256);97 end;98 99 57 {$R *.lfm} 100 58 … … 103 61 procedure TMainForm.FormCreate(Sender: TObject); 104 62 var 105 NewScene: T Scene;63 NewScene: TFastBitmap; 106 64 I: Integer; 107 65 begin 66 TabSheet1.DoubleBuffered := True; 108 67 Randomize; 109 68 Scenes := TObjectList.Create; 110 69 for I := 0 to SceneFrameCount - 1 do begin 111 NewScene := T Scene.Create;70 NewScene := TFastBitmap.Create; 112 71 NewScene.Size := Point(320, 240); 113 72 NewScene.RandomImage; … … 116 75 Bitmap := TBitmap.Create; 117 76 Bitmap.PixelFormat := pf24bit; 118 Image1.Picture.Bitmap.SetSize(TScene(Scenes[0]).Size.X, TScene(Scenes[0]).Size.Y); 119 Bitmap.SetSize(TScene(Scenes[0]).Size.X, TScene(Scenes[0]).Size.Y); 77 Image1.Picture.Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y); 78 Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y); 79 ComboBox1.ItemIndex := 0; 120 80 end; 121 81 … … 125 85 ButtonStart.Enabled := False; 126 86 Timer1.Enabled := True; 127 Frames := 0; 128 if ComboBox1.ItemIndex = 0 then Draw1; 129 if ComboBox1.ItemIndex = 1 then Draw3; 130 if ComboBox1.ItemIndex = 2 then Draw2; 131 if ComboBox1.ItemIndex = 3 then Draw4; 132 if ComboBox1.ItemIndex = 4 then Draw5; 133 if ComboBox1.ItemIndex = 5 then Draw6; 87 DrawMethod.Free; 88 if ComboBox1.ItemIndex >= 0 then begin 89 DrawMethod := DrawMethodClasses[ComboBox1.ItemIndex].Create; 90 DrawMethod.Bitmap := Image1.Picture.Bitmap; 91 DrawMethod.Bitmap.SetSize(Image1.Picture.Bitmap.Width, Image1.Picture.Bitmap.Height); 92 repeat 93 DrawMethod.DrawFrameTiming(TFastBitmap(Scenes[SceneIndex])); 94 SceneIndex := (SceneIndex + 1) mod Scenes.Count; 95 Application.ProcessMessages; 96 until not ButtonStop.Enabled; 97 end; 98 ButtonStopClick(Self); 134 99 end; 135 100 136 procedure TMainForm.Button 1Click(Sender: TObject);101 procedure TMainForm.ButtonBenchmarkClick(Sender: TObject); 137 102 var 138 103 NewItem: TListItem; 104 I: Integer; 139 105 begin 140 106 with ListView1, Items do … … 142 108 BeginUpdate; 143 109 Clear; 144 Draw1; 145 NewItem := Add; 146 NewItem.Caption := ComboBox1.Items[0]; 147 NewItem.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3))); 148 Draw3; 149 NewItem := Add; 150 NewItem.Caption := ComboBox1.Items[1]; 151 NewItem.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3))); 152 Draw2; 153 NewItem := Add; 154 NewItem.Caption := ComboBox1.Items[2]; 155 NewItem.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3))); 156 Draw4; 157 NewItem := Add; 158 NewItem.Caption := ComboBox1.Items[3]; 159 NewItem.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3))); 160 Draw5; 161 NewItem := Add; 162 NewItem.Caption := ComboBox1.Items[4]; 163 NewItem.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3))); 164 Draw6; 165 NewItem := Add; 166 NewItem.Caption := ComboBox1.Items[5]; 167 NewItem.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3))); 110 for I := 0 to High(DrawMethodClasses) do begin 111 DrawMethod.Free; 112 DrawMethod := DrawMethodClasses[I].Create; 113 DrawMethod.Bitmap := Image1.Picture.Bitmap; 114 DrawMethod.Bitmap.SetSize(Image1.Picture.Bitmap.Width, Image1.Picture.Bitmap.Height); 115 DrawMethod.DrawFrameTiming(TFastBitmap(Scenes[0])); 116 NewItem := Add; 117 NewItem.Caption := DrawMethod.Caption; 118 NewItem.SubItems.Add(FloatToStr(RoundTo(DrawMethod.FrameDuration / OneMillisecond, -3))); 119 NewItem.SubItems.Add(FloatToStr(RoundTo(1 / (DrawMethod.FrameDuration / OneSecond), -3))); 120 end; 168 121 finally 169 122 EndUpdate; … … 177 130 end; 178 131 132 procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction); 133 begin 134 ButtonStopClick(Self); 135 end; 136 179 137 procedure TMainForm.FormDestroy(Sender: TObject); 180 138 begin … … 185 143 procedure TMainForm.Timer1Timer(Sender: TObject); 186 144 begin 187 Label2.Caption := IntToStr(Frames); 188 Label4.Caption := FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3)); 189 Frames := 0; 190 end; 191 192 procedure TMainForm.Draw1; 193 var 194 Y, X: Integer; 195 begin 196 repeat 197 StartTime := NowPrecise; 198 Inc(Frames); 199 with TScene(Scenes[SceneIndex]) do begin 200 for X := 0 to Size.X - 1 do 201 for Y := 0 to Size.Y - 1 do 202 Image1.Picture.Bitmap.Canvas.Pixels[X, Y] := Pixels[X, Y] * $010101; 203 FrameDuration := NowPrecise - StartTime; 204 end; 205 SceneIndex := (SceneIndex + 1) mod Scenes.Count; 206 Application.ProcessMessages; 207 until ButtonStart.Enabled; 208 end; 209 210 procedure TMainForm.Draw2; 211 var 212 Y, X: Integer; 213 TempIntfImage: TLazIntfImage; 214 begin 215 try 216 TempIntfImage := TLazIntfImage.Create(0, 0); 217 repeat 218 StartTime := NowPrecise; 219 Inc(Frames); 220 with TScene(Scenes[SceneIndex]) do begin 221 TempIntfImage.LoadFromBitmap(Image1.Picture.Bitmap.Handle, 222 Image1.Picture.Bitmap.MaskHandle); 223 for X := 0 to Size.X - 1 do 224 for Y := 0 to Size.Y - 1 do 225 TempIntfImage.Colors[X, Y] := TColorToFPColor(Pixels[X, Y] * $010101); 226 Image1.Picture.Bitmap.LoadFromIntfImage(TempIntfImage); 227 FrameDuration := NowPrecise - StartTime; 228 end; 229 SceneIndex := (SceneIndex + 1) mod Scenes.Count; 230 Application.ProcessMessages; 231 until ButtonStart.Enabled; 232 finally 233 TempIntfImage.Free; 145 if Assigned(DrawMethod) then begin 146 if (DrawMethod.FrameDuration > 0) then 147 Label2.Caption := FloatToStr(RoundTo(1 / (DrawMethod.FrameDuration / OneSecond), -3)) 148 else Label2.Caption := '0'; 149 Label4.Caption := FloatToStr(RoundTo(DrawMethod.FrameDuration / OneMillisecond, -3)) + ' ms'; 234 150 end; 235 end;236 237 procedure TMainForm.Draw3;238 var239 Y, X: Integer;240 begin241 repeat242 StartTime := NowPrecise;243 Inc(Frames);244 with TScene(Scenes[SceneIndex]) do245 try246 Image1.Picture.Bitmap.BeginUpdate(True);247 for X := 0 to Size.X - 1 do248 for Y := 0 to Size.Y - 1 do249 Image1.Picture.Bitmap.Canvas.Pixels[X, Y] := Pixels[X, Y] * $010101;250 finally251 Image1.Picture.Bitmap.EndUpdate(False);252 end;253 FrameDuration := NowPrecise - StartTime;254 SceneIndex := (SceneIndex + 1) mod Scenes.Count;255 Application.ProcessMessages;256 until ButtonStart.Enabled;257 end;258 259 procedure TMainForm.Draw4;260 var261 Y, X: Integer;262 TempIntfImage: TLazIntfImage;263 C: TFPColor;264 begin265 try266 TempIntfImage := Image1.Picture.Bitmap.CreateIntfImage;267 repeat268 StartTime := NowPrecise;269 Inc(Frames);270 271 with TScene(Scenes[SceneIndex]) do begin272 for X := 0 to Size.X - 1 do273 for Y := 0 to Size.Y - 1 do begin274 C := TColorToFPColor(Pixels[X, Y] * $010101);275 TempIntfImage.Colors[X, Y] := C;276 end;277 Image1.Picture.Bitmap.LoadFromIntfImage(TempIntfImage);278 end;279 FrameDuration := NowPrecise - StartTime;280 SceneIndex := (SceneIndex + 1) mod Scenes.Count;281 Application.ProcessMessages;282 until ButtonStart.Enabled;283 finally284 TempIntfImage.Free;285 end;286 end;287 288 procedure TMainForm.Draw5;289 var290 Y, X: Integer;291 PixelPtr: PInteger;292 P: TPixelFormat;293 RawImage: TRawImage;294 BytePerPixel: Integer;295 begin296 P := Image1.Picture.Bitmap.PixelFormat;297 repeat298 StartTime := NowPrecise;299 Inc(Frames);300 with TScene(Scenes[SceneIndex]) do301 try302 Image1.Picture.Bitmap.BeginUpdate(False);303 RawImage := Image1.Picture.Bitmap.RawImage;304 PixelPtr := PInteger(RawImage.Data);305 BytePerPixel := RawImage.Description.BitsPerPixel div 8;306 for X := 0 to Size.X - 1 do307 for Y := 0 to Size.Y - 1 do begin308 PixelPtr^ := Pixels[X, Y] * $010101;309 Inc(PByte(PixelPtr), BytePerPixel);310 end;311 finally312 Image1.Picture.Bitmap.EndUpdate(False);313 end;314 FrameDuration := NowPrecise - StartTime;315 SceneIndex := (SceneIndex + 1) mod Scenes.Count;316 Application.ProcessMessages;317 until ButtonStart.Enabled;318 end;319 320 procedure TMainForm.Draw6;321 var322 Y, X: Integer;323 PixelPtr: PInteger;324 P: TPixelFormat;325 RawImage: TRawImage;326 BytePerPixel: Integer;327 hPaint, hBmp: HDC;328 begin329 P := Image1.Picture.Bitmap.PixelFormat;330 repeat331 StartTime := NowPrecise;332 Inc(Frames);333 with TScene(Scenes[SceneIndex]) do334 try335 Bitmap.BeginUpdate(False);336 RawImage := Bitmap.RawImage;337 PixelPtr := PInteger(RawImage.Data);338 BytePerPixel := RawImage.Description.BitsPerPixel div 8;339 for X := 0 to Size.X - 1 do340 for Y := 0 to Size.Y - 1 do begin341 PixelPtr^ := Pixels[X, Y] * $010101;342 Inc(PByte(PixelPtr), BytePerPixel);343 end;344 finally345 Bitmap.EndUpdate(False);346 end;347 hBmp := Bitmap.Canvas.Handle;348 hPaint := PaintBox1.Canvas.Handle;349 BitBlt(hPaint, 0, 0, Bitmap.Width, Bitmap.Height, hBmp, 0, 0, srcCopy);350 351 FrameDuration := NowPrecise - StartTime;352 SceneIndex := (SceneIndex + 1) mod Scenes.Count;353 Application.ProcessMessages;354 until ButtonStart.Enabled;355 151 end; 356 152
Note:
See TracChangeset
for help on using the changeset viewer.