diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs index b4ba02a95..11ef90e49 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.PixelFormats internal class PixelOperations : PixelOperations { /// - public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); + public override PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated); /// public override void FromVector4Destructive( diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs index c67be71e5..2e9db245f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs @@ -164,7 +164,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly bool Equals(Short4 other) => this.PackedValue.Equals(other); + public readonly bool Equals(Short4 other) => this.PackedValue.Equals(other.PackedValue); /// /// Gets the hash code for the current instance. 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 5566ccd74..5b1abb749 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs @@ -19,6 +19,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public A8_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = A8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -44,6 +46,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Argb32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Argb32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -69,6 +73,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgr24_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgr24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -94,6 +100,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgr565_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgr565.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -119,6 +127,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgra32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgra32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -144,6 +154,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgra4444_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgra4444.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -169,6 +181,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Bgra5551_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Bgra5551.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -194,6 +208,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Byte4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Byte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -219,6 +235,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public HalfSingle_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = HalfSingle.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -244,6 +262,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public HalfVector2_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = HalfVector2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -269,6 +289,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public HalfVector4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = HalfVector4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -294,6 +316,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public L16_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = L16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -319,6 +343,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public L8_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = L8.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -344,6 +370,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public La16_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = La16.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -369,6 +397,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public La32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = La32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -394,6 +424,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedByte2_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = NormalizedByte2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -419,6 +451,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedByte4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = NormalizedByte4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -444,6 +478,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedShort2_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = NormalizedShort2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -469,6 +505,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public NormalizedShort4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = NormalizedShort4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -494,6 +532,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rg32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rg32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -519,6 +559,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgb24_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgb24.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -544,6 +586,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgb48_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgb48.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -569,6 +613,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgba1010102_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgba1010102.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -594,6 +640,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgba32_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgba32.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -619,6 +667,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Rgba64_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Rgba64.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -644,6 +694,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public RgbaVector_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = RgbaVector.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -669,6 +721,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Short2_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Short2.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] @@ -694,6 +748,8 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations public Short4_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = Short4.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude index cd6e2a09d..bc093be85 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude @@ -75,6 +75,8 @@ using Xunit.Abstractions; public <#=pixelType#>_OperationsTests(ITestOutputHelper output) : base(output) { + var alphaRepresentation = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation; + this.HasUnassociatedAlpha = alphaRepresentation == PixelAlphaRepresentation.Unassociated; } [Fact] diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index 3c4b9dc79..d18c3c860 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations null; #endif - protected bool HasAlpha { get; set; } = true; + protected bool HasUnassociatedAlpha { get; set; } = true; protected PixelOperationsTests(ITestOutputHelper output) : base(output) @@ -168,7 +168,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.Premultiply(ref v); } @@ -176,7 +176,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations void ExpectedAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.UnPremultiply(ref v); } @@ -188,7 +188,14 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), PixelConversionModifiers.Premultiply)); + (s, d) => + { + PixelConversionModifiers modifiers = this.HasUnassociatedAlpha + ? PixelConversionModifiers.Premultiply + : PixelConversionModifiers.None; + + Operations.FromVector4Destructive(this.Configuration, s, d.GetSpan(), modifiers); + }); } [Theory] @@ -197,7 +204,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { void SourceAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.Premultiply(ref v); } @@ -205,7 +212,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations void ExpectedAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.UnPremultiply(ref v); } @@ -217,11 +224,18 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive( - this.Configuration, - s, - d.GetSpan(), - PixelConversionModifiers.Premultiply | PixelConversionModifiers.Scale)); + (s, d) => + { + PixelConversionModifiers modifiers = this.HasUnassociatedAlpha + ? PixelConversionModifiers.Premultiply + : PixelConversionModifiers.None; + + Operations.FromVector4Destructive( + this.Configuration, + s, + d.GetSpan(), + modifiers | PixelConversionModifiers.Scale); + }); } [Theory] @@ -232,7 +246,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { SRgbCompanding.Expand(ref v); - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.Premultiply(ref v); } @@ -240,7 +254,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations void ExpectedAction(ref Vector4 v) { - if (this.HasAlpha) + if (this.HasUnassociatedAlpha) { Vector4Utilities.UnPremultiply(ref v); } @@ -254,11 +268,18 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations TestOperation( source, expected, - (s, d) => Operations.FromVector4Destructive( - this.Configuration, - s, - d.GetSpan(), - PixelConversionModifiers.SRgbCompand | PixelConversionModifiers.Premultiply | PixelConversionModifiers.Scale)); + (s, d) => + { + PixelConversionModifiers modifiers = this.HasUnassociatedAlpha + ? PixelConversionModifiers.Premultiply + : PixelConversionModifiers.None; + + Operations.FromVector4Destructive( + this.Configuration, + s, + d.GetSpan(), + modifiers | PixelConversionModifiers.SRgbCompand | PixelConversionModifiers.Scale); + }); } [Theory]