Simba Code:
function TMFinder.CountColorTolerance(Color, xs, ys, xe, ye, Tolerance: Integer): Integer;
var
PtrData: TRetData;
Ptr: PRGB32;
PtrInc: Integer;
dX, dY, xx, yy: Integer;
compare: TCTSCompareFunction;
ctsinfo: TCTSInfo;
begin
Result := 0;
DefaultOperations(xs, ys, xe, ye);
dX := xe - xs;
dY := ye - ys;
PtrData := TClient(Client).IOManager.ReturnData(xs, ys, dX + 1, dY + 1);
Ptr := PtrData.Ptr;
PtrInc := PtrData.IncPtrWith;
result := 0;
ctsinfo := Create_CTSInfo(Color, Tolerance);
compare := Get_CTSCompare(Self.CTS);
for yy := ys to ye do
begin;
for xx := xs to xe do
begin
if compare(ctsinfo, Ptr) then
inc(result);
Inc(Ptr);
end;
Inc(Ptr, PtrInc)
end;
Free_CTSInfo(ctsinfo);
TClient(Client).IOManager.FreeReturnData;
end;
Uses the global CTS aka the current CTS before the function was called.