Browse Source

validating tests for Effects

af/merge-core
Anton Firszov 7 years ago
parent
commit
a96423ddc5
  1. 35
      tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs
  2. 42
      tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs
  3. 70
      tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs
  4. 2
      tests/Images/External

35
tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs

@ -10,35 +10,30 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
public class BackgroundColorTest : FileTestBase
[GroupOutput("Effects")]
public class BackgroundColorTest
{
public static readonly string[] InputImages =
{
TestImages.Png.Splash,
TestImages.Png.Ducky
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBackgroundColorFilter<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)]
public void FullImage<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);
}
provider.RunValidatingProcessorTest(x => x.BackgroundColor(NamedColors<TPixel>.HotPink));
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBackgroundColorFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)]
public void InBox<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.BackgroundColor(NamedColors<TPixel>.HotPink, bounds));
image.DebugSave(provider);
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
}
provider.RunRectangleConstrainedValidatingProcessorTest(
(x, rect) => x.BackgroundColor(NamedColors<TPixel>.HotPink, rect));
}
}
}

42
tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs

@ -10,40 +10,40 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
public class OilPaintTest : FileTestBase
[GroupOutput("Effects")]
public class OilPaintTest
{
public static readonly TheoryData<int, int> OilPaintValues = new TheoryData<int, int>
{
{ 15, 10 }, { 6, 5 }
{ 15, 10 },
{ 6, 5 }
};
public static readonly string[] InputImages =
{
TestImages.Png.CalliphoraPartial,
TestImages.Bmp.Car
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)]
public void ApplyOilPaintFilter<TPixel>(TestImageProvider<TPixel> provider, int levels, int brushSize)
[WithFileCollection(nameof(InputImages), nameof(OilPaintValues), PixelTypes.Rgba32)]
public void FullImage<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));
}
provider.RunValidatingProcessorTest(
x => x.OilPaint(levels, brushSize),
$"{levels}-{brushSize}",
appendPixelTypeToFileName: false);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)]
public void ApplyOilPaintFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int levels, int brushSize)
[WithFileCollection(nameof(InputImages), nameof(OilPaintValues), PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(OilPaintValues), 100, 100, PixelTypes.Rgba32)]
public void InBox<TPixel>(TestImageProvider<TPixel> provider, int levels, int brushSize)
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.OilPaint(levels, brushSize, bounds));
image.DebugSave(provider, string.Join("-", levels, brushSize));
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
}
provider.RunRectangleConstrainedValidatingProcessorTest(
(x, rect) => x.OilPaint(levels, brushSize, rect),
$"{levels}-{brushSize}");
}
}
}

70
tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs

@ -4,82 +4,32 @@
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.Effects
{
public class PixelateTest : FileTestBase
[GroupOutput("Effects")]
public class PixelateTest
{
public static readonly TheoryData<int> PixelateValues
= new TheoryData<int>
{
4 ,
8
};
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)
[WithFile(TestImages.Png.Ducky, nameof(PixelateValues), PixelTypes.Rgba32)]
public void FullImage<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);
// 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]);
}
}
}
}
}
provider.RunValidatingProcessorTest(x => x.Pixelate(value), value, appendPixelTypeToFileName: false);
}
[Theory]
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)]
public void ImageShouldApplyPixelateFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
[WithFile(TestImages.Png.CalliphoraPartial, nameof(PixelateValues), PixelTypes.Rgba32)]
public void InBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (var image = source.Clone())
{
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);
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.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
}
provider.RunRectangleConstrainedValidatingProcessorTest((x, rect) => x.Pixelate(value, rect), value);
}
}
}

2
tests/Images/External

@ -1 +1 @@
Subproject commit 0c524009f4d4b0edefddd944defdc408c3971536
Subproject commit 50de3b98694f20c9307d4d7cdac870f5820823c8
Loading…
Cancel
Save