Browse Source

Improve method name

Added comments too
af/merge-core
Scott Williams 9 years ago
parent
commit
e6d129646b
  1. 6
      tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
  2. 2
      tests/ImageSharp.Tests/ImageComparer.cs
  3. 39
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

6
tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs

@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Formats.Png
using (Image img2 = new Image(ms, new Configuration(new PngFormat())))
{
// img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder());
ImageComparer.VisualComparer(image, img2);
ImageComparer.CheckSimilarity(image, img2);
}
}
}
@ -53,7 +53,7 @@ namespace ImageSharp.Tests.Formats.Png
using (Image img2 = new Image(ms, new Configuration(new PngFormat())))
{
// img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder());
ImageComparer.VisualComparer(image, img2);
ImageComparer.CheckSimilarity(image, img2);
}
}
}
@ -75,7 +75,7 @@ namespace ImageSharp.Tests.Formats.Png
ms.Position = 0;
using (Image img2 = new Image(ms, new Configuration(new PngFormat())))
{
ImageComparer.VisualComparer(image, img2);
ImageComparer.CheckSimilarity(image, img2);
}
}
}

2
tests/ImageSharp.Tests/ImageComparer.cs

@ -32,7 +32,7 @@
/// 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>
public static void VisualComparer<TColorA, TColorB>(Image<TColorA> expected, Image<TColorB> actual, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor)
public static void CheckSimilarity<TColorA, TColorB>(Image<TColorA> expected, Image<TColorB> actual, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor)
where TColorA : struct, IPixel<TColorA>
where TColorB : struct, IPixel<TColorB>
{

39
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

@ -12,6 +12,11 @@ namespace ImageSharp.Tests
public abstract partial class TestImageProvider<TColor>
where TColor : struct, IPixel<TColor>
{
/// <summary>
/// A test image provider that produces test patterns.
/// </summary>
/// <typeparam name="TColor"></typeparam>
private class TestPatternProvider : TestImageProvider<TColor>
{
static Dictionary<string, Image<TColor>> testImages = new Dictionary<string, Image<TColor>>();
@ -43,19 +48,26 @@ namespace ImageSharp.Tests
}
}
/// <summary>
/// Draws the test pattern on an image by drawing 4 other patterns in the for quadrants of the image.
/// </summary>
/// <param name="image"></param>
private static void DrawTestPattern(Image<TColor> image)
{
// first lets split the image into 4 quadrants
using (PixelAccessor<TColor> pixels = image.Lock())
{
BlackWhiteChecker(pixels); // top left
HorizontalLines(pixels); // top right
VirticalBars(pixels); // top right
TransparentGradients(pixels); // bottom left
Raninbow(pixels); // bottom right
Rainbow(pixels); // bottom right
}
}
private static void HorizontalLines(PixelAccessor<TColor> pixels)
/// <summary>
/// Fills the top right quadrant with alternating solid vertical bars.
/// </summary>
/// <param name="pixels"></param>
private static void VirticalBars(PixelAccessor<TColor> pixels)
{
// topLeft
int left = pixels.Width / 2;
@ -82,6 +94,10 @@ namespace ImageSharp.Tests
}
}
/// <summary>
/// fills the top left quadrant with a black and white checker board.
/// </summary>
/// <param name="pixels"></param>
private static void BlackWhiteChecker(PixelAccessor<TColor> pixels)
{
// topLeft
@ -116,7 +132,11 @@ namespace ImageSharp.Tests
p = pstart;
}
}
/// <summary>
/// Fills the bottom left quadrent with 3 horizental bars in Red, Green and Blue with a alpha gradient from left (transparent) to right (solid).
/// </summary>
/// <param name="pixels"></param>
private static void TransparentGradients(PixelAccessor<TColor> pixels)
{
// topLeft
@ -155,9 +175,14 @@ namespace ImageSharp.Tests
pixels[x, y] = c;
}
}
}
private static void Raninbow(PixelAccessor<TColor> pixels)
/// <summary>
/// Fills the bottom right quadrant with all the colors producable by converting itterating over a uint and unpacking it.
/// A better algorithm could be used but it works
/// </summary>
/// <param name="pixels"></param>
private static void Rainbow(PixelAccessor<TColor> pixels)
{
int left = pixels.Width / 2;
int right = pixels.Width;

Loading…
Cancel
Save