Changeset 201 for GraphicTest


Ignore:
Timestamp:
Mar 17, 2011, 7:40:35 AM (13 years ago)
Author:
george
Message:
  • Modified: TFastBitmap class moved to separated unit.
  • Modified: Draw method transformed to individual classes in separated unit.
Location:
GraphicTest
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest

    • Property svn:ignore
      •  

        old new  
        11lib
        22GraphicTest
         3GraphicTest.exe
  • GraphicTest/GraphicTest.lpi

    r200 r201  
    3939      </Item2>
    4040    </RequiredPackages>
    41     <Units Count="17">
     41    <Units Count="20">
    4242      <Unit0>
    4343        <Filename Value="GraphicTest.lpr"/>
     
    4747        <TopLine Value="1"/>
    4848        <CursorPos X="17" Y="3"/>
    49         <UsageCount Value="26"/>
     49        <UsageCount Value="28"/>
    5050      </Unit0>
    5151      <Unit1>
     
    5858        <EditorIndex Value="0"/>
    5959        <WindowIndex Value="0"/>
    60         <TopLine Value="325"/>
    61         <CursorPos X="7" Y="335"/>
    62         <UsageCount Value="26"/>
     60        <TopLine Value="104"/>
     61        <CursorPos X="76" Y="111"/>
     62        <UsageCount Value="28"/>
    6363        <Loaded Value="True"/>
    6464        <LoadedDesigner Value="True"/>
     
    7676        <IsPartOfProject Value="True"/>
    7777        <UnitName Value="UPlatform"/>
    78         <EditorIndex Value="13"/>
     78        <EditorIndex Value="4"/>
    7979        <WindowIndex Value="0"/>
    8080        <TopLine Value="43"/>
    8181        <CursorPos X="1" Y="1"/>
    82         <UsageCount Value="26"/>
     82        <UsageCount Value="28"/>
    8383        <Loaded Value="True"/>
    8484      </Unit3>
     
    8686        <Filename Value="../../lazarus/lcl/intfgraphics.pas"/>
    8787        <UnitName Value="IntfGraphics"/>
    88         <EditorIndex Value="7"/>
    8988        <WindowIndex Value="0"/>
    9089        <TopLine Value="244"/>
    9190        <CursorPos X="49" Y="262"/>
    9291        <UsageCount Value="13"/>
    93         <Loaded Value="True"/>
    9492      </Unit4>
    9593      <Unit5>
    9694        <Filename Value="/usr/share/fpcsrc/2.4.0/packages/fcl-image/src/fpimage.pp"/>
    9795        <UnitName Value="FPimage"/>
    98         <EditorIndex Value="4"/>
    9996        <WindowIndex Value="0"/>
    10097        <TopLine Value="121"/>
    10198        <CursorPos X="57" Y="142"/>
    10299        <UsageCount Value="13"/>
    103         <Loaded Value="True"/>
    104100      </Unit5>
    105101      <Unit6>
    106102        <Filename Value="../../lazarus/lcl/include/lclintfh.inc"/>
    107         <EditorIndex Value="9"/>
    108103        <WindowIndex Value="0"/>
    109104        <TopLine Value="85"/>
    110105        <CursorPos X="10" Y="102"/>
    111106        <UsageCount Value="13"/>
    112         <Loaded Value="True"/>
    113107      </Unit6>
    114108      <Unit7>
    115109        <Filename Value="../../lazarus/lcl/include/lclintf.inc"/>
    116         <EditorIndex Value="10"/>
    117110        <WindowIndex Value="0"/>
    118111        <TopLine Value="153"/>
    119112        <CursorPos X="1" Y="160"/>
    120113        <UsageCount Value="13"/>
    121         <Loaded Value="True"/>
    122114      </Unit7>
    123115      <Unit8>
    124116        <Filename Value="../../lazarus/lcl/graphics.pp"/>
    125117        <UnitName Value="Graphics"/>
    126         <EditorIndex Value="2"/>
    127118        <WindowIndex Value="0"/>
    128119        <TopLine Value="1282"/>
    129120        <CursorPos X="15" Y="1299"/>
    130121        <UsageCount Value="13"/>
    131         <Loaded Value="True"/>
    132122      </Unit8>
    133123      <Unit9>
    134124        <Filename Value="../../lazarus/lcl/include/rasterimage.inc"/>
    135         <EditorIndex Value="3"/>
    136125        <WindowIndex Value="0"/>
    137126        <TopLine Value="546"/>
    138127        <CursorPos X="11" Y="553"/>
    139128        <UsageCount Value="13"/>
    140         <Loaded Value="True"/>
    141129      </Unit9>
    142130      <Unit10>
     
    149137      <Unit11>
    150138        <Filename Value="../../lazarus/lcl/interfaces/gtk2/gtk2lclintf.inc"/>
    151         <EditorIndex Value="11"/>
    152139        <WindowIndex Value="0"/>
    153140        <TopLine Value="444"/>
    154141        <CursorPos X="1" Y="461"/>
    155142        <UsageCount Value="13"/>
    156         <Loaded Value="True"/>
    157143      </Unit11>
    158144      <Unit12>
    159145        <Filename Value="/usr/share/fpcsrc/2.4.0/packages/gtk2/src/gtk+/gdk/gdkimage.inc"/>
    160         <EditorIndex Value="12"/>
    161146        <WindowIndex Value="0"/>
    162147        <TopLine Value="14"/>
    163148        <CursorPos X="24" Y="21"/>
    164149        <UsageCount Value="13"/>
    165         <Loaded Value="True"/>
    166150      </Unit12>
    167151      <Unit13>
    168152        <Filename Value="/usr/share/fpcsrc/2.4.0/packages/fcl-image/src/fpimage.inc"/>
    169         <EditorIndex Value="6"/>
    170153        <WindowIndex Value="0"/>
    171154        <TopLine Value="313"/>
    172155        <CursorPos X="24" Y="316"/>
    173156        <UsageCount Value="13"/>
    174         <Loaded Value="True"/>
    175157      </Unit13>
    176158      <Unit14>
    177159        <Filename Value="/usr/share/fpcsrc/2.4.0/packages/fcl-image/src/fppalette.inc"/>
    178         <EditorIndex Value="5"/>
    179160        <WindowIndex Value="0"/>
    180161        <TopLine Value="149"/>
    181162        <CursorPos X="3" Y="151"/>
    182163        <UsageCount Value="13"/>
    183         <Loaded Value="True"/>
    184164      </Unit14>
    185165      <Unit15>
    186166        <Filename Value="../../lazarus/lcl/graphtype.pp"/>
    187167        <UnitName Value="GraphType"/>
    188         <EditorIndex Value="8"/>
    189168        <WindowIndex Value="0"/>
    190169        <TopLine Value="171"/>
    191170        <CursorPos X="3" Y="188"/>
    192171        <UsageCount Value="12"/>
    193         <Loaded Value="True"/>
    194172      </Unit15>
    195173      <Unit16>
    196174        <Filename Value="/usr/share/fpcsrc/2.4.0/rtl/inc/systemh.inc"/>
    197         <EditorIndex Value="1"/>
    198175        <WindowIndex Value="0"/>
    199176        <TopLine Value="300"/>
    200177        <CursorPos X="3" Y="317"/>
    201178        <UsageCount Value="10"/>
    202         <Loaded Value="True"/>
    203179      </Unit16>
     180      <Unit17>
     181        <Filename Value="UDrawMethod.pas"/>
     182        <IsPartOfProject Value="True"/>
     183        <UnitName Value="UDrawMethod"/>
     184        <EditorIndex Value="3"/>
     185        <WindowIndex Value="0"/>
     186        <TopLine Value="152"/>
     187        <CursorPos X="13" Y="162"/>
     188        <UsageCount Value="22"/>
     189        <Loaded Value="True"/>
     190      </Unit17>
     191      <Unit18>
     192        <Filename Value="UFastBitmap.pas"/>
     193        <IsPartOfProject Value="True"/>
     194        <UnitName Value="UFastBitmap"/>
     195        <EditorIndex Value="2"/>
     196        <WindowIndex Value="0"/>
     197        <TopLine Value="1"/>
     198        <CursorPos X="30" Y="45"/>
     199        <UsageCount Value="22"/>
     200        <Loaded Value="True"/>
     201      </Unit18>
     202      <Unit19>
     203        <Filename Value="../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/rasterimage.inc"/>
     204        <EditorIndex Value="1"/>
     205        <WindowIndex Value="0"/>
     206        <TopLine Value="292"/>
     207        <CursorPos X="1" Y="305"/>
     208        <UsageCount Value="10"/>
     209        <Loaded Value="True"/>
     210      </Unit19>
    204211    </Units>
    205212    <JumpHistory Count="30" HistoryIndex="29">
    206213      <Position1>
    207         <Filename Value="../../lazarus/lcl/graphtype.pp"/>
    208         <Caret Line="188" Column="12" TopLine="173"/>
     214        <Filename Value="UDrawMethod.pas"/>
     215        <Caret Line="94" Column="8" TopLine="72"/>
    209216      </Position1>
    210217      <Position2>
    211         <Filename Value="UMainForm.pas"/>
    212         <Caret Line="278" Column="30" TopLine="253"/>
     218        <Filename Value="UDrawMethod.pas"/>
     219        <Caret Line="81" Column="20" TopLine="68"/>
    213220      </Position2>
    214221      <Position3>
    215         <Filename Value="UMainForm.pas"/>
    216         <Caret Line="265" Column="6" TopLine="253"/>
     222        <Filename Value="UDrawMethod.pas"/>
     223        <Caret Line="29" Column="24" TopLine="13"/>
    217224      </Position3>
    218225      <Position4>
    219         <Filename Value="UMainForm.pas"/>
    220         <Caret Line="272" Column="42" TopLine="256"/>
     226        <Filename Value="UDrawMethod.pas"/>
     227        <Caret Line="36" Column="1" TopLine="16"/>
    221228      </Position4>
    222229      <Position5>
    223         <Filename Value="UMainForm.pas"/>
    224         <Caret Line="278" Column="54" TopLine="256"/>
     230        <Filename Value="UDrawMethod.pas"/>
     231        <Caret Line="61" Column="1" TopLine="40"/>
    225232      </Position5>
    226233      <Position6>
    227         <Filename Value="UMainForm.pas"/>
    228         <Caret Line="277" Column="54" TopLine="255"/>
     234        <Filename Value="UDrawMethod.pas"/>
     235        <Caret Line="68" Column="17" TopLine="55"/>
    229236      </Position6>
    230237      <Position7>
    231238        <Filename Value="UMainForm.pas"/>
    232         <Caret Line="254" Column="27" TopLine="231"/>
     239        <Caret Line="164" Column="1" TopLine="140"/>
    233240      </Position7>
    234241      <Position8>
    235         <Filename Value="UMainForm.pas"/>
    236         <Caret Line="281" Column="13" TopLine="264"/>
     242        <Filename Value="UFastBitmap.pas"/>
     243        <Caret Line="13" Column="7" TopLine="4"/>
    237244      </Position8>
    238245      <Position9>
    239246        <Filename Value="UMainForm.pas"/>
    240         <Caret Line="286" Column="1" TopLine="260"/>
     247        <Caret Line="90" Column="23" TopLine="78"/>
    241248      </Position9>
    242249      <Position10>
    243250        <Filename Value="UMainForm.pas"/>
    244         <Caret Line="279" Column="42" TopLine="253"/>
     251        <Caret Line="91" Column="17" TopLine="78"/>
    245252      </Position10>
    246253      <Position11>
    247254        <Filename Value="UMainForm.pas"/>
    248         <Caret Line="10" Column="18" TopLine="1"/>
     255        <Caret Line="48" Column="1" TopLine="33"/>
    249256      </Position11>
    250257      <Position12>
    251258        <Filename Value="UMainForm.pas"/>
    252         <Caret Line="282" Column="40" TopLine="260"/>
     259        <Caret Line="96" Column="1" TopLine="74"/>
    253260      </Position12>
    254261      <Position13>
    255262        <Filename Value="UMainForm.pas"/>
    256         <Caret Line="10" Column="27" TopLine="1"/>
     263        <Caret Line="161" Column="7" TopLine="139"/>
    257264      </Position13>
    258265      <Position14>
    259266        <Filename Value="UMainForm.pas"/>
    260         <Caret Line="60" Column="36" TopLine="36"/>
     267        <Caret Line="146" Column="7" TopLine="101"/>
    261268      </Position14>
    262269      <Position15>
    263270        <Filename Value="UMainForm.pas"/>
    264         <Caret Line="168" Column="9" TopLine="166"/>
     271        <Caret Line="84" Column="3" TopLine="82"/>
    265272      </Position15>
    266273      <Position16>
    267274        <Filename Value="UMainForm.pas"/>
    268         <Caret Line="293" Column="1" TopLine="270"/>
     275        <Caret Line="88" Column="1" TopLine="82"/>
    269276      </Position16>
    270277      <Position17>
    271278        <Filename Value="UMainForm.pas"/>
    272         <Caret Line="119" Column="46" TopLine="102"/>
     279        <Caret Line="156" Column="35" TopLine="26"/>
    273280      </Position17>
    274281      <Position18>
    275282        <Filename Value="UMainForm.pas"/>
    276         <Caret Line="135" Column="78" TopLine="118"/>
     283        <Caret Line="88" Column="1" TopLine="75"/>
    277284      </Position18>
    278285      <Position19>
    279286        <Filename Value="UMainForm.pas"/>
    280         <Caret Line="183" Column="1" TopLine="166"/>
     287        <Caret Line="89" Column="1" TopLine="75"/>
    281288      </Position19>
    282289      <Position20>
    283290        <Filename Value="UMainForm.pas"/>
    284         <Caret Line="311" Column="7" TopLine="278"/>
     291        <Caret Line="91" Column="89" TopLine="69"/>
    285292      </Position20>
    286293      <Position21>
    287         <Filename Value="UMainForm.pas"/>
    288         <Caret Line="202" Column="1" TopLine="185"/>
     294        <Filename Value="UDrawMethod.pas"/>
     295        <Caret Line="194" Column="40" TopLine="182"/>
    289296      </Position21>
    290297      <Position22>
    291         <Filename Value="UMainForm.pas"/>
    292         <Caret Line="228" Column="1" TopLine="211"/>
     298        <Filename Value="UDrawMethod.pas"/>
     299        <Caret Line="170" Column="1" TopLine="157"/>
    293300      </Position22>
    294301      <Position23>
    295         <Filename Value="UMainForm.pas"/>
    296         <Caret Line="252" Column="1" TopLine="235"/>
     302        <Filename Value="UDrawMethod.pas"/>
     303        <Caret Line="193" Column="3" TopLine="189"/>
    297304      </Position23>
    298305      <Position24>
    299         <Filename Value="UMainForm.pas"/>
    300         <Caret Line="290" Column="3" TopLine="277"/>
     306        <Filename Value="UDrawMethod.pas"/>
     307        <Caret Line="71" Column="34" TopLine="60"/>
    301308      </Position24>
    302309      <Position25>
    303         <Filename Value="UMainForm.pas"/>
    304         <Caret Line="302" Column="30" TopLine="277"/>
     310        <Filename Value="UDrawMethod.pas"/>
     311        <Caret Line="21" Column="17" TopLine="8"/>
    305312      </Position25>
    306313      <Position26>
    307         <Filename Value="UMainForm.pas"/>
    308         <Caret Line="297" Column="62" TopLine="280"/>
     314        <Filename Value="UDrawMethod.pas"/>
     315        <Caret Line="248" Column="3" TopLine="245"/>
    309316      </Position26>
    310317      <Position27>
    311         <Filename Value="UMainForm.pas"/>
    312         <Caret Line="301" Column="17" TopLine="280"/>
     318        <Filename Value="UDrawMethod.pas"/>
     319        <Caret Line="195" Column="1" TopLine="182"/>
    313320      </Position27>
    314321      <Position28>
    315         <Filename Value="UMainForm.pas"/>
    316         <Caret Line="132" Column="38" TopLine="115"/>
     322        <Filename Value="UDrawMethod.pas"/>
     323        <Caret Line="196" Column="1" TopLine="182"/>
    317324      </Position28>
    318325      <Position29>
    319326        <Filename Value="UMainForm.pas"/>
    320         <Caret Line="347" Column="19" TopLine="325"/>
     327        <Caret Line="91" Column="89" TopLine="69"/>
    321328      </Position29>
    322329      <Position30>
    323330        <Filename Value="UMainForm.pas"/>
    324         <Caret Line="144" Column="1" TopLine="114"/>
     331        <Caret Line="119" Column="1" TopLine="101"/>
    325332      </Position30>
    326333    </JumpHistory>
  • GraphicTest/GraphicTest.lpr

    r200 r201  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UMainForm, UPlatform
     10  Forms, UMainForm, UPlatform, UDrawMethod, UFastBitmap
    1111  { you can add units after this };
    1212
  • GraphicTest/UMainForm.lfm

    r200 r201  
    11object MainForm: TMainForm
    2   Left = 357
     2  Left = 291
    33  Height = 452
    44  Top = 127
    5   Width = 627
     5  Width = 731
    66  Caption = 'Graphic test'
    77  ClientHeight = 452
    8   ClientWidth = 627
     8  ClientWidth = 731
     9  OnClose = FormClose
    910  OnCreate = FormCreate
    1011  OnDestroy = FormDestroy
    1112  LCLVersion = '0.9.31'
    1213  object PageControl1: TPageControl
    13     Left = 248
     14    Left = 312
    1415    Height = 432
    1516    Top = 16
    16     Width = 376
     17    Width = 416
    1718    ActivePage = TabSheet1
    1819    Anchors = [akTop, akLeft, akRight, akBottom]
     
    2122    object TabSheet1: TTabSheet
    2223      Caption = 'TImage'
    23       ClientHeight = 405
    24       ClientWidth = 372
     24      ClientHeight = 406
     25      ClientWidth = 408
    2526      object Image1: TImage
    2627        Left = 6
    27         Height = 392
     28        Height = 393
    2829        Top = 7
    29         Width = 362
     30        Width = 398
    3031        Anchors = [akTop, akLeft, akRight, akBottom]
    3132      end
     
    5758    Height = 14
    5859    Top = 95
    59     Width = 24
     60    Width = 23
    6061    Caption = 'FPS:'
    6162    ParentColor = False
     
    6566    Height = 14
    6667    Top = 95
    67     Width = 38
    68     Caption = 'Label2'
     68    Width = 10
     69    Caption = '   '
    6970    ParentColor = False
    7071  end
     
    8384    Height = 14
    8485    Top = 112
    85     Width = 83
     86    Width = 74
    8687    Caption = 'Frame duration'
    8788    ParentColor = False
     
    9192    Height = 14
    9293    Top = 112
    93     Width = 38
    94     Caption = 'Label4'
     94    Width = 10
     95    Caption = '   '
    9596    ParentColor = False
    9697  end
     
    99100    Height = 240
    100101    Top = 208
    101     Width = 232
     102    Width = 296
     103    Anchors = [akTop, akLeft, akBottom]
    102104    Columns = <   
    103105      item
     
    107109      item
    108110        Caption = 'Duration'
    109         Width = 111
     111        Width = 60
     112      end   
     113      item
     114        Caption = 'FPS'
     115        Width = 60
    110116      end>
    111117    TabOrder = 3
    112118    ViewStyle = vsReport
    113119  end
    114   object Button1: TButton
     120  object ButtonBenchmark: TButton
    115121    Left = 11
    116122    Height = 25
     
    118124    Width = 75
    119125    Caption = 'Benchmark'
    120     OnClick = Button1Click
     126    OnClick = ButtonBenchmarkClick
    121127    TabOrder = 4
    122128  end
    123129  object ComboBox1: TComboBox
    124130    Left = 7
    125     Height = 25
     131    Height = 21
    126132    Top = 64
    127133    Width = 233
    128     ItemHeight = 0
     134    ItemHeight = 13
    129135    Items.Strings = (
    130136      'TBitmap.Canvas.Pixels'
     
    142148    Height = 14
    143149    Top = 47
    144     Width = 46
     150    Width = 41
    145151    Caption = 'Method:'
    146152    ParentColor = False
     
    149155    OnTimer = Timer1Timer
    150156    left = 209
    151     top = 37
     157    top = 16
    152158  end
    153159end
  • GraphicTest/UMainForm.pas

    r200 r201  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    99  ExtCtrls, StdCtrls, DateUtils, UPlatform, LCLType, IntfGraphics, fpImage,
    10   Math, GraphType, Contnrs, LclIntf;
     10  Math, GraphType, Contnrs, LclIntf, UFastBitmap, UDrawMethod;
    1111
    1212const
    13   SceneFrameCount = 20;
     13  SceneFrameCount = 100;
    1414
    1515type
    1616
    17   { TScene }
    18 
    19   TScene = class
    20   private
    21     function GetSize: TPoint;
    22     procedure SetSize(const AValue: TPoint);
    23   public
    24     Pixels: array of array of Byte;
    25     procedure RandomImage;
    26     property Size: TPoint read GetSize write SetSize;
    27   end;
    2817
    2918  { TMainForm }
    3019
    3120  TMainForm = class(TForm)
    32     Button1: TButton;
     21    ButtonBenchmark: TButton;
    3322    ButtonStart: TButton;
    3423    ButtonStop: TButton;
     
    4635    TabSheet2: TTabSheet;
    4736    Timer1: TTimer;
    48     procedure Button1Click(Sender: TObject);
     37    procedure ButtonBenchmarkClick(Sender: TObject);
    4938    procedure ButtonStartClick(Sender: TObject);
    5039    procedure ButtonStopClick(Sender: TObject);
     40    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    5141    procedure FormCreate(Sender: TObject);
    5242    procedure FormDestroy(Sender: TObject);
    5343    procedure Timer1Timer(Sender: TObject);
    5444  private
    55     procedure Draw1;
    56     procedure Draw2;
    57     procedure Draw3;
    58     procedure Draw4;
    59     procedure Draw5;
    60     procedure Draw6;
    61     { private declarations }
    6245  public
     46    DrawMethod: TDrawMethod;
    6347    Bitmap: TBitmap;
    64     Frames: Integer;
    65     Scenes: TObjectList; // TObjectList<TScene>
     48    Scenes: TObjectList; // TObjectList<TFastBitmap>
    6649    SceneIndex: Integer;
    67     StartTime: TDateTime;
    68     FrameDuration: TDateTime;
    6950  end;
    7051
     
    7455implementation
    7556
    76 { TScene }
    77 
    78 function TScene.GetSize: TPoint;
    79 begin
    80   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 begin
    87   SetLength(Pixels, AValue.X, AValue.Y);
    88 end;
    89 
    90 procedure TScene.RandomImage;
    91 var
    92   X, Y: Integer;
    93 begin
    94   for Y := 0 to Size.Y - 1 do
    95     for X := 0 to Size.X - 1 do
    96       Pixels[X, Y] := Random(256);
    97 end;
    98 
    9957{$R *.lfm}
    10058
     
    10361procedure TMainForm.FormCreate(Sender: TObject);
    10462var
    105   NewScene: TScene;
     63  NewScene: TFastBitmap;
    10664  I: Integer;
    10765begin
     66  TabSheet1.DoubleBuffered := True;
    10867  Randomize;
    10968  Scenes := TObjectList.Create;
    11069  for I := 0 to SceneFrameCount - 1 do begin
    111     NewScene := TScene.Create;
     70    NewScene := TFastBitmap.Create;
    11271    NewScene.Size := Point(320, 240);
    11372    NewScene.RandomImage;
     
    11675  Bitmap := TBitmap.Create;
    11776  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;
    12080end;
    12181
     
    12585  ButtonStart.Enabled := False;
    12686  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);
    13499end;
    135100
    136 procedure TMainForm.Button1Click(Sender: TObject);
     101procedure TMainForm.ButtonBenchmarkClick(Sender: TObject);
    137102var
    138103  NewItem: TListItem;
     104  I: Integer;
    139105begin
    140106  with ListView1, Items do
     
    142108    BeginUpdate;
    143109    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;
    168121  finally
    169122    EndUpdate;
     
    177130end;
    178131
     132procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
     133begin
     134  ButtonStopClick(Self);
     135end;
     136
    179137procedure TMainForm.FormDestroy(Sender: TObject);
    180138begin
     
    185143procedure TMainForm.Timer1Timer(Sender: TObject);
    186144begin
    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';
    234150  end;
    235 end;
    236 
    237 procedure TMainForm.Draw3;
    238 var
    239   Y, X: Integer;
    240 begin
    241   repeat
    242     StartTime := NowPrecise;
    243     Inc(Frames);
    244     with TScene(Scenes[SceneIndex]) do
    245     try
    246       Image1.Picture.Bitmap.BeginUpdate(True);
    247       for X := 0 to Size.X - 1 do
    248         for Y := 0 to Size.Y - 1 do
    249           Image1.Picture.Bitmap.Canvas.Pixels[X, Y] := Pixels[X, Y] * $010101;
    250     finally
    251       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 var
    261   Y, X: Integer;
    262   TempIntfImage: TLazIntfImage;
    263   C: TFPColor;
    264 begin
    265   try
    266   TempIntfImage := Image1.Picture.Bitmap.CreateIntfImage;
    267   repeat
    268     StartTime := NowPrecise;
    269     Inc(Frames);
    270 
    271     with TScene(Scenes[SceneIndex]) do begin
    272       for X := 0 to Size.X - 1 do
    273         for Y := 0 to Size.Y - 1 do begin
    274           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   finally
    284     TempIntfImage.Free;
    285   end;
    286 end;
    287 
    288 procedure TMainForm.Draw5;
    289 var
    290   Y, X: Integer;
    291   PixelPtr: PInteger;
    292   P: TPixelFormat;
    293   RawImage: TRawImage;
    294   BytePerPixel: Integer;
    295 begin
    296   P := Image1.Picture.Bitmap.PixelFormat;
    297   repeat
    298     StartTime := NowPrecise;
    299     Inc(Frames);
    300     with TScene(Scenes[SceneIndex]) do
    301     try
    302       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 do
    307         for Y := 0 to Size.Y - 1 do begin
    308           PixelPtr^ := Pixels[X, Y] * $010101;
    309           Inc(PByte(PixelPtr), BytePerPixel);
    310         end;
    311     finally
    312       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 var
    322   Y, X: Integer;
    323   PixelPtr: PInteger;
    324   P: TPixelFormat;
    325   RawImage: TRawImage;
    326   BytePerPixel: Integer;
    327   hPaint, hBmp: HDC;
    328 begin
    329   P := Image1.Picture.Bitmap.PixelFormat;
    330   repeat
    331     StartTime := NowPrecise;
    332     Inc(Frames);
    333     with TScene(Scenes[SceneIndex]) do
    334     try
    335       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 do
    340         for Y := 0 to Size.Y - 1 do begin
    341           PixelPtr^ := Pixels[X, Y] * $010101;
    342           Inc(PByte(PixelPtr), BytePerPixel);
    343         end;
    344     finally
    345       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;
    355151end;
    356152
Note: See TracChangeset for help on using the changeset viewer.