From 84852a879681034fe7d3dcdba76e9cd7dba52ca7 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 18 Aug 2017 16:45:10 +0200 Subject: [PATCH 1/4] good by GenericFactory! --- .../Formats/Jpg/JpegDecoderTests.cs | 4 +-- .../Formats/Jpg/JpegUtilsTests.cs | 12 +++---- .../Image/PixelAccessorTests.cs | 8 ++--- .../ImageSharp.Tests/ImageSharp.Tests.csproj | 3 ++ .../Attributes/WithMemberFactoryAttribute.cs | 3 +- .../TestUtilities/Factories/GenericFactory.cs | 36 ------------------- .../TestUtilities/Factories/ImageFactory.cs | 24 ------------- .../ImageComparison/ImageSimilarityReport.cs | 2 +- .../ImageProviders/BlankProvider.cs | 2 +- .../ImageProviders/LambdaProvider.cs | 8 ++--- .../ImageProviders/TestImageProvider.cs | 12 ++----- .../Tests/TestImageProviderTests.cs | 4 +-- .../Tests/TestUtilityExtensionsTests.cs | 8 ++--- 13 files changed, 31 insertions(+), 95 deletions(-) delete mode 100644 tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs delete mode 100644 tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 141105c487..682b457c88 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -76,8 +76,8 @@ namespace ImageSharp.Tests image.Save(ms, encoder); } } - - Image mirror = provider.Factory.CreateImage(data); + + Image mirror = Image.Load(data); mirror.DebugSave(provider, $"_{subsample}_Q{quality}"); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs index f681e1d8f9..1075c46921 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs @@ -16,19 +16,19 @@ namespace ImageSharp.Tests public class JpegUtilsTests : TestBase { - public static Image CreateTestImage(GenericFactory factory) + public static Image CreateTestImage() where TPixel : struct, IPixel { - Image image = factory.CreateImage(10, 10); + var image = new Image(10, 10); using (PixelAccessor pixels = image.Lock()) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { - Vector4 v = new Vector4(i / 10f, j / 10f, 0, 1); + var v = new Vector4(i / 10f, j / 10f, 0, 1); - TPixel color = default(TPixel); + var color = default(TPixel); color.PackFromVector4(v); pixels[i, j] = color; @@ -45,7 +45,7 @@ namespace ImageSharp.Tests where TPixel : struct, IPixel { using (Image src = provider.GetImage()) - using (Image dest = provider.Factory.CreateImage(8, 8)) + using (Image dest = new Image(8,8)) using (PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz)) using (PixelAccessor s = src.Lock()) using (PixelAccessor d = dest.Lock()) @@ -68,7 +68,7 @@ namespace ImageSharp.Tests { using (Image src = provider.GetImage()) using (PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz)) - using (Image dest = provider.Factory.CreateImage(8, 8)) + using (Image dest = new Image(8, 8)) using (PixelAccessor s = src.Lock()) using (PixelAccessor d = dest.Lock()) { diff --git a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs index 98f316f439..37333576b5 100644 --- a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs +++ b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs @@ -17,20 +17,20 @@ namespace ImageSharp.Tests /// public class PixelAccessorTests { - public static Image CreateTestImage(GenericFactory factory) + public static Image CreateTestImage() where TPixel : struct, IPixel { - Image image = factory.CreateImage(10, 10); + var image = new Image(10, 10); using (PixelAccessor pixels = image.Lock()) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { - Vector4 v = new Vector4(i, j, 0, 1); + var v = new Vector4(i, j, 0, 1); v /= 10; - TPixel color = default(TPixel); + var color = default(TPixel); color.PackFromVector4(v); pixels[i, j] = color; diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 491b245bc4..03805ae32a 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -28,4 +28,7 @@ PreserveNewest + + + \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs index 6c6198c38d..53faff640a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs @@ -39,9 +39,8 @@ namespace ImageSharp.Tests Type colorType = args.Single(); Type imgType = typeof(Image<>).MakeGenericType(colorType); - Type genericFactoryType = (typeof(GenericFactory<>)).MakeGenericType(colorType); - Type funcType = typeof(Func<,>).MakeGenericType(genericFactoryType, imgType); + Type funcType = typeof(Func<>).MakeGenericType(imgType); MethodInfo genericMethod = m.MakeGenericMethod(args); diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs deleted file mode 100644 index efe548ee88..0000000000 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs +++ /dev/null @@ -1,36 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests -{ - using System; - - using ImageSharp.PixelFormats; - - /// - /// TODO: Non-generic 'Image' class has been removed. We no longer need the factory pattern here! - /// - /// Utility class to create specialized subclasses of generic classes (eg. ) - /// Used as parameter for -based factory methods - /// - public class GenericFactory - where TPixel : struct, IPixel - { - public virtual Image CreateImage(int width, int height) - { - return new Image(width, height); - } - - public virtual Image CreateImage(byte[] bytes) - { - return Image.Load(bytes); - } - - public virtual Image CreateImage(Image other) - { - return other.Clone(); - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs deleted file mode 100644 index efa08c736f..0000000000 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests -{ - using ImageSharp.PixelFormats; - - /// - /// TODO: Non-generic 'Image' class has been removed. We no longer need the factory pattern here! - /// - public class ImageFactory : GenericFactory - { - public override Image CreateImage(byte[] bytes) => Image.Load(bytes); - - public override Image CreateImage(int width, int height) => new Image(width, height); - - public override Image CreateImage(Image other) - { - return other.Clone(); - } - } -} diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs index 74995537e6..313d7ffb87 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs @@ -42,7 +42,7 @@ var sb = new StringBuilder(); if (this.TotalNormalizedDifference.HasValue) { - sb.AppendLine($"Total difference: {this.TotalNormalizedDifference.Value * 100:0.00}%"); + sb.AppendLine($"Total difference: {this.TotalNormalizedDifference.Value * 100:0.0000}%"); } int max = Math.Min(5, this.Differences.Length); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs index 4252a60b5e..af5e838755 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs @@ -33,7 +33,7 @@ namespace ImageSharp.Tests protected int Width { get; private set; } - public override Image GetImage() => this.Factory.CreateImage(this.Width, this.Height); + public override Image GetImage() => new Image(this.Width, this.Height); public override void Deserialize(IXunitSerializationInfo info) diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs index 30e7a63b50..ee150adc7c 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs @@ -18,14 +18,14 @@ namespace ImageSharp.Tests { private class LambdaProvider : TestImageProvider { - private readonly Func, Image> creator; + private readonly Func> factoryFunc; - public LambdaProvider(Func, Image> creator) + public LambdaProvider(Func> factoryFunc) { - this.creator = creator; + this.factoryFunc = factoryFunc; } - public override Image GetImage() => this.creator(this.Factory); + public override Image GetImage() => this.factoryFunc(); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index 99d1125d72..cc8c453c80 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -33,7 +33,6 @@ namespace ImageSharp.Tests /// public ImagingTestCaseUtility Utility { get; private set; } - public GenericFactory Factory { get; private set; } = new GenericFactory(); public string TypeName { get; private set; } public string MethodName { get; private set; } @@ -60,10 +59,10 @@ namespace ImageSharp.Tests } public static TestImageProvider Lambda( - Func, Image> func, + Func> factoryFunc, MethodInfo testMethod = null, PixelTypes pixelTypeOverride = PixelTypes.Undefined) - => new LambdaProvider(func).Init(testMethod, pixelTypeOverride); + => new LambdaProvider(factoryFunc).Init(testMethod, pixelTypeOverride); public static TestImageProvider Solid( int width, @@ -122,12 +121,7 @@ namespace ImageSharp.Tests } this.TypeName = typeName; this.MethodName = methodName; - - if (pixelTypeOverride == PixelTypes.Rgba32) - { - this.Factory = new ImageFactory() as GenericFactory; - } - + this.Utility = new ImagingTestCaseUtility { SourceFileOrDescription = this.SourceFileOrDescription, diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index e9c4fc3d3d..f10ebeb301 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -165,10 +165,10 @@ namespace ImageSharp.Tests /// /// /// - public static Image CreateTestImage(GenericFactory factory) + public static Image CreateTestImage() where TPixel : struct, IPixel { - return factory.CreateImage(3, 3); + return new Image(3, 3); } [Theory] diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index edee09c909..9a468da678 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -27,10 +27,10 @@ namespace ImageSharp.Tests private ITestOutputHelper Output { get; } - public static Image CreateTestImage(GenericFactory factory) + public static Image CreateTestImage() where TPixel : struct, IPixel { - Image image = factory.CreateImage(10, 10); + var image = new Image(10, 10); using (PixelAccessor pixels = image.Lock()) { @@ -38,10 +38,10 @@ namespace ImageSharp.Tests { for (int j = 0; j < 10; j++) { - Vector4 v = new Vector4(i, j, 0, 1); + var v = new Vector4(i, j, 0, 1); v /= 10; - TPixel color = default(TPixel); + var color = default(TPixel); color.PackFromVector4(v); pixels[i, j] = color; From 1562e32046c0b6dd57e2cddcf5e5a5dbf9d3725f Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 18 Aug 2017 18:09:18 +0200 Subject: [PATCH 2/4] Using Corecompat.System.Drawing as reference encoder/decoder for PNG. (Optimizing PNG-s with external tools from now.) --- src/ImageSharp/Configuration.cs | 2 +- src/ImageSharp/Image/ImageExtensions.cs | 2 +- .../Processors/Convolution/DetectEdgesTest.cs | 6 +- .../ImageProviders/FileProvider.cs | 13 +---- .../TestUtilities/ImagingTestCaseUtility.cs | 42 +++++++------- ...er.cs => SystemDrawingReferenceDecoder.cs} | 4 +- ...er.cs => SystemDrawingReferenceEncoder.cs} | 6 +- .../TestUtilities/TestEnvironment.cs | 58 +++++++++++++++++-- .../TestUtilities/TestImageExtensions.cs | 4 +- ...{TestUtilityExtensions.cs => TestUtils.cs} | 7 ++- .../Tests/ReferenceCodecTests.cs | 4 +- .../Tests/TestEnvironmentTests.cs | 24 ++++++++ .../Tests/TestUtilityExtensionsTests.cs | 2 +- tests/Images/External | 2 +- 14 files changed, 117 insertions(+), 59 deletions(-) rename tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/{ReferenceDecoder.cs => SystemDrawingReferenceDecoder.cs} (90%) rename tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/{ReferenceEncoder.cs => SystemDrawingReferenceEncoder.cs} (72%) rename tests/ImageSharp.Tests/TestUtilities/{TestUtilityExtensions.cs => TestUtils.cs} (97%) diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index f169822858..12ceca0b28 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -140,7 +140,7 @@ namespace ImageSharp /// /// The extension to discover /// The if found otherwise null - public IImageFormat FindFormatByFileExtensions(string extension) + public IImageFormat FindFormatByFileExtension(string extension) { return this.imageFormats.FirstOrDefault(x => x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)); } diff --git a/src/ImageSharp/Image/ImageExtensions.cs b/src/ImageSharp/Image/ImageExtensions.cs index 6095b49e3a..0eb3e2cab8 100644 --- a/src/ImageSharp/Image/ImageExtensions.cs +++ b/src/ImageSharp/Image/ImageExtensions.cs @@ -52,7 +52,7 @@ namespace ImageSharp Guard.NotNullOrEmpty(filePath, nameof(filePath)); string ext = Path.GetExtension(filePath).Trim('.'); - IImageFormat format = source.Configuration.FindFormatByFileExtensions(ext); + IImageFormat format = source.Configuration.FindFormatByFileExtension(ext); if (format == null) { var stringBuilder = new StringBuilder(); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index c753528f38..ee6650e55c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -40,7 +40,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution using (Image image = provider.GetImage()) { image.Mutate(x => x.DetectEdges(detector)); - image.DebugSave(provider, detector.ToString(), grayscale: true); + image.DebugSave(provider, detector.ToString()); } } @@ -52,7 +52,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution using (Image image = provider.GetImage()) { image.Mutate(x => x.DetectEdges()); - image.DebugSave(provider, grayscale: true); + image.DebugSave(provider); } } @@ -79,7 +79,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); image.Mutate(x => x.DetectEdges(bounds)); - image.DebugSave(provider, grayscale: true); + image.DebugSave(provider); // TODO: We don't need this any longer after switching to ReferenceImages ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs index 7ae103cd29..db30bb65d4 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs @@ -45,17 +45,8 @@ namespace ImageSharp.Tests public override Image GetImage() { - Key key = new Key(this.PixelType, this.FilePath); - - Image cachedImage = cache.GetOrAdd( - key, - fn => - { - TestFile testFile = TestFile.Create(this.FilePath); - return Image.Load(testFile.Bytes); - }); - - return cachedImage.Clone(); + IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(this.FilePath); + return this.GetImage(decoder); } public override Image GetImage(IImageDecoder decoder) diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index edb8bafac5..b157042b6e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -138,13 +138,11 @@ namespace ImageSharp.Tests string extension = null, IImageEncoder encoder = null, object testOutputDetails = null, - bool grayscale = false, bool appendPixelTypeToFileName = true) where TPixel : struct, IPixel { string path = this.GetTestOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName); - string extension1 = Path.GetExtension(path); - encoder = encoder ?? GetImageFormatByExtension(extension1, grayscale); + encoder = encoder ?? TestEnvironment.GetReferenceEncoder(path); using (FileStream stream = File.OpenWrite(path)) { @@ -173,26 +171,26 @@ namespace ImageSharp.Tests this.Init(method.DeclaringType.Name, method.Name); } - private static IImageEncoder GetImageFormatByExtension(string extension, bool grayscale) - { - extension = extension?.TrimStart('.'); - var format = Configuration.Default.FindFormatByFileExtensions(extension); - 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; - } - } + //private static IImageEncoder GetEncoderByExtension(string extension, bool grayscale) + //{ + // extension = extension?.TrimStart('.'); + // var format = Configuration.Default.FindFormatByFileExtension(extension); + // 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; - } + // return encoder; + //} private string GetTestOutputDir() { diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ReferenceDecoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs similarity index 90% rename from tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ReferenceDecoder.cs rename to tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs index 3ed3248b26..493866170a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ReferenceDecoder.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceDecoder.cs @@ -8,9 +8,9 @@ namespace ImageSharp.Tests.TestUtilities.ReferenceCodecs using ImageSharp.Formats; using ImageSharp.PixelFormats; - public class ReferenceDecoder : IImageDecoder + public class SystemDrawingReferenceDecoder : IImageDecoder { - public static ReferenceDecoder Instance { get; } = new ReferenceDecoder(); + public static SystemDrawingReferenceDecoder Instance { get; } = new SystemDrawingReferenceDecoder(); public Image Decode(Configuration configuration, Stream stream) where TPixel : struct, IPixel diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ReferenceEncoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs similarity index 72% rename from tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ReferenceEncoder.cs rename to tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs index 9018d66f7f..c1c10c469a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/ReferenceEncoder.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs @@ -9,16 +9,16 @@ namespace ImageSharp.Tests.TestUtilities.ReferenceCodecs using ImageSharp.Formats; using ImageSharp.PixelFormats; - public class ReferenceEncoder : IImageEncoder + public class SystemDrawingReferenceEncoder : IImageEncoder { private readonly System.Drawing.Imaging.ImageFormat imageFormat; - public ReferenceEncoder(ImageFormat imageFormat) + public SystemDrawingReferenceEncoder(ImageFormat imageFormat) { this.imageFormat = imageFormat; } - public static ReferenceEncoder Png { get; } = new ReferenceEncoder(System.Drawing.Imaging.ImageFormat.Png); + public static SystemDrawingReferenceEncoder Png { get; } = new SystemDrawingReferenceEncoder(System.Drawing.Imaging.ImageFormat.Png); public void Encode(Image image, Stream stream) where TPixel : struct, IPixel diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index 728cf45696..7cfc5c6e40 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -1,12 +1,13 @@ namespace ImageSharp.Tests { using System; - using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; - using System.Security; + using ImageSharp.Formats; + using ImageSharp.Tests.TestUtilities.ReferenceCodecs; + public static class TestEnvironment { private const string ImageSharpSolutionFileName = "ImageSharp.sln"; @@ -26,6 +27,8 @@ namespace ImageSharp.Tests return bool.TryParse(Environment.GetEnvironmentVariable("CI"), out isCi) && isCi; }); + private static Lazy configuration = new Lazy(CreateDefaultConfiguration); + // ReSharper disable once InconsistentNaming /// /// Gets a value indicating whether test execution runs on CI. @@ -34,6 +37,24 @@ namespace ImageSharp.Tests internal static string SolutionDirectoryFullPath => solutionDirectoryFullPath.Value; + internal static Configuration Configuration => configuration.Value; + + private static Configuration CreateDefaultConfiguration() + { + var configuration = new Configuration( + new PngConfigurationModule(), + new JpegConfigurationModule(), + new GifConfigurationModule(), + new BmpConfigurationModule() + ); + + configuration.SetDecoder(ImageFormats.Png, SystemDrawingReferenceDecoder.Instance); + configuration.SetEncoder(ImageFormats.Png, SystemDrawingReferenceEncoder.Png); + configuration.AddImageFormatDetector(new PngImageFormatDetector()); + + return configuration; + } + private static string GetSolutionDirectoryFullPathImpl() { string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location; @@ -62,23 +83,48 @@ namespace ImageSharp.Tests return directory.FullName; } - + /// /// Gets the correct full path to the Input Images directory. /// - internal static string InputImagesDirectoryFullPath => Path.Combine(SolutionDirectoryFullPath, InputImagesRelativePath); + internal static string InputImagesDirectoryFullPath => + Path.Combine(SolutionDirectoryFullPath, InputImagesRelativePath); /// /// Gets the correct full path to the Actual Output directory. (To be written to by the test cases.) /// - internal static string ActualOutputDirectoryFullPath => Path.Combine(SolutionDirectoryFullPath, ActualOutputDirectoryRelativePath); + internal static string ActualOutputDirectoryFullPath => Path.Combine( + SolutionDirectoryFullPath, + ActualOutputDirectoryRelativePath); /// /// Gets the correct full path to the Expected Output directory. (To compare the test results to.) /// - internal static string ReferenceOutputDirectoryFullPath => Path.Combine(SolutionDirectoryFullPath, ReferenceOutputDirectoryRelativePath); + internal static string ReferenceOutputDirectoryFullPath => Path.Combine( + SolutionDirectoryFullPath, + ReferenceOutputDirectoryRelativePath); internal static string GetReferenceOutputFileName(string actualOutputFileName) => actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput"); + + internal static IImageDecoder GetReferenceDecoder(string filePath) + { + IImageFormat format = GetImageFormat(filePath); + return Configuration.FindDecoder(format); + } + + internal static IImageEncoder GetReferenceEncoder(string filePath) + { + IImageFormat format = GetImageFormat(filePath); + return Configuration.FindEncoder(format); + } + + private static IImageFormat GetImageFormat(string filePath) + { + string extension = Path.GetExtension(filePath).ToLower(); + if (extension[0] == '.') extension = extension.Substring(1); + IImageFormat format = Configuration.FindFormatByFileExtension(extension); + return format; + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 35a7d17d40..e4563df4fd 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -29,7 +29,6 @@ namespace ImageSharp.Tests ITestImageProvider provider, object testOutputDetails = null, string extension = "png", - bool grayscale = false, bool appendPixelTypeToFileName = true) where TPixel : struct, IPixel { @@ -43,7 +42,6 @@ namespace ImageSharp.Tests image, extension, testOutputDetails: testOutputDetails, - grayscale: grayscale, appendPixelTypeToFileName: appendPixelTypeToFileName); return image; } @@ -139,7 +137,7 @@ namespace ImageSharp.Tests var testFile = TestFile.Create(path); - using (var original = Image.Load(testFile.Bytes, ReferenceDecoder.Instance)) + using (var original = Image.Load(testFile.Bytes, SystemDrawingReferenceDecoder.Instance)) { //original.DebugSave(provider, "__SYSTEMDRAWING__"); comparer.VerifySimilarity(original, image); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs similarity index 97% rename from tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs rename to tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index 835561fe0f..21ef03fa6f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -11,12 +11,13 @@ namespace ImageSharp.Tests using System.Linq; using System.Reflection; + using ImageSharp.Formats; using ImageSharp.PixelFormats; /// - /// Extension methods for TestUtilities + /// Various utility and extension methods. /// - public static class TestUtilityExtensions + public static class TestUtils { private static readonly Dictionary ClrTypes2PixelTypes = new Dictionary(); @@ -28,7 +29,7 @@ namespace ImageSharp.Tests .Except(new[] { PixelTypes.Undefined, PixelTypes.All }) .ToArray(); - static TestUtilityExtensions() + static TestUtils() { // Add Rgba32 Our default. Type defaultPixelFormatType = typeof(Rgba32); diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs index 51b5f49b61..6e3afbcae2 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ReferenceCodecTests.cs @@ -52,7 +52,7 @@ namespace ImageSharp.Tests where TPixel : struct, IPixel { string path = TestFile.GetInputFileFullPath(TestImages.Png.Splash); - using (Image image = Image.Load(path, ReferenceDecoder.Instance)) + using (Image image = Image.Load(path, SystemDrawingReferenceDecoder.Instance)) { image.DebugSave(dummyProvider); } @@ -65,7 +65,7 @@ namespace ImageSharp.Tests { using (Image image = provider.GetImage()) { - provider.Utility.SaveTestOutputFile(image, "png", ReferenceEncoder.Png); + provider.Utility.SaveTestOutputFile(image, "png", SystemDrawingReferenceEncoder.Png); } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs index ac537b3c39..10e08b5de0 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs @@ -6,8 +6,12 @@ // ReSharper disable InconsistentNaming namespace ImageSharp.Tests { + using System; using System.IO; + using ImageSharp.Formats; + using ImageSharp.Tests.TestUtilities.ReferenceCodecs; + using Xunit; using Xunit.Abstractions; @@ -59,5 +63,25 @@ namespace ImageSharp.Tests this.Output.WriteLine(expected); Assert.Contains(TestEnvironment.ReferenceOutputDirectoryFullPath, expected); } + + [Theory] + [InlineData("lol/foo.png", typeof(SystemDrawingReferenceEncoder))] + [InlineData("lol/Baz.JPG", typeof(JpegEncoder))] + [InlineData("lol/Baz.gif", typeof(GifEncoder))] + public void GetReferenceEncoder_ReturnsCorrectEncoders(string fileName, Type expectedEncoderType) + { + IImageEncoder encoder = TestEnvironment.GetReferenceEncoder(fileName); + Assert.IsType(expectedEncoderType, encoder); + } + + [Theory] + [InlineData("lol/foo.png", typeof(SystemDrawingReferenceDecoder))] + [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] + [InlineData("lol/Baz.gif", typeof(GifDecoder))] + public void GetReferenceDecoder_ReturnsCorrectEncoders(string fileName, Type expectedDecoderType) + { + IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(fileName); + Assert.IsType(expectedDecoderType, decoder); + } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 9a468da678..8651d246bc 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -147,7 +147,7 @@ namespace ImageSharp.Tests { KeyValuePair[] expanded = PixelTypes.All.ExpandAllTypes().ToArray(); - Assert.True(expanded.Length >= TestUtilityExtensions.GetAllPixelTypes().Length - 2); + Assert.True(expanded.Length >= TestUtils.GetAllPixelTypes().Length - 2); AssertContainsPixelType(PixelTypes.Rgba32, expanded); AssertContainsPixelType(PixelTypes.Rgba32, expanded); } diff --git a/tests/Images/External b/tests/Images/External index 6996009ff5..4929cbe0d7 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 6996009ff537d1c9cbc2b93d692cd89bf8f2a5c7 +Subproject commit 4929cbe0d743fe3c67a9b4d0c71fb3eed8b5537d From 02eb5f2f135ed2568a03bdfa9f847b65e2f00e00 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 18 Aug 2017 18:37:16 +0200 Subject: [PATCH 3/4] PngDecoder is covered now, and proven to be buggy :P --- .../Formats/Png/PngDecoderTests.cs | 12 ++++++++---- tests/ImageSharp.Tests/TestImages.cs | 1 + .../ImageComparison/ImageComparer.cs | 2 +- .../ImageComparison/TolerantImageComparer.cs | 4 ++-- .../TestUtilities/TestEnvironment.cs | 2 +- .../TestUtilities/TestImageExtensions.cs | 14 ++++++++++++-- tests/Images/Input/Png/SnakeGame.png | Bin 0 -> 6958 bytes 7 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 tests/Images/Input/Png/SnakeGame.png diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index 5f4055a936..1d40163d10 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -12,6 +12,8 @@ using Xunit; namespace ImageSharp.Tests { + using ImageSharp.Tests.TestUtilities.ImageComparison; + public class PngDecoderTests { private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; @@ -19,17 +21,19 @@ namespace ImageSharp.Tests public static readonly string[] TestFiles = { TestImages.Png.Splash, TestImages.Png.Indexed, TestImages.Png.Interlaced, TestImages.Png.FilterVar, - TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength2, TestImages.Png.Rgb48Bpp, TestImages.Png.Rgb48BppInterlaced + TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength2, TestImages.Png.Rgb48Bpp, + TestImages.Png.Rgb48BppInterlaced, TestImages.Png.SnakeGame }; [Theory] [WithFileCollection(nameof(TestFiles), PixelTypes)] - public void Decode(TestImageProvider imageProvider) + public void Decode(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = imageProvider.GetImage()) + using (Image image = provider.GetImage(new PngDecoder())) { - image.DebugSave(imageProvider); + image.DebugSave(provider); + image.CompareToOriginal(provider, ImageComparer.Exact); } } diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 527b78ae6b..66ca93bd23 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -31,6 +31,7 @@ namespace ImageSharp.Tests public const string Bike = "Png/Bike.png"; public const string BikeGrayscale = "Png/BikeGrayscale.png"; public const string Rgb48BppInterlaced = "Png/rgb-48bpp-interlaced.png"; + public const string SnakeGame = "Png/SnakeGame.png"; // Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html public const string Filter0 = "Png/filter0.png"; diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs index b13905ef57..80102e6010 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs @@ -10,7 +10,7 @@ namespace ImageSharp.Tests.TestUtilities.ImageComparison public abstract class ImageComparer { - public static ImageComparer Exact { get; } = ExactImageComparer.Instance; + public static ImageComparer Exact { get; } = Tolerant(0, 0); public static ImageComparer Tolerant( float imageThreshold = TolerantImageComparer.DefaultImageThreshold, diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index 23e5761806..0351b00200 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -66,7 +66,7 @@ for (int x = 0; x < width; x++) { - int d = GetDifferenceInPixelByteSum(ref aBuffer[x], ref bBuffer[x]); + int d = GetHammingDistanceInRgbaSpace(ref aBuffer[x], ref bBuffer[x]); if (d > this.PixelThresholdInPixelByteSum) { @@ -92,7 +92,7 @@ } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static int GetDifferenceInPixelByteSum(ref Rgba32 a, ref Rgba32 b) + private static int GetHammingDistanceInRgbaSpace(ref Rgba32 a, ref Rgba32 b) { return Diff(a.R, b.R) + Diff(a.G, b.G) + Diff(a.B, b.B) + Diff(a.A, b.A); } diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index 7cfc5c6e40..9b2f7c479e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -119,7 +119,7 @@ namespace ImageSharp.Tests return Configuration.FindEncoder(format); } - private static IImageFormat GetImageFormat(string filePath) + internal static IImageFormat GetImageFormat(string filePath) { string extension = Path.GetExtension(filePath).ToLower(); if (extension[0] == '.') extension = extension.Substring(1); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index e4563df4fd..17d75ff3f2 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -7,7 +7,9 @@ namespace ImageSharp.Tests { using System; using System.IO; + using System.Linq; + using ImageSharp.Formats; using ImageSharp.PixelFormats; using ImageSharp.Tests.TestUtilities.ImageComparison; using ImageSharp.Tests.TestUtilities.ReferenceCodecs; @@ -137,9 +139,17 @@ namespace ImageSharp.Tests var testFile = TestFile.Create(path); - using (var original = Image.Load(testFile.Bytes, SystemDrawingReferenceDecoder.Instance)) + IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(path); + IImageFormat format = TestEnvironment.GetImageFormat(path); + IImageDecoder defaultDecoder = Configuration.Default.FindDecoder(format); + + if (referenceDecoder.GetType() == defaultDecoder.GetType()) + { + throw new InvalidOperationException($"Can't use CompareToOriginal(): no actual reference decoder registered for {format.Name}"); + } + + using (var original = Image.Load(testFile.Bytes, referenceDecoder)) { - //original.DebugSave(provider, "__SYSTEMDRAWING__"); comparer.VerifySimilarity(original, image); } diff --git a/tests/Images/Input/Png/SnakeGame.png b/tests/Images/Input/Png/SnakeGame.png new file mode 100644 index 0000000000000000000000000000000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zK zuUZ>#C1bKB1&v3v=*0_ClkUeOp1%IGs-!JDuF5E5^zf>Q8^EpN@a)T<`pbZ1@t)Ey uY}jqJ3 Date: Fri, 18 Aug 2017 18:56:27 +0200 Subject: [PATCH 4/4] covered DetectEdges --- .../Processing/Processors/Convolution/DetectEdgesTest.cs | 8 +++++--- tests/Images/External | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index ee6650e55c..cdb48bdd2f 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -41,6 +41,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution { image.Mutate(x => x.DetectEdges(detector)); image.DebugSave(provider, detector.ToString()); + image.CompareToReferenceOutput(provider, detector.ToString()); } } @@ -53,6 +54,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution { image.Mutate(x => x.DetectEdges()); image.DebugSave(provider); + image.CompareToReferenceOutput(provider); } } @@ -73,16 +75,16 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution public void DetectEdges_InBox(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image source = provider.GetImage()) - using (Image image = source.Clone()) + using (Image image = provider.GetImage()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); image.Mutate(x => x.DetectEdges(bounds)); image.DebugSave(provider); + image.CompareToReferenceOutput(provider); // TODO: We don't need this any longer after switching to ReferenceImages - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + //ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/Images/External b/tests/Images/External index 4929cbe0d7..b466db97b5 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 4929cbe0d743fe3c67a9b4d0c71fb3eed8b5537d +Subproject commit b466db97b501bcd12a7e366ee1d2d6a6e45eb2d0