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
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
@ -80,7 +78,7 @@ namespace ImageSharp
return Orientation.Unknown;
}
Orientation orientation = (Orientation)value.Value;
var orientation = (Orientation)value.Value;
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.
// </copyright>
namespace ImageSharp.Tests
namespace ImageSharp.Tests.Processing.Transforms
{
using System.IO;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class AutoOrientTests : FileTestBase
{
public static readonly string[] FlipFiles = { TestImages.Bmp.F };
public static readonly TheoryData<RotateType, FlipType, ushort> OrientationValues
= new TheoryData<RotateType, FlipType, ushort>
{
@ -29,23 +29,19 @@ namespace ImageSharp.Tests
};
[Theory]
[MemberData(nameof(OrientationValues))]
public void ImageShouldFlip(RotateType rotateType, FlipType flipType, ushort orientation)
[WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), StandardPixelType)]
public void ImageShouldAutoRotate<TPixel>(TestImageProvider<TPixel> provider, RotateType rotateType, FlipType flipType, ushort orientation)
where TPixel : struct, IPixel<TPixel>
{
string path = this.CreateOutputDirectory("AutoOrient");
TestFile file = TestFile.Create(TestImages.Bmp.F);
using (Image<Rgba32> image = file.CreateImage())
using (Image<TPixel> image = provider.GetImage())
{
image.MetaData.ExifProfile = new ExifProfile();
image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation);
using (FileStream before = File.OpenWrite($"{path}/before-{file.FileName}"))
using (FileStream after = File.OpenWrite($"{path}/after-{file.FileName}"))
{
image.RotateFlip(rotateType, flipType).Save(before).AutoOrient().Save(after);
}
image.RotateFlip(rotateType, flipType)
.DebugSave(provider, "before", Extensions.Bmp)
.AutoOrient()
.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="settings">The settings</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>
{
if (bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCi) && isCi)
{
return;
return image;
}
// 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);
return image;
}
}
}

Loading…
Cancel
Save