Browse Source

Use EnsureProcessorChangesAreConstrained

af/merge-core
James Jackson-South 9 years ago
parent
commit
1e4d1df2c1
  1. 34
      tests/ImageSharp.Tests/ImageComparer.cs
  2. 5
      tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs
  3. 12
      tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs
  4. 5
      tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs
  5. 5
      tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs
  6. 5
      tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs
  7. 5
      tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs
  8. 5
      tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs
  9. 5
      tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs
  10. 5
      tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs
  11. 5
      tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs
  12. 5
      tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs
  13. 5
      tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs
  14. 5
      tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs
  15. 5
      tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs
  16. 5
      tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs
  17. 5
      tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs
  18. 5
      tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs
  19. 5
      tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs
  20. 5
      tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs
  21. 5
      tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs
  22. 7
      tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs
  23. 2
      tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs
  24. 5
      tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs
  25. 5
      tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs

34
tests/ImageSharp.Tests/ImageComparer.cs

@ -21,6 +21,38 @@ namespace ImageSharp.Tests
const int DefaultSegmentThreshold = 3; // The greyscale difference between 2 segements my be > 3 before it influences the overall difference
const float DefaultImageThreshold = 0.000F; // After segment thresholds the images must have no differences
/// <summary>
/// Fills the bounded area with a solid color and does a visual comparison between 2 images asserting the difference outwith
/// that area is less then a configurable threshold.
/// </summary>
/// <typeparam name="TPixelA">The color of the expected image</typeparam>
/// <typeparam name="TPixelB">The color type fo the the actual image</typeparam>
/// <param name="expected">The expected image</param>
/// <param name="actual">The actual image</param>
/// <param name="bounds">The bounds within the image has been altered</param>
/// <param name="imageTheshold">
/// The threshold for the percentage difference where the images are asumed to be the same.
/// The default/undefined value is <see cref="DefaultImageThreshold"/>
/// </param>
/// <param name="segmentThreshold">
/// The threshold of the individual segments before it acumulates towards the overall difference.
/// The default undefined value is <see cref="DefaultSegmentThreshold"/>
/// </param>
/// <param name="scalingFactor">
/// This is a sampling factor we sample a grid of average pixels <paramref name="scalingFactor"/> width by <paramref name="scalingFactor"/> high
/// The default undefined value is <see cref="DefaultScalingFactor"/>
/// </param>
public static void EnsureProcessorChangesAreConstrained<TPixelA, TPixelB>(Image<TPixelA> expected, Image<TPixelB> actual, Rectangle bounds, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor)
where TPixelA : struct, IPixel<TPixelA>
where TPixelB : struct, IPixel<TPixelB>
{
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
expected.Fill(NamedColors<TPixelA>.HotPink, bounds);
actual.Fill(NamedColors<TPixelB>.HotPink, bounds);
CheckSimilarity(expected, actual, imageTheshold, segmentThreshold, scalingFactor);
}
/// <summary>
/// Does a visual comparison between 2 images and then asserts the difference is less then a configurable threshold
/// </summary>
@ -64,7 +96,7 @@ namespace ImageSharp.Tests
/// This is a sampling factor we sample a grid of average pixels <paramref name="scalingFactor"/> width by <paramref name="scalingFactor"/> high
/// The default undefined value is <see cref="ImageComparer.DefaultScalingFactor"/>
/// </param>
/// <returns>Returns a number from 0 - 1 which represents the diference focter between the images.</returns>
/// <returns>Returns a number from 0 - 1 which represents the difference focter between the images.</returns>
public static float PercentageDifference<TPixelA, TPixelB>(this Image<TPixelA> source, Image<TPixelB> target, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor)
where TPixelA : struct, IPixel<TPixelA>
where TPixelB : struct, IPixel<TPixelB>

5
tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs

@ -44,10 +44,7 @@ namespace ImageSharp.Tests.Processing.Binarization
image.BinaryThreshold(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

12
tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
namespace ImageSharp.Tests.Processing.Binarization
{
using ImageSharp.Dithering;
using ImageSharp.Dithering.Ordered;
@ -56,10 +56,7 @@ namespace ImageSharp.Tests
image.Dither(ditherer, bounds)
.DebugSave(provider, name, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
@ -88,10 +85,7 @@ namespace ImageSharp.Tests
image.Dither(diffuser,.5F, bounds)
.DebugSave(provider, name, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs

@ -36,10 +36,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
image.BlackWhite(bounds)
.DebugSave(provider, null, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs

@ -50,10 +50,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
image.ColorBlindness(colorBlindness, bounds)
.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs

@ -54,10 +54,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
image.Grayscale(value, bounds)
.DebugSave(provider, value.ToString());
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs

@ -43,10 +43,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
image.Hue(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs

@ -36,10 +36,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
image.Kodachrome(bounds)
.DebugSave(provider, null, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs

@ -38,10 +38,7 @@ namespace ImageSharp.Tests
image.Lomograph(bounds)
.DebugSave(provider, null, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs

@ -36,10 +36,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
image.Polaroid(bounds)
.DebugSave(provider, null, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs

@ -43,10 +43,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
image.Saturation(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs

@ -36,10 +36,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
image.Sepia(bounds)
.DebugSave(provider, null, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs

@ -43,10 +43,7 @@ namespace ImageSharp.Tests.Processing.Convolution
image.BoxBlur(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs

@ -52,10 +52,7 @@ namespace ImageSharp.Tests.Processing.Convolution
image.DetectEdges(detector, bounds)
.DebugSave(provider, detector.ToString(), Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs

@ -43,10 +43,7 @@ namespace ImageSharp.Tests.Processing.Convolution
image.GaussianBlur(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs

@ -43,10 +43,7 @@ namespace ImageSharp.Tests.Processing.Convolution
image.GaussianSharpen(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs

@ -43,10 +43,7 @@ namespace ImageSharp.Tests.Processing.Effects
image.Alpha(value, bounds)
.DebugSave(provider, value, Extensions.Png);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs

@ -36,10 +36,7 @@ namespace ImageSharp.Tests.Processing.Effects
image.BackgroundColor(NamedColors<TPixel>.HotPink, bounds)
.DebugSave(provider, null, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs

@ -43,10 +43,7 @@ namespace ImageSharp.Tests.Processing.Effects
image.Brightness(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); ;
}
}
}

5
tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs

@ -43,10 +43,7 @@ namespace ImageSharp.Tests.Processing.Effects
image.Contrast(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs

@ -36,10 +36,7 @@ namespace ImageSharp.Tests.Processing.Effects
image.Invert(bounds)
.DebugSave(provider, null, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

7
tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs

@ -43,12 +43,7 @@ namespace ImageSharp.Tests
image.OilPaint(levels, brushSize, bounds)
.DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
// TODO: Why does the png box fail without the additional parameter.
ImageComparer.CheckSimilarity(source, image, 0.001F);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F);
}
}
}

2
tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs

@ -76,6 +76,8 @@ namespace ImageSharp.Tests.Processing.Effects
Assert.Equal(sourceColor, image[tx, ty]);
}
}
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs

@ -60,10 +60,7 @@ namespace ImageSharp.Tests.Processing.Overlays
image.Glow(bounds)
.DebugSave(provider, null, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

5
tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs

@ -60,10 +60,7 @@ namespace ImageSharp.Tests.Processing.Overlays
image.Vignette(bounds)
.DebugSave(provider, null, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

Loading…
Cancel
Save