diff --git a/tests/ImageSharp.Tests/FileTestBase.cs b/tests/ImageSharp.Tests/FileTestBase.cs
index 08ed69f3e..68ccfe06b 100644
--- a/tests/ImageSharp.Tests/FileTestBase.cs
+++ b/tests/ImageSharp.Tests/FileTestBase.cs
@@ -49,6 +49,11 @@ namespace ImageSharp.Tests
///
public const PixelTypes DefaultPixelType = PixelTypes.Rgba32;
+ ///
+ /// A few other pixel types to prove that a processor is not bound to a single one.
+ ///
+ public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector;
+
public static class Extensions
{
public const string Bmp = "bmp";
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs
index b303ef7f4..3e23b8ba4 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs
@@ -3,6 +3,7 @@
// Licensed under the Apache License, Version 2.0.
//
+// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests.Processing.Processors.Convolution
{
using ImageSharp.PixelFormats;
@@ -34,7 +35,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution
[Theory]
[WithTestPatternImages(nameof(DetectEdgesFilters), 100, 100, DefaultPixelType)]
[WithFileCollection(nameof(CommonTestImages), nameof(DetectEdgesFilters), DefaultPixelType)]
- public void DetectEdges(TestImageProvider provider, EdgeDetection detector)
+ public void DetectEdges_WorksWithAllFilters(TestImageProvider provider, EdgeDetection detector)
where TPixel : struct, IPixel
{
using (Image image = provider.GetImage())
@@ -44,9 +45,33 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution
}
}
+ [Theory]
+ [WithFileCollection(nameof(CommonTestImages), CommonNonDefaultPixelTypes)]
+ public void DetectEdges_IsNotBoundToSinglePixelType(TestImageProvider provider)
+ where TPixel : struct, IPixel
+ {
+ using (Image image = provider.GetImage())
+ {
+ image.Mutate(x => x.DetectEdges());
+ image.DebugSave(provider, grayscale: true);
+ }
+ }
+
+ [Theory]
+ [WithFile(TestImages.Gif.Giphy, DefaultPixelType)]
+ public void DetectEdges_IsAppliedToAllFrames(TestImageProvider provider)
+ where TPixel : struct, IPixel
+ {
+ using (Image image = provider.GetImage())
+ {
+ image.Mutate(x => x.DetectEdges());
+ image.DebugSave(provider, extension: "gif");
+ }
+ }
+
[Theory]
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
- public void DetectEdgesInBox(TestImageProvider provider)
+ public void DetectEdges_InBox(TestImageProvider provider)
where TPixel : struct, IPixel
{
using (Image source = provider.GetImage())
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
index 45209c3c8..c6585edaa 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
@@ -3,6 +3,7 @@
// Licensed under the Apache License, Version 2.0.
//
+// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests.Processing.Processors.Transforms
{
using ImageSharp.PixelFormats;
@@ -34,23 +35,11 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
{ "Welch", new WelchResampler() }
};
- [Theory]
- [WithFile(TestImages.Gif.Giphy, DefaultPixelType)]
- public void ResizeShouldApplyToAllFrames(TestImageProvider provider)
- where TPixel : struct, IPixel
- {
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, true));
- image.DebugSave(provider, extension: Extensions.Gif);
- }
- }
-
[Theory]
[WithTestPatternImages(nameof(AllReSamplers), 100, 100, DefaultPixelType, 0.5f)]
[WithFileCollection(nameof(CommonTestImages), nameof(AllReSamplers), DefaultPixelType, 0.5f)]
[WithFileCollection(nameof(CommonTestImages), nameof(AllReSamplers), DefaultPixelType, 0.3f)]
- public void ResizeFullImage(TestImageProvider provider, string name, IResampler sampler, float ratio)
+ public void Resize_WorksWithAllResamplers(TestImageProvider provider, string name, IResampler sampler, float ratio)
where TPixel : struct, IPixel
{
using (Image image = provider.GetImage())
@@ -64,7 +53,7 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
[Theory]
[WithTestPatternImages(100, 100, DefaultPixelType)]
- public void ResizeFullImage_Compand(TestImageProvider provider)
+ public void Resize_Compand(TestImageProvider provider)
where TPixel : struct, IPixel
{
using (Image image = provider.GetImage())
@@ -74,6 +63,30 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
}
}
+ [Theory]
+ [WithTestPatternImages(50, 50, CommonNonDefaultPixelTypes)]
+ public void Resize_IsNotBoundToSinglePixelType(TestImageProvider provider)
+ where TPixel : struct, IPixel
+ {
+ using (Image image = provider.GetImage())
+ {
+ image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, true));
+ image.DebugSave(provider);
+ }
+ }
+
+ [Theory]
+ [WithFile(TestImages.Gif.Giphy, DefaultPixelType)]
+ public void Resize_IsAppliedToAllFrames(TestImageProvider provider)
+ where TPixel : struct, IPixel
+ {
+ using (Image image = provider.GetImage())
+ {
+ image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, true));
+ image.DebugSave(provider, extension: Extensions.Gif);
+ }
+ }
+
[Theory]
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeFromSourceRectangle(TestImageProvider provider)
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageDimensionsMismatchException.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs
similarity index 100%
rename from tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageDimensionsMismatchException.cs
rename to tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImageDimensionsMismatchException.cs
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImagePixelsAreDifferentException.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagePixelsAreDifferentException.cs
similarity index 100%
rename from tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImagePixelsAreDifferentException.cs
rename to tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagePixelsAreDifferentException.cs
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImagesSimilarityException.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagesSimilarityException.cs
similarity index 100%
rename from tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImagesSimilarityException.cs
rename to tests/ImageSharp.Tests/TestUtilities/ImageComparison/Exceptions/ImagesSimilarityException.cs
diff --git a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
index 645a4dc59..5eee119f3 100644
--- a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
@@ -12,7 +12,7 @@ namespace ImageSharp.Tests
/// They trigger the desired parametrization for .
///
[Flags]
- public enum PixelTypes : uint
+ public enum PixelTypes
{
Undefined = 0,
@@ -52,11 +52,11 @@ namespace ImageSharp.Tests
Short4 = 1 << 17,
- Rgb24 = 18,
+ Rgb24 = 1 << 18,
- Bgr24 = 19,
+ Bgr24 = 1 << 19,
- Bgra32 = 20,
+ Bgra32 = 1 << 20,
// TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper
diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs
index e42cbe193..835561fe0 100644
--- a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs
@@ -103,7 +103,7 @@ namespace ImageSharp.Tests
return string.Join(separator, items.Select(o => string.Format(CultureInfo.InvariantCulture, "{0}", o)));
}
- public static Type ToType(this PixelTypes pixelType) => PixelTypes2ClrTypes[pixelType];
+ public static Type GetClrType(this PixelTypes pixelType) => PixelTypes2ClrTypes[pixelType];
///
/// Returns the enumerations for the given type.
@@ -112,6 +112,8 @@ namespace ImageSharp.Tests
///
public static PixelTypes GetPixelType(this Type colorStructClrType) => ClrTypes2PixelTypes[colorStructClrType];
+
+
public static IEnumerable> ExpandAllTypes(this PixelTypes pixelTypes)
{
if (pixelTypes == PixelTypes.Undefined)
@@ -124,11 +126,20 @@ namespace ImageSharp.Tests
return PixelTypes2ClrTypes;
}
- return AllConcretePixelTypes
- .Where(pt => pixelTypes.HasFlag(pt))
- .Select(pt => new KeyValuePair(pt, pt.ToType()));
+ var result = new Dictionary();
+ foreach (PixelTypes pt in AllConcretePixelTypes)
+ {
+ if (pixelTypes.HasAll(pt))
+ {
+ result[pt] = pt.GetClrType();
+ }
+ }
+ return result;
}
+ internal static bool HasAll(this PixelTypes pixelTypes, PixelTypes flagsToCheck) =>
+ (pixelTypes & flagsToCheck) == flagsToCheck;
+
///
/// Enumerate all available -s
///
diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs
index 9c7b20e7e..edee09c90 100644
--- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs
@@ -85,7 +85,7 @@ namespace ImageSharp.Tests
[InlineData(PixelTypes.Rgba32, typeof(Rgba32))]
public void ToType(PixelTypes pt, Type expectedType)
{
- Assert.Equal(pt.ToType(), expectedType);
+ Assert.Equal(pt.GetClrType(), expectedType);
}
[Theory]
@@ -105,7 +105,7 @@ namespace ImageSharp.Tests
}
[Fact]
- public void ToTypes()
+ public void ExpandAllTypes_1()
{
PixelTypes pixelTypes = PixelTypes.Alpha8 | PixelTypes.Bgr565 | PixelTypes.HalfVector2 | PixelTypes.Rgba32;
@@ -119,6 +119,29 @@ namespace ImageSharp.Tests
AssertContainsPixelType(PixelTypes.Rgba32, expanded);
}
+ [Fact]
+ public void ExpandAllTypes_2()
+ {
+ PixelTypes pixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector;
+
+ IEnumerable> expanded = pixelTypes.ExpandAllTypes();
+
+ Assert.Equal(3, expanded.Count());
+
+ AssertContainsPixelType(PixelTypes.Rgba32, expanded);
+ AssertContainsPixelType(PixelTypes.Bgra32, expanded);
+ AssertContainsPixelType(PixelTypes.RgbaVector, expanded);
+ }
+
+ [Fact]
+ public void Anyad()
+ {
+ PixelTypes pixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector;
+ PixelTypes anyad = pixelTypes & PixelTypes.Bgr565;
+
+ this.Output.WriteLine(anyad.ToString());
+ }
+
[Fact]
public void ToTypes_All()
{