示例#1
0
        private void SetupFileSystemWatcher()
        {
            // At the moment the feature is not stable so it's deactivated
            if (false)
            {
                ImageValidatorSettings settings = GetSettings();

                try
                {
                    fileSystemWatcher1.Path = settings.TestDir;
                    //            fileSystemWatcher1.NotifyFilter = NotifyFilters.LastWrite;
                    fileSystemWatcher1.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;

                    fileSystemWatcher2.Path = settings.RefDir;
                    //            fileSystemWatcher2.NotifyFilter = NotifyFilters.LastWrite;
                    fileSystemWatcher2.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
                }
                catch (System.ArgumentException)
                {
                }
                catch (System.IO.FileNotFoundException)
                {
                    // no need to handle this
                }
            }
        }
示例#2
0
 private void SetSettings(ImageValidatorSettings settings)
 {
     textBoxTestDir.Text     = settings.TestDir;
     textBoxRefDir.Text      = settings.RefDir;
     textBoxThreshold.Text   = settings.Threshold.ToString();
     textBoxCountToFail.Text = settings.PixelCountToFail.ToString();
 }
示例#3
0
        private bool LoadSettings(string FileName)
        {
            SetFileName(FileName);

            ImageValidatorSettings settings = new ImageValidatorSettings();

            XmlSerializer serializer = new XmlSerializer(settings.GetType());

            try
            {
                using (StreamReader file = new StreamReader(FileName))
                {
                    settings = serializer.Deserialize(file) as ImageValidatorSettings;
                    SetSettings(settings);
                }

                PopulateList();
                SetupFileSystemWatcher();
            }
            catch (Exception)
            {
                // update UI
                SetSettings(settings);
                return(false);
            }

            // update UI
            SetSettings(settings);

            return(true);
        }
示例#4
0
        private void GenerateHTMLReport(bool bThumbnails)
        {
//            string f = Clipboard.GetText();
//            HtmlFragment.CopyToClipboard("<b>Hello!</b>");
//            HtmlFragment.CopyToClipboard("<table style=\"width:100%\"><tr><th>Firstname</th><th>Lastname</th><th>Points</th></tr><tr><td>Jill</td><td>Smith</td><td>50</td></tr><tr><td>Eve</td><td>Jackson</td><td>94</td></tr><tr><td>John</td><td>Doe</td><td>80</td></tr></table>");

//            return;

            //   HtmlFragment.CopyToClipboard("<img width=240 height=160 src=\"data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7\">");

            if (saveFileDialogExport.ShowDialog() == DialogResult.OK)
            {
                ReportGenerator reportGenerator = new ReportGenerator();

                ImageValidatorSettings settings = GetSettings();

                string SettingsFileName = GetFileName();

                WaitUntilTestIsDone(ref data, ref settings);
                reportGenerator.ExportHTML(SettingsFileName, ref data, ref settings, saveFileDialogExport.FileName, false, bThumbnails);
            }

/*
 * //            var image = resizeImage(in
 *          ImageValidatorSettings settings = GetSettings();termediate.imageRef, 16 * 5, 9 * 5);
 *          var image = resizeImage(intermediate.imageRef, 16 * 5, 9 * 5);
 *
 *          MemoryStream stream = new MemoryStream();
 *
 * //            image.Save("d:\\temp\\da.png", ImageFormat.Png);
 *
 *          image.Save(stream, ImageFormat.Png);
 *
 * //            Convert.ToBase64CharArray(inArray, 0, inArray.Length, outArray, 0);
 *
 *          string Ret = "";
 *          for (int f = 0; f < 20; ++f)
 *          {
 *              Ret += "<img width=\"" + image.Width + "\" height=\"" + image.Height + "\" src=\"data:image/png;base64,";
 *  //            string Ret = "<img width=240 height=160 src=\"data:image/gif;base64,";
 *
 *              Ret += Convert.ToBase64String(stream.ToArray());
 *
 *  //            Ret += ConvertToBase64(stream);
 *  //            Ret += "R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7";
 *
 *              Ret += "\">\n";
 *          }
 *          HtmlFragment.CopyToClipboard(Ret);
 */

/*
 *                      var bytes = File.ReadAllBytes("C:\\somepath\\picture.png");
 *                      var b64String = Convert.ToBase64String(bytes);
 *                      var dataUrl = "data:image/png;base64," + b64String;
 */

//            image. ToBase64String();
        }
示例#5
0
 /*  // http://stackoverflow.com/questions/19134062/encode-a-filestream-to-base64-with-c-sharp
  * public string ConvertToBase64(Stream stream)
  * {
  *    byte[] inArray = new byte[(int)stream.Length];
  *    stream.Read(inArray, 0, (int)stream.Length);
  * //            return Convert.ToBase64String(inArray);
  *
  *    byte[] byt = System.Text.Encoding.UTF8.GetBytes(inArray);
  *
  *    // convert the byte array to a Base64 string
  *
  *    return Convert.ToBase64String(byt);
  * }
  */
 private void WaitUntilTestIsDone(ref ImageValidatorData data, ref ImageValidatorSettings settings)
 {
     // todo: progress bar, cancel button
     while (data.ProcessOneElement(settings))
     {
         UpdateListView();
     }
 }
示例#6
0
        private void newToolStripMenuNew_Click(object sender, EventArgs e)
        {
            DialogResult d = MessageBox.Show("Are you sure you want to create a new document?\nYour changes will not be saved.", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (d == DialogResult.Yes)
            {
                ImageValidatorSettings settings = new ImageValidatorSettings();

                SetSettings(settings);
                PopulateList();
            }
        }
示例#7
0
        // @retur if a element was processed
        public bool ProcessOneElement(ImageValidatorSettings settings)
        {
            foreach (ImageEntry entry in imageEntries)
            {
                if (entry.testResult == null)
                {
                    ImageValidatorIntermediate intermediate = new ImageValidatorIntermediate();
                    intermediate.Process(settings, entry);
                    return(true);
                }
            }

            return(false);
        }
示例#8
0
        public string GetString(ref ImageValidatorSettings settings)
        {
            if (ErrorText != null)
            {
                return(ErrorText);
            }
            else
            {
                string Ret = IsPassed(ref settings) ? "Passed" : "Failed";

                Ret += " (" + ErrorPixels.ToString() + ")";

                return(Ret);
            }
        }
示例#9
0
        private void UpdateListView()
        {
            // select first element if no element is currently selected
            int SelectedImageIndex = 0;

            if (listView1.SelectedIndices.Count == 1)
            {
                SelectedImageIndex = listView1.Items[listView1.SelectedIndices[0]].ImageIndex;
                listView1.SelectedIndices.Clear();
            }

            listView1.Items.Clear();

            ImageValidatorSettings settings = GetSettings();

            int Index = 0;

            foreach (ImageValidatorData.ImageEntry entry in data.imageEntries)
            {
                ImageValidatorData.ImageEntryColumnData columnData = new ImageValidatorData.ImageEntryColumnData(entry.Name);

                string ResultString = "?";

                if (entry.testResult != null)
                {
                    ResultString = entry.testResult.GetString(ref settings);
                }
                ListViewItem item = new ListViewItem(ResultString, Index++);
                item.SubItems.Add(columnData.Time);
//                item.SubItems.Add((1.0f + 0.1f * Index).ToString());
//                item.SubItems.Add(columnData.Actor);
//                item.SubItems.Add(columnData.Map);
//                item.SubItems.Add(columnData.Platform);
                item.SubItems.Add(Path.GetDirectoryName(entry.Name));
                item.SubItems.Add(Path.GetFileName(entry.Name));
                if (entry.testResult != null)
                {
                    item.BackColor = entry.testResult.GetColor(ref settings);
                }

                listView1.Items.Add(item);
            }

            if (listView1.Items.Count > 0)
            {
                listView1.SelectedIndices.Add(FindListViewIndexFromImageIndex(SelectedImageIndex));
            }
        }
示例#10
0
        public void Process(ImageValidatorSettings settings, ImageValidatorData.ImageEntry imageEntry)
        {
            if (imageTest != null)
            {
                imageTest.Dispose(); imageTest = null;
            }
            if (imageRef != null)
            {
                imageRef.Dispose(); imageRef = null;
            }

            imageTest = LoadBitmap(settings.TestDir + imageEntry.Name);
            imageRef  = LoadBitmap(settings.RefDir + imageEntry.Name);

            imageEntry.testResult = ComputeDiff(settings.Threshold);
        }
            public ValidationSummary(ref ImageValidatorData data, ref ImageValidatorSettings settings)
            {
                Failed    = 0;
                Succeeded = 0;

                foreach (ImageValidatorData.ImageEntry entry in data.imageEntries)
                {
                    TestResult test = entry.testResult;

                    if (test.IsPassed(ref settings))
                    {
                        ++Succeeded;
                    }
                    else
                    {
                        ++Failed;
                    }
                }
            }
            public ValidationSummary(ref ImageValidatorData data, ref ImageValidatorSettings settings)
            {
                Failed = 0;
                Succeeded = 0;

                foreach (ImageValidatorData.ImageEntry entry in data.imageEntries)
                {
                    TestResult test = entry.testResult;

                    if (test.IsPassed(ref settings))
                    {
                        ++Succeeded;
                    }
                    else
                    {
                        ++Failed;
                    }
                }
            }
示例#13
0
        private bool SaveSettings(string FileName)
        {
            SetFileName(saveFileDialog1.FileName);

            ImageValidatorSettings settings = GetSettings();

            XmlSerializer serializer = new XmlSerializer(settings.GetType());

            try
            {
                using (StreamWriter file = new StreamWriter(FileName))
                {
                    serializer.Serialize(file, settings);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
示例#14
0
        private ImageValidatorSettings GetSettings()
        {
            ImageValidatorSettings settings = new ImageValidatorSettings();

            settings.TestDir = textBoxTestDir.Text;
            settings.RefDir  = textBoxRefDir.Text;

            {
                int Value;
                Int32.TryParse(this.textBoxThreshold.Text, out Value);

                if (Value > 0)
                {
                    settings.Threshold = (uint)Value;
                }
            }

            {
                int Value;
                Int32.TryParse(this.textBoxCountToFail.Text, out Value);

                if (Value > 0)
                {
                    settings.PixelCountToFail = (uint)Value;
                }
            }


            /*
             * if (settings.TestDir == settings.RefDir)
             * {
             *  // it doesn't make sense to compare the same folders
             *  settings.TestDir = "";
             *  settings.RefDir = "";
             * }
             */

            return(settings);
        }
        // @retur if a element was processed
        public bool ProcessOneElement(ImageValidatorSettings settings)
        {
            foreach (ImageEntry entry in imageEntries)
            {
                if (entry.testResult == null)
                {
                    ImageValidatorIntermediate intermediate = new ImageValidatorIntermediate();
                    intermediate.Process(settings, entry);
                    return true;
                }
            }

            return false;
        }
        public void ExportHTML(string SettingsFileName, ref ImageValidatorData data, ref ImageValidatorSettings settings, string FileName, bool bSilent, bool bThumbnails)
        {
            ValidationSummary validationSummary = new ValidationSummary(ref data, ref settings);

            string Folder = Path.GetDirectoryName(FileName) + "\\" + Path.GetFileNameWithoutExtension(FileName) + "_Thumbnails";

            if (bThumbnails)
            {
                Directory.CreateDirectory(Folder);
            }

            // Note C# string literals can span multiple lines, " need to be converted to ""
            string template = @"
<!DOCTYPE HTML PUBLIC \""-//W3C//DTD HTML 4.01 Transitional//EN\"" \""http://www.w3.org/TR/html4/loose.dtd\"">
<html>
<head>
<title>ImageValidator Report</title>
</head>
<body>
<h1>ImageValidator Report</h1>

<br>
<h4>ImageValidator Settings ""%SETTINGSFILENAME%"":</h4>
<div style=""margin:10px;margin-left:40px"" >%SETTINGS% </div>
<br>

<h4>Summary:</h4>
<div style=""margin:10px;margin-left:40px""> %SUMMARY% </div>
<br>

<h4>Output:</h4>
<div style=""margin:10px;margin-left:40px""> %OUTPUT% </div>
<br>

<br>
<b>Generated by Application:</b> ImageValidator.exe (part of UnrealEngine by Epic Games)<br>
<b>Application Version:</b> %VERSION%<br>
<b>Generated by User:</b> %USER%<br>
<b>Generated Date:</b> %DATE%<br>

<style type=""text/css"">
//body { background-color:#000000; color:#E0E0E0 }

* {
    font-family: ?Times New Roman?, Times, serif;
 //   font-weight: bold;
    
}

h1 { color:#555555; font-size:32px; border-bottom:solid thin black; }

table, hd, th {
    border:0px; color:#000000; padding:4px; border-spacing:0px;
    border-collapse:collapse;
    }
   
td { padding:2px; padding-right:7px }
td.Output { padding:7px; border:1px solid #cccccc; }

th {
    background-color:#E0E0E0;
    color: #000000;
    text-align: left;
    border: 1px solid #c0c0c0;
}

a.prefix {
    border: 0px solid;
    padding: 3px;
    padding-left: 5px;
    padding-right: 5px;
    font-weight: bold;
    text-decoration:none;
    margin:4px;
    white-space: nowrap;
}

a.prefix:link {
    border:1px solid #7777FF;
    background-color:#ddddff;
    color: #7777FF;
}


a.prefix:hover {
    background-color:#7777FF;
    color: #ddddff;
}

</style>
    
</body>
</html>";

            // we can change this if needed:
            //ImageFormat imageFormat = ImageFormat.Jpeg;   // small file size?
            //ImageFormat imageFormat = ImageFormat.Gif;   // dither artifacts
            ImageFormat imageFormat = ImageFormat.Png;    // good compromise

            // we derive the extension from imageFormat e.g. ".jpg"
            string imageFormatExtension = "";
            {
                if (imageFormat == ImageFormat.Jpeg)
                {
                    imageFormatExtension = ".jpg";
                }
                else if (imageFormat == ImageFormat.Gif)
                {
                    imageFormatExtension = ".gif";
                }
                else if (imageFormat == ImageFormat.Png)
                {
                    imageFormatExtension = ".Png";
                }

                Debug.Assert(imageFormatExtension != "");
            }

            // todo: how to repro, Date, IVxml file attached?, thumbnails

            string Output = "<table class=Output><tr>";

            Output += "<th>Result (pixels failed)</th>";

            if (bThumbnails)
            {
                Output += "<th>Thumbnails (test/diff/ref)</th>";
            }
            Output += "<th>Matinee Location (in sec)</th>";
            //            Output += "<th>Actor</th>";
            //            Output += "<th>Map</th>";
            //            Output += "<th>Platform</th>";
            Output += "<th>Folder Name</th>";
            Output += "<th>File Name</th></tr>\n";
            {
                uint Index = 0;
                foreach (ImageValidatorData.ImageEntry entry in data.imageEntries)
                {
                    TestResult test = entry.testResult;
                    bool bShowDiffAndRefThumbnails = !test.IsPassed(ref settings);

                    // open table row
                    Output += "<tr class=Output>";

                    Color BackColor = Color.White;

                    string ThumbnailTest = Folder + "\\Test" + Index + imageFormatExtension;
                    string ThumbnailDiff = Folder + "\\Diff" + Index + imageFormatExtension;
                    string ThumbnailRef = Folder + "\\Ref" + Index + imageFormatExtension;

                    if (test != null)
                    {
                        BackColor = test.GetColor(ref settings);

                        if (bThumbnails)
                        {
                            test.ThumbnailTest.Save(ThumbnailTest, imageFormat);

                            if (bShowDiffAndRefThumbnails)
                            {
                                test.ThumbnailDiff.Save(ThumbnailDiff, imageFormat);
                                test.ThumbnailRef.Save(ThumbnailRef, imageFormat);
                            }
                        }
                    }

                    ImageValidatorData.ImageEntryColumnData columnData = new ImageValidatorData.ImageEntryColumnData(entry.Name);

                    string ResultString = "?";

                    if (entry.testResult != null)
                    {
                        ResultString = entry.testResult.GetString(ref settings);
                    }

                    Output += "<td class=Output bgcolor=" + ColorTranslator.ToHtml(BackColor) + ">" + ResultString + "</td>";

                    // thumbnails
                    if (bThumbnails)
                    {
                        Output += "<td class=Output>";

                        if (test != null)
                        {
                            Output += "<img src=\"" + ThumbnailTest + "\" width=" + test.ThumbnailTest.Width + " height=" + test.ThumbnailTest.Height + ">";

                            if (bShowDiffAndRefThumbnails)
                            {
                                Output += "<img src=\"" + ThumbnailDiff + "\" width=" + test.ThumbnailDiff.Width + " height=" + test.ThumbnailDiff.Height + ">";
                                Output += "<img src=\"" + ThumbnailRef + "\" width=" + test.ThumbnailRef.Width + " height=" + test.ThumbnailRef.Height + ">";
                            }
                        }

                        Output += "</td>";
                    }

                    Output += "<td class=Output>" + columnData.Time + "</td>";
                    //                    Output += "<td class=Output>" + columnData.Actor + "</td>";
                    //                    Output += "<td class=Output>" + columnData.Map + "</td>";
                    //                    Output += "<td class=Output>" + columnData.Platform + "</td>";
                    Output += "<td class=Output>" + Path.GetDirectoryName(entry.Name) + "</td>";
                    Output += "<td class=Output>" + Path.GetFileName(entry.Name) + "</td>";

                    // close table row
                    Output += "</tr>\n";
                    ++Index;
                }
                Output += "</table>\n";
            }

            string SettingsString = "";
            {
                SettingsString +=
                    "<table>\n" +
                    "<tr><td>Test Directory:</td> <td>" + settings.TestDir + "</td></tr>\n" +
                    "<tr><td>Reference Directory:</td> <td>" + settings.RefDir + "</td></tr>\n" +
                    "<tr><td>Threshold (in 0..255 range):</td> <td>" + settings.Threshold + "</td></tr>\n" +
                    "<tr><td>PixelCountToFail:</td> <td>" + settings.PixelCountToFail + "</td></tr>\n" +
                    "</table>\n";
            }

            string SummaryString = "";
            {
                bool bPassed = validationSummary.Failed == 0;

                string FailedColor = "";
                string SuceededColor = "";

                if (bPassed)
                {
                    SuceededColor = " bgcolor=" + ColorTranslator.ToHtml(TestResult.GetColor(true));
                }
                else
                {
                    FailedColor = " bgcolor=" + ColorTranslator.ToHtml(TestResult.GetColor(false));
                }
                
                SummaryString +=
                    "<table>\n" +
//                    "<tr><td>Files processed:</td> <td>" + (validationSummary.Failed + validationSummary.Succeeded) + "</td></tr>\n" +
                    "<tr><td" + FailedColor + ">Failed:</td> <td" + FailedColor + ">" + validationSummary.Failed + "</td></tr>\n" +
                    "<tr><td" + SuceededColor + ">Succeeded:</td> <td" + SuceededColor + ">" + validationSummary.Succeeded + "</td></tr>\n" +
                    "</table>\n";
            }

            template = template.Replace("%DATE%", DateTime.Now.ToString());
            template = template.Replace("%SETTINGSFILENAME%", SettingsFileName);

            template = template.Replace("%SETTINGS%", SettingsString);
            template = template.Replace("%SUMMARY%", SummaryString);

            template = template.Replace("%OUTPUT%", Output);
            template = template.Replace("%USER%", Environment.UserName);
            template = template.Replace("%VERSION%", ImageValidatorSettings.GetVersionString());


            System.IO.File.WriteAllText(FileName, template);

            if (!bSilent)
            {
                MessageBox.Show("Export to HTML successful", "ImageValidator", MessageBoxButtons.OK);
            }
        }
示例#17
0
      /*  // http://stackoverflow.com/questions/19134062/encode-a-filestream-to-base64-with-c-sharp
        public string ConvertToBase64(Stream stream)
        {
            byte[] inArray = new byte[(int)stream.Length];
            stream.Read(inArray, 0, (int)stream.Length);
//            return Convert.ToBase64String(inArray);

            byte[] byt = System.Text.Encoding.UTF8.GetBytes(inArray);

            // convert the byte array to a Base64 string

            return Convert.ToBase64String(byt);
        }
*/
        private void WaitUntilTestIsDone(ref ImageValidatorData data, ref ImageValidatorSettings settings)
        {
            // todo: progress bar, cancel button
            while (data.ProcessOneElement(settings))
            {
                UpdateListView();
            }
        }
 public bool IsPassed(ref ImageValidatorSettings settings)
 {
     return ErrorText == null && ErrorPixels < settings.PixelCountToFail;
 }
示例#19
0
        private void newToolStripMenuNew_Click(object sender, EventArgs e)
        {
            DialogResult d = MessageBox.Show("Are you sure you want to create a new document?\nYour changes will not be saved.", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (d == DialogResult.Yes)
            {
                ImageValidatorSettings settings = new ImageValidatorSettings();

                SetSettings(settings);
                PopulateList();
            }
        }
示例#20
0
 public bool IsPassed(ref ImageValidatorSettings settings)
 {
     return(ErrorText == null && ErrorPixels < settings.PixelCountToFail);
 }
示例#21
0
 public Color GetColor(ref ImageValidatorSettings settings)
 {
     return(GetColor(IsPassed(ref settings)));
 }
 public Color GetColor(ref ImageValidatorSettings settings)
 {
     return GetColor(IsPassed(ref settings));
 }
        public void ExportHTML(string SettingsFileName, ref ImageValidatorData data, ref ImageValidatorSettings settings, string FileName, bool bSilent, bool bThumbnails)
        {
            ValidationSummary validationSummary = new ValidationSummary(ref data, ref settings);

            string Folder = Path.GetDirectoryName(FileName) + "\\" + Path.GetFileNameWithoutExtension(FileName) + "_Thumbnails";

            if (bThumbnails)
            {
                Directory.CreateDirectory(Folder);
            }

            // Note C# string literals can span multiple lines, " need to be converted to ""
            string template = @"
<!DOCTYPE HTML PUBLIC \""-//W3C//DTD HTML 4.01 Transitional//EN\"" \""http://www.w3.org/TR/html4/loose.dtd\"">
<html>
<head>
<title>ImageValidator Report</title>
</head>
<body>
<h1>ImageValidator Report</h1>

<br>
<h4>ImageValidator Settings ""%SETTINGSFILENAME%"":</h4>
<div style=""margin:10px;margin-left:40px"" >%SETTINGS% </div>
<br>

<h4>Summary:</h4>
<div style=""margin:10px;margin-left:40px""> %SUMMARY% </div>
<br>

<h4>Output:</h4>
<div style=""margin:10px;margin-left:40px""> %OUTPUT% </div>
<br>

<br>
<b>Generated by Application:</b> ImageValidator.exe (part of UnrealEngine by Epic Games)<br>
<b>Application Version:</b> %VERSION%<br>
<b>Generated by User:</b> %USER%<br>
<b>Generated Date:</b> %DATE%<br>

<style type=""text/css"">
//body { background-color:#000000; color:#E0E0E0 }

* {
    font-family: ?Times New Roman?, Times, serif;
 //   font-weight: bold;
    
}

h1 { color:#555555; font-size:32px; border-bottom:solid thin black; }

table, hd, th {
    border:0px; color:#000000; padding:4px; border-spacing:0px;
    border-collapse:collapse;
    }
   
td { padding:2px; padding-right:7px }
td.Output { padding:7px; border:1px solid #cccccc; }

th {
    background-color:#E0E0E0;
    color: #000000;
    text-align: left;
    border: 1px solid #c0c0c0;
}

a.prefix {
    border: 0px solid;
    padding: 3px;
    padding-left: 5px;
    padding-right: 5px;
    font-weight: bold;
    text-decoration:none;
    margin:4px;
    white-space: nowrap;
}

a.prefix:link {
    border:1px solid #7777FF;
    background-color:#ddddff;
    color: #7777FF;
}


a.prefix:hover {
    background-color:#7777FF;
    color: #ddddff;
}

</style>
    
</body>
</html>";

            // we can change this if needed:
            //ImageFormat imageFormat = ImageFormat.Jpeg;   // small file size?
            //ImageFormat imageFormat = ImageFormat.Gif;   // dither artifacts
            ImageFormat imageFormat = ImageFormat.Png;    // good compromise

            // we derive the extension from imageFormat e.g. ".jpg"
            string imageFormatExtension = "";
            {
                if (imageFormat == ImageFormat.Jpeg)
                {
                    imageFormatExtension = ".jpg";
                }
                else if (imageFormat == ImageFormat.Gif)
                {
                    imageFormatExtension = ".gif";
                }
                else if (imageFormat == ImageFormat.Png)
                {
                    imageFormatExtension = ".Png";
                }

                Debug.Assert(imageFormatExtension != "");
            }

            // todo: how to repro, Date, IVxml file attached?, thumbnails

            string Output = "<table class=Output><tr>";

            Output += "<th>Result (pixels failed)</th>";

            if (bThumbnails)
            {
                Output += "<th>Thumbnails (test/diff/ref)</th>";
            }
            Output += "<th>Matinee Location (in sec)</th>";
            //            Output += "<th>Actor</th>";
            //            Output += "<th>Map</th>";
            //            Output += "<th>Platform</th>";
            Output += "<th>Folder Name</th>";
            Output += "<th>File Name</th></tr>\n";
            {
                uint Index = 0;
                foreach (ImageValidatorData.ImageEntry entry in data.imageEntries)
                {
                    TestResult test = entry.testResult;
                    bool       bShowDiffAndRefThumbnails = !test.IsPassed(ref settings);

                    // open table row
                    Output += "<tr class=Output>";

                    Color BackColor = Color.White;

                    string ThumbnailTest = Folder + "\\Test" + Index + imageFormatExtension;
                    string ThumbnailDiff = Folder + "\\Diff" + Index + imageFormatExtension;
                    string ThumbnailRef  = Folder + "\\Ref" + Index + imageFormatExtension;

                    if (test != null)
                    {
                        BackColor = test.GetColor(ref settings);

                        if (bThumbnails)
                        {
                            test.ThumbnailTest.Save(ThumbnailTest, imageFormat);

                            if (bShowDiffAndRefThumbnails)
                            {
                                test.ThumbnailDiff.Save(ThumbnailDiff, imageFormat);
                                test.ThumbnailRef.Save(ThumbnailRef, imageFormat);
                            }
                        }
                    }

                    ImageValidatorData.ImageEntryColumnData columnData = new ImageValidatorData.ImageEntryColumnData(entry.Name);

                    string ResultString = "?";

                    if (entry.testResult != null)
                    {
                        ResultString = entry.testResult.GetString(ref settings);
                    }

                    Output += "<td class=Output bgcolor=" + ColorTranslator.ToHtml(BackColor) + ">" + ResultString + "</td>";

                    // thumbnails
                    if (bThumbnails)
                    {
                        Output += "<td class=Output>";

                        if (test != null)
                        {
                            Output += "<img src=\"" + ThumbnailTest + "\" width=" + test.ThumbnailTest.Width + " height=" + test.ThumbnailTest.Height + ">";

                            if (bShowDiffAndRefThumbnails)
                            {
                                Output += "<img src=\"" + ThumbnailDiff + "\" width=" + test.ThumbnailDiff.Width + " height=" + test.ThumbnailDiff.Height + ">";
                                Output += "<img src=\"" + ThumbnailRef + "\" width=" + test.ThumbnailRef.Width + " height=" + test.ThumbnailRef.Height + ">";
                            }
                        }

                        Output += "</td>";
                    }

                    Output += "<td class=Output>" + columnData.Time + "</td>";
                    //                    Output += "<td class=Output>" + columnData.Actor + "</td>";
                    //                    Output += "<td class=Output>" + columnData.Map + "</td>";
                    //                    Output += "<td class=Output>" + columnData.Platform + "</td>";
                    Output += "<td class=Output>" + Path.GetDirectoryName(entry.Name) + "</td>";
                    Output += "<td class=Output>" + Path.GetFileName(entry.Name) + "</td>";

                    // close table row
                    Output += "</tr>\n";
                    ++Index;
                }
                Output += "</table>\n";
            }

            string SettingsString = "";
            {
                SettingsString +=
                    "<table>\n" +
                    "<tr><td>Test Directory:</td> <td>" + settings.TestDir + "</td></tr>\n" +
                    "<tr><td>Reference Directory:</td> <td>" + settings.RefDir + "</td></tr>\n" +
                    "<tr><td>Threshold (in 0..255 range):</td> <td>" + settings.Threshold + "</td></tr>\n" +
                    "<tr><td>PixelCountToFail:</td> <td>" + settings.PixelCountToFail + "</td></tr>\n" +
                    "</table>\n";
            }

            string SummaryString = "";

            {
                bool bPassed = validationSummary.Failed == 0;

                string FailedColor   = "";
                string SuceededColor = "";

                if (bPassed)
                {
                    SuceededColor = " bgcolor=" + ColorTranslator.ToHtml(TestResult.GetColor(true));
                }
                else
                {
                    FailedColor = " bgcolor=" + ColorTranslator.ToHtml(TestResult.GetColor(false));
                }

                SummaryString +=
                    "<table>\n" +
//                    "<tr><td>Files processed:</td> <td>" + (validationSummary.Failed + validationSummary.Succeeded) + "</td></tr>\n" +
                    "<tr><td" + FailedColor + ">Failed:</td> <td" + FailedColor + ">" + validationSummary.Failed + "</td></tr>\n" +
                    "<tr><td" + SuceededColor + ">Succeeded:</td> <td" + SuceededColor + ">" + validationSummary.Succeeded + "</td></tr>\n" +
                    "</table>\n";
            }

            template = template.Replace("%DATE%", DateTime.Now.ToString());
            template = template.Replace("%SETTINGSFILENAME%", SettingsFileName);

            template = template.Replace("%SETTINGS%", SettingsString);
            template = template.Replace("%SUMMARY%", SummaryString);

            template = template.Replace("%OUTPUT%", Output);
            template = template.Replace("%USER%", Environment.UserName);
            template = template.Replace("%VERSION%", ImageValidatorSettings.GetVersionString());


            System.IO.File.WriteAllText(FileName, template);

            if (!bSilent)
            {
                MessageBox.Show("Export to HTML successful", "ImageValidator", MessageBoxButtons.OK);
            }
        }
示例#24
0
 // settings file name
 private void SetFileName(string FileName)
 {
     // set window title
     Text = Path.GetFileName(FileName) + " - ImageValidator " + ImageValidatorSettings.GetVersionString();
     openFileDialog1.FileName = FileName;
 }
示例#25
0
 private void SetSettings(ImageValidatorSettings settings)
 {
     textBoxTestDir.Text = settings.TestDir;
     textBoxRefDir.Text = settings.RefDir;
     textBoxThreshold.Text = settings.Threshold.ToString();
     textBoxCountToFail.Text = settings.PixelCountToFail.ToString();
 }
        public string GetString(ref ImageValidatorSettings settings)
        {
            if (ErrorText != null)
            {
                return ErrorText;
            }
            else
            {
                string Ret = IsPassed(ref settings) ? "Passed" : "Failed";

                Ret += " (" + ErrorPixels.ToString() + ")";

                return Ret;
            }
        }
示例#27
0
        private ImageValidatorSettings GetSettings()
        {
            ImageValidatorSettings settings = new ImageValidatorSettings();

            settings.TestDir = textBoxTestDir.Text;
            settings.RefDir = textBoxRefDir.Text;

            {
                int Value;
                Int32.TryParse(this.textBoxThreshold.Text, out Value);

                if (Value > 0)
                {
                    settings.Threshold = (uint)Value;
                }
            }

            {
                int Value;
                Int32.TryParse(this.textBoxCountToFail.Text, out Value);

                if (Value > 0)
                {
                    settings.PixelCountToFail = (uint)Value;
                }
            }


            /*
            if (settings.TestDir == settings.RefDir)
            {
                // it doesn't make sense to compare the same folders
                settings.TestDir = "";
                settings.RefDir = "";
            }
            */

            return settings;
        }
        public void Process(ImageValidatorSettings settings, ImageValidatorData.ImageEntry imageEntry)
        {
            if (imageTest != null) { imageTest.Dispose(); imageTest = null; }
            if (imageRef != null) { imageRef.Dispose(); imageRef = null; }

            imageTest = LoadBitmap(settings.TestDir + imageEntry.Name);
            imageRef = LoadBitmap(settings.RefDir + imageEntry.Name);

            imageEntry.testResult = ComputeDiff(settings.Threshold);
        }
示例#29
0
        private bool LoadSettings(string FileName)
        {
            SetFileName(FileName);

            ImageValidatorSettings settings = new ImageValidatorSettings();

            XmlSerializer serializer = new XmlSerializer(settings.GetType());

            try
            {
                using (StreamReader file = new StreamReader(FileName))
                {
                    settings = serializer.Deserialize(file) as ImageValidatorSettings;
                    SetSettings(settings);
                }

                PopulateList();
                SetupFileSystemWatcher();
            }
            catch (Exception)
            {
                // update UI
                SetSettings(settings);
                return false;
            }

            // update UI
            SetSettings(settings);

            return true;
        }