From 14eaf8b266f0f11579ed4f87506eff1c3adc605a Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 15:42:31 +0200 Subject: [PATCH 01/35] Adds new test of factory for loading an image from a memory stream Former-commit-id: 98343f28edb50392fcad4d871451559a441e3152 --- .../ImageFactoryUnitTests.cs | 33 +++ .../ImageProcessor.UnitTests.csproj | 202 ++++++++++++------ src/ImageProcessor_Mono.sln | 26 ++- 3 files changed, 190 insertions(+), 71 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index a63f95ff2..1fc782073 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -51,5 +51,38 @@ namespace ImageProcessor.UnitTests Assert.IsNotNull(imageFactory.Image); } } + + /// > + /// Tests the loading of image from a memory stream + /// + /// + /// The file Name. + /// + /// + /// The expected mime type. + /// + [Test] + [TestCase("Chrysanthemum.jpg", "image/jpeg")] + [TestCase("Desert.jpg", "image/jpeg")] + [TestCase("cmyk.png", "image/png")] + [TestCase("Penguins.bmp", "image/bmp")] + [TestCase("Penguins.gif", "image/gif")] + public void TestLoadImageFromMemory(string fileName, string expectedMime) + { + string testPhoto = Path.Combine(this.localPath, string.Format("../../Images/{0}", fileName)); + byte[] photoBytes = File.ReadAllBytes(testPhoto); + + // ImageProcessor + using (MemoryStream inStream = new MemoryStream(photoBytes)) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(inStream); + Assert.AreEqual(null, imageFactory.ImagePath); + Assert.AreEqual(expectedMime, imageFactory.CurrentImageFormat.MimeType); + Assert.IsNotNull(imageFactory.Image); + } + } + } } } \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 81516b4b6..d5841e6c2 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -1,98 +1,177 @@  - + Debug AnyCPU - {633B1C4C-4823-47BE-9A01-A665F3118C8C} + {03CA9055-F997-428C-BF28-F50F991777C6} Library - Properties ImageProcessor.UnitTests ImageProcessor.UnitTests - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest + + ..\ true - + v4.5 true full false - bin\Debug\ - DEBUG;TRACE + bin\Debug + DEBUG; prompt 4 + false + false - pdbonly + full true - bin\Release\ - TRACE + bin\Release prompt 4 + false + false + + ..\packages\NUnit.2.6.3\lib\nunit.framework.dll - - + + - - - - - - - - - - - - + + + {D011A778-59C8-4BFA-A770-C350216BF161} + ImageProcessor.Web_NET45 + - {3b5dd734-fb7a-487d-8ce6-55e7af9aea7e} + {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E} ImageProcessor - - - - - - + + + Images\Chrysanthemum.jpg + PreserveNewest + + + Images\Desert.jpg + PreserveNewest + + + Images\Hydrangeas.jpg + PreserveNewest + + + Images\Jellyfish.jpg + PreserveNewest + + + Images\Koala.jpg + PreserveNewest + + + Images\Lighthouse.jpg + PreserveNewest + + + Images\Penguins-200.jpg + PreserveNewest + + + Images\Penguins-8.png + PreserveNewest + + + Images\Penguins.bmp + PreserveNewest + + + Images\Penguins.gif + PreserveNewest + + + Images\Penguins.jpg + PreserveNewest + + + Images\Penguins.png + PreserveNewest + + + Images\Penguins.tif + PreserveNewest + + + Images\Tulips.jpg + PreserveNewest + + + Images\bus.jpg + PreserveNewest + + + Images\cmyk.jpg + PreserveNewest + + + Images\cmyk.png + PreserveNewest + + + Images\jrt.jpg + PreserveNewest + + + Images\meter.gif + PreserveNewest + + + Images\rocks.jpg + PreserveNewest + + + Images\rotate.jpg + PreserveNewest + + + Images\sample1.jpg + PreserveNewest + + + Images\srgb.jpg + PreserveNewest + + + Images\srgb.png + PreserveNewest + + + Images\text.png + PreserveNewest + + + Images\thor.jpg + PreserveNewest + + + Images\udendørs-374.jpg + PreserveNewest + + + Images\udendørs.jpg + PreserveNewest + - - - - - False - - - False - - - False - - - False - - - - - - + @@ -100,11 +179,4 @@ - \ No newline at end of file diff --git a/src/ImageProcessor_Mono.sln b/src/ImageProcessor_Mono.sln index 7d47a2ca6..8b1e0fb37 100644 --- a/src/ImageProcessor_Mono.sln +++ b/src/ImageProcessor_Mono.sln @@ -3,12 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 VisualStudioVersion = 12.0.30110.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C427A497-74DC-49B1-8420-D6E68354F29B}" - ProjectSection(SolutionItems) = preProject - ImageProcessor.vsmdi = ImageProcessor.vsmdi - Local.testsettings = Local.testsettings - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{1E656CDE-124D-4FAF-837C-0EF1E192D418}" ProjectSection(SolutionItems) = preProject .nuget\NuGet.Config = .nuget\NuGet.Config @@ -24,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.Web_NET45", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessorConsole", "ImageProcessorConsole\ImageProcessorConsole.csproj", "{7BF5274B-56A7-4B62-8105-E9BDF25BAFE7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.UnitTests", "ImageProcessor.UnitTests\ImageProcessor.UnitTests.csproj", "{03CA9055-F997-428C-BF28-F50F991777C6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution All|Any CPU = All|Any CPU @@ -37,6 +33,24 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {03CA9055-F997-428C-BF28-F50F991777C6}.All|Any CPU.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|Any CPU.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|Mixed Platforms.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|x86.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|x86.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|x86.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|x86.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|Any CPU.Build.0 = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|x86.ActiveCfg = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|x86.Build.0 = Release|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Any CPU.ActiveCfg = All|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Any CPU.Build.0 = All|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Mixed Platforms.ActiveCfg = All|Any CPU From 7c37f5e89a6b624d75a07fc1ec12b485537228cc Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 18:03:26 +0200 Subject: [PATCH 02/35] Loads all the test images + tests a few filters as well (failing for gif images) Former-commit-id: 193b0354b1e8f9e227919084076d6fd1776425d1 --- .../ImageFactoryUnitTests.cs | 106 +++++++++++------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 1fc782073..7cd124b19 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -12,6 +12,7 @@ namespace ImageProcessor.UnitTests { using System; using System.IO; + using System.Collections.Generic; using NUnit.Framework; /// @@ -25,62 +26,89 @@ namespace ImageProcessor.UnitTests /// private readonly string localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); + /// + /// Lists the input files in the Images folder + /// + /// The list of files. + private static IEnumerable ListInputFiles() + { + return Directory.GetFiles("./Images"); + } + /// /// Tests the loading of image from a file /// - /// - /// The file Name. - /// - /// - /// The expected mime type. - /// [Test] - [TestCase("Chrysanthemum.jpg", "image/jpeg")] - [TestCase("Desert.jpg", "image/jpeg")] - [TestCase("cmyk.png", "image/png")] - [TestCase("Penguins.bmp", "image/bmp")] - [TestCase("Penguins.gif", "image/gif")] - public void TestLoadImageFromFile(string fileName, string expectedMime) + public void TestLoadImageFromFile() { - string testPhoto = Path.Combine(this.localPath, string.Format("../../Images/{0}", fileName)); - using (ImageFactory imageFactory = new ImageFactory()) + foreach (var fileName in ListInputFiles()) { - imageFactory.Load(testPhoto); - Assert.AreEqual(testPhoto, imageFactory.ImagePath); - Assert.AreEqual(expectedMime, imageFactory.CurrentImageFormat.MimeType); - Assert.IsNotNull(imageFactory.Image); + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + Assert.AreEqual(fileName, imageFactory.ImagePath); + Assert.IsNotNull(imageFactory.Image); + } } + } /// > /// Tests the loading of image from a memory stream /// - /// - /// The file Name. - /// - /// - /// The expected mime type. - /// [Test] - [TestCase("Chrysanthemum.jpg", "image/jpeg")] - [TestCase("Desert.jpg", "image/jpeg")] - [TestCase("cmyk.png", "image/png")] - [TestCase("Penguins.bmp", "image/bmp")] - [TestCase("Penguins.gif", "image/gif")] - public void TestLoadImageFromMemory(string fileName, string expectedMime) + public void TestLoadImageFromMemory() { - string testPhoto = Path.Combine(this.localPath, string.Format("../../Images/{0}", fileName)); - byte[] photoBytes = File.ReadAllBytes(testPhoto); + foreach (var fileName in ListInputFiles()) + { + byte[] photoBytes = File.ReadAllBytes(fileName); - // ImageProcessor - using (MemoryStream inStream = new MemoryStream(photoBytes)) + using (var inStream = new MemoryStream(photoBytes)) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(inStream); + Assert.AreEqual(null, imageFactory.ImagePath); + Assert.IsNotNull(imageFactory.Image); + } + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void ApplyEffectAlpha() + { + foreach (var fileName in ListInputFiles()) { - using (ImageFactory imageFactory = new ImageFactory()) + using (var imageFactory = new ImageFactory()) { - imageFactory.Load(inStream); - Assert.AreEqual(null, imageFactory.ImagePath); - Assert.AreEqual(expectedMime, imageFactory.CurrentImageFormat.MimeType); - Assert.IsNotNull(imageFactory.Image); + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Alpha(50); + var modified = imageFactory.Image.Clone(); + Assert.AreNotEqual(original, modified); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void ApplyEffectBrightness() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Brightness(50); + var modified = imageFactory.Image.Clone(); + Assert.AreNotEqual(original, modified); } } } From 03c19e3ae249e90d165a21750084f19b680a4212 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 18:13:23 +0200 Subject: [PATCH 03/35] Adds test for constraints resize Former-commit-id: a30d4df7acc83a74eab1ed881a010fe14b42dd1f --- .../ImageFactoryUnitTests.cs | 24 +++++++++++++++---- .../ImageProcessor.UnitTests.csproj | 4 ---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 7cd124b19..b81cff068 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -21,11 +21,6 @@ namespace ImageProcessor.UnitTests [TestFixture] public class ImageFactoryUnitTests { - /// - /// The path to the binary's folder - /// - private readonly string localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); - /// /// Lists the input files in the Images folder /// @@ -112,5 +107,24 @@ namespace ImageProcessor.UnitTests } } } + + /// + /// Tests that the image is well resized using constraints + /// + [Test] + public void ApplyConstraints() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Constrain(new System.Drawing.Size(200, 200)); + var modified = imageFactory.Image.Clone(); + Assert.AreNotEqual(original, modified); + } + } + } } } \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index d5841e6c2..4bb9bf77f 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -82,10 +82,6 @@ Images\Lighthouse.jpg PreserveNewest - - Images\Penguins-200.jpg - PreserveNewest - Images\Penguins-8.png PreserveNewest From 12e8fbca6c13821247bd02c423ba7c912e4815cd Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 18:16:34 +0200 Subject: [PATCH 04/35] Checks that the image is actually resized Former-commit-id: cf8a8931b6b28c4825283f3a6af4e8c4d087ca9e --- .../ImageFactoryUnitTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index b81cff068..936c32345 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -83,8 +83,7 @@ namespace ImageProcessor.UnitTests imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); imageFactory.Alpha(50); - var modified = imageFactory.Image.Clone(); - Assert.AreNotEqual(original, modified); + Assert.AreNotEqual(original, imageFactory.Image); } } } @@ -102,8 +101,7 @@ namespace ImageProcessor.UnitTests imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); imageFactory.Brightness(50); - var modified = imageFactory.Image.Clone(); - Assert.AreNotEqual(original, modified); + Assert.AreNotEqual(original, imageFactory.Image); } } } @@ -114,15 +112,17 @@ namespace ImageProcessor.UnitTests [Test] public void ApplyConstraints() { + const int maxSize = 200; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.Constrain(new System.Drawing.Size(200, 200)); - var modified = imageFactory.Image.Clone(); - Assert.AreNotEqual(original, modified); + imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.LessOrEqual(maxSize, imageFactory.Image.Width); + Assert.LessOrEqual(maxSize, imageFactory.Image.Height); } } } From ea1ac25f949153235c0a43d4fbf86cdec5a3b668 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 18:52:29 +0200 Subject: [PATCH 05/35] First fix of an animated gif problem on Mono Former-commit-id: 43eebfe02b5974def03fbf40962c787c2c6cdf0a --- src/ImageProcessor/Imaging/Formats/FormatUtilities.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs index 36d2e3c07..3c6e3b3e0 100644 --- a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs +++ b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs @@ -135,12 +135,14 @@ namespace ImageProcessor.Imaging.Formats int frameCount = image.GetFrameCount(frameDimension); int last = frameCount - 1; int delay = 0; - int index = 0; List gifFrames = new List(); for (int i = 0; i < frameCount; i++) { - int thisDelay = BitConverter.ToInt32(image.GetPropertyItem(20736).Value, index); + // GDI returns a single array with all delays, while Mono returns a different array for each frame + image.SelectActiveFrame(frameDimension, i); + var times = image.GetPropertyItem(20736).Value; + int thisDelay = BitConverter.ToInt32(times, 4*i % times.Length); int toAddDelay = thisDelay * 10 < 20 ? 20 : thisDelay * 10; // Minimum delay is 20 ms // Find the frame @@ -156,7 +158,6 @@ namespace ImageProcessor.Imaging.Formats } delay += toAddDelay; - index += 4; } info.GifFrames = gifFrames; From 77c0887972a10af797c57dc4fce11660d6f61ba4 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 20:48:03 +0200 Subject: [PATCH 06/35] Fixes a unit test (wrong parameters order) Former-commit-id: bcfb1caf15531d47653132153ad26cef59668c0e --- src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 936c32345..f81fd1c5b 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -121,8 +121,8 @@ namespace ImageProcessor.UnitTests var original = imageFactory.Image.Clone(); imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); Assert.AreNotEqual(original, imageFactory.Image); - Assert.LessOrEqual(maxSize, imageFactory.Image.Width); - Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + Assert.LessOrEqual(imageFactory.Image.Width, maxSize); + Assert.LessOrEqual(imageFactory.Image.Height, maxSize); } } } From 91b5adbee502c8574a384fa345c59b50fd94879c Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 22:25:54 +0200 Subject: [PATCH 07/35] Re-fix of a Mono problem + modify some 'var' usage Former-commit-id: 1a96ba18689b8aa25607f3b699971f39c16132f9 --- src/ImageProcessor/ImageFactory.cs | 62 ++++++++++++++++-------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 540e34c9a..4a68a5e86 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -177,13 +177,13 @@ namespace ImageProcessor /// public ImageFactory Load(string imagePath) { - FileInfo fileInfo = new FileInfo(imagePath); + var fileInfo = new FileInfo(imagePath); if (fileInfo.Exists) { this.ImagePath = imagePath; // Open a file stream to prevent the need for lock. - using (FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read)) + using (var fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read)) { ISupportedImageFormat format = FormatUtilities.GetFormat(fileStream); @@ -192,7 +192,7 @@ namespace ImageProcessor throw new ImageFormatException("Input stream is not a supported format."); } - MemoryStream memoryStream = new MemoryStream(); + var memoryStream = new MemoryStream(); // Copy the stream. fileStream.CopyTo(memoryStream); @@ -240,7 +240,11 @@ namespace ImageProcessor if (this.ShouldProcess) { // Set our new image as the memory stream value. + #if !__MonoCS__ Image newImage = Image.FromStream(this.InputStream, true); + #else + Image newImage = Image.FromStream(this.InputStream); + #endif // Dispose and reassign the image. this.Image.Dispose(); @@ -275,7 +279,7 @@ namespace ImageProcessor percentage = 0; } - Alpha alpha = new Alpha { DynamicParameter = percentage }; + var alpha = new Alpha { DynamicParameter = percentage }; this.CurrentImageFormat.ApplyProcessor(alpha.ProcessImage, this); } @@ -293,7 +297,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - AutoRotate autoRotate = new AutoRotate(); + var autoRotate = new AutoRotate(); this.CurrentImageFormat.ApplyProcessor(autoRotate.ProcessImage, this); } @@ -320,7 +324,7 @@ namespace ImageProcessor percentage = 0; } - Brightness brightness = new Brightness { DynamicParameter = percentage }; + var brightness = new Brightness { DynamicParameter = percentage }; this.CurrentImageFormat.ApplyProcessor(brightness.ProcessImage, this); } @@ -340,7 +344,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - ResizeLayer layer = new ResizeLayer(size, ResizeMode.Max); + var layer = new ResizeLayer(size, ResizeMode.Max); return this.Resize(layer); } @@ -368,7 +372,7 @@ namespace ImageProcessor percentage = 0; } - Contrast contrast = new Contrast { DynamicParameter = percentage }; + var contrast = new Contrast { DynamicParameter = percentage }; this.CurrentImageFormat.ApplyProcessor(contrast.ProcessImage, this); } @@ -388,7 +392,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - CropLayer cropLayer = new CropLayer(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, CropMode.Pixels); + var cropLayer = new CropLayer(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, CropMode.Pixels); return this.Crop(cropLayer); } @@ -399,7 +403,7 @@ namespace ImageProcessor /// Crops the current image to the given location and size. /// /// - /// The containing the coordinates and mode to crop the image with. + /// The containing the coordinates and mode to crop the image with. /// /// /// The current instance of the class. @@ -408,7 +412,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Crop crop = new Crop { DynamicParameter = cropLayer }; + var crop = new Crop { DynamicParameter = cropLayer }; this.CurrentImageFormat.ApplyProcessor(crop.ProcessImage, this); } @@ -429,7 +433,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Filter filter = new Filter { DynamicParameter = matrixFilter }; + var filter = new Filter { DynamicParameter = matrixFilter }; this.CurrentImageFormat.ApplyProcessor(filter.ProcessImage, this); } @@ -449,11 +453,11 @@ namespace ImageProcessor { if (this.ShouldProcess) { - RotateFlipType rotateFlipType = flipVertically == false - ? RotateFlipType.RotateNoneFlipX - : RotateFlipType.RotateNoneFlipY; + RotateFlipType rotateFlipType = flipVertically + ? RotateFlipType.RotateNoneFlipY + : RotateFlipType.RotateNoneFlipX; - Flip flip = new Flip { DynamicParameter = rotateFlipType }; + var flip = new Flip { DynamicParameter = rotateFlipType }; this.CurrentImageFormat.ApplyProcessor(flip.ProcessImage, this); } @@ -496,7 +500,7 @@ namespace ImageProcessor { if (this.ShouldProcess && size > 0) { - GaussianLayer layer = new GaussianLayer(size); + var layer = new GaussianLayer(size); return this.GaussianBlur(layer); } @@ -517,7 +521,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - GaussianBlur gaussianBlur = new GaussianBlur { DynamicParameter = gaussianLayer }; + var gaussianBlur = new GaussianBlur { DynamicParameter = gaussianLayer }; this.CurrentImageFormat.ApplyProcessor(gaussianBlur.ProcessImage, this); } @@ -543,7 +547,7 @@ namespace ImageProcessor { if (this.ShouldProcess && size > 0) { - GaussianLayer layer = new GaussianLayer(size); + var layer = new GaussianLayer(size); return this.GaussianSharpen(layer); } @@ -564,7 +568,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - GaussianSharpen gaussianSharpen = new GaussianSharpen { DynamicParameter = gaussianLayer }; + var gaussianSharpen = new GaussianSharpen { DynamicParameter = gaussianLayer }; this.CurrentImageFormat.ApplyProcessor(gaussianSharpen.ProcessImage, this); } @@ -607,7 +611,7 @@ namespace ImageProcessor int width = size.Width; int height = size.Height; - ResizeLayer resizeLayer = new ResizeLayer(new Size(width, height)); + var resizeLayer = new ResizeLayer(new Size(width, height)); return this.Resize(resizeLayer); } @@ -629,7 +633,7 @@ namespace ImageProcessor { var resizeSettings = new Dictionary { { "MaxWidth", resizeLayer.Size.Width.ToString("G") }, { "MaxHeight", resizeLayer.Size.Height.ToString("G") } }; - Resize resize = new Resize { DynamicParameter = resizeLayer, Settings = resizeSettings }; + var resize = new Resize { DynamicParameter = resizeLayer, Settings = resizeSettings }; this.CurrentImageFormat.ApplyProcessor(resize.ProcessImage, this); } @@ -655,7 +659,7 @@ namespace ImageProcessor degrees = 0; } - Rotate rotate = new Rotate { DynamicParameter = degrees }; + var rotate = new Rotate { DynamicParameter = degrees }; this.CurrentImageFormat.ApplyProcessor(rotate.ProcessImage, this); } @@ -680,7 +684,7 @@ namespace ImageProcessor roundedCornerLayer.Radius = 0; } - RoundedCorners roundedCorners = new RoundedCorners { DynamicParameter = roundedCornerLayer }; + var roundedCorners = new RoundedCorners { DynamicParameter = roundedCornerLayer }; this.CurrentImageFormat.ApplyProcessor(roundedCorners.ProcessImage, this); } @@ -707,7 +711,7 @@ namespace ImageProcessor percentage = 0; } - Saturation saturate = new Saturation { DynamicParameter = percentage }; + var saturate = new Saturation { DynamicParameter = percentage }; this.CurrentImageFormat.ApplyProcessor(saturate.ProcessImage, this); } @@ -727,7 +731,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Tint tint = new Tint { DynamicParameter = color }; + var tint = new Tint { DynamicParameter = color }; this.CurrentImageFormat.ApplyProcessor(tint.ProcessImage, this); } @@ -747,7 +751,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Vignette vignette = new Vignette + var vignette = new Vignette { DynamicParameter = color.HasValue && !color.Equals(Color.Transparent) ? color.Value @@ -774,7 +778,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Watermark watermark = new Watermark { DynamicParameter = textLayer }; + var watermark = new Watermark { DynamicParameter = textLayer }; this.CurrentImageFormat.ApplyProcessor(watermark.ProcessImage, this); } @@ -796,7 +800,7 @@ namespace ImageProcessor if (this.ShouldProcess) { // ReSharper disable once AssignNullToNotNullAttribute - DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(filePath)); + var directoryInfo = new DirectoryInfo(Path.GetDirectoryName(filePath)); if (!directoryInfo.Exists) { directoryInfo.Create(); From b28d2b94b0a6a47f42c021c80e6a8c4c7accb453 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 22:53:25 +0200 Subject: [PATCH 08/35] Adds a few more unit tests Former-commit-id: c782e8168d8b9b186cc0855e46bd0478019ec5d9 --- .../ImageFactoryUnitTests.cs | 122 +++++++++++++++++- 1 file changed, 119 insertions(+), 3 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index f81fd1c5b..ac5de24a4 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -74,7 +74,7 @@ namespace ImageProcessor.UnitTests /// Tests that a filter is really applied by checking that the image is modified /// [Test] - public void ApplyEffectAlpha() + public void TestApplyEffectAlpha() { foreach (var fileName in ListInputFiles()) { @@ -92,7 +92,7 @@ namespace ImageProcessor.UnitTests /// Tests that a filter is really applied by checking that the image is modified /// [Test] - public void ApplyEffectBrightness() + public void TestApplyEffectBrightness() { foreach (var fileName in ListInputFiles()) { @@ -106,11 +106,85 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectContrast() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Contrast(50); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that all filters can be applied + /// + [Test] + public void TestApplyEffectFilter() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.BlackWhite); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Comic); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Gotham); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.GreyScale); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.HiSatch); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Invert); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Lomograph); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.LoSatch); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Polaroid); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Sepia); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + } + } + } + /// /// Tests that the image is well resized using constraints /// [Test] - public void ApplyConstraints() + public void TestResizeConstraints() { const int maxSize = 200; foreach (var fileName in ListInputFiles()) @@ -126,5 +200,47 @@ namespace ImageProcessor.UnitTests } } } + + /// + /// Tests that the image is well cropped + /// + [Test] + public void TestCrop() + { + const int maxSize = 20; + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Crop(new System.Drawing.Rectangle(0, 0, maxSize, maxSize)); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.AreEqual(maxSize, imageFactory.Image.Width); + Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + } + } + } + + /// + /// Tests that the image is well cropped + /// + [Test] + public void TestCropWithCropLayer() + { + const int maxSize = 20; + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Crop(new Imaging.CropLayer(0, 0, maxSize, maxSize, Imaging.CropMode.Pixels)); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.AreEqual(maxSize, imageFactory.Image.Width); + Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + } + } + } } } \ No newline at end of file From bfa25f7473c5c5ccad09f562fb3589aa3d0e18e4 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 23:11:58 +0200 Subject: [PATCH 09/35] Adds a few more unit tests Former-commit-id: bca6ad3548ecf57e56eb416dcfbfd002b725b733 --- .../ImageFactoryUnitTests.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index ac5de24a4..7dd09e078 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -124,6 +124,42 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectBlur() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.GaussianBlur(5); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectBlurWithLayer() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.GaussianBlur(new Imaging.GaussianLayer() { Sigma = 10, Size = 5, Threshold = 2 }); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + /// /// Tests that all filters can be applied /// @@ -242,5 +278,31 @@ namespace ImageProcessor.UnitTests } } } + + /// + /// Tests that the image is flipped + /// + [Test] + public void TestFlip() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = (System.Drawing.Image)imageFactory.Image.Clone(); + imageFactory.Flip(true); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.AreEqual(original.Width, imageFactory.Image.Width); + Assert.AreEqual(original.Height, imageFactory.Image.Height); + imageFactory.Reset(); + + imageFactory.Flip(false); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.AreEqual(original.Width, imageFactory.Image.Width); + Assert.AreEqual(original.Height, imageFactory.Image.Height); + } + } + } } } \ No newline at end of file From f70dd8112fcfd8fb1cb8d2560c7af4045b48fe97 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 23:22:35 +0200 Subject: [PATCH 10/35] Adds a few more unit tests Former-commit-id: ccb39e91e174833342bf502d6f12dc75b149c0bf --- .../ImageFactoryUnitTests.cs | 82 ++++++++++++++++++- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 7dd09e078..60db9a8ee 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -154,7 +154,43 @@ namespace ImageProcessor.UnitTests { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.GaussianBlur(new Imaging.GaussianLayer() { Sigma = 10, Size = 5, Threshold = 2 }); + imageFactory.GaussianBlur(new Imaging.GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectSharpen() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.GaussianSharpen(5); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectSharpenWithLayer() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.GaussianSharpen(new Imaging.GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); Assert.AreNotEqual(original, imageFactory.Image); } } @@ -228,9 +264,7 @@ namespace ImageProcessor.UnitTests using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); - Assert.AreNotEqual(original, imageFactory.Image); Assert.LessOrEqual(imageFactory.Image.Width, maxSize); Assert.LessOrEqual(imageFactory.Image.Height, maxSize); } @@ -304,5 +338,47 @@ namespace ImageProcessor.UnitTests } } } + + /// + /// Tests that the image is resized + /// + [Test] + public void TestResize() + { + const int newSize = 150; + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + imageFactory.Resize(new System.Drawing.Size(newSize, newSize)); + Assert.AreEqual(newSize, imageFactory.Image.Width); + Assert.AreEqual(newSize, imageFactory.Image.Height); + } + } + } + + /// + /// Tests that the image is resized + /// + [Test] + public void TestResizeWithLayer() + { + const int newSize = 150; + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + imageFactory.Resize(new Imaging.ResizeLayer( + new System.Drawing.Size(newSize, newSize), + Imaging.ResizeMode.Stretch, + Imaging.AnchorPosition.Left, + true)); + Assert.AreEqual(newSize, imageFactory.Image.Width); + Assert.AreEqual(newSize, imageFactory.Image.Height); + } + } + } } } \ No newline at end of file From 601c7b452196b192860f4b8d6ee42be5ea4e0d07 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 00:37:38 +0200 Subject: [PATCH 11/35] Yet a few other unit tests Former-commit-id: cfc586b9f02332ec65eaea1ba0c89b6b4be6b27e --- .../ImageFactoryUnitTests.cs | 182 ++++++++++++++---- 1 file changed, 146 insertions(+), 36 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 60db9a8ee..d868b2245 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -11,8 +11,8 @@ namespace ImageProcessor.UnitTests { using System; - using System.IO; using System.Collections.Generic; + using System.IO; using NUnit.Framework; /// @@ -21,15 +21,6 @@ namespace ImageProcessor.UnitTests [TestFixture] public class ImageFactoryUnitTests { - /// - /// Lists the input files in the Images folder - /// - /// The list of files. - private static IEnumerable ListInputFiles() - { - return Directory.GetFiles("./Images"); - } - /// /// Tests the loading of image from a file /// @@ -45,10 +36,9 @@ namespace ImageProcessor.UnitTests Assert.IsNotNull(imageFactory.Image); } } - } - /// > + /// /// Tests the loading of image from a memory stream /// [Test] @@ -124,6 +114,84 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectSaturation() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Saturation(50); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectTint() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Tint(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue)); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectVignette() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Vignette(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue)); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectWatermark() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Watermark(new Imaging.TextLayer + { + Font = "Arial", + FontSize = 10, + Position = new System.Drawing.Point(10, 10), + Text = "Lorem ipsum dolor" + }); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + /// /// Tests that a filter is really applied by checking that the image is modified /// @@ -252,21 +320,39 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestRoundedCorners() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.RoundedCorners(new Imaging.RoundedCornerLayer(5, true, true, true, true)); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + /// /// Tests that the image is well resized using constraints /// [Test] public void TestResizeConstraints() { - const int maxSize = 200; + const int MaxSize = 200; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); - Assert.LessOrEqual(imageFactory.Image.Width, maxSize); - Assert.LessOrEqual(imageFactory.Image.Height, maxSize); + imageFactory.Constrain(new System.Drawing.Size(MaxSize, MaxSize)); + Assert.LessOrEqual(imageFactory.Image.Width, MaxSize); + Assert.LessOrEqual(imageFactory.Image.Height, MaxSize); } } } @@ -277,17 +363,17 @@ namespace ImageProcessor.UnitTests [Test] public void TestCrop() { - const int maxSize = 20; + const int MaxSize = 20; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.Crop(new System.Drawing.Rectangle(0, 0, maxSize, maxSize)); + imageFactory.Crop(new System.Drawing.Rectangle(0, 0, MaxSize, MaxSize)); Assert.AreNotEqual(original, imageFactory.Image); - Assert.AreEqual(maxSize, imageFactory.Image.Width); - Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + Assert.AreEqual(MaxSize, imageFactory.Image.Width); + Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); } } } @@ -298,17 +384,17 @@ namespace ImageProcessor.UnitTests [Test] public void TestCropWithCropLayer() { - const int maxSize = 20; + const int MaxSize = 20; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.Crop(new Imaging.CropLayer(0, 0, maxSize, maxSize, Imaging.CropMode.Pixels)); + imageFactory.Crop(new Imaging.CropLayer(0, 0, MaxSize, MaxSize, Imaging.CropMode.Pixels)); Assert.AreNotEqual(original, imageFactory.Image); - Assert.AreEqual(maxSize, imageFactory.Image.Width); - Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + Assert.AreEqual(MaxSize, imageFactory.Image.Width); + Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); } } } @@ -345,15 +431,15 @@ namespace ImageProcessor.UnitTests [Test] public void TestResize() { - const int newSize = 150; + const int NewSize = 150; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - imageFactory.Resize(new System.Drawing.Size(newSize, newSize)); - Assert.AreEqual(newSize, imageFactory.Image.Width); - Assert.AreEqual(newSize, imageFactory.Image.Height); + imageFactory.Resize(new System.Drawing.Size(NewSize, NewSize)); + Assert.AreEqual(NewSize, imageFactory.Image.Width); + Assert.AreEqual(NewSize, imageFactory.Image.Height); } } } @@ -364,21 +450,45 @@ namespace ImageProcessor.UnitTests [Test] public void TestResizeWithLayer() { - const int newSize = 150; + const int NewSize = 150; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - imageFactory.Resize(new Imaging.ResizeLayer( - new System.Drawing.Size(newSize, newSize), - Imaging.ResizeMode.Stretch, - Imaging.AnchorPosition.Left, - true)); - Assert.AreEqual(newSize, imageFactory.Image.Width); - Assert.AreEqual(newSize, imageFactory.Image.Height); + imageFactory.Resize(new Imaging.ResizeLayer(new System.Drawing.Size(NewSize, NewSize), Imaging.ResizeMode.Stretch, Imaging.AnchorPosition.Left)); + Assert.AreEqual(NewSize, imageFactory.Image.Width); + Assert.AreEqual(NewSize, imageFactory.Image.Height); } } } + + /// + /// Tests that the image is resized + /// + [Test] + public void TestRotate() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = (System.Drawing.Image)imageFactory.Image.Clone(); + imageFactory.Rotate(90); + Assert.AreEqual(original.Height, imageFactory.Image.Width); + Assert.AreEqual(original.Width, imageFactory.Image.Height); + } + } + } + + /// + /// Lists the input files in the Images folder + /// + /// The list of files. + private static IEnumerable ListInputFiles() + { + return Directory.GetFiles("./Images"); + } } } \ No newline at end of file From ec4274928e42f648529c102d7550b80f502e2146 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 00:41:53 +0200 Subject: [PATCH 12/35] Adds tests for saving the files Former-commit-id: 7893eb70f8315cf13da030fde6a4a3c9884f59aa --- .../ImageFactoryUnitTests.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index d868b2245..880871cc7 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -60,6 +60,45 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that the save method actually saves a file + /// + [Test] + public void TestSaveToDisk() + { + foreach (var fileName in ListInputFiles()) + { + var outputFileName = string.Format("./output/{0}", Path.GetFileName(fileName)); + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + imageFactory.Save(outputFileName); + Assert.AreEqual(true, File.Exists(outputFileName)); + } + } + } + + /// + /// Tests that the save method actually writes to memory + /// + [Test] + public void TestSaveToMemory() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + using (var s = new MemoryStream()) + { + imageFactory.Save(s); + s.Seek(0, SeekOrigin.Begin); + Assert.AreEqual(true, s.Capacity > 0); + } + } + } + } + /// /// Tests that a filter is really applied by checking that the image is modified /// From abdc216549afee230d47d28e91219d6a9d601421 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 11:09:25 +0200 Subject: [PATCH 13/35] Removes unnecessary images Former-commit-id: b7abba38c2ce512bdd6706af08fdabd25537f8b7 --- .../Images/Chrysanthemum.jpg.REMOVED.git-id | 1 - src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id | 1 - src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id | 1 - src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id | 1 - src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id | 1 - 5 files changed, 5 deletions(-) delete mode 100644 src/ImageProcessor.UnitTests/Images/Chrysanthemum.jpg.REMOVED.git-id delete mode 100644 src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id delete mode 100644 src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id delete mode 100644 src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id delete mode 100644 src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id diff --git a/src/ImageProcessor.UnitTests/Images/Chrysanthemum.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/Chrysanthemum.jpg.REMOVED.git-id deleted file mode 100644 index d067665c9..000000000 --- a/src/ImageProcessor.UnitTests/Images/Chrysanthemum.jpg.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -757c2a628dd03b1cbe4b3ef07c153897a702b57a \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id deleted file mode 100644 index 228aac3ab..000000000 --- a/src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -0b88c91336ff8073f34d21ccd683a01f0e0995da \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id deleted file mode 100644 index 74f69293c..000000000 --- a/src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -8150b46ab27c62ba51aaba551eef3f1a30f08de9 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id deleted file mode 100644 index ce873d473..000000000 --- a/src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -6ad3b846d4697584ff601ac481b14a4d3bbb5736 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id deleted file mode 100644 index aeca7b93c..000000000 --- a/src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -db4d55a332254cd6b41336c06f207682bf5a966f \ No newline at end of file From ee0317ddee99e9d6be7f5e9e478ca69dc79b3f0c Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 11:33:05 +0200 Subject: [PATCH 14/35] Filters the source images a bit, in order to speed up the unit tests + descriptive name Former-commit-id: eb53b2d6eef84df94cefa75642ac5be52af4e9e2 --- .../ImageProcessor.UnitTests.csproj | 132 ++++-------------- .../Images/autorotate.jpg.REMOVED.git-id | 1 + .../cmyk-profile-euroscale.jpg.REMOVED.git-id | 1 + .../Images/cmyk.jpg.REMOVED.git-id | 1 + .../color-vision-test.gif.REMOVED.git-id | 1 + .../Images/exif-Tulips.jpg.REMOVED.git-id | 1 + .../Images/exif-rocks.jpg.REMOVED.git-id | 1 + .../format-Penguins-8bit.png.REMOVED.git-id | 1 + .../Images/format-Penguins.bmp.REMOVED.git-id | 1 + .../Images/format-Penguins.gif.REMOVED.git-id | 1 + .../Images/format-Penguins.jpg.REMOVED.git-id | 1 + .../Images/format-Penguins.png.REMOVED.git-id | 1 + .../Images/format-Penguins.tif.REMOVED.git-id | 1 + .../Images/format-animated.gif | 3 + .../Images/hi-color.png | 3 + .../Images/hi-contrast.jpg | 3 + .../Images/hi-saturation.jpg | 3 + .../profile-adobe-rgb.jpg.REMOVED.git-id | 1 + .../Images/profile-srgb.jpg.REMOVED.git-id | 1 + .../Images/size-Penguins-200.jpg | 3 + .../Images/text-over-transparent.png | 3 + .../Images/udendørs.jpg.REMOVED.git-id | 1 + 22 files changed, 57 insertions(+), 108 deletions(-) create mode 100644 src/ImageProcessor.UnitTests/Images/autorotate.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/cmyk-profile-euroscale.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/cmyk.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/exif-Tulips.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/exif-rocks.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins-8bit.png.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.png.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.tif.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-animated.gif create mode 100644 src/ImageProcessor.UnitTests/Images/hi-color.png create mode 100644 src/ImageProcessor.UnitTests/Images/hi-contrast.jpg create mode 100644 src/ImageProcessor.UnitTests/Images/hi-saturation.jpg create mode 100644 src/ImageProcessor.UnitTests/Images/profile-adobe-rgb.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/profile-srgb.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg create mode 100644 src/ImageProcessor.UnitTests/Images/text-over-transparent.png create mode 100644 src/ImageProcessor.UnitTests/Images/udendørs.jpg.REMOVED.git-id diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 4bb9bf77f..726d0988e 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -58,114 +58,27 @@ - - Images\Chrysanthemum.jpg - PreserveNewest - - - Images\Desert.jpg - PreserveNewest - - - Images\Hydrangeas.jpg - PreserveNewest - - - Images\Jellyfish.jpg - PreserveNewest - - - Images\Koala.jpg - PreserveNewest - - - Images\Lighthouse.jpg - PreserveNewest - - - Images\Penguins-8.png - PreserveNewest - - - Images\Penguins.bmp - PreserveNewest - - - Images\Penguins.gif - PreserveNewest - - - Images\Penguins.jpg - PreserveNewest - - - Images\Penguins.png - PreserveNewest - - - Images\Penguins.tif - PreserveNewest - - - Images\Tulips.jpg - PreserveNewest - - - Images\bus.jpg - PreserveNewest - - - Images\cmyk.jpg - PreserveNewest - - - Images\cmyk.png - PreserveNewest - - - Images\jrt.jpg - PreserveNewest - - - Images\meter.gif - PreserveNewest - - - Images\rocks.jpg - PreserveNewest - - - Images\rotate.jpg - PreserveNewest - - - Images\sample1.jpg - PreserveNewest - - - Images\srgb.jpg - PreserveNewest - - - Images\srgb.png - PreserveNewest - - - Images\text.png - PreserveNewest - - - Images\thor.jpg - PreserveNewest - - - Images\udendørs-374.jpg - PreserveNewest - - - Images\udendørs.jpg - PreserveNewest - + + + + + + + + + + + + + + + + + + + + + @@ -175,4 +88,7 @@ + + + \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/autorotate.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/autorotate.jpg.REMOVED.git-id new file mode 100644 index 000000000..19785c8e5 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/autorotate.jpg.REMOVED.git-id @@ -0,0 +1 @@ +85a8ae18f9955def2b42ba9240bce4de1bfe5781 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/cmyk-profile-euroscale.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/cmyk-profile-euroscale.jpg.REMOVED.git-id new file mode 100644 index 000000000..7747bdaae --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/cmyk-profile-euroscale.jpg.REMOVED.git-id @@ -0,0 +1 @@ +13492524f9d984c12adfe6183a4c1d92fb11ec4e \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/cmyk.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/cmyk.jpg.REMOVED.git-id new file mode 100644 index 000000000..30b05146b --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/cmyk.jpg.REMOVED.git-id @@ -0,0 +1 @@ +ed725726e4ac1ffeac821664af14865a66fa933f \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id new file mode 100644 index 000000000..5c4f4195d --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id @@ -0,0 +1 @@ +35a926115b13b61dc37308f8d903b42d14f92924 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/exif-Tulips.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/exif-Tulips.jpg.REMOVED.git-id new file mode 100644 index 000000000..84b9aff85 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/exif-Tulips.jpg.REMOVED.git-id @@ -0,0 +1 @@ +54c51eb6a86f31a42433b8167470fb18dad32c7d \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/exif-rocks.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/exif-rocks.jpg.REMOVED.git-id new file mode 100644 index 000000000..41c6c25df --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/exif-rocks.jpg.REMOVED.git-id @@ -0,0 +1 @@ +33b6912af301bf216ee81d82b2c3ce6c49e03021 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins-8bit.png.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins-8bit.png.REMOVED.git-id new file mode 100644 index 000000000..aa9a70e0f --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins-8bit.png.REMOVED.git-id @@ -0,0 +1 @@ +c3d556d9d486b8b8b49cdbcc9c12a9d3a2db4c1f \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id new file mode 100644 index 000000000..74f69293c --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id @@ -0,0 +1 @@ +8150b46ab27c62ba51aaba551eef3f1a30f08de9 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id new file mode 100644 index 000000000..ce873d473 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id @@ -0,0 +1 @@ +6ad3b846d4697584ff601ac481b14a4d3bbb5736 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.jpg.REMOVED.git-id new file mode 100644 index 000000000..ad4371113 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.jpg.REMOVED.git-id @@ -0,0 +1 @@ +030ab8a685bebb796c24cc710edd9e69859164f6 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.png.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.png.REMOVED.git-id new file mode 100644 index 000000000..78062a0e7 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.png.REMOVED.git-id @@ -0,0 +1 @@ +a2c796fbb7de948230a22982ab74892891dd5198 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.tif.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.tif.REMOVED.git-id new file mode 100644 index 000000000..5f7b97e71 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.tif.REMOVED.git-id @@ -0,0 +1 @@ +c789aaec248568c24394b05c02db4233e0c5a4eb \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-animated.gif b/src/ImageProcessor.UnitTests/Images/format-animated.gif new file mode 100644 index 000000000..ac36f6f25 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-animated.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6212724b3e94908939823d0753b4307923b65d7a27f51823dd3ba7656543349c +size 22525 diff --git a/src/ImageProcessor.UnitTests/Images/hi-color.png b/src/ImageProcessor.UnitTests/Images/hi-color.png new file mode 100644 index 000000000..a9de4cc09 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/hi-color.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:977cc9071257655c9923d267ea5bd417b69754367c2f1aa8765247b68e2bb878 +size 1539 diff --git a/src/ImageProcessor.UnitTests/Images/hi-contrast.jpg b/src/ImageProcessor.UnitTests/Images/hi-contrast.jpg new file mode 100644 index 000000000..98ac863a2 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/hi-contrast.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0ce9e02f2a4663a0a0ed433d5594be87b3fa0387bc8335e80f84d59c34aa424 +size 51058 diff --git a/src/ImageProcessor.UnitTests/Images/hi-saturation.jpg b/src/ImageProcessor.UnitTests/Images/hi-saturation.jpg new file mode 100644 index 000000000..b56f9a83c --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/hi-saturation.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b2012b2eda13a531645c287c254ae5de0e9070368cb4bc806f48314e0464ccd +size 33850 diff --git a/src/ImageProcessor.UnitTests/Images/profile-adobe-rgb.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/profile-adobe-rgb.jpg.REMOVED.git-id new file mode 100644 index 000000000..4ffbf7a8a --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/profile-adobe-rgb.jpg.REMOVED.git-id @@ -0,0 +1 @@ +e29f32091aa13a5b047ccd960f3dc6da9656c84b \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/profile-srgb.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/profile-srgb.jpg.REMOVED.git-id new file mode 100644 index 000000000..f409bc82b --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/profile-srgb.jpg.REMOVED.git-id @@ -0,0 +1 @@ +ab9deaa737f9db9bf0f563e7843ba9b7981cec86 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg b/src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg new file mode 100644 index 000000000..07605996f --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:672de68017f17260126901065f1c6ade2b2981d33dea0dea1606bf7cfb6fdcf3 +size 10119 diff --git a/src/ImageProcessor.UnitTests/Images/text-over-transparent.png b/src/ImageProcessor.UnitTests/Images/text-over-transparent.png new file mode 100644 index 000000000..33d4962bc --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/text-over-transparent.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2322d8dd81df86b8135d399743ea758ad26d6b2ccdcc704e2687ae72d0c187e7 +size 7317 diff --git a/src/ImageProcessor.UnitTests/Images/udendørs.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/udendørs.jpg.REMOVED.git-id new file mode 100644 index 000000000..0db1445a2 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/udendørs.jpg.REMOVED.git-id @@ -0,0 +1 @@ +4d040d9aa3519b3d2303419d1f03eebebf88e956 \ No newline at end of file From 43ac2ffe50ef130398678621035bd57403c620ca Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 11:57:53 +0200 Subject: [PATCH 15/35] Fixes test image includes Former-commit-id: ece5f07535519335d8e992d5831440c9ed9600be --- .../ImageProcessor.UnitTests.csproj | 84 ++++++++++++++----- 1 file changed, 63 insertions(+), 21 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 726d0988e..4fbcc99b6 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -43,7 +43,9 @@ - + + PreserveNewest + @@ -59,26 +61,66 @@ - - - - - - - - - - - - - - - - - - - - + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + From 97a82afe84ef6a65dc8e9d712729779084e41a7b Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Wed, 25 Jun 2014 23:59:37 +0200 Subject: [PATCH 16/35] Creates a new Mono project so it can at least build (not yet run) on Xamarin/Mono Former-commit-id: 73972cac708c4e8958f0c40a99a86a0c9884eebb --- src/ImageProcessor_Mono.sln | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ImageProcessor_Mono.sln b/src/ImageProcessor_Mono.sln index 7d47a2ca6..d7e1410a8 100644 --- a/src/ImageProcessor_Mono.sln +++ b/src/ImageProcessor_Mono.sln @@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{1E656C EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor", "ImageProcessor\ImageProcessor.csproj", "{3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Website_MVC_NET4", "TestWebsites\NET4\Test_Website_MVC_NET4.csproj", "{30327C08-7574-4D7E-AC95-6A58753C6855}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.Web_NET4", "ImageProcessor.Web\NET4\ImageProcessor.Web_NET4.csproj", "{4F7050F2-465F-4E10-8DB2-2FB97AC6AA43}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.Web_NET45", "ImageProcessor.Web\NET45\ImageProcessor.Web_NET45.csproj", "{D011A778-59C8-4BFA-A770-C350216BF161}" @@ -37,6 +39,24 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {30327C08-7574-4D7E-AC95-6A58753C6855}.All|Any CPU.ActiveCfg = All|Any CPU + {30327C08-7574-4D7E-AC95-6A58753C6855}.All|Any CPU.Build.0 = All|Any CPU + {30327C08-7574-4D7E-AC95-6A58753C6855}.All|Mixed Platforms.ActiveCfg = All|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.All|Mixed Platforms.Build.0 = All|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.All|x86.ActiveCfg = All|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.All|x86.Build.0 = All|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|x86.ActiveCfg = Debug|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|x86.Build.0 = Debug|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|Any CPU.Build.0 = Release|Any CPU + {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|Mixed Platforms.Build.0 = Release|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|x86.ActiveCfg = Release|x86 + {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|x86.Build.0 = Release|x86 {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Any CPU.ActiveCfg = All|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Any CPU.Build.0 = All|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Mixed Platforms.ActiveCfg = All|Any CPU From ddd9be8d5daf2bf725c7980a006733e63b1d704f Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Thu, 26 Jun 2014 00:08:55 +0200 Subject: [PATCH 17/35] Removes MVC test project from Mono solution because of heavy dependencies Former-commit-id: c4a57569c8eec272ba8ea994022eb937ef6e4d8a --- src/ImageProcessor_Mono.sln | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/ImageProcessor_Mono.sln b/src/ImageProcessor_Mono.sln index d7e1410a8..7d47a2ca6 100644 --- a/src/ImageProcessor_Mono.sln +++ b/src/ImageProcessor_Mono.sln @@ -18,8 +18,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{1E656C EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor", "ImageProcessor\ImageProcessor.csproj", "{3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Website_MVC_NET4", "TestWebsites\NET4\Test_Website_MVC_NET4.csproj", "{30327C08-7574-4D7E-AC95-6A58753C6855}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.Web_NET4", "ImageProcessor.Web\NET4\ImageProcessor.Web_NET4.csproj", "{4F7050F2-465F-4E10-8DB2-2FB97AC6AA43}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.Web_NET45", "ImageProcessor.Web\NET45\ImageProcessor.Web_NET45.csproj", "{D011A778-59C8-4BFA-A770-C350216BF161}" @@ -39,24 +37,6 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {30327C08-7574-4D7E-AC95-6A58753C6855}.All|Any CPU.ActiveCfg = All|Any CPU - {30327C08-7574-4D7E-AC95-6A58753C6855}.All|Any CPU.Build.0 = All|Any CPU - {30327C08-7574-4D7E-AC95-6A58753C6855}.All|Mixed Platforms.ActiveCfg = All|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.All|Mixed Platforms.Build.0 = All|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.All|x86.ActiveCfg = All|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.All|x86.Build.0 = All|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|Any CPU.Build.0 = Debug|Any CPU - {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|x86.ActiveCfg = Debug|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.Debug|x86.Build.0 = Debug|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|Any CPU.ActiveCfg = Release|Any CPU - {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|Any CPU.Build.0 = Release|Any CPU - {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|Mixed Platforms.Build.0 = Release|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|x86.ActiveCfg = Release|x86 - {30327C08-7574-4D7E-AC95-6A58753C6855}.Release|x86.Build.0 = Release|x86 {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Any CPU.ActiveCfg = All|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Any CPU.Build.0 = All|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Mixed Platforms.ActiveCfg = All|Any CPU From 049cd3cfc7711eef2223d48ad1bcd0b1dcaf183e Mon Sep 17 00:00:00 2001 From: James South Date: Thu, 26 Jun 2014 22:30:08 +0100 Subject: [PATCH 18/35] Separating Unit Tests Hopefully rebuilding the projects will fix the AppVeyor issues. Former-commit-id: 61a12987b4f4c9324580f15b8f23b35c03876726 --- .../ImageProcessor.UnitTests.csproj | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 81516b4b6..96dfb17a2 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -65,6 +65,9 @@ ImageProcessor + + + @@ -72,6 +75,136 @@ + + + Images\1182076_e8c402e938_z.jpg + + + Images\bus.jpg + + + Images\Chrysanthemum.jpg + + + Images\circle.png + + + Images\cmyk.jpg + + + Images\cmyk.png + + + Images\color-vision-test.gif + + + Images\Desert.jpg + + + Images\emma.jpg + + + Images\falahill_design__160p.jpg + + + Images\fid11246.jpg + + + Images\fid9141.jpg + + + Images\header_1.jpg + + + Images\Hydrangeas.jpg + + + Images\Jellyfish.jpg + + + Images\jrt.jpg + + + Images\Koala.jpg + + + Images\Lighthouse.jpg + + + Images\lomo.jpg + + + Images\meter.gif + + + Images\negative.png + + + Images\negative2.png + + + Images\Penguins-200.jpg + + + Images\Penguins-8.png + + + Images\Penguins.bmp + + + Images\Penguins.gif + + + Images\Penguins.jpg + + + Images\Penguins.png + + + Images\Penguins.tif + + + Images\rocks.jpg + + + Images\rotate.jpg + + + Images\sample1.jpg + + + Images\srgb.jpg + + + Images\srgb.png + + + Images\text.png + + + Images\thor.jpg + + + Images\Tulips.jpg + + + Images\udendørs-374.jpg + + + Images\udendørs.jpg + + + Images\war_horse_quad.jpg + + + Images\WP_000009.jpg + + + + + {3b5dd734-fb7a-487d-8ce6-55e7af9aea7e} + ImageProcessor + From 5c56a16eecf22a01894c156d02ef04cadd2f86c6 Mon Sep 17 00:00:00 2001 From: James South Date: Thu, 26 Jun 2014 22:59:30 +0100 Subject: [PATCH 19/35] Moving Images in unit test Former-commit-id: 0448d1ccf9fad7e431636cbed45e6e7a3bf28cd2 --- .../ImageProcessor.UnitTests.csproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 96dfb17a2..981d8ded5 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -206,6 +206,14 @@ ImageProcessor + + + + + + + + From 70251bea635c5629226f9d2442a9ebf1c91e3cde Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 15:42:31 +0200 Subject: [PATCH 20/35] Adds new test of factory for loading an image from a memory stream Former-commit-id: d97f8846fc92eaf59c5595b9af871b246bf71b9f --- .../ImageFactoryUnitTests.cs | 33 +++ .../ImageProcessor.UnitTests.csproj | 201 ++++++++++++------ src/ImageProcessor_Mono.sln | 26 ++- 3 files changed, 190 insertions(+), 70 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index a63f95ff2..1fc782073 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -51,5 +51,38 @@ namespace ImageProcessor.UnitTests Assert.IsNotNull(imageFactory.Image); } } + + /// > + /// Tests the loading of image from a memory stream + /// + /// + /// The file Name. + /// + /// + /// The expected mime type. + /// + [Test] + [TestCase("Chrysanthemum.jpg", "image/jpeg")] + [TestCase("Desert.jpg", "image/jpeg")] + [TestCase("cmyk.png", "image/png")] + [TestCase("Penguins.bmp", "image/bmp")] + [TestCase("Penguins.gif", "image/gif")] + public void TestLoadImageFromMemory(string fileName, string expectedMime) + { + string testPhoto = Path.Combine(this.localPath, string.Format("../../Images/{0}", fileName)); + byte[] photoBytes = File.ReadAllBytes(testPhoto); + + // ImageProcessor + using (MemoryStream inStream = new MemoryStream(photoBytes)) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(inStream); + Assert.AreEqual(null, imageFactory.ImagePath); + Assert.AreEqual(expectedMime, imageFactory.CurrentImageFormat.MimeType); + Assert.IsNotNull(imageFactory.Image); + } + } + } } } \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 981d8ded5..111f5e03c 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -1,67 +1,58 @@  - + Debug AnyCPU - {633B1C4C-4823-47BE-9A01-A665F3118C8C} + {03CA9055-F997-428C-BF28-F50F991777C6} Library - Properties ImageProcessor.UnitTests ImageProcessor.UnitTests - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest + + ..\ true - + v4.5 true full false - bin\Debug\ - DEBUG;TRACE + bin\Debug + DEBUG; prompt 4 + false + false - pdbonly + full true - bin\Release\ - TRACE + bin\Release prompt 4 + false + false + + ..\packages\NUnit.2.6.3\lib\nunit.framework.dll - - + + - - - - - - - - - - - - + + + {D011A778-59C8-4BFA-A770-C350216BF161} + ImageProcessor.Web_NET45 + - {3b5dd734-fb7a-487d-8ce6-55e7af9aea7e} + {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E} ImageProcessor @@ -208,32 +199,121 @@ - - - - - + + + Images\Chrysanthemum.jpg + PreserveNewest + + + Images\Desert.jpg + PreserveNewest + + + Images\Hydrangeas.jpg + PreserveNewest + + + Images\Jellyfish.jpg + PreserveNewest + + + Images\Koala.jpg + PreserveNewest + + + Images\Lighthouse.jpg + PreserveNewest + + + Images\Penguins-200.jpg + PreserveNewest + + + Images\Penguins-8.png + PreserveNewest + + + Images\Penguins.bmp + PreserveNewest + + + Images\Penguins.gif + PreserveNewest + + + Images\Penguins.jpg + PreserveNewest + + + Images\Penguins.png + PreserveNewest + + + Images\Penguins.tif + PreserveNewest + + + Images\Tulips.jpg + PreserveNewest + + + Images\bus.jpg + PreserveNewest + + + Images\cmyk.jpg + PreserveNewest + + + Images\cmyk.png + PreserveNewest + + + Images\jrt.jpg + PreserveNewest + + + Images\meter.gif + PreserveNewest + + + Images\rocks.jpg + PreserveNewest + + + Images\rotate.jpg + PreserveNewest + + + Images\sample1.jpg + PreserveNewest + + + Images\srgb.jpg + PreserveNewest + + + Images\srgb.png + PreserveNewest + + + Images\text.png + PreserveNewest + + + Images\thor.jpg + PreserveNewest + + + Images\udendørs-374.jpg + PreserveNewest + + + Images\udendørs.jpg + PreserveNewest + - - - - - False - - - False - - - False - - - False - - - - - - + @@ -241,11 +321,4 @@ - \ No newline at end of file diff --git a/src/ImageProcessor_Mono.sln b/src/ImageProcessor_Mono.sln index 7d47a2ca6..8b1e0fb37 100644 --- a/src/ImageProcessor_Mono.sln +++ b/src/ImageProcessor_Mono.sln @@ -3,12 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 VisualStudioVersion = 12.0.30110.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C427A497-74DC-49B1-8420-D6E68354F29B}" - ProjectSection(SolutionItems) = preProject - ImageProcessor.vsmdi = ImageProcessor.vsmdi - Local.testsettings = Local.testsettings - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{1E656CDE-124D-4FAF-837C-0EF1E192D418}" ProjectSection(SolutionItems) = preProject .nuget\NuGet.Config = .nuget\NuGet.Config @@ -24,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.Web_NET45", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessorConsole", "ImageProcessorConsole\ImageProcessorConsole.csproj", "{7BF5274B-56A7-4B62-8105-E9BDF25BAFE7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor.UnitTests", "ImageProcessor.UnitTests\ImageProcessor.UnitTests.csproj", "{03CA9055-F997-428C-BF28-F50F991777C6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution All|Any CPU = All|Any CPU @@ -37,6 +33,24 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {03CA9055-F997-428C-BF28-F50F991777C6}.All|Any CPU.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|Any CPU.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|Mixed Platforms.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|x86.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.All|x86.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|x86.ActiveCfg = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Debug|x86.Build.0 = Debug|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|Any CPU.Build.0 = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|x86.ActiveCfg = Release|Any CPU + {03CA9055-F997-428C-BF28-F50F991777C6}.Release|x86.Build.0 = Release|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Any CPU.ActiveCfg = All|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Any CPU.Build.0 = All|Any CPU {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}.All|Mixed Platforms.ActiveCfg = All|Any CPU From 96e8286c2ab2e5e84121c7383034b35efe2d31ce Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 18:03:26 +0200 Subject: [PATCH 21/35] Loads all the test images + tests a few filters as well (failing for gif images) Former-commit-id: a0aacc78aeb810580ff7c3e0979502c3f60c5cd3 --- .../ImageFactoryUnitTests.cs | 106 +++++++++++------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 1fc782073..7cd124b19 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -12,6 +12,7 @@ namespace ImageProcessor.UnitTests { using System; using System.IO; + using System.Collections.Generic; using NUnit.Framework; /// @@ -25,62 +26,89 @@ namespace ImageProcessor.UnitTests /// private readonly string localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); + /// + /// Lists the input files in the Images folder + /// + /// The list of files. + private static IEnumerable ListInputFiles() + { + return Directory.GetFiles("./Images"); + } + /// /// Tests the loading of image from a file /// - /// - /// The file Name. - /// - /// - /// The expected mime type. - /// [Test] - [TestCase("Chrysanthemum.jpg", "image/jpeg")] - [TestCase("Desert.jpg", "image/jpeg")] - [TestCase("cmyk.png", "image/png")] - [TestCase("Penguins.bmp", "image/bmp")] - [TestCase("Penguins.gif", "image/gif")] - public void TestLoadImageFromFile(string fileName, string expectedMime) + public void TestLoadImageFromFile() { - string testPhoto = Path.Combine(this.localPath, string.Format("../../Images/{0}", fileName)); - using (ImageFactory imageFactory = new ImageFactory()) + foreach (var fileName in ListInputFiles()) { - imageFactory.Load(testPhoto); - Assert.AreEqual(testPhoto, imageFactory.ImagePath); - Assert.AreEqual(expectedMime, imageFactory.CurrentImageFormat.MimeType); - Assert.IsNotNull(imageFactory.Image); + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + Assert.AreEqual(fileName, imageFactory.ImagePath); + Assert.IsNotNull(imageFactory.Image); + } } + } /// > /// Tests the loading of image from a memory stream /// - /// - /// The file Name. - /// - /// - /// The expected mime type. - /// [Test] - [TestCase("Chrysanthemum.jpg", "image/jpeg")] - [TestCase("Desert.jpg", "image/jpeg")] - [TestCase("cmyk.png", "image/png")] - [TestCase("Penguins.bmp", "image/bmp")] - [TestCase("Penguins.gif", "image/gif")] - public void TestLoadImageFromMemory(string fileName, string expectedMime) + public void TestLoadImageFromMemory() { - string testPhoto = Path.Combine(this.localPath, string.Format("../../Images/{0}", fileName)); - byte[] photoBytes = File.ReadAllBytes(testPhoto); + foreach (var fileName in ListInputFiles()) + { + byte[] photoBytes = File.ReadAllBytes(fileName); - // ImageProcessor - using (MemoryStream inStream = new MemoryStream(photoBytes)) + using (var inStream = new MemoryStream(photoBytes)) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(inStream); + Assert.AreEqual(null, imageFactory.ImagePath); + Assert.IsNotNull(imageFactory.Image); + } + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void ApplyEffectAlpha() + { + foreach (var fileName in ListInputFiles()) { - using (ImageFactory imageFactory = new ImageFactory()) + using (var imageFactory = new ImageFactory()) { - imageFactory.Load(inStream); - Assert.AreEqual(null, imageFactory.ImagePath); - Assert.AreEqual(expectedMime, imageFactory.CurrentImageFormat.MimeType); - Assert.IsNotNull(imageFactory.Image); + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Alpha(50); + var modified = imageFactory.Image.Clone(); + Assert.AreNotEqual(original, modified); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void ApplyEffectBrightness() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Brightness(50); + var modified = imageFactory.Image.Clone(); + Assert.AreNotEqual(original, modified); } } } From 255184387557cd6a5fb301f267a750ed605d27d9 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 18:13:23 +0200 Subject: [PATCH 22/35] Adds test for constraints resize Former-commit-id: dca011a62587c43e6a59054c4949f09df14dbbf1 --- .../ImageFactoryUnitTests.cs | 24 +++++++++++++++---- .../ImageProcessor.UnitTests.csproj | 4 ---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 7cd124b19..b81cff068 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -21,11 +21,6 @@ namespace ImageProcessor.UnitTests [TestFixture] public class ImageFactoryUnitTests { - /// - /// The path to the binary's folder - /// - private readonly string localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); - /// /// Lists the input files in the Images folder /// @@ -112,5 +107,24 @@ namespace ImageProcessor.UnitTests } } } + + /// + /// Tests that the image is well resized using constraints + /// + [Test] + public void ApplyConstraints() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Constrain(new System.Drawing.Size(200, 200)); + var modified = imageFactory.Image.Clone(); + Assert.AreNotEqual(original, modified); + } + } + } } } \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 111f5e03c..c0311d476 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -224,10 +224,6 @@ Images\Lighthouse.jpg PreserveNewest - - Images\Penguins-200.jpg - PreserveNewest - Images\Penguins-8.png PreserveNewest From 87daabb306517b4f2d572123cb71a0945443605c Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 18:16:34 +0200 Subject: [PATCH 23/35] Checks that the image is actually resized Former-commit-id: c13de5b788d5fbd4f2d2224ed575cd667c8af838 --- .../ImageFactoryUnitTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index b81cff068..936c32345 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -83,8 +83,7 @@ namespace ImageProcessor.UnitTests imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); imageFactory.Alpha(50); - var modified = imageFactory.Image.Clone(); - Assert.AreNotEqual(original, modified); + Assert.AreNotEqual(original, imageFactory.Image); } } } @@ -102,8 +101,7 @@ namespace ImageProcessor.UnitTests imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); imageFactory.Brightness(50); - var modified = imageFactory.Image.Clone(); - Assert.AreNotEqual(original, modified); + Assert.AreNotEqual(original, imageFactory.Image); } } } @@ -114,15 +112,17 @@ namespace ImageProcessor.UnitTests [Test] public void ApplyConstraints() { + const int maxSize = 200; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.Constrain(new System.Drawing.Size(200, 200)); - var modified = imageFactory.Image.Clone(); - Assert.AreNotEqual(original, modified); + imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.LessOrEqual(maxSize, imageFactory.Image.Width); + Assert.LessOrEqual(maxSize, imageFactory.Image.Height); } } } From f7261feed54d6fe558a1530d6ff94f886b6640f9 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 18:52:29 +0200 Subject: [PATCH 24/35] First fix of an animated gif problem on Mono Former-commit-id: 03c0f1246530ecead97e5346cebd197f77a72401 --- src/ImageProcessor/Imaging/Formats/FormatUtilities.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs index 36d2e3c07..3c6e3b3e0 100644 --- a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs +++ b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs @@ -135,12 +135,14 @@ namespace ImageProcessor.Imaging.Formats int frameCount = image.GetFrameCount(frameDimension); int last = frameCount - 1; int delay = 0; - int index = 0; List gifFrames = new List(); for (int i = 0; i < frameCount; i++) { - int thisDelay = BitConverter.ToInt32(image.GetPropertyItem(20736).Value, index); + // GDI returns a single array with all delays, while Mono returns a different array for each frame + image.SelectActiveFrame(frameDimension, i); + var times = image.GetPropertyItem(20736).Value; + int thisDelay = BitConverter.ToInt32(times, 4*i % times.Length); int toAddDelay = thisDelay * 10 < 20 ? 20 : thisDelay * 10; // Minimum delay is 20 ms // Find the frame @@ -156,7 +158,6 @@ namespace ImageProcessor.Imaging.Formats } delay += toAddDelay; - index += 4; } info.GifFrames = gifFrames; From be2cb5e7bbbeef2eefd7c408848793567e1c002e Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 20:48:03 +0200 Subject: [PATCH 25/35] Fixes a unit test (wrong parameters order) Former-commit-id: b691dc9582d00c8ef9b0160d69c59914a63ecb18 --- src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 936c32345..f81fd1c5b 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -121,8 +121,8 @@ namespace ImageProcessor.UnitTests var original = imageFactory.Image.Clone(); imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); Assert.AreNotEqual(original, imageFactory.Image); - Assert.LessOrEqual(maxSize, imageFactory.Image.Width); - Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + Assert.LessOrEqual(imageFactory.Image.Width, maxSize); + Assert.LessOrEqual(imageFactory.Image.Height, maxSize); } } } From a019e0ffa5d3e06c20105043a9fa9b8b76963828 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 22:25:54 +0200 Subject: [PATCH 26/35] Re-fix of a Mono problem + modify some 'var' usage Former-commit-id: bbd7b29020665345032768961c448c64605620f9 --- src/ImageProcessor/ImageFactory.cs | 62 ++++++++++++++++-------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 540e34c9a..4a68a5e86 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -177,13 +177,13 @@ namespace ImageProcessor /// public ImageFactory Load(string imagePath) { - FileInfo fileInfo = new FileInfo(imagePath); + var fileInfo = new FileInfo(imagePath); if (fileInfo.Exists) { this.ImagePath = imagePath; // Open a file stream to prevent the need for lock. - using (FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read)) + using (var fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read)) { ISupportedImageFormat format = FormatUtilities.GetFormat(fileStream); @@ -192,7 +192,7 @@ namespace ImageProcessor throw new ImageFormatException("Input stream is not a supported format."); } - MemoryStream memoryStream = new MemoryStream(); + var memoryStream = new MemoryStream(); // Copy the stream. fileStream.CopyTo(memoryStream); @@ -240,7 +240,11 @@ namespace ImageProcessor if (this.ShouldProcess) { // Set our new image as the memory stream value. + #if !__MonoCS__ Image newImage = Image.FromStream(this.InputStream, true); + #else + Image newImage = Image.FromStream(this.InputStream); + #endif // Dispose and reassign the image. this.Image.Dispose(); @@ -275,7 +279,7 @@ namespace ImageProcessor percentage = 0; } - Alpha alpha = new Alpha { DynamicParameter = percentage }; + var alpha = new Alpha { DynamicParameter = percentage }; this.CurrentImageFormat.ApplyProcessor(alpha.ProcessImage, this); } @@ -293,7 +297,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - AutoRotate autoRotate = new AutoRotate(); + var autoRotate = new AutoRotate(); this.CurrentImageFormat.ApplyProcessor(autoRotate.ProcessImage, this); } @@ -320,7 +324,7 @@ namespace ImageProcessor percentage = 0; } - Brightness brightness = new Brightness { DynamicParameter = percentage }; + var brightness = new Brightness { DynamicParameter = percentage }; this.CurrentImageFormat.ApplyProcessor(brightness.ProcessImage, this); } @@ -340,7 +344,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - ResizeLayer layer = new ResizeLayer(size, ResizeMode.Max); + var layer = new ResizeLayer(size, ResizeMode.Max); return this.Resize(layer); } @@ -368,7 +372,7 @@ namespace ImageProcessor percentage = 0; } - Contrast contrast = new Contrast { DynamicParameter = percentage }; + var contrast = new Contrast { DynamicParameter = percentage }; this.CurrentImageFormat.ApplyProcessor(contrast.ProcessImage, this); } @@ -388,7 +392,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - CropLayer cropLayer = new CropLayer(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, CropMode.Pixels); + var cropLayer = new CropLayer(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, CropMode.Pixels); return this.Crop(cropLayer); } @@ -399,7 +403,7 @@ namespace ImageProcessor /// Crops the current image to the given location and size. /// /// - /// The containing the coordinates and mode to crop the image with. + /// The containing the coordinates and mode to crop the image with. /// /// /// The current instance of the class. @@ -408,7 +412,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Crop crop = new Crop { DynamicParameter = cropLayer }; + var crop = new Crop { DynamicParameter = cropLayer }; this.CurrentImageFormat.ApplyProcessor(crop.ProcessImage, this); } @@ -429,7 +433,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Filter filter = new Filter { DynamicParameter = matrixFilter }; + var filter = new Filter { DynamicParameter = matrixFilter }; this.CurrentImageFormat.ApplyProcessor(filter.ProcessImage, this); } @@ -449,11 +453,11 @@ namespace ImageProcessor { if (this.ShouldProcess) { - RotateFlipType rotateFlipType = flipVertically == false - ? RotateFlipType.RotateNoneFlipX - : RotateFlipType.RotateNoneFlipY; + RotateFlipType rotateFlipType = flipVertically + ? RotateFlipType.RotateNoneFlipY + : RotateFlipType.RotateNoneFlipX; - Flip flip = new Flip { DynamicParameter = rotateFlipType }; + var flip = new Flip { DynamicParameter = rotateFlipType }; this.CurrentImageFormat.ApplyProcessor(flip.ProcessImage, this); } @@ -496,7 +500,7 @@ namespace ImageProcessor { if (this.ShouldProcess && size > 0) { - GaussianLayer layer = new GaussianLayer(size); + var layer = new GaussianLayer(size); return this.GaussianBlur(layer); } @@ -517,7 +521,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - GaussianBlur gaussianBlur = new GaussianBlur { DynamicParameter = gaussianLayer }; + var gaussianBlur = new GaussianBlur { DynamicParameter = gaussianLayer }; this.CurrentImageFormat.ApplyProcessor(gaussianBlur.ProcessImage, this); } @@ -543,7 +547,7 @@ namespace ImageProcessor { if (this.ShouldProcess && size > 0) { - GaussianLayer layer = new GaussianLayer(size); + var layer = new GaussianLayer(size); return this.GaussianSharpen(layer); } @@ -564,7 +568,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - GaussianSharpen gaussianSharpen = new GaussianSharpen { DynamicParameter = gaussianLayer }; + var gaussianSharpen = new GaussianSharpen { DynamicParameter = gaussianLayer }; this.CurrentImageFormat.ApplyProcessor(gaussianSharpen.ProcessImage, this); } @@ -607,7 +611,7 @@ namespace ImageProcessor int width = size.Width; int height = size.Height; - ResizeLayer resizeLayer = new ResizeLayer(new Size(width, height)); + var resizeLayer = new ResizeLayer(new Size(width, height)); return this.Resize(resizeLayer); } @@ -629,7 +633,7 @@ namespace ImageProcessor { var resizeSettings = new Dictionary { { "MaxWidth", resizeLayer.Size.Width.ToString("G") }, { "MaxHeight", resizeLayer.Size.Height.ToString("G") } }; - Resize resize = new Resize { DynamicParameter = resizeLayer, Settings = resizeSettings }; + var resize = new Resize { DynamicParameter = resizeLayer, Settings = resizeSettings }; this.CurrentImageFormat.ApplyProcessor(resize.ProcessImage, this); } @@ -655,7 +659,7 @@ namespace ImageProcessor degrees = 0; } - Rotate rotate = new Rotate { DynamicParameter = degrees }; + var rotate = new Rotate { DynamicParameter = degrees }; this.CurrentImageFormat.ApplyProcessor(rotate.ProcessImage, this); } @@ -680,7 +684,7 @@ namespace ImageProcessor roundedCornerLayer.Radius = 0; } - RoundedCorners roundedCorners = new RoundedCorners { DynamicParameter = roundedCornerLayer }; + var roundedCorners = new RoundedCorners { DynamicParameter = roundedCornerLayer }; this.CurrentImageFormat.ApplyProcessor(roundedCorners.ProcessImage, this); } @@ -707,7 +711,7 @@ namespace ImageProcessor percentage = 0; } - Saturation saturate = new Saturation { DynamicParameter = percentage }; + var saturate = new Saturation { DynamicParameter = percentage }; this.CurrentImageFormat.ApplyProcessor(saturate.ProcessImage, this); } @@ -727,7 +731,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Tint tint = new Tint { DynamicParameter = color }; + var tint = new Tint { DynamicParameter = color }; this.CurrentImageFormat.ApplyProcessor(tint.ProcessImage, this); } @@ -747,7 +751,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Vignette vignette = new Vignette + var vignette = new Vignette { DynamicParameter = color.HasValue && !color.Equals(Color.Transparent) ? color.Value @@ -774,7 +778,7 @@ namespace ImageProcessor { if (this.ShouldProcess) { - Watermark watermark = new Watermark { DynamicParameter = textLayer }; + var watermark = new Watermark { DynamicParameter = textLayer }; this.CurrentImageFormat.ApplyProcessor(watermark.ProcessImage, this); } @@ -796,7 +800,7 @@ namespace ImageProcessor if (this.ShouldProcess) { // ReSharper disable once AssignNullToNotNullAttribute - DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(filePath)); + var directoryInfo = new DirectoryInfo(Path.GetDirectoryName(filePath)); if (!directoryInfo.Exists) { directoryInfo.Create(); From 7d18066d88a0588ddbf2ac9e79214e212235ff46 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 22:53:25 +0200 Subject: [PATCH 27/35] Adds a few more unit tests Former-commit-id: e7407d2bc753aac4bf9f3f0acf55d160149efb68 --- .../ImageFactoryUnitTests.cs | 122 +++++++++++++++++- 1 file changed, 119 insertions(+), 3 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index f81fd1c5b..ac5de24a4 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -74,7 +74,7 @@ namespace ImageProcessor.UnitTests /// Tests that a filter is really applied by checking that the image is modified /// [Test] - public void ApplyEffectAlpha() + public void TestApplyEffectAlpha() { foreach (var fileName in ListInputFiles()) { @@ -92,7 +92,7 @@ namespace ImageProcessor.UnitTests /// Tests that a filter is really applied by checking that the image is modified /// [Test] - public void ApplyEffectBrightness() + public void TestApplyEffectBrightness() { foreach (var fileName in ListInputFiles()) { @@ -106,11 +106,85 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectContrast() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Contrast(50); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that all filters can be applied + /// + [Test] + public void TestApplyEffectFilter() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.BlackWhite); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Comic); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Gotham); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.GreyScale); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.HiSatch); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Invert); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Lomograph); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.LoSatch); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Polaroid); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + + imageFactory.Filter(Imaging.Filters.MatrixFilters.Sepia); + Assert.AreNotEqual(original, imageFactory.Image); + imageFactory.Reset(); + } + } + } + /// /// Tests that the image is well resized using constraints /// [Test] - public void ApplyConstraints() + public void TestResizeConstraints() { const int maxSize = 200; foreach (var fileName in ListInputFiles()) @@ -126,5 +200,47 @@ namespace ImageProcessor.UnitTests } } } + + /// + /// Tests that the image is well cropped + /// + [Test] + public void TestCrop() + { + const int maxSize = 20; + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Crop(new System.Drawing.Rectangle(0, 0, maxSize, maxSize)); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.AreEqual(maxSize, imageFactory.Image.Width); + Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + } + } + } + + /// + /// Tests that the image is well cropped + /// + [Test] + public void TestCropWithCropLayer() + { + const int maxSize = 20; + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Crop(new Imaging.CropLayer(0, 0, maxSize, maxSize, Imaging.CropMode.Pixels)); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.AreEqual(maxSize, imageFactory.Image.Width); + Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + } + } + } } } \ No newline at end of file From 6ef0c72eb81fb3711c01db02d2233d958112ccb6 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 23:11:58 +0200 Subject: [PATCH 28/35] Adds a few more unit tests Former-commit-id: dbb26885a48c55480ce771d885a46d7726af0576 --- .../ImageFactoryUnitTests.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index ac5de24a4..7dd09e078 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -124,6 +124,42 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectBlur() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.GaussianBlur(5); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectBlurWithLayer() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.GaussianBlur(new Imaging.GaussianLayer() { Sigma = 10, Size = 5, Threshold = 2 }); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + /// /// Tests that all filters can be applied /// @@ -242,5 +278,31 @@ namespace ImageProcessor.UnitTests } } } + + /// + /// Tests that the image is flipped + /// + [Test] + public void TestFlip() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = (System.Drawing.Image)imageFactory.Image.Clone(); + imageFactory.Flip(true); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.AreEqual(original.Width, imageFactory.Image.Width); + Assert.AreEqual(original.Height, imageFactory.Image.Height); + imageFactory.Reset(); + + imageFactory.Flip(false); + Assert.AreNotEqual(original, imageFactory.Image); + Assert.AreEqual(original.Width, imageFactory.Image.Width); + Assert.AreEqual(original.Height, imageFactory.Image.Height); + } + } + } } } \ No newline at end of file From 412ab93c47dc9afbf6cf2a93ca3c2adcdf84dadf Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 23:22:35 +0200 Subject: [PATCH 29/35] Adds a few more unit tests Former-commit-id: f0987ec15552263ee8b2915d25d51514b5db2c31 --- .../ImageFactoryUnitTests.cs | 82 ++++++++++++++++++- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 7dd09e078..60db9a8ee 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -154,7 +154,43 @@ namespace ImageProcessor.UnitTests { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.GaussianBlur(new Imaging.GaussianLayer() { Sigma = 10, Size = 5, Threshold = 2 }); + imageFactory.GaussianBlur(new Imaging.GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectSharpen() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.GaussianSharpen(5); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectSharpenWithLayer() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.GaussianSharpen(new Imaging.GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); Assert.AreNotEqual(original, imageFactory.Image); } } @@ -228,9 +264,7 @@ namespace ImageProcessor.UnitTests using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); - Assert.AreNotEqual(original, imageFactory.Image); Assert.LessOrEqual(imageFactory.Image.Width, maxSize); Assert.LessOrEqual(imageFactory.Image.Height, maxSize); } @@ -304,5 +338,47 @@ namespace ImageProcessor.UnitTests } } } + + /// + /// Tests that the image is resized + /// + [Test] + public void TestResize() + { + const int newSize = 150; + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + imageFactory.Resize(new System.Drawing.Size(newSize, newSize)); + Assert.AreEqual(newSize, imageFactory.Image.Width); + Assert.AreEqual(newSize, imageFactory.Image.Height); + } + } + } + + /// + /// Tests that the image is resized + /// + [Test] + public void TestResizeWithLayer() + { + const int newSize = 150; + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + imageFactory.Resize(new Imaging.ResizeLayer( + new System.Drawing.Size(newSize, newSize), + Imaging.ResizeMode.Stretch, + Imaging.AnchorPosition.Left, + true)); + Assert.AreEqual(newSize, imageFactory.Image.Width); + Assert.AreEqual(newSize, imageFactory.Image.Height); + } + } + } } } \ No newline at end of file From 683d297dbf427b890063c1bd935794d70a496045 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 00:37:38 +0200 Subject: [PATCH 30/35] Yet a few other unit tests Former-commit-id: bd37755a47b8159d62b6eeb906fe8514ec51aad2 --- .../ImageFactoryUnitTests.cs | 182 ++++++++++++++---- 1 file changed, 146 insertions(+), 36 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 60db9a8ee..d868b2245 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -11,8 +11,8 @@ namespace ImageProcessor.UnitTests { using System; - using System.IO; using System.Collections.Generic; + using System.IO; using NUnit.Framework; /// @@ -21,15 +21,6 @@ namespace ImageProcessor.UnitTests [TestFixture] public class ImageFactoryUnitTests { - /// - /// Lists the input files in the Images folder - /// - /// The list of files. - private static IEnumerable ListInputFiles() - { - return Directory.GetFiles("./Images"); - } - /// /// Tests the loading of image from a file /// @@ -45,10 +36,9 @@ namespace ImageProcessor.UnitTests Assert.IsNotNull(imageFactory.Image); } } - } - /// > + /// /// Tests the loading of image from a memory stream /// [Test] @@ -124,6 +114,84 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectSaturation() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Saturation(50); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectTint() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Tint(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue)); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectVignette() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Vignette(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue)); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectWatermark() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Watermark(new Imaging.TextLayer + { + Font = "Arial", + FontSize = 10, + Position = new System.Drawing.Point(10, 10), + Text = "Lorem ipsum dolor" + }); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + /// /// Tests that a filter is really applied by checking that the image is modified /// @@ -252,21 +320,39 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestRoundedCorners() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.RoundedCorners(new Imaging.RoundedCornerLayer(5, true, true, true, true)); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + /// /// Tests that the image is well resized using constraints /// [Test] public void TestResizeConstraints() { - const int maxSize = 200; + const int MaxSize = 200; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); - Assert.LessOrEqual(imageFactory.Image.Width, maxSize); - Assert.LessOrEqual(imageFactory.Image.Height, maxSize); + imageFactory.Constrain(new System.Drawing.Size(MaxSize, MaxSize)); + Assert.LessOrEqual(imageFactory.Image.Width, MaxSize); + Assert.LessOrEqual(imageFactory.Image.Height, MaxSize); } } } @@ -277,17 +363,17 @@ namespace ImageProcessor.UnitTests [Test] public void TestCrop() { - const int maxSize = 20; + const int MaxSize = 20; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.Crop(new System.Drawing.Rectangle(0, 0, maxSize, maxSize)); + imageFactory.Crop(new System.Drawing.Rectangle(0, 0, MaxSize, MaxSize)); Assert.AreNotEqual(original, imageFactory.Image); - Assert.AreEqual(maxSize, imageFactory.Image.Width); - Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + Assert.AreEqual(MaxSize, imageFactory.Image.Width); + Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); } } } @@ -298,17 +384,17 @@ namespace ImageProcessor.UnitTests [Test] public void TestCropWithCropLayer() { - const int maxSize = 20; + const int MaxSize = 20; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.Crop(new Imaging.CropLayer(0, 0, maxSize, maxSize, Imaging.CropMode.Pixels)); + imageFactory.Crop(new Imaging.CropLayer(0, 0, MaxSize, MaxSize, Imaging.CropMode.Pixels)); Assert.AreNotEqual(original, imageFactory.Image); - Assert.AreEqual(maxSize, imageFactory.Image.Width); - Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + Assert.AreEqual(MaxSize, imageFactory.Image.Width); + Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); } } } @@ -345,15 +431,15 @@ namespace ImageProcessor.UnitTests [Test] public void TestResize() { - const int newSize = 150; + const int NewSize = 150; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - imageFactory.Resize(new System.Drawing.Size(newSize, newSize)); - Assert.AreEqual(newSize, imageFactory.Image.Width); - Assert.AreEqual(newSize, imageFactory.Image.Height); + imageFactory.Resize(new System.Drawing.Size(NewSize, NewSize)); + Assert.AreEqual(NewSize, imageFactory.Image.Width); + Assert.AreEqual(NewSize, imageFactory.Image.Height); } } } @@ -364,21 +450,45 @@ namespace ImageProcessor.UnitTests [Test] public void TestResizeWithLayer() { - const int newSize = 150; + const int NewSize = 150; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - imageFactory.Resize(new Imaging.ResizeLayer( - new System.Drawing.Size(newSize, newSize), - Imaging.ResizeMode.Stretch, - Imaging.AnchorPosition.Left, - true)); - Assert.AreEqual(newSize, imageFactory.Image.Width); - Assert.AreEqual(newSize, imageFactory.Image.Height); + imageFactory.Resize(new Imaging.ResizeLayer(new System.Drawing.Size(NewSize, NewSize), Imaging.ResizeMode.Stretch, Imaging.AnchorPosition.Left)); + Assert.AreEqual(NewSize, imageFactory.Image.Width); + Assert.AreEqual(NewSize, imageFactory.Image.Height); } } } + + /// + /// Tests that the image is resized + /// + [Test] + public void TestRotate() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = (System.Drawing.Image)imageFactory.Image.Clone(); + imageFactory.Rotate(90); + Assert.AreEqual(original.Height, imageFactory.Image.Width); + Assert.AreEqual(original.Width, imageFactory.Image.Height); + } + } + } + + /// + /// Lists the input files in the Images folder + /// + /// The list of files. + private static IEnumerable ListInputFiles() + { + return Directory.GetFiles("./Images"); + } } } \ No newline at end of file From 892818bcfc0caa850f9e4999c59e6c126d577d55 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 00:41:53 +0200 Subject: [PATCH 31/35] Adds tests for saving the files Former-commit-id: bab7f1273663d36a546e323f680cac1d7c622284 --- .../ImageFactoryUnitTests.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index d868b2245..880871cc7 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -60,6 +60,45 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that the save method actually saves a file + /// + [Test] + public void TestSaveToDisk() + { + foreach (var fileName in ListInputFiles()) + { + var outputFileName = string.Format("./output/{0}", Path.GetFileName(fileName)); + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + imageFactory.Save(outputFileName); + Assert.AreEqual(true, File.Exists(outputFileName)); + } + } + } + + /// + /// Tests that the save method actually writes to memory + /// + [Test] + public void TestSaveToMemory() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + using (var s = new MemoryStream()) + { + imageFactory.Save(s); + s.Seek(0, SeekOrigin.Begin); + Assert.AreEqual(true, s.Capacity > 0); + } + } + } + } + /// /// Tests that a filter is really applied by checking that the image is modified /// From c516908062ff743f4b4a2c9b6f820bb73ddc4283 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 11:09:25 +0200 Subject: [PATCH 32/35] Removes unnecessary images Former-commit-id: 2b75ccda89d49667260a2d21b0c5ea7754107f3a --- .../Images/Chrysanthemum.jpg.REMOVED.git-id | 1 - src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id | 1 - src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id | 1 - src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id | 1 - src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id | 1 - 5 files changed, 5 deletions(-) delete mode 100644 src/ImageProcessor.UnitTests/Images/Chrysanthemum.jpg.REMOVED.git-id delete mode 100644 src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id delete mode 100644 src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id delete mode 100644 src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id delete mode 100644 src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id diff --git a/src/ImageProcessor.UnitTests/Images/Chrysanthemum.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/Chrysanthemum.jpg.REMOVED.git-id deleted file mode 100644 index d067665c9..000000000 --- a/src/ImageProcessor.UnitTests/Images/Chrysanthemum.jpg.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -757c2a628dd03b1cbe4b3ef07c153897a702b57a \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id deleted file mode 100644 index 228aac3ab..000000000 --- a/src/ImageProcessor.UnitTests/Images/Desert.jpg.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -0b88c91336ff8073f34d21ccd683a01f0e0995da \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id deleted file mode 100644 index 74f69293c..000000000 --- a/src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -8150b46ab27c62ba51aaba551eef3f1a30f08de9 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id deleted file mode 100644 index ce873d473..000000000 --- a/src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -6ad3b846d4697584ff601ac481b14a4d3bbb5736 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id deleted file mode 100644 index aeca7b93c..000000000 --- a/src/ImageProcessor.UnitTests/Images/cmyk.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -db4d55a332254cd6b41336c06f207682bf5a966f \ No newline at end of file From 3ff7de32ffd718496bdddc3cdb5b801ead3277ab Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 11:33:05 +0200 Subject: [PATCH 33/35] Filters the source images a bit, in order to speed up the unit tests + descriptive name Former-commit-id: bcdb5097fee49ef671a3150815e1a7b4f11721fd --- .../ImageProcessor.UnitTests.csproj | 24 +++++++++++++++++++ .../Images/autorotate.jpg.REMOVED.git-id | 1 + .../cmyk-profile-euroscale.jpg.REMOVED.git-id | 1 + .../Images/cmyk.jpg.REMOVED.git-id | 1 + .../color-vision-test.gif.REMOVED.git-id | 1 + .../Images/exif-Tulips.jpg.REMOVED.git-id | 1 + .../Images/exif-rocks.jpg.REMOVED.git-id | 1 + .../format-Penguins-8bit.png.REMOVED.git-id | 1 + .../Images/format-Penguins.bmp.REMOVED.git-id | 1 + .../Images/format-Penguins.gif.REMOVED.git-id | 1 + .../Images/format-Penguins.jpg.REMOVED.git-id | 1 + .../Images/format-Penguins.png.REMOVED.git-id | 1 + .../Images/format-Penguins.tif.REMOVED.git-id | 1 + .../Images/format-animated.gif | 3 +++ .../Images/hi-color.png | 3 +++ .../Images/hi-contrast.jpg | 3 +++ .../Images/hi-saturation.jpg | 3 +++ .../profile-adobe-rgb.jpg.REMOVED.git-id | 1 + .../Images/profile-srgb.jpg.REMOVED.git-id | 1 + .../Images/size-Penguins-200.jpg | 3 +++ .../Images/text-over-transparent.png | 3 +++ .../Images/udendørs.jpg.REMOVED.git-id | 1 + 22 files changed, 57 insertions(+) create mode 100644 src/ImageProcessor.UnitTests/Images/autorotate.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/cmyk-profile-euroscale.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/cmyk.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/exif-Tulips.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/exif-rocks.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins-8bit.png.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.png.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-Penguins.tif.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/format-animated.gif create mode 100644 src/ImageProcessor.UnitTests/Images/hi-color.png create mode 100644 src/ImageProcessor.UnitTests/Images/hi-contrast.jpg create mode 100644 src/ImageProcessor.UnitTests/Images/hi-saturation.jpg create mode 100644 src/ImageProcessor.UnitTests/Images/profile-adobe-rgb.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/profile-srgb.jpg.REMOVED.git-id create mode 100644 src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg create mode 100644 src/ImageProcessor.UnitTests/Images/text-over-transparent.png create mode 100644 src/ImageProcessor.UnitTests/Images/udendørs.jpg.REMOVED.git-id diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index c0311d476..4d47bb062 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -308,6 +308,27 @@ Images\udendørs.jpg PreserveNewest + + + + + + + + + + + + + + + + + + + + + @@ -317,4 +338,7 @@ + + + \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/autorotate.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/autorotate.jpg.REMOVED.git-id new file mode 100644 index 000000000..19785c8e5 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/autorotate.jpg.REMOVED.git-id @@ -0,0 +1 @@ +85a8ae18f9955def2b42ba9240bce4de1bfe5781 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/cmyk-profile-euroscale.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/cmyk-profile-euroscale.jpg.REMOVED.git-id new file mode 100644 index 000000000..7747bdaae --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/cmyk-profile-euroscale.jpg.REMOVED.git-id @@ -0,0 +1 @@ +13492524f9d984c12adfe6183a4c1d92fb11ec4e \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/cmyk.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/cmyk.jpg.REMOVED.git-id new file mode 100644 index 000000000..30b05146b --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/cmyk.jpg.REMOVED.git-id @@ -0,0 +1 @@ +ed725726e4ac1ffeac821664af14865a66fa933f \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id new file mode 100644 index 000000000..5c4f4195d --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id @@ -0,0 +1 @@ +35a926115b13b61dc37308f8d903b42d14f92924 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/exif-Tulips.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/exif-Tulips.jpg.REMOVED.git-id new file mode 100644 index 000000000..84b9aff85 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/exif-Tulips.jpg.REMOVED.git-id @@ -0,0 +1 @@ +54c51eb6a86f31a42433b8167470fb18dad32c7d \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/exif-rocks.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/exif-rocks.jpg.REMOVED.git-id new file mode 100644 index 000000000..41c6c25df --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/exif-rocks.jpg.REMOVED.git-id @@ -0,0 +1 @@ +33b6912af301bf216ee81d82b2c3ce6c49e03021 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins-8bit.png.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins-8bit.png.REMOVED.git-id new file mode 100644 index 000000000..aa9a70e0f --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins-8bit.png.REMOVED.git-id @@ -0,0 +1 @@ +c3d556d9d486b8b8b49cdbcc9c12a9d3a2db4c1f \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id new file mode 100644 index 000000000..74f69293c --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id @@ -0,0 +1 @@ +8150b46ab27c62ba51aaba551eef3f1a30f08de9 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id new file mode 100644 index 000000000..ce873d473 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id @@ -0,0 +1 @@ +6ad3b846d4697584ff601ac481b14a4d3bbb5736 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.jpg.REMOVED.git-id new file mode 100644 index 000000000..ad4371113 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.jpg.REMOVED.git-id @@ -0,0 +1 @@ +030ab8a685bebb796c24cc710edd9e69859164f6 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.png.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.png.REMOVED.git-id new file mode 100644 index 000000000..78062a0e7 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.png.REMOVED.git-id @@ -0,0 +1 @@ +a2c796fbb7de948230a22982ab74892891dd5198 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-Penguins.tif.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.tif.REMOVED.git-id new file mode 100644 index 000000000..5f7b97e71 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-Penguins.tif.REMOVED.git-id @@ -0,0 +1 @@ +c789aaec248568c24394b05c02db4233e0c5a4eb \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/format-animated.gif b/src/ImageProcessor.UnitTests/Images/format-animated.gif new file mode 100644 index 000000000..ac36f6f25 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/format-animated.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6212724b3e94908939823d0753b4307923b65d7a27f51823dd3ba7656543349c +size 22525 diff --git a/src/ImageProcessor.UnitTests/Images/hi-color.png b/src/ImageProcessor.UnitTests/Images/hi-color.png new file mode 100644 index 000000000..a9de4cc09 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/hi-color.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:977cc9071257655c9923d267ea5bd417b69754367c2f1aa8765247b68e2bb878 +size 1539 diff --git a/src/ImageProcessor.UnitTests/Images/hi-contrast.jpg b/src/ImageProcessor.UnitTests/Images/hi-contrast.jpg new file mode 100644 index 000000000..98ac863a2 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/hi-contrast.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0ce9e02f2a4663a0a0ed433d5594be87b3fa0387bc8335e80f84d59c34aa424 +size 51058 diff --git a/src/ImageProcessor.UnitTests/Images/hi-saturation.jpg b/src/ImageProcessor.UnitTests/Images/hi-saturation.jpg new file mode 100644 index 000000000..b56f9a83c --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/hi-saturation.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b2012b2eda13a531645c287c254ae5de0e9070368cb4bc806f48314e0464ccd +size 33850 diff --git a/src/ImageProcessor.UnitTests/Images/profile-adobe-rgb.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/profile-adobe-rgb.jpg.REMOVED.git-id new file mode 100644 index 000000000..4ffbf7a8a --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/profile-adobe-rgb.jpg.REMOVED.git-id @@ -0,0 +1 @@ +e29f32091aa13a5b047ccd960f3dc6da9656c84b \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/profile-srgb.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/profile-srgb.jpg.REMOVED.git-id new file mode 100644 index 000000000..f409bc82b --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/profile-srgb.jpg.REMOVED.git-id @@ -0,0 +1 @@ +ab9deaa737f9db9bf0f563e7843ba9b7981cec86 \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg b/src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg new file mode 100644 index 000000000..07605996f --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:672de68017f17260126901065f1c6ade2b2981d33dea0dea1606bf7cfb6fdcf3 +size 10119 diff --git a/src/ImageProcessor.UnitTests/Images/text-over-transparent.png b/src/ImageProcessor.UnitTests/Images/text-over-transparent.png new file mode 100644 index 000000000..33d4962bc --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/text-over-transparent.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2322d8dd81df86b8135d399743ea758ad26d6b2ccdcc704e2687ae72d0c187e7 +size 7317 diff --git a/src/ImageProcessor.UnitTests/Images/udendørs.jpg.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/udendørs.jpg.REMOVED.git-id new file mode 100644 index 000000000..0db1445a2 --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/udendørs.jpg.REMOVED.git-id @@ -0,0 +1 @@ +4d040d9aa3519b3d2303419d1f03eebebf88e956 \ No newline at end of file From 3ff3807e15c539590b1f76de863805ec0826f393 Mon Sep 17 00:00:00 2001 From: James South Date: Sun, 29 Jun 2014 11:53:20 +0100 Subject: [PATCH 34/35] Fixing tests to work on Windows. Former-commit-id: 23664e1cac0916c0cc493769b7f9ebe0de78e981 --- build/Build.bat | 2 +- .../ImageFactoryUnitTests.cs | 248 ++++++++++-------- .../ImageProcessor.UnitTests.csproj | 6 +- src/ImageProcessor/ImageFactory.cs | 4 +- .../Imaging/Formats/FormatUtilities.cs | 2 +- 5 files changed, 147 insertions(+), 115 deletions(-) diff --git a/build/Build.bat b/build/Build.bat index 513d111e3..21c4eb0a4 100644 --- a/build/Build.bat +++ b/build/Build.bat @@ -20,7 +20,7 @@ ECHO Packing the NuGet release files ..\src\.nuget\NuGet.exe pack NuSpecs\ImageProcessor.nuspec -Version %version% ..\src\.nuget\NuGet.exe pack NuSpecs\ImageProcessor.Web.nuspec -Version %webversion% ..\src\.nuget\NuGet.exe pack NuSpecs\ImageProcessor.Web.Config.nuspec -Version %webconfigversion% - +PAUSE IF ERRORLEVEL 1 GOTO :showerror diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 880871cc7..c5f569a39 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -12,7 +12,9 @@ namespace ImageProcessor.UnitTests { using System; using System.Collections.Generic; + using System.Drawing; using System.IO; + using System.Linq; using NUnit.Framework; /// @@ -21,18 +23,23 @@ namespace ImageProcessor.UnitTests [TestFixture] public class ImageFactoryUnitTests { + /// + /// The list of images. Designed to speed up the tests a little. + /// + private IEnumerable images; + /// /// Tests the loading of image from a file /// [Test] public void TestLoadImageFromFile() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - Assert.AreEqual(fileName, imageFactory.ImagePath); + imageFactory.Load(file.FullName); + Assert.AreEqual(file.FullName, imageFactory.ImagePath); Assert.IsNotNull(imageFactory.Image); } } @@ -44,13 +51,13 @@ namespace ImageProcessor.UnitTests [Test] public void TestLoadImageFromMemory() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - byte[] photoBytes = File.ReadAllBytes(fileName); + byte[] photoBytes = File.ReadAllBytes(file.FullName); - using (var inStream = new MemoryStream(photoBytes)) + using (MemoryStream inStream = new MemoryStream(photoBytes)) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { imageFactory.Load(inStream); Assert.AreEqual(null, imageFactory.ImagePath); @@ -66,12 +73,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestSaveToDisk() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - var outputFileName = string.Format("./output/{0}", Path.GetFileName(fileName)); - using (var imageFactory = new ImageFactory()) + string outputFileName = string.Format("./output/{0}", file.Name); + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); + imageFactory.Load(file.FullName); imageFactory.Save(outputFileName); Assert.AreEqual(true, File.Exists(outputFileName)); } @@ -84,12 +91,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestSaveToMemory() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - using (var s = new MemoryStream()) + imageFactory.Load(file.FullName); + using (MemoryStream s = new MemoryStream()) { imageFactory.Save(s); s.Seek(0, SeekOrigin.Begin); @@ -105,12 +112,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectAlpha() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.Alpha(50); Assert.AreNotEqual(original, imageFactory.Image); } @@ -123,12 +130,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectBrightness() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.Brightness(50); Assert.AreNotEqual(original, imageFactory.Image); } @@ -141,12 +148,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectContrast() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.Contrast(50); Assert.AreNotEqual(original, imageFactory.Image); } @@ -159,12 +166,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectSaturation() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.Saturation(50); Assert.AreNotEqual(original, imageFactory.Image); } @@ -177,13 +184,13 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectTint() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); - imageFactory.Tint(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue)); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.Tint(Color.FromKnownColor(KnownColor.AliceBlue)); Assert.AreNotEqual(original, imageFactory.Image); } } @@ -195,13 +202,13 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectVignette() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); - imageFactory.Vignette(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue)); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.Vignette(Color.FromKnownColor(KnownColor.AliceBlue)); Assert.AreNotEqual(original, imageFactory.Image); } } @@ -213,19 +220,19 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectWatermark() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.Watermark(new Imaging.TextLayer - { - Font = "Arial", - FontSize = 10, - Position = new System.Drawing.Point(10, 10), - Text = "Lorem ipsum dolor" - }); + { + Font = "Arial", + FontSize = 10, + Position = new Point(10, 10), + Text = "Lorem ipsum dolor" + }); Assert.AreNotEqual(original, imageFactory.Image); } } @@ -237,12 +244,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectBlur() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.GaussianBlur(5); Assert.AreNotEqual(original, imageFactory.Image); } @@ -255,12 +262,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectBlurWithLayer() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.GaussianBlur(new Imaging.GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); Assert.AreNotEqual(original, imageFactory.Image); } @@ -273,12 +280,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectSharpen() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.GaussianSharpen(5); Assert.AreNotEqual(original, imageFactory.Image); } @@ -291,12 +298,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectSharpenWithLayer() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.GaussianSharpen(new Imaging.GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); Assert.AreNotEqual(original, imageFactory.Image); } @@ -309,12 +316,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestApplyEffectFilter() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.Filter(Imaging.Filters.MatrixFilters.BlackWhite); Assert.AreNotEqual(original, imageFactory.Image); @@ -365,12 +372,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestRoundedCorners() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.RoundedCorners(new Imaging.RoundedCornerLayer(5, true, true, true, true)); Assert.AreNotEqual(original, imageFactory.Image); } @@ -384,12 +391,12 @@ namespace ImageProcessor.UnitTests public void TestResizeConstraints() { const int MaxSize = 200; - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - imageFactory.Constrain(new System.Drawing.Size(MaxSize, MaxSize)); + imageFactory.Load(file.FullName); + imageFactory.Constrain(new Size(MaxSize, MaxSize)); Assert.LessOrEqual(imageFactory.Image.Width, MaxSize); Assert.LessOrEqual(imageFactory.Image.Height, MaxSize); } @@ -403,13 +410,13 @@ namespace ImageProcessor.UnitTests public void TestCrop() { const int MaxSize = 20; - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); - imageFactory.Crop(new System.Drawing.Rectangle(0, 0, MaxSize, MaxSize)); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.Crop(new Rectangle(0, 0, MaxSize, MaxSize)); Assert.AreNotEqual(original, imageFactory.Image); Assert.AreEqual(MaxSize, imageFactory.Image.Width); Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); @@ -424,12 +431,12 @@ namespace ImageProcessor.UnitTests public void TestCropWithCropLayer() { const int MaxSize = 20; - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.Crop(new Imaging.CropLayer(0, 0, MaxSize, MaxSize, Imaging.CropMode.Pixels)); Assert.AreNotEqual(original, imageFactory.Image); Assert.AreEqual(MaxSize, imageFactory.Image.Width); @@ -444,12 +451,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestFlip() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = (System.Drawing.Image)imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.Flip(true); Assert.AreNotEqual(original, imageFactory.Image); Assert.AreEqual(original.Width, imageFactory.Image.Width); @@ -471,12 +478,12 @@ namespace ImageProcessor.UnitTests public void TestResize() { const int NewSize = 150; - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - imageFactory.Resize(new System.Drawing.Size(NewSize, NewSize)); + imageFactory.Load(file.FullName); + imageFactory.Resize(new Size(NewSize, NewSize)); Assert.AreEqual(NewSize, imageFactory.Image.Width); Assert.AreEqual(NewSize, imageFactory.Image.Height); } @@ -490,12 +497,12 @@ namespace ImageProcessor.UnitTests public void TestResizeWithLayer() { const int NewSize = 150; - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - imageFactory.Resize(new Imaging.ResizeLayer(new System.Drawing.Size(NewSize, NewSize), Imaging.ResizeMode.Stretch, Imaging.AnchorPosition.Left)); + imageFactory.Load(file.FullName); + imageFactory.Resize(new Imaging.ResizeLayer(new Size(NewSize, NewSize), Imaging.ResizeMode.Stretch, Imaging.AnchorPosition.Left)); Assert.AreEqual(NewSize, imageFactory.Image.Width); Assert.AreEqual(NewSize, imageFactory.Image.Height); } @@ -508,12 +515,12 @@ namespace ImageProcessor.UnitTests [Test] public void TestRotate() { - foreach (var fileName in ListInputFiles()) + foreach (FileInfo file in this.ListInputFiles()) { - using (var imageFactory = new ImageFactory()) + using (ImageFactory imageFactory = new ImageFactory()) { - imageFactory.Load(fileName); - var original = (System.Drawing.Image)imageFactory.Image.Clone(); + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); imageFactory.Rotate(90); Assert.AreEqual(original.Height, imageFactory.Image.Width); Assert.AreEqual(original.Width, imageFactory.Image.Height); @@ -521,13 +528,40 @@ namespace ImageProcessor.UnitTests } } + /// + /// Gets the files matching the given extensions. + /// + /// The . + /// The extensions. + /// A collection of + /// The extensions variable is null. + private static IEnumerable GetFilesByExtensions(DirectoryInfo dir, params string[] extensions) + { + if (extensions == null) + { + throw new ArgumentNullException("extensions"); + } + + IEnumerable files = dir.EnumerateFiles(); + return files.Where(f => extensions.Contains(f.Extension, StringComparer.OrdinalIgnoreCase)); + } + /// /// Lists the input files in the Images folder /// /// The list of files. - private static IEnumerable ListInputFiles() + private IEnumerable ListInputFiles() { - return Directory.GetFiles("./Images"); + if (this.images != null) + { + return this.images; + } + + DirectoryInfo directoryInfo = new DirectoryInfo("./Images"); + + this.images = GetFilesByExtensions(directoryInfo, new[] { ".jpg", ".jpeg", ".png", ".gif", ".tiff", ".bmp", ".webp" }); + + return this.images; } } } \ No newline at end of file diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 4d47bb062..b020e2858 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - {03CA9055-F997-428C-BF28-F50F991777C6} + {633B1C4C-4823-47BE-9A01-A665F3118C8C} Library ImageProcessor.UnitTests ImageProcessor.UnitTests @@ -338,7 +338,5 @@ - - - + \ No newline at end of file diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 4a68a5e86..03e92fdde 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -183,7 +183,7 @@ namespace ImageProcessor this.ImagePath = imagePath; // Open a file stream to prevent the need for lock. - using (var fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read)) + using (FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read)) { ISupportedImageFormat format = FormatUtilities.GetFormat(fileStream); @@ -192,7 +192,7 @@ namespace ImageProcessor throw new ImageFormatException("Input stream is not a supported format."); } - var memoryStream = new MemoryStream(); + MemoryStream memoryStream = new MemoryStream(); // Copy the stream. fileStream.CopyTo(memoryStream); diff --git a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs index 3c6e3b3e0..3ee8cf6cb 100644 --- a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs +++ b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs @@ -142,7 +142,7 @@ namespace ImageProcessor.Imaging.Formats // GDI returns a single array with all delays, while Mono returns a different array for each frame image.SelectActiveFrame(frameDimension, i); var times = image.GetPropertyItem(20736).Value; - int thisDelay = BitConverter.ToInt32(times, 4*i % times.Length); + int thisDelay = BitConverter.ToInt32(times, (4 * i) % times.Length); int toAddDelay = thisDelay * 10 < 20 ? 20 : thisDelay * 10; // Minimum delay is 20 ms // Find the frame From 4d2b42d66fcb9c153859abe6f52d7627efb11d5b Mon Sep 17 00:00:00 2001 From: James South Date: Sun, 29 Jun 2014 12:35:41 +0100 Subject: [PATCH 35/35] fixing unit test project file. Former-commit-id: b3947dcf2bd94e7f2b96dc4c5f952e072e7f46ff --- .../ImageProcessor.UnitTests.csproj | 349 +++--------------- 1 file changed, 57 insertions(+), 292 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index b020e2858..4cc93cb0f 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -1,336 +1,95 @@  - + Debug AnyCPU {633B1C4C-4823-47BE-9A01-A665F3118C8C} Library + Properties ImageProcessor.UnitTests ImageProcessor.UnitTests - - + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest ..\ true - v4.5 + true full false - bin\Debug - DEBUG; + bin\Debug\ + DEBUG;TRACE prompt 4 - false - false - full + pdbonly true - bin\Release + bin\Release\ + TRACE prompt 4 - false - false - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll - - + + + + + + + + + + - - - - - {D011A778-59C8-4BFA-A770-C350216BF161} - ImageProcessor.Web_NET45 - - - {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E} - ImageProcessor - + - - - - - - - - - - Images\1182076_e8c402e938_z.jpg - - - Images\bus.jpg - - - Images\Chrysanthemum.jpg - - - Images\circle.png - - - Images\cmyk.jpg - - - Images\cmyk.png - - - Images\color-vision-test.gif - - - Images\Desert.jpg - - - Images\emma.jpg - - - Images\falahill_design__160p.jpg - - - Images\fid11246.jpg - - - Images\fid9141.jpg - - - Images\header_1.jpg - - - Images\Hydrangeas.jpg - - - Images\Jellyfish.jpg - - - Images\jrt.jpg - - - Images\Koala.jpg - - - Images\Lighthouse.jpg - - - Images\lomo.jpg - - - Images\meter.gif - - - Images\negative.png - - - Images\negative2.png - - - Images\Penguins-200.jpg - - - Images\Penguins-8.png - - - Images\Penguins.bmp - - - Images\Penguins.gif - - - Images\Penguins.jpg - - - Images\Penguins.png - - - Images\Penguins.tif - - - Images\rocks.jpg - - - Images\rotate.jpg - - - Images\sample1.jpg - - - Images\srgb.jpg - - - Images\srgb.png - - - Images\text.png - - - Images\thor.jpg - - - Images\Tulips.jpg - - - Images\udendørs-374.jpg - - - Images\udendørs.jpg - - - Images\war_horse_quad.jpg - - - Images\WP_000009.jpg - - {3b5dd734-fb7a-487d-8ce6-55e7af9aea7e} ImageProcessor - - - - Images\Chrysanthemum.jpg - PreserveNewest - - - Images\Desert.jpg - PreserveNewest - - - Images\Hydrangeas.jpg - PreserveNewest - - - Images\Jellyfish.jpg - PreserveNewest - - - Images\Koala.jpg - PreserveNewest - - - Images\Lighthouse.jpg - PreserveNewest - - - Images\Penguins-8.png - PreserveNewest - - - Images\Penguins.bmp - PreserveNewest - - - Images\Penguins.gif - PreserveNewest - - - Images\Penguins.jpg - PreserveNewest - - - Images\Penguins.png - PreserveNewest - - - Images\Penguins.tif - PreserveNewest - - - Images\Tulips.jpg - PreserveNewest - - - Images\bus.jpg - PreserveNewest - - - Images\cmyk.jpg - PreserveNewest - - - Images\cmyk.png - PreserveNewest - - - Images\jrt.jpg - PreserveNewest - - - Images\meter.gif - PreserveNewest - - - Images\rocks.jpg - PreserveNewest - - - Images\rotate.jpg - PreserveNewest - - - Images\sample1.jpg - PreserveNewest - - - Images\srgb.jpg - PreserveNewest - - - Images\srgb.png - PreserveNewest - - - Images\text.png - PreserveNewest - - - Images\thor.jpg - PreserveNewest - - - Images\udendørs-374.jpg - PreserveNewest - - - Images\udendørs.jpg - PreserveNewest - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + + @@ -338,5 +97,11 @@ - + \ No newline at end of file