From d2e3e278f19e855da705c208d22a542e2f95d85c Mon Sep 17 00:00:00 2001 From: Wizzup? Date: Wed, 2 Dec 2009 20:18:38 +0000 Subject: [PATCH] DTM uses CTS 1. FindDTM/FindDTMs are `done' for now. Unless you guys/girls really want AreaShape, then I can add those too. git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@264 3f818213-9676-44b0-a9b4-5e4c4e03d09d --- Projects/MufasaTests/project1.lpi | 122 ++++++++++---------- Projects/MufasaTests/project1.lpr | 9 +- Projects/SAMufasaGUI/project1.lpi | 186 +++++++++++++++--------------- Units/MMLCore/dtmutil.pas | 2 +- Units/MMLCore/finder.pas | 28 ++--- 5 files changed, 177 insertions(+), 170 deletions(-) diff --git a/Projects/MufasaTests/project1.lpi b/Projects/MufasaTests/project1.lpi index 56275dd..ac91064 100644 --- a/Projects/MufasaTests/project1.lpi +++ b/Projects/MufasaTests/project1.lpi @@ -35,10 +35,10 @@ - - + + - + @@ -53,7 +53,7 @@ - + @@ -69,22 +69,24 @@ - + - - - + + + + + - - + + @@ -94,7 +96,7 @@ - + @@ -103,7 +105,7 @@ - + @@ -112,7 +114,7 @@ - + @@ -176,7 +178,7 @@ - + @@ -185,16 +187,16 @@ - + - - - + + + @@ -208,124 +210,124 @@ - - + + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - - + + - - + + - + - + - - + + - - + + - - + + - + - - + + - - + + - + - + - + - + - + - - + + - - + + diff --git a/Projects/MufasaTests/project1.lpr b/Projects/MufasaTests/project1.lpr index 05b879c..f1fdbea 100644 --- a/Projects/MufasaTests/project1.lpr +++ b/Projects/MufasaTests/project1.lpr @@ -78,20 +78,21 @@ begin dtm.p[0] := Point(2, 2); dtm.p[1] := Point(-3, -3); dtm.p[2] := Point(0, 0); - dtm.c[0] := 0; + dtm.c[0] := 255; + dtm.t[0] := 255; dtm.asz[1] := 1; dtm.ash[1] := dtm_Rectangle; setlength(p, 1); time := GetTickCount; - C.MFinder.FindDTMs(dtm, p, 0, 0,799, 599, 10); + C.MFinder.FindDTMs(dtm, p, 0, 0,799, 599, 0); //C.MFinder.FindDTM(dtm, p[0].x, p[0].y, 0, 0,799, 599); writeln(inttostr(gettickcount - time)); writeln(inttostr(length(p))); - for i := 0 to high(p) do - writeln(format('%d: (%d, %d)', [i, p[i].x, p[i].y])); + {for i := 0 to high(p) do + writeln(format('%d: (%d, %d)', [i, p[i].x, p[i].y])); } //bmp.OnDestroy:=nil; diff --git a/Projects/SAMufasaGUI/project1.lpi b/Projects/SAMufasaGUI/project1.lpi index 76e74c9..67caa64 100644 --- a/Projects/SAMufasaGUI/project1.lpi +++ b/Projects/SAMufasaGUI/project1.lpi @@ -38,9 +38,11 @@ - + + + @@ -229,8 +231,8 @@ - - + + @@ -272,7 +274,7 @@ - + @@ -287,8 +289,8 @@ - - + + @@ -313,7 +315,7 @@ - + @@ -382,7 +384,7 @@ - + @@ -402,8 +404,8 @@ - - + + @@ -707,9 +709,9 @@ - - - + + + @@ -783,9 +785,11 @@ - - + + + + @@ -797,8 +801,8 @@ - - + + @@ -993,7 +997,7 @@ - + @@ -1192,7 +1196,7 @@ - + @@ -1506,8 +1510,8 @@ - - + + @@ -1758,7 +1762,7 @@ - + @@ -1772,7 +1776,7 @@ - + @@ -1781,7 +1785,7 @@ - + @@ -1791,7 +1795,7 @@ - + @@ -1828,124 +1832,124 @@ - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - - + + diff --git a/Units/MMLCore/dtmutil.pas b/Units/MMLCore/dtmutil.pas index e004f70..588f6a3 100644 --- a/Units/MMLCore/dtmutil.pas +++ b/Units/MMLCore/dtmutil.pas @@ -216,7 +216,7 @@ begin end; //FillChar(Result, SizeOf(TBox), 0); - writeln(Format('DTM Bounding Box: %d, %d : %d, %d', [b.x1, b.y1,b.x2,b.y2])); + //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; diff --git a/Units/MMLCore/finder.pas b/Units/MMLCore/finder.pas index 7b37678..cd3a946 100644 --- a/Units/MMLCore/finder.pas +++ b/Units/MMLCore/finder.pas @@ -1593,7 +1593,6 @@ begin 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, maxToFind: Integer): Boolean; var // Colours of DTMs @@ -1610,15 +1609,13 @@ var xx, yy: integer; i, xxx,yyy: Integer; - // for comparions. - clR, clG, clB: Integer; + // for comparisons. + rgbs: array of TRGB32; //clientdata cd: TPRGB32Array; PtrData: TRetData; - Ptr: PRGB32; - PtrInc: Integer; // point count pc: Integer = 0; @@ -1636,9 +1633,9 @@ begin end; // Get the area we should search in for the Main Point. - writeln(Format('%d, %d, %d, %d', [x1,y1,x2,y2])); + //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])); + //writeln(Format('%d, %d, %d, %d', [MA.x1,MA.y1,MA.x2,MA.y2])); DefaultOperations(MA.x1, MA.y1, MA.x2, MA.y2); @@ -1666,18 +1663,21 @@ begin // 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])); + //writeln(format('w,h: %d, %d', [w,h])); + + // pre calc rgb values for dtms + SetLength(rgbs, dtm.l); + for i := 0 to dtm.l - 1 do + ColorToRGB(dtm.c[i], rgbs[i].r, rgbs[i].g, rgbs[i].b); for yy := MA.y1 to MA.y2 do for xx := MA.x1 to MA.x2 do begin // main point - //if dtm.c[0] <> RGBToColor(cd[yy][xx].R, cd[yy][xx].G, cd[yy][xx].B) then - if not SimilarColors(dtm.c[0], RGBToColor(cd[yy][xx].R, cd[yy][xx].G, cd[yy][xx].B), dtm.t[0]) then + if Sqrt(sqr(rgbs[0].r - cd[yy][xx].R) + sqr(rgbs[0].g - cd[yy][xx].G) + sqr(rgbs[0].b - cd[yy][xx].B)) > dtm.t[0] then + // if not 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 @@ -1688,8 +1688,8 @@ begin // may want to remove this line, but I think it is a good optimisation. if B[xxx][yyy] and (1 shl i) = 0 then begin - //if dtm.c[i] = RGBToColor(cd[yyy][xxx].R, cd[yyy][xxx].G, cd[yyy][xxx].B) then - if SimilarColors(dtm.c[i], RGBToColor(cd[yyy][xxx].R, cd[yyy][xxx].G, cd[yyy][xxx].B), dtm.t[i]) then + if Sqrt(sqr(rgbs[i].r - cd[yyy][xxx].R) + sqr(rgbs[i].g - cd[yyy][xxx].G) + sqr(rgbs[i].b - cd[yyy][xxx].B)) <= dtm.t[i] then + // if 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;