Browse Source

merge with master

af/merge-core
Scott Williams 9 years ago
parent
commit
999b09e84e
  1. 11
      src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs
  2. 1
      src/ImageSharp/Processing/Transforms/AutoOrient.cs
  3. 2
      tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
  4. 17
      tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs
  5. 16
      tests/ImageSharp.Tests/Image/PixelAccessorTests.cs
  6. 4
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  7. 13
      tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs
  8. 35
      tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs

11
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);

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

@ -5,6 +5,7 @@
namespace ImageSharp
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;

2
tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj

@ -18,7 +18,7 @@
<ItemGroup>
<!--<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />-->
<PackageReference Include="Moq" Version="4.7.1" />
<PackageReference Include="xunit" Version="2.3.0-beta2-build3683" />
<PackageReference Include="xunit" Version="2.3.0-beta3-build3705" />
<!--<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />-->
</ItemGroup>
<ItemGroup>

17
tests/ImageSharp.Tests/Colorspaces/ColorSpaceEqualityTests.cs

@ -3,6 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
// 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

16
tests/ImageSharp.Tests/Image/PixelAccessorTests.cs

@ -114,7 +114,7 @@ namespace ImageSharp.Tests
{
using (Image<Rgba32> image = new Image<Rgba32>(1, 1))
{
CopyFromZYX(image);
CopyFromZYXImpl(image);
}
}
@ -123,7 +123,7 @@ namespace ImageSharp.Tests
{
using (Image<Rgba32> image = new Image<Rgba32>(1, 1))
{
CopyFromZYXW(image);
CopyFromZYXWImpl(image);
}
}
@ -132,7 +132,7 @@ namespace ImageSharp.Tests
{
using (Image<Rgba32> image = new Image<Rgba32>(1, 1))
{
CopyToZYX(image);
CopyToZYXImpl(image);
}
}
@ -141,11 +141,11 @@ namespace ImageSharp.Tests
{
using (Image<Rgba32> image = new Image<Rgba32>(1, 1))
{
CopyToZYXW(image);
CopyToZYXWImpl(image);
}
}
private static void CopyFromZYX<TPixel>(Image<TPixel> image)
private static void CopyFromZYXImpl<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
using (PixelAccessor<TPixel> pixels = image.Lock())
@ -172,7 +172,7 @@ namespace ImageSharp.Tests
}
}
private static void CopyFromZYXW<TPixel>(Image<TPixel> image)
private static void CopyFromZYXWImpl<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
using (PixelAccessor<TPixel> pixels = image.Lock())
@ -200,7 +200,7 @@ namespace ImageSharp.Tests
}
}
private static void CopyToZYX<TPixel>(Image<TPixel> image)
private static void CopyToZYXImpl<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
using (PixelAccessor<TPixel> pixels = image.Lock())
@ -222,7 +222,7 @@ namespace ImageSharp.Tests
}
}
private static void CopyToZYXW<TPixel>(Image<TPixel> image)
private static void CopyToZYXWImpl<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
using (PixelAccessor<TPixel> pixels = image.Lock())

4
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -12,8 +12,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Moq" Version="4.7.1" />
<PackageReference Include="xunit" Version="2.3.0-beta2-build3683" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta2-build1317" />
<PackageReference Include="xunit" Version="2.3.0-beta3-build3705" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta3-build3705" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ImageSharp.Drawing\ImageSharp.Drawing.csproj" />

13
tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs

@ -15,7 +15,18 @@ namespace ImageSharp.Tests
public class ColorDefinitionTests
{
public static IEnumerable<string[]> ColorNames => typeof(NamedColors<Rgba32>).GetTypeInfo().GetFields().Select(x => new[] { x.Name });
public static TheoryData<string> ColorNames
{
get
{
var result = new TheoryData<string>();
foreach (string name in typeof(NamedColors<Rgba32>).GetTypeInfo().GetFields().Select(x => x.Name ))
{
result.Add(name);
}
return result;
}
}
[Theory]
[MemberData(nameof(ColorNames))]

35
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<ExifDataType, byte[]> InvalidOrientationValues
= new TheoryData<ExifDataType, byte[]>
{
{ 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<TPixel>(TestImageProvider<TPixel> 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<TPixel>(TestImageProvider<TPixel> provider, ExifDataType dataType, byte[] orientation)
where TPixel : struct, IPixel<TPixel>
{
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<TPixel> image = provider.GetImage())
{
image.MetaData.ExifProfile = new ExifProfile(bytes);
image.Mutate(x=>x.AutoOrient());
}
}
}
}
Loading…
Cancel
Save