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 a63f95ff2..c5f569a39 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -11,7 +11,10 @@ namespace ImageProcessor.UnitTests { using System; + using System.Collections.Generic; + using System.Drawing; using System.IO; + using System.Linq; using NUnit.Framework; /// @@ -21,35 +24,544 @@ namespace ImageProcessor.UnitTests public class ImageFactoryUnitTests { /// - /// The path to the binary's folder + /// The list of images. Designed to speed up the tests a little. /// - private readonly string localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); + private IEnumerable 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 (FileInfo file in this.ListInputFiles()) { - imageFactory.Load(testPhoto); - Assert.AreEqual(testPhoto, imageFactory.ImagePath); - Assert.AreEqual(expectedMime, imageFactory.CurrentImageFormat.MimeType); - Assert.IsNotNull(imageFactory.Image); + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Assert.AreEqual(file.FullName, imageFactory.ImagePath); + Assert.IsNotNull(imageFactory.Image); + } } } + + /// + /// Tests the loading of image from a memory stream + /// + [Test] + public void TestLoadImageFromMemory() + { + foreach (FileInfo file in this.ListInputFiles()) + { + byte[] photoBytes = File.ReadAllBytes(file.FullName); + + using (MemoryStream inStream = new MemoryStream(photoBytes)) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(inStream); + Assert.AreEqual(null, imageFactory.ImagePath); + Assert.IsNotNull(imageFactory.Image); + } + } + } + } + + /// + /// Tests that the save method actually saves a file + /// + [Test] + public void TestSaveToDisk() + { + foreach (FileInfo file in this.ListInputFiles()) + { + string outputFileName = string.Format("./output/{0}", file.Name); + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + imageFactory.Save(outputFileName); + Assert.AreEqual(true, File.Exists(outputFileName)); + } + } + } + + /// + /// Tests that the save method actually writes to memory + /// + [Test] + public void TestSaveToMemory() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + using (MemoryStream 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 + /// + [Test] + public void TestApplyEffectAlpha() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.Alpha(50); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectBrightness() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.Brightness(50); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectContrast() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.Contrast(50); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectSaturation() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)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 (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.Tint(Color.FromKnownColor(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 (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.Vignette(Color.FromKnownColor(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 (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.Watermark(new Imaging.TextLayer + { + Font = "Arial", + FontSize = 10, + Position = new 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 + /// + [Test] + public void TestApplyEffectBlur() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)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 (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + 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); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectSharpen() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)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 (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + 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); + } + } + } + + /// + /// Tests that all filters can be applied + /// + [Test] + public void TestApplyEffectFilter() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + Image original = (Image)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 a filter is really applied by checking that the image is modified + /// + [Test] + public void TestRoundedCorners() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + 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); + } + } + } + + /// + /// Tests that the image is well resized using constraints + /// + [Test] + public void TestResizeConstraints() + { + const int MaxSize = 200; + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + imageFactory.Constrain(new Size(MaxSize, MaxSize)); + Assert.LessOrEqual(imageFactory.Image.Width, MaxSize); + Assert.LessOrEqual(imageFactory.Image.Height, MaxSize); + } + } + } + + /// + /// Tests that the image is well cropped + /// + [Test] + public void TestCrop() + { + const int MaxSize = 20; + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + 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); + } + } + } + + /// + /// Tests that the image is well cropped + /// + [Test] + public void TestCropWithCropLayer() + { + const int MaxSize = 20; + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + 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); + Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); + } + } + } + + /// + /// Tests that the image is flipped + /// + [Test] + public void TestFlip() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + 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); + 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); + } + } + } + + /// + /// Tests that the image is resized + /// + [Test] + public void TestResize() + { + const int NewSize = 150; + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + imageFactory.Load(file.FullName); + imageFactory.Resize(new 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 (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + 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); + } + } + } + + /// + /// Tests that the image is resized + /// + [Test] + public void TestRotate() + { + foreach (FileInfo file in this.ListInputFiles()) + { + using (ImageFactory imageFactory = new ImageFactory()) + { + 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); + } + } + } + + /// + /// 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 IEnumerable ListInputFiles() + { + 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 81516b4b6..c872dbbb8 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -1,98 +1,124 @@  - + 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;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 - - - - - - - - - - - - - - + + - + + PreserveNewest + + - {3b5dd734-fb7a-487d-8ce6-55e7af9aea7e} + {3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E} ImageProcessor - - - - - - + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + - - - - - False - - - False - - - False - - - False - - - - - - + @@ -100,11 +126,5 @@ - + \ No newline at end of file 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/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/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 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/Penguins.bmp.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id similarity index 100% rename from src/ImageProcessor.UnitTests/Images/Penguins.bmp.REMOVED.git-id rename to src/ImageProcessor.UnitTests/Images/format-Penguins.bmp.REMOVED.git-id diff --git a/src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id b/src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id similarity index 100% rename from src/ImageProcessor.UnitTests/Images/Penguins.gif.REMOVED.git-id rename to src/ImageProcessor.UnitTests/Images/format-Penguins.gif.REMOVED.git-id 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 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(); diff --git a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs index 36d2e3c07..3ee8cf6cb 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; 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