Changeset 202 for GraphicTest/UDrawMethod.pas
- Timestamp:
- Mar 17, 2011, 9:38:21 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/UDrawMethod.pas
r201 r202 6 6 7 7 uses 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; 10 11 11 12 type … … 14 15 15 16 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); 16 23 public 17 24 Caption: string; 18 25 Terminated: Boolean; 19 Bitmap: TBitmap;20 26 FrameDuration: TDateTime; 21 27 constructor Create; virtual; 28 destructor Destroy; override; 22 29 procedure DrawFrame(FastBitmap: TFastBitmap); virtual; 23 30 procedure DrawFrameTiming(FastBitmap: TFastBitmap); 24 procedure DrawLoop; 31 property Bitmap: TBitmap read FBitmap write SetBitmap; 32 property PaintBox: TPaintBox read FPaintBox write SetPaintBox; 25 33 end; 26 34 … … 54 62 TLazIntfImageColorsNoCopy = class(TDrawMethod) 55 63 TempIntfImage: TLazIntfImage; 64 procedure SetBitmap(const AValue: TBitmap); override; 56 65 constructor Create; override; 57 66 destructor Destroy; override; … … 73 82 end; 74 83 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 75 94 const 76 DrawMethodClasses: array[0.. 5] of TDrawMethodClass = (95 DrawMethodClasses: array[0..6] of TDrawMethodClass = ( 77 96 TCanvasPixels, TCanvasPixelsUpdateLock, TLazIntfImageColorsCopy, 78 TLazIntfImageColorsNoCopy, TBitmapRawImageData, TBitmapRawImageDataPaintBox); 97 TLazIntfImageColorsNoCopy, TBitmapRawImageData, TBitmapRawImageDataPaintBox, 98 TBGRABitmapPaintBox); 79 99 80 100 implementation 81 101 102 { TBGRABitmapPaintBox } 103 104 procedure TBGRABitmapPaintBox.SetBitmap(const AValue: TBitmap); 105 begin 106 inherited; 107 BGRABitmap.SetSize(Bitmap.Width, Bitmap.Height); 108 end; 109 110 constructor TBGRABitmapPaintBox.Create; 111 begin 112 inherited; 113 Caption := 'TBGRABitmap PaintBox'; 114 BGRABitmap := TBGRABitmap.Create(0, 0); 115 end; 116 117 destructor TBGRABitmapPaintBox.Destroy; 118 begin 119 BGRABitmap.Free; 120 inherited Destroy; 121 end; 122 123 procedure TBGRABitmapPaintBox.DrawFrame(FastBitmap: TFastBitmap); 124 var 125 X, Y: Integer; 126 P: PBGRAPixel; 127 begin 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); 142 end; 143 82 144 { TBitmapRawImageDataPaintBox } 83 145 84 146 constructor TBitmapRawImageDataPaintBox.Create; 85 147 begin 148 inherited; 86 149 Caption := 'TBitmap.RawImage.Data PaintBox'; 87 150 end; … … 95 158 BytePerPixel: Integer; 96 159 hPaint, hBmp: HDC; 160 begin 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); 181 end; 182 183 { TBitmapRawImageData } 184 185 constructor TBitmapRawImageData.Create; 186 begin 187 inherited; 188 Caption := 'TBitmap.RawImage.Data'; 189 end; 190 191 procedure TBitmapRawImageData.DrawFrame(FastBitmap: TFastBitmap); 192 var 193 Y, X: Integer; 194 PixelPtr: PInteger; 195 P: TPixelFormat; 196 RawImage: TRawImage; 197 BytePerPixel: Integer; 97 198 begin 98 199 P := Bitmap.PixelFormat; … … 111 212 Bitmap.EndUpdate(False); 112 213 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 begin122 Caption := 'TBitmap.RawImage.Data';123 end;124 125 procedure TBitmapRawImageData.DrawFrame(FastBitmap: TFastBitmap);126 var127 Y, X: Integer;128 PixelPtr: PInteger;129 P: TPixelFormat;130 RawImage: TRawImage;131 BytePerPixel: Integer;132 begin133 P := Bitmap.PixelFormat;134 with FastBitmap do135 try136 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 do141 for Y := 0 to Size.Y - 1 do begin142 PixelPtr^ := Pixels[X, Y] * $010101;143 Inc(PByte(PixelPtr), BytePerPixel);144 end;145 finally146 Bitmap.EndUpdate(False);147 end;148 214 end; 149 215 150 216 { TLazIntfImageColorsNoCopy } 151 217 218 procedure TLazIntfImageColorsNoCopy.SetBitmap(const AValue: TBitmap); 219 begin 220 inherited SetBitmap(AValue); 221 TempIntfImage.Free; 222 TempIntfImage := Bitmap.CreateIntfImage; 223 end; 224 152 225 constructor TLazIntfImageColorsNoCopy.Create; 153 226 begin 227 inherited; 154 228 Caption := 'TLazIntfImage.Colors no copy'; 155 229 end; … … 166 240 begin 167 241 with FastBitmap do begin 168 if not Assigned(TempIntfImage) then169 TempIntfImage := Bitmap.CreateIntfImage;170 242 for X := 0 to Size.X - 1 do 171 243 for Y := 0 to Size.Y - 1 do … … 179 251 constructor TLazIntfImageColorsCopy.Create; 180 252 begin 253 inherited; 181 254 Caption := 'TLazIntfImage.Colors copy'; 182 255 TempIntfImage := TLazIntfImage.Create(0, 0); … … 207 280 constructor TCanvasPixelsUpdateLock.Create; 208 281 begin 282 inherited; 209 283 Caption := 'TBitmap.Canvas.Pixels Update locking'; 210 284 end; … … 229 303 constructor TCanvasPixels.Create; 230 304 begin 305 inherited; 231 306 Caption := 'TBitmap.Canvas.Pixels'; 232 307 end; … … 245 320 { TDrawMethod } 246 321 322 procedure TDrawMethod.SetBitmap(const AValue: TBitmap); 323 begin 324 if FBitmap = AValue then exit; 325 FBitmap := AValue; 326 TempBitmap.SetSize(FBitmap.Width, FBitmap.Height); 327 end; 328 329 procedure TDrawMethod.SetPaintBox(const AValue: TPaintBox); 330 begin 331 if FPaintBox = AValue then Exit; 332 FPaintBox := AValue; 333 end; 334 247 335 constructor TDrawMethod.Create; 248 336 begin 249 337 TempBitmap := TBitmap.Create; 338 end; 339 340 destructor TDrawMethod.Destroy; 341 begin 342 TempBitmap.Free; 343 inherited Destroy; 250 344 end; 251 345 … … 264 358 end; 265 359 266 procedure TDrawMethod.DrawLoop;267 begin268 end;269 270 360 end. 271 361
Note:
See TracChangeset
for help on using the changeset viewer.