Added new DTM Finding. Not done yet, but getting there.

Needs a few obvious optimizations, and rotated isn't implemented yet.
Needs a stress-test script.

Added a script to test the difference between FindColorsTolerance and FindColorsToleranceOptimisation.



git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@260 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2009-12-01 23:41:43 +00:00
parent 17cb6596cc
commit c0132294be
9 changed files with 832 additions and 800 deletions

View File

@ -11,7 +11,7 @@
<TargetFileExt Value=""/>
<Icon Value="0"/>
<UseXPManifest Value="True"/>
<ActiveEditorIndexAtStart Value="0"/>
<ActiveEditorIndexAtStart Value="2"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -30,15 +30,15 @@
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<Units Count="19">
<Units Count="22">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<CursorPos X="23" Y="98"/>
<TopLine Value="84"/>
<CursorPos X="88" Y="89"/>
<TopLine Value="61"/>
<EditorIndex Value="0"/>
<UsageCount Value="38"/>
<UsageCount Value="66"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -46,15 +46,15 @@
<UnitName Value="CustApp"/>
<CursorPos X="15" Y="51"/>
<TopLine Value="32"/>
<UsageCount Value="9"/>
<UsageCount Value="7"/>
</Unit1>
<Unit2>
<Filename Value="../../Units/MMLCore/client.pas"/>
<UnitName Value="Client"/>
<CursorPos X="40" Y="5"/>
<TopLine Value="5"/>
<EditorIndex Value="2"/>
<UsageCount Value="14"/>
<CursorPos X="21" Y="51"/>
<TopLine Value="35"/>
<EditorIndex Value="6"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
@ -62,15 +62,15 @@
<UnitName Value="windowutil"/>
<CursorPos X="110" Y="30"/>
<TopLine Value="3"/>
<UsageCount Value="9"/>
<UsageCount Value="7"/>
</Unit3>
<Unit4>
<Filename Value="../../Units/MMLCore/window.pas"/>
<UnitName Value="Window"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="6"/>
<UsageCount Value="13"/>
<CursorPos X="55" Y="251"/>
<TopLine Value="236"/>
<EditorIndex Value="9"/>
<UsageCount Value="27"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
@ -78,31 +78,33 @@
<UnitName Value="colour_conv"/>
<CursorPos X="24" Y="7"/>
<TopLine Value="37"/>
<UsageCount Value="9"/>
<UsageCount Value="7"/>
</Unit5>
<Unit6>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<UnitName Value="finder"/>
<CursorPos X="37" Y="11"/>
<TopLine Value="1"/>
<UsageCount Value="17"/>
<CursorPos X="52" Y="1654"/>
<TopLine Value="1645"/>
<EditorIndex Value="2"/>
<UsageCount Value="31"/>
<Loaded Value="True"/>
</Unit6>
<Unit7>
<Filename Value="../../Units/MMLCore/input.pas"/>
<UnitName Value="Input"/>
<CursorPos X="56" Y="49"/>
<TopLine Value="24"/>
<EditorIndex Value="1"/>
<UsageCount Value="13"/>
<EditorIndex Value="5"/>
<UsageCount Value="27"/>
<Loaded Value="True"/>
</Unit7>
<Unit8>
<Filename Value="../../Units/MMLCore/mufasatypes.pas"/>
<UnitName Value="MufasaTypes"/>
<CursorPos X="27" Y="50"/>
<TopLine Value="36"/>
<EditorIndex Value="7"/>
<UsageCount Value="15"/>
<CursorPos X="1" Y="88"/>
<TopLine Value="76"/>
<EditorIndex Value="10"/>
<UsageCount Value="29"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
@ -110,195 +112,220 @@
<UnitName Value="ocr"/>
<CursorPos X="11" Y="361"/>
<TopLine Value="330"/>
<EditorIndex Value="3"/>
<UsageCount Value="14"/>
<EditorIndex Value="7"/>
<UsageCount Value="28"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="../../../../Documents/fpc/rtl/objpas/sysutils/diskh.inc"/>
<CursorPos X="10" Y="18"/>
<TopLine Value="1"/>
<UsageCount Value="10"/>
<UsageCount Value="8"/>
</Unit10>
<Unit11>
<Filename Value="../../Units/MMLCore/files.pas"/>
<UnitName Value="files"/>
<CursorPos X="5" Y="42"/>
<TopLine Value="27"/>
<UsageCount Value="10"/>
<UsageCount Value="8"/>
</Unit11>
<Unit12>
<Filename Value="../../../../Documents/lazarus/lcl/graphics.pp"/>
<UnitName Value="Graphics"/>
<CursorPos X="3" Y="1426"/>
<TopLine Value="1411"/>
<UsageCount Value="10"/>
<UsageCount Value="8"/>
</Unit12>
<Unit13>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<UnitName Value="bitmaps"/>
<CursorPos X="11" Y="736"/>
<TopLine Value="722"/>
<EditorIndex Value="5"/>
<UsageCount Value="12"/>
<CursorPos X="32" Y="835"/>
<TopLine Value="850"/>
<EditorIndex Value="1"/>
<UsageCount Value="26"/>
<Loaded Value="True"/>
</Unit13>
<Unit14>
<Filename Value="../../../../Documents/fpc/rtl/inc/objpash.inc"/>
<CursorPos X="22" Y="177"/>
<TopLine Value="162"/>
<UsageCount Value="10"/>
<UsageCount Value="8"/>
</Unit14>
<Unit15>
<Filename Value="../../../../Documents/lazarus/lcl/intfgraphics.pas"/>
<UnitName Value="IntfGraphics"/>
<CursorPos X="30" Y="2975"/>
<TopLine Value="2959"/>
<UsageCount Value="10"/>
<UsageCount Value="8"/>
</Unit15>
<Unit16>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<UnitName Value="mmlpsthread"/>
<CursorPos X="3" Y="154"/>
<TopLine Value="235"/>
<UsageCount Value="10"/>
<UsageCount Value="8"/>
</Unit16>
<Unit17>
<Filename Value="../../../../Documents/fpc/rtl/i386/mmx.pp"/>
<UnitName Value="mmx"/>
<CursorPos X="80" Y="15"/>
<TopLine Value="71"/>
<UsageCount Value="10"/>
<UsageCount Value="8"/>
</Unit17>
<Unit18>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/ocr.inc"/>
<CursorPos X="20" Y="5"/>
<TopLine Value="1"/>
<EditorIndex Value="4"/>
<UsageCount Value="10"/>
<EditorIndex Value="8"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<UnitName Value="dtm"/>
<CursorPos X="31" Y="74"/>
<TopLine Value="123"/>
<EditorIndex Value="4"/>
<UsageCount Value="24"/>
<Loaded Value="True"/>
</Unit19>
<Unit20>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<UnitName Value="dtmutil"/>
<CursorPos X="54" Y="196"/>
<TopLine Value="173"/>
<EditorIndex Value="3"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit20>
<Unit21>
<Filename Value="../../../../Documents/fpc/packages/fcl-base/src/custapp.pp"/>
<UnitName Value="CustApp"/>
<CursorPos X="59" Y="48"/>
<TopLine Value="18"/>
<UsageCount Value="9"/>
</Unit21>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="656" Column="18" TopLine="636"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1738" Column="59" TopLine="1718"/>
</Position1>
<Position2>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<Caret Line="62" Column="33" TopLine="47"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1743" Column="53" TopLine="1718"/>
</Position2>
<Position3>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="653" Column="39" TopLine="637"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1652" Column="33" TopLine="1643"/>
</Position3>
<Position4>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="52" Column="40" TopLine="37"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1661" Column="1" TopLine="1643"/>
</Position4>
<Position5>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="73" Column="33" TopLine="58"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1664" Column="17" TopLine="1637"/>
</Position5>
<Position6>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="373" Column="39" TopLine="368"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1610" Column="19" TopLine="1594"/>
</Position6>
<Position7>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<Caret Line="98" Column="27" TopLine="91"/>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<Caret Line="41" Column="23" TopLine="26"/>
</Position7>
<Position8>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="656" Column="33" TopLine="637"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1607" Column="4" TopLine="1644"/>
</Position8>
<Position9>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="63" Column="37" TopLine="47"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1420" Column="24" TopLine="1407"/>
</Position9>
<Position10>
<Filename Value="project1.lpr"/>
<Caret Line="68" Column="30" TopLine="63"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1603" Column="51" TopLine="1638"/>
</Position10>
<Position11>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<Caret Line="487" Column="3" TopLine="469"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1609" Column="1" TopLine="1600"/>
</Position11>
<Position12>
<Filename Value="project1.lpr"/>
<Caret Line="81" Column="4" TopLine="66"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1656" Column="123" TopLine="1644"/>
</Position12>
<Position13>
<Filename Value="project1.lpr"/>
<Caret Line="60" Column="4" TopLine="45"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1661" Column="42" TopLine="1651"/>
</Position13>
<Position14>
<Filename Value="project1.lpr"/>
<Caret Line="81" Column="4" TopLine="66"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1669" Column="49" TopLine="1654"/>
</Position14>
<Position15>
<Filename Value="project1.lpr"/>
<Caret Line="60" Column="4" TopLine="45"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1664" Column="1" TopLine="1644"/>
</Position15>
<Position16>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="11" Column="67" TopLine="1"/>
<Filename Value="project1.lpr"/>
<Caret Line="79" Column="40" TopLine="54"/>
</Position16>
<Position17>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="466" Column="18" TopLine="451"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1620" Column="20" TopLine="1604"/>
</Position17>
<Position18>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="477" Column="36" TopLine="45"/>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<Caret Line="39" Column="27" TopLine="24"/>
</Position18>
<Position19>
<Filename Value="../../Units/MMLCore/ocr.pas"/>
<Caret Line="493" Column="19" TopLine="478"/>
<Filename Value="../../Units/MMLCore/dtmutil.pas"/>
<Caret Line="40" Column="27" TopLine="24"/>
</Position19>
<Position20>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<Caret Line="98" Column="33" TopLine="91"/>
<Filename Value="project1.lpr"/>
<Caret Line="90" Column="11" TopLine="64"/>
</Position20>
<Position21>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="33" Column="53" TopLine="31"/>
<Filename Value="project1.lpr"/>
<Caret Line="78" Column="19" TopLine="61"/>
</Position21>
<Position22>
<Filename Value="project1.lpr"/>
<Caret Line="12" Column="6" TopLine="1"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1796" Column="59" TopLine="1771"/>
</Position22>
<Position23>
<Filename Value="project1.lpr"/>
<Caret Line="41" Column="17" TopLine="23"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1789" Column="43" TopLine="1774"/>
</Position23>
<Position24>
<Filename Value="project1.lpr"/>
<Caret Line="96" Column="16" TopLine="75"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="707" Column="17" TopLine="697"/>
</Position24>
<Position25>
<Filename Value="../../Units/MMLCore/input.pas"/>
<Caret Line="47" Column="65" TopLine="33"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="51" Column="36" TopLine="36"/>
</Position25>
<Position26>
<Filename Value="project1.lpr"/>
<Caret Line="13" Column="25" TopLine="1"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="1633" Column="15" TopLine="1619"/>
</Position26>
<Position27>
<Filename Value="project1.lpr"/>
<Caret Line="96" Column="39" TopLine="82"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="51" Column="36" TopLine="36"/>
</Position27>
<Position28>
<Filename Value="../../Units/MMLCore/input.pas"/>
<Caret Line="47" Column="33" TopLine="33"/>
<Filename Value="project1.lpr"/>
<Caret Line="86" Column="19" TopLine="71"/>
</Position28>
<Position29>
<Filename Value="../../Units/MMLCore/bitmaps.pas"/>
<Caret Line="477" Column="35" TopLine="469"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="82" Column="26" TopLine="63"/>
</Position29>
<Position30>
<Filename Value="project1.lpr"/>
<Caret Line="97" Column="12" TopLine="73"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="84" Column="26" TopLine="63"/>
</Position30>
</JumpHistory>
</ProjectOptions>
@ -309,6 +336,13 @@
<OtherUnitFiles Value="$(ProjPath)/../../Units/MMLCore/;$(ProjPath)/../../Units/Misc/;$(ProjPath)/../../Units/MMLAddon/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/$(LCLWidgetType)/;$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/;$(ProjPath)/../../Units/Linux/;$(LazarusDir)/components/mouseandkeyinput/"/>
</SearchPaths>
<CodeGeneration>
<Checks>
<IOChecks Value="True"/>
<RangeChecks Value="True"/>
<OverflowChecks Value="True"/>
<StackChecks Value="True"/>
</Checks>
<VerifyObjMethodCallValidity Value="True"/>
<Optimizations>
<OptimizationLevel Value="3"/>
</Optimizations>

View File

@ -10,7 +10,7 @@ uses
Forms,Interfaces,
LCLIntf,
Client,
bitmaps,x ,mufasatypes
bitmaps,x ,mufasatypes,dtm,dtmutil
{ you can add units after this };
@ -36,7 +36,9 @@ var
ErrorMsg: String;
Time: DWord;
C: TClient;
I{, W, H, X, Y}: Integer;
I: Integer;
dtm: pdtm;
p:tpointarray;
bmp: TMufasaBitmap;
begin
@ -57,7 +59,74 @@ begin
{ add your program here }
C := TClient.Create;
{$WARNING Change This Path!}
bmp := TMufasaBitmap.Create;
bmp.SetSize(10,10);
FillChar(bmp.FData[0],sizeof(trgb32)*100, 0);
bmp.FastSetPixel(8,8,255);
bmp.FastSetPixel(9,9,255);
bmp.FastSetPixel(7,7,255);
bmp.FastSetPixel(9,8,255);
bmp.FastSetPixel(8,9,255);
C.MWindow.SetTarget(bmp);
initdtm(dtm, 3);
dtm.p[0] := Point(2, 2);
dtm.p[1] := Point(-3, -3);
dtm.p[2] := Point(0, 0);
dtm.c[0] := 255;
dtm.asz[1] := 0;
dtm.ash[1] := dtm_Rectangle;
setlength(p, 0);
C.MFinder.FindDTMs(dtm, p, 0, 0, 9, 9);
for i := 0 to high(p) do
writeln(format('%d: (%d, %d)', [i, p[i].x, p[i].y]));
//bmp.OnDestroy:=nil;
bmp.Free;
C.Free;
// stop program loop
Terminate;
end;
constructor MufasaTests.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor MufasaTests.Destroy;
begin
inherited Destroy;
end;
procedure MufasaTests.WriteHelp;
begin
{ add your help code here }
writeln('Usage: ',ExeName,' -h');
end;
var
Application: MufasaTests;
{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}
begin
Application:=MufasaTests.Create(nil);
Application.Title:='My Application';
Application.Run;
Application.Free;
end.
{ {$WARNING Change This Path!}
C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/Fonts/');
//C.MOCR.InitTOCR('/home/merlijn/Programs/mufasa/ben/');
@ -95,43 +164,4 @@ begin
//C.MInput.ClickMouse(5,5, mouse_Left);
sleep(2000);
C.MInput.SendText('a');
C.Free;
bmp.OnDestroy:=nil;
bmp.Free;
// stop program loop
Terminate;
end;
constructor MufasaTests.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor MufasaTests.Destroy;
begin
inherited Destroy;
end;
procedure MufasaTests.WriteHelp;
begin
{ add your help code here }
writeln('Usage: ',ExeName,' -h');
end;
var
Application: MufasaTests;
{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}
begin
Application:=MufasaTests.Create(nil);
Application.Title:='My Application';
Application.Run;
Application.Free;
end.
C.MInput.SendText('a'); }

View File

@ -33,16 +33,14 @@
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="253">
<Units Count="255">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="project1"/>
<CursorPos X="17" Y="41"/>
<TopLine Value="26"/>
<EditorIndex Value="12"/>
<TopLine Value="16"/>
<UsageCount Value="205"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
@ -65,7 +63,7 @@
<UnitName Value="CompTypes"/>
<CursorPos X="13" Y="531"/>
<TopLine Value="523"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit3>
<Unit4>
<Filename Value="mufasatypes.pas"/>
@ -155,7 +153,7 @@
<UnitName Value="xlib"/>
<CursorPos X="47" Y="1272"/>
<TopLine Value="1257"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit16>
<Unit17>
<Filename Value="testunit.pas"/>
@ -164,9 +162,9 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="TestUnit"/>
<CursorPos X="50" Y="950"/>
<TopLine Value="944"/>
<EditorIndex Value="7"/>
<CursorPos X="79" Y="950"/>
<TopLine Value="874"/>
<EditorIndex Value="4"/>
<UsageCount Value="202"/>
<Loaded Value="True"/>
</Unit17>
@ -182,7 +180,7 @@
<UnitName Value="CompInput"/>
<CursorPos X="6" Y="462"/>
<TopLine Value="449"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit19>
<Unit20>
<Filename Value="../FPC/FPCCheckout/rtl/win/wininc/func.inc"/>
@ -221,9 +219,9 @@
<Filename Value="../../Units/MMLCore/client.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Client"/>
<CursorPos X="25" Y="49"/>
<TopLine Value="37"/>
<EditorIndex Value="2"/>
<CursorPos X="20" Y="66"/>
<TopLine Value="55"/>
<EditorIndex Value="1"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit25>
@ -231,8 +229,8 @@
<Filename Value="../../Units/MMLCore/mufasatypes.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="MufasaTypes"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<CursorPos X="11" Y="89"/>
<TopLine Value="81"/>
<EditorIndex Value="0"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
@ -256,9 +254,9 @@
<Filename Value="../../Units/MMLCore/window.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Window"/>
<CursorPos X="13" Y="462"/>
<TopLine Value="452"/>
<EditorIndex Value="5"/>
<CursorPos X="31" Y="262"/>
<TopLine Value="247"/>
<EditorIndex Value="3"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit29>
@ -272,9 +270,9 @@
<Unit31>
<Filename Value="../../Units/MMLCore/windowutil.pas"/>
<UnitName Value="windowutil"/>
<CursorPos X="81" Y="21"/>
<TopLine Value="14"/>
<EditorIndex Value="21"/>
<CursorPos X="23" Y="8"/>
<TopLine Value="1"/>
<EditorIndex Value="10"/>
<UsageCount Value="55"/>
<Loaded Value="True"/>
</Unit31>
@ -283,26 +281,24 @@
<UnitName Value="Input"/>
<CursorPos X="71" Y="274"/>
<TopLine Value="242"/>
<EditorIndex Value="4"/>
<UsageCount Value="93"/>
<Loaded Value="True"/>
</Unit32>
<Unit33>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="finder"/>
<CursorPos X="57" Y="858"/>
<TopLine Value="828"/>
<CursorPos X="108" Y="76"/>
<TopLine Value="59"/>
<EditorIndex Value="5"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit33>
<Unit34>
<Filename Value="../../../lazarus/lcl/graphics.pp"/>
<UnitName Value="Graphics"/>
<CursorPos X="14" Y="1035"/>
<TopLine Value="1025"/>
<EditorIndex Value="16"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit34>
<Unit35>
<Filename Value="../../Units/MMLAddon/mmlthread.pas"/>
@ -315,9 +311,9 @@
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="mmlpsthread"/>
<CursorPos X="40" Y="49"/>
<TopLine Value="51"/>
<EditorIndex Value="24"/>
<CursorPos X="19" Y="258"/>
<TopLine Value="245"/>
<EditorIndex Value="11"/>
<UsageCount Value="202"/>
<Loaded Value="True"/>
</Unit36>
@ -339,14 +335,14 @@
<UnitName Value="types"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit39>
<Unit40>
<Filename Value="../../../FPC/FPCCheckout/rtl/objpas/typinfo.pp"/>
<UnitName Value="typinfo"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit40>
<Unit41>
<Filename Value="../../Units/PascalScript/uPSC_forms.pas"/>
@ -366,7 +362,7 @@
<UnitName Value="LResources"/>
<CursorPos X="3" Y="1396"/>
<TopLine Value="1396"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit43>
<Unit44>
<Filename Value="../../../lazarus/components/synedit/synmemo.pas"/>
@ -384,9 +380,9 @@
</Unit45>
<Unit46>
<Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/>
<CursorPos X="56" Y="87"/>
<TopLine Value="81"/>
<EditorIndex Value="25"/>
<CursorPos X="1" Y="55"/>
<TopLine Value="38"/>
<EditorIndex Value="7"/>
<UsageCount Value="100"/>
<Loaded Value="True"/>
</Unit46>
@ -408,7 +404,7 @@
<UnitName Value="bitmaps"/>
<CursorPos X="1" Y="352"/>
<TopLine Value="343"/>
<EditorIndex Value="3"/>
<EditorIndex Value="2"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
</Unit49>
@ -417,7 +413,7 @@
<UnitName Value="FPCanvas"/>
<CursorPos X="96" Y="409"/>
<TopLine Value="188"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit50>
<Unit51>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/colour.inc"/>
@ -477,27 +473,21 @@
<UnitName Value="LCLIntf"/>
<CursorPos X="10" Y="76"/>
<TopLine Value="66"/>
<EditorIndex Value="18"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit59>
<Unit60>
<Filename Value="../../../lazarus/lcl/intfgraphics.pas"/>
<UnitName Value="IntfGraphics"/>
<CursorPos X="3" Y="1336"/>
<TopLine Value="1334"/>
<EditorIndex Value="19"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit60>
<Unit61>
<Filename Value="../../../lazarus/lcl/graphtype.pp"/>
<UnitName Value="GraphType"/>
<CursorPos X="45" Y="1006"/>
<TopLine Value="994"/>
<EditorIndex Value="20"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit61>
<Unit62>
<Filename Value="../../../FPC/FPCCheckout/packages/fcl-image/src/fpcolors.inc"/>
@ -541,16 +531,14 @@
<UnitName Value="CompMaths"/>
<CursorPos X="26" Y="43"/>
<TopLine Value="14"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit68>
<Unit69>
<Filename Value="../../../FPC/FPCCheckout/rtl/objpas/math.pp"/>
<UnitName Value="math"/>
<CursorPos X="10" Y="155"/>
<TopLine Value="145"/>
<EditorIndex Value="10"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit69>
<Unit70>
<Filename Value="../../../FPC/FPCCheckout/rtl/inc/systemh.inc"/>
@ -568,8 +556,8 @@
<Filename Value="../../Units/MMLCore/colour_conv.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="colour_conv"/>
<CursorPos X="3" Y="164"/>
<TopLine Value="187"/>
<CursorPos X="27" Y="207"/>
<TopLine Value="152"/>
<UsageCount Value="201"/>
</Unit72>
<Unit73>
@ -588,10 +576,8 @@
<Unit75>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/other.inc"/>
<CursorPos X="1" Y="78"/>
<TopLine Value="62"/>
<EditorIndex Value="27"/>
<TopLine Value="1"/>
<UsageCount Value="46"/>
<Loaded Value="True"/>
</Unit75>
<Unit76>
<Filename Value="../../Units/PascalScript/uPSCompiler.pas"/>
@ -631,9 +617,7 @@
<UnitName Value="plugins"/>
<CursorPos X="36" Y="32"/>
<TopLine Value="32"/>
<EditorIndex Value="1"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
</Unit81>
<Unit82>
<Filename Value="../../../Compilertje/Units/CogatUnits/compfiles.pas"/>
@ -690,9 +674,7 @@
<UnitName Value="Controls"/>
<CursorPos X="3" Y="1426"/>
<TopLine Value="1416"/>
<EditorIndex Value="23"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit90>
<Unit91>
<Filename Value="../../../lazarus/lcl/include/control.inc"/>
@ -725,9 +707,11 @@
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="dtm"/>
<CursorPos X="52" Y="405"/>
<TopLine Value="398"/>
<CursorPos X="3" Y="74"/>
<TopLine Value="59"/>
<EditorIndex Value="6"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
</Unit95>
<Unit96>
<Filename Value="../../../cogat/Units/CogatUnits/comppicker.pas"/>
@ -742,16 +726,14 @@
<UnitName Value="colourpicker"/>
<CursorPos X="7" Y="215"/>
<TopLine Value="205"/>
<EditorIndex Value="8"/>
<UsageCount Value="201"/>
<Loaded Value="True"/>
</Unit97>
<Unit98>
<Filename Value="../../../cogat/Units/CogatUnits/compdragger.pas"/>
<UnitName Value="CompDragger"/>
<CursorPos X="101" Y="26"/>
<TopLine Value="26"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit98>
<Unit99>
<Filename Value="../../../cogat/mainform.pas"/>
@ -782,9 +764,7 @@
<UnitName Value="Forms"/>
<CursorPos X="23" Y="660"/>
<TopLine Value="650"/>
<EditorIndex Value="22"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit102>
<Unit103>
<Filename Value="../../../usr/lib64/fpc/2.2.4/source/rtl/unix/cthreads.pp"/>
@ -816,9 +796,11 @@
</Unit106>
<Unit107>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/dtm.inc"/>
<CursorPos X="39" Y="26"/>
<TopLine Value="14"/>
<CursorPos X="21" Y="75"/>
<TopLine Value="50"/>
<EditorIndex Value="8"/>
<UsageCount Value="14"/>
<Loaded Value="True"/>
</Unit107>
<Unit108>
<Filename Value="../../../Documents/lazarus/lcl/graphics.pp"/>
@ -921,15 +903,13 @@
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<CursorPos X="87" Y="236"/>
<TopLine Value="232"/>
<EditorIndex Value="9"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit122>
<Unit123>
<Filename Value="../../../lazarus/lcl/include/application.inc"/>
<CursorPos X="37" Y="945"/>
<TopLine Value="925"/>
<UsageCount Value="0"/>
<UsageCount Value="10"/>
</Unit123>
<Unit124>
<Filename Value="../../../lazarus/components/synedit/syneditkeycmds.pp"/>
@ -1013,7 +993,7 @@
<UnitName Value="web"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="154"/>
<UsageCount Value="155"/>
</Unit136>
<Unit137>
<Filename Value="../../../lazarus/lcl/lazhelphtml.pas"/>
@ -1212,9 +1192,7 @@
<UnitName Value="framescript"/>
<CursorPos X="106" Y="190"/>
<TopLine Value="180"/>
<EditorIndex Value="6"/>
<UsageCount Value="147"/>
<Loaded Value="True"/>
<UsageCount Value="148"/>
</Unit161>
<Unit162>
<Filename Value="framesynedit.lrs"/>
@ -1528,8 +1506,8 @@
<UnitName Value="colourhistory"/>
<CursorPos X="3" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="11"/>
<UsageCount Value="84"/>
<EditorIndex Value="9"/>
<UsageCount Value="85"/>
<Loaded Value="True"/>
</Unit208>
<Unit209>
@ -1780,9 +1758,7 @@
<UnitName Value="about"/>
<CursorPos X="44" Y="21"/>
<TopLine Value="4"/>
<EditorIndex Value="13"/>
<UsageCount Value="47"/>
<Loaded Value="True"/>
<UsageCount Value="48"/>
</Unit245>
<Unit246>
<Filename Value="../../Units/MMLAddon/PSInc/Wrappers/file.inc"/>
@ -1794,11 +1770,9 @@
<Filename Value="../../Units/MMLAddon/internets.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="internets"/>
<CursorPos X="34" Y="7"/>
<CursorPos X="87" Y="3"/>
<TopLine Value="1"/>
<EditorIndex Value="26"/>
<UsageCount Value="41"/>
<Loaded Value="True"/>
<UsageCount Value="42"/>
</Unit247>
<Unit248>
<Filename Value="debugimageform.pas"/>
@ -1807,7 +1781,7 @@
<UnitName Value="debugimageform"/>
<CursorPos X="20" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="28"/>
<UsageCount Value="29"/>
</Unit248>
<Unit249>
<Filename Value="debugimage.pas"/>
@ -1817,9 +1791,7 @@
<UnitName Value="debugimage"/>
<CursorPos X="100" Y="103"/>
<TopLine Value="82"/>
<EditorIndex Value="14"/>
<UsageCount Value="27"/>
<Loaded Value="True"/>
<UsageCount Value="28"/>
</Unit249>
<Unit250>
<Filename Value="debugimage.lrs"/>
@ -1831,140 +1803,149 @@
<Filename Value="../../../lazarus/lcl/include/canvas.inc"/>
<CursorPos X="19" Y="141"/>
<TopLine Value="135"/>
<EditorIndex Value="17"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit251>
<Unit252>
<Filename Value="../../../lazarus/lcl/interfacebase.pp"/>
<UnitName Value="InterfaceBase"/>
<CursorPos X="3" Y="172"/>
<TopLine Value="162"/>
<EditorIndex Value="15"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit252>
<Unit253>
<Filename Value="../../../../Documents/lazarus/lcl/lclintf.pas"/>
<UnitName Value="LCLIntf"/>
<CursorPos X="77" Y="75"/>
<TopLine Value="67"/>
<UsageCount Value="10"/>
</Unit253>
<Unit254>
<Filename Value="../../../../Documents/fpc/rtl/inc/systemh.inc"/>
<CursorPos X="35" Y="574"/>
<TopLine Value="558"/>
<UsageCount Value="10"/>
</Unit254>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="testunit.pas"/>
<Caret Line="1082" Column="13" TopLine="1077"/>
<Filename Value="../../Units/MMLCore/finder.pas"/>
<Caret Line="793" Column="11" TopLine="789"/>
</Position1>
<Position2>
<Filename Value="../../Units/MMLAddon/colourpicker.pas"/>
<Caret Line="215" Column="7" TopLine="205"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="312" Column="29" TopLine="299"/>
</Position2>
<Position3>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="196" Column="27" TopLine="186"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="321" Column="17" TopLine="301"/>
</Position3>
<Position4>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="197" Column="29" TopLine="186"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="312" Column="1" TopLine="297"/>
</Position4>
<Position5>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="199" Column="39" TopLine="186"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="322" Column="54" TopLine="303"/>
</Position5>
<Position6>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="201" Column="36" TopLine="186"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="319" Column="60" TopLine="304"/>
</Position6>
<Position7>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="202" Column="28" TopLine="186"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="320" Column="23" TopLine="309"/>
</Position7>
<Position8>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="204" Column="24" TopLine="186"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="461" Column="36" TopLine="452"/>
</Position8>
<Position9>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="208" Column="32" TopLine="198"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="67" Column="43" TopLine="54"/>
</Position9>
<Position10>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="209" Column="30" TopLine="198"/>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="64" Column="40" TopLine="56"/>
</Position10>
<Position11>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="210" Column="31" TopLine="198"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="259" Column="57" TopLine="29"/>
</Position11>
<Position12>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="213" Column="28" TopLine="198"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="745" Column="34" TopLine="719"/>
</Position12>
<Position13>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="214" Column="27" TopLine="198"/>
<Filename Value="../../Units/MMLCore/window.pas"/>
<Caret Line="79" Column="44" TopLine="64"/>
</Position13>
<Position14>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="226" Column="25" TopLine="216"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="329" Column="19" TopLine="309"/>
</Position14>
<Position15>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="230" Column="35" TopLine="216"/>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="177" Column="37" TopLine="159"/>
</Position15>
<Position16>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="232" Column="42" TopLine="216"/>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="210" Column="20" TopLine="195"/>
</Position16>
<Position17>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="233" Column="30" TopLine="216"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="304" Column="1" TopLine="290"/>
</Position17>
<Position18>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="235" Column="33" TopLine="216"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="28" Column="12" TopLine="13"/>
</Position18>
<Position19>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="242" Column="74" TopLine="232"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="33" Column="46" TopLine="23"/>
</Position19>
<Position20>
<Filename Value="../../../lazarus/lcl/include/winapih.inc"/>
<Caret Line="243" Column="31" TopLine="232"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="43" Column="60" TopLine="28"/>
</Position20>
<Position21>
<Filename Value="debugimage.pas"/>
<Caret Line="121" Column="45" TopLine="111"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="46" Column="7" TopLine="31"/>
</Position21>
<Position22>
<Filename Value="debugimage.pas"/>
<Caret Line="97" Column="1" TopLine="94"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="58" Column="41" TopLine="43"/>
</Position22>
<Position23>
<Filename Value="testunit.pas"/>
<Caret Line="1082" Column="13" TopLine="1077"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="59" Column="3" TopLine="44"/>
</Position23>
<Position24>
<Filename Value="testunit.pas"/>
<Caret Line="1116" Column="82" TopLine="1111"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="73" Column="65" TopLine="58"/>
</Position24>
<Position25>
<Filename Value="testunit.pas"/>
<Caret Line="1114" Column="42" TopLine="1111"/>
<Filename Value="../../Units/MMLCore/client.pas"/>
<Caret Line="66" Column="20" TopLine="55"/>
</Position25>
<Position26>
<Filename Value="testunit.pas"/>
<Caret Line="1120" Column="35" TopLine="1111"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="75" Column="50" TopLine="60"/>
</Position26>
<Position27>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="23" Column="27" TopLine="19"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="71" Column="39" TopLine="56"/>
</Position27>
<Position28>
<Filename Value="testunit.pas"/>
<Caret Line="1113" Column="1" TopLine="1111"/>
<Filename Value="../../Units/MMLCore/dtm.pas"/>
<Caret Line="72" Column="64" TopLine="57"/>
</Position28>
<Position29>
<Filename Value="testunit.pas"/>
<Caret Line="789" Column="14" TopLine="787"/>
<Filename Value="../../Units/MMLAddon/mmlpsthread.pas"/>
<Caret Line="258" Column="19" TopLine="245"/>
</Position29>
<Position30>
<Filename Value="testunit.pas"/>
<Caret Line="387" Column="53" TopLine="375"/>
<Filename Value="../../Units/MMLAddon/PSInc/pscompile.inc"/>
<Caret Line="16" Column="25" TopLine="1"/>
</Position30>
</JumpHistory>
</ProjectOptions>

31
Tests/PS/ColourTest.mufa Normal file
View File

@ -0,0 +1,31 @@
program new;
var
p1, p2: TPointArray;
w, h: integer;
i, col: integer;
bmp: integer;
begin
SetColorToleranceSpeed(2);
bmp := LoadBitmap('/home/merlijn/Pictures/Mooi/Carina_1_by_Eeitam.png');
SetTargetBitmap(bmp);
GetClientDimensions(W, H);
writeln(inttostr(w) + ' : ' + inttostr(h));
for i := 0 to 100 do
begin
col := Random(clWhite);
writeln(inttostr(col));
FindColorsTolerance(p1, col, 0, 0, W - 1, H - 1, 40);
FindColorsToleranceOptimised(p2, col, 0, 0, W - 1, H - 1, 40);
writeln(inttostr(length(p1)) + ' : ' + inttostr(length(p2)));
if(length(p1) <> length(p2)) then
writeln('wat!');
setlength(p1,0);
setlength(p2,0);
end;
FreeBitmap(bmp);
end.

View File

@ -22,39 +22,67 @@
}
function ps_FindDTM(DTM: Integer; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
var
temp: pDTM;
begin
Result := CurrThread.Client.MDTM.FindDTM(DTM, x, y, x1, y1, x2, y2);
if CurrThread.Client.MDTM.GetDTM(DTM, temp) then
Result := CurrThread.Client.MFinder.FindDTM(temp, x, y, x1, y1, x2, y2)
else
begin
x := 0;
y := 0;
Result := False;
end;
end;
function ps_FindDTMs(DTM: Integer; out p: TPointArray; x1, y1, x2, y2: Integer): Boolean;
var
temp: pDTM;
begin
Result := CurrThread.Client.MDTM.FindDTMs(DTM, p, x1, y1, x2, y2);
if CurrThread.Client.MDTM.GetDTM(DTM, temp) then
Result := CurrThread.Client.MFinder.FindDTMs(temp, p, x1, y1, x2, y2)
else
begin
setlength(p,0);
Result := False;
end;
end;
function ps_FindDTMRotated(DTM: Integer; out x, y: Integer; x1, y1, x2, y2:
Integer; sAngle, eAngle, aStep: Extended;
out aFound: Extended): Boolean;
var
temp: pDTM;
begin
Result := CurrThread.Client.MDTM.FindDTMRotated(DTM, x, y, x1, y1, x2, y2,
sAngle, eAngle, aStep, aFound);
if CurrThread.Client.MDTM.GetDTM(DTM, temp) then
Result := CurrThread.Client.MFinder.FindDTMRotated(temp, x, y, x1, y1, x2, y2, sAngle, eAngle, aStep, aFound)
else
begin
x := 0;
y := 0;
Result := False;
end;
end;
function ps_FindDTMsRotated(DTM: Integer; out x, y: Integer; x1, y1, x2, y2:
Integer; sAngle, eAngle, aStep: Extended;
out aFound: Extended): Boolean;
function ps_FindDTMsRotated(DTM: Integer; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean;
var
temp: pDTM;
begin
Result := CurrThread.Client.MDTM.FindDTMRotated(DTM, x, y, x1, y1, x2, y2,
sAngle, eAngle, aStep, aFound);
if CurrThread.Client.MDTM.GetDTM(DTM, temp) then
Result := CurrThread.Client.MFinder.FindDTMsRotated(temp, Points, x1, y1, x2, y2,
sAngle, eAngle, aStep, aFound)
else
Result := False;
end;
function ps_FindDTMsRotated(DTM: Integer; out Points: TPointArray; x1,
{function ps_FindDTMsRotated(DTM: Integer; out Points: TPointArray; x1,
y1, x2, y2: Integer; sAngle, eAngle,
aStep: Extended; out aFound: T2DExtendedArray)
: Boolean;
begin
Result := CurrThread.Client.MDTM.FindDTMsRotated(DTM, Points, x1, y1, x2, y2,
sAngle, eAngle, aStep, aFound);
end;
end; }
function ps_DTMFromString(DTMString: String): Integer;
var

View File

@ -33,13 +33,17 @@ uses
type
TMDTM = class(TObject)
private
public
function AddDTM(d: TDTM): Integer;
function AddpDTM(d: pDTM): Integer;
function GetDTM(index: Integer; out dtm: pDTM): Boolean;
procedure FreeDTM(DTM: Integer);
Function StringToDTM(S: String): pDTM;
function FindDTM(DTM: Integer; out x, y: Integer; x1, y1, x2,
{ function FindDTM(DTM: Integer; out x, y: Integer; x1, y1, x2,
y2: Integer): Boolean;
function FindDTMs(DTM: Integer; out Points: TPointArray; x1, y1, x2,
y2: Integer): Boolean;
@ -50,22 +54,18 @@ type
y1, x2, y2: Integer; sAngle, eAngle,
aStep: Extended; out aFound: T2DExtendedArray)
: Boolean;
function pFindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2:
Integer): Boolean;
function pFindDTMs(DTM: pDTM; out Points: TPointArray; x1, y1, x2,
y2: Integer): Boolean;
function pFindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2:
Integer): Boolean;
function pFindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2,
y2: Integer; sAngle, eAngle, aStep: Extended;
out aFound: Extended): Boolean;
y2: Integer; sAngle, eAngle, aStep: Extended;
out aFound: Extended): Boolean;
function pFindDTMsRotated(DTM: pDTM; out Points: TPointArray; x1,
y1, x2, y2: Integer; sAngle, eAngle,
aStep: Extended; out aFound: T2DExtendedArray)
: Boolean;
y1, x2, y2: Integer; sAngle, eAngle,
aStep: Extended; out aFound: T2DExtendedArray)
: Boolean;
}
constructor Create(Owner: TObject);
destructor Destroy; override;
private
function AreaShape(Color, Tolerance, Size, Shape: Integer; P: TPoint) : Boolean; inline;
private
Client: TObject;
@ -76,13 +76,6 @@ type
FreeSpots: Array Of Integer;
end;
const
dtm_Rectangle = 0;
dtm_Cross = 1;
dtm_DiagonalCross = 2;
dtm_Circle = 3;
dtm_Triangle = 4;
{
I am not sure wether I should simply copy and paste the old DTM implementation,
or rewrite it from scratch.
@ -112,6 +105,7 @@ type
TBufferByteArray = Array[0..524287] of Byte;
PBufferByteArray = ^TBufferByteArray;
constructor TMDTM.Create(Owner: TObject);
begin
inherited Create;
@ -152,102 +146,13 @@ begin
inherited Destroy;
end;
type
PMSimColor = function (Color1,Color2,Tolerance : Integer) : boolean of object;
PMGetCol = function (x, y: integer): TColor of object;
Function TMDTM.AreaShape(Color, Tolerance, Size, Shape: Integer; P: TPoint) : Boolean; inline;
Var
X, Y, S: Integer;
SimCol: PMSimColor;
GetCol: PMGetCol;
Function AreaShape(Color, Tolerance, Size, Shape: Integer; P: TPoint) : Boolean; inline;
Begin
SimCol := @TClient(Client).MFinder.SimilarColors;
GetCol := @TClient(Client).MWindow.GetColor;
Case Shape Of
dtm_Rectangle:
Begin
{
Example:
3x3
X X X
X X X
X X X
}
For X := P.X - Size To P.X + Size Do
For Y := P.Y - Size To P.Y + Size Do
If SimCol(GetCol(X, Y), Color, Tolerance) Then
Begin
Result := True;
Exit;
End;
End;
dtm_Cross:
{
Example:
3x3
X
X X X
X
}
Begin
For X := P.X - Size To P.X + Size Do
If SimCol(GetCol(X, P.Y), Color, Tolerance) Then
Begin
Result := True;
Exit;
End;
For Y := P.Y - Size To P.Y + Size Do
If SimCol(GetCol(P.X, Y), Color, Tolerance) Then
Begin
Result := True;
Exit;
End;
End;
dtm_DiagonalCross:
{
Example:
3x3
X X
X
X X
}
Begin
For S := -Size To Size Do
Begin
If SimCol(GetCol(P.X + S, P.Y + S), Color, Tolerance) Then
Begin
Result := True;
Exit;
End;
If SimCol(GetCol(P.X + S, P.Y - S), Color, Tolerance) Then
Begin
Result := True;
Exit;
End;
End;
End;
4:
Begin
raise Exception.CreateFmt('The given DTM Shape ([%d]) is not yet' +
' implemented.', [Shape]);
End;
Else
WriteLn('Incorrect Shape');
End;
Result := False;
End;
{/\
Rotates the given point (p) by A (in radians) around the point defined by cx, cy.
/\}
// Rotates the given point (p) by A (in radians) around the point defined by cx, cy.
function RotatePoint(p: TPoint; angle, mx, my: Extended): TPoint; inline;
@ -306,6 +211,7 @@ begin
Result.t[i] := PInteger(@b^[c+24])^;
end;
end;
result.l := length(result.p);
end;
function TMDTM.AddDTM(d: TDTM): Integer;
@ -380,61 +286,21 @@ begin
SetLength(DTMList[DTM].t, 0);
SetLength(DTMList[DTM].asz, 0);
SetLength(DTMList[DTM].ash, 0);
DTMList[DTM].l := 0;
except
raise Exception.CreateFmt('Invalid DTM passed to FreeDTM', []);
//WriteLn('Invalid DTM');
end;
SetLength(FreeSpots, Length(FreeSpots) + 1);
FreeSpots[High(FreeSpots)] := DTM;
end;
procedure DTMBounds(dtm: pDTM; var x1, y1, x2, y2: Integer);
var
i: Integer;
B: TBox;
begin
FillChar(b,sizeOf(TBox),0);
for i := 0 to high(dtm.p) do
begin
B.X1 := Min(B.X1, dtm.p[i].X - dtm.asz[i]);
B.Y1 := Min(B.Y1, dtm.p[i].Y - dtm.asz[i]);
B.X2 := Max(B.X2, dtm.p[i].X + dtm.asz[i]);
B.Y2 := Max(B.Y2, dtm.p[i].Y + dtm.asz[i]);
end;
{writeln(inttostr(B.x1) + ', ' + inttostr(b.y1) + ', ' + inttostr(b.x2) +
', ' + inttostr(b.y2)); }
x1 += -B.X1;
y1 += -B.Y1;
X2 -= B.X2;
Y2 -= B.Y2;
end;
// TODO
procedure DTMRotatedBounds(dtm: pDTM; var x1, y1, x2, y2: Integer);
var
i: Integer;
B: TBox;
begin
FillChar(b,sizeOf(TBox),0);
for i := 0 to high(dtm.p) do
begin
B.X1 := Min(B.X1, dtm.p[i].X - dtm.asz[i]);
B.Y1 := Min(B.Y1, dtm.p[i].Y - dtm.asz[i]);
B.X2 := Max(B.X2, dtm.p[i].X + dtm.asz[i]);
B.Y2 := Max(B.Y2, dtm.p[i].Y + dtm.asz[i]);
end;
x1 += -Sqr(B.X1);
y1 += -Sqr(B.Y1);
X2 -= Sqr(B.X2);
Y2 -= Sqr(B.Y2);
end;
{
Tries to find the given DTM (index). If found will put the point the dtm has
been found at in x, y and result to true.
}
function TMDTM.FindDTM(DTM: Integer; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
{function TMDTM.FindDTM(DTM: Integer; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
var
temp: pDTM;
begin
@ -446,90 +312,26 @@ begin
y := 0;
Result := False;
end;
end;
end; }
{
Tries to find the given pDTM. If found will put the point the dtm has
been found at in x, y and result to true.
}
function TMDTM.pFindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
var
mP: TPointArray;
I, J, H, dH: Integer;
Found: Boolean;
TempTP: TPoint;
{function TMDTM.pFindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
begin
for I := 1 to High(DTM.p) do
begin
DTM.p[I].x := DTM.p[I].x - DTM.p[0].x;
DTM.p[I].y := DTM.p[I].y - DTM.p[0].y;
end;
{writeln(inttostr(x1) + ', ' + inttostr(y1) + ', ' + inttostr(x2) +
', ' + inttostr(y2)); }
DTMBounds(DTM, x1, y1, x2, y2);
{writeln(inttostr(x1) + ', ' + inttostr(y1) + ', ' + inttostr(x2) +
', ' + inttostr(y2)); }
{If X2 > X1 then
//Exit;
If Y2 > Y1 then }
//Exit;
// Will make sure there are no out of bounds exceptions, and will make it faster
with TClient(Client) do
begin
MWindow.Freeze();
MFinder.FindColorsTolerance(mP, DTM.c[Low(DTM.c)], x1, y1, x2, y2,
DTM.t[Low(DTM.t)]);
MWindow.GetDimensions(H, dH);
end;
H := High(mP);
dH := High(DTM.p);
for I := 0 to H do
begin
// Use MainPoint's AreaSize and Shape.
// for Loop on mP, depending on the AreaShape. then on all the code beneath
// this point, use the var that is retrieved from the for loop.
Found := True;
for J := 1 to dH do
begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
//Now would be the time to Rotate TempTP
if not AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) then
begin
Found := False;
Break;
end;
end;
if Found then
begin
Result := True;
x := mP[I].X;
y := mP[I].Y;
TClient(Client).MWindow.UnFreeze();
Exit;
end;
end;
TClient(Client).MWindow.UnFreeze();
Result := False;
end;
end; }
{/\
Tries to find the given DTM (index). Will return true if it has found one or more
DTM's. All the occurances are stored in the Points (TPointArray)
/\}
function TMDTM.FindDTMs(DTM: Integer; out Points: TPointArray; x1, y1, x2, y2: Integer): Boolean;
{function TMDTM.FindDTMs(DTM: Integer; out Points: TPointArray; x1, y1, x2, y2: Integer): Boolean;
Var
temp: pDTM;
Begin
@ -540,78 +342,36 @@ Begin
SetLength(Points, 0);
Result := False;
End;
End;
End; }
{/\
Tries to find the given pDTM. Will return true if it has found one or more
DTM's. All the occurances are stored in the Points (TPointArray)
/\}
Function TMDTM.pFindDTMs(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer): Boolean;
Var
mP: TPointArray;
I, J, H, dH: Integer;
Found: Boolean;
TempTP: TPoint;
Begin
Result := False;
SetLength(Points, 0);
For I := 1 To High(DTM.p) Do
Begin
DTM.p[I].x := DTM.p[I].x - DTM.p[0].x;
DTM.p[I].y := DTM.p[I].y - DTM.p[0].y;
End;
{wat}
// Then, first find all occurances of all colours on the given client.
// Each point has a colour, and we call them C_0...C_n.
// MP denotes the points of the main point colour on the client.
// P_i denotes the points on the client for C_i
// O_i denotes the point offset, and possible area shape and size.
// B_i denotes a boolean representation of P_i for C_i, for C_1...C_n.
// B_0 and O_0 are the merry exception here, as we don't need them for C_0,
// which we will show later.
{writeln(inttostr(x1) + ', ' + inttostr(y1) + ', ' + inttostr(x2) +
', ' + inttostr(y2)); }
DTMBounds(DTM, x1, y1, x2, y2);
{ writeln(inttostr(x1) + ', ' + inttostr(y1) + ', ' + inttostr(x2) +
', ' + inttostr(y2)); }
{If X2 > X1 then
//Exit;
If Y2 > Y1 then }
//Exit;
// Will make sure there are no out of bounds exceptions, and will make it faster
// I hope it is clear how this will be respresented in computer data
// structures.
with TClient(Client) do
begin
MWindow.Freeze();
// Now, we iterate for i in range(1, n),
// We use MP_i, and iterate for j in range(0, dtm_points),
// Calculate the B_j indices (with MP_i and O_j) for each j, and
// see if B_j is not true, go on with MP_i + 1.
// Possible using areasize/shape.
MFinder.FindColorsTolerance(mP, DTM.c[Low(DTM.c)], x1, y1, x2, y2,
DTM.t[Low(DTM.t)]);
MWindow.GetDimensions(H, dH);
end;
H := High(mP);
dH := High(DTM.p);
For I := 0 To H Do
Begin
Found := True;
For J := 1 To dH Do
Begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
If Not AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
Found := False;
Break;
End;
End;
If Found Then
Begin
Result := True;
SetLength(Points, Length(Points) + 1);
Points[High(Points)] := mP[I];
End;
End;
TClient(Client).MWindow.UnFreeze();
Result := Length(Points) > 0;
End;
// else, if B_j is true, continue with this inner loop.
// If B_{0...dtm_points} were all true, the point is valid.
{/\
Tries to find the given DTM (index). If found will put the point the dtm has
@ -620,7 +380,7 @@ End;
Returns all Angles in an Extended array.
/\}
Function TMDTM.FindDTMRotated(DTM: Integer; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;
{Function TMDTM.FindDTMRotated(DTM: Integer; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;
Var
temp: pDTM;
Begin
@ -633,7 +393,7 @@ Begin
aFound := 0.0;
Result := False;
End;
End;
End; }
{/\
Tries to find the given pDTM. If found will put the point the dtm has
@ -642,115 +402,11 @@ End;
Returns all Angles in an Extended array.
/\}
Function TMDTM.pFindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;
Var
mP: TPointArray;
I, J, H, dH, R, W: Integer;
Angle: Array Of Extended;
tAngle: Extended;
Found: Boolean;
TempTP: TPoint;
// MaxSubPointDist: TPoint;
{Function TMDTM.pFindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;
Begin
For I := 1 To High(DTM.p) Do
Begin
DTM.p[I].x := DTM.p[I].x - DTM.p[0].x;
DTM.p[I].y := DTM.p[I].y - DTM.p[0].y;
End;
writeln(inttostr(x1) + ', ' + inttostr(y1) + ', ' + inttostr(x2) +
', ' + inttostr(y2));
DTMRotatedBounds(DTM, x1, y1, x2, y2);
writeln(inttostr(x1) + ', ' + inttostr(y1) + ', ' + inttostr(x2) +
', ' + inttostr(y2));
{If X2 > X1 then
//Exit;
If Y2 > Y1 then }
//Exit;
// Will make sure there are no out of bounds exceptions, and will make it faster
with TClient(Client) do
begin
MWindow.Freeze();
MFinder.FindColorsTolerance(mP, DTM.c[Low(DTM.c)], x1, y1, x2, y2,
DTM.t[Low(DTM.t)]);
MWindow.GetDimensions(H, dH);
end;
H := High(mP);
dH := High(DTM.p);
For I := 0 To H Do
Begin
// Use MainPoint's AreaSize and Shape.
// For Loop on mP, depending on the AreaShape. Then on all the code beneath
// this point, use the var that is retrieved from the for loop.
Found := True;
SetLength(Angle, 0);
Found := True;
For J := 1 To dH Do
Begin
If Length(Angle) = 0 Then
Begin
tAngle := sAngle;
While tAngle <= eAngle Do
Begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
TempTP := RotatePoint(TempTP, tAngle, mP[I].X, mP[I].Y);
If AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
SetLength(Angle, Length(Angle) + 1);
Angle[High(Angle)] := tAngle;
Found := True;
End;
tAngle := tAngle + aStep;
End;
End;
Found := Length(Angle) > 0;
For R := 0 To High(Angle) Do
Begin
writeln('dtm: ' + inttostr(dtm.p[j].x) + ', ' + inttostr(dtm.p[j].y));
writeln('mP: ' + inttostr(mP[i].x) + ', ' + inttostr(mP[i].y));
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
writeln('TempTP: ' + inttostr(TempTP.x) + ', ' + inttostr(TempTP.y));
TempTP := RotatePoint(TempTP, Angle[R], mP[I].X, mP[I].Y);
writeln('TempTP: ' + inttostr(TempTP.x) + ', ' + inttostr(TempTP.y));
If Not AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
For W := R To High(Angle) - 1 Do
Angle[W] := Angle[W + 1];
SetLength(Angle, Length(Angle) - 1);
If Length(Angle) = 0 Then
Begin
Found := False;
Break;
End;
End;
End;
If Not Found Then
Break;
End;
If Found Then
Begin
Result := True;
x := mP[I].X;
y := mP[I].Y;
aFound := Angle[0];
TClient(Client).MWindow.UnFreeze();
Exit;
End;
End;
TClient(Client).MWindow.UnFreeze();
Result := False;
End;
End; }
{/\
Tries to find the given DTM (index). Will return true if it has found one or more
@ -760,7 +416,7 @@ End;
Returns all Angles in a Two Dimensional Extended array.
/\}
Function TMDTM.FindDTMsRotated(DTM: Integer; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean;
{Function TMDTM.FindDTMsRotated(DTM: Integer; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean;
Var
temp: pDTM;
Begin
@ -772,7 +428,7 @@ Begin
SetLength(aFound, 0);
Result := False;
End;
End;
End; }
{/\
Tries to find the given pDTM. Will return true if it has found one or more
@ -782,109 +438,12 @@ End;
Returns all Angles in a Two Dimensional Extended array.
/\}
Function TMDTM.pFindDTMsRotated(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean;
Var
mP: TPointArray;
I, J, H, dH, R, W, PCount: Integer;
Angle: TExtendedArray;
tAngle: Extended;
Found: Boolean;
TempTP: TPoint;
{Function TMDTM.pFindDTMsRotated(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean;
Begin
For I := 1 To High(DTM.p) Do
Begin
DTM.p[I].x := DTM.p[I].x - DTM.p[0].x;
DTM.p[I].y := DTM.p[I].y - DTM.p[0].y;
End;
DTMBounds(DTM, x1, y1, x2, y2);
{If X2 > X1 then
//Exit;
If Y2 > Y1 then }
//Exit;
// Will make sure there are no out of bounds exceptions, and will make it faster
with TClient(Client) do
begin
MWindow.Freeze();
MFinder.FindColorsTolerance(mP, DTM.c[Low(DTM.c)], x1, y1, x2, y2,
DTM.t[Low(DTM.t)]);
MWindow.GetDimensions(H, dH);
end;
H := High(mP);
dH := High(DTM.p);
PCount := 0;
For I := 0 To H Do
Begin
//WriteLn('I: ' + IntToStr(I));
// Use MainPoint's AreaSize and Shape.
// For Loop on mP, depending on the AreaShape. Then on all the code beneath
// this point, use the var that is retrieved from the for loop.
//Found := True;
SetLength(Angle, 0);
Found := True;
For J := 1 To dH Do
Begin
If Length(Angle) = 0 Then
Begin
tAngle := sAngle;
While tAngle <= eAngle Do
Begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
TempTP := RotatePoint(TempTP, tAngle, mP[I].X, mP[I].Y);
If AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
SetLength(Angle, Length(Angle) + 1);
Angle[High(Angle)] := tAngle;
Found := True;
End;
tAngle := tAngle + aStep;
End;
End;
Found := Length(Angle) > 0;
{If Found Then
WriteLn('Angle length after first search: ' + IntToStr(Length(Angle))); }
For R := 0 To High(Angle) Do
Begin
TempTP.X := DTM.p[J].X + mP[I].X;
TempTP.Y := DTM.p[J].Y + mP[I].Y;
TempTP := RotatePoint(TempTP, Angle[R], mP[I].X, mP[I].Y);
If Not AreaShape(DTM.c[J], DTM.t[J], DTM.asz[J], DTM.ash[J], TempTP) Then
Begin
For W := R To High(Angle) - 1 Do
Angle[W] := Angle[W + 1];
SetLength(Angle, Length(Angle) - 1);
If Length(Angle) = 0 Then
Begin
Found := False;
Break;
End;
End;
End;
If Not Found Then
Break;
End;
If Found Then
Begin
SetLength(Points, PCount + 1);
Points[PCount] := mP[I];
PCount := PCount + 1;
SetLength(aFound, Length(aFound) + 1);
aFound[High(aFound)] := Angle;
Continue;
End;
End;
TClient(Client).MWindow.UnFreeze();
Result := Length(Points) > 0;
End;
// Don't forget to pre calculate the rotated points at the start.
// Saves a lot of rotatepoint() calls.
End; }
end.

View File

@ -35,7 +35,43 @@ Function pDTMToTDTM(Const DTM: pDTM): TDTM;
Function tDTMTopDTM(Const DTM: TDTM): pDTM;
Procedure PrintpDTM(tDTM : pDTM);
procedure initdtm(var d: pdtm; len: integer);
function ValidMainPointBox(var dtm: pDTM; const x1, y1, x2, y2: Integer): TBox;
function ValidMainPointBoxRotated(var dtm: pDTM; const x1, y1, x2, y2: Integer): TBox;
function DTMConsistent(var dtm: pdtm): boolean;
procedure NormalizeDTM(var dtm: pdtm);
const
dtm_Rectangle = 0;
dtm_Cross = 1;
dtm_DiagonalCross = 2;
dtm_Circle = 3;
dtm_Triangle = 4;
implementation
uses math;
// macro
procedure initdtm(var d: pdtm; len: integer);
var
i: integer;
begin
d.l := len;
setlength(d.p, len);
setlength(d.c, len);
setlength(d.t, len);
setlength(d.ash, len);
setlength(d.asz, len);
FillChar(d.p[0], SizeOf(TPoint) * len, 0);
FillChar(d.c[0], SizeOf(Integer) * len, 0);
FillChar(d.t[0], SizeOf(Integer) * len, 0);
FillChar(d.ash[0], SizeOf(Integer) * len, 0);
// Better set it to 1, than fill with 0.
FillChar(d.asz[0], SizeOf(Integer) * len, 0);
{for i := 0 to len - 1 do
d.asz[i] := 1; }
end;
Procedure PrintpDTM(tDTM : pDTM);
var
@ -65,7 +101,7 @@ Begin
Result.MainPoint := Temp;
SetLength(Result.SubPoints, Length(DTM.p) - 1);
For I := 1 To High(DTM.p) Do
For I := 1 To DTM.l-1 Do
Begin
Temp.X := 0; Temp.Y := 0; Temp.AreaSize := 0; Temp.AreaShape := 0; Temp.Color := 0; Temp.Tolerance := 0;
Temp.X := DTM.p[i].x;
@ -111,7 +147,87 @@ Begin
Result.asz[I] := DTM.SubPoints[I - 1].AreaSize;
Result.ash[I] := DTM.SubPoints[I - 1].AreaShape;
End;
Result.l := length(Result.p);
End;
{ TODO: Check if bounds are correct? }
function DTMConsistent(var dtm: pdtm): boolean;
var
i: integer;
begin
if dtm.l = 0 then
Exit(False);
if dtm.l <> length(dtm.p) then
Exit(False);
if dtm.l <> length(dtm.c) then
Exit(False);
if dtm.l <> length(dtm.t) then
Exit(False);
if dtm.l <> length(dtm.asz) then
Exit(False);
if dtm.l <> length(dtm.ash) then
Exit(False);
for i := 0 to dtm.l-1 do
if dtm.asz[i] < 0 then
Exit(False);
for i := 0 to dtm.l-1 do
if dtm.c[i] < 0 then
Exit(False);
for i := 0 to dtm.l-1 do
if dtm.t[i] < 0 then
Exit(False);
for i := 0 to dtm.l-1 do
if dtm.ash[i] < 0 then
Exit(False);
end;
procedure NormalizeDTM(var dtm: pdtm);
var
i:integer;
begin
for i := 0 to dtm.l do
dtm.p[i] := dtm.p[i] - dtm.p[0];
end;
Function ValidMainPointBox(var dtm: pDTM; const x1, y1, x2, y2: Integer): TBox;
var
i: Integer;
b: TBox;
begin
// writeln(format('%d, %d', [0,0]));
for i := 1 to high(dtm.c) do
begin
dtm.p[i] := dtm.p[i] - dtm.p[0];
// writeln(format('%d, %d', [dtm.p[i].x, dtm.p[i].y]));
end;
dtm.p[0] := dtm.p[0] - dtm.p[0];
FillChar(b, SizeOf(TBox), 0);
for i := 0 to high(dtm.c) do
begin
b.x1 := min(b.x1, dtm.p[i].x - dtm.asz[i]);
b.y1 := min(b.y1, dtm.p[i].y - dtm.asz[i]);
b.x2 := max(b.x2, dtm.p[i].x + dtm.asz[i]);
b.y2 := max(b.y2, dtm.p[i].y + dtm.asz[i]);
end;
//FillChar(Result, SizeOf(TBox), 0);
writeln(Format('DTM Bounding Box: %d, %d : %d, %d', [b.x1, b.y1,b.x2,b.y2]));
Result.x1 := x1 - b.x1;
Result.y1 := y1 - b.y1;
Result.x2 := x2 - b.x2;
Result.y2 := y2 - b.y2;
end;
Function ValidMainPointBoxRotated(var dtm: pDTM; const x1, y1, x2, y2: Integer): TBox;
begin
end;
end.

View File

@ -77,7 +77,14 @@ type
function FindBitmapSpiralTolerance(bitmap: TMufasaBitmap; var x, y: Integer; xs, ys, xe, ye,tolerance : integer): Boolean;
function FindBitmapsSpiralTolerance(bitmap: TMufasaBitmap; x, y: Integer; out Points : TPointArray; xs, ys, xe, ye,tolerance: Integer): Boolean;
function FindDeformedBitmapToleranceIn(bitmap: TMufasaBitmap; out x, y: Integer; xs, ys, xe, ye: Integer; tolerance: Integer; Range: Integer; AllowPartialAccuracy: Boolean; var accuracy: Extended): Boolean;
protected
function FindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
function FindDTMs(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer): Boolean;
function FindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;
function FindDTMsRotated(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean;
protected
Client: TObject;
Percentage : array[0..255] of Extended; //We store all the possible RGB / 255 divisions.
CachedWidth, CachedHeight : integer;
@ -90,7 +97,8 @@ implementation
uses
Client, // For the Client Casts.
colour_conv, // For RGBToColor, etc.
math //min/max
math, //min/max
dtmutil
;
type
TPRGB32Array = array of PRGB32;
@ -1570,5 +1578,248 @@ begin
end;
end;
function TMFinder.FindDTM(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer): Boolean;
var
P: TPointArray;
begin
Self.FindDTMs(DTM, P, x1, y1, x2, y2);
if(Length(p) > 0) then
begin
x := p[0].x;
y := p[0].y;
Exit(True);
end;
Exit(False);
end;
// TODO: Add a max count, so we can use it more efficiently for FindDTM?
function TMFinder.FindDTMs(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer): Boolean;
var
// Colours of DTMs
C: Array of Integer;
// Bitwise
b: Array of Array of Integer;
// bounds
W, H: integer;
MA: TBox;
// for loops, etc
xx, yy: integer;
i, xxx,yyy: Integer;
// for comparions.
clR, clG, clB: Integer;
//clientdata
cd: TPRGB32Array;
PtrData: TRetData;
Ptr: PRGB32;
PtrInc: Integer;
// point count
pc: Integer = 0;
label EndOfLoop;
label AnotherLoopEnd;
begin
if not DTMConsistent(dtm) then
begin
raise Exception.CreateFmt('FindDTMs: DTM is not consistent.', []);
Exit;
end;
// Get the area we should search in for the Main Point.
writeln(Format('%d, %d, %d, %d', [x1,y1,x2,y2]));
MA := ValidMainPointBox(DTM, x1, y1, x2, y2);
writeln(Format('%d, %d, %d, %d', [MA.x1,MA.y1,MA.x2,MA.y2]));
DefaultOperations(MA.x1, MA.y1, MA.x2, MA.y2);
// Init data structure B.
W := x2 - x1;
H := y2 - y1;
setlength(b, W + 1);
for i := 0 to W do
begin
setlength(b[i], H + 1);
// does setlength init already? if it doesn't, do we want to init here?
// or do we want to init in the loop, as we loop over every b anyway?
//FillChar(b[i][0], SizeOf(Integer) * H, 0);
end;
// C = DTM.C
C := DTM.c;
// Now, we must find the occurances of all colours.
// This part should be turned into a more general function (for DTM Finding).
// Something like FindColorsMultiBooleanArray (?)
// Retreive Client Data.
PtrData := TClient(Client).MWindow.ReturnData(x1, y1, W + 1, H + 1);
// Do we want to "cache" these vars?
// We will, for now. Easier to type.
Ptr := PtrData.Ptr;
PtrInc := PtrData.IncPtrWith;
cd := CalculateRowPtrs(PtrData, h + 1);
writeln(format('w,h: %d, %d', [w,h]));
for yy := 0 to h do
for xx := 0 to w do
begin
//writeln(format('x,y: %d, %d', [xx,yy]));
// main point
if not TClient(Client).MFinder.SimilarColors(dtm.c[0], RGBToColor(cd[yy][xx].R, cd[yy][xx].G, cd[yy][xx].B), dtm.t[0]) then
goto AnotherLoopEnd;
b[xx][yy] := B[xx][yy] or 1;
for i := 1 to dtm.l - 1 do
begin // use square areashape - it covers all.
for xxx := xx - dtm.asz[i] + dtm.p[i].x to xx + dtm.asz[i] + dtm.p[i].x do
for yyy := yy - dtm.asz[i] + dtm.p[i].y to yy + dtm.asz[i]+ dtm.p[i].y do
// may want to remove this line, but I think it is a good optimisation.
if B[xxx][yyy] and (1 shl i) = 0 then
if TClient(Client).MFinder.SimilarColors(dtm.c[i], RGBToColor(cd[yyy][xxx].R, cd[yyy][xxx].G, cd[yyy][xxx].B), dtm.t[i]) then
b[xxx][yyy] := B[xxx][yyy] or (1 shl i)
else
goto AnotherLoopEnd;
end;
AnotherLoopEnd:
//writeln(format('b[%d][%d]: %d' ,[xx,yy,b[xx][yy]]));
end;
{for yy := 0 to h do
for xx := 0 to w do
writeln(format('b[%d][%d]: %d' ,[xx,yy,b[xx][yy]])); }
// Now iterate over the data. (Main Point Bounds)
for yy := MA.y1-y1 to MA.y2-y1 do
for xx := MA.x1-x1 to MA.x2-x1 do
begin
//writeln(format('Testing for MP at %d, %d', [xx,yy]));
//writeln(format('Testing for MP RealPoints at %d, %d', [xx+x1,yy+y1]));
if (b[xx][yy] and 1) = 0 then
continue;
//writeln(format('Got a MP at %d, %d', [xx,yy]));
//writeln(format('Got a MP Real Points at %d, %d', [xx+x1,yy+y1]));
for i := 1 to dtm.l - 1 do
begin
//writeln(format('i: %d',[i]));
case dtm.ash[i] of
{ Example:
3x3 (AreaSize = 1)
X X X
X X X
X X X }
//areasize and areashape. areasize = 0 is completly valid
dtm_Rectangle:
begin
//writeln(Format('X - From, To: %d, %d', [xx - dtm.asz[i]+ dtm.p[i].x, xx + dtm.asz[i]+ dtm.p[i].x]));
for xxx := xx - dtm.asz[i] + dtm.p[i].x to xx + dtm.asz[i] + dtm.p[i].x do
for yyy := yy - dtm.asz[i] + dtm.p[i].y to yy + dtm.asz[i]+ dtm.p[i].y do
if b[xxx][yyy] and (1 shl i) = 0 then
goto EndOfLoop;
end;
{ Example:
3x3 (AreaSize = 1)
X
X X X
X }
dtm_Cross:
begin
for xxx := xx - dtm.asz[i] + dtm.p[i].x to xx + dtm.asz[i] + dtm.p[i].x do
begin
//writeln(format('Cross - One. %d, %d', [xxx,dtm.p[i].y + yy]));
if b[xxx][dtm.p[i].y + yy] and (1 shl i) = 0 then
goto EndOfLoop;
end;
for yyy := yy - dtm.asz[i] + dtm.p[i].y to yy + dtm.asz[i]+ dtm.p[i].y do
begin
//writeln(format('Cross - One. %d, %d', [dtm.p[i].x + xx,yyy]));
if b[dtm.p[i].x + xx][yyy] and (1 shl i) = 0 then
goto EndOfLoop;
end;
end;
{ Example:
3x3 (AreaSize = 1)
X X
X
X X }
dtm_DiagonalCross:
begin
for xxx := -dtm.asz[i] to dtm.asz[i] do
begin
if b[xx + dtm.p[i].x + xxx][yy + dtm.p[i].y + xxx] and (1 shl i) = 0 then
goto EndOfLoop;
if b[xx + dtm.p[i].x + xxx][yy + dtm.p[i].y + xxx] and (1 shl i) = 0 then
goto EndOfLoop;
end;
end
else
begin
raise exception.createFMT('FindDTMs: Invalid Areashape!', []);
Exit;
end;
end;
// point [xx,yy] found if we make it to here
//writeln(Format('Wat (Real Points): %d, %d', [xx+x1, yy+y1])); //Good old wat!
end;
ClientTPA[pc] := Point(xx+x1, yy+y1);
Inc(pc);
//writeln(Format('Found a Point: %d, %d', [xx+x1, yy+y1]));
EndOfLoop:
end;
TClient(Client).MWindow.FreeReturnData;
SetLength(Points, pc);
Move(ClientTPA[0], Points[0], pc * SizeOf(TPoint));
end;
function TMFinder.FindDTMRotated(DTM: pDTM; out x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;
begin
raise Exception.CreateFmt('Not done yet!', []);
end;
function TMFinder.FindDTMsRotated(DTM: pDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray): Boolean;
begin
// Don't forget to pre calculate the rotated points at the start.
// Saves a lot of rotatepoint() calls.
raise Exception.CreateFmt('Not done yet!', []);
end;
end.
{ crap code }
// this is the probably the slowest part of the algorithm.
{ for yy := y1 to y2 do
begin
for xx := x1 to x2 do
begin
{for i := 0 to dtm.l - 1 do
begin
// optimise this later...
if TClient(Client).MFinder.SimilarColors(dtm.c[i], RGBToColor(Ptr^.R,Ptr^.G,Ptr^.B) , dtm.t[i]) then
B[xx][yy] := B[xx][yy] or (1 shl i);
end; }
inc(Ptr);
end;
inc(Ptr, PtrInc);
end;
}

View File

@ -86,7 +86,9 @@ type
x1, y1, x2, y2: Integer;
end;
{ TODO: add cts per colour/tolerance? }
pDTM = record
l: Integer;
p: TPointArray;
c, t, asz, ash: TIntegerArray;
end;