private static void TestFile(FileInfo input) { var infile = input.FullName; var outfile = infile.Replace(".in.png", ".out.png"); var titlefile = infile.Replace(".in.png", ".title.png"); Console.ResetColor(); var output = new ConsoleOutputList(); output.Add(string.Format("Test {0}/{1}... ", Interlocked.Increment(ref test), numTests)); string reason = CompareItemExtraction(infile, outfile, titlefile, output); if (reason == "") { output.Add("passed!", ConsoleColor.Green); Interlocked.Increment(ref success); } else { output.Add(string.Format("failed ({0})\n{1}", reason, input.Name), ConsoleColor.Red); Interlocked.Increment(ref fail); } if (verbose) { lock (lockobj) { output.Print(); } } else { lock (lockobj) { Console.CursorLeft = 0; Console.Write("{0} - {1}", success, fail); } } }
private static string CompareItemExtraction(string infile, string outfile, string titlefile, ConsoleOutputList output, bool imageCompare = false) { var match = cursorPattern.Match(infile); if (!match.Success) { return("failed to extract cursor position!"); } var bmp = new Bitmap(infile); var cursorPos = new Point(match.Groups["x"].Value.ToInt(), match.Groups["y"].Value.ToInt()); var sw = new Stopwatch(); var ie = new ItemExtractor(bmp, cursorPos); Item item = null; var success = false; sw.Start(); try { success = ie.FindItem(); item = ie.ExtractItem(false); } catch { } sw.Stop(); var itemTime = sw.Elapsed.TotalSeconds; extractTimes.Add(itemTime); output.Add("("); output.AddTime(itemTime); var result = ""; if (imageCompare) { result = CompareImageResult(success ? item.Image : null, outfile, "item"); } else { var itemMatch = itemPattern.Match(infile); if (!itemMatch.Success) { if (success) { result = string.Format( "Unexpectedly found item at {0}", ie.ItemFrame); } } else { if (success) { var expected = new Rectangle( itemMatch.Groups["x"].Value.ToInt(), itemMatch.Groups["y"].Value.ToInt(), itemMatch.Groups["width"].Value.ToInt(), itemMatch.Groups["height"].Value.ToInt()); var found = ie.ItemFrame; if (found != expected) { result = string.Format( "Found item at {0}, expected {1}", found, expected); } } else { result = "No item found"; } } } if (result == "") { Bitmap title = null; if (success) { var titleWatch = new Stopwatch(); titleWatch.Start(); title = ItemExtractor.ExtractItemName(item.Image); titleWatch.Stop(); var titleTime = titleWatch.Elapsed.TotalSeconds; extractTitleTimes.Add(titleTime); output.Add(" - "); output.AddTime(titleTime); } result = CompareImageResult(title, titlefile, "title"); } output.Add(") "); return(result); }