From 78a9e9e0b883fdca9c0fe49d8819000452ad49f1 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 30 May 2017 15:55:11 +1000 Subject: [PATCH] Alpha --- .../Processing/Effects/AlphaTest.cs | 53 +++++++++++++++++ .../Processors/Filters/AlphaTest.cs | 57 ------------------- 2 files changed, 53 insertions(+), 57 deletions(-) create mode 100644 tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs delete mode 100644 tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs diff --git a/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs new file mode 100644 index 0000000000..a25e48ac38 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs @@ -0,0 +1,53 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Effects +{ + using ImageSharp.PixelFormats; + + using Xunit; + + public class AlphaTest : FileTestBase + { + public static readonly TheoryData AlphaValues + = new TheoryData + { + 20/100F, + 80/100F + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), StandardPixelType)] + public void ImageShouldApplyAlphaFilter(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Alpha(value) + .DebugSave(provider, value, Extensions.Png); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), StandardPixelType)] + public void ImageShouldApplyAlphaFilterInBox(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Alpha(value, bounds) + .DebugSave(provider, value, Extensions.Png); + + // Draw identical shapes over the bounded and compare to ensure changes are constrained. + image.Fill(NamedColors.HotPink, bounds); + source.Fill(NamedColors.HotPink, bounds); + ImageComparer.CheckSimilarity(image, source); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs b/tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs deleted file mode 100644 index 401ac916bd..0000000000 --- a/tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests -{ - using System.IO; - - using ImageSharp.PixelFormats; - - using Xunit; - - public class AlphaTest : FileTestBase - { - public static readonly TheoryData AlphaValues - = new TheoryData - { - 20/100f , - 80/100f - }; - - [Theory] - [MemberData(nameof(AlphaValues))] - public void ImageShouldApplyAlphaFilter(float value) - { - string path = this.CreateOutputDirectory("Alpha"); - - foreach (TestFile file in Files) - { - string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) - using (FileStream output = File.OpenWrite($"{path}/{filename}")) - { - image.Alpha(value).Save(output); - } - } - } - - [Theory] - [MemberData(nameof(AlphaValues))] - public void ImageShouldApplyAlphaFilterInBox(float value) - { - string path = this.CreateOutputDirectory("Alpha"); - - foreach (TestFile file in Files) - { - string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) - using (FileStream output = File.OpenWrite($"{path}/{filename}")) - { - image.Alpha(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); - } - } - } - } -} \ No newline at end of file