Changeset 27


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

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r16 r27  
    6464    MousePos: TPoint;
    6565    Activated: Boolean;
     66  public
    6667    procedure EraseBackground(DC: HDC); override;
    67   public
    6868    procedure UpdateStatusBar;
    6969    procedure Redraw;
     
    120120    TempBitmap.SetSize(View.SrcRect.Right - View.SrcRect.Left,
    121121      View.SrcRect.Bottom - View.SrcRect.Top);
    122     TempBitmap.BeginUpdate(True);
     122    //TempBitmap.BeginUpdate(True);
    123123    TempBitmap.Canvas.Brush.Color := clBlack;
    124124    TempBitmap.Canvas.FillRect(0, 0, TempBitmap.Width, TempBitmap.Height);
    125125    View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);
    126     Bitmap.PaintToCanvas(TempBitmap.Canvas, View.SrcRect);
    127     TempBitmap.EndUpdate(False);
     126    //Bitmap.PaintToCanvas(TempBitmap.Canvas, View.SrcRect);
     127    Bitmap.PaintToBitmap(TempBitmap, View.SrcRect);
     128    //TempBitmap.EndUpdate(False);
    128129    PaintBox1.Canvas.StretchDraw(View.DestRect, TempBitmap);
    129130    //PaintBox1.Canvas.Draw(0, 0, TempBitmap);
  • trunk/Packages/FastGraphics/ColorFormats/UColorRGB8.pas

    r26 r27  
    5454    procedure PaintToCanvas(Canvas: TCanvas); override;
    5555    procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); override;
     56    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); override;
    5657    procedure LoadFromCanvas(Canvas: TCanvas); override;
    5758    function GetDataSize: Integer; override;
     
    9192function TPixmapRGB8.RGB8ToColor(Value: TColorRGB8): TColor;
    9293begin
    93   Result := (Value.R shl 16) or (Value.G shl 8) or (Value.B shl 0);
     94  Result := (Value.B shl 16) or (Value.G shl 8) or (Value.R shl 0);
    9495end;
    9596
     
    159160end;
    160161
     162procedure TBPixmapRGB8.PaintToBitmap(Bitmap: TBitmap; Rect: TRect);
     163begin
     164  Pixmap.PaintToBitmap(Bitmap, Rect, Pixmap.RGB8ToColor);
     165end;
     166
    161167procedure TBPixmapRGB8.LoadFromCanvas(Canvas: TCanvas);
    162168begin
  • trunk/Packages/FastGraphics/UFGraphics.pas

    r26 r27  
    4343    procedure PaintToCanvas(Canvas: TCanvas); virtual; overload;
    4444    procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); virtual; overload;
     45    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); virtual;
    4546    procedure LoadFromCanvas(Canvas: TCanvas); virtual;
    4647    function GetDataSize: Integer; virtual;
     
    171172    procedure PaintToCanvas(Canvas: TCanvas); overload;
    172173    procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); overload;
     174    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); overload;
    173175    procedure LoadFromCanvas(Canvas: TCanvas);
    174176    function GetDataSize: Integer;
     
    373375end;
    374376
     377procedure TBImage.PaintToBitmap(Bitmap: TBitmap; Rect: TRect);
     378begin
     379end;
     380
    375381procedure TBImage.LoadFromCanvas(Canvas: TCanvas);
    376382begin
     
    479485begin
    480486  FBackend.PaintToCanvas(Canvas, Rect);
     487end;
     488
     489procedure TFPixmap.PaintToBitmap(Bitmap: TBitmap; Rect: TRect);
     490begin
     491  FBackend.PaintToBitmap(Bitmap, Rect);
    481492end;
    482493
  • 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
  • trunk/UCore.pas

    r26 r27  
    207207begin
    208208  Project.Bitmap.Clear;
    209   TFColor(Project.Bitmap.Canvas.Pen.Color).ColorFormat := Project.Bitmap.ColorFormat;
    210   TFColor(Project.Bitmap.Canvas.Pen.Color).SetColorName(cnWhite);
     209  (Project.Bitmap.Canvas.Pen.Color as TFColor).ColorFormat := Project.Bitmap.ColorFormat;
     210  (Project.Bitmap.Canvas.Pen.Color as TFColor).SetColorName(cnWhite);
    211211  Project.Bitmap.Canvas.Pen.MoveTo(Point(80, 80));
    212212  Project.Bitmap.Canvas.Pen.LineTo(Point(50, 20));
Note: See TracChangeset for help on using the changeset viewer.