Recent

Author Topic: [SOLVED] Improvement of lcl/include/canvas.inc TCanvas.BrushCopy  (Read 1756 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 406
The original code doesn't read and write data in a lean way, making the CPU use it's cache poorly. A similar situation has been described in the forum at:
Lazarus » Forum » Free Pascal » FPC development (Moderators: FPK, Tomas Hajny) » Improvement of packages/fcl-image/src/fpcanvas.inc TFPCustomCanvas.Erase
https://forum.lazarus.freepascal.org/index.php/topic,62788.0.html
I've replaced "for x := 0 to lSrcWidth-1 do for y := 0 to lSrcHeight-1 do" with "for y := 0 to lSrcHeight-1 do for x := 0 to lSrcWidth-1 do". Basically, I've switched the "for" loops.

Here is a patch:
Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/include/canvas.inc b/lcl/include/canvas.inc
  2. index 97665929b9..4c5300288f 100644
  3. --- a/lcl/include/canvas.inc
  4. +++ b/lcl/include/canvas.inc
  5. @@ -754,8 +754,8 @@ begin
  6.  
  7.      // Next copy the bitmap to a intfimage to be able to make the color change
  8.      lIntfImage.LoadFromBitmap(lPaintedBitmap.Handle, 0);
  9. -    for x := 0 to lSrcWidth-1 do
  10. -      for y := 0 to lSrcHeight-1 do
  11. +    for y := 0 to lSrcHeight-1 do
  12. +      for x := 0 to lSrcWidth-1 do
  13.        begin
  14.          lPixelColor := lIntfImage.Colors[x, y];
  15.          if (lPixelColor.red = lTransparentColor.red) and
« Last Edit: April 11, 2023, 08:34:27 am by lagprogramming »

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Improvement of lcl/include/canvas.inc TCanvas.BrushCopy
« Reply #1 on: April 10, 2023, 11:57:26 pm »
Since this is relatively clear, I committed it to the main branch without a proper bug report. But since I don't have commit rights in the FPC project I cannot help you with the related FPCustomCanvas issue.

Once again, you are wasting your time when you publish fixes here in the forum. They will be forgotten after a few days since most developers do not read the forum, and if they do they usually insist on a proper bug report for better documentation.

I really do not understand why you have such an aversion against the bug tracker?

lagprogramming

  • Sr. Member
  • ****
  • Posts: 406
Re: Improvement of lcl/include/canvas.inc TCanvas.BrushCopy
« Reply #2 on: April 11, 2023, 08:34:12 am »
Your interventions are valuable, wp.  ;)

AlexTP

  • Hero Member
  • *****
  • Posts: 2406
    • UVviewsoft

 

TinyPortal © 2005-2018