Exemplo n.º 1
0
        private void SaveForUnitTests(Results r, Bitmap result, System.Drawing.Size size)
        {
            var path = Path.Combine("Tooltips", string.Format("{0}x{1}", size.Width, size.Height));
            Directory.CreateDirectory(path);

            string filepath;
            int i = 0;
            do
            {
                i++;
                filepath = Path.Combine(path, i.ToString("00") + ".png");
            } while (File.Exists(filepath));

            result.Save(filepath, ImageFormat.Png);

            //File.AppendAllText(@"Tooltips\items.json", JsonConvert.SerializeObject(r, Formatting.Indented));
        }
Exemplo n.º 2
0
        void HandleItem()
        {
            tabControl1.SelectTab(tabItem);
            panelDebugPictures.Controls.Clear();

            Trace.TraceInformation("Hello :)");

            var bmp = GetDiabloScreenshot();

            bmp.Save("last_screenshot.png", ImageFormat.Png);

            var result = Screenshot.GetTooltip(bmp);
            if (result == null)
            {
                tbItemSpecs.Text = "Tooltip not found";
                return;
            }
            result.Save("last.png", ImageFormat.Png);

            var sw = Stopwatch.StartNew();
            var tt = new D3Bit.Tooltip(result);
            var r = new Results(tt);
            sw.Stop();

            pbItem.Image = tt.Processed;

            //SaveForUnitTests(r, result, bmp.Size);

            //var sb = new StringBuilder();
            //sb.AppendLine("Name: {0}", r.Name);
            //sb.AppendLine("Type: {0} {1}", r.Quality, r.Type);
            //sb.AppendLine("DPS: {0}", r.DPS);
            //sb.AppendLine("Meta: {0}", r.Meta);
            //sb.AppendLine("Affixes:");
            //sb.Append(r.Affixes.Aggregate(new StringBuilder(), (o, v) => o.AppendLine("\t{0} = {1}", v.Key, v.Value)).ToString());
            //sb.AppendLine("Socket bonuses: {0}", r.SocketBonuses);
            //sb.AppendLine();
            //sb.AppendLine("{0}ms", sw.ElapsedMilliseconds);

            tbItemSpecs.Text = JsonConvert.SerializeObject(r, Formatting.Indented);

            #if DEBUG
            foreach (var item in tt.DebugBitmaps)
            {
                var pb = new PictureBox();
                pb.SizeMode = PictureBoxSizeMode.AutoSize;
                pb.Image = item;
                pb.ContextMenuStrip = cmPictures;

                panelDebugPictures.Controls.Add(pb);
            }
            #endif
        }
Exemplo n.º 3
0
		static void ExtractTooltips()
		{
			var dstPath = @"..\..\..\!Data\Tooltips";
			var imagesPath = Path.Combine(dstPath, "images");
				
			var specificTooltip = "";

			var files = Directory.GetFiles(dstPath, "1920x1200*_imagesearch.bmp");//.Take(10).ToArray();
			int i = 1;

			var html = new StringBuilder();			
			html.AppendLine("<!DOCTYPE html>");
			html.AppendLine(@"<html xmlns=""http://www.w3.org/1999/xhtml"">");
			html.AppendLine("<head>");
			html.AppendLine(@"<link rel=""Stylesheet"" type=""text/css"" href=""styles.css"">");
			html.AppendLine("</head>");
			html.AppendLine("<body>").AppendLine(@"<table cellpadding=""0"" cellspacing=""0"">");

			WarmUp(files[0]);

			var results1 = new List<Results>();
			var results2 = new List<Results>();

			foreach (var file in files)
			{
				if (!string.IsNullOrEmpty(specificTooltip) && !file.Contains(specificTooltip))
				{
					continue;
				}

				var filename = Path.GetFileName(file);

				var m = Regex.Match(filename, @"(?<W>\d+)x(?<H>\d+)");
				int width = int.Parse(m.Groups["W"].Value);
				int height = int.Parse(m.Groups["H"].Value);

				Bitmap bitmap = Bitmap.FromFile(file) as Bitmap;

				var path = Path.Combine(imagesPath, Path.GetFileNameWithoutExtension(file) + ".jpg");
				if (!File.Exists(path))
				{
					bitmap.Save(path, ImageFormat.Jpeg);
				}

				var tt2 = new TooltipWrapper<Tooltip>(new Tooltip(bitmap), width, height);
				var result2 = new Results(tt2);
				tt2.WrappedTooltip.Save(Path.Combine(dstPath, "tmp_v2", filename));

				//var tt = new TooltipWrapper<Tooltip_old>(new Tooltip_old(bitmap), width, height);
				//var result1 = new Results(tt);
				//tt.WrappedTooltip.Save(Path.Combine(dstPath, "tmp", filename));

				var diffClass = ""; // result1.GetHashCode() == result2.GetHashCode() ? "" : "different";

				html.AppendLine(@"<tr class=""{0}"">", diffClass);
				
				html.AppendLine(@"<td class=""tooltip"">");
				html.AppendLine("<div>");
				html.AppendLine("<img src='images/{0}' />", Path.GetFileName(path));
				html.AppendLine("<span>{0}x{1}</span>", width, height);
				html.AppendLine("</div>");
				html.AppendLine("</td>");

				html.AppendLine("<td class='tt1'>");
				html.AppendLine("<img src='tmp/{0}' />", filename);
				html.AppendLine("</td>");

				html.AppendLine("<td class='tt2'>");
				html.AppendLine("<img src='tmp_v2/{0}' />", filename);
				html.AppendLine("</td>");

				//html.AppendLine(@"<td class=""original"">");
				//html.AppendLine("<pre>");
				//RenderResults(html, result1);
				//html.AppendLine("</pre>");
				//html.AppendLine("</td>");

				html.AppendLine(@"<td class=""improved"">");
				html.AppendLine("<pre>");
				RenderResults(html, result2);
				html.AppendLine("</pre>");
				html.AppendLine("</td>");
				
				html.AppendLine("</tr>");

				//results1.Add(result1);
				results2.Add(result2);

				Console.WriteLine("{0}/{1}", i++, files.Count());
			}

			var r1 = results1.Sum(r => r.TimeTaken) / 1000.0;
			var	r2 = results2.Sum(r => r.TimeTaken) / 1000.0;

			html.AppendLine("<tr>{0}<td class='performance'>{1:0.00}s</td><td class='performance'>{2:0.00}s ({3:0%})</td></tr>", 
				string.Join("", Enumerable.Repeat("<td></td>", 3)), 
				r1, r2, (r2 - r1) / r1
			);

			html.AppendLine("</table>");
			html.AppendLine("</body>").AppendLine("</html>");

			File.WriteAllText(Path.Combine(dstPath, "results.html"), html.ToString());
		}
Exemplo n.º 4
0
        private void BatchSaveForUnitTests()
        {
            var path = @"d:\Programs\Benchmarks\Fraps\Screenshots";

            var pb = new ProgressBar();
            pb.Maximum = 18;
            pb.Dock = DockStyle.Bottom;
            Controls.Add(pb);
            pb.Show();

            foreach (var file in Directory.GetFiles(path, "*.png"))
            {
                var bmp = Bitmap.FromFile(file) as Bitmap;
                var result = Screenshot.GetTooltip(bmp, false);
                if (result == null)
                {
                    Debugger.Break();
                    return;
                }

                var tt = new D3Bit.Tooltip(result);
                var r = new Results(tt);

                pbItem.Image = tt.Processed;

                SaveForUnitTests(r, result, bmp.Size);
                pb.Increment(1);
                Trace.TraceInformation("Saved " + r.Name);
                bmp.Dispose();
            }
            pb.Hide();
            MessageBox.Show("Done!");
        }
Exemplo n.º 5
0
		private static void RenderResults(StringBuilder html, Results r)
		{
			html.AppendLine("<strong>Name</strong>: " + r.Name);
			html.AppendLine("<strong>Type</strong>: " + r.Quality + " " + r.Type);
			html.AppendLine("<strong>DPS</strong>: " + r.DPS);
			html.AppendLine("<strong>Meta</strong>: " + r.Meta).AppendLine();
			//html.AppendLine("<strong>Affixes</strong>: ")
			//    .AppendLine(r.Affixes.Aggregate(new StringBuilder(), (sb, kvp) => sb.AppendLine("<strong>{0}</strong> = {1}", kvp.Key, kvp.Value)).ToString());
			//html.AppendLine("<strong>Socket bonuses</strong>: " + r.SocketBonuses);
			html.AppendLine().AppendLine();

			html.AppendLine(@"<span class=""performance"">{0}ms</span>", r.TimeTaken);
		}