Ignore:
Timestamp:
Dec 22, 2016, 5:35:25 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Use faster drawing to TBitmap RawImage.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/FastGraphics/UGGraphics.pas

    r26 r27  
    66
    77uses
    8   Classes, SysUtils, Graphics;
     8  Classes, SysUtils, Graphics, GraphType;
    99
    1010type
     
    6666    procedure PaintToCanvas(Canvas: TCanvas; ColorConvertFunc: TGConvertColor); overload;
    6767    procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect; ColorConvertFunc: TGConvertColor); overload;
     68    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect; ColorConvertFunc: TGConvertColor);
    6869    procedure LoadFromCanvas(Canvas: TCanvas; ColorConvertFunc: TGConvertFromColor); overload;
    6970    procedure Fill(Color: TGColor); overload;
     
    191192end;
    192193
     194procedure TGPixmap<TGColor>.PaintToBitmap(Bitmap: TBitmap; Rect: TRect;
     195  ColorConvertFunc: TGConvertColor);
     196var
     197  X, Y: Integer;
     198  PixelPtr: PInteger;
     199  PixelPtrMax: PInteger;
     200  PixelRowPtr: PInteger;
     201  P: TPixelFormat;
     202  RawImage: TRawImage;
     203  BytePerPixel: Integer;
     204begin
     205  try
     206    Bitmap.BeginUpdate(False);
     207    RawImage := Bitmap.RawImage;
     208    PixelRowPtr := PInteger(RawImage.Data);
     209    BytePerPixel := RawImage.Description.BitsPerPixel div 8;
     210    PixelPtrMax := PixelRowPtr + RawImage.Description.Width * RawImage.Description.Height * BytePerPixel;
     211    for Y := Rect.Top to Rect.Bottom - 1 do begin
     212      PixelPtr := PixelRowPtr;
     213      for X := Rect.Left to Rect.Right - 1 do begin
     214        if (X >= 0) and (X < FSize.X) and (Y >= 0) and (Y < FSize.Y) and (PixelPtr < PixelPtrMax) then
     215          PixelPtr^ := ColorConvertFunc(Pixels[X, Y]);
     216        Inc(PByte(PixelPtr), BytePerPixel);
     217
     218      end;
     219      Inc(PByte(PixelRowPtr), RawImage.Description.BytesPerLine);
     220    end;
     221  finally
     222    Bitmap.EndUpdate(False);
     223  end;
     224end;
     225
    193226procedure TGPixmap<TGColor>.LoadFromCanvas(Canvas: TCanvas; ColorConvertFunc: TGConvertFromColor); overload;
    194227var
Note: See TracChangeset for help on using the changeset viewer.