[Lazarus] Slow pointer assignments

Leonardo M. Ramé l.rame at griensu.com
Thu Apr 18 15:28:02 CEST 2013


Hi, this routine copies pixel data from a buffer onto a
TBitmap.RawImage.Data structure.

var
  PixelPtr: PByte;
  PixelRowPtr: PByte;

begin
  PixelRowPtr := Fbmp.RawImage.Data;
  for Y := 0 to Self.Height - 1 do
  begin
    PixelPtr := PixelRowPtr;
    for X := 0 to Self.Width - 1 do
    begin
      PixelPtr^ := lRed;
      Inc(PixelPtr, 1);
      PixelPtr^ := lGreen;
      Inc(PixelPtr, 1);
      PixelPtr^ := lBlue;
      Inc(PixelPtr, 1);
      PixelPtr^ := 255;
      Inc(PixelPtr, 1);
    end;
    Inc(PixelRowPtr, FBmp.RawImage.Description.BytesPerLine);
  end;   
end;

I've found it's very slow (in terms of milliseconds) when the TBitmap is
bigger. What I can do to make it faster?.

P.S.: as you can see, I removed the way lRed, lGreen and lBlue are
calculated, because that won't change the overall speed of the routine.

-  
Leonardo M. Ramé
http://leonardorame.blogspot.com




More information about the Lazarus mailing list