mirror of https://github.com/SixLabors/ImageSharp
4 changed files with 83 additions and 107 deletions
@ -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.
|
|||
// 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.Overlays |
|||
{ |
|||
public class VignetteTest : FileTestBase |
|||
[GroupOutput("Overlays")] |
|||
public class VignetteTest : OverlayTestBase |
|||
{ |
|||
[Theory] |
|||
[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); |
|||
protected override void Apply<T>(IImageProcessingContext<T> ctx, T color) => ctx.Vignette(color); |
|||
|
|||
image.Mutate(x => x.Vignette(bounds)); |
|||
image.DebugSave(provider); |
|||
protected override void Apply<T>(IImageProcessingContext<T> ctx, float radiusX, float radiusY) => |
|||
ctx.Vignette(radiusX, radiusY); |
|||
|
|||
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); |
|||
} |
|||
} |
|||
protected override void Apply<T>(IImageProcessingContext<T> ctx, Rectangle rect) => ctx.Vignette(rect); |
|||
} |
|||
} |
|||
@ -1 +1 @@ |
|||
Subproject commit 56ee5df145d9696e401e2bc53e615c553cfb32d5 |
|||
Subproject commit 854ba68b05162bdd87c0c9bbdcdb1c848aa6ddbe |
|||
Loading…
Reference in new issue