Skip to content

Commit 72904e1

Browse files
Merge pull request #1790 from SixLabors/bp/pixelformattests
Use Convert.To after rounding in Pack() to avoid different behavior on ARM vs x86/x64
2 parents 2add3e1 + a68aea3 commit 72904e1

36 files changed

Lines changed: 149 additions & 269 deletions

src/ImageSharp/PixelFormats/PixelImplementations/A8.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public partial struct A8 : IPixel<A8>, IPackedVector<byte>
7373

7474
/// <inheritdoc />
7575
[MethodImpl(InliningOptions.ShortMethod)]
76-
public readonly Vector4 ToVector4() => new Vector4(0, 0, 0, this.PackedValue / 255F);
76+
public readonly Vector4 ToVector4() => new(0, 0, 0, this.PackedValue / 255F);
7777

7878
/// <inheritdoc/>
7979
[MethodImpl(InliningOptions.ShortMethod)]

src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public partial struct Argb32 : IPixel<Argb32>, IPackedVector<uint>
4444
/// <summary>
4545
/// The maximum byte value.
4646
/// </summary>
47-
private static readonly Vector4 MaxBytes = new Vector4(255);
47+
private static readonly Vector4 MaxBytes = new(255);
4848

4949
/// <summary>
5050
/// The half vector value.
5151
/// </summary>
52-
private static readonly Vector4 Half = new Vector4(0.5F);
52+
private static readonly Vector4 Half = new(0.5F);
5353

5454
/// <summary>
5555
/// Initializes a new instance of the <see cref="Argb32"/> struct.
@@ -151,7 +151,7 @@ public uint PackedValue
151151
/// <param name="source">The <see cref="Argb32"/>.</param>
152152
/// <returns>The <see cref="Color"/>.</returns>
153153
[MethodImpl(InliningOptions.ShortMethod)]
154-
public static implicit operator Color(Argb32 source) => new Color(source);
154+
public static implicit operator Color(Argb32 source) => new(source);
155155

156156
/// <summary>
157157
/// Converts a <see cref="Color"/> to <see cref="Argb32"/>.

src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Bgr24(byte r, byte g, byte b)
5656
/// <param name="source">The <see cref="Bgr24"/>.</param>
5757
/// <returns>The <see cref="Color"/>.</returns>
5858
[MethodImpl(InliningOptions.ShortMethod)]
59-
public static implicit operator Color(Bgr24 source) => new Color(source);
59+
public static implicit operator Color(Bgr24 source) => new(source);
6060

6161
/// <summary>
6262
/// Converts a <see cref="Color"/> to <see cref="Bgr24"/>.
@@ -225,7 +225,7 @@ public void FromRgba64(Rgba64 source)
225225
public override readonly bool Equals(object obj) => obj is Bgr24 other && this.Equals(other);
226226

227227
/// <inheritdoc />
228-
public override readonly string ToString() => $"Bgra({this.B}, {this.G}, {this.R})";
228+
public override readonly string ToString() => $"Bgr24({this.B}, {this.G}, {this.R})";
229229

230230
/// <inheritdoc/>
231231
[MethodImpl(InliningOptions.ShortMethod)]

src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void FromVector4(Vector4 vector)
8181

8282
/// <inheritdoc />
8383
[MethodImpl(InliningOptions.ShortMethod)]
84-
public readonly Vector4 ToVector4() => new Vector4(this.ToVector3(), 1F);
84+
public readonly Vector4 ToVector4() => new(this.ToVector3(), 1F);
8585

8686
/// <inheritdoc/>
8787
[MethodImpl(InliningOptions.ShortMethod)]
@@ -125,10 +125,7 @@ public void FromVector4(Vector4 vector)
125125

126126
/// <inheritdoc />
127127
[MethodImpl(InliningOptions.ShortMethod)]
128-
public void ToRgba32(ref Rgba32 dest)
129-
{
130-
dest.FromScaledVector4(this.ToScaledVector4());
131-
}
128+
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
132129

133130
/// <inheritdoc/>
134131
[MethodImpl(InliningOptions.ShortMethod)]
@@ -144,13 +141,10 @@ public void ToRgba32(ref Rgba32 dest)
144141
/// </summary>
145142
/// <returns>The <see cref="Vector3"/>.</returns>
146143
[MethodImpl(InliningOptions.ShortMethod)]
147-
public readonly Vector3 ToVector3()
148-
{
149-
return new Vector3(
144+
public readonly Vector3 ToVector3() => new(
150145
((this.PackedValue >> 11) & 0x1F) * (1F / 31F),
151146
((this.PackedValue >> 5) & 0x3F) * (1F / 63F),
152147
(this.PackedValue & 0x1F) * (1F / 31F));
153-
}
154148

155149
/// <inheritdoc />
156150
public override readonly bool Equals(object obj) => obj is Bgr565 other && this.Equals(other);

src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public partial struct Bgra32 : IPixel<Bgra32>, IPackedVector<uint>
4141
/// <summary>
4242
/// The maximum byte value.
4343
/// </summary>
44-
private static readonly Vector4 MaxBytes = new Vector4(255);
44+
private static readonly Vector4 MaxBytes = new(255);
4545

4646
/// <summary>
4747
/// The half vector value.
4848
/// </summary>
49-
private static readonly Vector4 Half = new Vector4(0.5F);
49+
private static readonly Vector4 Half = new(0.5F);
5050

5151
/// <summary>
5252
/// Initializes a new instance of the <see cref="Bgra32"/> struct.
@@ -104,7 +104,7 @@ public uint PackedValue
104104
/// <param name="source">The <see cref="Bgra32"/>.</param>
105105
/// <returns>The <see cref="Color"/>.</returns>
106106
[MethodImpl(InliningOptions.ShortMethod)]
107-
public static implicit operator Color(Bgra32 source) => new Color(source);
107+
public static implicit operator Color(Bgra32 source) => new(source);
108108

109109
/// <summary>
110110
/// Converts a <see cref="Color"/> to <see cref="Bgra32"/>.

src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ public readonly Vector4 ToVector4()
128128

129129
/// <inheritdoc />
130130
[MethodImpl(InliningOptions.ShortMethod)]
131-
public void ToRgba32(ref Rgba32 dest)
132-
{
133-
dest.FromScaledVector4(this.ToScaledVector4());
134-
}
131+
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
135132

136133
/// <inheritdoc/>
137134
[MethodImpl(InliningOptions.ShortMethod)]

src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,11 @@ public Bgra5551(float x, float y, float z, float w)
7878

7979
/// <inheritdoc />
8080
[MethodImpl(InliningOptions.ShortMethod)]
81-
public readonly Vector4 ToVector4()
82-
{
83-
return new Vector4(
81+
public readonly Vector4 ToVector4() => new(
8482
((this.PackedValue >> 10) & 0x1F) / 31F,
8583
((this.PackedValue >> 5) & 0x1F) / 31F,
8684
((this.PackedValue >> 0) & 0x1F) / 31F,
8785
(this.PackedValue >> 15) & 0x01);
88-
}
8986

9087
/// <inheritdoc />
9188
[MethodImpl(InliningOptions.ShortMethod)]
@@ -129,10 +126,7 @@ public readonly Vector4 ToVector4()
129126

130127
/// <inheritdoc />
131128
[MethodImpl(InliningOptions.ShortMethod)]
132-
public void ToRgba32(ref Rgba32 dest)
133-
{
134-
dest.FromScaledVector4(this.ToScaledVector4());
135-
}
129+
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
136130

137131
/// <inheritdoc/>
138132
[MethodImpl(InliningOptions.ShortMethod)]

src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,11 @@ public Byte4(float x, float y, float z, float w)
7878

7979
/// <inheritdoc />
8080
[MethodImpl(InliningOptions.ShortMethod)]
81-
public readonly Vector4 ToVector4()
82-
{
83-
return new Vector4(
81+
public readonly Vector4 ToVector4() => new(
8482
this.PackedValue & 0xFF,
8583
(this.PackedValue >> 0x8) & 0xFF,
8684
(this.PackedValue >> 0x10) & 0xFF,
8785
(this.PackedValue >> 0x18) & 0xFF);
88-
}
8986

9087
/// <inheritdoc />
9188
[MethodImpl(InliningOptions.ShortMethod)]
@@ -129,10 +126,7 @@ public readonly Vector4 ToVector4()
129126

130127
/// <inheritdoc />
131128
[MethodImpl(InliningOptions.ShortMethod)]
132-
public void ToRgba32(ref Rgba32 dest)
133-
{
134-
dest.FromScaledVector4(this.ToScaledVector4());
135-
}
129+
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
136130

137131
/// <inheritdoc/>
138132
[MethodImpl(InliningOptions.ShortMethod)]

src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public readonly Vector4 ToScaledVector4()
7474

7575
/// <inheritdoc />
7676
[MethodImpl(InliningOptions.ShortMethod)]
77-
public readonly Vector4 ToVector4() => new Vector4(this.ToSingle(), 0, 0, 1F);
77+
public readonly Vector4 ToVector4() => new(this.ToSingle(), 0, 0, 1F);
7878

7979
/// <inheritdoc />
8080
[MethodImpl(InliningOptions.ShortMethod)]
@@ -118,10 +118,7 @@ public readonly Vector4 ToScaledVector4()
118118

119119
/// <inheritdoc />
120120
[MethodImpl(InliningOptions.ShortMethod)]
121-
public void ToRgba32(ref Rgba32 dest)
122-
{
123-
dest.FromScaledVector4(this.ToScaledVector4());
124-
}
121+
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
125122

126123
/// <inheritdoc/>
127124
[MethodImpl(InliningOptions.ShortMethod)]

src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ public readonly Vector4 ToVector4()
129129

130130
/// <inheritdoc />
131131
[MethodImpl(InliningOptions.ShortMethod)]
132-
public void ToRgba32(ref Rgba32 dest)
133-
{
134-
dest.FromScaledVector4(this.ToScaledVector4());
135-
}
132+
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
136133

137134
/// <inheritdoc/>
138135
[MethodImpl(InliningOptions.ShortMethod)]

0 commit comments

Comments
 (0)