mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
35 changed files with 1621 additions and 510 deletions
@ -0,0 +1,56 @@ |
|||||
|
// // Copyright (c) Six Labors and contributors.
|
||||
|
// // Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.ImageSharp.Processing; |
||||
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
||||
|
using SixLabors.Primitives; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution |
||||
|
{ |
||||
|
[GroupOutput("Convolution")] |
||||
|
public abstract class Basic1ParameterConvolutionTests |
||||
|
{ |
||||
|
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05F); |
||||
|
|
||||
|
public static readonly TheoryData<int> Values = new TheoryData<int> { 3, 5 }; |
||||
|
|
||||
|
public static readonly string[] InputImages = |
||||
|
{ |
||||
|
TestImages.Bmp.Car, |
||||
|
TestImages.Png.CalliphoraPartial |
||||
|
}; |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(InputImages), nameof(Values), PixelTypes.Rgba32)] |
||||
|
public void OnFullImage<TPixel>(TestImageProvider<TPixel> provider, int value) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
provider.Utility.TestGroupName = this.GetType().Name; |
||||
|
provider.RunValidatingProcessorTest( |
||||
|
x => this.Apply(x, value), |
||||
|
value, |
||||
|
ValidatorComparer); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(InputImages), nameof(Values), PixelTypes.Rgba32)] |
||||
|
public void InBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
provider.Utility.TestGroupName = this.GetType().Name; |
||||
|
provider.RunRectangleConstrainedValidatingProcessorTest( |
||||
|
(x, rect) => this.Apply(x, value, rect), |
||||
|
value, |
||||
|
ValidatorComparer); |
||||
|
} |
||||
|
|
||||
|
protected abstract void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value) |
||||
|
where TPixel : struct, IPixel<TPixel>; |
||||
|
|
||||
|
protected abstract void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value, Rectangle bounds) |
||||
|
where TPixel : struct, IPixel<TPixel>; |
||||
|
} |
||||
|
} |
||||
@ -1,51 +1,17 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
// Copyright (c) Six Labors and contributors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
using SixLabors.ImageSharp.Processing; |
using SixLabors.ImageSharp.Processing; |
||||
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
||||
|
|
||||
using SixLabors.Primitives; |
using SixLabors.Primitives; |
||||
using Xunit; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution |
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution |
||||
{ |
{ |
||||
public class BoxBlurTest : FileTestBase |
[GroupOutput("Convolution")] |
||||
|
public class BoxBlurTest : Basic1ParameterConvolutionTests |
||||
{ |
{ |
||||
public static readonly TheoryData<int> BoxBlurValues |
protected override void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value) => ctx.BoxBlur(value); |
||||
= new TheoryData<int> |
|
||||
{ |
|
||||
3, |
|
||||
5 |
|
||||
}; |
|
||||
|
|
||||
[Theory] |
|
||||
[WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)] |
|
||||
public void ImageShouldApplyBoxBlurFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|
||||
where TPixel : struct, IPixel<TPixel> |
|
||||
{ |
|
||||
using (Image<TPixel> image = provider.GetImage()) |
|
||||
{ |
|
||||
image.Mutate(x => x.BoxBlur(value)); |
|
||||
image.DebugSave(provider, value); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)] |
|
||||
public void ImageShouldApplyBoxBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
|
||||
where TPixel : struct, IPixel<TPixel> |
|
||||
{ |
|
||||
using (Image<TPixel> source = provider.GetImage()) |
|
||||
using (Image<TPixel> image = source.Clone()) |
|
||||
{ |
|
||||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|
||||
|
|
||||
image.Mutate(x => x.BoxBlur(value, bounds)); |
|
||||
image.DebugSave(provider, value); |
|
||||
|
|
||||
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); |
protected override void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value, Rectangle bounds) => |
||||
} |
ctx.BoxBlur(value, bounds); |
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.Reflection; |
||||
|
|
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.ImageSharp.Processing; |
||||
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
||||
|
using SixLabors.Primitives; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays |
||||
|
{ |
||||
|
[GroupOutput("Overlays")] |
||||
|
public abstract class OverlayTestBase |
||||
|
{ |
||||
|
public static string[] ColorNames = { "Blue", "White" }; |
||||
|
|
||||
|
public static string[] InputImages = { TestImages.Png.Ducky, TestImages.Png.Splash }; |
||||
|
|
||||
|
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05f); |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(InputImages), nameof(ColorNames), PixelTypes.Rgba32)] |
||||
|
public void FullImage_ApplyColor<TPixel>(TestImageProvider<TPixel> provider, string colorName) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
provider.Utility.TestGroupName = this.GetType().Name; |
||||
|
var f = (FieldInfo)typeof(NamedColors<TPixel>).GetMember(colorName)[0]; |
||||
|
TPixel color = (TPixel)f.GetValue(null); |
||||
|
|
||||
|
provider.RunValidatingProcessorTest(x => this.Apply(x, color), colorName, ValidatorComparer, appendPixelTypeToFileName: false); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)] |
||||
|
public void FullImage_ApplyRadius<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
provider.Utility.TestGroupName = this.GetType().Name; |
||||
|
provider.RunValidatingProcessorTest( |
||||
|
x => |
||||
|
{ |
||||
|
Size size = x.GetCurrentSize(); |
||||
|
this.Apply(x, size.Width / 4f, size.Height / 4f); |
||||
|
}, |
||||
|
comparer: ValidatorComparer, |
||||
|
appendPixelTypeToFileName: false); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)] |
||||
|
public void InBox<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
provider.Utility.TestGroupName = this.GetType().Name; |
||||
|
provider.RunRectangleConstrainedValidatingProcessorTest((x, rect) => this.Apply(x, rect)); |
||||
|
} |
||||
|
|
||||
|
protected abstract void Apply<T>(IImageProcessingContext<T> ctx, T color) |
||||
|
where T : struct, IPixel<T>; |
||||
|
|
||||
|
protected abstract void Apply<T>(IImageProcessingContext<T> ctx, float radiusX, float radiusY) |
||||
|
where T : struct, IPixel<T>; |
||||
|
|
||||
|
protected abstract void Apply<T>(IImageProcessingContext<T> ctx, Rectangle rect) |
||||
|
where T : struct, IPixel<T>; |
||||
|
} |
||||
|
} |
||||
@ -1,68 +1,19 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
// Copyright (c) Six Labors and contributors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
using SixLabors.ImageSharp.Processing; |
using SixLabors.ImageSharp.Processing; |
||||
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
||||
|
|
||||
using SixLabors.Primitives; |
using SixLabors.Primitives; |
||||
using Xunit; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays |
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays |
||||
{ |
{ |
||||
public class VignetteTest : FileTestBase |
[GroupOutput("Overlays")] |
||||
|
public class VignetteTest : OverlayTestBase |
||||
{ |
{ |
||||
[Theory] |
protected override void Apply<T>(IImageProcessingContext<T> ctx, T color) => ctx.Vignette(color); |
||||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|
||||
public void ImageShouldApplyVignetteFilter<TPixel>(TestImageProvider<TPixel> provider) |
|
||||
where TPixel : struct, IPixel<TPixel> |
|
||||
{ |
|
||||
using (Image<TPixel> image = provider.GetImage()) |
|
||||
{ |
|
||||
image.Mutate(x => x.Vignette()); |
|
||||
image.DebugSave(provider); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|
||||
public void ImageShouldApplyVignetteFilterColor<TPixel>(TestImageProvider<TPixel> provider) |
|
||||
where TPixel : struct, IPixel<TPixel> |
|
||||
{ |
|
||||
using (Image<TPixel> image = provider.GetImage()) |
|
||||
{ |
|
||||
image.Mutate(x => x.Vignette(NamedColors<TPixel>.Orange)); |
|
||||
image.DebugSave(provider); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|
||||
public void ImageShouldApplyVignetteFilterRadius<TPixel>(TestImageProvider<TPixel> provider) |
|
||||
where TPixel : struct, IPixel<TPixel> |
|
||||
{ |
|
||||
using (Image<TPixel> image = provider.GetImage()) |
|
||||
{ |
|
||||
image.Mutate(x => x.Vignette(image.Width / 4F, image.Height / 4F)); |
|
||||
image.DebugSave(provider); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|
||||
public void ImageShouldApplyVignetteFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
|
||||
where TPixel : struct, IPixel<TPixel> |
|
||||
{ |
|
||||
using (Image<TPixel> source = provider.GetImage()) |
|
||||
using (var image = source.Clone()) |
|
||||
{ |
|
||||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|
||||
|
|
||||
image.Mutate(x => x.Vignette(bounds)); |
protected override void Apply<T>(IImageProcessingContext<T> ctx, float radiusX, float radiusY) => |
||||
image.DebugSave(provider); |
ctx.Vignette(radiusX, radiusY); |
||||
|
|
||||
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); |
protected override void Apply<T>(IImageProcessingContext<T> ctx, Rectangle rect) => ctx.Vignette(rect); |
||||
} |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
@ -1,72 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Reflection; |
|
||||
|
|
||||
using SixLabors.ImageSharp.Processing; |
|
||||
using SixLabors.ImageSharp.Processing.Processors.Transforms; |
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms |
|
||||
{ |
|
||||
public class SkewTest : FileTestBase |
|
||||
{ |
|
||||
public static readonly TheoryData<float, float> SkewValues |
|
||||
= new TheoryData<float, float> |
|
||||
{ |
|
||||
{ 20, 10 }, |
|
||||
{ -20, -10 } |
|
||||
}; |
|
||||
|
|
||||
public static readonly List<string> ResamplerNames |
|
||||
= new List<string> |
|
||||
{ |
|
||||
nameof(KnownResamplers.Bicubic), |
|
||||
nameof(KnownResamplers.Box), |
|
||||
nameof(KnownResamplers.CatmullRom), |
|
||||
nameof(KnownResamplers.Hermite), |
|
||||
nameof(KnownResamplers.Lanczos2), |
|
||||
nameof(KnownResamplers.Lanczos3), |
|
||||
nameof(KnownResamplers.Lanczos5), |
|
||||
nameof(KnownResamplers.Lanczos8), |
|
||||
nameof(KnownResamplers.MitchellNetravali), |
|
||||
nameof(KnownResamplers.NearestNeighbor), |
|
||||
nameof(KnownResamplers.Robidoux), |
|
||||
nameof(KnownResamplers.RobidouxSharp), |
|
||||
nameof(KnownResamplers.Spline), |
|
||||
nameof(KnownResamplers.Triangle), |
|
||||
nameof(KnownResamplers.Welch), |
|
||||
}; |
|
||||
|
|
||||
[Theory] |
|
||||
[WithTestPatternImages(nameof(SkewValues), 100, 50, DefaultPixelType)] |
|
||||
public void ImageShouldSkew<TPixel>(TestImageProvider<TPixel> provider, float x, float y) |
|
||||
where TPixel : struct, IPixel<TPixel> |
|
||||
{ |
|
||||
using (Image<TPixel> image = provider.GetImage()) |
|
||||
{ |
|
||||
image.Mutate(i => i.Skew(x, y)); |
|
||||
image.DebugSave(provider, string.Join("_", x, y)); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[WithTestPatternImages(nameof(SkewValues), 100, 50, DefaultPixelType)] |
|
||||
public void ImageShouldSkewWithSampler<TPixel>(TestImageProvider<TPixel> provider, float x, float y) |
|
||||
where TPixel : struct, IPixel<TPixel> |
|
||||
{ |
|
||||
foreach (string resamplerName in ResamplerNames) |
|
||||
{ |
|
||||
IResampler sampler = TestUtils.GetResampler(resamplerName); |
|
||||
using (Image<TPixel> image = provider.GetImage()) |
|
||||
{ |
|
||||
image.Mutate(i => i.Skew(x, y, sampler)); |
|
||||
image.DebugSave(provider, string.Join("_", x, y, resamplerName)); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,67 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.ImageSharp.Processing; |
||||
|
using SixLabors.ImageSharp.Processing.Processors.Transforms; |
||||
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms |
||||
|
{ |
||||
|
[GroupOutput("Transforms")] |
||||
|
public class SkewTests |
||||
|
{ |
||||
|
private const PixelTypes CommonPixelTypes = PixelTypes.Bgra32 | PixelTypes.Rgb24; |
||||
|
|
||||
|
public static readonly string[] ResamplerNames = new[] |
||||
|
{ |
||||
|
nameof(KnownResamplers.Bicubic), |
||||
|
nameof(KnownResamplers.Box), |
||||
|
nameof(KnownResamplers.CatmullRom), |
||||
|
nameof(KnownResamplers.Hermite), |
||||
|
nameof(KnownResamplers.Lanczos2), |
||||
|
nameof(KnownResamplers.Lanczos3), |
||||
|
nameof(KnownResamplers.Lanczos5), |
||||
|
nameof(KnownResamplers.Lanczos8), |
||||
|
nameof(KnownResamplers.MitchellNetravali), |
||||
|
nameof(KnownResamplers.NearestNeighbor), |
||||
|
nameof(KnownResamplers.Robidoux), |
||||
|
nameof(KnownResamplers.RobidouxSharp), |
||||
|
nameof(KnownResamplers.Spline), |
||||
|
nameof(KnownResamplers.Triangle), |
||||
|
nameof(KnownResamplers.Welch), |
||||
|
}; |
||||
|
|
||||
|
public static readonly TheoryData<float, float> SkewValues = new TheoryData<float, float> |
||||
|
{ |
||||
|
{ 20, 10 }, |
||||
|
{ -20, -10 } |
||||
|
}; |
||||
|
|
||||
|
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.01f); |
||||
|
|
||||
|
[Theory] |
||||
|
[WithTestPatternImages(nameof(SkewValues), 100, 50, CommonPixelTypes)] |
||||
|
public void Skew_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider, float x, float y) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
provider.RunValidatingProcessorTest(ctx => ctx.Skew(x, y), $"{x}_{y}", ValidatorComparer); |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFile(TestImages.Png.Ducky, nameof(ResamplerNames), PixelTypes.Rgba32)] |
||||
|
public void Skew_WorksWithAllResamplers<TPixel>(TestImageProvider<TPixel> provider, string resamplerName) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
IResampler sampler = TestUtils.GetResampler(resamplerName); |
||||
|
|
||||
|
provider.RunValidatingProcessorTest( |
||||
|
x => x.Skew(21, 32, sampler), |
||||
|
resamplerName, |
||||
|
comparer: ValidatorComparer, |
||||
|
appendPixelTypeToFileName: false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1 +1 @@ |
|||||
Subproject commit 1ca515499663e8b0b7c924a49b8d212f7447bdb0 |
Subproject commit c057090b4402120a83a8efe251aa5b691db9c0dc |
||||
Loading…
Reference in new issue