// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO; // Path
using System.Drawing; // Color
using System.Drawing.Imaging; // ImageData
using System.Diagnostics; // Debug.
using System.Windows.Forms; // MessageBox
namespace ImageValidator
{
class ReportGenerator
{
private struct ValidationSummary
{
public uint Failed;
public uint Succeeded;
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 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 = @"
ImageValidator Report
ImageValidator Report
ImageValidator Settings ""%SETTINGSFILENAME%"":
%SETTINGS%
Summary:
%SUMMARY%
Output:
%OUTPUT%
Generated by Application: ImageValidator.exe (part of UnrealEngine by Epic Games)
Application Version: %VERSION%
Generated by User: %USER%
Generated Date: %DATE%
";
// 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 = "";
Output += "Result (pixels failed) | ";
if (bThumbnails)
{
Output += "Thumbnails (test/diff/ref) | ";
}
Output += "Matinee Location (in sec) | ";
// Output += "Actor | ";
// Output += "Map | ";
// Output += "Platform | ";
Output += "Folder Name | ";
Output += "File Name |
\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 += "";
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 += "" + ResultString + " | ";
// thumbnails
if (bThumbnails)
{
Output += "";
if (test != null)
{
Output += " ";
if (bShowDiffAndRefThumbnails)
{
Output += " ";
Output += " ";
}
}
Output += " | ";
}
Output += "" + columnData.Time + " | ";
// Output += "" + columnData.Actor + " | ";
// Output += "" + columnData.Map + " | ";
// Output += "" + columnData.Platform + " | ";
Output += "" + Path.GetDirectoryName(entry.Name) + " | ";
Output += "" + Path.GetFileName(entry.Name) + " | ";
// close table row
Output += "
\n";
++Index;
}
Output += "
\n";
}
string SettingsString = "";
{
SettingsString +=
"\n" +
"Test Directory: | " + settings.TestDir + " |
\n" +
"Reference Directory: | " + settings.RefDir + " |
\n" +
"Threshold (in 0..255 range): | " + settings.Threshold + " |
\n" +
"PixelCountToFail: | " + settings.PixelCountToFail + " |
\n" +
"
\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 +=
"\n" +
// "Files processed: | " + (validationSummary.Failed + validationSummary.Succeeded) + " |
\n" +
"Failed: | " + validationSummary.Failed + " |
\n" +
"Succeeded: | " + validationSummary.Succeeded + " |
\n" +
"
\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);
}
}
}
}