@@ -18,15 +18,7 @@ public static int DecodeASTC(ReadOnlySpan<byte> input, int width, int height, in
1818 return DecodeASTC ( input , width , height , blockWidth , blockHeight , output ) ;
1919 }
2020
21- public unsafe static int DecodeASTC ( ReadOnlySpan < byte > input , int width , int height , int blockWidth , int blockHeight , Span < byte > output )
22- {
23- fixed ( byte * outputPtr = output )
24- {
25- return DecodeASTC ( input , width , height , blockWidth , blockHeight , outputPtr ) ;
26- }
27- }
28-
29- private unsafe static int DecodeASTC ( ReadOnlySpan < byte > input , int width , int height , int blockWidth , int blockHeight , byte * output )
21+ public static int DecodeASTC ( ReadOnlySpan < byte > input , int width , int height , int blockWidth , int blockHeight , Span < byte > output )
3022 {
3123 ValidateBlockDimension ( blockWidth ) ;
3224 ValidateBlockDimension ( blockHeight ) ;
@@ -41,19 +33,23 @@ private unsafe static int DecodeASTC(ReadOnlySpan<byte> input, int width, int he
4133 {
4234 DecodeBlock ( input [ inputOffset ..] , blockWidth , blockHeight , buf ) ;
4335 int clen = s < bcw - 1 ? blockWidth : clen_last ;
44- uint * outputPtr = ( uint * ) ( output + ( t * blockHeight * 4 * width + s * 4 * blockWidth ) ) ;
4536 for ( int i = 0 , y = t * blockHeight ; i < blockHeight && y < height ; i ++ , y ++ )
4637 {
38+ int outputOffsetUInt32 = t * blockHeight * width + s * blockWidth + i * width ;
4739 for ( int j = 0 ; j < clen ; j ++ )
4840 {
49- outputPtr [ j ] = buf [ j + i * blockWidth ] ;
41+ WriteUInt32 ( output , outputOffsetUInt32 + j , buf [ j + i * blockWidth ] ) ;
5042 }
51-
52- outputPtr += width ;
5343 }
5444 }
5545 }
5646 return inputOffset ;
47+
48+ [ MethodImpl ( MethodImplOptions . AggressiveInlining | MethodImplOptions . AggressiveOptimization ) ]
49+ static void WriteUInt32 ( Span < byte > buffer , int offsetUInt32 , uint value )
50+ {
51+ BinaryPrimitives . WriteUInt32LittleEndian ( buffer . Slice ( offsetUInt32 * sizeof ( uint ) ) , value ) ;
52+ }
5753 }
5854
5955 private unsafe static void DecodeBlock ( ReadOnlySpan < byte > input , int blockWidth , int blockHeight , Span < uint > output )
@@ -775,7 +771,7 @@ private unsafe static void ApplicateColor(BlockData block, Span<uint> output)
775771 }
776772 }
777773
778- private unsafe static void DecodeIntseq ( ReadOnlySpan < byte > input , int offset , int a , int b , int count , bool reverse , Span < IntSeqData > _out )
774+ private static void DecodeIntseq ( ReadOnlySpan < byte > input , int offset , int a , int b , int count , bool reverse , Span < IntSeqData > _out )
779775 {
780776 if ( count <= 0 )
781777 {
0 commit comments