From 47962f177a119f98f57f4cb6b0ef55a1ed948012 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Thu, 26 Feb 2015 14:09:06 +0100 Subject: [PATCH 1/5] Saves the output of the imagefactory tests to check the results Former-commit-id: 7d87f6fb1f0653b5e321a6b29f52991793206df1 Former-commit-id: 9b2be9184156b0e276c948e696ebdb5e4b63a69c --- .../ImageFactoryUnitTests.cs | 85 ++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 847c639048..70907280be 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -122,16 +122,18 @@ namespace ImageProcessor.UnitTests [Test] public void AlphaIsModified() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.Alpha(50); - AssertionHelpers.AssertImagesAreDifferent( original, imageFactory.Image, "because the alpha operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/alpha-" + i++.ToString() + ".jpg"); } } @@ -141,11 +143,14 @@ namespace ImageProcessor.UnitTests [Test] public void BrightnessIsModified() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.Brightness(50); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the brightness operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/brightness-" + i++.ToString() + ".jpg"); } } @@ -168,11 +173,14 @@ namespace ImageProcessor.UnitTests [Test] public void ContrastIsModified() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.Contrast(50); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the contrast operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/contrast-" + i++.ToString() + ".jpg"); } } @@ -182,11 +190,14 @@ namespace ImageProcessor.UnitTests [Test] public void SaturationIsModified() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.Saturation(50); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the saturation operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/saturation-" + i++.ToString() + ".jpg"); } } @@ -196,11 +207,14 @@ namespace ImageProcessor.UnitTests [Test] public void TintIsModified() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.Tint(Color.FromKnownColor(KnownColor.AliceBlue)); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the tint operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/tint-" + i++.ToString() + ".jpg"); } } @@ -210,11 +224,14 @@ namespace ImageProcessor.UnitTests [Test] public void VignetteEffectIsApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.Vignette(Color.FromKnownColor(KnownColor.AliceBlue)); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the vignette operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/vignette-" + i++.ToString() + ".jpg"); } } @@ -224,6 +241,7 @@ namespace ImageProcessor.UnitTests [Test] public void WatermarkIsApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); @@ -235,6 +253,8 @@ namespace ImageProcessor.UnitTests Text = "Lorem ipsum dolor" }); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the watermark operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/watermark-" + i++.ToString() + ".jpg"); } } @@ -244,11 +264,14 @@ namespace ImageProcessor.UnitTests [Test] public void BlurEffectIsApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.GaussianBlur(5); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the blur operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/blur-" + i++.ToString() + ".jpg"); } } @@ -258,11 +281,14 @@ namespace ImageProcessor.UnitTests [Test] public void BlurWithLayerIsApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.GaussianBlur(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the layered blur operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/blurlayer-" + i++.ToString() + ".jpg"); } } @@ -272,11 +298,14 @@ namespace ImageProcessor.UnitTests [Test] public void SharpenEffectIsApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.GaussianSharpen(5); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the sharpen operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/sharpen-" + i++.ToString() + ".jpg"); } } @@ -286,11 +315,14 @@ namespace ImageProcessor.UnitTests [Test] public void SharpenWithLayerIsApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.GaussianSharpen(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the layered sharpen operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/sharpenlayer-" + i++.ToString() + ".jpg"); } } @@ -300,6 +332,7 @@ namespace ImageProcessor.UnitTests [Test] public void FilterIsApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); @@ -318,12 +351,15 @@ namespace ImageProcessor.UnitTests MatrixFilters.Sepia }; + int j = 0; foreach (IMatrixFilter filter in filters) { imageFactory.Filter(filter); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/filter-" + j++.ToString() + "-image-" + i++.ToString() + ".jpg"); } } } @@ -334,11 +370,14 @@ namespace ImageProcessor.UnitTests [Test] public void RoundedCornersAreApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.RoundedCorners(new RoundedCornerLayer(5)); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the rounded corners operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/roundedcorners-" + i++.ToString() + ".jpg"); } } @@ -348,12 +387,15 @@ namespace ImageProcessor.UnitTests [Test] public void ImageIsResizedWithinConstraints() { + int i = 0; const int MaxSize = 200; foreach (ImageFactory imageFactory in this.ListInputImages()) { imageFactory.Constrain(new Size(MaxSize, MaxSize)); imageFactory.Image.Width.Should().BeLessOrEqualTo(MaxSize, "because the image size should have been reduced"); imageFactory.Image.Height.Should().BeLessOrEqualTo(MaxSize, "because the image size should have been reduced"); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/resizedcontraints-" + i++.ToString() + ".jpg"); } } @@ -363,6 +405,7 @@ namespace ImageProcessor.UnitTests [Test] public void ImageIsCropped() { + int i = 0; const int MaxSize = 20; foreach (ImageFactory imageFactory in this.ListInputImages()) { @@ -372,6 +415,8 @@ namespace ImageProcessor.UnitTests imageFactory.Image.Width.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize); imageFactory.Image.Height.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/crop-" + i++.ToString() + ".jpg"); } } @@ -381,6 +426,7 @@ namespace ImageProcessor.UnitTests [Test] public void ImageIsCroppedWithLayer() { + int i = 0; const int MaxSize = 20; foreach (ImageFactory imageFactory in this.ListInputImages()) { @@ -390,6 +436,8 @@ namespace ImageProcessor.UnitTests imageFactory.Image.Width.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize); imageFactory.Image.Height.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/croplayer-" + i++.ToString() + ".jpg"); } } @@ -399,6 +447,7 @@ namespace ImageProcessor.UnitTests [Test] public void ImageIsFlipped() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); @@ -413,6 +462,8 @@ namespace ImageProcessor.UnitTests AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the horizontal flip operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Image.Width.Should().Be(original.Width, "because the dimensions should not have changed"); imageFactory.Image.Height.Should().Be(original.Height, "because the dimensions should not have changed"); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/flip-" + i++.ToString() + ".jpg"); } } @@ -422,6 +473,7 @@ namespace ImageProcessor.UnitTests [Test] public void ImageIsResized() { + int i = 0; const int NewSize = 150; foreach (ImageFactory imageFactory in this.ListInputImages()) { @@ -429,6 +481,8 @@ namespace ImageProcessor.UnitTests imageFactory.Image.Width.Should().Be(NewSize, "because the new image's size should be {0}x{0}", NewSize); imageFactory.Image.Height.Should().Be(NewSize, "because the new image's size should be {0}x{0}", NewSize); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/resized-" + i++.ToString() + ".jpg"); } } @@ -438,6 +492,7 @@ namespace ImageProcessor.UnitTests [Test] public void ImageIsResizedWithLayer() { + int i = 0; const int NewSize = 150; foreach (ImageFactory imageFactory in this.ListInputImages()) { @@ -445,6 +500,8 @@ namespace ImageProcessor.UnitTests imageFactory.Image.Width.Should().Be(NewSize, "because the new image's size should be {0}x{0}", NewSize); imageFactory.Image.Height.Should().Be(NewSize, "because the new image's size should be {0}x{0}", NewSize); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/resizedlayer-" + i++.ToString() + ".jpg"); } } @@ -454,6 +511,7 @@ namespace ImageProcessor.UnitTests [Test] public void ImageIsRotated() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); @@ -461,6 +519,8 @@ namespace ImageProcessor.UnitTests imageFactory.Image.Width.Should().Be(original.Height, "because the rotated image dimensions should have been switched"); imageFactory.Image.Height.Should().Be(original.Width, "because the rotated image dimensions should have been switched"); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/rotated-" + i++.ToString() + ".jpg"); } } @@ -470,6 +530,7 @@ namespace ImageProcessor.UnitTests [Test] public void ImageIsRotatedInside() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); @@ -477,6 +538,10 @@ namespace ImageProcessor.UnitTests imageFactory.Image.Width.Should().Be(original.Width, "because the rotated image dimensions should not have changed"); imageFactory.Image.Height.Should().Be(original.Height, "because the rotated image dimensions should not have changed"); + + AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the inside image should have been rotated on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/rotatebounded-" + i++.ToString() + ".jpg"); } } @@ -486,6 +551,7 @@ namespace ImageProcessor.UnitTests [Test] public void ImageIsRotatedInsideAndResized() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); @@ -493,6 +559,10 @@ namespace ImageProcessor.UnitTests imageFactory.Image.Width.Should().NotBe(original.Width, "because the rotated image dimensions should have changed"); imageFactory.Image.Height.Should().NotBe(original.Height, "because the rotated image dimensions should have changed"); + + AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the inside image should have been rotated on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/rotateboundedresized-" + i++.ToString() + ".jpg"); } } @@ -502,6 +572,7 @@ namespace ImageProcessor.UnitTests [Test] public void HueIsModified() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); @@ -513,6 +584,8 @@ namespace ImageProcessor.UnitTests imageFactory.Hue(116, true); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the hue+rotate operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/hue-" + i++.ToString() + ".jpg"); } } @@ -522,11 +595,14 @@ namespace ImageProcessor.UnitTests [Test] public void PixelateEffectIsApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.Pixelate(8); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the pixelate operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/pixelate-" + i++.ToString() + ".jpg"); } } @@ -552,11 +628,14 @@ namespace ImageProcessor.UnitTests [Test] public void ColorIsReplaced() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); imageFactory.ReplaceColor(Color.White, Color.Black, 90); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the color replace operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/colorreplace-" + i++.ToString() + ".jpg"); } } @@ -566,6 +645,7 @@ namespace ImageProcessor.UnitTests [Test] public void EdgeDetectionEffectIsApplied() { + int i = 0; foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); @@ -583,12 +663,15 @@ namespace ImageProcessor.UnitTests new SobelEdgeFilter() }; + int j = 0; foreach (IEdgeFilter filter in filters) { imageFactory.DetectEdges(filter); AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/edgefilter-" + j++.ToString() + "-image-" + i++.ToString() + ".jpg"); } } } From 874a229b6ddf011e65f2543fadc47bb9dddeb723 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Thu, 26 Feb 2015 14:16:15 +0100 Subject: [PATCH 2/5] Adds strecthed test image Former-commit-id: e7dd960547bb07f434b999865c7d89a4455e1d49 Former-commit-id: c9f3278e7792e7ab0185f455fefa42516dde8d86 --- src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs | 8 ++++++-- .../ImageProcessor.UnitTests.csproj | 3 +++ src/ImageProcessor.UnitTests/Images/stretched.jpg | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/ImageProcessor.UnitTests/Images/stretched.jpg diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 70907280be..12abc9e046 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -359,8 +359,10 @@ namespace ImageProcessor.UnitTests imageFactory.Reset(); AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); - imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/filter-" + j++.ToString() + "-image-" + i++.ToString() + ".jpg"); + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/filter-" + j++.ToString() + "-image-" + i.ToString() + ".jpg"); } + + i++; } } @@ -671,8 +673,10 @@ namespace ImageProcessor.UnitTests imageFactory.Reset(); AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); - imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/edgefilter-" + j++.ToString() + "-image-" + i++.ToString() + ".jpg"); + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/edgefilter-" + j++.ToString() + "-image-" + i.ToString() + ".jpg"); } + + i++; } } diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 1d808f9637..f7a94845a2 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -134,6 +134,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/src/ImageProcessor.UnitTests/Images/stretched.jpg b/src/ImageProcessor.UnitTests/Images/stretched.jpg new file mode 100644 index 0000000000..8e7f73148a --- /dev/null +++ b/src/ImageProcessor.UnitTests/Images/stretched.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1444d3336f0f04126c31850ff9dd89205bd7a553f7d4d1eb1df406fb6c344fa3 +size 32300 From 2f28fe5311a2317373e9298a83be58457adde8a2 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Thu, 26 Feb 2015 14:25:32 +0100 Subject: [PATCH 3/5] Adds failing tests for negative angle Former-commit-id: 68d80544153a5baa6b61d41716f5c7e4a11a2c3e Former-commit-id: f2bb2e2df8e7b47bfede287328cf64c66fdf7542 --- .../Imaging/Helpers/ImageMathsUnitTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ImageProcessor.UnitTests/Imaging/Helpers/ImageMathsUnitTests.cs b/src/ImageProcessor.UnitTests/Imaging/Helpers/ImageMathsUnitTests.cs index 3e1ffdfb36..f8d56fd545 100644 --- a/src/ImageProcessor.UnitTests/Imaging/Helpers/ImageMathsUnitTests.cs +++ b/src/ImageProcessor.UnitTests/Imaging/Helpers/ImageMathsUnitTests.cs @@ -22,6 +22,7 @@ [TestCase(100, 100, 45, 141, 141)] [TestCase(100, 100, 30, 137, 137)] [TestCase(100, 200, 50, 217, 205)] + [TestCase(100, 200, -50, 217, 205)] public void BoundingRotatedRectangleIsCalculated(int width, int height, float angle, int expectedWidth, int expectedHeight) { Rectangle result = ImageMaths.GetBoundingRotatedRectangle(width, height, angle); @@ -44,11 +45,16 @@ [TestCase(200, 100, 45, 2.12f)] [TestCase(600, 450, 20, 1.39f)] [TestCase(600, 450, 45, 1.64f)] + [TestCase(100, 200, -45, 1.22f)] public void RotationZoomIsCalculated(int imageWidth, int imageHeight, float angle, float expected) { float result = ImageMaths.ZoomAfterRotation(imageWidth, imageHeight, angle); result.Should().BeApproximately(expected, 0.01f, "because the zoom level after rotation should have been calculated"); + + result.Should().BePositive("because we're always zooming in so the zoom level should always be positive"); + + result.Should().BeGreaterOrEqualTo(1, "because the zoom should always increase the size and not reduce it"); } } } \ No newline at end of file From 8395a1c2bd02804e4db9770ca59d2a4918d3594d Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Thu, 26 Feb 2015 14:53:36 +0100 Subject: [PATCH 4/5] Adds imagefactory unit test for counter-clockwise rotation Former-commit-id: 7a4859a397c53aebb3701e5d9bee8f53984eeade Former-commit-id: 57d54f8e7906ad2f12cf5e1420c1b54e587cad33 --- .../ImageFactoryUnitTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 12abc9e046..ac3f9cdb66 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -547,6 +547,27 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that the image's inside is rotated counter-clockwise + /// + [Test] + public void ImageIsRotatedInsideCounterClockwise() + { + int i = 0; + foreach (ImageFactory imageFactory in this.ListInputImages()) + { + Image original = (Image)imageFactory.Image.Clone(); + imageFactory.RotateBounded(-45, true); + + imageFactory.Image.Width.Should().Be(original.Width, "because the rotated image dimensions should not have changed"); + imageFactory.Image.Height.Should().Be(original.Height, "because the rotated image dimensions should not have changed"); + + AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the inside image should have been rotated on {0}", imageFactory.ImagePath); + + imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/rotateboundedccw-" + i++.ToString() + ".jpg"); + } + } + /// /// Tests that the image's inside is rotated and resized /// From 819090c22b5351e5fe1966856cae33fa99db1496 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Thu, 26 Feb 2015 15:14:32 +0100 Subject: [PATCH 5/5] Fixes the CCW rotation bug Former-commit-id: a345ee7057e77842cd18a9ce193d768c0049f53e Former-commit-id: f12f641601310783f14f14621c088fb627b79a2e --- src/ImageProcessor/Imaging/Helpers/ImageMaths.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageProcessor/Imaging/Helpers/ImageMaths.cs b/src/ImageProcessor/Imaging/Helpers/ImageMaths.cs index d232198409..f8ebc5d909 100644 --- a/src/ImageProcessor/Imaging/Helpers/ImageMaths.cs +++ b/src/ImageProcessor/Imaging/Helpers/ImageMaths.cs @@ -316,7 +316,7 @@ namespace ImageProcessor.Imaging.Helpers /// The zoom needed public static float ZoomAfterRotation(int imageWidth, int imageHeight, float angleInDegrees) { - double radians = DegreesToRadians(angleInDegrees); + double radians = Math.Abs(DegreesToRadians(angleInDegrees)); double radiansSin = Math.Sin(radians); double radiansCos = Math.Cos(radians);