mirror of https://github.com/SixLabors/ImageSharp
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.
50 lines
1.4 KiB
50 lines
1.4 KiB
namespace ImageSharp.Tests.TestUtilities.ImageComparison
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
public class ImageSimilarityReport
|
|
{
|
|
public ImageSimilarityReport(IImageBase expectedImage, IImageBase actualImage, IEnumerable<PixelDifference> differences)
|
|
{
|
|
this.ExpectedImage = expectedImage;
|
|
this.ActualImage = actualImage;
|
|
this.Differences = differences.ToArray();
|
|
}
|
|
|
|
public IImageBase ExpectedImage { get; }
|
|
|
|
public IImageBase ActualImage { get; }
|
|
|
|
public PixelDifference[] Differences { get; }
|
|
|
|
public bool IsEmpty => this.Differences.Length == 0;
|
|
|
|
public override string ToString()
|
|
{
|
|
return this.IsEmpty ? "[SimilarImages]" : StringifyDifferences(this.Differences);
|
|
}
|
|
|
|
private static string StringifyDifferences(PixelDifference[] differences)
|
|
{
|
|
var sb = new StringBuilder();
|
|
int max = Math.Min(5, differences.Length);
|
|
|
|
for (int i = 0; i < max; i++)
|
|
{
|
|
sb.Append(differences[i]);
|
|
if (i < max - 1)
|
|
{
|
|
sb.Append("; ");
|
|
}
|
|
}
|
|
if (differences.Length >= 5)
|
|
{
|
|
sb.Append("...");
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|