@@ -137,24 +137,31 @@ public static int GetBitsNeededForColorDepth(int colors)
137
137
public static int GetColorCountForBitDepth ( int bitDepth )
138
138
=> 1 << bitDepth ;
139
139
140
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
141
+ internal static Vector4 Transform ( Vector4 vector , in ColorMatrix . Impl matrix )
142
+ {
143
+ Vector4 result = matrix . X * vector . X ;
144
+
145
+ result += matrix . Y * vector . Y ;
146
+ result += matrix . Z * vector . Z ;
147
+ result += matrix . W * vector . W ;
148
+
149
+ result . X += matrix . V . X ;
150
+ result . Y += matrix . V . Y ;
151
+ result . Z += matrix . V . Z ;
152
+ result . W += matrix . V . W ;
153
+
154
+ return result ;
155
+ }
156
+
140
157
/// <summary>
141
158
/// Transforms a vector by the given color matrix.
142
159
/// </summary>
143
160
/// <param name="vector">The source vector.</param>
144
161
/// <param name="matrix">The transformation color matrix.</param>
145
162
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
146
163
public static void Transform ( ref Vector4 vector , ref ColorMatrix matrix )
147
- {
148
- float x = vector . X ;
149
- float y = vector . Y ;
150
- float z = vector . Z ;
151
- float w = vector . W ;
152
-
153
- vector . X = ( x * matrix . M11 ) + ( y * matrix . M21 ) + ( z * matrix . M31 ) + ( w * matrix . M41 ) + matrix . M51 ;
154
- vector . Y = ( x * matrix . M12 ) + ( y * matrix . M22 ) + ( z * matrix . M32 ) + ( w * matrix . M42 ) + matrix . M52 ;
155
- vector . Z = ( x * matrix . M13 ) + ( y * matrix . M23 ) + ( z * matrix . M33 ) + ( w * matrix . M43 ) + matrix . M53 ;
156
- vector . W = ( x * matrix . M14 ) + ( y * matrix . M24 ) + ( z * matrix . M34 ) + ( w * matrix . M44 ) + matrix . M54 ;
157
- }
164
+ => vector = Transform ( vector , matrix . AsImpl ( ) ) ;
158
165
159
166
/// <summary>
160
167
/// Bulk variant of <see cref="Transform(ref Vector4, ref ColorMatrix)"/>.
0 commit comments