packages/fcl-image/src/fpimage.inc has procedure TFPCustomImage.Assign(Source: TPersistent);
Procedure TFPCustomImage.Assign(Source: TPersistent);
Var
Src : TFPCustomImage;
X,Y : Integer;
begin
If Source is TFPCustomImage then
begin
Src:=TFPCustomImage(Source);
// Copy extra info
FExtra.Assign(Src.Fextra);
// Copy palette if needed.
SetSize(0,0); { avoid side-effects in descendant classes }
UsePalette:=Src.UsePalette;
If UsePalette then
begin
Palette.Count:=0;
Palette.Merge(Src.Palette);
end;
// Copy image.
SetSize(Src.Width,Src.height);
If UsePalette then
For x:=0 to Src.Width-1 do
For y:=0 to src.Height-1 do
pixels[X,Y]:=src.pixels[X,Y]
else
For x:=0 to Src.Width-1 do
For y:=0 to src.Height-1 do
self[X,Y]:=src[X,Y];
end
else
Inherited Assign(Source);
end;
The following patch improves CPU cache usage by switching the x and y loops. In addition, some cosmetics: two empty lines have been removed, "Var" has been changed to "var" and "[X,Y]" has been changed to "[x,y]".
diff --git a/packages/fcl-image/src/fpimage.inc b/packages/fcl-image/src/fpimage.inc
index 3e2075900d..54be93074c 100644
--- a/packages/fcl-image/src/fpimage.inc
+++ b/packages/fcl-image/src/fpimage.inc
@@ -460,11 +460,9 @@ procedure TFPCustomImage.CheckIndex (x,y:integer);
end;
Procedure TFPCustomImage.Assign(Source: TPersistent);
-
-Var
+var
Src : TFPCustomImage;
- X,Y : Integer;
-
+ x,y : Integer;
begin
If Source is TFPCustomImage then
begin
@@ -482,13 +480,13 @@ procedure TFPCustomImage.CheckIndex (x,y:integer);
// Copy image.
SetSize(Src.Width,Src.height);
If UsePalette then
- For x:=0 to Src.Width-1 do
- For y:=0 to src.Height-1 do
- pixels[X,Y]:=src.pixels[X,Y]
+ For y:=0 to src.Height-1 do
+ For x:=0 to Src.Width-1 do
+ pixels[x,y]:=src.pixels[x,y]
else
- For x:=0 to Src.Width-1 do
- For y:=0 to src.Height-1 do
- self[X,Y]:=src[X,Y];
+ For y:=0 to src.Height-1 do
+ For x:=0 to Src.Width-1 do
+ self[x,y]:=src[x,y];
end
else
Inherited Assign(Source);