Browse Source

.

pull/298/head
Anton Firszov 9 years ago
parent
commit
9da4345485
  1. 12
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  2. 4
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs

12
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -40,7 +40,7 @@ namespace ImageSharp.Tests
private ITestOutputHelper Output { get; } private ITestOutputHelper Output { get; }
private float GetSimilarityPercentage<TPixel>(Image<TPixel> image, TestImageProvider<TPixel> provider) private float GetDifferenceInPercents<TPixel>(Image<TPixel> image, TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
var reportingComparer = ImageComparer.Tolerant(0, 0); var reportingComparer = ImageComparer.Tolerant(0, 0);
@ -55,7 +55,7 @@ namespace ImageSharp.Tests
return report.TotalNormalizedDifference.Value * 100; return report.TotalNormalizedDifference.Value * 100;
} }
return 100; return 0;
} }
[Theory] [Theory]
@ -68,14 +68,14 @@ namespace ImageSharp.Tests
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
{ {
double similarity = this.GetSimilarityPercentage(image, provider); double d = this.GetDifferenceInPercents(image, provider);
this.Output.WriteLine($"Similarity with ORIGINAL decoder: {similarity:0.0000}%"); this.Output.WriteLine($"Difference using ORIGINAL decoder: {d:0.0000}%");
} }
using (Image<TPixel> image = provider.GetImage(new PdfJsJpegDecoder())) using (Image<TPixel> image = provider.GetImage(new PdfJsJpegDecoder()))
{ {
double similarity = this.GetSimilarityPercentage(image, provider); double d = this.GetDifferenceInPercents(image, provider);
this.Output.WriteLine($"Similarity with PDFJS decoder: {similarity:0.0000}%"); this.Output.WriteLine($"Difference using PDFJS decoder: {d:0.0000}%");
} }
} }

4
tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs

@ -73,13 +73,13 @@
var diff = new PixelDifference(new Point(x, y), aBuffer[x], bBuffer[x]); var diff = new PixelDifference(new Point(x, y), aBuffer[x], bBuffer[x]);
differences.Add(diff); differences.Add(diff);
float percentageDiff = (float)d / 4.0f / 255.0f; totalDifference += d;
totalDifference += percentageDiff;
} }
} }
} }
float normalizedDifference = totalDifference / ((float)actual.Width * (float)actual.Height); float normalizedDifference = totalDifference / ((float)actual.Width * (float)actual.Height);
normalizedDifference /= 4.0f * 255.0f;
if (normalizedDifference > this.ImageThreshold) if (normalizedDifference > this.ImageThreshold)
{ {

Loading…
Cancel
Save