Ignore:
Timestamp:
Mar 18, 2011, 9:34:42 AM (13 years ago)
Author:
george
Message:
  • Fixed: Red and Blue color components swaping.
  • Fixed: PageControl tabs auto switching.
  • Modified: TFastBitmap class replaced by similar one which use pixels data as one memory block instead of array of arrays. With only one memory block optimization using FillChar and Move can be used.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/UFastBitmap.pas

    r201 r206  
    66
    77uses
    8   Classes, SysUtils;
     8  Classes, SysUtils, Dialogs;
    99
    1010type
     11 TFastBitmapPixel = Integer;
     12 PFastBitmapPixel = ^TFastBitmapPixel;
     13
     14 TFastBitmapPixelComponents = packed record
     15   B, G, R, A: Byte;
     16 end;
     17
    1118 { TFastBitmap }
    1219
    1320  TFastBitmap = class
    1421  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
    1537    function GetSize: TPoint;
    1638    procedure SetSize(const AValue: TPoint);
    1739  public
    18     Pixels: array of array of Byte;
     40    Pixels: array of array of TFastBitmapPixel;
    1941    procedure RandomImage;
    2042    property Size: TPoint read GetSize write SetSize;
    2143  end;
    2244
     45function SwapBRComponent(Value: Integer): Integer; inline;
     46function NoSwapBRComponent(Value: Integer): Integer; inline;
     47
    2348implementation
    2449
    25 { TFastBitmap }
     50function SwapBRComponent(Value: Integer): Integer;
     51begin
     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;
     56end;
    2657
    27 function TFastBitmap.GetSize: TPoint;
     58function NoSwapBRComponent(Value: Integer): Integer;
     59begin
     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;
     64end;
     65
     66{ TFastBitmap2 }
     67
     68function TFastBitmap2.GetSize: TPoint;
    2869begin
    2970  Result.X := Length(Pixels);
     
    3273end;
    3374
    34 procedure TFastBitmap.SetSize(const AValue: TPoint);
     75procedure TFastBitmap2.SetSize(const AValue: TPoint);
    3576begin
    3677  SetLength(Pixels, AValue.X, AValue.Y);
    3778end;
    3879
    39 procedure TFastBitmap.RandomImage;
     80procedure TFastBitmap2.RandomImage;
    4081var
    4182  X, Y: Integer;
     
    4687end;
    4788
     89{ TFastBitmap }
     90
     91function TFastBitmap.GetPixel(X, Y: Integer): TFastBitmapPixel;
     92begin
     93  Result := PFastBitmapPixel(FPixelsData + (Y * FSize.X + X) * SizeOf(TFastBitmapPixel))^;
     94end;
     95
     96procedure TFastBitmap.SetPixel(X, Y: Integer; const AValue: TFastBitmapPixel);
     97begin
     98  PFastBitmapPixel(FPixelsData + (Y * FSize.X + X) * SizeOf(TFastBitmapPixel))^ := AValue;
     99end;
     100
     101procedure TFastBitmap.SetSize(const AValue: TPoint);
     102begin
     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));
     106end;
     107
     108constructor TFastBitmap.Create;
     109begin
     110  Size := Point(0, 0);
     111end;
     112
     113destructor TFastBitmap.Destroy;
     114begin
     115  FreeMem(FPixelsData);
     116  inherited Destroy;
     117end;
     118
     119procedure TFastBitmap.RandomImage;
     120var
     121  I, X, Y: Integer;
     122begin
     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);
     131end;
     132
    48133
    49134end.
Note: See TracChangeset for help on using the changeset viewer.