Changeset 202 for GraphicTest


Ignore:
Timestamp:
Mar 17, 2011, 9:38:21 AM (13 years ago)
Author:
george
Message:
  • Added: TBGRABitmap.ScanLine method.
  • Modified: All draw methods objects are allocated on program creation now.
Location:
GraphicTest
Files:
18 added
4 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/GraphicTest.lpi

    r201 r202  
    3939      </Item2>
    4040    </RequiredPackages>
    41     <Units Count="20">
     41    <Units Count="27">
    4242      <Unit0>
    4343        <Filename Value="GraphicTest.lpr"/>
     
    4747        <TopLine Value="1"/>
    4848        <CursorPos X="17" Y="3"/>
    49         <UsageCount Value="28"/>
     49        <UsageCount Value="32"/>
    5050      </Unit0>
    5151      <Unit1>
     
    5858        <EditorIndex Value="0"/>
    5959        <WindowIndex Value="0"/>
    60         <TopLine Value="104"/>
    61         <CursorPos X="76" Y="111"/>
    62         <UsageCount Value="28"/>
     60        <TopLine Value="107"/>
     61        <CursorPos X="1" Y="122"/>
     62        <UsageCount Value="32"/>
    6363        <Loaded Value="True"/>
    6464        <LoadedDesigner Value="True"/>
     
    7070        <TopLine Value="1"/>
    7171        <CursorPos X="42" Y="22"/>
    72         <UsageCount Value="19"/>
     72        <UsageCount Value="18"/>
    7373      </Unit2>
    7474      <Unit3>
     
    7676        <IsPartOfProject Value="True"/>
    7777        <UnitName Value="UPlatform"/>
    78         <EditorIndex Value="4"/>
     78        <EditorIndex Value="11"/>
    7979        <WindowIndex Value="0"/>
    8080        <TopLine Value="43"/>
    8181        <CursorPos X="1" Y="1"/>
    82         <UsageCount Value="28"/>
     82        <UsageCount Value="32"/>
    8383        <Loaded Value="True"/>
    8484      </Unit3>
     
    8989        <TopLine Value="244"/>
    9090        <CursorPos X="49" Y="262"/>
    91         <UsageCount Value="13"/>
     91        <UsageCount Value="12"/>
    9292      </Unit4>
    9393      <Unit5>
     
    9797        <TopLine Value="121"/>
    9898        <CursorPos X="57" Y="142"/>
    99         <UsageCount Value="13"/>
     99        <UsageCount Value="12"/>
    100100      </Unit5>
    101101      <Unit6>
     
    104104        <TopLine Value="85"/>
    105105        <CursorPos X="10" Y="102"/>
    106         <UsageCount Value="13"/>
     106        <UsageCount Value="12"/>
    107107      </Unit6>
    108108      <Unit7>
     
    111111        <TopLine Value="153"/>
    112112        <CursorPos X="1" Y="160"/>
    113         <UsageCount Value="13"/>
     113        <UsageCount Value="12"/>
    114114      </Unit7>
    115115      <Unit8>
     
    119119        <TopLine Value="1282"/>
    120120        <CursorPos X="15" Y="1299"/>
    121         <UsageCount Value="13"/>
     121        <UsageCount Value="12"/>
    122122      </Unit8>
    123123      <Unit9>
     
    126126        <TopLine Value="546"/>
    127127        <CursorPos X="11" Y="553"/>
    128         <UsageCount Value="13"/>
     128        <UsageCount Value="12"/>
    129129      </Unit9>
    130130      <Unit10>
     
    133133        <TopLine Value="389"/>
    134134        <CursorPos X="1" Y="411"/>
    135         <UsageCount Value="10"/>
     135        <UsageCount Value="9"/>
    136136      </Unit10>
    137137      <Unit11>
     
    140140        <TopLine Value="444"/>
    141141        <CursorPos X="1" Y="461"/>
    142         <UsageCount Value="13"/>
     142        <UsageCount Value="12"/>
    143143      </Unit11>
    144144      <Unit12>
     
    147147        <TopLine Value="14"/>
    148148        <CursorPos X="24" Y="21"/>
    149         <UsageCount Value="13"/>
     149        <UsageCount Value="12"/>
    150150      </Unit12>
    151151      <Unit13>
     
    154154        <TopLine Value="313"/>
    155155        <CursorPos X="24" Y="316"/>
    156         <UsageCount Value="13"/>
     156        <UsageCount Value="12"/>
    157157      </Unit13>
    158158      <Unit14>
     
    161161        <TopLine Value="149"/>
    162162        <CursorPos X="3" Y="151"/>
    163         <UsageCount Value="13"/>
     163        <UsageCount Value="12"/>
    164164      </Unit14>
    165165      <Unit15>
     
    169169        <TopLine Value="171"/>
    170170        <CursorPos X="3" Y="188"/>
    171         <UsageCount Value="12"/>
     171        <UsageCount Value="11"/>
    172172      </Unit15>
    173173      <Unit16>
     
    176176        <TopLine Value="300"/>
    177177        <CursorPos X="3" Y="317"/>
    178         <UsageCount Value="10"/>
     178        <UsageCount Value="9"/>
    179179      </Unit16>
    180180      <Unit17>
     
    182182        <IsPartOfProject Value="True"/>
    183183        <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"/>
     184        <EditorIndex Value="6"/>
     185        <WindowIndex Value="0"/>
     186        <TopLine Value="1"/>
     187        <CursorPos X="33" Y="15"/>
     188        <UsageCount Value="26"/>
    189189        <Loaded Value="True"/>
    190190      </Unit17>
     
    193193        <IsPartOfProject Value="True"/>
    194194        <UnitName Value="UFastBitmap"/>
    195         <EditorIndex Value="2"/>
     195        <EditorIndex Value="5"/>
    196196        <WindowIndex Value="0"/>
    197197        <TopLine Value="1"/>
    198         <CursorPos X="30" Y="45"/>
    199         <UsageCount Value="22"/>
     198        <CursorPos X="20" Y="20"/>
     199        <UsageCount Value="26"/>
    200200        <Loaded Value="True"/>
    201201      </Unit18>
    202202      <Unit19>
    203203        <Filename Value="../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/rasterimage.inc"/>
     204        <EditorIndex Value="2"/>
     205        <WindowIndex Value="0"/>
     206        <TopLine Value="504"/>
     207        <CursorPos X="1" Y="521"/>
     208        <UsageCount Value="12"/>
     209        <Loaded Value="True"/>
     210      </Unit19>
     211      <Unit20>
     212        <Filename Value="bgrabitmap/bgradefaultbitmap.pas"/>
     213        <UnitName Value="BGRADefaultBitmap"/>
     214        <EditorIndex Value="3"/>
     215        <WindowIndex Value="0"/>
     216        <TopLine Value="224"/>
     217        <CursorPos X="15" Y="237"/>
     218        <UsageCount Value="11"/>
     219        <Loaded Value="True"/>
     220      </Unit20>
     221      <Unit21>
     222        <Filename Value="bgrabitmap/bgrawinbitmap.pas"/>
     223        <UnitName Value="BGRAWinBitmap"/>
     224        <EditorIndex Value="4"/>
     225        <WindowIndex Value="0"/>
     226        <TopLine Value="169"/>
     227        <CursorPos X="1" Y="190"/>
     228        <UsageCount Value="11"/>
     229        <Loaded Value="True"/>
     230      </Unit21>
     231      <Unit22>
     232        <Filename Value="../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/extctrls.pp"/>
     233        <UnitName Value="ExtCtrls"/>
    204234        <EditorIndex Value="1"/>
    205235        <WindowIndex Value="0"/>
    206         <TopLine Value="292"/>
    207         <CursorPos X="1" Y="305"/>
     236        <TopLine Value="584"/>
     237        <CursorPos X="3" Y="597"/>
    208238        <UsageCount Value="10"/>
    209239        <Loaded Value="True"/>
    210       </Unit19>
     240      </Unit22>
     241      <Unit23>
     242        <Filename Value="../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/winapih.inc"/>
     243        <EditorIndex Value="9"/>
     244        <WindowIndex Value="0"/>
     245        <TopLine Value="32"/>
     246        <CursorPos X="10" Y="45"/>
     247        <UsageCount Value="10"/>
     248        <Loaded Value="True"/>
     249      </Unit23>
     250      <Unit24>
     251        <Filename Value="../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/include/winapi.inc"/>
     252        <EditorIndex Value="10"/>
     253        <WindowIndex Value="0"/>
     254        <TopLine Value="51"/>
     255        <CursorPos X="3" Y="53"/>
     256        <UsageCount Value="10"/>
     257        <Loaded Value="True"/>
     258      </Unit24>
     259      <Unit25>
     260        <Filename Value="../../../Projekty2/FreePascalManager/trunk/Instance/1/Lazarus/lcl/graphics.pp"/>
     261        <UnitName Value="Graphics"/>
     262        <EditorIndex Value="8"/>
     263        <WindowIndex Value="0"/>
     264        <TopLine Value="1081"/>
     265        <CursorPos X="15" Y="1094"/>
     266        <UsageCount Value="10"/>
     267        <Loaded Value="True"/>
     268      </Unit25>
     269      <Unit26>
     270        <Filename Value="../../../Projekty2/FreePascalManager/trunk/Instance/1/FPC/rtl/objpas/classes/classesh.inc"/>
     271        <EditorIndex Value="7"/>
     272        <WindowIndex Value="0"/>
     273        <TopLine Value="1883"/>
     274        <CursorPos X="10" Y="1896"/>
     275        <UsageCount Value="10"/>
     276        <Loaded Value="True"/>
     277      </Unit26>
    211278    </Units>
    212     <JumpHistory Count="30" HistoryIndex="29">
     279    <JumpHistory Count="29" HistoryIndex="28">
    213280      <Position1>
    214         <Filename Value="UDrawMethod.pas"/>
    215         <Caret Line="94" Column="8" TopLine="72"/>
     281        <Filename Value="bgrabitmap/bgrawinbitmap.pas"/>
     282        <Caret Line="177" Column="1" TopLine="165"/>
    216283      </Position1>
    217284      <Position2>
    218         <Filename Value="UDrawMethod.pas"/>
    219         <Caret Line="81" Column="20" TopLine="68"/>
     285        <Filename Value="bgrabitmap/bgrawinbitmap.pas"/>
     286        <Caret Line="179" Column="1" TopLine="165"/>
    220287      </Position2>
    221288      <Position3>
    222         <Filename Value="UDrawMethod.pas"/>
    223         <Caret Line="29" Column="24" TopLine="13"/>
     289        <Filename Value="bgrabitmap/bgrawinbitmap.pas"/>
     290        <Caret Line="180" Column="1" TopLine="165"/>
    224291      </Position3>
    225292      <Position4>
    226         <Filename Value="UDrawMethod.pas"/>
    227         <Caret Line="36" Column="1" TopLine="16"/>
     293        <Filename Value="bgrabitmap/bgrawinbitmap.pas"/>
     294        <Caret Line="181" Column="1" TopLine="168"/>
    228295      </Position4>
    229296      <Position5>
    230         <Filename Value="UDrawMethod.pas"/>
    231         <Caret Line="61" Column="1" TopLine="40"/>
     297        <Filename Value="bgrabitmap/bgrawinbitmap.pas"/>
     298        <Caret Line="183" Column="1" TopLine="168"/>
    232299      </Position5>
    233300      <Position6>
    234         <Filename Value="UDrawMethod.pas"/>
    235         <Caret Line="68" Column="17" TopLine="55"/>
     301        <Filename Value="bgrabitmap/bgrawinbitmap.pas"/>
     302        <Caret Line="187" Column="1" TopLine="168"/>
    236303      </Position6>
    237304      <Position7>
    238         <Filename Value="UMainForm.pas"/>
    239         <Caret Line="164" Column="1" TopLine="140"/>
     305        <Filename Value="bgrabitmap/bgrawinbitmap.pas"/>
     306        <Caret Line="189" Column="1" TopLine="168"/>
    240307      </Position7>
    241308      <Position8>
    242         <Filename Value="UFastBitmap.pas"/>
    243         <Caret Line="13" Column="7" TopLine="4"/>
     309        <Filename Value="bgrabitmap/bgradefaultbitmap.pas"/>
     310        <Caret Line="809" Column="1" TopLine="796"/>
    244311      </Position8>
    245312      <Position9>
    246         <Filename Value="UMainForm.pas"/>
    247         <Caret Line="90" Column="23" TopLine="78"/>
     313        <Filename Value="bgrabitmap/bgradefaultbitmap.pas"/>
     314        <Caret Line="810" Column="1" TopLine="796"/>
    248315      </Position9>
    249316      <Position10>
    250         <Filename Value="UMainForm.pas"/>
    251         <Caret Line="91" Column="17" TopLine="78"/>
     317        <Filename Value="bgrabitmap/bgrawinbitmap.pas"/>
     318        <Caret Line="190" Column="1" TopLine="169"/>
    252319      </Position10>
    253320      <Position11>
    254         <Filename Value="UMainForm.pas"/>
    255         <Caret Line="48" Column="1" TopLine="33"/>
     321        <Filename Value="bgrabitmap/bgradefaultbitmap.pas"/>
     322        <Caret Line="503" Column="1" TopLine="490"/>
    256323      </Position11>
    257324      <Position12>
    258         <Filename Value="UMainForm.pas"/>
    259         <Caret Line="96" Column="1" TopLine="74"/>
     325        <Filename Value="UDrawMethod.pas"/>
     326        <Caret Line="102" Column="1" TopLine="96"/>
    260327      </Position12>
    261328      <Position13>
    262         <Filename Value="UMainForm.pas"/>
    263         <Caret Line="161" Column="7" TopLine="139"/>
     329        <Filename Value="UDrawMethod.pas"/>
     330        <Caret Line="133" Column="25" TopLine="111"/>
    264331      </Position13>
    265332      <Position14>
    266         <Filename Value="UMainForm.pas"/>
    267         <Caret Line="146" Column="7" TopLine="101"/>
     333        <Filename Value="UDrawMethod.pas"/>
     334        <Caret Line="134" Column="16" TopLine="111"/>
    268335      </Position14>
    269336      <Position15>
    270337        <Filename Value="UMainForm.pas"/>
    271         <Caret Line="84" Column="3" TopLine="82"/>
     338        <Caret Line="78" Column="50" TopLine="67"/>
    272339      </Position15>
    273340      <Position16>
    274         <Filename Value="UMainForm.pas"/>
    275         <Caret Line="88" Column="1" TopLine="82"/>
     341        <Filename Value="UDrawMethod.pas"/>
     342        <Caret Line="8" Column="32" TopLine="3"/>
    276343      </Position16>
    277344      <Position17>
    278345        <Filename Value="UMainForm.pas"/>
    279         <Caret Line="156" Column="35" TopLine="26"/>
     346        <Caret Line="8" Column="20" TopLine="1"/>
    280347      </Position17>
    281348      <Position18>
    282349        <Filename Value="UMainForm.pas"/>
    283         <Caret Line="88" Column="1" TopLine="75"/>
     350        <Caret Line="33" Column="19" TopLine="12"/>
    284351      </Position18>
    285352      <Position19>
    286         <Filename Value="UMainForm.pas"/>
    287         <Caret Line="89" Column="1" TopLine="75"/>
     353        <Filename Value="UDrawMethod.pas"/>
     354        <Caret Line="8" Column="42" TopLine="1"/>
    288355      </Position19>
    289356      <Position20>
    290         <Filename Value="UMainForm.pas"/>
    291         <Caret Line="91" Column="89" TopLine="69"/>
     357        <Filename Value="UDrawMethod.pas"/>
     358        <Caret Line="29" Column="39" TopLine="14"/>
    292359      </Position20>
    293360      <Position21>
    294361        <Filename Value="UDrawMethod.pas"/>
    295         <Caret Line="194" Column="40" TopLine="182"/>
     362        <Caret Line="138" Column="5" TopLine="120"/>
    296363      </Position21>
    297364      <Position22>
    298365        <Filename Value="UDrawMethod.pas"/>
    299         <Caret Line="170" Column="1" TopLine="157"/>
     366        <Caret Line="173" Column="23" TopLine="157"/>
    300367      </Position22>
    301368      <Position23>
    302369        <Filename Value="UDrawMethod.pas"/>
    303         <Caret Line="193" Column="3" TopLine="189"/>
     370        <Caret Line="158" Column="12" TopLine="155"/>
    304371      </Position23>
    305372      <Position24>
    306373        <Filename Value="UDrawMethod.pas"/>
    307         <Caret Line="71" Column="34" TopLine="60"/>
     374        <Caret Line="28" Column="34" TopLine="14"/>
    308375      </Position24>
    309376      <Position25>
    310377        <Filename Value="UDrawMethod.pas"/>
    311         <Caret Line="21" Column="17" TopLine="8"/>
     378        <Caret Line="177" Column="48" TopLine="155"/>
    312379      </Position25>
    313380      <Position26>
    314381        <Filename Value="UDrawMethod.pas"/>
    315         <Caret Line="248" Column="3" TopLine="245"/>
     382        <Caret Line="316" Column="26" TopLine="305"/>
    316383      </Position26>
    317384      <Position27>
    318385        <Filename Value="UDrawMethod.pas"/>
    319         <Caret Line="195" Column="1" TopLine="182"/>
     386        <Caret Line="329" Column="3" TopLine="327"/>
    320387      </Position27>
    321388      <Position28>
    322389        <Filename Value="UDrawMethod.pas"/>
    323         <Caret Line="196" Column="1" TopLine="182"/>
     390        <Caret Line="178" Column="29" TopLine="164"/>
    324391      </Position28>
    325392      <Position29>
    326         <Filename Value="UMainForm.pas"/>
    327         <Caret Line="91" Column="89" TopLine="69"/>
     393        <Filename Value="UDrawMethod.pas"/>
     394        <Caret Line="179" Column="22" TopLine="164"/>
    328395      </Position29>
    329       <Position30>
    330         <Filename Value="UMainForm.pas"/>
    331         <Caret Line="119" Column="1" TopLine="101"/>
    332       </Position30>
    333396    </JumpHistory>
    334397  </ProjectOptions>
     
    340403    <SearchPaths>
    341404      <IncludeFiles Value="$(ProjOutDir)"/>
     405      <OtherUnitFiles Value="BGRABitmap"/>
    342406      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
    343407    </SearchPaths>
     
    350414    </Linking>
    351415    <Other>
     416      <CompilerMessages>
     417        <UseMsgFile Value="True"/>
     418      </CompilerMessages>
    352419      <CompilerPath Value="$(CompPath)"/>
    353420    </Other>
  • GraphicTest/UDrawMethod.pas

    r201 r202  
    66
    77uses
    8   Classes, SysUtils, UPlatform, UFastBitmap, Graphics,
    9   LCLType, IntfGraphics, fpImage, GraphType;
     8  Classes, SysUtils, StdCtrls, ExtCtrls, UPlatform, UFastBitmap, Graphics,
     9  LCLType, IntfGraphics, fpImage, GraphType, BGRABitmap, BGRABitmapTypes,
     10  LclIntf;
    1011
    1112type
     
    1415
    1516  TDrawMethod = class
     17  private
     18    FBitmap: TBitmap;
     19    TempBitmap: TBitmap;
     20    FPaintBox: TPaintBox;
     21    procedure SetBitmap(const AValue: TBitmap); virtual;
     22    procedure SetPaintBox(const AValue: TPaintBox);
    1623  public
    1724    Caption: string;
    1825    Terminated: Boolean;
    19     Bitmap: TBitmap;
    2026    FrameDuration: TDateTime;
    2127    constructor Create; virtual;
     28    destructor Destroy; override;
    2229    procedure DrawFrame(FastBitmap: TFastBitmap); virtual;
    2330    procedure DrawFrameTiming(FastBitmap: TFastBitmap);
    24     procedure DrawLoop;
     31    property Bitmap: TBitmap read FBitmap write SetBitmap;
     32    property PaintBox: TPaintBox read FPaintBox write SetPaintBox;
    2533  end;
    2634
     
    5462  TLazIntfImageColorsNoCopy = class(TDrawMethod)
    5563    TempIntfImage: TLazIntfImage;
     64    procedure SetBitmap(const AValue: TBitmap); override;
    5665    constructor Create; override;
    5766    destructor Destroy; override;
     
    7382  end;
    7483
     84  { TBGRABitmapPaintBox }
     85
     86  TBGRABitmapPaintBox = class(TDrawMethod)
     87    BGRABitmap: TBGRABitmap;
     88    procedure SetBitmap(const AValue: TBitmap); override;
     89    constructor Create; override;
     90    destructor Destroy; override;
     91    procedure DrawFrame(FastBitmap: TFastBitmap); override;
     92  end;
     93
    7594const
    76   DrawMethodClasses: array[0..5] of TDrawMethodClass = (
     95  DrawMethodClasses: array[0..6] of TDrawMethodClass = (
    7796    TCanvasPixels, TCanvasPixelsUpdateLock, TLazIntfImageColorsCopy,
    78     TLazIntfImageColorsNoCopy, TBitmapRawImageData, TBitmapRawImageDataPaintBox);
     97    TLazIntfImageColorsNoCopy, TBitmapRawImageData, TBitmapRawImageDataPaintBox,
     98    TBGRABitmapPaintBox);
    7999
    80100implementation
    81101
     102{ TBGRABitmapPaintBox }
     103
     104procedure TBGRABitmapPaintBox.SetBitmap(const AValue: TBitmap);
     105begin
     106  inherited;
     107  BGRABitmap.SetSize(Bitmap.Width, Bitmap.Height);
     108end;
     109
     110constructor TBGRABitmapPaintBox.Create;
     111begin
     112  inherited;
     113  Caption := 'TBGRABitmap PaintBox';
     114  BGRABitmap := TBGRABitmap.Create(0, 0);
     115end;
     116
     117destructor TBGRABitmapPaintBox.Destroy;
     118begin
     119  BGRABitmap.Free;
     120  inherited Destroy;
     121end;
     122
     123procedure TBGRABitmapPaintBox.DrawFrame(FastBitmap: TFastBitmap);
     124var
     125  X, Y: Integer;
     126  P: PBGRAPixel;
     127begin
     128  with FastBitmap do
     129  for Y := 0 to Size.Y - 1 do begin
     130    P := BGRABitmap.ScanLine[Y];
     131    for X := 0 to Size.X - 1 do begin
     132      P^.red := Pixels[X, Y];
     133      P^.green := Pixels[X, Y];
     134      P^.blue := Pixels[X, Y];
     135      P^.alpha := 255;
     136      Inc(P);
     137    end;
     138  end;
     139  BGRABitmap.InvalidateBitmap; // changed by direct access
     140  //BGRABitmap.Draw(Bitmap.Canvas, 0, 0, False);
     141  BGRABitmap.Draw(PaintBox.Canvas, 0, 0, True);
     142end;
     143
    82144{ TBitmapRawImageDataPaintBox }
    83145
    84146constructor TBitmapRawImageDataPaintBox.Create;
    85147begin
     148  inherited;
    86149  Caption := 'TBitmap.RawImage.Data PaintBox';
    87150end;
     
    95158  BytePerPixel: Integer;
    96159  hPaint, hBmp: HDC;
     160begin
     161  P := TempBitmap.PixelFormat;
     162    with FastBitmap do
     163    try
     164      TempBitmap.BeginUpdate(False);
     165      RawImage := TempBitmap.RawImage;
     166      PixelPtr := PInteger(RawImage.Data);
     167      BytePerPixel := RawImage.Description.BitsPerPixel div 8;
     168      for X := 0 to Size.X - 1 do
     169        for Y := 0 to Size.Y - 1 do begin
     170          PixelPtr^ := Pixels[X, Y] * $010101;
     171          Inc(PByte(PixelPtr), BytePerPixel);
     172        end;
     173    finally
     174      TempBitmap.EndUpdate(False);
     175    end;
     176    hBmp := TempBitmap.Canvas.Handle;
     177    hPaint := PaintBox.Canvas.Handle;
     178    PaintBox.Canvas.CopyRect(Rect(0, 0, Bitmap.Width, Bitmap.Height), TempBitmap.Canvas,
     179      Rect(0, 0, TempBitmap.Width, TempBitmap.Height));
     180    //BitBlt(hPaint, 0, 0, TempBitmap.Width, TempBitmap.Height, hBmp, 0, 0, srcCopy);
     181end;
     182
     183{ TBitmapRawImageData }
     184
     185constructor TBitmapRawImageData.Create;
     186begin
     187  inherited;
     188  Caption := 'TBitmap.RawImage.Data';
     189end;
     190
     191procedure TBitmapRawImageData.DrawFrame(FastBitmap: TFastBitmap);
     192var
     193  Y, X: Integer;
     194  PixelPtr: PInteger;
     195  P: TPixelFormat;
     196  RawImage: TRawImage;
     197  BytePerPixel: Integer;
    97198begin
    98199  P := Bitmap.PixelFormat;
     
    111212      Bitmap.EndUpdate(False);
    112213    end;
    113     hBmp := Bitmap.Canvas.Handle;
    114     //hPaint := PaintBox1.Canvas.Handle;
    115     //BitBlt(hPaint, 0, 0, Bitmap.Width, Bitmap.Height, hBmp, 0, 0, srcCopy);
    116 end;
    117 
    118 { TBitmapRawImageData }
    119 
    120 constructor TBitmapRawImageData.Create;
    121 begin
    122   Caption := 'TBitmap.RawImage.Data';
    123 end;
    124 
    125 procedure TBitmapRawImageData.DrawFrame(FastBitmap: TFastBitmap);
    126 var
    127   Y, X: Integer;
    128   PixelPtr: PInteger;
    129   P: TPixelFormat;
    130   RawImage: TRawImage;
    131   BytePerPixel: Integer;
    132 begin
    133   P := Bitmap.PixelFormat;
    134     with FastBitmap do
    135     try
    136       Bitmap.BeginUpdate(False);
    137       RawImage := Bitmap.RawImage;
    138       PixelPtr := PInteger(RawImage.Data);
    139       BytePerPixel := RawImage.Description.BitsPerPixel div 8;
    140       for X := 0 to Size.X - 1 do
    141         for Y := 0 to Size.Y - 1 do begin
    142           PixelPtr^ := Pixels[X, Y] * $010101;
    143           Inc(PByte(PixelPtr), BytePerPixel);
    144         end;
    145     finally
    146       Bitmap.EndUpdate(False);
    147     end;
    148214end;
    149215
    150216{ TLazIntfImageColorsNoCopy }
    151217
     218procedure TLazIntfImageColorsNoCopy.SetBitmap(const AValue: TBitmap);
     219begin
     220  inherited SetBitmap(AValue);
     221  TempIntfImage.Free;
     222  TempIntfImage := Bitmap.CreateIntfImage;
     223end;
     224
    152225constructor TLazIntfImageColorsNoCopy.Create;
    153226begin
     227  inherited;
    154228  Caption := 'TLazIntfImage.Colors no copy';
    155229end;
     
    166240begin
    167241  with FastBitmap do begin
    168     if not Assigned(TempIntfImage) then
    169       TempIntfImage := Bitmap.CreateIntfImage;
    170242    for X := 0 to Size.X - 1 do
    171243      for Y := 0 to Size.Y - 1 do
     
    179251constructor TLazIntfImageColorsCopy.Create;
    180252begin
     253  inherited;
    181254  Caption := 'TLazIntfImage.Colors copy';
    182255  TempIntfImage := TLazIntfImage.Create(0, 0);
     
    207280constructor TCanvasPixelsUpdateLock.Create;
    208281begin
     282  inherited;
    209283  Caption := 'TBitmap.Canvas.Pixels Update locking';
    210284end;
     
    229303constructor TCanvasPixels.Create;
    230304begin
     305  inherited;
    231306  Caption := 'TBitmap.Canvas.Pixels';
    232307end;
     
    245320{ TDrawMethod }
    246321
     322procedure TDrawMethod.SetBitmap(const AValue: TBitmap);
     323begin
     324  if FBitmap = AValue then exit;
     325  FBitmap := AValue;
     326  TempBitmap.SetSize(FBitmap.Width, FBitmap.Height);
     327end;
     328
     329procedure TDrawMethod.SetPaintBox(const AValue: TPaintBox);
     330begin
     331  if FPaintBox = AValue then Exit;
     332  FPaintBox := AValue;
     333end;
     334
    247335constructor TDrawMethod.Create;
    248336begin
    249 
     337  TempBitmap := TBitmap.Create;
     338end;
     339
     340destructor TDrawMethod.Destroy;
     341begin
     342  TempBitmap.Free;
     343  inherited Destroy;
    250344end;
    251345
     
    264358end;
    265359
    266 procedure TDrawMethod.DrawLoop;
    267 begin
    268 end;
    269 
    270360end.
    271361
  • GraphicTest/UMainForm.lfm

    r201 r202  
    11object MainForm: TMainForm
    2   Left = 291
     2  Left = 214
    33  Height = 452
    4   Top = 127
     4  Top = 106
    55  Width = 731
    66  Caption = 'Graphic test'
     
    5555  end
    5656  object Label1: TLabel
    57     Left = 11
     57    Left = 9
    5858    Height = 14
    5959    Top = 95
     
    8181  end
    8282  object Label3: TLabel
    83     Left = 11
     83    Left = 9
    8484    Height = 14
    8585    Top = 112
     
    131131    Height = 21
    132132    Top = 64
    133     Width = 233
     133    Width = 297
    134134    ItemHeight = 13
    135     Items.Strings = (
    136       'TBitmap.Canvas.Pixels'
    137       'TBitmap.Canvas.Pixels Update lock'
    138       'TLazIntfImage copy from'
    139       'TLazIntfImage create new'
    140       'TBitmap.RawData on TImage'
    141       'TBitmap.RawData on TPaintBox'
    142     )
    143135    Style = csDropDownList
    144136    TabOrder = 5
  • GraphicTest/UMainForm.pas

    r201 r202  
    4444  private
    4545  public
    46     DrawMethod: TDrawMethod;
     46    DrawMethods: TObjectList; // TObjectList<TDrawMethod>
    4747    Bitmap: TBitmap;
    4848    Scenes: TObjectList; // TObjectList<TFastBitmap>
     
    6262var
    6363  NewScene: TFastBitmap;
     64  NewDrawMethod: TDrawMethod;
    6465  I: Integer;
    6566begin
     
    7778  Image1.Picture.Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y);
    7879  Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y);
     80
     81  DrawMethods := TObjectList.Create;
     82  ComboBox1.Clear;
     83  for I := 0 to High(DrawMethodClasses) do begin
     84    NewDrawMethod := DrawMethodClasses[I].Create;
     85    NewDrawMethod.Bitmap := Image1.Picture.Bitmap;
     86    NewDrawMethod.PaintBox := PaintBox1;
     87    DrawMethods.Add(NewDrawMethod);
     88    ComboBox1.Items.Add(NewDrawMethod.Caption);
     89  end;
    7990  ComboBox1.ItemIndex := 0;
    8091end;
     
    8596  ButtonStart.Enabled := False;
    8697  Timer1.Enabled := True;
    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);
     98  if ComboBox1.ItemIndex >= 0 then
     99  with TDrawMethod(DrawMethods[ComboBox1.ItemIndex]) do begin
    92100    repeat
    93       DrawMethod.DrawFrameTiming(TFastBitmap(Scenes[SceneIndex]));
     101      DrawFrameTiming(TFastBitmap(Scenes[SceneIndex]));
    94102      SceneIndex := (SceneIndex + 1) mod Scenes.Count;
    95103      Application.ProcessMessages;
     
    108116    BeginUpdate;
    109117    Clear;
    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]));
     118    for I := 0 to DrawMethods.Count - 1 do
     119    with TDrawMethod(DrawMethods[I]) do begin
     120      DrawFrameTiming(TFastBitmap(Scenes[0]));
     121      DrawFrameTiming(TFastBitmap(Scenes[0]));
    116122      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)));
     123      NewItem.Caption := Caption;
     124      NewItem.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3)));
     125      NewItem.SubItems.Add(FloatToStr(RoundTo(1 / (FrameDuration / OneSecond), -3)));
    120126    end;
    121127  finally
     
    137143procedure TMainForm.FormDestroy(Sender: TObject);
    138144begin
     145  DrawMethods.Free;
    139146  Scenes.Free;
    140147  Bitmap.Free;
     
    143150procedure TMainForm.Timer1Timer(Sender: TObject);
    144151begin
    145   if Assigned(DrawMethod) then begin
    146     if (DrawMethod.FrameDuration > 0) then
    147       Label2.Caption := FloatToStr(RoundTo(1 / (DrawMethod.FrameDuration / OneSecond), -3))
     152  if (ComboBox1.ItemIndex >= 0) then
     153  with TDrawMethod(DrawMethods[ComboBox1.ItemIndex]) do begin
     154    if (FrameDuration > 0) then
     155      Label2.Caption := FloatToStr(RoundTo(1 / (FrameDuration / OneSecond), -3))
    148156      else Label2.Caption := '0';
    149     Label4.Caption := FloatToStr(RoundTo(DrawMethod.FrameDuration / OneMillisecond, -3)) + ' ms';
     157    Label4.Caption := FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3)) + ' ms';
    150158  end;
    151159end;
Note: See TracChangeset for help on using the changeset viewer.