SRL Archive - Suggestions

Increase Simba's Max Image Finding Size..


Brandon

2013-10-26 18:44:49

Ok so I'm doing some testing and benchmarking for the worst case possible scenario of Image finding. What I'm doing is testing how fast Simba can find a 100x100 image within a 10200x10200 image where the 100x100 image is placed at the very bottom right corner of the larger image.

This:


-----------------------
|.....................|
|.....................|
|.....................|
|.....................|
|.....................|
|.................----|
|................|****|
|.................----|
-----------------------

So you can see the smaller image is at the worst case possible position for Simba's FindBitmapToleranceIn function..

Now here's the problem. The large image is 286mb on disk and when loading it with Simba's LoadBitmap function and then performing a find, it says "Out of memory"..

However, just loading it, I can load it 5x++ over..


Procedure DebugBitmap(Bmp: Integer);
var
W, H: Integer;
Begin
GetBitmapSize(Bmp, W, H);
DisplayDebugImgWindow(W, H);
DrawBitmapDebugImg(Bmp);
End;

Procedure CropBitmap(var Bmp: Integer; XS, YS, XE, YE: Integer);
var
T, Old, New: Integer;
Begin
Old := GetImageTarget;
New := SetTargetBitmap(Bmp);
T := BitmapFromClient(XS, YS, XE, YE);
SetImageTarget(Old);
FreeTarget(New);
FreeBitmap(Bmp);
Bmp := T;
End;

var
OldTarget, NewTarget: Integer;
Bmp, SmallImage: Integer;
X, Y, W, H: Integer;
begin
Bmp := LoadBitmap('C:/Users/Brandon/Desktop/World.bmp');
GetBitmapSize(Bmp, W, H);
OldTarget := GetImageTarget;
NewTarget := SetTargetBitmap(Bmp);

SmallImage := CopyBitmap(Bmp);
CropBitmap(SmallImage, 9800, 9800, 9900, 9900);

FindBitmapToleranceIn(SmallImage, X, Y, 0, 0, W - 1, H - 1, 50);

SetImageTarget(OldTarget);
FreeTarget(NewTarget);

FreeBitmap(Bmp);
FreeBitmap(SmallImage);
end.


Compiled successfully in 203 ms.
Exception in Script: Runtime error: "Out of memory" at line 36, column 24
The following bitmaps were not freed: [0, 2]

The above code won't let me find a small 100x100 bitmap in the large 10200x10200 bitmap. It says it ran out of memory.. Task manager shows Simba using 400mb of memory to do this..

However, I can go up to 1500mb+ of memory doing the following:

Procedure ReadFile(var Str: String; var Total: Integer);
var
Hnd: Integer;
Size: Integer;
begin
try
Hnd := OpenFile('C:/Users/Brandon/Desktop/World.bmp', false);
Size := FileSize(Hnd);

ReadFileString(Hnd, Str, Size);
except
writeln('exception caught.');
finally
CloseFile(Hnd);
end;

Total := Total + Size;
end;

var
Total: Integer;
Str, Str2, Str3, Str4, Str5: String;
begin
ReadFile(Str, Total);
ReadFile(Str2, Total);
ReadFile(Str3, Total);
ReadFile(Str4, Total);
ReadFile(Str5, Total);
Sleep(2000);
writeln('Total Bytes Read: ', Total);
writeln('Total MBytes Read: ', Round(Total / (1024 * 1024)));
writeln('Total GBytes Read: ', Total / (1024 * 1024 * 1024));
end.


Total Bytes Read: 1500000270
Total MBytes Read: 1431
Total GBytes Read: 1.39698411338031
Successfully executed.

So.. Why does this limitation exist? Why allow me to load the same file 5x+ as a string and I'm able to parse that string but as a single image, I can't even use it once! Any ideas?


Also, there is a leak in Simba. If an exception occurs, Simba's garbage collection does NOT free anything! However, if no exception occurs, the memory is freed upon the script thread terminating. I thought Simba auto-frees everything ones the thread terminates? No?

Wizzup?

2013-12-22 05:43:44

Can you file a bug for this? I am interested in picking this up.