@@ -35,14 +35,23 @@ public CieLchuv(float l, float c, float h)
3535 /// <param name="vector">The vector representing the l, c, h components.</param>
3636 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
3737 public CieLchuv ( Vector3 vector )
38- : this ( )
3938 {
4039 vector = Vector3 . Clamp ( vector , Min , Max ) ;
4140 this . L = vector . X ;
4241 this . C = vector . Y ;
4342 this . H = vector . Z ;
4443 }
4544
45+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
46+ #pragma warning disable SA1313 // Parameter names should begin with lower-case letter
47+ private CieLchuv ( Vector3 vector , bool _ )
48+ #pragma warning restore SA1313 // Parameter names should begin with lower-case letter
49+ {
50+ this . L = vector . X ;
51+ this . C = vector . Y ;
52+ this . H = vector . Z ;
53+ }
54+
4655 /// <summary>
4756 /// Gets the lightness dimension.
4857 /// <remarks>A value ranging between 0 (black), 100 (diffuse white) or higher (specular white).</remarks>
@@ -51,7 +60,7 @@ public CieLchuv(Vector3 vector)
5160
5261 /// <summary>
5362 /// Gets the a chroma component.
54- /// <remarks>A value ranging from 0 to 200.</remarks>
63+ /// <remarks>A value ranging from -200 to 200.</remarks>
5564 /// </summary>
5665 public float C { get ; }
5766
@@ -81,6 +90,49 @@ public CieLchuv(Vector3 vector)
8190 /// </returns>
8291 public static bool operator != ( CieLchuv left , CieLchuv right ) => ! left . Equals ( right ) ;
8392
93+ /// <inheritdoc/>
94+ public Vector4 ToScaledVector4 ( )
95+ {
96+ Vector3 v3 = default ;
97+ v3 += this . AsVector3Unsafe ( ) ;
98+ v3 += new Vector3 ( 0 , 200 , 0 ) ;
99+ v3 /= new Vector3 ( 100 , 400 , 360 ) ;
100+ return new Vector4 ( v3 , 1F ) ;
101+ }
102+
103+ /// <inheritdoc/>
104+ public static CieLchuv FromScaledVector4 ( Vector4 source )
105+ {
106+ Vector3 v3 = source . AsVector3 ( ) ;
107+ v3 *= new Vector3 ( 100 , 400 , 360 ) ;
108+ v3 -= new Vector3 ( 0 , 200 , 0 ) ;
109+ return new CieLchuv ( v3 , true ) ;
110+ }
111+
112+ /// <inheritdoc/>
113+ public static void ToScaledVector4 ( ReadOnlySpan < CieLchuv > source , Span < Vector4 > destination )
114+ {
115+ Guard . DestinationShouldNotBeTooShort ( source , destination , nameof ( destination ) ) ;
116+
117+ // TODO: Optimize via SIMD
118+ for ( int i = 0 ; i < source . Length ; i ++ )
119+ {
120+ destination [ i ] = source [ i ] . ToScaledVector4 ( ) ;
121+ }
122+ }
123+
124+ /// <inheritdoc/>
125+ public static void FromScaledVector4 ( ReadOnlySpan < Vector4 > source , Span < CieLchuv > destination )
126+ {
127+ Guard . DestinationShouldNotBeTooShort ( source , destination , nameof ( destination ) ) ;
128+
129+ // TODO: Optimize via SIMD
130+ for ( int i = 0 ; i < source . Length ; i ++ )
131+ {
132+ destination [ i ] = FromScaledVector4 ( source [ i ] ) ;
133+ }
134+ }
135+
84136 /// <inheritdoc/>
85137 public static CieLchuv FromProfileConnectingSpace ( ColorConversionOptions options , in CieXyz source )
86138 {
0 commit comments