Changeset 18


Ignore:
Timestamp:
Jan 21, 2018, 10:21:23 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Optimized drawing virtual screen to form canvas.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r17 r18  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    99  ExtCtrls, Menus, ActnList, UKernel, UMemory, UDevice, UPlatformBase, LCLType,
    10   UGraphics;
     10  UGraphics, GraphType;
    1111
    1212type
     
    188188var
    189189  X, Y: Integer;
    190   DX, DY: Integer;
    191   P, PR: PByte;
    192 begin
     190  SourceBytePerPixel: Integer;
     191  SourceBytePerLine: Integer;
     192  SourcePixelPtr: PByte;
     193  SourcePixelRowPtr: PByte;
     194  RawImage: TRawImage;
     195  DestPixelRowPtr: PByte;
     196  DestPixelPtr: PByte;
     197  DestBytePerPixel: Integer;
     198  DestBytePerLine: Integer;
     199  SizeX: Integer;
     200  SizeY: Integer;
     201begin
     202{  var
     203    X, Y: Integer;
     204    PixelPtr: PInteger;
     205    PixelRowPtr: PInteger;
     206    RawImage: TRawImage;
     207    BytePerPixel: Integer;
     208    SourcePixelPtr: Integer;
     209  begin
     210    try
     211      Bitmap.BeginUpdate;
     212      RawImage := Bitmap.RawImage;
     213      PixelRowPtr := PInteger(RawImage.Data);
     214      BytePerPixel := RawImage.Description.BitsPerPixel div 8;
     215      for Y := 0 to Bitmap.Height - 1 do begin
     216        PixelPtr := PixelRowPtr;
     217        for X := 0 to Bitmap.Width - 1 do begin
     218          SourcePixelPtr := TMatter(Matter[Surface.ItemsXY[Trunc(X / Bitmap.Width * Surface.Count.X),
     219              Trunc(Y / Bitmap.Height * Surface.Count.Y)]]).Color;
     220          PixelPtr^ := SwapBRComponent(SourcePixelPtr);
     221          Inc(PByte(PixelPtr), BytePerPixel);
     222        end;
     223        Inc(PByte(PixelRowPtr), RawImage.Description.BytesPerLine);
     224      end;
     225    finally
     226      Bitmap.EndUpdate;
     227    end;
     228}
    193229  try
     230    TempBitmap.SetSize(VideoDevice.VideoMode.Size.X, VideoDevice.VideoMode.Size.Y);
    194231    TempBitmap.BeginUpdate;
    195     TempBitmap.SetSize(PaintBox1.Width, PaintBox1.Height);
    196 
     232    RawImage := TempBitmap.RawImage;
     233    DestPixelRowPtr := RawImage.Data;
     234    DestBytePerPixel := RawImage.Description.BitsPerPixel div 8;
     235    DestBytePerLine := RawImage.Description.BytesPerLine;
    197236    if Assigned(VideoDevice.VideoMemory) then begin
    198       DX := VideoDevice.VideoMode.GetBytesPerPixel;
    199       DY := VideoDevice.VideoMode.GetBytesPerLine;
    200       P := VideoDevice.VideoMemory;
    201       for Y := 0 to VideoDevice.VideoMode.Size.Y - 1 do begin
    202         PR := P;
    203         for X := 0 to VideoDevice.VideoMode.Size.X - 1 do begin
    204           TempBitmap.Canvas.Pixels[X, Y] := PInteger(PR)^ and $ffffff;
    205           Inc(PR, DX);
     237      SourceBytePerPixel := VideoDevice.VideoMode.GetBytesPerPixel;
     238      SourceBytePerLine := VideoDevice.VideoMode.GetBytesPerLine;
     239      SourcePixelRowPtr := VideoDevice.VideoMemory;
     240      SizeX := VideoDevice.VideoMode.Size.X;
     241      SizeY := VideoDevice.VideoMode.Size.Y;
     242      for Y := 0 to SizeY - 1 do begin
     243        SourcePixelPtr := SourcePixelRowPtr;
     244        DestPixelPtr := DestPixelRowPtr;
     245        for X := 0 to SizeX - 1 do begin
     246          PInteger(DestPixelPtr)^ := PInteger(SourcePixelPtr)^ and $ffffff;
     247          Inc(SourcePixelPtr, SourceBytePerPixel);
     248          Inc(DestPixelPtr, DestBytePerPixel);
    206249        end;
    207         Inc(P, DY);
     250        Inc(SourcePixelRowPtr, SourceBytePerLine);
     251        Inc(DestPixelRowPtr, DestBytePerLine);
    208252      end;
    209253    end;
    210254  finally
     255    TempBitmap.EndUpdate;
    211256    PaintBox1.Canvas.Draw(0, 0, TempBitmap);
    212     TempBitmap.EndUpdate;
    213257  end;
    214258end;
  • trunk/Platform/Base/UPlatformBase.pas

    r17 r18  
    6666  protected
    6767    procedure SetVideoMode(Mode: TVideoMode); override;
     68    function GetVideoMemory: PByte; override;
    6869  public
    6970    VideoMemory: PByte;
     
    7172    Canvas: TCanvas;
    7273    procedure GetSupportedModes(Modes: TObjectList); override;
    73     function GetVideoMemory: PByte; override;
    7474    procedure VideoMemoryChange; override;
    7575    constructor Create; override;
Note: See TracChangeset for help on using the changeset viewer.