mirror of https://github.com/SixLabors/ImageSharp
4 changed files with 133 additions and 92 deletions
@ -1,92 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using SixLabors.ImageSharp.Dithering; |
|
||||
using SixLabors.ImageSharp.Dithering.Ordered; |
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
||||
|
|
||||
using SixLabors.Primitives; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization |
|
||||
{ |
|
||||
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); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[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 = source.Clone()) |
|
||||
{ |
|
||||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|
||||
|
|
||||
image.Mutate(x => x.Dither(ditherer, bounds)); |
|
||||
image.DebugSave(provider, name); |
|
||||
|
|
||||
ImageComparer.Tolerant().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); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[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 = source.Clone()) |
|
||||
{ |
|
||||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|
||||
|
|
||||
image.Mutate(x => x.Dither(diffuser, .5F, bounds)); |
|
||||
image.DebugSave(provider, name); |
|
||||
|
|
||||
ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,132 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.Dithering; |
||||
|
using SixLabors.ImageSharp.Dithering.Ordered; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
||||
|
|
||||
|
using SixLabors.Primitives; |
||||
|
using Xunit; |
||||
|
// ReSharper disable InconsistentNaming
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization |
||||
|
{ |
||||
|
using System.Linq; |
||||
|
|
||||
|
public class DitherTests : FileTestBase |
||||
|
{ |
||||
|
public static readonly string[] CommonTestImages = |
||||
|
{ |
||||
|
TestImages.Png.CalliphoraPartial, TestImages.Png.Bike |
||||
|
}; |
||||
|
|
||||
|
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() }, |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
private static IOrderedDither DefaultDitherer => new Ordered(); |
||||
|
|
||||
|
private static IErrorDiffuser DefaultErrorDiffuser => new Atkinson(); |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(CommonTestImages), nameof(Ditherers), DefaultPixelType)] |
||||
|
[WithTestPatternImages(nameof(Ditherers), 100, 100, DefaultPixelType)] |
||||
|
public void DitherFilter_WorksWithAllDitherers<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); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(CommonTestImages), nameof(ErrorDiffusers), DefaultPixelType)] |
||||
|
[WithTestPatternImages(nameof(ErrorDiffusers), 100, 100, DefaultPixelType)] |
||||
|
public void DiffusionFilter_WorksWithAllErrorDiffusers<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); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFile(TestImages.Png.Bike, CommonNonDefaultPixelTypes)] |
||||
|
public void DitherFilter_ShouldNotDependOnSinglePixelType<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
image.Mutate(x => x.Dither(DefaultDitherer)); |
||||
|
image.DebugSave(provider); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFile(TestImages.Png.Bike, CommonNonDefaultPixelTypes)] |
||||
|
public void DiffusionFilter_ShouldNotDependOnSinglePixelType<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
image.Mutate(x => x.Dither(DefaultErrorDiffuser, 0.5f)); |
||||
|
image.DebugSave(provider); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFile(TestImages.Png.CalliphoraPartial, DefaultPixelType)] |
||||
|
public void ApplyDitherFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
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.Dither(DefaultDitherer, bounds)); |
||||
|
image.DebugSave(provider); |
||||
|
|
||||
|
ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// TODO: Does not work because of a bug! Fix it!
|
||||
|
[Theory(Skip = "TODO: Does not work because of a bug! Fix it!")] |
||||
|
[WithFile(TestImages.Png.CalliphoraPartial, DefaultPixelType)] |
||||
|
public void ApplyDiffusionFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
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.Dither(DefaultErrorDiffuser, .5F, bounds)); |
||||
|
image.DebugSave(provider); |
||||
|
|
||||
|
ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue