mirror of https://github.com/SixLabors/ImageSharp
8 changed files with 368 additions and 398 deletions
@ -0,0 +1,35 @@ |
|||||
|
// <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 ImageSharp.Tests.Processing.Transforms |
||||
|
{ |
||||
|
using ImageSharp.PixelFormats; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
public class PadTest : FileTestBase |
||||
|
{ |
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(DefaultFiles), StandardPixelType)] |
||||
|
public void ImageShouldPad<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
image.Pad(image.Width + 50, image.Height + 50) |
||||
|
.DebugSave(provider, null, Extensions.Bmp); |
||||
|
|
||||
|
// Check pixels are empty
|
||||
|
for (int y = 0; y < 25; y++) |
||||
|
{ |
||||
|
for (int x = 0; x < 25; x++) |
||||
|
{ |
||||
|
Assert.Equal(image[x, y], default(TPixel)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,273 @@ |
|||||
|
// <copyright file="ResizeTests.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 ResizeTests : FileTestBase |
||||
|
{ |
||||
|
public static readonly string[] ResizeFiles = { TestImages.Jpeg.Baseline.Calliphora }; |
||||
|
|
||||
|
public static readonly TheoryData<string, IResampler> ReSamplers = |
||||
|
new TheoryData<string, IResampler> |
||||
|
{ |
||||
|
{ "Bicubic", new BicubicResampler() }, |
||||
|
{ "Triangle", new TriangleResampler() }, |
||||
|
{ "NearestNeighbor", new NearestNeighborResampler() }, |
||||
|
{ "Box", new BoxResampler() }, |
||||
|
{ "Lanczos3", new Lanczos3Resampler() }, |
||||
|
{ "Lanczos5", new Lanczos5Resampler() }, |
||||
|
{ "MitchellNetravali", new MitchellNetravaliResampler() }, |
||||
|
{ "Lanczos8", new Lanczos8Resampler() }, |
||||
|
{ "Hermite", new HermiteResampler() }, |
||||
|
{ "Spline", new SplineResampler() }, |
||||
|
{ "Robidoux", new RobidouxResampler() }, |
||||
|
{ "RobidouxSharp", new RobidouxSharpResampler() }, |
||||
|
{ "Welch", new WelchResampler() } |
||||
|
}; |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResize<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
image.Resize(image.Width / 2, image.Height / 2, sampler, true) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeFromSourceRectangle<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
var sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4); |
||||
|
var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); |
||||
|
|
||||
|
image.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeWidthAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
image.Resize(image.Width / 3, 0, sampler, false) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeHeightAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
image.Resize(0, image.Height / 3, sampler, false) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeWithCropWidthMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
var options = new ResizeOptions |
||||
|
{ |
||||
|
Sampler = sampler, |
||||
|
Size = new Size(image.Width / 2, image.Height) |
||||
|
}; |
||||
|
|
||||
|
image.Resize(options) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeWithCropHeightMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
var options = new ResizeOptions |
||||
|
{ |
||||
|
Sampler = sampler, |
||||
|
Size = new Size(image.Width, image.Height / 2) |
||||
|
}; |
||||
|
|
||||
|
image.Resize(options) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeWithPadMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
var options = new ResizeOptions |
||||
|
{ |
||||
|
Sampler = sampler, |
||||
|
Size = new Size(image.Width + 200, image.Height), |
||||
|
Mode = ResizeMode.Pad |
||||
|
}; |
||||
|
|
||||
|
image.Resize(options) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeWithBoxPadMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
var options = new ResizeOptions |
||||
|
{ |
||||
|
Sampler = sampler, |
||||
|
Size = new Size(image.Width + 200, image.Height + 200), |
||||
|
Mode = ResizeMode.BoxPad |
||||
|
}; |
||||
|
|
||||
|
image.Resize(options) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeWithMaxMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
var options = new ResizeOptions |
||||
|
{ |
||||
|
Sampler = sampler, |
||||
|
Size = new Size(300, 300), |
||||
|
Mode = ResizeMode.Max |
||||
|
}; |
||||
|
|
||||
|
image.Resize(options) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeWithMinMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
var options = new ResizeOptions |
||||
|
{ |
||||
|
Sampler = sampler, |
||||
|
Size = new Size((int)MathF.Round(image.Width * .75F), (int)MathF.Round(image.Height * .95F)), |
||||
|
Mode = ResizeMode.Min |
||||
|
}; |
||||
|
|
||||
|
image.Resize(options) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), StandardPixelType)] |
||||
|
public void ImageShouldResizeWithStretchMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
var options = new ResizeOptions |
||||
|
{ |
||||
|
Sampler = sampler, |
||||
|
Size = new Size(image.Width / 2, image.Height), |
||||
|
Mode = ResizeMode.Stretch |
||||
|
}; |
||||
|
|
||||
|
image.Resize(options) |
||||
|
.DebugSave(provider, name, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(-2, 0)] |
||||
|
[InlineData(-1, 0)] |
||||
|
[InlineData(0, 1)] |
||||
|
[InlineData(1, 0)] |
||||
|
[InlineData(2, 0)] |
||||
|
public static void BicubicWindowOscillatesCorrectly(float x, float expected) |
||||
|
{ |
||||
|
var sampler = new BicubicResampler(); |
||||
|
float result = sampler.GetValue(x); |
||||
|
|
||||
|
Assert.Equal(result, expected); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(-2, 0)] |
||||
|
[InlineData(-1, 0)] |
||||
|
[InlineData(0, 1)] |
||||
|
[InlineData(1, 0)] |
||||
|
[InlineData(2, 0)] |
||||
|
public static void TriangleWindowOscillatesCorrectly(float x, float expected) |
||||
|
{ |
||||
|
var sampler = new TriangleResampler(); |
||||
|
float result = sampler.GetValue(x); |
||||
|
|
||||
|
Assert.Equal(result, expected); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(-2, 0)] |
||||
|
[InlineData(-1, 0)] |
||||
|
[InlineData(0, 1)] |
||||
|
[InlineData(1, 0)] |
||||
|
[InlineData(2, 0)] |
||||
|
public static void Lanczos3WindowOscillatesCorrectly(float x, float expected) |
||||
|
{ |
||||
|
var sampler = new Lanczos3Resampler(); |
||||
|
float result = sampler.GetValue(x); |
||||
|
|
||||
|
Assert.Equal(result, expected); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[InlineData(-4, 0)] |
||||
|
[InlineData(-2, 0)] |
||||
|
[InlineData(0, 1)] |
||||
|
[InlineData(2, 0)] |
||||
|
[InlineData(4, 0)] |
||||
|
public static void Lanczos5WindowOscillatesCorrectly(float x, float expected) |
||||
|
{ |
||||
|
var sampler = new Lanczos5Resampler(); |
||||
|
float result = sampler.GetValue(x); |
||||
|
|
||||
|
Assert.Equal(result, expected); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,31 +0,0 @@ |
|||||
// <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 ImageSharp.Tests |
|
||||
{ |
|
||||
using System.IO; |
|
||||
|
|
||||
using ImageSharp.PixelFormats; |
|
||||
|
|
||||
using Xunit; |
|
||||
|
|
||||
public class PadTest : FileTestBase |
|
||||
{ |
|
||||
[Fact] |
|
||||
public void ImageShouldApplyPadSampler() |
|
||||
{ |
|
||||
string path = this.CreateOutputDirectory("Pad"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) |
|
||||
{ |
|
||||
image.Pad(image.Width + 50, image.Height + 50).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,350 +0,0 @@ |
|||||
// <copyright file="ResizeTests.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; |
|
||||
using System.IO; |
|
||||
|
|
||||
using ImageSharp.PixelFormats; |
|
||||
|
|
||||
using ImageSharp.Processing; |
|
||||
using Xunit; |
|
||||
|
|
||||
public class ResizeTests : FileTestBase |
|
||||
{ |
|
||||
public static readonly TheoryData<string, IResampler> ReSamplers = |
|
||||
new TheoryData<string, IResampler> |
|
||||
{ |
|
||||
{ "Bicubic", new BicubicResampler() }, |
|
||||
{ "Triangle", new TriangleResampler() }, |
|
||||
{ "NearestNeighbor", new NearestNeighborResampler() }, |
|
||||
|
|
||||
// Perf: Enable for local testing only
|
|
||||
// { "Box", new BoxResampler() },
|
|
||||
// { "Lanczos3", new Lanczos3Resampler() },
|
|
||||
// { "Lanczos5", new Lanczos5Resampler() },
|
|
||||
{ "MitchellNetravali", new MitchellNetravaliResampler() }, |
|
||||
|
|
||||
// { "Lanczos8", new Lanczos8Resampler() },
|
|
||||
// { "Hermite", new HermiteResampler() },
|
|
||||
// { "Spline", new SplineResampler() },
|
|
||||
// { "Robidoux", new RobidouxResampler() },
|
|
||||
// { "RobidouxSharp", new RobidouxSharpResampler() },
|
|
||||
// { "RobidouxSoft", new RobidouxSoftResampler() },
|
|
||||
// { "Welch", new WelchResampler() }
|
|
||||
}; |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResize(string name, IResampler sampler) |
|
||||
{ |
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
image.Resize(image.Width / 2, image.Height / 2, sampler, true).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeFromSourceRectangle(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}-SourceRect"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
Rectangle sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4); |
|
||||
Rectangle destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); |
|
||||
image.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeWidthAndKeepAspect(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}-FixedWidth"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
image.Resize(image.Width / 3, 0, sampler, false).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeHeightAndKeepAspect(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}-FixedHeight"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
image.Resize(0, image.Height / 3, sampler, false).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeWithCropWidthMode(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}-CropWidth"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
ResizeOptions options = new ResizeOptions |
|
||||
{ |
|
||||
Sampler = sampler, |
|
||||
Size = new Size(image.Width / 2, image.Height) |
|
||||
}; |
|
||||
|
|
||||
image.Resize(options).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeWithCropHeightMode(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}-CropHeight"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
ResizeOptions options = new ResizeOptions |
|
||||
{ |
|
||||
Sampler = sampler, |
|
||||
Size = new Size(image.Width, image.Height / 2) |
|
||||
}; |
|
||||
|
|
||||
image.Resize(options).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeWithPadMode(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}-Pad"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
ResizeOptions options = new ResizeOptions |
|
||||
{ |
|
||||
Size = new Size(image.Width + 200, image.Height), |
|
||||
Mode = ResizeMode.Pad |
|
||||
}; |
|
||||
|
|
||||
image.Resize(options).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeWithBoxPadMode(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}-BoxPad"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
ResizeOptions options = new ResizeOptions |
|
||||
{ |
|
||||
Sampler = sampler, |
|
||||
Size = new Size(image.Width + 200, image.Height + 200), |
|
||||
Mode = ResizeMode.BoxPad |
|
||||
}; |
|
||||
|
|
||||
image.Resize(options).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeWithMaxMode(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}Max"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
ResizeOptions options = new ResizeOptions |
|
||||
{ |
|
||||
Sampler = sampler, |
|
||||
Size = new Size(300, 300), |
|
||||
Mode = ResizeMode.Max |
|
||||
}; |
|
||||
|
|
||||
image.Resize(options).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeWithMinMode(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}-Min"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
ResizeOptions options = new ResizeOptions |
|
||||
{ |
|
||||
Sampler = sampler, |
|
||||
Size = new Size((int)Math.Round(image.Width * .75F), (int)Math.Round(image.Height * .95F)), |
|
||||
Mode = ResizeMode.Min |
|
||||
}; |
|
||||
|
|
||||
image.Resize(options).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(ReSamplers))] |
|
||||
public void ImageShouldResizeWithStretchMode(string name, IResampler sampler) |
|
||||
{ |
|
||||
name = $"{name}Stretch"; |
|
||||
|
|
||||
string path = this.CreateOutputDirectory("Resize"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(name); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
ResizeOptions options = new ResizeOptions |
|
||||
{ |
|
||||
Sampler = sampler, |
|
||||
Size = new Size(image.Width / 2, image.Height), |
|
||||
Mode = ResizeMode.Stretch |
|
||||
}; |
|
||||
|
|
||||
image.Resize(options).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(-2, 0)] |
|
||||
[InlineData(-1, 0)] |
|
||||
[InlineData(0, 1)] |
|
||||
[InlineData(1, 0)] |
|
||||
[InlineData(2, 0)] |
|
||||
public static void BicubicWindowOscillatesCorrectly(float x, float expected) |
|
||||
{ |
|
||||
BicubicResampler sampler = new BicubicResampler(); |
|
||||
float result = sampler.GetValue(x); |
|
||||
|
|
||||
Assert.Equal(result, expected); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(-2, 0)] |
|
||||
[InlineData(-1, 0)] |
|
||||
[InlineData(0, 1)] |
|
||||
[InlineData(1, 0)] |
|
||||
[InlineData(2, 0)] |
|
||||
public static void TriangleWindowOscillatesCorrectly(float x, float expected) |
|
||||
{ |
|
||||
TriangleResampler sampler = new TriangleResampler(); |
|
||||
float result = sampler.GetValue(x); |
|
||||
|
|
||||
Assert.Equal(result, expected); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(-2, 0)] |
|
||||
[InlineData(-1, 0)] |
|
||||
[InlineData(0, 1)] |
|
||||
[InlineData(1, 0)] |
|
||||
[InlineData(2, 0)] |
|
||||
public static void Lanczos3WindowOscillatesCorrectly(float x, float expected) |
|
||||
{ |
|
||||
Lanczos3Resampler sampler = new Lanczos3Resampler(); |
|
||||
float result = sampler.GetValue(x); |
|
||||
|
|
||||
Assert.Equal(result, expected); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData(-4, 0)] |
|
||||
[InlineData(-2, 0)] |
|
||||
[InlineData(0, 1)] |
|
||||
[InlineData(2, 0)] |
|
||||
[InlineData(4, 0)] |
|
||||
public static void Lanczos5WindowOscillatesCorrectly(float x, float expected) |
|
||||
{ |
|
||||
Lanczos5Resampler sampler = new Lanczos5Resampler(); |
|
||||
float result = sampler.GetValue(x); |
|
||||
|
|
||||
Assert.Equal(result, expected); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue