diff --git a/src/ImageProcessorCore/Filters/BinaryThreshold.cs b/src/ImageProcessorCore/Filters/BinaryThreshold.cs new file mode 100644 index 000000000..5d244ead4 --- /dev/null +++ b/src/ImageProcessorCore/Filters/BinaryThreshold.cs @@ -0,0 +1,60 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore +{ + using Processors; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Applies binerization to the image splitting the pixels at the given threshold. + /// + /// The pixel format. + /// The packed format. long, float. + /// The image this method extends. + /// The threshold to apply binerization of the image. Must be between 0 and 1. + /// A delegate which is called as progress is made processing the image. + /// The . + public static Image BinaryThreshold(this Image source, float threshold, ProgressEventHandler progressHandler = null) + where T : IPackedVector + where TP : struct + { + return BinaryThreshold(source, threshold, source.Bounds, progressHandler); + } + + /// + /// Applies binerization to the image splitting the pixels at the given threshold. + /// + /// The pixel format. + /// The packed format. long, float. + /// The image this method extends. + /// The threshold to apply binerization of the image. Must be between 0 and 1. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// A delegate which is called as progress is made processing the image. + /// The . + public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle, ProgressEventHandler progressHandler = null) + where T : IPackedVector + where TP : struct + { + BinaryThresholdProcessor processor = new BinaryThresholdProcessor(threshold); + processor.OnProgress += progressHandler; + + try + { + return source.Process(rectangle, processor); + } + finally + { + processor.OnProgress -= progressHandler; + } + } + } +} diff --git a/src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs similarity index 86% rename from src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs rename to src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs index 38e32415d..78da97f11 100644 --- a/src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs +++ b/src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -14,7 +14,7 @@ namespace ImageProcessorCore.Processors /// /// The pixel format. /// The packed format. long, float. - public class ThresholdProcessor : ImageProcessor + public class BinaryThresholdProcessor : ImageProcessor where T : IPackedVector where TP : struct { @@ -25,13 +25,19 @@ namespace ImageProcessorCore.Processors /// /// is less than 0 or is greater than 1. /// - public ThresholdProcessor(float threshold) + public BinaryThresholdProcessor(float threshold) { // TODO: Check limit. Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold)); this.Value = threshold; - this.UpperColor.PackVector(Color.White.ToVector4()); - this.LowerColor.PackVector(Color.Black.ToVector4()); + + T upper = default(T); + upper.PackVector(Color.White.ToVector4()); + this.UpperColor = upper; + + T lower = default(T); + lower.PackVector(Color.Black.ToVector4()); + this.LowerColor = lower; } /// @@ -58,6 +64,9 @@ namespace ImageProcessorCore.Processors /// protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { + // target.SetPixels(source.Width, source.Height, source.Pixels); + + float threshold = this.Value; T upper = this.UpperColor; T lower = this.LowerColor; diff --git a/src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs index 29afff11a..6cd7726c9 100644 --- a/src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs @@ -48,7 +48,7 @@ namespace ImageProcessorCore.Processors new SobelProcessor().Apply(temp, source, sourceRectangle); // Apply threshold binarization filter. - new ThresholdProcessor(.5f).Apply(temp, temp, sourceRectangle); + new BinaryThresholdProcessor(.5f).Apply(temp, temp, sourceRectangle); // Search for the first white pixels Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0); diff --git a/tests/ImageProcessorCore.Tests/Processors/Filters/BinaryThreshold.cs b/tests/ImageProcessorCore.Tests/Processors/Filters/BinaryThreshold.cs new file mode 100644 index 000000000..1dcc28d70 --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Filters/BinaryThreshold.cs @@ -0,0 +1,47 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Tests +{ + using System.IO; + + using Xunit; + + public class BinaryThresholdTest : FileTestBase + { + public static readonly TheoryData BinaryThresholdValues + = new TheoryData + { + .25f , + .75f , + }; + + [Theory] + [MemberData("BinaryThresholdValues")] + public void ImageShouldApplyBinaryThresholdFilter(float value) + { + const string path = "TestOutput/BinaryThreshold"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + string filename = Path.GetFileNameWithoutExtension(file) + "-" + value + Path.GetExtension(file); + + Image image = new Image(stream); + using (FileStream output = File.OpenWrite($"{path}/{filename}")) + { + image.BinaryThreshold(value) + .Save(output); + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/CropTest.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/CropTest.cs new file mode 100644 index 000000000..a92d0feb0 --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/CropTest.cs @@ -0,0 +1,38 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Tests +{ + using System.IO; + + using Xunit; + + public class CropTest : FileTestBase + { + [Fact] + public void ImageShouldApplyCropSampler() + { + const string path = "TestOutput/Crop"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + string filename = Path.GetFileName(file); + Image image = new Image(stream); + using (FileStream output = File.OpenWrite($"{path}/{filename}")) + { + image.Crop(image.Width / 2, image.Height / 2, this.ProgressUpdate) + .Save(output); + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/EntropyCropTest.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/EntropyCropTest.cs new file mode 100644 index 000000000..a1de08990 --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/EntropyCropTest.cs @@ -0,0 +1,47 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Tests +{ + using System.IO; + + using Xunit; + + public class EntropyCropTest : FileTestBase + { + public static readonly TheoryData EntropyCropValues + = new TheoryData + { + .25f , + .75f , + }; + + [Theory] + [MemberData("EntropyCropValues")] + public void ImageShouldApplyEntropyCropSampler(float value) + { + const string path = "TestOutput/EntropyCrop"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + string filename = Path.GetFileNameWithoutExtension(file) + "-" + value + Path.GetExtension(file); + + Image image = new Image(stream); + using (FileStream output = File.OpenWrite($"{path}/{filename}")) + { + image.EntropyCrop(value) + .Save(output); + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/PadTest.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/PadTest.cs new file mode 100644 index 000000000..8a70b0887 --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/PadTest.cs @@ -0,0 +1,38 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Tests +{ + using System.IO; + + using Xunit; + + public class PadTest : FileTestBase + { + [Fact] + public void ImageShouldApplyPadSampler() + { + const string path = "TestOutput/Pad"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + string filename = Path.GetFileName(file); + Image image = new Image(stream); + using (FileStream output = File.OpenWrite($"{path}/{filename}")) + { + image.Pad(image.Width + 50, image.Height + 50, this.ProgressUpdate) + .Save(output); + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/ResizeTests.cs similarity index 51% rename from tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs rename to tests/ImageProcessorCore.Tests/Processors/Samplers/ResizeTests.cs index 0cb8ff025..dbd36bee7 100644 --- a/tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/ResizeTests.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -9,8 +9,10 @@ namespace ImageProcessorCore.Tests using Xunit; - public class SamplerTests : FileTestBase + public class ResizeTests : FileTestBase { + private const string path = "TestOutput/Resize"; + public static readonly TheoryData ReSamplers = new TheoryData { @@ -31,46 +33,13 @@ namespace ImageProcessorCore.Tests //{ "Welch", new WelchResampler() } }; - public static readonly TheoryData RotateFlips = new TheoryData - { - { RotateType.None, FlipType.Vertical }, - { RotateType.None, FlipType.Horizontal }, - { RotateType.Rotate90, FlipType.None }, - { RotateType.Rotate180, FlipType.None }, - { RotateType.Rotate270, FlipType.None }, - }; - - [Fact] - public void ImageShouldPad() - { - if (!Directory.Exists("TestOutput/Pad")) - { - Directory.CreateDirectory("TestOutput/Pad"); - } - - foreach (string file in Files) - { - using (FileStream stream = File.OpenRead(file)) - { - string filename = Path.GetFileName(file); - - Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/Pad/{filename}")) - { - image.Pad(image.Width + 50, image.Height + 50, this.ProgressUpdate) - .Save(output); - } - } - } - } - [Theory] [MemberData("ReSamplers")] public void ImageShouldResize(string name, IResampler sampler) { - if (!Directory.Exists("TestOutput/Resize")) + if (!Directory.Exists(path)) { - Directory.CreateDirectory("TestOutput/Resize"); + Directory.CreateDirectory(path); } foreach (string file in Files) @@ -80,7 +49,7 @@ namespace ImageProcessorCore.Tests string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}")) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Resize(image.Width / 2, image.Height / 2, sampler, false, this.ProgressUpdate) .Save(output); @@ -92,13 +61,13 @@ namespace ImageProcessorCore.Tests [Fact] public void ImageShouldResizeWidthAndKeepAspect() { - if (!Directory.Exists("TestOutput/Resize")) + const string name = "FixedWidth"; + + if (!Directory.Exists(path)) { - Directory.CreateDirectory("TestOutput/Resize"); + Directory.CreateDirectory(path); } - var name = "FixedWidth"; - foreach (string file in Files) { using (FileStream stream = File.OpenRead(file)) @@ -106,7 +75,7 @@ namespace ImageProcessorCore.Tests string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}")) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Resize(image.Width / 3, 0, new TriangleResampler(), false, this.ProgressUpdate) .Save(output); @@ -118,13 +87,13 @@ namespace ImageProcessorCore.Tests [Fact] public void ImageShouldResizeHeightAndKeepAspect() { - if (!Directory.Exists("TestOutput/Resize")) + const string name = "FixedHeight"; + + if (!Directory.Exists(path)) { - Directory.CreateDirectory("TestOutput/Resize"); + Directory.CreateDirectory(path); } - string name = "FixedHeight"; - foreach (string file in Files) { using (FileStream stream = File.OpenRead(file)) @@ -132,7 +101,7 @@ namespace ImageProcessorCore.Tests string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}")) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { image.Resize(0, image.Height / 3, new TriangleResampler(), false, this.ProgressUpdate) .Save(output); @@ -144,19 +113,21 @@ namespace ImageProcessorCore.Tests [Fact] public void ImageShouldResizeWithCropMode() { - if (!Directory.Exists("TestOutput/ResizeCrop")) + const string name = "Crop"; + + if (!Directory.Exists(path)) { - Directory.CreateDirectory("TestOutput/ResizeCrop"); + Directory.CreateDirectory(path); } foreach (string file in Files) { using (FileStream stream = File.OpenRead(file)) { - string filename = Path.GetFileName(file); + string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/ResizeCrop/{filename}")) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions() { @@ -173,19 +144,21 @@ namespace ImageProcessorCore.Tests [Fact] public void ImageShouldResizeWithPadMode() { - if (!Directory.Exists("TestOutput/ResizePad")) + const string name = "Pad"; + + if (!Directory.Exists(path)) { - Directory.CreateDirectory("TestOutput/ResizePad"); + Directory.CreateDirectory(path); } foreach (string file in Files) { using (FileStream stream = File.OpenRead(file)) { - string filename = Path.GetFileName(file); + string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/ResizePad/{filename}")) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions() { @@ -203,19 +176,21 @@ namespace ImageProcessorCore.Tests [Fact] public void ImageShouldResizeWithBoxPadMode() { - if (!Directory.Exists("TestOutput/ResizeBoxPad")) + const string name = "BoxPad"; + + if (!Directory.Exists(path)) { - Directory.CreateDirectory("TestOutput/ResizeBoxPad"); + Directory.CreateDirectory(path); } foreach (string file in Files) { using (FileStream stream = File.OpenRead(file)) { - string filename = Path.GetFileName(file); + string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/ResizeBoxPad/{filename}")) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions() { @@ -233,25 +208,26 @@ namespace ImageProcessorCore.Tests [Fact] public void ImageShouldResizeWithMaxMode() { - if (!Directory.Exists("TestOutput/ResizeMax")) + const string name = "Max"; + + if (!Directory.Exists(path)) { - Directory.CreateDirectory("TestOutput/ResizeMax"); + Directory.CreateDirectory(path); } foreach (string file in Files) { using (FileStream stream = File.OpenRead(file)) { - string filename = Path.GetFileName(file); + string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/ResizeMax/{filename}")) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions() { Size = new Size(300, 300), - Mode = ResizeMode.Max, - //Sampler = new NearestNeighborResampler() + Mode = ResizeMode.Max }; image.Resize(options, this.ProgressUpdate) @@ -264,19 +240,21 @@ namespace ImageProcessorCore.Tests [Fact] public void ImageShouldResizeWithMinMode() { - if (!Directory.Exists("TestOutput/ResizeMin")) + const string name = "Min"; + + if (!Directory.Exists(path)) { - Directory.CreateDirectory("TestOutput/ResizeMin"); + Directory.CreateDirectory(path); } foreach (string file in Files) { using (FileStream stream = File.OpenRead(file)) { - string filename = Path.GetFileName(file); + string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/ResizeMin/{filename}")) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions() { @@ -294,19 +272,21 @@ namespace ImageProcessorCore.Tests [Fact] public void ImageShouldResizeWithStretchMode() { - if (!Directory.Exists("TestOutput/ResizeStretch")) + const string name = "Stretch"; + + if (!Directory.Exists(path)) { - Directory.CreateDirectory("TestOutput/ResizeStretch"); + Directory.CreateDirectory(path); } foreach (string file in Files) { using (FileStream stream = File.OpenRead(file)) { - string filename = Path.GetFileName(file); + string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file); Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/ResizeStretch/{filename}")) + using (FileStream output = File.OpenWrite($"{path}/{filename}")) { ResizeOptions options = new ResizeOptions() { @@ -321,158 +301,6 @@ namespace ImageProcessorCore.Tests } } - //[Fact] - //public void ImageShouldNotDispose() - //{ - // if (!Directory.Exists("TestOutput/Dispose")) - // { - // Directory.CreateDirectory("TestOutput/Dispose"); - // } - - // foreach (string file in Files) - // { - // using (FileStream stream = File.OpenRead(file)) - // { - // string filename = Path.GetFileName(file); - - // Image image = new Image(stream); - // image = image.BackgroundColor(Color.RebeccaPurple); - // using (FileStream output = File.OpenWrite($"TestOutput/Dispose/{filename}")) - // { - // ResizeOptions options = new ResizeOptions() - // { - // Size = new Size(image.Width - 10, image.Height), - // Mode = ResizeMode.Stretch - // }; - - // image.Resize(options, this.ProgressUpdate) - // .Save(output); - // } - // } - // } - //} - - [Theory] - [MemberData("RotateFlips")] - public void ImageShouldRotateFlip(RotateType rotateType, FlipType flipType) - { - if (!Directory.Exists("TestOutput/RotateFlip")) - { - Directory.CreateDirectory("TestOutput/RotateFlip"); - } - - foreach (string file in Files) - { - using (FileStream stream = File.OpenRead(file)) - { - string filename = Path.GetFileNameWithoutExtension(file) + "-" + rotateType + flipType + Path.GetExtension(file); - - Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/RotateFlip/{filename}")) - { - image.RotateFlip(rotateType, flipType, this.ProgressUpdate) - .Save(output); - } - } - } - } - - [Fact] - public void ImageShouldRotate() - { - if (!Directory.Exists("TestOutput/Rotate")) - { - Directory.CreateDirectory("TestOutput/Rotate"); - } - - foreach (string file in Files) - { - using (FileStream stream = File.OpenRead(file)) - { - string filename = Path.GetFileName(file); - - Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/Rotate/{filename}")) - { - image.Rotate(-170, this.ProgressUpdate) - .Save(output); - } - } - } - } - - [Fact] - public void ImageShouldSkew() - { - if (!Directory.Exists("TestOutput/Skew")) - { - Directory.CreateDirectory("TestOutput/Skew"); - } - - // Matches live example http://www.w3schools.com/css/tryit.asp?filename=trycss3_transform_skew - foreach (string file in Files) - { - using (FileStream stream = File.OpenRead(file)) - { - string filename = Path.GetFileName(file); - - Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/Skew/{filename}")) - { - image.Skew(-20, -10, this.ProgressUpdate) - .Save(output); - } - } - } - } - - [Fact] - public void ImageShouldEntropyCrop() - { - if (!Directory.Exists("TestOutput/EntropyCrop")) - { - Directory.CreateDirectory("TestOutput/EntropyCrop"); - } - - foreach (string file in Files) - { - using (FileStream stream = File.OpenRead(file)) - { - string filename = Path.GetFileNameWithoutExtension(file) + "-EntropyCrop" + Path.GetExtension(file); - - Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/EntropyCrop/{filename}")) - { - image.EntropyCrop(.5f, this.ProgressUpdate).Save(output); - } - } - } - } - - [Fact] - public void ImageShouldCrop() - { - if (!Directory.Exists("TestOutput/Crop")) - { - Directory.CreateDirectory("TestOutput/Crop"); - } - - foreach (string file in Files) - { - using (FileStream stream = File.OpenRead(file)) - { - - string filename = Path.GetFileNameWithoutExtension(file) + "-Crop" + Path.GetExtension(file); - - Image image = new Image(stream); - using (FileStream output = File.OpenWrite($"TestOutput/Crop/{filename}")) - { - image.Crop(image.Width / 2, image.Height / 2, this.ProgressUpdate).Save(output); - } - } - } - } - [Theory] [InlineData(-2, 0)] [InlineData(-1, 0)] diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/RotateFlipTest.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/RotateFlipTest.cs new file mode 100644 index 000000000..72fcfb7b9 --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/RotateFlipTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Tests +{ + using System.IO; + + using Xunit; + + public class RotateFlipTest : FileTestBase + { + public static readonly TheoryData RotateFlipValues + = new TheoryData + { + { RotateType.None, FlipType.Vertical }, + { RotateType.None, FlipType.Horizontal }, + { RotateType.Rotate90, FlipType.None }, + { RotateType.Rotate180, FlipType.None }, + { RotateType.Rotate270, FlipType.None }, + }; + + [Theory] + [MemberData("RotateFlipValues")] + public void ImageShouldRotateFlip(RotateType rotateType, FlipType flipType) + { + const string path = "TestOutput/RotateFlip"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + string filename = Path.GetFileNameWithoutExtension(file) + "-" + rotateType + flipType + Path.GetExtension(file); + + Image image = new Image(stream); + using (FileStream output = File.OpenWrite($"{path}/{filename}")) + { + image.RotateFlip(rotateType, flipType, this.ProgressUpdate) + .Save(output); + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/RotateTest.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/RotateTest.cs new file mode 100644 index 000000000..7b38656b1 --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/RotateTest.cs @@ -0,0 +1,47 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Tests +{ + using System.IO; + + using Xunit; + + public class RotateTest : FileTestBase + { + public static readonly TheoryData RotateValues + = new TheoryData + { + 170 , + -170 , + }; + + [Theory] + [MemberData("RotateValues")] + public void ImageShouldApplyRotateSampler(float value) + { + const string path = "TestOutput/Rotate"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + string filename = Path.GetFileNameWithoutExtension(file) + "-" + value + Path.GetExtension(file); + + Image image = new Image(stream); + using (FileStream output = File.OpenWrite($"{path}/{filename}")) + { + image.Rotate(value) + .Save(output); + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/SkewTest.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/SkewTest.cs new file mode 100644 index 000000000..4a0c77cfe --- /dev/null +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/SkewTest.cs @@ -0,0 +1,49 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Tests +{ + using System.IO; + + using Xunit; + + public class SkewTest : FileTestBase + { + public static readonly TheoryData SkewValues + = new TheoryData + { + { 20, 10 }, + { -20, -10 } + }; + + [Theory] + [MemberData("SkewValues")] + public void ImageShouldApplySkewSampler(float x, float y) + { + const string path = "TestOutput/Skew"; + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + // Matches live example + // http://www.w3schools.com/css/tryit.asp?filename=trycss3_transform_skew + foreach (string file in Files) + { + using (FileStream stream = File.OpenRead(file)) + { + string filename = Path.GetFileNameWithoutExtension(file) + "-" + x + "-" + y + Path.GetExtension(file); + + Image image = new Image(stream); + using (FileStream output = File.OpenWrite($"{path}/{filename}")) + { + image.Skew(x, y) + .Save(output); + } + } + } + } + } +} \ No newline at end of file