Changeset 206 for GraphicTest/UFastBitmap.pas
- Timestamp:
- Mar 18, 2011, 9:34:42 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/UFastBitmap.pas
r201 r206 6 6 7 7 uses 8 Classes, SysUtils ;8 Classes, SysUtils, Dialogs; 9 9 10 10 type 11 TFastBitmapPixel = Integer; 12 PFastBitmapPixel = ^TFastBitmapPixel; 13 14 TFastBitmapPixelComponents = packed record 15 B, G, R, A: Byte; 16 end; 17 11 18 { TFastBitmap } 12 19 13 20 TFastBitmap = class 14 21 private 22 FPixelsData: PByte; 23 FSize: TPoint; 24 function GetPixel(X, Y: Integer): TFastBitmapPixel; inline; 25 procedure SetPixel(X, Y: Integer; const AValue: TFastBitmapPixel); inline; 26 procedure SetSize(const AValue: TPoint); 27 public 28 constructor Create; 29 destructor Destroy; override; 30 procedure RandomImage; 31 property Size: TPoint read FSize write SetSize; 32 property Pixels[X, Y: Integer]: TFastBitmapPixel read GetPixel write SetPixel; 33 end; 34 35 TFastBitmap2 = class 36 private 15 37 function GetSize: TPoint; 16 38 procedure SetSize(const AValue: TPoint); 17 39 public 18 Pixels: array of array of Byte;40 Pixels: array of array of TFastBitmapPixel; 19 41 procedure RandomImage; 20 42 property Size: TPoint read GetSize write SetSize; 21 43 end; 22 44 45 function SwapBRComponent(Value: Integer): Integer; inline; 46 function NoSwapBRComponent(Value: Integer): Integer; inline; 47 23 48 implementation 24 49 25 { TFastBitmap } 50 function SwapBRComponent(Value: Integer): Integer; 51 begin 52 // Result := (Value and $00ff00) or ((Value shr 16) and $ff) or ((Value and $ff) shl 16); 53 Result := Value; 54 TFastBitmapPixelComponents(Result).R := TFastBitmapPixelComponents(Value).B; 55 TFastBitmapPixelComponents(Result).B := TFastBitmapPixelComponents(Value).R; 56 end; 26 57 27 function TFastBitmap.GetSize: TPoint; 58 function NoSwapBRComponent(Value: Integer): Integer; 59 begin 60 // Result := (Value and $00ff00) or ((Value shr 16) and $ff) or ((Value and $ff) shl 16); 61 Result := Value; 62 TFastBitmapPixelComponents(Result).B := TFastBitmapPixelComponents(Value).B; 63 TFastBitmapPixelComponents(Result).R := TFastBitmapPixelComponents(Value).R; 64 end; 65 66 { TFastBitmap2 } 67 68 function TFastBitmap2.GetSize: TPoint; 28 69 begin 29 70 Result.X := Length(Pixels); … … 32 73 end; 33 74 34 procedure TFastBitmap .SetSize(const AValue: TPoint);75 procedure TFastBitmap2.SetSize(const AValue: TPoint); 35 76 begin 36 77 SetLength(Pixels, AValue.X, AValue.Y); 37 78 end; 38 79 39 procedure TFastBitmap .RandomImage;80 procedure TFastBitmap2.RandomImage; 40 81 var 41 82 X, Y: Integer; … … 46 87 end; 47 88 89 { TFastBitmap } 90 91 function TFastBitmap.GetPixel(X, Y: Integer): TFastBitmapPixel; 92 begin 93 Result := PFastBitmapPixel(FPixelsData + (Y * FSize.X + X) * SizeOf(TFastBitmapPixel))^; 94 end; 95 96 procedure TFastBitmap.SetPixel(X, Y: Integer; const AValue: TFastBitmapPixel); 97 begin 98 PFastBitmapPixel(FPixelsData + (Y * FSize.X + X) * SizeOf(TFastBitmapPixel))^ := AValue; 99 end; 100 101 procedure TFastBitmap.SetSize(const AValue: TPoint); 102 begin 103 if (FSize.X = AValue.X) and (FSize.Y = AValue.X) then Exit; 104 FSize := AValue; 105 FPixelsData := ReAllocMem(FPixelsData, FSize.X * FSize.Y * SizeOf(TFastBitmapPixel)); 106 end; 107 108 constructor TFastBitmap.Create; 109 begin 110 Size := Point(0, 0); 111 end; 112 113 destructor TFastBitmap.Destroy; 114 begin 115 FreeMem(FPixelsData); 116 inherited Destroy; 117 end; 118 119 procedure TFastBitmap.RandomImage; 120 var 121 I, X, Y: Integer; 122 begin 123 for I := 0 to 2 do 124 for Y := 0 to (Size.Y div 2) - 1 do 125 for X := 0 to (Size.X div 3) - 1 do 126 Pixels[X + (I * (Size.X div 3)), Y] := 255 shl (I * 8); 127 128 for Y := (Size.Y div 2) to Size.Y - 1 do 129 for X := 0 to Size.X - 1 do 130 Pixels[X, Y] := Random(256) or (Random(256) shl 16) or (Random(256) shl 8); 131 end; 132 48 133 49 134 end.
Note:
See TracChangeset
for help on using the changeset viewer.