From 151bacc0203f097f7aa09d6f3adb52cd97171a78 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 23 Oct 2021 19:22:57 +0200 Subject: [PATCH 1/2] Use Convert.To after rounding to avoid different behavior on ARM vs x86/x64 --- .../PixelImplementations/NormalizedByte2.cs | 12 ++++++---- .../PixelImplementations/NormalizedByte4.cs | 20 ++++++++-------- .../PixelImplementations/NormalizedShort2.cs | 11 +++++---- .../PixelImplementations/NormalizedShort4.cs | 23 ++++++++++--------- .../PixelImplementations/Short2.cs | 4 ++-- .../PixelImplementations/Short4.cs | 8 +++---- 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs index 8b244d391..720a1eef6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs @@ -15,7 +15,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// public partial struct NormalizedByte2 : IPixel, IPackedVector { - private static readonly Vector2 Half = new Vector2(127); + private const float MaxPos = 127F; + + private static readonly Vector2 Half = new Vector2(MaxPos); private static readonly Vector2 MinusOne = new Vector2(-1F); /// @@ -154,8 +156,8 @@ namespace SixLabors.ImageSharp.PixelFormats public readonly Vector2 ToVector2() { return new Vector2( - (sbyte)((this.PackedValue >> 0) & 0xFF) / 127F, - (sbyte)((this.PackedValue >> 8) & 0xFF) / 127F); + (sbyte)((this.PackedValue >> 0) & 0xFF) / MaxPos, + (sbyte)((this.PackedValue >> 8) & 0xFF) / MaxPos); } /// @@ -181,8 +183,8 @@ namespace SixLabors.ImageSharp.PixelFormats { vector = Vector2.Clamp(vector, MinusOne, Vector2.One) * Half; - int byte2 = ((ushort)Math.Round(vector.X) & 0xFF) << 0; - int byte1 = ((ushort)Math.Round(vector.Y) & 0xFF) << 8; + int byte2 = ((ushort)Convert.ToInt16(Math.Round(vector.X)) & 0xFF) << 0; + int byte1 = ((ushort)Convert.ToInt16(Math.Round(vector.Y)) & 0xFF) << 8; return (ushort)(byte2 | byte1); } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs index 84f0bb022..d1b4b73f2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs @@ -15,7 +15,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// public partial struct NormalizedByte4 : IPixel, IPackedVector { - private static readonly Vector4 Half = new Vector4(127); + private const float MaxPos = 127F; + + private static readonly Vector4 Half = new Vector4(MaxPos); private static readonly Vector4 MinusOne = new Vector4(-1F); /// @@ -92,10 +94,10 @@ namespace SixLabors.ImageSharp.PixelFormats public readonly Vector4 ToVector4() { return new Vector4( - (sbyte)((this.PackedValue >> 0) & 0xFF) / 127F, - (sbyte)((this.PackedValue >> 8) & 0xFF) / 127F, - (sbyte)((this.PackedValue >> 16) & 0xFF) / 127F, - (sbyte)((this.PackedValue >> 24) & 0xFF) / 127F); + (sbyte)((this.PackedValue >> 0) & 0xFF) / MaxPos, + (sbyte)((this.PackedValue >> 8) & 0xFF) / MaxPos, + (sbyte)((this.PackedValue >> 16) & 0xFF) / MaxPos, + (sbyte)((this.PackedValue >> 24) & 0xFF) / MaxPos); } /// @@ -176,10 +178,10 @@ namespace SixLabors.ImageSharp.PixelFormats { vector = Numerics.Clamp(vector, MinusOne, Vector4.One) * Half; - uint byte4 = ((uint)MathF.Round(vector.X) & 0xFF) << 0; - uint byte3 = ((uint)MathF.Round(vector.Y) & 0xFF) << 8; - uint byte2 = ((uint)MathF.Round(vector.Z) & 0xFF) << 16; - uint byte1 = ((uint)MathF.Round(vector.W) & 0xFF) << 24; + uint byte4 = ((uint)Convert.ToInt16(MathF.Round(vector.X)) & 0xFF) << 0; + uint byte3 = ((uint)Convert.ToInt16(MathF.Round(vector.Y)) & 0xFF) << 8; + uint byte2 = ((uint)Convert.ToInt16(MathF.Round(vector.Z)) & 0xFF) << 16; + uint byte1 = ((uint)Convert.ToInt16(MathF.Round(vector.W)) & 0xFF) << 24; return byte4 | byte3 | byte2 | byte1; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs index 97bbc1206..d08a54603 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs @@ -15,7 +15,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// public partial struct NormalizedShort2 : IPixel, IPackedVector { - private static readonly Vector2 Max = new Vector2(0x7FFF); + // Largest two byte positive number 0xFFFF >> 1; + private const float MaxPos = 0x7FFF; + + private static readonly Vector2 Max = new Vector2(MaxPos); private static readonly Vector2 Min = Vector2.Negate(Max); /// @@ -156,11 +159,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Vector2 ToVector2() { - const float MaxVal = 0x7FFF; - return new Vector2( - (short)(this.PackedValue & 0xFFFF) / MaxVal, - (short)(this.PackedValue >> 0x10) / MaxVal); + (short)(this.PackedValue & 0xFFFF) / MaxPos, + (short)(this.PackedValue >> 0x10) / MaxPos); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs index a3fd8989c..158b6eb4b 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs @@ -15,7 +15,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// public partial struct NormalizedShort4 : IPixel, IPackedVector { - private static readonly Vector4 Max = new Vector4(0x7FFF); + // Largest two byte positive number 0xFFFF >> 1; + private const float MaxPos = 0x7FFF; + + private static readonly Vector4 Max = new Vector4(MaxPos); private static readonly Vector4 Min = Vector4.Negate(Max); /// @@ -91,13 +94,11 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(InliningOptions.ShortMethod)] public readonly Vector4 ToVector4() { - const float MaxVal = 0x7FFF; - return new Vector4( - (short)((this.PackedValue >> 0x00) & 0xFFFF) / MaxVal, - (short)((this.PackedValue >> 0x10) & 0xFFFF) / MaxVal, - (short)((this.PackedValue >> 0x20) & 0xFFFF) / MaxVal, - (short)((this.PackedValue >> 0x30) & 0xFFFF) / MaxVal); + (short)((this.PackedValue >> 0x00) & 0xFFFF) / MaxPos, + (short)((this.PackedValue >> 0x10) & 0xFFFF) / MaxPos, + (short)((this.PackedValue >> 0x20) & 0xFFFF) / MaxPos, + (short)((this.PackedValue >> 0x30) & 0xFFFF) / MaxPos); } /// @@ -180,10 +181,10 @@ namespace SixLabors.ImageSharp.PixelFormats vector = Numerics.Clamp(vector, Min, Max); // Round rather than truncate. - ulong word4 = ((ulong)MathF.Round(vector.X) & 0xFFFF) << 0x00; - ulong word3 = ((ulong)MathF.Round(vector.Y) & 0xFFFF) << 0x10; - ulong word2 = ((ulong)MathF.Round(vector.Z) & 0xFFFF) << 0x20; - ulong word1 = ((ulong)MathF.Round(vector.W) & 0xFFFF) << 0x30; + ulong word4 = ((ulong)Convert.ToInt32(MathF.Round(vector.X)) & 0xFFFF) << 0x00; + ulong word3 = ((ulong)Convert.ToInt32(MathF.Round(vector.Y)) & 0xFFFF) << 0x10; + ulong word2 = ((ulong)Convert.ToInt32(MathF.Round(vector.Z)) & 0xFFFF) << 0x20; + ulong word1 = ((ulong)Convert.ToInt32(MathF.Round(vector.W)) & 0xFFFF) << 0x30; return word4 | word3 | word2 | word1; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs index f7a4f9994..101027a78 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs @@ -181,8 +181,8 @@ namespace SixLabors.ImageSharp.PixelFormats private static uint Pack(Vector2 vector) { vector = Vector2.Clamp(vector, Min, Max); - uint word2 = (uint)Math.Round(vector.X) & 0xFFFF; - uint word1 = ((uint)Math.Round(vector.Y) & 0xFFFF) << 0x10; + uint word2 = (uint)Convert.ToInt32(Math.Round(vector.X)) & 0xFFFF; + uint word1 = ((uint)Convert.ToInt32(Math.Round(vector.Y)) & 0xFFFF) << 0x10; return word2 | word1; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs index 409f46c72..86a519297 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs @@ -186,10 +186,10 @@ namespace SixLabors.ImageSharp.PixelFormats vector = Numerics.Clamp(vector, Min, Max); // Clamp the value between min and max values - ulong word4 = ((ulong)Math.Round(vector.X) & 0xFFFF) << 0x00; - ulong word3 = ((ulong)Math.Round(vector.Y) & 0xFFFF) << 0x10; - ulong word2 = ((ulong)Math.Round(vector.Z) & 0xFFFF) << 0x20; - ulong word1 = ((ulong)Math.Round(vector.W) & 0xFFFF) << 0x30; + ulong word4 = ((ulong)Convert.ToInt32(Math.Round(vector.X)) & 0xFFFF) << 0x00; + ulong word3 = ((ulong)Convert.ToInt32(Math.Round(vector.Y)) & 0xFFFF) << 0x10; + ulong word2 = ((ulong)Convert.ToInt32(Math.Round(vector.Z)) & 0xFFFF) << 0x20; + ulong word1 = ((ulong)Convert.ToInt32(Math.Round(vector.W)) & 0xFFFF) << 0x30; return word4 | word3 | word2 | word1; } From 49e57722b815ec550e15cd41fe4e3202abe5287c Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 23 Oct 2021 20:05:25 +0200 Subject: [PATCH 2/2] Cleanup --- .../PixelFormats/PixelImplementations/A8.cs | 2 +- .../PixelImplementations/Argb32.cs | 6 +-- .../PixelImplementations/Bgr24.cs | 4 +- .../PixelImplementations/Bgr565.cs | 12 ++---- .../PixelImplementations/Bgra32.cs | 6 +-- .../PixelImplementations/Bgra4444.cs | 5 +-- .../PixelImplementations/Bgra5551.cs | 10 +---- .../PixelImplementations/Byte4.cs | 10 +---- .../PixelImplementations/HalfSingle.cs | 7 +--- .../PixelImplementations/HalfVector2.cs | 5 +-- .../PixelImplementations/HalfVector4.cs | 10 +---- .../PixelFormats/PixelImplementations/L16.cs | 25 +++-------- .../PixelFormats/PixelImplementations/L8.cs | 4 +- .../PixelFormats/PixelImplementations/La16.cs | 6 +-- .../PixelFormats/PixelImplementations/La32.cs | 2 +- .../PixelImplementations/NormalizedByte2.cs | 11 ++--- .../PixelImplementations/NormalizedByte4.cs | 14 ++----- .../PixelImplementations/NormalizedShort2.cs | 12 ++---- .../PixelImplementations/NormalizedShort4.cs | 12 ++---- .../PixelFormats/PixelImplementations/Rg32.cs | 9 ++-- .../PixelImplementations/Rgb24.cs | 4 +- .../PixelImplementations/Rgb48.cs | 2 +- .../PixelImplementations/Rgba1010102.cs | 12 ++---- .../PixelImplementations/Rgba32.cs | 19 ++++----- .../PixelImplementations/Rgba64.cs | 2 +- .../PixelImplementations/RgbaVector.cs | 13 +++--- .../PixelImplementations/Short2.cs | 8 ++-- .../PixelFormats/Bgr24Tests.cs | 3 +- .../PixelFormats/Bgra32Tests.cs | 11 +++-- .../ImageSharp.Tests/PixelFormats/L8Tests.cs | 24 +---------- .../PixelFormats/La16Tests.cs | 24 +---------- .../PixelFormats/PixelBlenderTests.cs | 6 +-- .../PixelFormats/PixelConverterTests.cs | 42 +++++++++---------- .../PixelFormats/Rgb24Tests.cs | 4 +- .../PixelFormats/UnPackedPixelTests.cs | 2 +- 35 files changed, 111 insertions(+), 237 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs index 77df2bc80..cca7ff7db 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() => new Vector4(0, 0, 0, this.PackedValue / 255F); + public readonly Vector4 ToVector4() => new(0, 0, 0, this.PackedValue / 255F); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs index 3ac9b523f..8c1b04ff1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs @@ -44,12 +44,12 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// The maximum byte value. /// - private static readonly Vector4 MaxBytes = new Vector4(255); + private static readonly Vector4 MaxBytes = new(255); /// /// The half vector value. /// - private static readonly Vector4 Half = new Vector4(0.5F); + private static readonly Vector4 Half = new(0.5F); /// /// Initializes a new instance of the struct. @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// The . /// The . [MethodImpl(InliningOptions.ShortMethod)] - public static implicit operator Color(Argb32 source) => new Color(source); + public static implicit operator Color(Argb32 source) => new(source); /// /// Converts a to . diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs index 6cff5fd77..22e983a65 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// The . /// The . [MethodImpl(InliningOptions.ShortMethod)] - public static implicit operator Color(Bgr24 source) => new Color(source); + public static implicit operator Color(Bgr24 source) => new(source); /// /// Converts a to . @@ -225,7 +225,7 @@ namespace SixLabors.ImageSharp.PixelFormats public override readonly bool Equals(object obj) => obj is Bgr24 other && this.Equals(other); /// - public override readonly string ToString() => $"Bgra({this.B}, {this.G}, {this.R})"; + public override readonly string ToString() => $"Bgr24({this.B}, {this.G}, {this.R})"; /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs index fd12b6837..5585310b9 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() => new Vector4(this.ToVector3(), 1F); + public readonly Vector4 ToVector4() => new(this.ToVector3(), 1F); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -125,10 +125,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -144,13 +141,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// The . [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector3 ToVector3() - { - return new Vector3( + public readonly Vector3 ToVector3() => new( ((this.PackedValue >> 11) & 0x1F) * (1F / 31F), ((this.PackedValue >> 5) & 0x3F) * (1F / 63F), (this.PackedValue & 0x1F) * (1F / 31F)); - } /// public override readonly bool Equals(object obj) => obj is Bgr565 other && this.Equals(other); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs index 190345dda..be4e178c2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs @@ -41,12 +41,12 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// The maximum byte value. /// - private static readonly Vector4 MaxBytes = new Vector4(255); + private static readonly Vector4 MaxBytes = new(255); /// /// The half vector value. /// - private static readonly Vector4 Half = new Vector4(0.5F); + private static readonly Vector4 Half = new(0.5F); /// /// Initializes a new instance of the struct. @@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// The . /// The . [MethodImpl(InliningOptions.ShortMethod)] - public static implicit operator Color(Bgra32 source) => new Color(source); + public static implicit operator Color(Bgra32 source) => new(source); /// /// Converts a to . diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs index 8fa5219d5..3578f1dd3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs @@ -128,10 +128,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs index b3a0d0896..0254397c3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs @@ -78,14 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() - { - return new Vector4( + public readonly Vector4 ToVector4() => new( ((this.PackedValue >> 10) & 0x1F) / 31F, ((this.PackedValue >> 5) & 0x1F) / 31F, ((this.PackedValue >> 0) & 0x1F) / 31F, (this.PackedValue >> 15) & 0x01); - } /// [MethodImpl(InliningOptions.ShortMethod)] @@ -129,10 +126,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs index e26121291..0995f8417 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs @@ -78,14 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() - { - return new Vector4( + public readonly Vector4 ToVector4() => new( this.PackedValue & 0xFF, (this.PackedValue >> 0x8) & 0xFF, (this.PackedValue >> 0x10) & 0xFF, (this.PackedValue >> 0x18) & 0xFF); - } /// [MethodImpl(InliningOptions.ShortMethod)] @@ -129,10 +126,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs index 5c4aa1cfb..b0ef0f6a9 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() => new Vector4(this.ToSingle(), 0, 0, 1F); + public readonly Vector4 ToVector4() => new(this.ToSingle(), 0, 0, 1F); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -118,10 +118,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs index 39cb6f799..8be826130 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs @@ -129,10 +129,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs index 9826d61a2..955b274ac 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs @@ -86,14 +86,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() - { - return new Vector4( + public readonly Vector4 ToVector4() => new( HalfTypeHelper.Unpack((ushort)this.PackedValue), HalfTypeHelper.Unpack((ushort)(this.PackedValue >> 0x10)), HalfTypeHelper.Unpack((ushort)(this.PackedValue >> 0x20)), HalfTypeHelper.Unpack((ushort)(this.PackedValue >> 0x30))); - } /// [MethodImpl(InliningOptions.ShortMethod)] @@ -137,10 +134,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs index dd31aae2f..6d1128dd2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs @@ -72,33 +72,24 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromArgb32(Argb32 source) - { - this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + public void FromArgb32(Argb32 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance( ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); - } /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromBgr24(Bgr24 source) - { - this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + public void FromBgr24(Bgr24 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance( ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); - } /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromBgra32(Bgra32 source) - { - this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + public void FromBgra32(Bgra32 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance( ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); - } /// [MethodImpl(InliningOptions.ShortMethod)] @@ -122,23 +113,17 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgb24(Rgb24 source) - { - this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + public void FromRgb24(Rgb24 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance( ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); - } /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromRgba32(Rgba32 source) - { - this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + public void FromRgba32(Rgba32 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance( ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); - } /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs index c570c33a1..ffff60be5 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs @@ -14,8 +14,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// public partial struct L8 : IPixel, IPackedVector { - private static readonly Vector4 MaxBytes = new Vector4(255F); - private static readonly Vector4 Half = new Vector4(0.5F); + private static readonly Vector4 MaxBytes = new(255F); + private static readonly Vector4 Half = new(0.5F); /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs index 5a69431a1..877aaed81 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs @@ -16,8 +16,8 @@ namespace SixLabors.ImageSharp.PixelFormats [StructLayout(LayoutKind.Explicit)] public partial struct La16 : IPixel, IPackedVector { - private static readonly Vector4 MaxBytes = new Vector4(255F); - private static readonly Vector4 Half = new Vector4(0.5F); + private static readonly Vector4 MaxBytes = new(255F); + private static readonly Vector4 Half = new(0.5F); /// /// Gets or sets the luminance component. @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Initializes a new instance of the struct. /// /// The luminance component. - /// The alpha componant. + /// The alpha component. public La16(byte l, byte a) { this.L = l; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs index 66d0e38c7..f19f22813 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// Initializes a new instance of the struct. /// /// The luminance component. - /// The alpha componant. + /// The alpha component. public La32(ushort l, ushort a) { this.L = l; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs index 720a1eef6..62eaf949d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs @@ -17,8 +17,8 @@ namespace SixLabors.ImageSharp.PixelFormats { private const float MaxPos = 127F; - private static readonly Vector2 Half = new Vector2(MaxPos); - private static readonly Vector2 MinusOne = new Vector2(-1F); + private static readonly Vector2 Half = new(MaxPos); + private static readonly Vector2 MinusOne = new(-1F); /// /// Initializes a new instance of the struct. @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() => new Vector4(this.ToVector2(), 0F, 1F); + public readonly Vector4 ToVector4() => new(this.ToVector2(), 0F, 1F); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -153,12 +153,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// The . [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector2 ToVector2() - { - return new Vector2( + public readonly Vector2 ToVector2() => new( (sbyte)((this.PackedValue >> 0) & 0xFF) / MaxPos, (sbyte)((this.PackedValue >> 8) & 0xFF) / MaxPos); - } /// public override readonly bool Equals(object obj) => obj is NormalizedByte2 other && this.Equals(other); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs index d1b4b73f2..2e81b3e2d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs @@ -17,8 +17,8 @@ namespace SixLabors.ImageSharp.PixelFormats { private const float MaxPos = 127F; - private static readonly Vector4 Half = new Vector4(MaxPos); - private static readonly Vector4 MinusOne = new Vector4(-1F); + private static readonly Vector4 Half = new(MaxPos); + private static readonly Vector4 MinusOne = new(-1F); /// /// Initializes a new instance of the struct. @@ -91,14 +91,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() - { - return new Vector4( + public readonly Vector4 ToVector4() => new( (sbyte)((this.PackedValue >> 0) & 0xFF) / MaxPos, (sbyte)((this.PackedValue >> 8) & 0xFF) / MaxPos, (sbyte)((this.PackedValue >> 16) & 0xFF) / MaxPos, (sbyte)((this.PackedValue >> 24) & 0xFF) / MaxPos); - } /// [MethodImpl(InliningOptions.ShortMethod)] @@ -142,10 +139,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs index d08a54603..b97aaacec 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.PixelFormats // Largest two byte positive number 0xFFFF >> 1; private const float MaxPos = 0x7FFF; - private static readonly Vector2 Max = new Vector2(MaxPos); + private static readonly Vector2 Max = new(MaxPos); private static readonly Vector2 Min = Vector2.Negate(Max); /// @@ -138,10 +138,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -157,12 +154,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// The . [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector2 ToVector2() - { - return new Vector2( + public readonly Vector2 ToVector2() => new( (short)(this.PackedValue & 0xFFFF) / MaxPos, (short)(this.PackedValue >> 0x10) / MaxPos); - } /// public override readonly bool Equals(object obj) => obj is NormalizedShort2 other && this.Equals(other); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs index 158b6eb4b..f2e8aedd8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.PixelFormats // Largest two byte positive number 0xFFFF >> 1; private const float MaxPos = 0x7FFF; - private static readonly Vector4 Max = new Vector4(MaxPos); + private static readonly Vector4 Max = new(MaxPos); private static readonly Vector4 Min = Vector4.Negate(Max); /// @@ -92,14 +92,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() - { - return new Vector4( + public readonly Vector4 ToVector4() => new( (short)((this.PackedValue >> 0x00) & 0xFFFF) / MaxPos, (short)((this.PackedValue >> 0x10) & 0xFFFF) / MaxPos, (short)((this.PackedValue >> 0x20) & 0xFFFF) / MaxPos, (short)((this.PackedValue >> 0x30) & 0xFFFF) / MaxPos); - } /// [MethodImpl(InliningOptions.ShortMethod)] @@ -143,10 +140,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs index d7e6f53cf..12b6e153f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public partial struct Rg32 : IPixel, IPackedVector { - private static readonly Vector2 Max = new Vector2(ushort.MaxValue); + private static readonly Vector2 Max = new(ushort.MaxValue); /// /// Initializes a new instance of the struct. @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() => new Vector4(this.ToVector2(), 0F, 1F); + public readonly Vector4 ToVector4() => new(this.ToVector2(), 0F, 1F); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -123,10 +123,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs index 7fd63c676..3b5bdb3d5 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs @@ -36,8 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats [FieldOffset(2)] public byte B; - private static readonly Vector4 MaxBytes = new Vector4(byte.MaxValue); - private static readonly Vector4 Half = new Vector4(0.5F); + private static readonly Vector4 MaxBytes = new(byte.MaxValue); + private static readonly Vector4 Half = new(0.5F); /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs index e3738b70c..d16b7db7a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() => new Vector4(this.R / Max, this.G / Max, this.B / Max, 1F); + public readonly Vector4 ToVector4() => new(this.R / Max, this.G / Max, this.B / Max, 1F); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs index dee2f9fcb..e68726018 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public partial struct Rgba1010102 : IPixel, IPackedVector { - private static readonly Vector4 Multiplier = new Vector4(1023F, 1023F, 1023F, 3F); + private static readonly Vector4 Multiplier = new(1023F, 1023F, 1023F, 3F); /// /// Initializes a new instance of the struct. @@ -78,14 +78,11 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() - { - return new Vector4( + public readonly Vector4 ToVector4() => new Vector4( (this.PackedValue >> 0) & 0x03FF, (this.PackedValue >> 10) & 0x03FF, (this.PackedValue >> 20) & 0x03FF, (this.PackedValue >> 30) & 0x03) / Multiplier; - } /// [MethodImpl(InliningOptions.ShortMethod)] @@ -129,10 +126,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest.FromScaledVector4(this.ToScaledVector4()); - } + public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs index 868165e9c..3dc6490f1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs @@ -44,8 +44,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// public byte A; - private static readonly Vector4 MaxBytes = new Vector4(byte.MaxValue); - private static readonly Vector4 Half = new Vector4(0.5F); + private static readonly Vector4 MaxBytes = new(byte.MaxValue); + private static readonly Vector4 Half = new(0.5F); /// /// Initializes a new instance of the struct. @@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.PixelFormats public Rgb24 Rgb { [MethodImpl(InliningOptions.ShortMethod)] - readonly get => new Rgb24(this.R, this.G, this.B); + readonly get => new(this.R, this.G, this.B); [MethodImpl(InliningOptions.ShortMethod)] set @@ -154,7 +154,7 @@ namespace SixLabors.ImageSharp.PixelFormats public Bgr24 Bgr { [MethodImpl(InliningOptions.ShortMethod)] - readonly get => new Bgr24(this.R, this.G, this.B); + readonly get => new(this.R, this.G, this.B); [MethodImpl(InliningOptions.ShortMethod)] set @@ -181,7 +181,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// The . /// The . [MethodImpl(InliningOptions.ShortMethod)] - public static implicit operator Color(Rgba32 source) => new Color(source); + public static implicit operator Color(Rgba32 source) => new(source); /// /// Converts a to . @@ -393,10 +393,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public void ToRgba32(ref Rgba32 dest) - { - dest = this; - } + public void ToRgba32(ref Rgba32 dest) => dest = this; /// [MethodImpl(InliningOptions.ShortMethod)] @@ -424,7 +421,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// A hexadecimal string representation of the value. public readonly string ToHex() { - uint hexOrder = (uint)(this.A << 0 | this.B << 8 | this.G << 16 | this.R << 24); + uint hexOrder = (uint)((this.A << 0) | (this.B << 8) | (this.G << 16) | (this.R << 24)); return hexOrder.ToString("X8"); } @@ -523,7 +520,7 @@ namespace SixLabors.ImageSharp.PixelFormats return hex + "FF"; } - if (hex.Length < 3 || hex.Length > 4) + if (hex.Length is < 3 or > 4) { return null; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs index 9add3d718..4cfa0bf97 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs @@ -162,7 +162,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// The . /// The . [MethodImpl(InliningOptions.ShortMethod)] - public static implicit operator Color(Rgba64 source) => new Color(source); + public static implicit operator Color(Rgba64 source) => new(source); /// /// Converts a to . diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs index 97e103d0f..cd6f53c4e 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs @@ -43,8 +43,8 @@ namespace SixLabors.ImageSharp.PixelFormats public float A; private const float MaxBytes = byte.MaxValue; - private static readonly Vector4 Max = new Vector4(MaxBytes); - private static readonly Vector4 Half = new Vector4(0.5F); + private static readonly Vector4 Max = new(MaxBytes); + private static readonly Vector4 Half = new(0.5F); /// /// Initializes a new instance of the struct. @@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() => new Vector4(this.R, this.G, this.B, this.A); + public readonly Vector4 ToVector4() => new(this.R, this.G, this.B, this.A); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -183,7 +183,7 @@ namespace SixLabors.ImageSharp.PixelFormats // Hex is RRGGBBAA Vector4 vector = this.ToVector4() * Max; vector += Half; - uint hexOrder = (uint)((byte)vector.W | (byte)vector.Z << 8 | (byte)vector.Y << 16 | (byte)vector.X << 24); + uint hexOrder = (uint)((byte)vector.W | ((byte)vector.Z << 8) | ((byte)vector.Y << 16) | ((byte)vector.X << 24)); return hexOrder.ToString("X8"); } @@ -199,10 +199,7 @@ namespace SixLabors.ImageSharp.PixelFormats && this.A.Equals(other.A); /// - public override readonly string ToString() - { - return FormattableString.Invariant($"RgbaVector({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##}, {this.A:#0.##})"); - } + public override readonly string ToString() => FormattableString.Invariant($"RgbaVector({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##}, {this.A:#0.##})"); /// public override readonly int GetHashCode() => HashCode.Combine(this.R, this.G, this.B, this.A); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs index 101027a78..24f6b4d1d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs @@ -21,8 +21,8 @@ namespace SixLabors.ImageSharp.PixelFormats // Two's complement private const float MinNeg = ~(int)MaxPos; - private static readonly Vector2 Max = new Vector2(MaxPos); - private static readonly Vector2 Min = new Vector2(MinNeg); + private static readonly Vector2 Max = new(MaxPos); + private static readonly Vector2 Min = new(MinNeg); /// /// Initializes a new instance of the struct. @@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector4 ToVector4() => new Vector4((short)(this.PackedValue & 0xFFFF), (short)(this.PackedValue >> 0x10), 0, 1); + public readonly Vector4 ToVector4() => new((short)(this.PackedValue & 0xFFFF), (short)(this.PackedValue >> 0x10), 0, 1); /// [MethodImpl(InliningOptions.ShortMethod)] @@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// The . [MethodImpl(InliningOptions.ShortMethod)] - public readonly Vector2 ToVector2() => new Vector2((short)(this.PackedValue & 0xFFFF), (short)(this.PackedValue >> 0x10)); + public readonly Vector2 ToVector2() => new((short)(this.PackedValue & 0xFFFF), (short)(this.PackedValue >> 0x10)); /// public override readonly bool Equals(object obj) => obj is Short2 other && this.Equals(other); diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs index f6a6d44bb..36cdd157d 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs @@ -28,8 +28,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.NotEqual(color1, color2); } - public static readonly TheoryData ColorData = - new TheoryData { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 255, 42 } }; + public static readonly TheoryData ColorData = new() { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 255, 42 } }; [Theory] [MemberData(nameof(ColorData))] diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs index b7fbdde71..4b8f4c2ea 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs @@ -35,10 +35,13 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats } public static readonly TheoryData ColorData = - new TheoryData - { - { 1, 2, 3, 4 }, { 4, 5, 6, 7 }, { 0, 255, 42, 0 }, { 1, 2, 3, 255 } - }; + new() + { + { 1, 2, 3, 4 }, + { 4, 5, 6, 7 }, + { 0, 255, 42, 0 }, + { 1, 2, 3, 255 } + }; [Theory] [MemberData(nameof(ColorData))] diff --git a/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs b/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs index d877283c1..fc91590d2 100644 --- a/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/L8Tests.cs @@ -12,29 +12,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public class L8Tests { public static readonly TheoryData LuminanceData - = new TheoryData - { - 0, - 1, - 2, - 3, - 5, - 13, - 31, - 71, - 73, - 79, - 83, - 109, - 127, - 128, - 131, - 199, - 250, - 251, - 254, - 255 - }; + = new() { 0, 1, 2, 3, 5, 13, 31, 71, 73, 79, 83, 109, 127, 128, 131, 199, 250, 251, 254, 255 }; [Theory] [InlineData(0)] diff --git a/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs b/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs index 2c9a27028..7e082147e 100644 --- a/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/La16Tests.cs @@ -12,29 +12,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public class La16Tests { public static readonly TheoryData LuminanceData - = new TheoryData - { - 0, - 1, - 2, - 3, - 5, - 13, - 31, - 71, - 73, - 79, - 83, - 109, - 127, - 128, - 131, - 199, - 250, - 251, - 254, - 255 - }; + = new() { 0, 1, 2, 3, 5, 13, 31, 71, 73, 79, 83, 109, 127, 128, 131, 199, 250, 251, 254, 255 }; [Theory] [InlineData(0, 0)] diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs index 7954f1aff..5988cc851 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats [Trait("Category", "PixelFormats")] public class PixelBlenderTests { - public static TheoryData BlenderMappings = new TheoryData + public static TheoryData BlenderMappings = new() { { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOver), PixelColorBlendingMode.Normal }, { new TestPixel(), typeof(DefaultPixelBlenders.ScreenSrcOver), PixelColorBlendingMode.Screen }, @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.IsType(type, blender); } - public static TheoryData ColorBlendingExpectedResults = new TheoryData + public static TheoryData ColorBlendingExpectedResults = new() { { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Normal, Color.MidnightBlue }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Screen, new Rgba32(0xFFEEE7FF) }, @@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.Equal(actualResult.ToVector4(), expectedResult.ToVector4()); } - public static TheoryData AlphaCompositionExpectedResults = new TheoryData + public static TheoryData AlphaCompositionExpectedResults = new() { { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.Clear, new Rgba32(0) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.Xor, new Rgba32(0) }, diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs index ec53629a8..315f9f776 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs @@ -11,21 +11,21 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public abstract partial class PixelConverterTests { public static readonly TheoryData RgbaData = - new TheoryData - { - { 0, 0, 0, 0 }, - { 0, 0, 0, 255 }, - { 0, 0, 255, 0 }, - { 0, 255, 0, 0 }, - { 255, 0, 0, 0 }, - { 255, 255, 255, 255 }, - { 0, 0, 0, 1 }, - { 0, 0, 1, 0 }, - { 0, 1, 0, 0 }, - { 1, 0, 0, 0 }, - { 3, 5, 7, 11 }, - { 67, 71, 101, 109 } - }; + new() + { + { 0, 0, 0, 0 }, + { 0, 0, 0, 255 }, + { 0, 0, 255, 0 }, + { 0, 255, 0, 0 }, + { 255, 0, 0, 0 }, + { 255, 255, 255, 255 }, + { 0, 0, 0, 1 }, + { 0, 0, 1, 0 }, + { 0, 1, 0, 0 }, + { 1, 0, 0, 0 }, + { 3, 5, 7, 11 }, + { 67, 71, 101, 109 } + }; public class FromRgba32 : PixelConverterTests { @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void ToArgb32(byte r, byte g, byte b, byte a) { byte[] source = ReferenceImplementations.MakeRgba32ByteArray(r, g, b, a); - var actual = new byte[source.Length]; + byte[] actual = new byte[source.Length]; PixelConverter.FromRgba32.ToArgb32(source, actual); @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void ToBgra32(byte r, byte g, byte b, byte a) { byte[] source = ReferenceImplementations.MakeRgba32ByteArray(r, g, b, a); - var actual = new byte[source.Length]; + byte[] actual = new byte[source.Length]; PixelConverter.FromRgba32.ToBgra32(source, actual); @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void ToRgba32(byte r, byte g, byte b, byte a) { byte[] source = ReferenceImplementations.MakeArgb32ByteArray(r, g, b, a); - var actual = new byte[source.Length]; + byte[] actual = new byte[source.Length]; PixelConverter.FromArgb32.ToRgba32(source, actual); @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void ToBgra32(byte r, byte g, byte b, byte a) { byte[] source = ReferenceImplementations.MakeArgb32ByteArray(r, g, b, a); - var actual = new byte[source.Length]; + byte[] actual = new byte[source.Length]; PixelConverter.FromArgb32.ToBgra32(source, actual); @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void ToArgb32(byte r, byte g, byte b, byte a) { byte[] source = ReferenceImplementations.MakeBgra32ByteArray(r, g, b, a); - var actual = new byte[source.Length]; + byte[] actual = new byte[source.Length]; PixelConverter.FromBgra32.ToArgb32(source, actual); @@ -110,7 +110,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public void ToRgba32(byte r, byte g, byte b, byte a) { byte[] source = ReferenceImplementations.MakeBgra32ByteArray(r, g, b, a); - var actual = new byte[source.Length]; + byte[] actual = new byte[source.Length]; PixelConverter.FromBgra32.ToRgba32(source, actual); diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs index 4d4f8c9fb..6c98e623f 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public class Rgb24Tests { public static readonly TheoryData ColorData = - new TheoryData + new() { { 1, 2, 3 }, { 4, 5, 6 }, @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats Assert.Equal(3, rgb.B); } - private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new Vector4( + private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new( r / 255f, g / 255f, b / 255f, diff --git a/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs b/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs index 9492fef90..20484b073 100644 --- a/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs @@ -5,7 +5,7 @@ using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using Xunit; -namespace SixLabors.ImageSharp.Tests.Colors +namespace SixLabors.ImageSharp.Tests.PixelFormats { [Trait("Category", "PixelFormats")] public class UnPackedPixelTests