Bookstore

Recent

Author Topic: Extremely slow CopyRect in android  (Read 2749 times)

stab

  • Full Member
  • ***
  • Posts: 186
Extremely slow CopyRect in android
« on: December 01, 2012, 02:58:48 pm »
Hi,

Platform: Windows 7
Lazarus: 1.1
FPC:        2.7.1 SVN Rev: 39352

Attached is a small app I made to test CopyRect. Was astonished of how slow it is.
The app consist of an Image(245x245 pixels), a combobox with the extent of 4 different rectangles. Selecting one makes a CopyRect to the Image.

Actual code:
procedure TfrmCopyrectMain.cbxCopyRectsChange(Sender: TObject);
var
  copyRect : TRect;
  tempList, logList : TStringList;
  startTime, endTime : TDateTime;
begin
  if FBitmap = nil then Exit;

  tempList:=TStringList.Create;
  try
    if FBitmap.Width = 0 then
    begin
      FBitmap.Assign(Image1.Picture.Bitmap);
      FTotRect.Left:=0;
      FTotRect.Top:=0;
      FTotRect.Right:=Image1.Width;
      FTotRect.Bottom:=Image1.Height;
   end;

    startTime := Now;

    if cbxCopyRects.ItemIndex = 0 then
      Image1.Picture.Bitmap.Canvas.CopyRect(FTotRect,  FBitmap.Canvas, FTotRect)
    else
    begin
      tempList.Text:=AnsiReplaceText(cbxCopyRects.Items[cbxCopyRects.ItemIndex], ',', Chr(13) + Chr(10));
      copyRect.Left:=StrToInt(tempList.Strings[0]);
      copyRect.Top:=StrToInt(tempList.Strings[1]);
      copyRect.Right:=StrToInt(tempList.Strings[2]);
      copyRect.Bottom:=StrToInt(tempList.Strings[3]);

      Image1.Picture.Bitmap.Canvas.CopyRect(FTotRect,  FBitmap.Canvas, copyRect);
    end;

    endTime := Now;
    LogExecutionTime(endTime- startTime, cbxCopyRects.Items[cbxCopyRects.ItemIndex]);
  finally
    FreeAndNil(tempList);
  end;
end;

These are the execution times I logged:
0,0, 100, 100         -  00:00:02.733
100, 100, 200,150 -  00:00:02.848
120, 120, 200, 200 - 00:00:02.652
Original                   - 00:00:00.080

As seen it takes 80 milliseconds to copy the entire image back to itself and more than 2 seconds to copy a part of it.

Maybe I'm doing something wrong or perhaps someone has a suggestion on how
to achieve a fast copy.
I'm working on a map application and want to be able to zoom in on a part of current displayed map area. Tried this first in an app in Windows 7 and there it was real fast.

Attached is my test app. Directory for log file is hardcoded to /sdcard/LazarusApps.

Regards
stab :-\