Changeset 442 for GraphicTest


Ignore:
Timestamp:
Nov 22, 2012, 9:37:20 AM (12 years ago)
Author:
chronos
Message:
  • Modified: OpenGL methods could be disabled by compiler define opengl.
  • Fixed: Range check error in pixel assignment. Type Cardinal used instead of type Integer.
Location:
GraphicTest
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest

    • Property svn:ignore
      •  

        old new  
        77GraphicTest.rc
        88GraphicTest.lps
         9GraphicTest.dbg
  • GraphicTest/GraphicTest.lpi

    r356 r442  
    129129    </CodeGeneration>
    130130    <Linking>
     131      <Debugging>
     132        <UseHeaptrc Value="True"/>
     133        <UseExternalDbgSyms Value="True"/>
     134      </Debugging>
    131135      <Options>
    132136        <Win32>
  • GraphicTest/UDrawMethod.pas

    r356 r442  
    11unit UDrawMethod;
    22
    3 {$mode objfpc}{$H+}
     3{$mode delphi}{$H+}
    44
    55interface
    66
    77uses
    8   Classes, SysUtils, StdCtrls, ExtCtrls, UPlatform, UFastBitmap, Graphics,
     8  Classes, SysUtils, ExtCtrls, UPlatform, UFastBitmap, Graphics,
    99  LCLType, IntfGraphics, fpImage, GraphType, BGRABitmap, BGRABitmapTypes,
    10   LclIntf, GL, GLExt, OpenGLContext;
     10  LclIntf{$IFDEF opengl}, GL, GLExt, OpenGLContext{$ENDIF};
    1111
    1212type
     
    2929    StepDuration: TDateTime;
    3030    PaintObject: TPaintObject;
     31    {$IFDEF opengl}
    3132    OpenGLBitmap: Pointer;
    3233    OpenGLControl: TOpenGLControl;
    3334    TextureId: GLuint;
     35    {$ENDIF}
    3436    procedure Init; virtual;
    3537    constructor Create; virtual;
     
    114116  end;
    115117
     118  {$IFDEF opengl}
    116119  { TOpenGLMethod }
    117120
     
    135138    procedure DrawFrame(FastBitmap: TFastBitmap); override;
    136139  end;
     140  {$ENDIF}
    137141
    138142const
    139   DrawMethodClasses: array[0..10] of TDrawMethodClass = (
     143  DrawMethodClasses: array[0..{$IFDEF opengl}10{$ELSE}8{$ENDIF}] of TDrawMethodClass = (
    140144    TCanvasPixels, TCanvasPixelsUpdateLock, TLazIntfImageColorsCopy,
    141145    TLazIntfImageColorsNoCopy, TBitmapRawImageData, TBitmapRawImageDataPaintBox,
    142     TBitmapRawImageDataMove, TBGRABitmapPaintBox, TOpenGLMethod, TOpenGLPBOMethod,
    143     TDummyMethod);
     146    TBitmapRawImageDataMove, TBGRABitmapPaintBox{$IFDEF opengl}, TOpenGLMethod, TOpenGLPBOMethod{$ENDIF}
     147    ,TDummyMethod);
    144148
    145149implementation
     
    208212end;
    209213
     214{$IFDEF opengl}
    210215{ TOpenGLPBOMethod }
    211216
     
    435440end;
    436441
     442{$ENDIF}
     443
    437444{ TBGRABitmapPaintBox }
    438445
     
    460467var
    461468  X, Y: Integer;
    462   P: PInteger;
     469  P: PCardinal;
    463470begin
    464471  with FastBitmap do
    465472  for Y := 0 to Size.Y - 1 do begin
    466     P := PInteger(BGRABitmap.ScanLine[Y]);
     473    P := PCardinal(BGRABitmap.ScanLine[Y]);
    467474    for X := 0 to Size.X - 1 do begin
    468475      P^ := NoSwapBRComponent(Pixels[X, Y]) or $ff000000;
     
    492499var
    493500  Y, X: Integer;
    494   PixelPtr: PInteger;
    495   RowPtr: PInteger;
     501  PixelPtr: PCardinal;
     502  RowPtr: PCardinal;
    496503  P: TPixelFormat;
    497504  RawImage: TRawImage;
     
    505512      TempBitmap.BeginUpdate(False);
    506513      RawImage := TempBitmap.RawImage;
    507       RowPtr := PInteger(RawImage.Data);
     514      RowPtr := PCardinal(RawImage.Data);
    508515      BytePerPixel := RawImage.Description.BitsPerPixel div 8;
    509516      BytePerRow := RawImage.Description.BytesPerLine;
     
    538545var
    539546  Y, X: Integer;
    540   PixelPtr: PInteger;
    541   RowPtr: PInteger;
     547  PixelPtr: PCardinal;
     548  RowPtr: PCardinal;
    542549  P: TPixelFormat;
    543550  RawImage: TRawImage;
     
    550557      Bitmap.BeginUpdate(False);
    551558      RawImage := Bitmap.RawImage;
    552       RowPtr := PInteger(RawImage.Data);
     559      RowPtr := PCardinal(RawImage.Data);
    553560      BytePerPixel := RawImage.Description.BitsPerPixel div 8;
    554561      BytePerRow := RawImage.Description.BytesPerLine;
     
    643650  try
    644651    Bitmap.BeginUpdate(True);
    645     for X := 0 to Size.X - 1 do
    646       for Y := 0 to Size.Y - 1 do
    647         Bitmap.Canvas.Pixels[X, Y] := SwapBRComponent(Pixels[X, Y]);
     652    for Y := 0 to Size.Y - 1 do
     653      for X := 0 to Size.X - 1 do
     654        Bitmap.Canvas.Pixels[X, Y] := TColor(SwapBRComponent(Pixels[X, Y]));
    648655  finally
    649656    Bitmap.EndUpdate(False);
     
    664671begin
    665672  with FastBitmap do begin
    666     for X := 0 to Size.X - 1 do
    667       for Y := 0 to Size.Y - 1 do
    668         Bitmap.Canvas.Pixels[X, Y] := SwapBRComponent(Pixels[X, Y]);
     673    for Y := 0 to Size.Y - 1 do
     674      for X := 0 to Size.X - 1 do
     675        Bitmap.Canvas.Pixels[X, Y] := TColor(SwapBRComponent(Pixels[X, Y]));
    669676  end;
    670677end;
  • GraphicTest/UFastBitmap.pas

    r356 r442  
    1010type
    1111
    12   TFastBitmapPixel = Integer;
     12  TFastBitmapPixel = Cardinal;
    1313  (*TFastBitmapPixel = record
    1414    Blue: Byte;
     
    7070  end;
    7171
    72 function SwapBRComponent(Value: Integer): Integer; inline;
    73 function NoSwapBRComponent(Value: Integer): Integer; inline;
     72function SwapBRComponent(Value: Cardinal): Cardinal; inline;
     73function NoSwapBRComponent(Value: Cardinal): Cardinal; inline;
    7474
    7575implementation
    7676
    77 function SwapBRComponent(Value: Integer): Integer;
     77function SwapBRComponent(Value: Cardinal): Cardinal;
    7878begin
    7979//  Result := (Value and $00ff00) or ((Value shr 16) and $ff) or ((Value and $ff) shl 16);
     
    8383end;
    8484
    85 function NoSwapBRComponent(Value: Integer): Integer;
     85function NoSwapBRComponent(Value: Cardinal): Cardinal;
    8686begin
    8787//  Result := (Value and $00ff00) or ((Value shr 16) and $ff) or ((Value and $ff) shl 16);
     
    211211    for Y := 0 to (Size.Y div 2) - 1 do
    212212      for X := 0 to (Size.X div 3) - 1 do
    213         Pixels[X + (I * (Size.X div 3)), Y] := 255 shl (I * 8);
     213        Pixels[X + (I * (Size.X div 3)), Y] := (255 shl (I * 8)) and $ffffff;
    214214
    215215  for Y := (Size.Y div 2) to Size.Y - 1 do
    216216    for X := 0 to Size.X - 1 do
    217       Pixels[X, Y] := Random(256) or (Random(256) shl 16) or (Random(256) shl 8);
     217      Pixels[X, Y] := (Random(256) or (Random(256) shl 16) or (Random(256) shl 8)) and $ffffff;
    218218end;
    219219
  • GraphicTest/UMainForm.pas

    r338 r442  
    11unit UMainForm;
    22
    3 {$mode Delphi}{$H+}
     3{$mode delphi}{$H+}
    44
    55interface
     
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    99  ExtCtrls, StdCtrls, DateUtils, UPlatform, LCLType, IntfGraphics, fpImage,
    10   Math, GraphType, Contnrs, LclIntf, Spin, UFastBitmap, UDrawMethod, GL,
    11   OpenGLContext;
     10  Math, GraphType, Contnrs, LclIntf, Spin, UFastBitmap, UDrawMethod
     11  {$IFDEF opengl}, GL, OpenGLContext{$ENDIF};
    1212
    1313const
     
    4646    procedure Timer1Timer(Sender: TObject);
    4747  private
     48    {$IFDEF opengl}
    4849    OpenGLControl1: TOpenGLControl;
    4950    TextureId: GLuint;
    5051    TextureData: Pointer;
     52    {$ENDIF}
    5153    MethodIndex: Integer;
    5254    SingleTestActive: Boolean;
    5355    AllTestActive: Boolean;
    5456    procedure OpenGLControl1Resize(Sender: TObject);
     57    {$IFDEF opengl}
    5558    procedure InitGL;
     59    {$ENDIF}
    5660    procedure UpdateMethodList;
    5761    procedure UpdateInterface;
     
    9397  Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y);
    9498
     99  {$IFDEF opengl}
    95100  OpenGLControl1 := TOpenGLControl.Create(Self);
    96101  with OpenGLControl1 do begin
     
    103108  end;
    104109  GetMem(TextureData, OpenGLControl1.Width * OpenGLControl1.Height * SizeOf(Integer));
     110  {$ENDIF}
    105111
    106112  DrawMethods := TObjectList.Create;
     
    109115    NewDrawMethod.Bitmap := Image1.Picture.Bitmap;
    110116    NewDrawMethod.PaintBox := PaintBox1;
     117    {$IFDEF opengl}
    111118    NewDrawMethod.OpenGLBitmap := TextureData;
    112119    NewDrawMethod.OpenGLControl := OpenGLControl1;
     120    {$ENDIF}
    113121    NewDrawMethod.Init;
    114122    DrawMethods.Add(NewDrawMethod);
     
    191199begin
    192200  ListViewMethods.Clear;
    193   FreeMem(TextureData, OpenGLControl1.Width * OpenGLControl1.Height);
    194   DrawMethods.Free;
    195   Scenes.Free;
    196   Bitmap.Free;
     201  {$IFDEF opengl}FreeMem(TextureData, OpenGLControl1.Width * OpenGLControl1.Height);{$ENDIF}
     202  FreeAndNil(DrawMethods);
     203  FreeAndNil(Scenes);
     204  FreeAndNil(Bitmap);
    197205end;
    198206
     
    232240procedure TMainForm.OpenGLControl1Resize(Sender: TObject);
    233241begin
     242  {$IFDEF opengl}
    234243  glViewport(0, 0, OpenGLControl1.Width, OpenGLControl1.Height);
    235 end;
    236 
     244  {$ENDIF}
     245end;
     246
     247{$IFDEF opengl}
    237248procedure TMainForm.InitGL;
    238249begin
     
    254265  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    255266end;
     267{$ENDIF}
    256268
    257269procedure TMainForm.UpdateMethodList;
  • GraphicTest/UPlatform.pas

    r200 r442  
    11unit UPlatform;
    22
    3 {$mode Delphi}{$H+}
     3{$mode delphi}{$H+}
    44
    55interface
Note: See TracChangeset for help on using the changeset viewer.