Ignore:
Timestamp:
Mar 17, 2011, 9:38:21 AM (14 years ago)
Author:
george
Message:
  • Added: TBGRABitmap.ScanLine method.
  • Modified: All draw methods objects are allocated on program creation now.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.