// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Dithering; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Binarization { public class BinaryDitherTest : BaseImageOperationsExtensionTest { private readonly IOrderedDither orderedDither; private readonly IErrorDiffuser errorDiffuser; public BinaryDitherTest() { this.orderedDither = KnownDitherers.BayerDither4x4; this.errorDiffuser = KnownDiffusers.FloydSteinberg; } [Fact] public void BinaryDither_CorrectProcessor() { this.operations.BinaryDither(this.orderedDither); BinaryOrderedDitherProcessor p = this.Verify>(); Assert.Equal(this.orderedDither, p.Dither); Assert.Equal(NamedColors.White, p.UpperColor); Assert.Equal(NamedColors.Black, p.LowerColor); } [Fact] public void BinaryDither_rect_CorrectProcessor() { this.operations.BinaryDither(this.orderedDither, this.rect); BinaryOrderedDitherProcessor p = this.Verify>(this.rect); Assert.Equal(this.orderedDither, p.Dither); Assert.Equal(NamedColors.White, p.UpperColor); Assert.Equal(NamedColors.Black, p.LowerColor); } [Fact] public void BinaryDither_index_CorrectProcessor() { this.operations.BinaryDither(this.orderedDither, NamedColors.Yellow, NamedColors.HotPink); BinaryOrderedDitherProcessor p = this.Verify>(); Assert.Equal(this.orderedDither, p.Dither); Assert.Equal(NamedColors.Yellow, p.UpperColor); Assert.Equal(NamedColors.HotPink, p.LowerColor); } [Fact] public void BinaryDither_index_rect_CorrectProcessor() { this.operations.BinaryDither(this.orderedDither, NamedColors.Yellow, NamedColors.HotPink, this.rect); BinaryOrderedDitherProcessor p = this.Verify>(this.rect); Assert.Equal(this.orderedDither, p.Dither); Assert.Equal(NamedColors.HotPink, p.LowerColor); } [Fact] public void BinaryDither_ErrorDiffuser_CorrectProcessor() { this.operations.BinaryDiffuse(this.errorDiffuser, .4F); BinaryErrorDiffusionProcessor p = this.Verify>(); Assert.Equal(this.errorDiffuser, p.Diffuser); Assert.Equal(.4F, p.Threshold); Assert.Equal(NamedColors.White, p.UpperColor); Assert.Equal(NamedColors.Black, p.LowerColor); } [Fact] public void BinaryDither_ErrorDiffuser_rect_CorrectProcessor() { this.operations.BinaryDiffuse(this.errorDiffuser, .3F, this.rect); BinaryErrorDiffusionProcessor p = this.Verify>(this.rect); Assert.Equal(this.errorDiffuser, p.Diffuser); Assert.Equal(.3F, p.Threshold); Assert.Equal(NamedColors.White, p.UpperColor); Assert.Equal(NamedColors.Black, p.LowerColor); } [Fact] public void BinaryDither_ErrorDiffuser_CorrectProcessorWithColors() { this.operations.BinaryDiffuse(this.errorDiffuser, .5F, NamedColors.HotPink, NamedColors.Yellow); BinaryErrorDiffusionProcessor p = this.Verify>(); Assert.Equal(this.errorDiffuser, p.Diffuser); Assert.Equal(.5F, p.Threshold); Assert.Equal(NamedColors.HotPink, p.UpperColor); Assert.Equal(NamedColors.Yellow, p.LowerColor); } [Fact] public void BinaryDither_ErrorDiffuser_rect_CorrectProcessorWithColors() { this.operations.BinaryDiffuse(this.errorDiffuser, .5F, NamedColors.HotPink, NamedColors.Yellow, this.rect); BinaryErrorDiffusionProcessor p = this.Verify>(this.rect); Assert.Equal(this.errorDiffuser, p.Diffuser); Assert.Equal(.5F, p.Threshold); Assert.Equal(NamedColors.HotPink, p.UpperColor); Assert.Equal(NamedColors.Yellow, p.LowerColor); } } }