@@ -69,7 +69,7 @@ public static TPixel ColorFromRgba64Premultiplied<TPixel>(Rgba64 rgba, ulong r,
6969 {
7070 rgba . PackedValue = r | ( g << 16 ) | ( b << 32 ) | ( a << 48 ) ;
7171 var vec = rgba . ToVector4 ( ) ;
72- return UnPremultiply ( vec , color ) ;
72+ return UnPremultiply ( ref vec , color ) ;
7373 }
7474
7575 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -85,7 +85,7 @@ public static TPixel ColorScaleTo24Bit<TPixel>(ulong r, ulong g, ulong b, TPixel
8585 public static TPixel ColorScaleTo24Bit < TPixel > ( ulong r , ulong g , ulong b , ulong a , TPixel color )
8686 where TPixel : unmanaged, IPixel < TPixel >
8787 {
88- var colorVector = new Vector4 ( r * Scale24Bit , g * Scale24Bit , b * Scale24Bit , a * Scale24Bit ) ;
88+ Vector4 colorVector = new Vector4 ( r , g , b , a ) * Scale24Bit ;
8989 color . FromVector4 ( colorVector ) ;
9090 return color ;
9191 }
@@ -94,8 +94,8 @@ public static TPixel ColorScaleTo24Bit<TPixel>(ulong r, ulong g, ulong b, ulong
9494 public static TPixel ColorScaleTo24BitPremultiplied < TPixel > ( ulong r , ulong g , ulong b , ulong a , TPixel color )
9595 where TPixel : unmanaged, IPixel < TPixel >
9696 {
97- var colorVector = new Vector4 ( r * Scale24Bit , g * Scale24Bit , b * Scale24Bit , a * Scale24Bit ) ;
98- return UnPremultiply ( colorVector , color ) ;
97+ Vector4 colorVector = new Vector4 ( r , g , b , a ) * Scale24Bit ;
98+ return UnPremultiply ( ref colorVector , color ) ;
9999 }
100100
101101 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -111,7 +111,7 @@ public static TPixel ColorScaleTo32Bit<TPixel>(ulong r, ulong g, ulong b, TPixel
111111 public static TPixel ColorScaleTo32Bit < TPixel > ( ulong r , ulong g , ulong b , ulong a , TPixel color )
112112 where TPixel : unmanaged, IPixel < TPixel >
113113 {
114- var colorVector = new Vector4 ( r * Scale32Bit , g * Scale32Bit , b * Scale32Bit , a * Scale32Bit ) ;
114+ Vector4 colorVector = new Vector4 ( r , g , b , a ) * Scale32Bit ;
115115 color . FromVector4 ( colorVector ) ;
116116 return color ;
117117 }
@@ -120,8 +120,8 @@ public static TPixel ColorScaleTo32Bit<TPixel>(ulong r, ulong g, ulong b, ulong
120120 public static TPixel ColorScaleTo32BitPremultiplied < TPixel > ( ulong r , ulong g , ulong b , ulong a , TPixel color )
121121 where TPixel : unmanaged, IPixel < TPixel >
122122 {
123- var colorVector = new Vector4 ( r * Scale32Bit , g * Scale32Bit , b * Scale32Bit , a * Scale32Bit ) ;
124- return UnPremultiply ( colorVector , color ) ;
123+ Vector4 colorVector = new Vector4 ( r , g , b , a ) * Scale32Bit ;
124+ return UnPremultiply ( ref colorVector , color ) ;
125125 }
126126
127127 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -152,22 +152,11 @@ public static TPixel ColorScaleTo32Bit<TPixel>(ulong intensity, TPixel color)
152152 }
153153
154154 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
155- public static void UnPremultiplyRow < TPixel > ( Span < Vector4 > vectors , Span < TPixel > pixelRow , TPixel color )
155+ public static TPixel UnPremultiply < TPixel > ( ref Vector4 vector , TPixel color )
156156 where TPixel : unmanaged, IPixel < TPixel >
157157 {
158- for ( int x = 0 ; x < vectors . Length ; x ++ )
159- {
160- Vector4 vec = vectors [ x ] ;
161- pixelRow [ x ] = UnPremultiply ( vec , color ) ;
162- }
163- }
164-
165- [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
166- public static TPixel UnPremultiply < TPixel > ( Vector4 vec , TPixel color )
167- where TPixel : unmanaged, IPixel < TPixel >
168- {
169- float invW = 1.0f / vec . W ;
170- color . FromVector4 ( new Vector4 ( vec . X * invW , vec . Y * invW , vec . Z * invW , vec . W ) ) ;
158+ Numerics . UnPremultiply ( ref vector ) ;
159+ color . FromVector4 ( vector ) ;
171160
172161 return color ;
173162 }
0 commit comments