Browse Source

AutoOrient

pull/232/head
James Jackson-South 9 years ago
parent
commit
f24863fa66
  1. 4
      src/ImageSharp/Processing/Transforms/AutoOrient.cs
  2. 28
      tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs
  3. 5
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

4
src/ImageSharp/Processing/Transforms/AutoOrient.cs

@ -5,12 +5,10 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using ImageSharp.PixelFormats; using ImageSharp.PixelFormats;
using ImageSharp.Processing; using ImageSharp.Processing;
using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
@ -80,7 +78,7 @@ namespace ImageSharp
return Orientation.Unknown; return Orientation.Unknown;
} }
Orientation orientation = (Orientation)value.Value; var orientation = (Orientation)value.Value;
source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft); source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft);

28
tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs → tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs

@ -3,17 +3,17 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Tests namespace ImageSharp.Tests.Processing.Transforms
{ {
using System.IO;
using ImageSharp.PixelFormats; using ImageSharp.PixelFormats;
using ImageSharp.Processing; using ImageSharp.Processing;
using Xunit; using Xunit;
public class AutoOrientTests : FileTestBase public class AutoOrientTests : FileTestBase
{ {
public static readonly string[] FlipFiles = { TestImages.Bmp.F };
public static readonly TheoryData<RotateType, FlipType, ushort> OrientationValues public static readonly TheoryData<RotateType, FlipType, ushort> OrientationValues
= new TheoryData<RotateType, FlipType, ushort> = new TheoryData<RotateType, FlipType, ushort>
{ {
@ -29,23 +29,19 @@ namespace ImageSharp.Tests
}; };
[Theory] [Theory]
[MemberData(nameof(OrientationValues))] [WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), StandardPixelType)]
public void ImageShouldFlip(RotateType rotateType, FlipType flipType, ushort orientation) public void ImageShouldAutoRotate<TPixel>(TestImageProvider<TPixel> provider, RotateType rotateType, FlipType flipType, ushort orientation)
where TPixel : struct, IPixel<TPixel>
{ {
string path = this.CreateOutputDirectory("AutoOrient"); using (Image<TPixel> image = provider.GetImage())
TestFile file = TestFile.Create(TestImages.Bmp.F);
using (Image<Rgba32> image = file.CreateImage())
{ {
image.MetaData.ExifProfile = new ExifProfile(); image.MetaData.ExifProfile = new ExifProfile();
image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation); image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation);
using (FileStream before = File.OpenWrite($"{path}/before-{file.FileName}")) image.RotateFlip(rotateType, flipType)
using (FileStream after = File.OpenWrite($"{path}/after-{file.FileName}")) .DebugSave(provider, "before", Extensions.Bmp)
{ .AutoOrient()
image.RotateFlip(rotateType, flipType).Save(before).AutoOrient().Save(after); .DebugSave(provider, "after", Extensions.Bmp);
}
} }
} }
} }

5
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -22,12 +22,12 @@ namespace ImageSharp.Tests
/// <param name="provider">The image provider</param> /// <param name="provider">The image provider</param>
/// <param name="settings">The settings</param> /// <param name="settings">The settings</param>
/// <param name="extension">The extension</param> /// <param name="extension">The extension</param>
public static void DebugSave<TPixel>(this Image<TPixel> image, ITestImageProvider provider, object settings = null, string extension = "png") public static Image<TPixel> DebugSave<TPixel>(this Image<TPixel> image, ITestImageProvider provider, object settings = null, string extension = "png")
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
if (bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCi) && isCi) if (bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCi) && isCi)
{ {
return; return image;
} }
// We are running locally then we want to save it out // We are running locally then we want to save it out
@ -55,6 +55,7 @@ namespace ImageSharp.Tests
} }
provider.Utility.SaveTestOutputFile(image, extension, tag: tag); provider.Utility.SaveTestOutputFile(image, extension, tag: tag);
return image;
} }
} }
} }

Loading…
Cancel
Save