Browse Source

Better sampler tests

Fixes thresholder.


Former-commit-id: 38af3bd0e8028989997c45c12f865601e36e1368
Former-commit-id: b9e84eb7f0a56c5f896498f71838f790651b3398
Former-commit-id: 7c5d5789d6fca88d9b5f751124dbb9d24efd8ea2
af/merge-core
James Jackson-South 10 years ago
parent
commit
4e9e4d0db9
  1. 60
      src/ImageProcessorCore/Filters/BinaryThreshold.cs
  2. 19
      src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs
  3. 2
      src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs
  4. 47
      tests/ImageProcessorCore.Tests/Processors/Filters/BinaryThreshold.cs
  5. 38
      tests/ImageProcessorCore.Tests/Processors/Samplers/CropTest.cs
  6. 47
      tests/ImageProcessorCore.Tests/Processors/Samplers/EntropyCropTest.cs
  7. 38
      tests/ImageProcessorCore.Tests/Processors/Samplers/PadTest.cs
  8. 280
      tests/ImageProcessorCore.Tests/Processors/Samplers/ResizeTests.cs
  9. 50
      tests/ImageProcessorCore.Tests/Processors/Samplers/RotateFlipTest.cs
  10. 47
      tests/ImageProcessorCore.Tests/Processors/Samplers/RotateTest.cs
  11. 49
      tests/ImageProcessorCore.Tests/Processors/Samplers/SkewTest.cs

60
src/ImageProcessorCore/Filters/BinaryThreshold.cs

@ -0,0 +1,60 @@
// <copyright file="BinaryThreshold.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
{
using Processors;
/// <summary>
/// Extension methods for the <see cref="Image{T,TP}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies binerization to the image splitting the pixels at the given threshold.
/// </summary>
/// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="threshold">The threshold to apply binerization of the image. Must be between 0 and 1.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image{T,TP}"/>.</returns>
public static Image<T, TP> BinaryThreshold<T, TP>(this Image<T, TP> source, float threshold, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
return BinaryThreshold(source, threshold, source.Bounds, progressHandler);
}
/// <summary>
/// Applies binerization to the image splitting the pixels at the given threshold.
/// </summary>
/// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="threshold">The threshold to apply binerization of the image. Must be between 0 and 1.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image{T,TP}"/>.</returns>
public static Image<T, TP> BinaryThreshold<T, TP>(this Image<T, TP> source, float threshold, Rectangle rectangle, ProgressEventHandler progressHandler = null)
where T : IPackedVector<TP>
where TP : struct
{
BinaryThresholdProcessor<T, TP> processor = new BinaryThresholdProcessor<T, TP>(threshold);
processor.OnProgress += progressHandler;
try
{
return source.Process(rectangle, processor);
}
finally
{
processor.OnProgress -= progressHandler;
}
}
}
}

19
src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs → src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs

@ -1,4 +1,4 @@
// <copyright file="ThresholdProcessor.cs" company="James Jackson-South">
// <copyright file="BinaryThresholdProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -14,7 +14,7 @@ namespace ImageProcessorCore.Processors
/// </summary>
/// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
public class ThresholdProcessor<T, TP> : ImageProcessor<T, TP>
public class BinaryThresholdProcessor<T, TP> : ImageProcessor<T, TP>
where T : IPackedVector<TP>
where TP : struct
{
@ -25,13 +25,19 @@ namespace ImageProcessorCore.Processors
/// <exception cref="ArgumentException">
/// <paramref name="threshold"/> is less than 0 or is greater than 1.
/// </exception>
public ThresholdProcessor(float threshold)
public BinaryThresholdProcessor(float threshold)
{
// TODO: Check limit.
Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold));
this.Value = threshold;
this.UpperColor.PackVector(Color.White.ToVector4());
this.LowerColor.PackVector(Color.Black.ToVector4());
T upper = default(T);
upper.PackVector(Color.White.ToVector4());
this.UpperColor = upper;
T lower = default(T);
lower.PackVector(Color.Black.ToVector4());
this.LowerColor = lower;
}
/// <summary>
@ -58,6 +64,9 @@ namespace ImageProcessorCore.Processors
/// <inheritdoc/>
protected override void Apply(ImageBase<T, TP> target, ImageBase<T, TP> source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
// target.SetPixels(source.Width, source.Height, source.Pixels);
float threshold = this.Value;
T upper = this.UpperColor;
T lower = this.LowerColor;

2
src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs

@ -48,7 +48,7 @@ namespace ImageProcessorCore.Processors
new SobelProcessor<T, TP>().Apply(temp, source, sourceRectangle);
// Apply threshold binarization filter.
new ThresholdProcessor<T, TP>(.5f).Apply(temp, temp, sourceRectangle);
new BinaryThresholdProcessor<T, TP>(.5f).Apply(temp, temp, sourceRectangle);
// Search for the first white pixels
Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0);

47
tests/ImageProcessorCore.Tests/Processors/Filters/BinaryThreshold.cs

@ -0,0 +1,47 @@
// <copyright file="BinaryThresholdTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Tests
{
using System.IO;
using Xunit;
public class BinaryThresholdTest : FileTestBase
{
public static readonly TheoryData<float> BinaryThresholdValues
= new TheoryData<float>
{
.25f ,
.75f ,
};
[Theory]
[MemberData("BinaryThresholdValues")]
public void ImageShouldApplyBinaryThresholdFilter(float value)
{
const string path = "TestOutput/BinaryThreshold";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileNameWithoutExtension(file) + "-" + value + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BinaryThreshold(value)
.Save(output);
}
}
}
}
}
}

38
tests/ImageProcessorCore.Tests/Processors/Samplers/CropTest.cs

@ -0,0 +1,38 @@
// <copyright file="CropTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Tests
{
using System.IO;
using Xunit;
public class CropTest : FileTestBase
{
[Fact]
public void ImageShouldApplyCropSampler()
{
const string path = "TestOutput/Crop";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Crop(image.Width / 2, image.Height / 2, this.ProgressUpdate)
.Save(output);
}
}
}
}
}
}

47
tests/ImageProcessorCore.Tests/Processors/Samplers/EntropyCropTest.cs

@ -0,0 +1,47 @@
// <copyright file="EntropyCropTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Tests
{
using System.IO;
using Xunit;
public class EntropyCropTest : FileTestBase
{
public static readonly TheoryData<float> EntropyCropValues
= new TheoryData<float>
{
.25f ,
.75f ,
};
[Theory]
[MemberData("EntropyCropValues")]
public void ImageShouldApplyEntropyCropSampler(float value)
{
const string path = "TestOutput/EntropyCrop";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileNameWithoutExtension(file) + "-" + value + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.EntropyCrop(value)
.Save(output);
}
}
}
}
}
}

38
tests/ImageProcessorCore.Tests/Processors/Samplers/PadTest.cs

@ -0,0 +1,38 @@
// <copyright file="PadTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Tests
{
using System.IO;
using Xunit;
public class PadTest : FileTestBase
{
[Fact]
public void ImageShouldApplyPadSampler()
{
const string path = "TestOutput/Pad";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Pad(image.Width + 50, image.Height + 50, this.ProgressUpdate)
.Save(output);
}
}
}
}
}
}

280
tests/ImageProcessorCore.Tests/Processors/Samplers/SamplerTests.cs → tests/ImageProcessorCore.Tests/Processors/Samplers/ResizeTests.cs

@ -1,4 +1,4 @@
// <copyright file="SamplerTests.cs" company="James Jackson-South">
// <copyright file="ResizeTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -9,8 +9,10 @@ namespace ImageProcessorCore.Tests
using Xunit;
public class SamplerTests : FileTestBase
public class ResizeTests : FileTestBase
{
private const string path = "TestOutput/Resize";
public static readonly TheoryData<string, IResampler> ReSamplers =
new TheoryData<string, IResampler>
{
@ -31,46 +33,13 @@ namespace ImageProcessorCore.Tests
//{ "Welch", new WelchResampler() }
};
public static readonly TheoryData<RotateType, FlipType> RotateFlips = new TheoryData<RotateType, FlipType>
{
{ RotateType.None, FlipType.Vertical },
{ RotateType.None, FlipType.Horizontal },
{ RotateType.Rotate90, FlipType.None },
{ RotateType.Rotate180, FlipType.None },
{ RotateType.Rotate270, FlipType.None },
};
[Fact]
public void ImageShouldPad()
{
if (!Directory.Exists("TestOutput/Pad"))
{
Directory.CreateDirectory("TestOutput/Pad");
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/Pad/{filename}"))
{
image.Pad(image.Width + 50, image.Height + 50, this.ProgressUpdate)
.Save(output);
}
}
}
}
[Theory]
[MemberData("ReSamplers")]
public void ImageShouldResize(string name, IResampler sampler)
{
if (!Directory.Exists("TestOutput/Resize"))
if (!Directory.Exists(path))
{
Directory.CreateDirectory("TestOutput/Resize");
Directory.CreateDirectory(path);
}
foreach (string file in Files)
@ -80,7 +49,7 @@ namespace ImageProcessorCore.Tests
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}"))
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Resize(image.Width / 2, image.Height / 2, sampler, false, this.ProgressUpdate)
.Save(output);
@ -92,13 +61,13 @@ namespace ImageProcessorCore.Tests
[Fact]
public void ImageShouldResizeWidthAndKeepAspect()
{
if (!Directory.Exists("TestOutput/Resize"))
const string name = "FixedWidth";
if (!Directory.Exists(path))
{
Directory.CreateDirectory("TestOutput/Resize");
Directory.CreateDirectory(path);
}
var name = "FixedWidth";
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
@ -106,7 +75,7 @@ namespace ImageProcessorCore.Tests
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}"))
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Resize(image.Width / 3, 0, new TriangleResampler(), false, this.ProgressUpdate)
.Save(output);
@ -118,13 +87,13 @@ namespace ImageProcessorCore.Tests
[Fact]
public void ImageShouldResizeHeightAndKeepAspect()
{
if (!Directory.Exists("TestOutput/Resize"))
const string name = "FixedHeight";
if (!Directory.Exists(path))
{
Directory.CreateDirectory("TestOutput/Resize");
Directory.CreateDirectory(path);
}
string name = "FixedHeight";
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
@ -132,7 +101,7 @@ namespace ImageProcessorCore.Tests
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/Resize/{filename}"))
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Resize(0, image.Height / 3, new TriangleResampler(), false, this.ProgressUpdate)
.Save(output);
@ -144,19 +113,21 @@ namespace ImageProcessorCore.Tests
[Fact]
public void ImageShouldResizeWithCropMode()
{
if (!Directory.Exists("TestOutput/ResizeCrop"))
const string name = "Crop";
if (!Directory.Exists(path))
{
Directory.CreateDirectory("TestOutput/ResizeCrop");
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/ResizeCrop/{filename}"))
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
ResizeOptions options = new ResizeOptions()
{
@ -173,19 +144,21 @@ namespace ImageProcessorCore.Tests
[Fact]
public void ImageShouldResizeWithPadMode()
{
if (!Directory.Exists("TestOutput/ResizePad"))
const string name = "Pad";
if (!Directory.Exists(path))
{
Directory.CreateDirectory("TestOutput/ResizePad");
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/ResizePad/{filename}"))
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
ResizeOptions options = new ResizeOptions()
{
@ -203,19 +176,21 @@ namespace ImageProcessorCore.Tests
[Fact]
public void ImageShouldResizeWithBoxPadMode()
{
if (!Directory.Exists("TestOutput/ResizeBoxPad"))
const string name = "BoxPad";
if (!Directory.Exists(path))
{
Directory.CreateDirectory("TestOutput/ResizeBoxPad");
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/ResizeBoxPad/{filename}"))
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
ResizeOptions options = new ResizeOptions()
{
@ -233,25 +208,26 @@ namespace ImageProcessorCore.Tests
[Fact]
public void ImageShouldResizeWithMaxMode()
{
if (!Directory.Exists("TestOutput/ResizeMax"))
const string name = "Max";
if (!Directory.Exists(path))
{
Directory.CreateDirectory("TestOutput/ResizeMax");
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/ResizeMax/{filename}"))
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
ResizeOptions options = new ResizeOptions()
{
Size = new Size(300, 300),
Mode = ResizeMode.Max,
//Sampler = new NearestNeighborResampler()
Mode = ResizeMode.Max
};
image.Resize(options, this.ProgressUpdate)
@ -264,19 +240,21 @@ namespace ImageProcessorCore.Tests
[Fact]
public void ImageShouldResizeWithMinMode()
{
if (!Directory.Exists("TestOutput/ResizeMin"))
const string name = "Min";
if (!Directory.Exists(path))
{
Directory.CreateDirectory("TestOutput/ResizeMin");
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/ResizeMin/{filename}"))
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
ResizeOptions options = new ResizeOptions()
{
@ -294,19 +272,21 @@ namespace ImageProcessorCore.Tests
[Fact]
public void ImageShouldResizeWithStretchMode()
{
if (!Directory.Exists("TestOutput/ResizeStretch"))
const string name = "Stretch";
if (!Directory.Exists(path))
{
Directory.CreateDirectory("TestOutput/ResizeStretch");
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
string filename = Path.GetFileNameWithoutExtension(file) + "-" + name + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/ResizeStretch/{filename}"))
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
ResizeOptions options = new ResizeOptions()
{
@ -321,158 +301,6 @@ namespace ImageProcessorCore.Tests
}
}
//[Fact]
//public void ImageShouldNotDispose()
//{
// if (!Directory.Exists("TestOutput/Dispose"))
// {
// Directory.CreateDirectory("TestOutput/Dispose");
// }
// foreach (string file in Files)
// {
// using (FileStream stream = File.OpenRead(file))
// {
// string filename = Path.GetFileName(file);
// Image image = new Image(stream);
// image = image.BackgroundColor(Color.RebeccaPurple);
// using (FileStream output = File.OpenWrite($"TestOutput/Dispose/{filename}"))
// {
// ResizeOptions options = new ResizeOptions()
// {
// Size = new Size(image.Width - 10, image.Height),
// Mode = ResizeMode.Stretch
// };
// image.Resize(options, this.ProgressUpdate)
// .Save(output);
// }
// }
// }
//}
[Theory]
[MemberData("RotateFlips")]
public void ImageShouldRotateFlip(RotateType rotateType, FlipType flipType)
{
if (!Directory.Exists("TestOutput/RotateFlip"))
{
Directory.CreateDirectory("TestOutput/RotateFlip");
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileNameWithoutExtension(file) + "-" + rotateType + flipType + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/RotateFlip/{filename}"))
{
image.RotateFlip(rotateType, flipType, this.ProgressUpdate)
.Save(output);
}
}
}
}
[Fact]
public void ImageShouldRotate()
{
if (!Directory.Exists("TestOutput/Rotate"))
{
Directory.CreateDirectory("TestOutput/Rotate");
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/Rotate/{filename}"))
{
image.Rotate(-170, this.ProgressUpdate)
.Save(output);
}
}
}
}
[Fact]
public void ImageShouldSkew()
{
if (!Directory.Exists("TestOutput/Skew"))
{
Directory.CreateDirectory("TestOutput/Skew");
}
// Matches live example http://www.w3schools.com/css/tryit.asp?filename=trycss3_transform_skew
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/Skew/{filename}"))
{
image.Skew(-20, -10, this.ProgressUpdate)
.Save(output);
}
}
}
}
[Fact]
public void ImageShouldEntropyCrop()
{
if (!Directory.Exists("TestOutput/EntropyCrop"))
{
Directory.CreateDirectory("TestOutput/EntropyCrop");
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileNameWithoutExtension(file) + "-EntropyCrop" + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/EntropyCrop/{filename}"))
{
image.EntropyCrop(.5f, this.ProgressUpdate).Save(output);
}
}
}
}
[Fact]
public void ImageShouldCrop()
{
if (!Directory.Exists("TestOutput/Crop"))
{
Directory.CreateDirectory("TestOutput/Crop");
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileNameWithoutExtension(file) + "-Crop" + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"TestOutput/Crop/{filename}"))
{
image.Crop(image.Width / 2, image.Height / 2, this.ProgressUpdate).Save(output);
}
}
}
}
[Theory]
[InlineData(-2, 0)]
[InlineData(-1, 0)]

50
tests/ImageProcessorCore.Tests/Processors/Samplers/RotateFlipTest.cs

@ -0,0 +1,50 @@
// <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 ImageProcessorCore.Tests
{
using System.IO;
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("RotateFlipValues")]
public void ImageShouldRotateFlip(RotateType rotateType, FlipType flipType)
{
const string path = "TestOutput/RotateFlip";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileNameWithoutExtension(file) + "-" + rotateType + flipType + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.RotateFlip(rotateType, flipType, this.ProgressUpdate)
.Save(output);
}
}
}
}
}
}

47
tests/ImageProcessorCore.Tests/Processors/Samplers/RotateTest.cs

@ -0,0 +1,47 @@
// <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 ImageProcessorCore.Tests
{
using System.IO;
using Xunit;
public class RotateTest : FileTestBase
{
public static readonly TheoryData<float> RotateValues
= new TheoryData<float>
{
170 ,
-170 ,
};
[Theory]
[MemberData("RotateValues")]
public void ImageShouldApplyRotateSampler(float value)
{
const string path = "TestOutput/Rotate";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileNameWithoutExtension(file) + "-" + value + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Rotate(value)
.Save(output);
}
}
}
}
}
}

49
tests/ImageProcessorCore.Tests/Processors/Samplers/SkewTest.cs

@ -0,0 +1,49 @@
// <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 ImageProcessorCore.Tests
{
using System.IO;
using Xunit;
public class SkewTest : FileTestBase
{
public static readonly TheoryData<float, float> SkewValues
= new TheoryData<float, float>
{
{ 20, 10 },
{ -20, -10 }
};
[Theory]
[MemberData("SkewValues")]
public void ImageShouldApplySkewSampler(float x, float y)
{
const string path = "TestOutput/Skew";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
// Matches live example
// http://www.w3schools.com/css/tryit.asp?filename=trycss3_transform_skew
foreach (string file in Files)
{
using (FileStream stream = File.OpenRead(file))
{
string filename = Path.GetFileNameWithoutExtension(file) + "-" + x + "-" + y + Path.GetExtension(file);
Image image = new Image(stream);
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Skew(x, y)
.Save(output);
}
}
}
}
}
}
Loading…
Cancel
Save