diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs index 5b1abb749..9d6ec8960 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs @@ -3,7 +3,6 @@ // -using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; using Xunit; using Xunit.Abstractions; @@ -23,20 +22,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => A8.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = A8.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = A8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -50,20 +44,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Argb32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Argb32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Argb32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -77,20 +66,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgr24.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgr24.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgr24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -104,20 +88,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgr565.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgr565.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgr565.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -131,20 +110,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgra32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgra32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgra32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -158,20 +132,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgra4444.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgra4444.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgra4444.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -185,20 +154,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Bgra5551.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Bgra5551.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Bgra5551.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -212,20 +176,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Byte4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Byte4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Byte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -239,20 +198,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => HalfSingle.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = HalfSingle.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = HalfSingle.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -266,20 +220,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => HalfVector2.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = HalfVector2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = HalfVector2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -293,20 +242,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => HalfVector4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = HalfVector4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = HalfVector4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -320,20 +264,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => L16.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = L16.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = L16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -347,20 +286,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => L8.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = L8.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = L8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -374,20 +308,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => La16.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = La16.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = La16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -401,20 +330,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => La32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = La32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = La32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -428,20 +352,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => NormalizedByte2.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = NormalizedByte2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = NormalizedByte2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -455,20 +374,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => NormalizedByte4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = NormalizedByte4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = NormalizedByte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -482,20 +396,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => NormalizedShort2.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = NormalizedShort2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = NormalizedShort2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -509,20 +418,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => NormalizedShort4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = NormalizedShort4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = NormalizedShort4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -536,20 +440,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rg32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rg32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rg32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -563,20 +462,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgb24.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgb24.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgb24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -590,20 +484,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgb48.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgb48.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgb48.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -617,20 +506,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgba1010102.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgba1010102.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgba1010102.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -644,20 +528,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgba32.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgba32.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgba32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -671,20 +550,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Rgba64.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Rgba64.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Rgba64.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -698,20 +572,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => RgbaVector.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = RgbaVector.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = RgbaVector.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } @@ -725,20 +594,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Short2.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Short2.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Short2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } @@ -752,20 +616,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + protected override PixelOperations Operations => Short4.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = Short4.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = Short4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude index bc093be85..50026b3f8 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude @@ -8,7 +8,6 @@ // -using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; using Xunit; using Xunit.Abstractions; @@ -79,20 +78,15 @@ using Xunit.Abstractions; this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } - [Fact] - public void IsSpecialImplementation() => Assert.IsType<<#=pixelType#>.PixelOperations>(PixelOperations<<#=pixelType#>>.Instance); + protected override PixelOperations<<#=pixelType#>> Operations => <#=pixelType#>.PixelOperations.Instance; [Fact] - public void PixelTypeInfoHasCorrectBitsPerPixel() - { - var bits = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel; - Assert.Equal(Unsafe.SizeOf<<#=pixelType#>>() * 8, bits); - } + public void IsSpecialImplementation() => Assert.IsType<<#=pixelType#>.PixelOperations>(PixelOperations<<#=pixelType#>>.Instance); [Fact] public void PixelTypeInfoHasCorrectAlphaRepresentation() { - var alphaRepresentation = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; Assert.Equal(<#=alpha#>, alphaRepresentation); } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index d18c3c860..543184e34 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations protected Configuration Configuration => Configuration.Default; - internal static PixelOperations Operations => PixelOperations.Instance; + protected virtual PixelOperations Operations => PixelOperations.Instance; internal static TPixel[] CreateExpectedPixelData(Vector4[] source, RefAction vectorModifier = null) { @@ -105,6 +105,33 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations return expected; } + [Fact] + public void PixelTypeInfoHasCorrectBitsPerPixel() + { + var bits = this.Operations.GetPixelTypeInfo().BitsPerPixel; + Assert.Equal(Unsafe.SizeOf() * 8, bits); + } + + [Fact] + public void PixelAlphaRepresentation_DefinesPresenceOfAlphaChannel() + { + // We use 0 - 255 as we have pixel formats that store + // the alpha component in less than 8 bits. + const byte Alpha = byte.MinValue; + const byte NoAlpha = byte.MaxValue; + + TPixel pixel = default; + pixel.FromRgba32(new Rgba32(0, 0, 0, Alpha)); + + Rgba32 dest = default; + pixel.ToRgba32(ref dest); + + bool hasAlpha = this.Operations.GetPixelTypeInfo().AlphaRepresentation != PixelAlphaRepresentation.None; + + byte expectedAlpha = hasAlpha ? Alpha : NoAlpha; + Assert.Equal(expectedAlpha, dest.A); + } + [Theory] [MemberData(nameof(ArraySizesData))] public void FromVector4(int count) @@ -115,7 +142,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan())); } [Theory] @@ -131,7 +158,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations (s, d) => { Span destPixels = d.GetSpan(); - Operations.FromVector4Destructive(this.Configuration, (Span)s, destPixels, PixelConversionModifiers.Scale); + this.Operations.FromVector4Destructive(this.Configuration, (Span)s, destPixels, PixelConversionModifiers.Scale); }); } @@ -155,7 +182,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive( + (s, d) => this.Operations.FromVector4Destructive( this.Configuration, s, d.GetSpan(), @@ -194,7 +221,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations ? PixelConversionModifiers.Premultiply : PixelConversionModifiers.None; - Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), modifiers); + this.Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), modifiers); }); } @@ -230,7 +257,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations ? PixelConversionModifiers.Premultiply : PixelConversionModifiers.None; - Operations.FromVector4Destructive( + this.Operations.FromVector4Destructive( this.Configuration, s, d.GetSpan(), @@ -274,7 +301,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations ? PixelConversionModifiers.Premultiply : PixelConversionModifiers.None; - Operations.FromVector4Destructive( + this.Operations.FromVector4Destructive( this.Configuration, s, d.GetSpan(), @@ -292,7 +319,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.ToVector4(this.Configuration, s, d.GetSpan())); } public static readonly TheoryData Generic_To_Data = new TheoryData @@ -317,7 +344,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations PixelConverterTests.ReferenceImplementations.To(this.Configuration, source, expected); - TestOperation(source, expected, (s, d) => Operations.To(this.Configuration, (ReadOnlySpan)s, d.GetSpan())); + TestOperation(source, expected, (s, d) => this.Operations.To(this.Configuration, (ReadOnlySpan)s, d.GetSpan())); } [Theory] @@ -333,7 +360,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations (s, d) => { Span destVectors = d.GetSpan(); - Operations.ToVector4(this.Configuration, (ReadOnlySpan)s, destVectors, PixelConversionModifiers.Scale); + this.Operations.ToVector4(this.Configuration, (ReadOnlySpan)s, destVectors, PixelConversionModifiers.Scale); }); } @@ -357,7 +384,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4( + (s, d) => this.Operations.ToVector4( this.Configuration, s, d.GetSpan(), @@ -384,7 +411,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4(this.Configuration, s, d.GetSpan(), PixelConversionModifiers.Premultiply)); + (s, d) => this.Operations.ToVector4(this.Configuration, s, d.GetSpan(), PixelConversionModifiers.Premultiply)); } [Theory] @@ -407,7 +434,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4( + (s, d) => this.Operations.ToVector4( this.Configuration, s, d.GetSpan(), @@ -436,7 +463,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToVector4( + (s, d) => this.Operations.ToVector4( this.Configuration, s, d.GetSpan(), @@ -460,7 +487,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromArgb32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromArgb32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -485,7 +512,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToArgb32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToArgb32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -505,7 +532,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromBgr24Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromBgr24Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -528,7 +555,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToBgr24Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToBgr24Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -548,7 +575,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromBgra32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromBgra32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -572,7 +599,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToBgra32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToBgra32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -594,7 +621,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromBgra5551Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromBgra5551Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -618,7 +645,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToBgra5551Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToBgra5551Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -637,7 +664,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromL8(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.FromL8(this.Configuration, s, d.GetSpan())); } [Theory] @@ -655,7 +682,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToL8(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.ToL8(this.Configuration, s, d.GetSpan())); } [Theory] @@ -679,7 +706,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromL16(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.FromL16(this.Configuration, s, d.GetSpan())); } [Theory] @@ -697,7 +724,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToL16(this.Configuration, s, d.GetSpan())); + (s, d) => this.Operations.ToL16(this.Configuration, s, d.GetSpan())); } [Theory] @@ -719,7 +746,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromLa16Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromLa16Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -743,7 +770,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToLa16Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToLa16Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -765,7 +792,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromLa32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromLa32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -791,7 +818,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToLa32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToLa32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -811,7 +838,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromRgb24Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromRgb24Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -834,7 +861,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToRgb24Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToRgb24Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -854,7 +881,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromRgba32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromRgba32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -878,7 +905,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToRgba32Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToRgba32Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -898,7 +925,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromRgb48Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromRgb48Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -925,7 +952,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToRgb48Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToRgb48Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -945,7 +972,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromRgba64Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.FromRgba64Bytes(this.Configuration, s, d.GetSpan(), count)); } [Theory] @@ -974,7 +1001,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.ToRgba64Bytes(this.Configuration, s, d.GetSpan(), count)); + (s, d) => this.Operations.ToRgba64Bytes(this.Configuration, s, d.GetSpan(), count)); } public delegate void RefAction(ref T1 arg1);