Browse Source

Rotate, Skew

af/merge-core
James Jackson-South 9 years ago
parent
commit
6b07ff2b28
  1. 1
      tests/ImageSharp.Sandbox46/Program.cs
  2. 6
      tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs
  3. 39
      tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs
  4. 55
      tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs
  5. 33
      tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs
  6. 44
      tests/ImageSharp.Tests/Processors/Filters/RotateFlipTest.cs
  7. 67
      tests/ImageSharp.Tests/Processors/Filters/RotateTest.cs
  8. 42
      tests/ImageSharp.Tests/Processors/Filters/SkewTest.cs

1
tests/ImageSharp.Sandbox46/Program.cs

@ -10,6 +10,7 @@ namespace ImageSharp.Sandbox46
using ImageSharp.Tests;
using ImageSharp.Tests.Colors;
using ImageSharp.Tests.Processing.Transforms;
using Xunit.Abstractions;

6
tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs

@ -1,4 +1,4 @@
// <copyright file="RotateFlipTest.cs" company="James Jackson-South">
// <copyright file="AutoOrientTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -39,9 +39,9 @@ namespace ImageSharp.Tests.Processing.Transforms
image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation);
image.RotateFlip(rotateType, flipType)
.DebugSave(provider, "before", Extensions.Bmp)
.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "1_before"), Extensions.Bmp)
.AutoOrient()
.DebugSave(provider, "after", Extensions.Bmp);
.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after"), Extensions.Bmp);
}
}
}

39
tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs

@ -0,0 +1,39 @@
// <copyright file="RotateFlipTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class RotateFlipTests : FileTestBase
{
public static readonly string[] FlipFiles = { TestImages.Bmp.F };
public static readonly TheoryData<RotateType, FlipType> RotateFlipValues
= new TheoryData<RotateType, FlipType>
{
{ RotateType.None, FlipType.Vertical },
{ RotateType.None, FlipType.Horizontal },
{ RotateType.Rotate90, FlipType.None },
{ RotateType.Rotate180, FlipType.None },
{ RotateType.Rotate270, FlipType.None },
};
[Theory]
[WithFileCollection(nameof(FlipFiles), nameof(RotateFlipValues), StandardPixelType)]
public void ImageShouldRotateFlip<TPixel>(TestImageProvider<TPixel> provider, RotateType rotateType, FlipType flipType)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.RotateFlip(rotateType, flipType)
.DebugSave(provider, string.Join("_", rotateType, flipType), Extensions.Bmp);
}
}
}
}

55
tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs

@ -0,0 +1,55 @@
// <copyright file="RotateTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class RotateTests : FileTestBase
{
public static readonly TheoryData<float> RotateFloatValues
= new TheoryData<float>
{
170,
-170
};
public static readonly TheoryData<RotateType> RotateEnumValues
= new TheoryData<RotateType>
{
RotateType.None,
RotateType.Rotate90,
RotateType.Rotate180,
RotateType.Rotate270
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(RotateFloatValues), StandardPixelType)]
public void ImageShouldRotate<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Rotate(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(RotateEnumValues), StandardPixelType)]
public void ImageShouldRotateEnum<TPixel>(TestImageProvider<TPixel> provider, RotateType value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Rotate(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
}
}

33
tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs

@ -0,0 +1,33 @@
// <copyright file="SkewTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using Xunit;
public class SkewTest : FileTestBase
{
public static readonly TheoryData<float, float> SkewValues
= new TheoryData<float, float>
{
{ 20, 10 },
{ -20, -10 }
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(SkewValues), StandardPixelType)]
public void ImageShouldSkew<TPixel>(TestImageProvider<TPixel> provider, float x, float y)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Skew(x, y)
.DebugSave(provider, string.Join("_", x, y), Extensions.Bmp);
}
}
}
}

44
tests/ImageSharp.Tests/Processors/Filters/RotateFlipTest.cs

@ -1,44 +0,0 @@
// <copyright file="RotateFlipTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System.IO;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class RotateFlipTest : FileTestBase
{
public static readonly TheoryData<RotateType, FlipType> RotateFlipValues
= new TheoryData<RotateType, FlipType>
{
{ RotateType.None, FlipType.Vertical },
{ RotateType.None, FlipType.Horizontal },
{ RotateType.Rotate90, FlipType.None },
{ RotateType.Rotate180, FlipType.None },
{ RotateType.Rotate270, FlipType.None },
};
[Theory]
[MemberData(nameof(RotateFlipValues))]
public void ImageShouldRotateFlip(RotateType rotateType, FlipType flipType)
{
string path = this.CreateOutputDirectory("RotateFlip");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(rotateType + "-" + flipType);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.RotateFlip(rotateType, flipType).Save(output);
}
}
}
}
}

67
tests/ImageSharp.Tests/Processors/Filters/RotateTest.cs

@ -1,67 +0,0 @@
// <copyright file="RotateTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System.IO;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class RotateTest : FileTestBase
{
public static readonly TheoryData<float> RotateFloatValues
= new TheoryData<float>
{
170 ,
-170 ,
};
public static readonly TheoryData<RotateType> RotateEnumValues
= new TheoryData<RotateType>
{
RotateType.None,
RotateType.Rotate90,
RotateType.Rotate180,
RotateType.Rotate270
};
[Theory]
[MemberData(nameof(RotateFloatValues))]
public void ImageShouldApplyRotateSampler(float value)
{
string path = this.CreateOutputDirectory("Rotate");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Rotate(value).Save(output);
}
}
}
[Theory]
[MemberData(nameof(RotateEnumValues))]
public void ImageShouldApplyRotateSampler(RotateType value)
{
string path = this.CreateOutputDirectory("Rotate");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Rotate(value).Save(output);
}
}
}
}
}

42
tests/ImageSharp.Tests/Processors/Filters/SkewTest.cs

@ -1,42 +0,0 @@
// <copyright file="SkewTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class SkewTest : FileTestBase
{
public static readonly TheoryData<float, float> SkewValues
= new TheoryData<float, float>
{
{ 20, 10 },
{ -20, -10 }
};
[Theory]
[MemberData(nameof(SkewValues))]
public void ImageShouldApplySkewSampler(float x, float y)
{
string path = this.CreateOutputDirectory("Skew");
// Matches live example
// http://www.w3schools.com/css/tryit.asp?filename=trycss3_transform_skew
foreach (TestFile file in Files)
{
string filename = file.GetFileName(x + "-" + y);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Skew(x, y).Save(output);
}
}
}
}
}
Loading…
Cancel
Save