diff --git a/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs
index f18eb80926..3a4eb31aee 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs
@@ -93,7 +93,16 @@ namespace ImageSharp.Processing.Processors
return Orientation.Unknown;
}
- var orientation = (Orientation)value.Value;
+ Orientation orientation;
+ if (value.DataType == ExifDataType.Short)
+ {
+ orientation = (Orientation)value.Value;
+ }
+ else
+ {
+ orientation = (Orientation)Convert.ToUInt16(value.Value);
+ source.MetaData.ExifProfile.RemoveValue(ExifTag.Orientation);
+ }
source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft);
diff --git a/src/ImageSharp/Processing/Transforms/AutoOrient.cs b/src/ImageSharp/Processing/Transforms/AutoOrient.cs
index fb7bfb4ac7..6f7d1b665c 100644
--- a/src/ImageSharp/Processing/Transforms/AutoOrient.cs
+++ b/src/ImageSharp/Processing/Transforms/AutoOrient.cs
@@ -5,6 +5,7 @@
namespace ImageSharp
{
+ using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
index ae17f3698d..b9124afc6a 100644
--- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
+++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
@@ -18,7 +18,7 @@
-
+
diff --git a/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs b/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs
index 2a5462b40f..da58ddcda8 100644
--- a/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs
+++ b/tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs
@@ -3,6 +3,7 @@
// Licensed under the Apache License, Version 2.0.
//
+// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests.Colorspaces
{
using System;
@@ -141,7 +142,7 @@ namespace ImageSharp.Tests.Colorspaces
[Theory]
[MemberData(nameof(EmptyData))]
- public void Equality(IColorVector color)
+ public void Vector_Equals_WhenTrue(IColorVector color)
{
// Act
bool equal = color.Vector.Equals(Vector3.Zero);
@@ -152,7 +153,7 @@ namespace ImageSharp.Tests.Colorspaces
[Theory]
[MemberData(nameof(EqualityData))]
- public void Equality(object first, object second, Type type)
+ public void Equals_WhenTrue(object first, object second, Type type)
{
// Act
bool equal = first.Equals(second);
@@ -165,7 +166,7 @@ namespace ImageSharp.Tests.Colorspaces
[MemberData(nameof(NotEqualityDataNulls))]
[MemberData(nameof(NotEqualityDataDifferentObjects))]
[MemberData(nameof(NotEqualityData))]
- public void NotEquality(object first, object second, Type type)
+ public void Equals_WhenFalse(object first, object second, Type type)
{
// Act
bool equal = first.Equals(second);
@@ -176,7 +177,7 @@ namespace ImageSharp.Tests.Colorspaces
[Theory]
[MemberData(nameof(EqualityData))]
- public void HashCodeEqual(object first, object second, Type type)
+ public void GetHashCode_WhenEqual(object first, object second, Type type)
{
// Act
bool equal = first.GetHashCode() == second.GetHashCode();
@@ -187,7 +188,7 @@ namespace ImageSharp.Tests.Colorspaces
[Theory]
[MemberData(nameof(NotEqualityDataDifferentObjects))]
- public void HashCodeNotEqual(object first, object second, Type type)
+ public void GetHashCode_WhenNotEqual(object first, object second, Type type)
{
// Act
bool equal = first.GetHashCode() == second.GetHashCode();
@@ -198,7 +199,7 @@ namespace ImageSharp.Tests.Colorspaces
[Theory]
[MemberData(nameof(EqualityData))]
- public void EqualityObject(object first, object second, Type type)
+ public void GenericEquals_WhenTrue(object first, object second, Type type)
{
// Arrange
// Cast to the known object types, this is so that we can hit the
@@ -216,7 +217,7 @@ namespace ImageSharp.Tests.Colorspaces
[Theory]
[MemberData(nameof(NotEqualityData))]
- public void NotEqualityObject(object first, object second, Type type)
+ public void GenericEquals_WhenFalse(object first, object second, Type type)
{
// Arrange
// Cast to the known object types, this is so that we can hit the
@@ -253,7 +254,7 @@ namespace ImageSharp.Tests.Colorspaces
[Theory]
[MemberData(nameof(NotEqualityData))]
- public void NotEqualityOperator(object first, object second, Type type)
+ public void Operator_WhenTrue(object first, object second, Type type)
{
// Arrange
// Cast to the known object types, this is so that we can hit the
diff --git a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs
index 4ffc33580a..98f316f439 100644
--- a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs
+++ b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs
@@ -114,7 +114,7 @@ namespace ImageSharp.Tests
{
using (Image image = new Image(1, 1))
{
- CopyFromZYX(image);
+ CopyFromZYXImpl(image);
}
}
@@ -123,7 +123,7 @@ namespace ImageSharp.Tests
{
using (Image image = new Image(1, 1))
{
- CopyFromZYXW(image);
+ CopyFromZYXWImpl(image);
}
}
@@ -132,7 +132,7 @@ namespace ImageSharp.Tests
{
using (Image image = new Image(1, 1))
{
- CopyToZYX(image);
+ CopyToZYXImpl(image);
}
}
@@ -141,11 +141,11 @@ namespace ImageSharp.Tests
{
using (Image image = new Image(1, 1))
{
- CopyToZYXW(image);
+ CopyToZYXWImpl(image);
}
}
- private static void CopyFromZYX(Image image)
+ private static void CopyFromZYXImpl(Image image)
where TPixel : struct, IPixel
{
using (PixelAccessor pixels = image.Lock())
@@ -172,7 +172,7 @@ namespace ImageSharp.Tests
}
}
- private static void CopyFromZYXW(Image image)
+ private static void CopyFromZYXWImpl(Image image)
where TPixel : struct, IPixel
{
using (PixelAccessor pixels = image.Lock())
@@ -200,7 +200,7 @@ namespace ImageSharp.Tests
}
}
- private static void CopyToZYX(Image image)
+ private static void CopyToZYXImpl(Image image)
where TPixel : struct, IPixel
{
using (PixelAccessor pixels = image.Lock())
@@ -222,7 +222,7 @@ namespace ImageSharp.Tests
}
}
- private static void CopyToZYXW(Image image)
+ private static void CopyToZYXWImpl(Image image)
where TPixel : struct, IPixel
{
using (PixelAccessor pixels = image.Lock())
diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
index 9f3beb9e81..b0429d9ede 100644
--- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
+++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj
@@ -12,8 +12,8 @@
-
-
+
+
diff --git a/tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs b/tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs
index 7e5af92972..db5b4a4c91 100644
--- a/tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs
@@ -15,7 +15,18 @@ namespace ImageSharp.Tests
public class ColorDefinitionTests
{
- public static IEnumerable ColorNames => typeof(NamedColors).GetTypeInfo().GetFields().Select(x => new[] { x.Name });
+ public static TheoryData ColorNames
+ {
+ get
+ {
+ var result = new TheoryData();
+ foreach (string name in typeof(NamedColors).GetTypeInfo().GetFields().Select(x => x.Name ))
+ {
+ result.Add(name);
+ }
+ return result;
+ }
+ }
[Theory]
[MemberData(nameof(ColorNames))]
diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs
index 6c1d32b337..3799054beb 100644
--- a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs
+++ b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs
@@ -5,6 +5,7 @@
namespace ImageSharp.Tests.Processing.Transforms
{
+ using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
@@ -28,6 +29,16 @@ namespace ImageSharp.Tests.Processing.Transforms
{ RotateType.Rotate90, FlipType.None, 8 },
};
+ public static readonly TheoryData InvalidOrientationValues
+ = new TheoryData
+ {
+ { ExifDataType.Byte, new byte[] { 1 } },
+ { ExifDataType.SignedByte, new byte[] { 2 } },
+ { ExifDataType.SignedShort, BitConverter.GetBytes((short) 3) },
+ { ExifDataType.Long, BitConverter.GetBytes((uint) 4) },
+ { ExifDataType.SignedLong, BitConverter.GetBytes((int) 5) }
+ };
+
[Theory]
[WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), DefaultPixelType)]
public void ImageShouldAutoRotate(TestImageProvider provider, RotateType rotateType, FlipType flipType, ushort orientation)
@@ -45,5 +56,29 @@ namespace ImageSharp.Tests.Processing.Transforms
image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after"), Extensions.Bmp);
}
}
+
+ [Theory]
+ [WithFileCollection(nameof(FlipFiles), nameof(InvalidOrientationValues), DefaultPixelType)]
+ public void ImageShouldAutoRotateInvalidValues(TestImageProvider provider, ExifDataType dataType, byte[] orientation)
+ where TPixel : struct, IPixel
+ {
+ var profile = new ExifProfile();
+ profile.SetValue(ExifTag.JPEGTables, orientation);
+
+ byte[] bytes = profile.ToByteArray();
+ // Change the tag into ExifTag.Orientation
+ bytes[16] = 18;
+ bytes[17] = 1;
+ // Change the data type
+ bytes[18] = (byte)dataType;
+ // Change the number of components
+ bytes[20] = 1;
+
+ using (Image image = provider.GetImage())
+ {
+ image.MetaData.ExifProfile = new ExifProfile(bytes);
+ image.Mutate(x=>x.AutoOrient());
+ }
+ }
}
}
\ No newline at end of file