mirror of
https://github.com/moparisthebest/Simba
synced 2025-02-11 21:00:13 -05:00
libMML: Swapped tolerance parameters.
pyMML: Added findColorTolerance and findColorsTolerance.
This commit is contained in:
parent
a103641897
commit
9f6cdb2de3
@ -13,6 +13,7 @@ type
|
|||||||
|
|
||||||
Const
|
Const
|
||||||
RESULT_OK = 0;
|
RESULT_OK = 0;
|
||||||
|
RESULT_FALSE = 1;
|
||||||
RESULT_ERROR = -1;
|
RESULT_ERROR = -1;
|
||||||
|
|
||||||
MOUSE_UP = 0;
|
MOUSE_UP = 0;
|
||||||
@ -101,11 +102,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function findColor(var x, y: integer; color, x1, y1, x2, y2: integer): integer;
|
function findColor(var x, y: integer; color, x1, y1, x2, y2: integer): integer;
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
C.MFinder.FindColor(x, y, color, x1, y1, x2, y2);
|
if C.MFinder.FindColor(x, y, color, x1, y1, x2, y2) then
|
||||||
|
result := RESULT_OK
|
||||||
|
else
|
||||||
|
result := RESULT_FALSE;
|
||||||
except on e : Exception do
|
except on e : Exception do
|
||||||
begin
|
begin
|
||||||
result := RESULT_ERROR;
|
result := RESULT_ERROR;
|
||||||
@ -114,107 +117,68 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function returnpoints: PTPoint; cdecl;
|
function findColorTolerance(var x, y: integer; color, tol, x1, y1, x2, y2: integer): integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
result := AllocMem(sizeof(TPoint) * 2);
|
try
|
||||||
result[0].x := 5;
|
if C.MFinder.FindColorTolerance(x, y, color, x1, y1, x2, y2, tol) then
|
||||||
result[0].y := 10;
|
result := RESULT_OK
|
||||||
result[1].x := 20;
|
else
|
||||||
result[1].y := 30;
|
result := RESULT_FALSE;
|
||||||
|
except on e : Exception do
|
||||||
|
begin
|
||||||
|
result := RESULT_ERROR;
|
||||||
|
last_error := PChar(e.Message);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function printpoints(b: PTPoint; len: integer): boolean; cdecl;
|
function findColors(var ptr: PTPoint; color, x1, y1, x2, y2: integer): integer;
|
||||||
var i:integer;
|
|
||||||
begin
|
|
||||||
for i := 0 to len - 1 do
|
|
||||||
writeln('X, Y: (' + inttostr(b[i].x) + ', ' + inttostr(b[i].y) + ')');
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure hoi(var i: integer); cdecl;
|
|
||||||
begin
|
|
||||||
i := i + 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{function givedtm:PPDTM; cdecl;
|
|
||||||
var
|
var
|
||||||
dtm: PPDTM;
|
TPA: TPointArray;
|
||||||
begin
|
begin
|
||||||
writeln('Size: ' + inttostr(sizeof(pdtm)));
|
try
|
||||||
writeln('Size: ' + inttostr(sizeof(ptruint)));
|
C.MFinder.FindColors(TPA, color, x1, y1, x2, y2);
|
||||||
dtm := AllocMem(sizeof(pdtm));
|
except on e : Exception do
|
||||||
initdtm(dtm^,2);
|
begin
|
||||||
result:=dtm;
|
result := RESULT_ERROR;
|
||||||
dtm^.n := PChar('wat');
|
last_error := PChar(e.Message);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
ptr := AllocMem(sizeof(tpoint) * (length(TPA) + 1));
|
||||||
|
PInteger(ptr)[0] := length(TPA);
|
||||||
|
Move(TPA[0], ptr[1], length(TPA)*sizeof(tpoint));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function givedtm2:PDTM; cdecl;
|
function findColorsTolerance(var ptr: PTPoint; color, tol, x1, y1, x2, y2: integer): integer;
|
||||||
|
|
||||||
var
|
var
|
||||||
dtm: pdtm;
|
TPA: TPointArray;
|
||||||
begin
|
begin
|
||||||
initdtm(dtm,2);
|
try
|
||||||
result:=dtm;
|
C.MFinder.FindColorsTolerance(TPA, color, x1, y1, x2, y2, tol);
|
||||||
//result.n := PChar('wat');
|
except on e : Exception do
|
||||||
//writeln('woohoo');
|
begin
|
||||||
end; }
|
result := RESULT_ERROR;
|
||||||
|
last_error := PChar(e.Message);
|
||||||
function returnarray: tpointarray; cdecl;
|
end;
|
||||||
var
|
end;
|
||||||
i:integer;
|
ptr := AllocMem(sizeof(tpoint) * (length(TPA) + 1));
|
||||||
begin
|
PInteger(ptr)[0] := length(TPA);
|
||||||
setlength(result,5);
|
Move(TPA[0], ptr[1], length(TPA)*sizeof(tpoint));
|
||||||
for i := 0 to high(result) do
|
|
||||||
result[i] := Point(i * 50, i + 50);
|
|
||||||
writeln('res: ' + IntToStr(PtrUInt(result)));
|
|
||||||
gr := @result[0];
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure printarray2(var arr: TPointArray); cdecl;
|
|
||||||
var i:integer;
|
|
||||||
begin
|
|
||||||
for i := 0 to high(arr) do
|
|
||||||
writeln(inttostr(arr[i].x) + ',' + inttostr(arr[i].y));
|
|
||||||
setlength(arr,0);
|
|
||||||
writeln('GR: ' + inttostr(tpoint(tpointarray(gr)[0]).y));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure printarray(arr: PTPoint); cdecl;
|
|
||||||
var
|
|
||||||
i:integer;
|
|
||||||
arr2: TPointArray;
|
|
||||||
begin
|
|
||||||
writeln('arr: ' + IntToStr(PtrUInt(@arr[0])));
|
|
||||||
setlength(arr2,0);
|
|
||||||
arr2 := @arr[0];
|
|
||||||
writeln('arr2: ' + IntToStr(PtrUInt(@arr2[0])));
|
|
||||||
{ for i := 0 to 4 do
|
|
||||||
writeln(inttostr(arr[i].x) + ',' + inttostr(arr[i].y));
|
|
||||||
|
|
||||||
writeln(length(arr2));
|
|
||||||
for i := 0 to high(arr2) do
|
|
||||||
writeln(inttostr(arr2[i].x) + ',' + inttostr(arr2[i].y)); }
|
|
||||||
|
|
||||||
printarray2(arr2);
|
|
||||||
writeln(inttostr(length(arr2)));
|
|
||||||
writeln(inttostr(arr[0].x) + ',' + inttostr(arr[0].y));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure fpc_freemem_(p:pointer); cdecl;
|
procedure fpc_freemem_(p:pointer); cdecl;
|
||||||
begin
|
begin
|
||||||
writeln('free: ' + inttostr(qword(p)));
|
|
||||||
freemem(pointer(ptruint(p)));
|
freemem(pointer(ptruint(p)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fpc_allocmem_(size: ptruint): pointer; cdecl;
|
function fpc_allocmem_(size: ptruint): pointer; cdecl;
|
||||||
begin
|
begin
|
||||||
result:=AllocMem(size);
|
result:= AllocMem(size);
|
||||||
writeln('alloc: ' + inttostr(qword(result)));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fpc_reallocmem_(size: ptruint; ptr: pointer): pointer;
|
function fpc_reallocmem_(size: ptruint; ptr: pointer): pointer;
|
||||||
begin
|
begin
|
||||||
result:=ReAllocMem(ptr, size);
|
result:= ReAllocMem(ptr, size);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -228,12 +192,9 @@ exports
|
|||||||
|
|
||||||
{ Finder }
|
{ Finder }
|
||||||
findColor,
|
findColor,
|
||||||
|
findColors,
|
||||||
|
|
||||||
returnpoints,
|
{ Mem Management }
|
||||||
printpoints,
|
|
||||||
hoi,
|
|
||||||
returnarray,
|
|
||||||
printarray,
|
|
||||||
fpc_freemem_,
|
fpc_freemem_,
|
||||||
fpc_allocmem_,
|
fpc_allocmem_,
|
||||||
fpc_reallocmem_;
|
fpc_reallocmem_;
|
||||||
|
@ -20,14 +20,22 @@ class Color(object):
|
|||||||
self._mc = MC
|
self._mc = MC
|
||||||
self._initialiseDLLFuncs()
|
self._initialiseDLLFuncs()
|
||||||
|
|
||||||
def find(self, box, color):
|
def find(self, box, color, tol = 0):
|
||||||
x, y = (c_int(-1), c_int(-1))
|
x, y = (c_int(-1), c_int(-1))
|
||||||
self._mc.dll.findColor(byref(x), byref(y), color, *box)
|
if tol is 0:
|
||||||
|
ret = self._mc.dll.findColor(byref(x), byref(y), color, *box)
|
||||||
|
else:
|
||||||
|
ret = self._mc.dll.findColorTolerance(byref(x), byref(y), color,
|
||||||
|
tol, *box)
|
||||||
return (x, y)
|
return (x, y)
|
||||||
|
|
||||||
def findAll(self, box, color):
|
def findAll(self, box, color, tol = 0):
|
||||||
ptr = PPOINT()
|
ptr = PPOINT()
|
||||||
self._mc.dll.findColors(byref(ptr), color, *box)
|
if tol is 0:
|
||||||
|
self._mc.dll.findColors(byref(ptr), color, *box)
|
||||||
|
else:
|
||||||
|
self._mc.dll.findColors(byref(ptr), color, tol, *box)
|
||||||
|
|
||||||
arr = PascalArray(POINT, ptr, self._mc)
|
arr = PascalArray(POINT, ptr, self._mc)
|
||||||
print 'Length:', len(arr)
|
print 'Length:', len(arr)
|
||||||
# for i in range(len(arr)):
|
# for i in range(len(arr)):
|
||||||
|
Loading…
Reference in New Issue
Block a user