mirror of https://github.com/SixLabors/ImageSharp
97 changed files with 2941 additions and 1544 deletions
@ -1,40 +0,0 @@ |
|||
|
|||
namespace ImageSharp.Tests.Drawing.Paths |
|||
{ |
|||
using System; |
|||
using System.IO; |
|||
using ImageSharp; |
|||
using ImageSharp.Processing; |
|||
using System.Collections.Generic; |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
|
|||
/// <summary>
|
|||
/// Watches but does not actually run the processors against the image.
|
|||
/// </summary>
|
|||
/// <seealso cref="ImageSharp.Image{Rgba32}" />
|
|||
public class ProcessorWatchingImage : Image<Rgba32> |
|||
{ |
|||
public List<ProcessorDetails> ProcessorApplications { get; } = new List<ProcessorDetails>(); |
|||
|
|||
public ProcessorWatchingImage(int width, int height) |
|||
: base(Configuration.CreateDefaultInstance(), width, height) |
|||
{ |
|||
} |
|||
|
|||
public override void ApplyProcessor(IImageProcessor<Rgba32> processor, Rectangle rectangle) |
|||
{ |
|||
this.ProcessorApplications.Add(new ProcessorDetails |
|||
{ |
|||
processor = processor, |
|||
rectangle = rectangle |
|||
}); |
|||
} |
|||
|
|||
public struct ProcessorDetails |
|||
{ |
|||
public IImageProcessor<Rgba32> processor; |
|||
public Rectangle rectangle; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// <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 |
|||
{ |
|||
using System; |
|||
using ImageSharp.PixelFormats; |
|||
using ImageSharp.Processing; |
|||
using Xunit; |
|||
|
|||
public class DelegateTest : BaseImageOperationsExtensionTest |
|||
{ |
|||
[Fact] |
|||
public void Run_CreatedDelegateProcessor() |
|||
{ |
|||
Action<Image<Rgba32>> action = (i) => { }; |
|||
this.operations.Run(action); |
|||
|
|||
DelegateProcessor<Rgba32> processor = this.Verify<DelegateProcessor<Rgba32>>(); |
|||
Assert.Equal(action, processor.Action); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
// <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 ImageSharp.Tests.Processing.Processors.Binarization |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class BinaryThresholdTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<float> BinaryThresholdValues |
|||
= new TheoryData<float> |
|||
{ |
|||
.25F, |
|||
.75F |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)] |
|||
public void ImageShouldApplyBinaryThresholdFilter<TPixel>(TestImageProvider<TPixel> provider, float value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.BinaryThreshold(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)] |
|||
public void ImageShouldApplyBinaryThresholdInBox<TPixel>(TestImageProvider<TPixel> provider, float value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
|
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.BinaryThreshold(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
// <copyright file="DitherTest.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.Processors.Binarization |
|||
{ |
|||
using ImageSharp.Dithering; |
|||
using ImageSharp.Dithering.Ordered; |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class DitherTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<string, IOrderedDither> Ditherers = new TheoryData<string, IOrderedDither> |
|||
{ |
|||
{ "Ordered", new Ordered() }, |
|||
{ "Bayer", new Bayer() } |
|||
}; |
|||
|
|||
public static readonly TheoryData<string, IErrorDiffuser> ErrorDiffusers = new TheoryData<string, IErrorDiffuser> |
|||
{ |
|||
{ "Atkinson", new Atkinson() }, |
|||
{ "Burks", new Burks() }, |
|||
{ "FloydSteinberg", new FloydSteinberg() }, |
|||
{ "JarvisJudiceNinke", new JarvisJudiceNinke() }, |
|||
{ "Sierra2", new Sierra2() }, |
|||
{ "Sierra3", new Sierra3() }, |
|||
{ "SierraLite", new SierraLite() }, |
|||
{ "Stucki", new Stucki() }, |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)] |
|||
public void ImageShouldApplyDitherFilter<TPixel>(TestImageProvider<TPixel> provider, string name, IOrderedDither ditherer) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Dither(ditherer)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)] |
|||
public void ImageShouldApplyDitherFilterInBox<TPixel>(TestImageProvider<TPixel> provider, string name, IOrderedDither ditherer) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Dither(ditherer, bounds)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)] |
|||
public void ImageShouldApplyDiffusionFilter<TPixel>(TestImageProvider<TPixel> provider, string name, IErrorDiffuser diffuser) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Dither(diffuser, .5F)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)] |
|||
public void ImageShouldApplyDiffusionFilterInBox<TPixel>(TestImageProvider<TPixel> provider, string name, IErrorDiffuser diffuser) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Dither(diffuser, .5F, bounds)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// <copyright file="BlackWhiteTest.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.Processors.ColorMatrix |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class BlackWhiteTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyBlackWhiteFilter<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.BlackWhite()); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyBlackWhiteFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.BlackWhite(bounds)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
// <copyright file="ColorBlindnessTest.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.Processors.ColorMatrix |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using ImageSharp.Processing; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class ColorBlindnessTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<ColorBlindness> ColorBlindnessFilters |
|||
= new TheoryData<ColorBlindness> |
|||
{ |
|||
ColorBlindness.Achromatomaly, |
|||
ColorBlindness.Achromatopsia, |
|||
ColorBlindness.Deuteranomaly, |
|||
ColorBlindness.Deuteranopia, |
|||
ColorBlindness.Protanomaly, |
|||
ColorBlindness.Protanopia, |
|||
ColorBlindness.Tritanomaly, |
|||
ColorBlindness.Tritanopia |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)] |
|||
public void ImageShouldApplyColorBlindnessFilter<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.ColorBlindness(colorBlindness)); |
|||
image.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)] |
|||
public void ImageShouldApplyColorBlindnessFilterInBox<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.ColorBlindness(colorBlindness, bounds)); |
|||
image.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
// <copyright file="GrayscaleTest.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.Processors.ColorMatrix |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using ImageSharp.Processing; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class GrayscaleTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<GrayscaleMode> GrayscaleModeTypes |
|||
= new TheoryData<GrayscaleMode> |
|||
{ |
|||
GrayscaleMode.Bt601, |
|||
GrayscaleMode.Bt709 |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Use test patterns over loaded images to save decode time.
|
|||
/// </summary>
|
|||
[Theory] |
|||
[WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)] |
|||
public void ImageShouldApplyGrayscaleFilterAll<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Grayscale(value)); |
|||
byte[] data = new byte[3]; |
|||
for (int i = 0; i < image.Pixels.Length; i++) |
|||
{ |
|||
image.Pixels[i].ToXyzBytes(data, 0); |
|||
Assert.Equal(data[0], data[1]); |
|||
Assert.Equal(data[1], data[2]); |
|||
} |
|||
|
|||
image.DebugSave(provider, value.ToString()); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)] |
|||
public void ImageShouldApplyGrayscaleFilterInBox<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); |
|||
image.Mutate(x => x.Grayscale(value, bounds)); |
|||
image.DebugSave(provider, value.ToString()); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="HueTest.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.Processors.ColorMatrix |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class HueTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> HueValues |
|||
= new TheoryData<int> |
|||
{ |
|||
180, |
|||
-180 |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)] |
|||
public void ImageShouldApplyHueFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Hue(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)] |
|||
public void ImageShouldApplyHueFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Hue(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// <copyright file="KodachromeTest.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.Processors.ColorMatrix |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class KodachromeTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyKodachromeFilter<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Kodachrome()); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyKodachromeFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Kodachrome(bounds)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
// <copyright file="LomographTest.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.Processors.ColorMatrix |
|||
{ |
|||
using System.IO; |
|||
|
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class LomographTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyLomographFilter<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Lomograph()); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyLomographFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Lomograph(bounds)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// <copyright file="PolaroidTest.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.Processors.ColorMatrix |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class PolaroidTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyPolaroidFilter<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Polaroid()); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyPolaroidFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Polaroid(bounds)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="SaturationTest.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.Processors.ColorMatrix |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class SaturationTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> SaturationValues |
|||
= new TheoryData<int> |
|||
{ |
|||
50 , |
|||
-50 , |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)] |
|||
public void ImageShouldApplySaturationFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Saturation(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)] |
|||
public void ImageShouldApplySaturationFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Saturation(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// <copyright file="SepiaTest.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.Processors.ColorMatrix |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class SepiaTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplySepiaFilter<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Sepia()); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplySepiaFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Sepia(bounds)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="BoxBlurTest.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.Processors.Convolution |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class BoxBlurTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> BoxBlurValues |
|||
= 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, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[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 (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.BoxBlur(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
// <copyright file="DetectEdgesTest.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.Processors.Convolution |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using ImageSharp.Processing; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class DetectEdgesTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<EdgeDetection> DetectEdgesFilters |
|||
= new TheoryData<EdgeDetection> |
|||
{ |
|||
EdgeDetection.Kayyali, |
|||
EdgeDetection.Kirsch, |
|||
EdgeDetection.Lapacian3X3, |
|||
EdgeDetection.Lapacian5X5, |
|||
EdgeDetection.LaplacianOfGaussian, |
|||
EdgeDetection.Prewitt, |
|||
EdgeDetection.RobertsCross, |
|||
EdgeDetection.Robinson, |
|||
EdgeDetection.Scharr, |
|||
EdgeDetection.Sobel |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)] |
|||
public void ImageShouldApplyDetectEdgesFilter<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.DetectEdges(detector)); |
|||
image.DebugSave(provider, detector.ToString(), Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)] |
|||
public void ImageShouldApplyDetectEdgesFilterInBox<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.DetectEdges(detector, bounds)); |
|||
image.DebugSave(provider, detector.ToString(), Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="GaussianBlurTest.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.Processors.Convolution |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class GaussianBlurTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> GaussianBlurValues |
|||
= new TheoryData<int> |
|||
{ |
|||
3, |
|||
5 |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)] |
|||
public void ImageShouldApplyGaussianBlurFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.GaussianBlur(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)] |
|||
public void ImageShouldApplyGaussianBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.GaussianBlur(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="GaussianSharpenTest.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.Processors.Convolution |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class GaussianSharpenTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> GaussianSharpenValues |
|||
= new TheoryData<int> |
|||
{ |
|||
3, |
|||
5 |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)] |
|||
public void ImageShouldApplyGaussianSharpenFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.GaussianSharpen(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)] |
|||
public void ImageShouldApplyGaussianSharpenFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.GaussianSharpen(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="AlphaTest.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.Processors.Effects |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class AlphaTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<float> AlphaValues |
|||
= new TheoryData<float> |
|||
{ |
|||
20/100F, |
|||
80/100F |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)] |
|||
public void ImageShouldApplyAlphaFilter<TPixel>(TestImageProvider<TPixel> provider, float value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Alpha(value)); |
|||
image.DebugSave(provider, value, Extensions.Png); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)] |
|||
public void ImageShouldApplyAlphaFilterInBox<TPixel>(TestImageProvider<TPixel> provider, float value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Alpha(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Png); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// <copyright file="BackgroundColorTest.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.Processors.Effects |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class BackgroundColorTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyBackgroundColorFilter<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.BackgroundColor(NamedColors<TPixel>.HotPink)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyBackgroundColorFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.BackgroundColor(NamedColors<TPixel>.HotPink, bounds)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="BrightnessTest.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.Processors.Effects |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class BrightnessTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> BrightnessValues |
|||
= new TheoryData<int> |
|||
{ |
|||
50, |
|||
-50 |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)] |
|||
public void ImageShouldApplyBrightnessFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Brightness(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)] |
|||
public void ImageShouldApplyBrightnessFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Brightness(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); ; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="ContrastTest.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.Processors.Effects |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class ContrastTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> ContrastValues |
|||
= new TheoryData<int> |
|||
{ |
|||
50, |
|||
-50 |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)] |
|||
public void ImageShouldApplyContrastFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Contrast(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)] |
|||
public void ImageShouldApplyContrastFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Contrast(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// <copyright file="InvertTest.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.Processors.Effects |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class InvertTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyInvertFilter<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Invert()); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyInvertFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Invert(bounds)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="OilPaintTest.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.Processors.Effects |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class OilPaintTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int, int> OilPaintValues |
|||
= new TheoryData<int, int> |
|||
{ |
|||
{ 15, 10 }, |
|||
{ 6, 5 } |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)] |
|||
public void ImageShouldApplyOilPaintFilter<TPixel>(TestImageProvider<TPixel> provider, int levels, int brushSize) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.OilPaint(levels, brushSize)); |
|||
image.DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)] |
|||
public void ImageShouldApplyOilPaintFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int levels, int brushSize) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.OilPaint(levels, brushSize, bounds)); |
|||
image.DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,84 @@ |
|||
// <copyright file="PixelateTest.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.Processors.Effects |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class PixelateTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> PixelateValues |
|||
= new TheoryData<int> |
|||
{ |
|||
4 , |
|||
8 |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)] |
|||
public void ImageShouldApplyPixelateFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Pixelate(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
// Test the neigbouring pixels
|
|||
for (int y = 0; y < image.Height; y += value) |
|||
{ |
|||
for (int x = 0; x < image.Width; x += value) |
|||
{ |
|||
TPixel source = image[x, y]; |
|||
for (int pixY = y; pixY < y + value && pixY < image.Height; pixY++) |
|||
{ |
|||
for (int pixX = x; pixX < x + value && pixX < image.Width; pixX++) |
|||
{ |
|||
Assert.Equal(source, image[pixX, pixY]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)] |
|||
public void ImageShouldApplyPixelateFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Pixelate(value, bounds)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
|
|||
for (int y = 0; y < image.Height; y++) |
|||
{ |
|||
for (int x = 0; x < image.Width; x++) |
|||
{ |
|||
int tx = x; |
|||
int ty = y; |
|||
TPixel sourceColor = source[tx, ty]; |
|||
if (bounds.Contains(tx, ty)) |
|||
{ |
|||
int sourceX = tx - ((tx - bounds.Left) % value) + (value / 2); |
|||
int sourceY = ty - ((ty - bounds.Top) % value) + (value / 2); |
|||
|
|||
sourceColor = image[sourceX, sourceY]; |
|||
} |
|||
Assert.Equal(sourceColor, image[tx, ty]); |
|||
} |
|||
} |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
// <copyright file="GlowTest.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.Processors.Overlays |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class GlowTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyGlowFilter<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Glow()); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyGlowFilterColor<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Glow(NamedColors<TPixel>.Orange)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyGlowFilterRadius<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Glow(image.Width / 4F)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldApplyGlowFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Glow(bounds)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
// <copyright file="VignetteTest.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.Processors.Overlays |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
using Xunit; |
|||
|
|||
public class VignetteTest : FileTestBase |
|||
{ |
|||
[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, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[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, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[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, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[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 = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Mutate(x => x.Vignette(bounds)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,84 @@ |
|||
// <copyright file="AutoOrientTests.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.Processors.Transforms |
|||
{ |
|||
using System; |
|||
using ImageSharp.PixelFormats; |
|||
using ImageSharp.Processing; |
|||
|
|||
using Xunit; |
|||
|
|||
public class AutoOrientTests : FileTestBase |
|||
{ |
|||
public static readonly string[] FlipFiles = { TestImages.Bmp.F }; |
|||
|
|||
public static readonly TheoryData<RotateType, FlipType, ushort> OrientationValues |
|||
= new TheoryData<RotateType, FlipType, ushort> |
|||
{ |
|||
{ RotateType.None, FlipType.None, 0 }, |
|||
{ RotateType.None, FlipType.None, 1 }, |
|||
{ RotateType.None, FlipType.Horizontal, 2 }, |
|||
{ RotateType.Rotate180, FlipType.None, 3 }, |
|||
{ RotateType.Rotate180, FlipType.Horizontal, 4 }, |
|||
{ RotateType.Rotate90, FlipType.Horizontal, 5 }, |
|||
{ RotateType.Rotate270, FlipType.None, 6 }, |
|||
{ RotateType.Rotate90, FlipType.Vertical, 7 }, |
|||
{ RotateType.Rotate90, FlipType.None, 8 }, |
|||
}; |
|||
|
|||
public static readonly TheoryData<ExifDataType, byte[]> InvalidOrientationValues |
|||
= new TheoryData<ExifDataType, byte[]> |
|||
{ |
|||
{ ExifDataType.Byte, new byte[] { 1 } }, |
|||
{ ExifDataType.SignedByte, new byte[] { 2 } }, |
|||
{ ExifDataType.SignedShort, BitConverter.GetBytes((short) 3) }, |
|||
{ ExifDataType.Long, BitConverter.GetBytes((uint) 4) }, |
|||
{ ExifDataType.SignedLong, BitConverter.GetBytes((int) 5) } |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), DefaultPixelType)] |
|||
public void ImageShouldAutoRotate<TPixel>(TestImageProvider<TPixel> provider, RotateType rotateType, FlipType flipType, ushort orientation) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.MetaData.ExifProfile = new ExifProfile(); |
|||
image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation); |
|||
|
|||
image.Mutate(x => x.RotateFlip(rotateType, flipType)); |
|||
image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "1_before"), Extensions.Bmp); |
|||
|
|||
image.Mutate(x => x.AutoOrient()); |
|||
image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after"), Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(FlipFiles), nameof(InvalidOrientationValues), DefaultPixelType)] |
|||
public void ImageShouldAutoRotateInvalidValues<TPixel>(TestImageProvider<TPixel> provider, ExifDataType dataType, byte[] orientation) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
var profile = new ExifProfile(); |
|||
profile.SetValue(ExifTag.JPEGTables, orientation); |
|||
|
|||
byte[] bytes = profile.ToByteArray(); |
|||
// Change the tag into ExifTag.Orientation
|
|||
bytes[16] = 18; |
|||
bytes[17] = 1; |
|||
// Change the data type
|
|||
bytes[18] = (byte)dataType; |
|||
// Change the number of components
|
|||
bytes[20] = 1; |
|||
|
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.MetaData.ExifProfile = new ExifProfile(bytes); |
|||
image.Mutate(x=>x.AutoOrient()); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// <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 ImageSharp.Tests.Processing.Processors.Transforms |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
using Xunit; |
|||
|
|||
public class CropTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldCrop<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Crop(image.Width / 2, image.Height / 2)); |
|||
image.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
// <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 ImageSharp.Tests.Processing.Processors.Transforms |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
using Xunit; |
|||
|
|||
public class EntropyCropTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<float> EntropyCropValues |
|||
= new TheoryData<float> |
|||
{ |
|||
.25F, |
|||
.75F |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(EntropyCropValues), DefaultPixelType)] |
|||
public void ImageShouldEntropyCrop<TPixel>(TestImageProvider<TPixel> provider, float value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.EntropyCrop(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
// <copyright file="FlipTest.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.Processors.Transforms |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using ImageSharp.Processing; |
|||
|
|||
using Xunit; |
|||
|
|||
public class FlipTests : FileTestBase |
|||
{ |
|||
public static readonly string[] FlipFiles = { TestImages.Bmp.F }; |
|||
|
|||
public static readonly TheoryData<FlipType> FlipValues |
|||
= new TheoryData<FlipType> |
|||
{ |
|||
{ FlipType.None }, |
|||
{ FlipType.Vertical }, |
|||
{ FlipType.Horizontal }, |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(FlipFiles), nameof(FlipValues), DefaultPixelType)] |
|||
public void ImageShouldFlip<TPixel>(TestImageProvider<TPixel> provider, FlipType flipType) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Flip(flipType)); |
|||
image.DebugSave(provider, flipType, Extensions.Bmp); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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.Processors.Transforms |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
using Xunit; |
|||
|
|||
public class PadTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] |
|||
public void ImageShouldPad<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Pad(image.Width + 50, image.Height + 50)); |
|||
image.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(default(TPixel), image[x, y]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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.Processors.Transforms |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using ImageSharp.Processing; |
|||
using SixLabors.Primitives; |
|||
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), DefaultPixelType)] |
|||
public void ImageShouldResize<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, sampler, true)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
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.Mutate(x => x.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
public void ImageShouldResizeWidthAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Resize(image.Width / 3, 0, sampler, false)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
public void ImageShouldResizeHeightAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Resize(0, image.Height / 3, sampler, false)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
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.Mutate(x => x.Resize(options)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
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.Mutate(x => x.Resize(options)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
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.Mutate(x => x.Resize(options)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
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.Mutate(x => x.Resize(options)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
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.Mutate(x => x.Resize(options)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
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.Mutate(x => x.Resize(options)); |
|||
image.DebugSave(provider, name, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)] |
|||
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.Mutate(x => x.Resize(options)); |
|||
image.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); |
|||
} |
|||
} |
|||
} |
|||
@ -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.Processors.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), DefaultPixelType)] |
|||
public void ImageShouldRotateFlip<TPixel>(TestImageProvider<TPixel> provider, RotateType rotateType, FlipType flipType) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.RotateFlip(rotateType, flipType)); |
|||
image.DebugSave(provider, string.Join("_", rotateType, flipType), Extensions.Bmp); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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.Processors.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), DefaultPixelType)] |
|||
public void ImageShouldRotate<TPixel>(TestImageProvider<TPixel> provider, float value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Rotate(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), nameof(RotateEnumValues), DefaultPixelType)] |
|||
public void ImageShouldRotateEnum<TPixel>(TestImageProvider<TPixel> provider, RotateType value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Mutate(x => x.Rotate(value)); |
|||
image.DebugSave(provider, value, Extensions.Bmp); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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.Processors.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), 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), Extensions.Bmp); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using ImageSharp.PixelFormats; |
|||
using Xunit.Abstractions; |
|||
|
|||
namespace ImageSharp.Tests.TestUtilities |
|||
{ |
|||
public class TestType<T> : IXunitSerializable |
|||
{ |
|||
public TestType() |
|||
{ |
|||
} |
|||
|
|||
public void Deserialize(IXunitSerializationInfo info) |
|||
{ |
|||
} |
|||
|
|||
public void Serialize(IXunitSerializationInfo info) |
|||
{ |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"Type<{typeof(T).Name}>"; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue