|
3 | 3 |
|
4 | 4 | using System.Numerics; |
5 | 5 | using System.Runtime.CompilerServices; |
| 6 | +using System.Runtime.InteropServices; |
6 | 7 |
|
7 | 8 | namespace SixLabors.ImageSharp.ColorProfiles; |
8 | 9 |
|
9 | 10 | /// <summary> |
10 | 11 | /// Represents the CIE L*C*h°, cylindrical form of the CIE L*a*b* 1976 color. |
11 | 12 | /// <see href="https://en.wikipedia.org/wiki/Lab_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC"/> |
12 | 13 | /// </summary> |
| 14 | +[StructLayout(LayoutKind.Sequential)] |
13 | 15 | public readonly struct CieLch : IColorProfile<CieLch, CieLab> |
14 | 16 | { |
15 | 17 | private static readonly Vector3 Min = new(0, -200, 0); |
@@ -80,22 +82,6 @@ public CieLch(Vector3 vector) |
80 | 82 | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
81 | 83 | public static bool operator !=(CieLch left, CieLch right) => !left.Equals(right); |
82 | 84 |
|
83 | | - /// <inheritdoc/> |
84 | | - public override int GetHashCode() |
85 | | - => HashCode.Combine(this.L, this.C, this.H); |
86 | | - |
87 | | - /// <inheritdoc/> |
88 | | - public override string ToString() => FormattableString.Invariant($"CieLch({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})"); |
89 | | - |
90 | | - /// <inheritdoc/> |
91 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
92 | | - public override bool Equals(object? obj) => obj is CieLch other && this.Equals(other); |
93 | | - |
94 | | - /// <inheritdoc/> |
95 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
96 | | - public bool Equals(CieLch other) |
97 | | - => new Vector3(this.L, this.C, this.H) == new Vector3(other.L, other.C, other.H); |
98 | | - |
99 | 85 | /// <inheritdoc/> |
100 | 86 | public static CieLch FromProfileConnectingSpace(ColorConversionOptions options, in CieLab source) |
101 | 87 | { |
@@ -159,4 +145,22 @@ public static void ToProfileConnectionSpace(ColorConversionOptions options, Read |
159 | 145 | /// <inheritdoc/> |
160 | 146 | public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource() |
161 | 147 | => ChromaticAdaptionWhitePointSource.WhitePoint; |
| 148 | + |
| 149 | + /// <inheritdoc/> |
| 150 | + public override int GetHashCode() |
| 151 | + => HashCode.Combine(this.L, this.C, this.H); |
| 152 | + |
| 153 | + /// <inheritdoc/> |
| 154 | + public override string ToString() => FormattableString.Invariant($"CieLch({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})"); |
| 155 | + |
| 156 | + /// <inheritdoc/> |
| 157 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 158 | + public override bool Equals(object? obj) => obj is CieLch other && this.Equals(other); |
| 159 | + |
| 160 | + /// <inheritdoc/> |
| 161 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 162 | + public bool Equals(CieLch other) |
| 163 | + => this.AsVector3Unsafe() == other.AsVector3Unsafe(); |
| 164 | + |
| 165 | + private Vector3 AsVector3Unsafe() => Unsafe.As<CieLch, Vector3>(ref Unsafe.AsRef(in this)); |
162 | 166 | } |
0 commit comments