Ignore:
Timestamp:
Nov 22, 2012, 2:32:10 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Each methods separated to own unit. Code from unit is displayed to user in main form after method selection.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/UDrawMethod.pas

    r443 r447  
    77uses
    88  Classes, SysUtils, ExtCtrls, UPlatform, UFastBitmap, Graphics, Controls,
    9   LCLType, IntfGraphics, fpImage, GraphType, BGRABitmap, BGRABitmapTypes,
     9  LCLType, IntfGraphics, fpImage, GraphType,
    1010  LclIntf{$IFDEF opengl}, GL, GLExt, OpenGLContext{$ENDIF};
    1111
     
    1919  private
    2020    FControl: TControl;
    21     TempBitmap: TBitmap;
    2221  public
    2322    Caption: string;
     23    Description: TStringList;
    2424    Terminated: Boolean;
    2525    FrameDuration: TDateTime;
    2626    StepDuration: TDateTime;
    2727    PaintObject: TPaintObject;
     28    TempBitmap: TBitmap;
    2829    procedure Init(Parent: TWinControl; Size: TPoint); virtual;
    2930    procedure Done; virtual;
     
    5253    procedure Init(Parent: TWinControl; Size: TPoint); override;
    5354    procedure Done; override;
    54   end;
    55 
    56   { TDummyMethod }
    57 
    58   TDummyMethod = class(TDrawMethod)
    59     constructor Create; override;
    60     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    61   end;
    62 
    63   { TCanvasPixels }
    64 
    65   TCanvasPixels = class(TDrawMethodImage)
    66     constructor Create; override;
    67     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    68   end;
    69 
    70   { TCanvasPixelsUpdateLock }
    71 
    72   TCanvasPixelsUpdateLock = class(TDrawMethodImage)
    73     constructor Create; override;
    74     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    75   end;
    76 
    77   { TLazIntfImageColorsCopy }
    78 
    79   TLazIntfImageColorsCopy = class(TDrawMethodImage)
    80     TempIntfImage: TLazIntfImage;
    81     constructor Create; override;
    82     destructor Destroy; override;
    83     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    84   end;
    85 
    86   { TLazIntfImageColorsNoCopy }
    87 
    88   TLazIntfImageColorsNoCopy = class(TDrawMethodImage)
    89     TempIntfImage: TLazIntfImage;
    90     procedure Init(Parent: TWinControl; Size: TPoint); override;
    91     constructor Create; override;
    92     destructor Destroy; override;
    93     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    94   end;
    95 
    96   { TBitmapRawImageData }
    97 
    98   TBitmapRawImageData = class(TDrawMethodImage)
    99     constructor Create; override;
    100     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    101   end;
    102 
    103   { TBitmapRawImageDataPaintBox }
    104 
    105   TBitmapRawImageDataPaintBox = class(TDrawMethodPaintBox)
    106     constructor Create; override;
    107     procedure Paint(Sender: TObject); override;
    108     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    109   end;
    110 
    111   { TBitmapRawImageDataMove }
    112 
    113   TBitmapRawImageDataMove = class(TDrawMethodImage)
    114     constructor Create; override;
    115     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    116   end;
    117 
    118   { TBGRABitmapPaintBox }
    119 
    120   TBGRABitmapPaintBox = class(TDrawMethodPaintBox)
    121     BGRABitmap: TBGRABitmap;
    122     procedure Paint(Sender: TObject); override;
    123     procedure Init(Parent: TWinControl; Size: TPoint); override;
    124     constructor Create; override;
    125     destructor Destroy; override;
    126     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    12755  end;
    12856
     
    14068  end;
    14169
    142   { TOpenGLMethod }
    143 
    144   TOpenGLMethod = class(TDrawMethodOpenGL)
    145     constructor Create; override;
    146     destructor Destroy; override;
    147     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    148   end;
    149 
    150   { TOpenGLPBOMethod }
    151 
    152   TOpenGLPBOMethod = class(TDrawMethodOpenGL)
    153     pboIds: array[0..1] of GLuint;
    154     Index, NextIndex: Integer;
    155     procedure Init(AParent: TWinControl; Size: TPoint); override;
    156     constructor Create; override;
    157     destructor Destroy; override;
    158     procedure DrawFrame(FastBitmap: TFastBitmap); override;
    159   end;
    16070  {$ENDIF}
    16171
    162 const
    163   DrawMethodClasses: array[0..{$IFDEF opengl}10{$ELSE}8{$ENDIF}] of TDrawMethodClass = (
    164     TCanvasPixels, TCanvasPixelsUpdateLock, TLazIntfImageColorsCopy,
    165     TLazIntfImageColorsNoCopy, TBitmapRawImageData, TBitmapRawImageDataPaintBox,
    166     TBitmapRawImageDataMove, TBGRABitmapPaintBox{$IFDEF opengl}, TOpenGLMethod, TOpenGLPBOMethod{$ENDIF}
    167     ,TDummyMethod);
    16872
    16973implementation
     
    212116end;
    213117
    214 { TDummyMethod }
    215 
    216 constructor TDummyMethod.Create;
    217 begin
    218   inherited Create;
    219   Caption := 'Dummy';
    220 end;
    221 
    222 procedure TDummyMethod.DrawFrame(FastBitmap: TFastBitmap);
    223 begin
    224 end;
    225 
    226 { TBitmapRawImageDataMove }
    227 
    228 constructor TBitmapRawImageDataMove.Create;
    229 begin
    230   inherited;
    231   Caption := 'TBitmap.RawImage.Data Move';
    232 end;
    233 
    234 procedure TBitmapRawImageDataMove.DrawFrame(FastBitmap: TFastBitmap);
    235 var
    236   Y, X: Integer;
    237   PixelPtr: PInteger;
    238   RowPtr: PInteger;
    239   P: TPixelFormat;
    240   RawImage: TRawImage;
    241   BytePerPixel: Integer;
    242   BytePerRow: Integer;
    243 begin
    244   P := Image.Picture.Bitmap.PixelFormat;
    245     with FastBitmap do
    246     try
    247       Image.Picture.Bitmap.BeginUpdate(False);
    248       RawImage := Image.Picture.Bitmap.RawImage;
    249       RowPtr := PInteger(RawImage.Data);
    250       BytePerPixel := RawImage.Description.BitsPerPixel div 8;
    251       BytePerRow := RawImage.Description.BytesPerLine;
    252       Move(FastBitmap.PixelsData^, RowPtr^, Size.Y * BytePerRow);
    253     finally
    254       Image.Picture.Bitmap.EndUpdate(False);
    255     end;
    256 end;
    257118
    258119{$IFDEF opengl}
    259 { TOpenGLPBOMethod }
    260 
    261 //procedure glGenBuffersARB2 : procedure(n : GLsizei; buffers : PGLuint); extdecl;
    262 
    263 procedure TOpenGLPBOMethod.Init(AParent: TWinControl; Size: TPoint);
    264 var
    265   DataSize: Integer;
    266   glExtensions: string;
    267 begin
    268   inherited;
    269 
    270   OpenGLControl.MakeCurrent;
    271   DataSize := OpenGLControl.Width * OpenGLControl.Height * SizeOf(Integer);
    272 //  glGenBuffersARB(Length(pboIds), PGLuint(pboIds));
    273   //if glext_LoadExtension('GL_ARB_pixel_buffer_object') then
    274   if Load_GL_ARB_vertex_buffer_object then begin
    275     glGenBuffersARB(2, @pboIds);
    276     glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[0]);
    277     glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, DataSize, Pointer(0), GL_STREAM_READ_ARB);
    278     glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[1]);
    279     glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, DataSize, Pointer(0), GL_STREAM_READ_ARB);
    280 
    281   end else raise Exception.Create('GL_ARB_pixel_buffer_object not supported');
    282 
    283   glEnable(GL_TEXTURE_2D);
    284   glBindTexture(GL_TEXTURE_2D, TextureId);
    285     //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    286     //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    287     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    288     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    289     glTexImage2D(GL_TEXTURE_2D, 0, 4, OpenGLControl.Width, OpenGLControl.Height,
    290       0, GL_RGBA, GL_UNSIGNED_BYTE, OpenGLBitmap);
    291 end;
    292 
    293 constructor TOpenGLPBOMethod.Create;
    294 begin
    295   inherited Create;
    296   Caption := 'OpenGL PBO';
    297   PaintObject := poOpenGL;
    298 //  SetLength(pboIds, 2);
    299   Index := 0;
    300   NextIndex := 1;
    301 end;
    302 
    303 destructor TOpenGLPBOMethod.Destroy;
    304 begin
    305   inherited Destroy;
    306 end;
    307 
    308 procedure TOpenGLPBOMethod.DrawFrame(FastBitmap: TFastBitmap);
    309 var
    310   X, Y: Integer;
    311   P: PCardinal;
    312   R: PCardinal;
    313   Ptr: ^GLubyte;
    314   TextureShift: TPoint;
    315   TextureShift2: TPoint;
    316 const
    317   GL_CLAMP_TO_EDGE = $812F;
    318 begin
    319   // "index" is used to read pixels from framebuffer to a PBO
    320   // "nextIndex" is used to update pixels in the other PBO
    321   Index := (Index + 1) mod 2;
    322   NextIndex := (Index + 1) mod 2;
    323 
    324   glLoadIdentity;
    325 
    326   glBindTexture(GL_TEXTURE_2D, TextureId);
    327     //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    328     //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    329     //glTexImage2D(GL_TEXTURE_2D, 0, 4, OpenGLControl.Width, OpenGLControl.Height,
    330     //  0, GL_RGBA, GL_UNSIGNED_BYTE, OpenGLBitmap);
    331     //glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 256,
    332     //0, GL_RGBA, GL_UNSIGNED_BYTE, OpenGLBitmap);
    333 
    334   // bind the texture and PBO
    335   //glBindTexture(GL_TEXTURE_2D, textureId);
    336   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[index]);
    337 
    338   // copy pixels from PBO to texture object
    339   // Use offset instead of ponter.
    340   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, OpenGLControl.Width, OpenGLControl.Height,
    341     GL_BGRA, GL_UNSIGNED_BYTE, Pointer(0));
    342 
    343 
    344   // bind PBO to update texture source
    345   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[nextIndex]);
    346 
    347   // Note that glMapBufferARB() causes sync issue.
    348   // If GPU is working with this buffer, glMapBufferARB() will wait(stall)
    349   // until GPU to finish its job. To avoid waiting (idle), you can call
    350   // first glBufferDataARB() with NULL pointer before glMapBufferARB().
    351   // If you do that, the previous data in PBO will be discarded and
    352   // glMapBufferARB() returns a new allocated pointer immediately
    353   // even if GPU is still working with the previous data.
    354   glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, OpenGLControl.Width * OpenGLControl.Height * SizeOf(Integer), Pointer(0), GL_STREAM_DRAW_ARB);
    355 
    356   // map the buffer object into client's memory
    357   ptr := glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
    358   if Assigned(ptr) then begin
    359     // update data directly on the mapped buffer
    360     P := PCardinal(Ptr);
    361     with FastBitmap do
    362     for Y := 0 to Size.Y - 2 do begin
    363       R := P;
    364       for X := 0 to Size.X - 1 do begin
    365         R^ := NoSwapBRComponent(Pixels[X, Y]) or $ff000000;
    366         Inc(R);
    367       end;
    368       Inc(P, Size.X);
    369     end;
    370     glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
    371   end;
    372 
    373   // it is good idea to release PBOs with ID 0 after use.
    374   // Once bound with 0, all pixel operations are back to normal ways.
    375   glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
    376 
    377   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
    378   //glRotatef(30.0, 0, 0, 1.0);
    379   glTranslatef(-OpenGLControl.Width / 2, -OpenGLControl.Height / 2, 0.0);
    380   glBindTexture(GL_TEXTURE_2D, TextureId);
    381 
    382   TextureShift := Point(0, 0);
    383   TextureShift2 := Point(0, 0);
    384   glBegin(GL_QUADS);
    385     glColor3ub(255, 255, 255);
    386     glTexCoord2f(TextureShift.X, TextureShift.Y);
    387     glVertex3f(TextureShift2.X, TextureShift2.Y, 0);
    388     glTexCoord2f(TextureShift.X + OpenGLControl.Width div 2, TextureShift.Y);
    389     glVertex3f(TextureShift2.X + OpenGLControl.Width, TextureShift2.Y, 0);
    390     glTexCoord2f(TextureShift.X + OpenGLControl.Width div 2, TextureShift.Y + OpenGLControl.Height div 2);
    391     glVertex3f(TextureShift2.X + OpenGLControl.Width, TextureShift2.Y + OpenGLControl.Height, 0);
    392     glTexCoord2f(TextureShift.X, TextureShift.Y + OpenGLControl.Height div 2);
    393     glVertex3f(TextureShift2.X, TextureShift2.Y + OpenGLControl.Height, 0);
    394   glEnd();
    395 
    396   OpenGLControl.SwapBuffers;
    397 end;
    398 
    399 { TOpenGLMethod }
    400 
    401 constructor TOpenGLMethod.Create;
    402 begin
    403   inherited Create;
    404   Caption := 'OpenGL';
    405   PaintObject := poOpenGL;
    406 end;
    407 
    408 destructor TOpenGLMethod.Destroy;
    409 begin
    410   inherited Destroy;
    411 end;
    412 
    413 procedure TOpenGLMethod.DrawFrame(FastBitmap: TFastBitmap);
    414 var
    415   X, Y: Integer;
    416   P: PCardinal;
    417   R: PCardinal;
    418 const
    419   GL_CLAMP_TO_EDGE = $812F;
    420 begin
    421   glLoadIdentity;
    422   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
    423   //glLoadIdentity;             { clear the matrix }
    424   //glTranslatef(0.0, 0.0, -3.0);  // -2.5); { viewing transformation }
    425 
    426   P := OpenGLBitmap;
    427   with FastBitmap do
    428   for Y := 0 to Size.Y - 1 do begin
    429     R := P;
    430     for X := 0 to Size.X - 1 do begin
    431       //R^ := Round($ff * (Y / Size.Y)) or $ff000000;
    432       R^  := NoSwapBRComponent(Pixels[X, Y]) or $ff000000;
    433       Inc(R);
    434     end;
    435     Inc(P, Size.X);
    436   end;
    437 
    438     //glRotatef(30.0, 0, 0, 1.0);
    439     glTranslatef(-OpenGLControl.Width div 2, -OpenGLControl.Height div 2, 0.0);
    440 
    441     glEnable(GL_TEXTURE_2D);
    442     glBindTexture(GL_TEXTURE_2D, TextureId);
    443       //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    444       //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    445       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    446       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    447       glTexImage2D(GL_TEXTURE_2D, 0, 4, OpenGLControl.Width, OpenGLControl.Height,
    448         0, GL_RGBA, GL_UNSIGNED_BYTE, OpenGLBitmap);
    449       //glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 256,
    450       //0, GL_RGBA, GL_UNSIGNED_BYTE, OpenGLBitmap);
    451 
    452     //Define how alpha blending will work and enable alpha blending.
    453     //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    454     //glEnable(GL_BLEND);
    455 
    456     glBegin(GL_QUADS);
    457     //glBegin(GL_POLYGON);
    458       glColor3ub(255, 255, 255);
    459       glTexCoord2f(0, 0);
    460       glVertex3f(0, 0, 0);
    461       glTexCoord2f(OpenGLControl.Width div 2, 0);
    462       glVertex3f(OpenGLControl.Width, 0, 0);
    463       glTexCoord2f(OpenGLControl.Width div 2, OpenGLControl.Height div 2);
    464       glVertex3f(OpenGLControl.Width, OpenGLControl.Height, 0);
    465       glTexCoord2f(0, OpenGLControl.Height div 2);
    466       glVertex3f(0, OpenGLControl.Height, 0);
    467     glEnd();
    468 
    469   OpenGLControl.SwapBuffers;
    470 end;
    471120
    472121{ TDrawMethodOpenGL }
     
    521170{$ENDIF}
    522171
    523 { TBGRABitmapPaintBox }
    524 
    525 procedure TBGRABitmapPaintBox.Paint(Sender: TObject);
    526 begin
    527   //BGRABitmap.Draw(Bitmap.Canvas, 0, 0, True);
    528   BGRABitmap.Draw(PaintBox.Canvas, 0, 0, True);
    529 end;
    530 
    531 procedure TBGRABitmapPaintBox.Init(Parent: TWinControl; Size: TPoint);
    532 begin
    533   inherited Init(Parent, Size);
    534   BGRABitmap.SetSize(PaintBox.Width, PaintBox.Height);
    535 end;
    536 
    537 constructor TBGRABitmapPaintBox.Create;
    538 begin
    539   inherited;
    540   Caption := 'TBGRABitmap PaintBox';
    541   BGRABitmap := TBGRABitmap.Create(0, 0);
    542   PaintObject := poPaintBox;
    543 end;
    544 
    545 destructor TBGRABitmapPaintBox.Destroy;
    546 begin
    547   BGRABitmap.Free;
    548   inherited Destroy;
    549 end;
    550 
    551 procedure TBGRABitmapPaintBox.DrawFrame(FastBitmap: TFastBitmap);
    552 var
    553   X, Y: Integer;
    554   P: PCardinal;
    555 begin
    556   with FastBitmap do
    557   for Y := 0 to Size.Y - 1 do begin
    558     P := PCardinal(BGRABitmap.ScanLine[Y]);
    559     for X := 0 to Size.X - 1 do begin
    560       P^ := NoSwapBRComponent(Pixels[X, Y]) or $ff000000;
    561       //P^ := Pixels[X, Y] or $ff000000;
    562       (*P^.red := Pixels[X, Y];
    563       P^.green := Pixels[X, Y];
    564       P^.blue := Pixels[X, Y];
    565       P^.alpha := 255; *)
    566       Inc(P);
    567     end;
    568   end;
    569   BGRABitmap.InvalidateBitmap; // changed by direct access
    570   PaintBox.Repaint;
    571 end;
    572 
    573 { TBitmapRawImageDataPaintBox }
    574 
    575 constructor TBitmapRawImageDataPaintBox.Create;
    576 begin
    577   inherited;
    578   Caption := 'TBitmap.RawImage.Data PaintBox';
    579   PaintObject := poPaintBox;
    580 end;
    581 
    582 procedure TBitmapRawImageDataPaintBox.Paint(Sender: TObject);
    583 var
    584   hPaint, hBmp: HDC;
    585 begin
    586   hBmp := TempBitmap.Canvas.Handle;
    587   hPaint := PaintBox.Canvas.Handle;
    588   PaintBox.Canvas.CopyRect(Rect(0, 0, PaintBox.Width, PaintBox.Height), TempBitmap.Canvas,
    589     Rect(0, 0, TempBitmap.Width, TempBitmap.Height));
    590  // PaintBox.Canvas.Draw(0, 0, TempBitmap);
    591   //BitBlt(hPaint, 0, 0, TempBitmap.Width, TempBitmap.Height, hBmp, 0, 0, srcCopy);
    592 end;
    593 
    594 procedure TBitmapRawImageDataPaintBox.DrawFrame(FastBitmap: TFastBitmap);
    595 var
    596   Y, X: Integer;
    597   PixelPtr: PCardinal;
    598   RowPtr: PCardinal;
    599   P: TPixelFormat;
    600   RawImage: TRawImage;
    601   BytePerPixel: Integer;
    602   BytePerRow: Integer;
    603 begin
    604   P := TempBitmap.PixelFormat;
    605     with FastBitmap do
    606     try
    607       TempBitmap.BeginUpdate(False);
    608       RawImage := TempBitmap.RawImage;
    609       RowPtr := PCardinal(RawImage.Data);
    610       BytePerPixel := RawImage.Description.BitsPerPixel div 8;
    611       BytePerRow := RawImage.Description.BytesPerLine;
    612       for Y := 0 to Size.Y - 1 do begin
    613         PixelPtr := RowPtr;
    614         for X := 0 to Size.X - 1 do begin
    615           PixelPtr^ := Pixels[X, Y];
    616           Inc(PByte(PixelPtr), BytePerPixel);
    617         end;
    618         Inc(PByte(RowPtr), BytePerRow);
    619       end;
    620     finally
    621       TempBitmap.EndUpdate(False);
    622     end;
    623   PaintBox.Repaint;
    624 end;
    625 
    626 { TBitmapRawImageData }
    627 
    628 constructor TBitmapRawImageData.Create;
    629 begin
    630   inherited;
    631   Caption := 'TBitmap.RawImage.Data';
    632 end;
    633 
    634 procedure TBitmapRawImageData.DrawFrame(FastBitmap: TFastBitmap);
    635 var
    636   Y, X: Integer;
    637   PixelPtr: PCardinal;
    638   RowPtr: PCardinal;
    639   P: TPixelFormat;
    640   RawImage: TRawImage;
    641   BytePerPixel: Integer;
    642   BytePerRow: Integer;
    643 begin
    644   P := Image.Picture.Bitmap.PixelFormat;
    645     with FastBitmap do
    646     try
    647       Image.Picture.Bitmap.BeginUpdate(False);
    648       RawImage := Image.Picture.Bitmap.RawImage;
    649       RowPtr := PCardinal(RawImage.Data);
    650       BytePerPixel := RawImage.Description.BitsPerPixel div 8;
    651       BytePerRow := RawImage.Description.BytesPerLine;
    652       for Y := 0 to Size.Y - 1 do begin
    653         PixelPtr := RowPtr;
    654         for X := 0 to Size.X - 1 do begin
    655           PixelPtr^ := Pixels[X, Y];
    656           Inc(PByte(PixelPtr), BytePerPixel);
    657         end;
    658         Inc(PByte(RowPtr), BytePerRow);
    659       end;
    660     finally
    661       Image.Picture.Bitmap.EndUpdate(False);
    662     end;
    663 end;
    664 
    665 { TLazIntfImageColorsNoCopy }
    666 
    667 procedure TLazIntfImageColorsNoCopy.Init(Parent: TWinControl; Size: TPoint);
    668 begin
    669   inherited Init(Parent, Size);
    670   TempIntfImage.Free;
    671   TempIntfImage := Image.Picture.Bitmap.CreateIntfImage;
    672 end;
    673 
    674 constructor TLazIntfImageColorsNoCopy.Create;
    675 begin
    676   inherited;
    677   Caption := 'TLazIntfImage.Colors no copy';
    678 end;
    679 
    680 destructor TLazIntfImageColorsNoCopy.Destroy;
    681 begin
    682   TempIntfImage.Free;
    683   inherited Destroy;
    684 end;
    685 
    686 procedure TLazIntfImageColorsNoCopy.DrawFrame(FastBitmap: TFastBitmap);
    687 var
    688   Y, X: Integer;
    689 begin
    690   with FastBitmap do begin
    691     for X := 0 to Size.X - 1 do
    692       for Y := 0 to Size.Y - 1 do
    693         TempIntfImage.Colors[X, Y] := TColorToFPColor(SwapBRComponent(Pixels[X, Y]));
    694     Image.Picture.Bitmap.LoadFromIntfImage(TempIntfImage);
    695   end;
    696 end;
    697 
    698 { TLazIntfImageColorsCopy }
    699 
    700 constructor TLazIntfImageColorsCopy.Create;
    701 begin
    702   inherited;
    703   Caption := 'TLazIntfImage.Colors copy';
    704   TempIntfImage := TLazIntfImage.Create(0, 0);
    705 end;
    706 
    707 destructor TLazIntfImageColorsCopy.Destroy;
    708 begin
    709   TempIntfImage.Free;
    710   inherited Destroy;
    711 end;
    712 
    713 procedure TLazIntfImageColorsCopy.DrawFrame(FastBitmap: TFastBitmap);
    714 var
    715   Y, X: Integer;
    716 begin
    717   with FastBitmap do begin
    718     TempIntfImage.LoadFromBitmap(Image.Picture.Bitmap.Handle,
    719       Image.Picture.Bitmap.MaskHandle);
    720     for X := 0 to Size.X - 1 do
    721       for Y := 0 to Size.Y - 1 do
    722         TempIntfImage.Colors[X, Y] := TColorToFPColor(SwapBRComponent(Pixels[X, Y]));
    723     Image.Picture.Bitmap.LoadFromIntfImage(TempIntfImage);
    724   end;
    725 end;
    726 
    727 { TCanvasPixelsUpdateLock }
    728 
    729 constructor TCanvasPixelsUpdateLock.Create;
    730 begin
    731   inherited;
    732   Caption := 'TBitmap.Canvas.Pixels Update locking';
    733 end;
    734 
    735 procedure TCanvasPixelsUpdateLock.DrawFrame(FastBitmap: TFastBitmap);
    736 var
    737   Y, X: Integer;
    738 begin
    739   with FastBitmap do
    740   try
    741     Image.Picture.Bitmap.BeginUpdate(True);
    742     for Y := 0 to Size.Y - 1 do
    743       for X := 0 to Size.X - 1 do
    744         Image.Picture.Bitmap.Canvas.Pixels[X, Y] := TColor(SwapBRComponent(Pixels[X, Y]));
    745   finally
    746     Image.Picture.Bitmap.EndUpdate(False);
    747   end;
    748 end;
    749 
    750 { TCanvasPixels }
    751 
    752 constructor TCanvasPixels.Create;
    753 begin
    754   inherited;
    755   Caption := 'TBitmap.Canvas.Pixels';
    756 end;
    757 
    758 procedure TCanvasPixels.DrawFrame(FastBitmap: TFastBitmap);
    759 var
    760   Y, X: Integer;
    761 begin
    762   with FastBitmap do begin
    763     for Y := 0 to Size.Y - 1 do
    764       for X := 0 to Size.X - 1 do
    765         Image.Picture.Bitmap.Canvas.Pixels[X, Y] := TColor(SwapBRComponent(Pixels[X, Y]));
    766   end;
    767 end;
    768172
    769173{ TDrawMethod }
     
    783187begin
    784188  TempBitmap := TBitmap.Create;
     189  Description := TStringList.Create;
    785190end;
    786191
    787192destructor TDrawMethod.Destroy;
    788193begin
     194  FreeAndNil(Description);
    789195  FreeAndNil(TempBitmap);
    790196  inherited Destroy;
Note: See TracChangeset for help on using the changeset viewer.