Improved CPU cache usage at packages/fcl-image/src/pixtools.pp

By lagprogramming from forum.

packages/fcl-image/src/pixtools.pp has:

procedure FillRectangleColor (Canv:TFPCustomCanvas; x1,y1, x2,y2:integer; const color:TFPColor);
var x,y : integer;
begin
  SortRect (x1,y1, x2,y2);
  with Canv do
    begin
    for x := x1 to x2 do
      for y := y1 to y2 do
        DrawPixel(x,y,color);
    end;
end;

....

procedure FillRectangleImage (Canv:TFPCustomCanvas; x1,y1, x2,y2:integer; const Image:TFPCustomImage);
var x,y : integer;
begin
  with image do
    for x := x1 to x2 do
      for y := y1 to y2 do
        Canv.DrawPixel(x,y, colors[x mod width, y mod height]);
end;    

....

procedure FillRectangleImageRel (Canv:TFPCustomCanvas; x1,y1, x2,y2:integer; const Image:TFPCustomImage);
var x,y : integer;
begin
  with image do
    for x := x1 to x2 do
      for y := y1 to y2 do
        Canv.DrawPixel(x,y, colors[(x-x1) mod width, (y-y1) mod height]);
end;

The following patch improves CPU cache usage by switching the x and y loops.

diff --git a/packages/fcl-image/src/pixtools.pp b/packages/fcl-image/src/pixtools.pp
index b8baccb5bb..da0fbfe700 100644
--- a/packages/fcl-image/src/pixtools.pp
+++ b/packages/fcl-image/src/pixtools.pp
@@ -73,8 +73,8 @@ procedure FillRectangleColor (Canv:TFPCustomCanvas; x1,y1, x2,y2:integer; const
   SortRect (x1,y1, x2,y2);
   with Canv do
     begin
-    for x := x1 to x2 do
-      for y := y1 to y2 do
+    for y := y1 to y2 do
+      for x := x1 to x2 do
         DrawPixel(x,y,color);
     end;
 end;
@@ -555,8 +555,8 @@ procedure FillRectangleImage (Canv:TFPCustomCanvas; x1,y1, x2,y2:integer; const
 var x,y : integer;
 begin
   with image do
-    for x := x1 to x2 do
-      for y := y1 to y2 do
+    for y := y1 to y2 do
+      for x := x1 to x2 do
         Canv.DrawPixel(x,y, colors[x mod width, y mod height]);
 end;
 
@@ -564,8 +564,8 @@ procedure FillRectangleImageRel (Canv:TFPCustomCanvas; x1,y1, x2,y2:integer; con
 var x,y : integer;
 begin
   with image do
-    for x := x1 to x2 do
-      for y := y1 to y2 do
+    for y := y1 to y2 do
+      for x := x1 to x2 do
         Canv.DrawPixel(x,y, colors[(x-x1) mod width, (y-y1) mod height]);
 end;