From 7a9e276a80c408126907886cd2ac48fa75f7e070 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 15 Aug 2017 04:47:03 +0200 Subject: [PATCH] optimized ResizeTests output further, added Bike.png --- .../ImageSharp.Sandbox46.csproj | 2 +- .../ImageSharp.Tests/ImageSharp.Tests.csproj | 4 +- .../Processors/Convolution/DetectEdgesTest.cs | 9 +-- .../Processors/Transforms/ResizeTests.cs | 68 ++++++++++--------- tests/ImageSharp.Tests/TestImages.cs | 2 + .../TestUtilities/ImagingTestCaseUtility.cs | 25 +++++-- .../TestUtilities/TestImageExtensions.cs | 16 ++++- .../Tests/IntegrationTestUtilsTests.cs | 4 +- tests/Images/Input/Png/Bike.png | 3 + .../Input/Png/CalliphoraPartialGrayscale.png | 3 + 10 files changed, 86 insertions(+), 50 deletions(-) create mode 100644 tests/Images/Input/Png/Bike.png create mode 100644 tests/Images/Input/Png/CalliphoraPartialGrayscale.png diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj index b9124afc6a..4047d552aa 100644 --- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj +++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj @@ -18,7 +18,7 @@ - + diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index aded62b8f2..491b245bc4 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index 11c77d7113..18342ee810 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -12,8 +12,9 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution public class DetectEdgesTest : FileTestBase { - public static readonly TheoryData DetectEdgesFilters - = new TheoryData + public static readonly string[] CommonTestImages = { TestImages.Png.Bike }; + + public static readonly TheoryData DetectEdgesFilters = new TheoryData { EdgeDetection.Kayyali, EdgeDetection.Kirsch, @@ -29,7 +30,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution [Theory] [WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)] - public void ImageShouldApplyDetectEdgesFilter(TestImageProvider provider, EdgeDetection detector) + public void DetectEdges(TestImageProvider provider, EdgeDetection detector) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -41,7 +42,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution [Theory] [WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)] - public void ImageShouldApplyDetectEdgesFilterInBox(TestImageProvider provider, EdgeDetection detector) + public void DetectEdgesInBox(TestImageProvider provider, EdgeDetection detector) where TPixel : struct, IPixel { using (Image source = provider.GetImage()) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index 79e3521bcd..45209c3c82 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -12,7 +12,9 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms public class ResizeTests : FileTestBase { - public static readonly string[] ResizeFiles = { TestImages.Png.CalliphoraPartial }; + public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial }; + + public static readonly string[] GrayscaleTestImages = { TestImages.Png.CalliphoraPartialGrayscale }; public static readonly TheoryData AllReSamplers = new TheoryData @@ -31,7 +33,7 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms { "RobidouxSharp", new RobidouxSharpResampler() }, { "Welch", new WelchResampler() } }; - + [Theory] [WithFile(TestImages.Gif.Giphy, DefaultPixelType)] public void ResizeShouldApplyToAllFrames(TestImageProvider provider) @@ -46,8 +48,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms [Theory] [WithTestPatternImages(nameof(AllReSamplers), 100, 100, DefaultPixelType, 0.5f)] - [WithFileCollection(nameof(ResizeFiles), nameof(AllReSamplers), DefaultPixelType, 0.5f)] - [WithFileCollection(nameof(ResizeFiles), nameof(AllReSamplers), DefaultPixelType, 0.3f)] + [WithFileCollection(nameof(CommonTestImages), nameof(AllReSamplers), DefaultPixelType, 0.5f)] + [WithFileCollection(nameof(CommonTestImages), nameof(AllReSamplers), DefaultPixelType, 0.3f)] public void ResizeFullImage(TestImageProvider provider, string name, IResampler sampler, float ratio) where TPixel : struct, IPixel { @@ -73,8 +75,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeFromSourceRectangle(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeFromSourceRectangle(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -83,13 +85,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); image.Mutate(x => x.Resize(image.Width, image.Height, new BicubicResampler(), sourceRectangle, destRectangle, false)); - image.DebugSave(provider); + image.DebugSave(provider, grayscale: true); } } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeWidthAndKeepAspect(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeWidthAndKeepAspect(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -100,20 +102,20 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeHeightAndKeepAspect(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeHeightAndKeepAspect(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) { image.Mutate(x => x.Resize(0, image.Height / 3, false)); - image.DebugSave(provider); + image.DebugSave(provider, grayscale: true); } } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeWithCropWidthMode(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeWithCropWidthMode(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -124,13 +126,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms }; image.Mutate(x => x.Resize(options)); - image.DebugSave(provider); + image.DebugSave(provider, grayscale: true); } } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeWithCropHeightMode(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeWithCropHeightMode(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -141,13 +143,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms }; image.Mutate(x => x.Resize(options)); - image.DebugSave(provider); + image.DebugSave(provider, grayscale: true); } } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeWithPadMode(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeWithPadMode(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -159,13 +161,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms }; image.Mutate(x => x.Resize(options)); - image.DebugSave(provider); + image.DebugSave(provider, grayscale: true); } } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeWithBoxPadMode(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeWithBoxPadMode(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -177,13 +179,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms }; image.Mutate(x => x.Resize(options)); - image.DebugSave(provider); + image.DebugSave(provider, grayscale: true); } } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeWithMaxMode(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeWithMaxMode(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -195,13 +197,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms }; image.Mutate(x => x.Resize(options)); - image.DebugSave(provider); + image.DebugSave(provider, grayscale: true); } } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeWithMinMode(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeWithMinMode(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -213,13 +215,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms }; image.Mutate(x => x.Resize(options)); - image.DebugSave(provider); + image.DebugSave(provider, grayscale: true); } } [Theory] - [WithFileCollection(nameof(ResizeFiles), DefaultPixelType)] - public void ImageShouldResizeWithStretchMode(TestImageProvider provider) + [WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)] + public void ResizeWithStretchMode(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -231,7 +233,7 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms }; image.Mutate(x => x.Resize(options)); - image.DebugSave(provider); + image.DebugSave(provider, grayscale: true); } } diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 606b9f9d54..33a1f41541 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -27,6 +27,8 @@ namespace ImageSharp.Tests public const string Interlaced = "Png/interlaced.png"; public const string Rgb48Bpp = "Png/rgb-48bpp.png"; public const string CalliphoraPartial = "Png/CalliphoraPartial.png"; + public const string CalliphoraPartialGrayscale = "Png/CalliphoraPartialGrayscale.png"; + public const string Bike = "Png/Bike.png"; public const string Rgb48BppInterlaced = "Png/rgb-48bpp-interlaced.png"; // Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index 43e6ca2559..a009b4f4c5 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -131,12 +131,13 @@ namespace ImageSharp.Tests Image image, string extension = null, IImageEncoder encoder = null, - object settings = null) + object testOutputDetails = null, + bool grayscale = false) where TPixel : struct, IPixel { - string path = this.GetTestOutputFileName(extension: extension, settings: settings); + string path = this.GetTestOutputFileName(extension: extension, settings: testOutputDetails); string extension1 = Path.GetExtension(path); - encoder = encoder ?? GetImageFormatByExtension(extension1); + encoder = encoder ?? GetImageFormatByExtension(extension1, grayscale); using (FileStream stream = File.OpenWrite(path)) { @@ -158,11 +159,25 @@ namespace ImageSharp.Tests this.Init(method.DeclaringType.Name, method.Name); } - private static IImageEncoder GetImageFormatByExtension(string extension) + private static IImageEncoder GetImageFormatByExtension(string extension, bool grayscale) { extension = extension?.TrimStart('.'); var format = Configuration.Default.FindFormatByFileExtensions(extension); - return Configuration.Default.FindEncoder(format); + IImageEncoder encoder = Configuration.Default.FindEncoder(format); + PngEncoder pngEncoder = encoder as PngEncoder; + if (pngEncoder != null) + { + pngEncoder = new PngEncoder(); + encoder = pngEncoder; + pngEncoder.CompressionLevel = 9; + + if (grayscale) + { + pngEncoder.PngColorType = PngColorType.Grayscale; + } + } + + return encoder; } private string GetTestOutputDir() diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 7a40caad1e..35a84b86b6 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -28,7 +28,8 @@ namespace ImageSharp.Tests this Image image, ITestImageProvider provider, object settings = null, - string extension = "png") + string extension = "png", + bool grayscale = false) where TPixel : struct, IPixel { if (TestEnvironment.RunsOnCI) @@ -38,7 +39,11 @@ namespace ImageSharp.Tests // We are running locally then we want to save it out - provider.Utility.SaveTestOutputFile(image, extension, settings: settings); + provider.Utility.SaveTestOutputFile( + image, + extension, + testOutputDetails: settings, + grayscale: grayscale); return image; } @@ -47,6 +52,7 @@ namespace ImageSharp.Tests ITestImageProvider provider, object settings = null, string extension = "png", + bool monochrome1Bpp = false, float imageTheshold = ImageComparer.DefaultImageThreshold, byte segmentThreshold = ImageComparer.DefaultSegmentThreshold, int scalingFactor = ImageComparer.DefaultScalingFactor) @@ -56,7 +62,11 @@ namespace ImageSharp.Tests if (!TestEnvironment.RunsOnCI) { - provider.Utility.SaveTestOutputFile(image, extension, settings: settings); + provider.Utility.SaveTestOutputFile( + image, + extension, + testOutputDetails: settings, + grayscale: monochrome1Bpp); } if (!File.Exists(referenceOutputFile)) diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/IntegrationTestUtilsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/IntegrationTestUtilsTests.cs index bf4631f3d3..51b5f49b61 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/IntegrationTestUtilsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/IntegrationTestUtilsTests.cs @@ -6,11 +6,11 @@ namespace ImageSharp.Tests using Xunit; using Xunit.Abstractions; - public class IntegrationTestUtilsTests + public class ReferenceCodecTests { private ITestOutputHelper Output { get; } - public IntegrationTestUtilsTests(ITestOutputHelper output) + public ReferenceCodecTests(ITestOutputHelper output) { this.Output = output; } diff --git a/tests/Images/Input/Png/Bike.png b/tests/Images/Input/Png/Bike.png new file mode 100644 index 0000000000..743c10a015 --- /dev/null +++ b/tests/Images/Input/Png/Bike.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e23edfeed35f1d5e29ab6429223c788ba8f7da8aba30f1ffd02d6c4b2f3f428 +size 344266 diff --git a/tests/Images/Input/Png/CalliphoraPartialGrayscale.png b/tests/Images/Input/Png/CalliphoraPartialGrayscale.png new file mode 100644 index 0000000000..9a42449c51 --- /dev/null +++ b/tests/Images/Input/Png/CalliphoraPartialGrayscale.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52ad4d68de5759444b46d9ba2dc9f023f09409cc31d839ceb069e2082b8debe0 +size 98190