Skip to content

Commit b458ff2

Browse files
Optimize and cleanup per review
1 parent cb56bae commit b458ff2

16 files changed

+87
-128
lines changed

src/ImageSharp/ColorProfiles/CieLab.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ namespace SixLabors.ImageSharp.ColorProfiles;
1212
/// </summary>
1313
public readonly struct CieLab : IProfileConnectingSpace<CieLab, CieXyz>
1414
{
15-
/// <summary>
16-
/// D50 standard illuminant.
17-
/// Used when reference white is not specified explicitly.
18-
/// </summary>
19-
public static readonly CieXyz DefaultWhitePoint = KnownIlluminants.D50;
20-
2115
/// <summary>
2216
/// Initializes a new instance of the <see cref="CieLab"/> struct.
2317
/// </summary>
@@ -50,19 +44,19 @@ public CieLab(Vector3 vector)
5044
/// Gets the lightness dimension.
5145
/// <remarks>A value usually ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
5246
/// </summary>
53-
public readonly float L { get; }
47+
public float L { get; }
5448

5549
/// <summary>
5650
/// Gets the a color component.
5751
/// <remarks>A value usually ranging from -100 to 100. Negative is green, positive magenta.</remarks>
5852
/// </summary>
59-
public readonly float A { get; }
53+
public float A { get; }
6054

6155
/// <summary>
6256
/// Gets the b color component.
6357
/// <remarks>A value usually ranging from -100 to 100. Negative is blue, positive is yellow</remarks>
6458
/// </summary>
65-
public readonly float B { get; }
59+
public float B { get; }
6660

6761
/// <summary>
6862
/// Compares two <see cref="CieLab"/> objects for equality.
@@ -97,10 +91,8 @@ public CieLab(Vector3 vector)
9791

9892
/// <inheritdoc/>
9993
[MethodImpl(MethodImplOptions.AggressiveInlining)]
100-
public bool Equals(CieLab other) =>
101-
this.L.Equals(other.L)
102-
&& this.A.Equals(other.A)
103-
&& this.B.Equals(other.B);
94+
public bool Equals(CieLab other)
95+
=> new Vector3(this.L, this.A, this.B) == new Vector3(other.L, other.A, other.B);
10496

10597
/// <inheritdoc/>
10698
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/ImageSharp/ColorProfiles/CieLch.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ public CieLch(Vector3 vector)
4444
/// Gets the lightness dimension.
4545
/// <remarks>A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
4646
/// </summary>
47-
public readonly float L { get; }
47+
public float L { get; }
4848

4949
/// <summary>
5050
/// Gets the a chroma component.
5151
/// <remarks>A value ranging from 0 to 200.</remarks>
5252
/// </summary>
53-
public readonly float C { get; }
53+
public float C { get; }
5454

5555
/// <summary>
5656
/// Gets the h° hue component in degrees.
5757
/// <remarks>A value ranging from 0 to 360.</remarks>
5858
/// </summary>
59-
public readonly float H { get; }
59+
public float H { get; }
6060

6161
/// <summary>
6262
/// Compares two <see cref="CieLch"/> objects for equality.
@@ -94,9 +94,7 @@ public override int GetHashCode()
9494
/// <inheritdoc/>
9595
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9696
public bool Equals(CieLch other)
97-
=> this.L.Equals(other.L)
98-
&& this.C.Equals(other.C)
99-
&& this.H.Equals(other.H);
97+
=> new Vector3(this.L, this.C, this.H) == new Vector3(other.L, other.C, other.H);
10098

10199
/// <inheritdoc/>
102100
public static CieLch FromProfileConnectingSpace(ColorConversionOptions options, in CieLab source)

src/ImageSharp/ColorProfiles/CieLchuv.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,19 @@ public CieLchuv(Vector3 vector)
4545
/// Gets the lightness dimension.
4646
/// <remarks>A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
4747
/// </summary>
48-
public readonly float L { get; }
48+
public float L { get; }
4949

5050
/// <summary>
5151
/// Gets the a chroma component.
5252
/// <remarks>A value ranging from 0 to 200.</remarks>
5353
/// </summary>
54-
public readonly float C { get; }
54+
public float C { get; }
5555

5656
/// <summary>
5757
/// Gets the h° hue component in degrees.
5858
/// <remarks>A value ranging from 0 to 360.</remarks>
5959
/// </summary>
60-
public readonly float H { get; }
61-
62-
/// <summary>
63-
/// Gets the reference white point of this color
64-
/// </summary>
65-
public readonly CieXyz WhitePoint { get; }
60+
public float H { get; }
6661

6762
/// <summary>
6863
/// Compares two <see cref="CieLchuv"/> objects for equality.
@@ -151,7 +146,7 @@ public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSo
151146

152147
/// <inheritdoc/>
153148
public override int GetHashCode()
154-
=> HashCode.Combine(this.L, this.C, this.H, this.WhitePoint);
149+
=> HashCode.Combine(this.L, this.C, this.H);
155150

156151
/// <inheritdoc/>
157152
public override string ToString()
@@ -164,10 +159,7 @@ public override bool Equals(object? obj)
164159
/// <inheritdoc/>
165160
[MethodImpl(MethodImplOptions.AggressiveInlining)]
166161
public bool Equals(CieLchuv other)
167-
=> this.L.Equals(other.L)
168-
&& this.C.Equals(other.C)
169-
&& this.H.Equals(other.H)
170-
&& this.WhitePoint.Equals(other.WhitePoint);
162+
=> new Vector3(this.L, this.C, this.H) == new Vector3(other.L, other.C, other.H);
171163

172164
/// <summary>
173165
/// Computes the saturation of the color (chroma normalized by lightness)

src/ImageSharp/ColorProfiles/CieLuv.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ public CieLuv(Vector3 vector)
4646
/// Gets the lightness dimension
4747
/// <remarks>A value usually ranging between 0 and 100.</remarks>
4848
/// </summary>
49-
public readonly float L { get; }
49+
public float L { get; }
5050

5151
/// <summary>
5252
/// Gets the blue-yellow chromaticity coordinate of the given white point.
5353
/// <remarks>A value usually ranging between -100 and 100.</remarks>
5454
/// </summary>
55-
public readonly float U { get; }
55+
public float U { get; }
5656

5757
/// <summary>
5858
/// Gets the red-green chromaticity coordinate of the given white point.
5959
/// <remarks>A value usually ranging between -100 and 100.</remarks>
6060
/// </summary>
61-
public readonly float V { get; }
61+
public float V { get; }
6262

6363
/// <summary>
6464
/// Compares two <see cref="CieLuv"/> objects for equality.
@@ -205,9 +205,7 @@ public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSo
205205
/// <inheritdoc/>
206206
[MethodImpl(MethodImplOptions.AggressiveInlining)]
207207
public bool Equals(CieLuv other)
208-
=> this.L.Equals(other.L)
209-
&& this.U.Equals(other.U)
210-
&& this.V.Equals(other.V);
208+
=> new Vector3(this.L, this.U, this.V) == new Vector3(other.L, other.U, other.V);
211209

212210
[MethodImpl(MethodImplOptions.AggressiveInlining)]
213211
private static double ComputeU(in CieXyz source)

src/ImageSharp/ColorProfiles/CieXyChromaticityCoordinates.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using System.Numerics;
45
using System.Runtime.CompilerServices;
56

67
// ReSharper disable CompareOfFloatsByEqualityOperator
@@ -29,15 +30,15 @@ public CieXyChromaticityCoordinates(float x, float y)
2930
/// <remarks>
3031
/// Ranges usually from 0 to 1.
3132
/// </remarks>
32-
public readonly float X { get; }
33+
public float X { get; }
3334

3435
/// <summary>
3536
/// Gets the chromaticity Y-coordinate
3637
/// </summary>
3738
/// <remarks>
3839
/// Ranges usually from 0 to 1.
3940
/// </remarks>
40-
public readonly float Y { get; }
41+
public float Y { get; }
4142

4243
/// <summary>
4344
/// Compares two <see cref="CieXyChromaticityCoordinates"/> objects for equality.
@@ -79,5 +80,5 @@ public override bool Equals(object? obj)
7980
/// <inheritdoc/>
8081
[MethodImpl(InliningOptions.ShortMethod)]
8182
public bool Equals(CieXyChromaticityCoordinates other)
82-
=> this.X.Equals(other.X) && this.Y.Equals(other.Y);
83+
=> new Vector2(this.X, this.Y) == new Vector2(other.X, other.Y);
8384
}

src/ImageSharp/ColorProfiles/CieXyy.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ public CieXyy(Vector3 vector)
4545
/// Gets the X chrominance component.
4646
/// <remarks>A value usually ranging between 0 and 1.</remarks>
4747
/// </summary>
48-
public readonly float X { get; }
48+
public float X { get; }
4949

5050
/// <summary>
5151
/// Gets the Y chrominance component.
5252
/// <remarks>A value usually ranging between 0 and 1.</remarks>
5353
/// </summary>
54-
public readonly float Y { get; }
54+
public float Y { get; }
5555

5656
/// <summary>
5757
/// Gets the Y luminance component.
5858
/// <remarks>A value usually ranging between 0 and 1.</remarks>
5959
/// </summary>
60-
public readonly float Yl { get; }
60+
public float Yl { get; }
6161

6262
/// <summary>
6363
/// Compares two <see cref="CieXyy"/> objects for equality.
@@ -150,7 +150,5 @@ public override string ToString()
150150
/// <inheritdoc/>
151151
[MethodImpl(MethodImplOptions.AggressiveInlining)]
152152
public bool Equals(CieXyy other)
153-
=> this.X.Equals(other.X)
154-
&& this.Y.Equals(other.Y)
155-
&& this.Yl.Equals(other.Yl);
153+
=> new Vector3(this.X, this.Y, this.Yl) == new Vector3(other.X, other.Y, other.Yl);
156154
}

src/ImageSharp/ColorProfiles/CieXyz.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Numerics;
55
using System.Runtime.CompilerServices;
6-
using System.Runtime.Intrinsics;
76

87
namespace SixLabors.ImageSharp.ColorProfiles;
98

@@ -99,9 +98,7 @@ public CieXyz(Vector3 vector)
9998
/// <inheritdoc/>
10099
[MethodImpl(MethodImplOptions.AggressiveInlining)]
101100
public bool Equals(CieXyz other)
102-
=> this.X.Equals(other.X)
103-
&& this.Y.Equals(other.Y)
104-
&& this.Z.Equals(other.Z);
101+
=> new Vector3(this.X, this.Y, this.Z) == new Vector3(other.X, other.Y, other.Z);
105102

106103
/// <inheritdoc/>
107104
public static CieXyz FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source)

src/ImageSharp/ColorProfiles/Cmyk.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@ public Cmyk(Vector4 vector)
4545
/// Gets the cyan color component.
4646
/// <remarks>A value ranging between 0 and 1.</remarks>
4747
/// </summary>
48-
public readonly float C { get; }
48+
public float C { get; }
4949

5050
/// <summary>
5151
/// Gets the magenta color component.
5252
/// <remarks>A value ranging between 0 and 1.</remarks>
5353
/// </summary>
54-
public readonly float M { get; }
54+
public float M { get; }
5555

5656
/// <summary>
5757
/// Gets the yellow color component.
5858
/// <remarks>A value ranging between 0 and 1.</remarks>
5959
/// </summary>
60-
public readonly float Y { get; }
60+
public float Y { get; }
6161

6262
/// <summary>
6363
/// Gets the keyline black color component.
6464
/// <remarks>A value ranging between 0 and 1.</remarks>
6565
/// </summary>
66-
public readonly float K { get; }
66+
public float K { get; }
6767

6868
/// <summary>
6969
/// Compares two <see cref="Cmyk"/> objects for equality.
@@ -157,8 +157,5 @@ public override bool Equals(object? obj)
157157
/// <inheritdoc/>
158158
[MethodImpl(MethodImplOptions.AggressiveInlining)]
159159
public bool Equals(Cmyk other)
160-
=> this.C.Equals(other.C)
161-
&& this.M.Equals(other.M)
162-
&& this.Y.Equals(other.Y)
163-
&& this.K.Equals(other.K);
160+
=> new Vector4(this.C, this.M, this.Y, this.K) == new Vector4(other.C, other.M, other.Y, other.K);
164161
}

src/ImageSharp/ColorProfiles/Hsl.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ public Hsl(Vector3 vector)
4343
/// Gets the hue component.
4444
/// <remarks>A value ranging between 0 and 360.</remarks>
4545
/// </summary>
46-
public readonly float H { get; }
46+
public float H { get; }
4747

4848
/// <summary>
4949
/// Gets the saturation component.
5050
/// <remarks>A value ranging between 0 and 1.</remarks>
5151
/// </summary>
52-
public readonly float S { get; }
52+
public float S { get; }
5353

5454
/// <summary>
5555
/// Gets the lightness component.
5656
/// <remarks>A value ranging between 0 and 1.</remarks>
5757
/// </summary>
58-
public readonly float L { get; }
58+
public float L { get; }
5959

6060
/// <summary>
6161
/// Compares two <see cref="Hsl"/> objects for equality.
@@ -200,9 +200,7 @@ public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSo
200200
/// <inheritdoc/>
201201
[MethodImpl(MethodImplOptions.AggressiveInlining)]
202202
public bool Equals(Hsl other)
203-
=> this.H.Equals(other.H)
204-
&& this.S.Equals(other.S)
205-
&& this.L.Equals(other.L);
203+
=> new Vector3(this.H, this.S, this.L) == new Vector3(other.H, other.S, other.L);
206204

207205
[MethodImpl(MethodImplOptions.AggressiveInlining)]
208206
private static float GetColorComponent(float first, float second, float third)

src/ImageSharp/ColorProfiles/Hsv.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ public Hsv(Vector3 vector)
4343
/// Gets the hue component.
4444
/// <remarks>A value ranging between 0 and 360.</remarks>
4545
/// </summary>
46-
public readonly float H { get; }
46+
public float H { get; }
4747

4848
/// <summary>
4949
/// Gets the saturation component.
5050
/// <remarks>A value ranging between 0 and 1.</remarks>
5151
/// </summary>
52-
public readonly float S { get; }
52+
public float S { get; }
5353

5454
/// <summary>
5555
/// Gets the value (brightness) component.
5656
/// <remarks>A value ranging between 0 and 1.</remarks>
5757
/// </summary>
58-
public readonly float V { get; }
58+
public float V { get; }
5959

6060
/// <summary>
6161
/// Compares two <see cref="Hsv"/> objects for equality.
@@ -223,7 +223,5 @@ public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSo
223223
/// <inheritdoc/>
224224
[MethodImpl(MethodImplOptions.AggressiveInlining)]
225225
public bool Equals(Hsv other)
226-
=> this.H.Equals(other.H)
227-
&& this.S.Equals(other.S)
228-
&& this.V.Equals(other.V);
226+
=> new Vector3(this.H, this.S, this.V) == new Vector3(other.H, other.S, other.V);
229227
}

0 commit comments

Comments
 (0)