Ignore:
Timestamp:
Mar 20, 2011, 7:18:27 PM (14 years ago)
Author:
george
Message:
  • Added: OpenGL PBO method.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/UFastBitmap.pas

    r206 r212  
    3333  end;
    3434
     35  { TFastBitmap3 }
     36
     37  TFastBitmap3 = class
     38  private
     39    FPixelsData: PByte;
     40    FSize: TPoint;
     41    procedure SetSize(const AValue: TPoint);
     42  public
     43    constructor Create;
     44    destructor Destroy; override;
     45    procedure RandomImage;
     46    property Size: TPoint read FSize write SetSize;
     47    function GetPixelAddress(X, Y: Integer): PFastBitmapPixel; inline;
     48    function GetPixelSize: Integer; inline;
     49  end;
     50
    3551  TFastBitmap2 = class
    3652  private
     
    6480end;
    6581
     82{ TFastBitmap3 }
     83
     84procedure TFastBitmap3.SetSize(const AValue: TPoint);
     85begin
     86  if (FSize.X = AValue.X) and (FSize.Y = AValue.X) then Exit;
     87  FSize := AValue;
     88  FPixelsData := ReAllocMem(FPixelsData, FSize.X * FSize.Y * SizeOf(TFastBitmapPixel));
     89end;
     90
     91constructor TFastBitmap3.Create;
     92begin
     93
     94end;
     95
     96destructor TFastBitmap3.Destroy;
     97begin
     98  inherited Destroy;
     99end;
     100
     101procedure TFastBitmap3.RandomImage;
     102var
     103  I, X, Y: Integer;
     104  PRow: PFastBitmapPixel;
     105  PPixel: PFastBitmapPixel;
     106begin
     107  for I := 0 to 2 do begin
     108    PRow := GetPixelAddress(I * (Size.X div 3), 0);
     109    for Y := 0 to (Size.Y div 2) - 1 do begin
     110      PPixel := PRow;
     111      for X := 0 to (Size.X div 3) - 1 do begin
     112        PPixel^ := 255 shl (I * 8);
     113        Inc(PPixel);
     114      end;
     115      Inc(PRow, Size.X);
     116    end;
     117  end;
     118
     119  PRow := GetPixelAddress(0, Size.Y div 2);
     120  for Y := (Size.Y div 2) to Size.Y - 1 do begin
     121    PPixel := PRow;
     122    for X := 0 to Size.X - 1 do begin
     123      PPixel^ := Random(256) or (Random(256) shl 16) or (Random(256) shl 8);
     124      Inc(PPixel);
     125    end;
     126    Inc(PRow, Size.X);
     127  end;
     128end;
     129
     130function TFastBitmap3.GetPixelAddress(X, Y: Integer): PFastBitmapPixel;
     131begin
     132  Result := PFastBitmapPixel(FPixelsData) + Y * FSize.X + X;
     133end;
     134
     135function TFastBitmap3.GetPixelSize: Integer;
     136begin
     137  Result := SizeOf(TFastBitmapPixel);
     138end;
     139
    66140{ TFastBitmap2 }
    67141
Note: See TracChangeset for help on using the changeset viewer.