mirror of https://github.com/SixLabors/ImageSharp
4 changed files with 128 additions and 140 deletions
@ -0,0 +1,46 @@ |
|||
// <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.Effects |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
using Xunit; |
|||
|
|||
public class InvertTest : FileTestBase |
|||
{ |
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), StandardPixelType)] |
|||
public void ImageShouldApplyInvertFilter<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Invert() |
|||
.DebugSave(provider, null, Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(DefaultFiles), StandardPixelType)] |
|||
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.Invert(bounds) |
|||
.DebugSave(provider, null, Extensions.Bmp); |
|||
|
|||
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
|
|||
image.Fill(NamedColors<TPixel>.HotPink, bounds); |
|||
source.Fill(NamedColors<TPixel>.HotPink, bounds); |
|||
ImageComparer.CheckSimilarity(image, source); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
// <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.Effects |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
|
|||
using Xunit; |
|||
|
|||
public class PixelateTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<int> PixelateValues |
|||
= new TheoryData<int> |
|||
{ |
|||
4 , |
|||
8 |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.StandardImageClass)] |
|||
public void ImageShouldApplyPixelateFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Pixelate(value) |
|||
.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.StandardImageClass)] |
|||
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.Pixelate(value, bounds) |
|||
.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]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,46 +0,0 @@ |
|||
// <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 |
|||
{ |
|||
using System.IO; |
|||
|
|||
using ImageSharp.PixelFormats; |
|||
|
|||
using Xunit; |
|||
|
|||
public class InvertTest : FileTestBase |
|||
{ |
|||
[Fact] |
|||
public void ImageShouldApplyInvertFilter() |
|||
{ |
|||
string path = this.CreateOutputDirectory("Invert"); |
|||
foreach (TestFile file in Files) |
|||
{ |
|||
using (Image<Rgba32> image = file.CreateImage()) |
|||
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) |
|||
{ |
|||
image.Invert().Save(output); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void ImageShouldApplyInvertFilterInBox() |
|||
{ |
|||
string path = this.CreateOutputDirectory("Invert"); |
|||
|
|||
foreach (TestFile file in Files) |
|||
{ |
|||
string filename = file.GetFileName("InBox"); |
|||
using (Image<Rgba32> image = file.CreateImage()) |
|||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|||
{ |
|||
image.Invert(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,94 +0,0 @@ |
|||
// <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 |
|||
{ |
|||
using System.IO; |
|||
using ImageSharp.PixelFormats; |
|||
using Xunit; |
|||
|
|||
public class PixelateTest |
|||
{ |
|||
public static readonly TheoryData<int> PixelateValues |
|||
= new TheoryData<int> |
|||
{ |
|||
4 , |
|||
8 |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.StandardImageClass)] |
|||
public void ImageShouldApplyPixelateFilter<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.Pixelate(value) |
|||
.DebugSave(provider, new |
|||
{ |
|||
size = value |
|||
}); |
|||
|
|||
using (PixelAccessor<TPixel> pixels = image.Lock()) |
|||
{ |
|||
for (int y = 0; y < pixels.Height; y += value) |
|||
{ |
|||
for (int x = 0; x < pixels.Width; x += value) |
|||
{ |
|||
TPixel source = pixels[x, y]; |
|||
for (int pixY = y; pixY < y + value && pixY < pixels.Height; pixY++) |
|||
{ |
|||
for (int pixX = x; pixX < x + value && pixX < pixels.Width; pixX++) |
|||
{ |
|||
Assert.Equal(source, pixels[pixX, pixY]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.StandardImageClass)] |
|||
public void ImageShouldApplyPixelateFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (Image<TPixel> image = new Image<TPixel>(source)) |
|||
{ |
|||
Rectangle rect = new Rectangle(image.Width/4, image.Height / 4, image.Width / 2, image.Height / 2); |
|||
|
|||
image.Pixelate(value, rect) |
|||
.DebugSave(provider, new |
|||
{ |
|||
size = value |
|||
}); |
|||
|
|||
using (PixelAccessor<TPixel> pixels = image.Lock()) |
|||
using (PixelAccessor<TPixel> sourcePixels = source.Lock()) |
|||
{ |
|||
for (int y = 0; y < pixels.Height; y++) |
|||
{ |
|||
for (int x = 0; x < pixels.Width; x++) |
|||
{ |
|||
var tx = x; |
|||
var ty = y; |
|||
TPixel sourceColor = sourcePixels[tx, ty]; |
|||
if (rect.Contains(tx, ty)) |
|||
{ |
|||
var sourceX = tx - ((tx - rect.Left) % value) + (value / 2); |
|||
var sourceY = ty - ((ty - rect.Top) % value) + (value / 2); |
|||
|
|||
sourceColor = pixels[sourceX, sourceY]; |
|||
} |
|||
Assert.Equal(sourceColor, pixels[tx, ty]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue