Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Aug 13, 2023
1 parent e705756 commit 3a26f44
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 152 deletions.
16 changes: 11 additions & 5 deletions Source/finders/simba.finder_bitmap.pas
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ function FindBitmapOnBuffer(var Limit: TSimpleThreadsafeLimit;
SearchWidth, SearchHeight: Integer): TPointArray;

var
BitmapFinderMT_Enabled: Boolean = True;
BitmapFinderMT_SliceHeight: Integer = 125;
BitmapFinderMT_SliceWidth: Integer = 250;
BitmapFinderMultithreadOpts: record
Enabled: Boolean;
SliceWidth, SliceHeight: Integer;
end;

implementation

Expand All @@ -47,10 +48,10 @@ function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer;
begin
Result := 1;

if BitmapFinderMT_Enabled and (SearchWidth >= BitmapFinderMT_SliceWidth) and (SearchHeight >= (BitmapFinderMT_SliceHeight * 2)) then // not worth
if BitmapFinderMultithreadOpts.Enabled and (SearchWidth >= BitmapFinderMultithreadOpts.SliceWidth) and (SearchHeight >= (BitmapFinderMultithreadOpts.SliceHeight * 2)) then // not worth
begin
for I := SimbaThreadPool.ThreadCount - 1 downto 2 do
if (SearchHeight div I) > BitmapFinderMT_SliceHeight then // Each slice is at least `MatchTemplateMT_SliceHeight` pixels
if (SearchHeight div I) > BitmapFinderMultithreadOpts.SliceHeight then // Each slice is at least `MatchTemplateMT_SliceHeight` pixels
Exit(I);
end;

Expand Down Expand Up @@ -274,5 +275,10 @@ function FindBitmapOnBuffer(var Limit: TSimpleThreadsafeLimit; Bitmap: TSimbaIma
end;
end;

initialization
BitmapFinderMultithreadOpts.Enabled := True;
BitmapFinderMultithreadOpts.SliceHeight := 125;
BitmapFinderMultithreadOpts.SliceWidth := 250;

end.

18 changes: 11 additions & 7 deletions Source/finders/simba.finder_color.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ function MatchColorsOnTarget(Target: TSimbaTarget; Bounds: TBox;
Formula: EColorSpace; Color: TColor; Multipliers: TChannelMultipliers): TSingleMatrix;

var
ColorFinderMT_Enabled: Boolean = True;
ColorFinderMT_SliceHeight: Integer = 125;
ColorFinderMT_SliceWidth: Integer = 250;
ColorFinderMultithreadOpts: record
Enabled: Boolean;
SliceWidth, SliceHeight: Integer;
end;

implementation

Expand All @@ -56,10 +57,10 @@ function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer;
begin
Result := 1;

if ColorFinderMT_Enabled and (SearchWidth >= ColorFinderMT_SliceWidth) and (SearchHeight >= (ColorFinderMT_SliceHeight * 2)) then // not worth
if ColorFinderMultithreadOpts.Enabled and (SearchWidth >= ColorFinderMultithreadOpts.SliceWidth) and (SearchHeight >= (ColorFinderMultithreadOpts.SliceHeight * 2)) then // not worth
begin
for I := SimbaThreadPool.ThreadCount - 1 downto 2 do
if (SearchHeight div I) > ColorFinderMT_SliceHeight then // Each slice is at leastColorFinderMT_SliceHeight` pixels
if (SearchHeight div I) > ColorFinderMultithreadOpts.SliceHeight then // Each slice is at leastColorFinderMT_SliceHeight` pixels
Exit(I);
end;

Expand Down Expand Up @@ -352,6 +353,9 @@ function MatchColorsOnTarget(Target: TSimbaTarget; Bounds: TBox;
end;
end;

end.

initialization
ColorFinderMultithreadOpts.Enabled := True;
ColorFinderMultithreadOpts.SliceWidth := 125;
ColorFinderMultithreadOpts.SliceHeight := 250;

end.
16 changes: 11 additions & 5 deletions Source/matchtemplate/simba.matchtemplate.pas
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer;
function Multithread(Image, Templ: TIntegerMatrix; MatchTemplate: TMatchTemplate; Normed: Boolean): TSingleMatrix;

var
MatchTemplateMT_Enabled: Boolean = True;
MatchTemplateMT_SliceHeight: Integer = 125;
MatchTemplateMT_SliceWidth: Integer = 250;
MatchTemplateMultithreadOpts: record
Enabled: Boolean;
SliceWidth, SliceHeight: Integer;
end;

implementation

Expand All @@ -74,10 +75,10 @@ function CalculateSlices(SearchWidth, SearchHeight: Integer): Integer;
begin
Result := 1;

if MatchTemplateMT_Enabled and (SearchWidth >= MatchTemplateMT_SliceWidth) and (SearchHeight >= (MatchTemplateMT_SliceHeight * 2)) then // not worth
if MatchTemplateMultithreadOpts.Enabled and (SearchWidth >= MatchTemplateMultithreadOpts.SliceWidth) and (SearchHeight >= (MatchTemplateMultithreadOpts.SliceHeight * 2)) then // not worth
begin
for I := SimbaThreadPool.ThreadCount - 1 downto 2 do
if (SearchHeight div I) > MatchTemplateMT_SliceHeight then // Each slice is at least `MatchTemplateMT_SliceHeight` pixels
if (SearchHeight div I) > MatchTemplateMultithreadOpts.SliceHeight then // Each slice is at least `MatchTemplateMT_SliceHeight` pixels
Exit(I);
end;

Expand Down Expand Up @@ -174,4 +175,9 @@ function MatchTemplate(Image, Template: TIntegerMatrix; Formula: ETMFormula): TS
end;
end;

initialization
MatchTemplateMultithreadOpts.Enabled := True;
MatchTemplateMultithreadOpts.SliceWidth := 125;
MatchTemplateMultithreadOpts.SliceHeight := 250;

end.
21 changes: 8 additions & 13 deletions Source/script/imports/simba/simba.import_finder.pas
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ procedure _LapeFinder_GetPixelDifference1(const Params: PParamArray; const Resul
(*
TFinder.GetPixelDifference
~~~~~~~~~~~~~~~~~~~~~~~~~~
> function TFinder.GetPixelDifference(WaitTime, Tolerance: Integer; Area: TBox = [-1,-1,-1,-1]): Integer;
> function TFinder.GetPixelDifference(WaitTime, Tolerance: Single; Area: TBox = [-1,-1,-1,-1]): Integer;
*)
procedure _LapeFinder_GetPixelDifference2(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PInteger(Result)^ := PSimbaFinder(Params^[0])^.GetPixelDifference(PInteger(Params^[1])^, PInteger(Params^[2])^, PBox(Params^[3])^);
PInteger(Result)^ := PSimbaFinder(Params^[0])^.GetPixelDifference(PInteger(Params^[1])^, PSingle(Params^[2])^, PBox(Params^[3])^);
end;

(*
Expand All @@ -282,11 +282,11 @@ procedure _LapeFinder_GetPixelDifferenceTPA1(const Params: PParamArray; const Re
(*
TFinder.GetPixelDifferenceTPA
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> function TFinder.GetPixelDifferenceTPA(WaitTime, Tolerance: Integer; Area: TBox = [-1,-1,-1,-1]): TPointArray;
> function TFinder.GetPixelDifferenceTPA(WaitTime, Tolerance: Single; Area: TBox = [-1,-1,-1,-1]): TPointArray;
*)
procedure _LapeFinder_GetPixelDifferenceTPA2(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPointArray(Result)^ := PSimbaFinder(Params^[0])^.GetPixelDifferenceTPA(PInteger(Params^[1])^, PInteger(Params^[2])^, PBox(Params^[3])^);
PPointArray(Result)^ := PSimbaFinder(Params^[0])^.GetPixelDifferenceTPA(PInteger(Params^[1])^, PSingle(Params^[2])^, PBox(Params^[3])^);
end;

(*
Expand Down Expand Up @@ -343,13 +343,8 @@ procedure ImportFinder(Compiler: TSimbaScript_Compiler);
begin
ImportingSection := 'Finder';

addGlobalVar(ltBoolean, @ColorFinderMT_Enabled, 'ColorFinderMT_Enabled');
addGlobalVar(ltInt32, @ColorFinderMT_SliceHeight, 'ColorFinderMT_SliceHeight');
addGlobalVar(ltInt32, @ColorFinderMT_SliceWidth, 'ColorFinderMT_SliceWidth');

addGlobalVar(ltBoolean, @BitmapFinderMT_Enabled, 'BitmapFinderMT_Enabled');
addGlobalVar(ltInt32, @BitmapFinderMT_SliceHeight, 'BitmapFinderMT_SliceHeight');
addGlobalVar(ltInt32, @BitmapFinderMT_SliceWidth, 'BitmapFinderMT_SliceWidth');
addGlobalVar('record Enabled: Boolean; SliceWidth, SliceHeight: Integer; end;', @ColorFinderMultithreadOpts, 'ColorFinderMultithreadOpts');
addGlobalVar('record Enabled: Boolean; SliceWidth, SliceHeight: Integer; end;', @BitmapFinderMultithreadOpts, 'BitmapFinderMultithreadOpts');

addGlobalType([
'record',
Expand Down Expand Up @@ -415,9 +410,9 @@ procedure ImportFinder(Compiler: TSimbaScript_Compiler);
addFinderMethod('function TFinder.GetColorsMatrix(Bounds: TBox = [-1,-1,-1,-1]): TIntegerMatrix', @_LapeFinder_GetColorsMatrix);

addFinderMethod('function TFinder.GetPixelDifference(WaitTime: Integer; Area: TBox = [-1,-1,-1,-1]): Integer; overload', @_LapeFinder_GetPixelDifference1);
addFinderMethod('function TFinder.GetPixelDifference(WaitTime, Tolerance: Integer; Area: TBox = [-1,-1,-1,-1]): Integer; overload', @_LapeFinder_GetPixelDifference2);
addFinderMethod('function TFinder.GetPixelDifference(WaitTime: Integer; Tolerance: Single; Area: TBox = [-1,-1,-1,-1]): Integer; overload', @_LapeFinder_GetPixelDifference2);
addFinderMethod('function TFinder.GetPixelDifferenceTPA(WaitTime: Integer; Area: TBox = [-1,-1,-1,-1]): TPointArray; overload', @_LapeFinder_GetPixelDifferenceTPA1);
addFinderMethod('function TFinder.GetPixelDifferenceTPA(WaitTime, Tolerance: Integer; Area: TBox = [-1,-1,-1,-1]): TPointArray; overload', @_LapeFinder_GetPixelDifferenceTPA2);
addFinderMethod('function TFinder.GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Single; Area: TBox = [-1,-1,-1,-1]): TPointArray; overload', @_LapeFinder_GetPixelDifferenceTPA2);

addFinderMethod('function TFinder.AverageBrightness(Area: TBox = [-1,-1,-1,-1]): Integer', @_LapeFinder_AverageBrightness);
addFinderMethod('function TFinder.PeakBrightness(Area: TBox = [-1,-1,-1,-1]): Integer', @_LapeFinder_PeakBrightness);
Expand Down
4 changes: 1 addition & 3 deletions Source/script/imports/simba/simba.import_matchtemplate.pas
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ procedure ImportMatchTemplate(Compiler: TSimbaScript_Compiler);
begin
ImportingSection := 'Match Template';

addGlobalVar(ltBoolean, @MatchTemplateMT_Enabled, 'MatchTemplateMT_Enabled');
addGlobalVar(ltInt32, @MatchTemplateMT_SliceHeight, 'MatchTemplateMT_SliceHeight');
addGlobalVar(ltInt32, @MatchTemplateMT_SliceWidth, 'MatchTemplateMT_SliceWidth');
addGlobalVar('record Enabled: Boolean; SliceWidth, SliceHeight: Integer; end;', @MatchTemplateMultithreadOpts, 'MatchTemplateMultithreadOpts');

addClass('TMatchTemplateCache');
addGlobalType('(TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED, TM_SQDIFF, TM_SQDIFF_NORMED)', 'ETMFormula');
Expand Down
18 changes: 18 additions & 0 deletions Source/script/simba.compiler_dump.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ TSimbaCompilerDump = class(TSimbaScript_Compiler)
procedure addBaseDefine(Define: lpString; Value: lpString = ''); override;

function addDelayedCode(ACode: lpString; AFileName: lpString = ''; AfterCompilation: Boolean = True; IsGlobal: Boolean = True): TLapeTree_Base; override;

function addGlobalFunc(Header: lpString; Value: Pointer): TLapeGlobalVar; override;
function addGlobalFunc(Header: lpString; Body: TStringArray): TLapeTree_Method; override;

function addGlobalType(Typ: TLapeType; AName: lpString; ACopy: Boolean): TLapeType; override;
function addGlobalType(Str: lpString; AName: lpString): TLapeType; override;

function addGlobalVar(Typ: lpString; Value: lpString; AName: lpString): TLapeGlobalVar; override;
function addGlobalVar(Typ: lpString; Value: Pointer; AName: lpString): TLapeGlobalVar; override;
function addGlobalVar(AVar: TLapeGlobalVar; AName: lpString = ''): TLapeGlobalVar; override;

procedure DumpToFile(FileName: String);
end;
Expand Down Expand Up @@ -214,6 +219,19 @@ function TSimbaCompilerDump.addGlobalVar(Typ: lpString; Value: lpString; AName:
Result._DocPos.FileName := ImportingSection;
end;

function TSimbaCompilerDump.addGlobalVar(Typ: lpString; Value: Pointer; AName: lpString): TLapeGlobalVar;
begin
Result := inherited addGlobalVar(Typ, Value, AName);

AddCode('var ' + AName + ': ' + Typ);
end;

function TSimbaCompilerDump.addGlobalVar(AVar: TLapeGlobalVar; AName: lpString): TLapeGlobalVar;
begin
Result := inherited addGlobalVar(AVar, AName);
Result._DocPos.FileName := ImportingSection;
end;

procedure TSimbaCompilerDump.DumpToFile(FileName: String);
var
BaseType: ELapeBaseType;
Expand Down
8 changes: 0 additions & 8 deletions Source/script/simba.script_compiler.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ TSimbaScript_Compiler = class(TLapeCompiler)

procedure addDelayedCode(Code: TStringArray; AFileName: lpString = ''); virtual; overload;

function addGlobalVar(AVar: TLapeGlobalVar; AName: lpString = ''): TLapeGlobalVar; override;

function addGlobalFunc(Header: lpString; Body: TStringArray): TLapeTree_Method; virtual; overload;
function addGlobalFunc(Header: lpString; Value: Pointer; ABI: TFFIABI): TLapeGlobalVar; virtual; overload;
procedure addGlobalFuncOverride(Header: lpString; Body: TStringArray); virtual;
Expand Down Expand Up @@ -236,11 +234,5 @@ procedure TSimbaScript_Compiler.addDelayedCode(Code: TStringArray; AFileName: lp
addDelayedCode(LapeDelayedFlags + LineEnding.Join(Code), AFileName);
end;

function TSimbaScript_Compiler.addGlobalVar(AVar: TLapeGlobalVar; AName: lpString): TLapeGlobalVar;
begin
Result := inherited;
Result._DocPos.FileName := ImportingSection;
end;

end.

107 changes: 0 additions & 107 deletions Source/script/simba.script_compiler_debugger.pas

This file was deleted.

8 changes: 4 additions & 4 deletions Source/simba.finder.pas
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ TColorTolerance = record
function GetColorsMatrix(Bounds: TBox): TIntegerMatrix;

function GetPixelDifference(WaitTime: Integer; Area: TBox): Integer; overload;
function GetPixelDifference(WaitTime: Integer; Tolerance: Integer; Area: TBox): Integer; overload;
function GetPixelDifference(WaitTime: Integer; Tolerance: Single; Area: TBox): Integer; overload;
function GetPixelDifferenceTPA(WaitTime: Integer; Area: TBox): TPointArray; overload;
function GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Integer; Area: TBox): TPointArray; overload;
function GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Single; Area: TBox): TPointArray; overload;

function AverageBrightness(Area: TBox): Integer;
function PeakBrightness(Area: TBox): Integer;
Expand Down Expand Up @@ -294,7 +294,7 @@ function TSimbaFinder.GetPixelDifference(WaitTime: Integer; Area: TBox): Integer
end;
end;

function TSimbaFinder.GetPixelDifference(WaitTime: Integer; Tolerance: Integer; Area: TBox): Integer;
function TSimbaFinder.GetPixelDifference(WaitTime: Integer; Tolerance: Single; Area: TBox): Integer;
var
BitmapBefore, BitmapAfter: TSimbaImage;
begin
Expand Down Expand Up @@ -338,7 +338,7 @@ function TSimbaFinder.GetPixelDifferenceTPA(WaitTime: Integer; Area: TBox): TPoi
end;
end;

function TSimbaFinder.GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Integer; Area: TBox): TPointArray;
function TSimbaFinder.GetPixelDifferenceTPA(WaitTime: Integer; Tolerance: Single; Area: TBox): TPointArray;
var
BitmapBefore, BitmapAfter: TSimbaImage;
begin
Expand Down

0 comments on commit 3a26f44

Please sign in to comment.