📷 A modern, cross-platform, 2D Graphics library for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

69 lines
2.2 KiB

namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class ImageSimilarityReport
{
public ImageSimilarityReport(
IImageFrame expectedImage,
IImageFrame actualImage,
IEnumerable<PixelDifference> differences,
float? totalNormalizedDifference = null)
{
this.ExpectedImage = expectedImage;
this.ActualImage = actualImage;
this.TotalNormalizedDifference = totalNormalizedDifference;
this.Differences = differences.ToArray();
}
public static ImageSimilarityReport Empty =>
new ImageSimilarityReport(null, null, Enumerable.Empty<PixelDifference>(), 0f);
// TODO: This should not be a nullable value!
public float? TotalNormalizedDifference { get; }
public string DifferencePercentageString => this.TotalNormalizedDifference.HasValue
? $"{this.TotalNormalizedDifference.Value * 100:0.0000}%"
: "?";
public IImageFrame ExpectedImage { get; }
public IImageFrame ActualImage { get; }
public PixelDifference[] Differences { get; }
public bool IsEmpty => this.Differences.Length == 0;
public override string ToString()
{
return this.IsEmpty ? "[SimilarImages]" : this.PrintDifference();
}
private string PrintDifference()
{
var sb = new StringBuilder();
if (this.TotalNormalizedDifference.HasValue)
{
sb.AppendLine($"Total difference: {this.DifferencePercentageString}");
}
int max = Math.Min(5, this.Differences.Length);
for (int i = 0; i < max; i++)
{
sb.Append(this.Differences[i]);
if (i < max - 1)
{
sb.Append("; ");
}
}
if (this.Differences.Length >= 5)
{
sb.Append("...");
}
return sb.ToString();
}
}
}