|
27 | 27 | Unzipping, IsSetup: Boolean; |
28 | 28 | end; |
29 | 29 |
|
30 | | -function TRSItemFinder.Align(image, template: TImage): Boolean; |
| 30 | + |
| 31 | +function TRSItemFinder._AlignHelper(img: TImage; tBorder, border: TPointArray; out align: TPoint): Boolean; |
31 | 32 | var |
32 | | - borderA, borderB, tmp1, tmp2: TPointArray; |
33 | | - bounds: TBox; |
34 | | - align, p: TPoint; |
| 33 | + color: TColor; |
| 34 | + pt: TPoint; |
35 | 35 | begin |
36 | | - borderA := image.FindColor(RSColors.ITEM_BORDER, 0); |
37 | | - tmp1 := borderA.ExcludeBox([0,0,image.Width,8]); |
38 | | - borderA := tmp1; |
39 | | - borderB := template.FindColor($000000, 1) + template.FindColor(RSColors.ITEM_BORDER_WHITE, 0); |
40 | | - tmp2 := borderB.ExcludeBox([0,0,template.Width,8]); |
41 | | - borderB := tmp2; |
| 36 | + if border = [] then Exit; |
42 | 37 |
|
43 | | - if (borderA.Length = 0) or (borderB.Length = 0) then Exit; |
| 38 | + align := tBorder.Last - border.Last; |
| 39 | + border := border.Offset(align); |
44 | 40 |
|
45 | | - align := borderA[High(borderA)] - borderB[High(borderB)]; |
46 | | - borderB := borderB.Offset(align); |
| 41 | + color := TRSItem.Border; |
47 | 42 |
|
48 | | - for p in borderB do |
| 43 | + for pt in border do |
49 | 44 | begin |
50 | | - if p.Y <= 8 then Continue;//stack number... Don't compare. |
51 | | - |
52 | | - if not image.InImage(p.X, p.Y) then Exit; |
53 | | - if (image.Pixel[p.X, p.Y] <> RSColors.ITEM_BORDER) then Exit; |
| 45 | + if pt.Y <= 8 then |
| 46 | + Continue; //stack number... Don't compare. |
| 47 | + if not img.InImage(pt.X, pt.Y) then |
| 48 | + Exit; |
| 49 | + if img.Pixel[pt.X, pt.Y] <> color then |
| 50 | + Exit; |
54 | 51 | end; |
55 | 52 |
|
56 | | - bounds := borderA.Bounds; |
| 53 | + Result := True; |
| 54 | +end; |
| 55 | + |
| 56 | +function TRSItemFinder.Align(image, template: TImage): Boolean; |
| 57 | +var |
| 58 | + tBorder, bBorder, wBorder: TPointArray; |
| 59 | + bounds: TBox; |
| 60 | + align: TPoint; |
| 61 | +begin |
| 62 | + tBorder := image.FindColor(TRSItem.Border, 0).ExcludeBox([0,0,image.Width,8]); |
| 63 | + bBorder := template.FindColor(TRSItem.Border, 0).ExcludeBox([0,0,template.Width,8]); |
| 64 | + wBorder := template.FindColor(TRSItem.BorderWhite, 0); |
| 65 | + |
| 66 | + if tBorder = [] then |
| 67 | + Exit; |
| 68 | + |
| 69 | + if not Self._AlignHelper(image, tBorder, bBorder, align) and |
| 70 | + not Self._AlignHelper(image, tBorder, wBorder, align) then |
| 71 | + Exit; |
| 72 | + |
| 73 | + bounds := tBorder.Bounds; |
57 | 74 | image.Crop(bounds); |
58 | 75 | template.Crop(bounds.Offset([-align.X, -align.Y])); |
59 | 76 | Result := True; |
60 | 77 | end; |
61 | 78 |
|
62 | 79 | procedure TRSItemFinder.Clean(image, template: TImage); |
63 | 80 | var |
64 | | - color: TColor; |
| 81 | + stack: ERSStack; |
65 | 82 | tpa: TPointArray; |
66 | 83 | begin |
67 | 84 | image.DrawColor := $0; |
68 | 85 | template.DrawColor := $0; |
69 | 86 |
|
70 | 87 | template.DrawTPA(image.FindColor($0, 0)); |
71 | 88 |
|
72 | | - tpa := image.FindColor(RSColors.ITEM_SHADOW, 0); |
73 | | - for color in RSColors.STACK_COLORS do |
74 | | - tpa += template.FindColor(color, 0); |
| 89 | + tpa := image.FindColor(TRSItem.Shadow, 0); |
| 90 | + for stack := Low(ERSStack) to High(ERSStack) do |
| 91 | + tpa += template.FindColor(stack.Color, 0); |
75 | 92 |
|
76 | | - tpa += template.FindColor(RSColors.ITEM_BORDER, 0); |
| 93 | + tpa += template.FindColor(TRSItem.Border, 0); |
77 | 94 | image.DrawTPA(tpa); |
78 | 95 | template.DrawTPA(tpa); |
79 | 96 | end; |
@@ -262,7 +279,7 @@ begin |
262 | 279 | for i := 0 to High(boxes) do |
263 | 280 | begin |
264 | 281 | if skip[i] then Continue; |
265 | | - if not RSColors.HasItem(boxes[i]) then |
| 282 | + if not TRSItem.InBounds(boxes[i]) then |
266 | 283 | begin |
267 | 284 | skip[i] := True; |
268 | 285 | Continue; |
@@ -303,7 +320,7 @@ begin |
303 | 320 | for i := 0 to High(boxes) do |
304 | 321 | begin |
305 | 322 | if skip[i] then Continue; |
306 | | - if not RSColors.HasItem(boxes[i]) then |
| 323 | + if not TRSItem.InBounds(boxes[i]) then |
307 | 324 | begin |
308 | 325 | skip[i] := True; |
309 | 326 | Continue; |
@@ -353,7 +370,7 @@ begin |
353 | 370 | for i := 0 to High(boxes) do |
354 | 371 | begin |
355 | 372 | if skip[i] then Continue; |
356 | | - if not RSColors.HasItem(boxes[i]) then |
| 373 | + if not TRSItem.InBounds(boxes[i]) then |
357 | 374 | begin |
358 | 375 | skip[i] := True; |
359 | 376 | Continue; |
|
398 | 415 | tpa: TPointArray; |
399 | 416 | border: TImage; |
400 | 417 | begin |
401 | | - tpa := img.FindColor(RSColors.ITEM_BORDER, 0, [0, 9, 35, 31]); |
| 418 | + tpa := img.FindColor(TRSItem.Border, 0, [0, 9, 35, 31]); |
402 | 419 | if tpa = [] then Exit; |
403 | 420 | border := new TImage(36, 32); |
404 | 421 | border.DrawColor := $FFFFFF; |
|
0 commit comments