@@ -564,8 +564,8 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
564
564
low = BinaryPrimitives . ReadUInt64LittleEndian ( compressedBlock ) ,
565
565
high = BinaryPrimitives . ReadUInt64LittleEndian ( compressedBlock . Slice ( sizeof ( ulong ) ) )
566
566
} ;
567
- int [ ] [ ] endpoints = CreateRectangularArray < int > ( 6 , 4 ) ;
568
- int [ ] [ ] indices = CreateRectangularArray < int > ( 4 , 4 ) ;
567
+ Span2D < int > endpoints = new ( stackalloc int [ 6 * 4 ] , 6 , 4 ) ;
568
+ Span2D < int > indices = new ( stackalloc int [ 4 * 4 ] , 4 , 4 ) ;
569
569
570
570
int decompressedOffset = 0 ;
571
571
@@ -618,15 +618,15 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
618
618
{
619
619
for ( int j = 0 ; j < numEndpoints ; ++ j )
620
620
{
621
- endpoints [ j ] [ i ] = bstream . ReadBits ( Bc7Tables . ActualBitsCount [ 0 ] [ mode ] ) ;
621
+ endpoints [ j , i ] = bstream . ReadBits ( Bc7Tables . ActualBitsCount [ 0 ] [ mode ] ) ;
622
622
}
623
623
}
624
624
// Alpha (if any)
625
625
if ( Bc7Tables . ActualBitsCount [ 1 ] [ mode ] > 0 )
626
626
{
627
627
for ( int j = 0 ; j < numEndpoints ; ++ j )
628
628
{
629
- endpoints [ j ] [ 3 ] = bstream . ReadBits ( Bc7Tables . ActualBitsCount [ 1 ] [ mode ] ) ;
629
+ endpoints [ j , 3 ] = bstream . ReadBits ( Bc7Tables . ActualBitsCount [ 1 ] [ mode ] ) ;
630
630
}
631
631
}
632
632
@@ -639,7 +639,7 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
639
639
// component-wise left-shift
640
640
for ( int j = 0 ; j < 4 ; ++ j )
641
641
{
642
- endpoints [ i ] [ j ] <<= 1 ;
642
+ endpoints [ i , j ] <<= 1 ;
643
643
}
644
644
}
645
645
@@ -652,10 +652,10 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
652
652
// rgb component-wise insert pbits
653
653
for ( int k = 0 ; k < 3 ; ++ k )
654
654
{
655
- endpoints [ 0 ] [ k ] |= i ;
656
- endpoints [ 1 ] [ k ] |= i ;
657
- endpoints [ 2 ] [ k ] |= j ;
658
- endpoints [ 3 ] [ k ] |= j ;
655
+ endpoints [ 0 , k ] |= i ;
656
+ endpoints [ 1 , k ] |= i ;
657
+ endpoints [ 2 , k ] |= j ;
658
+ endpoints [ 3 , k ] |= j ;
659
659
}
660
660
}
661
661
else if ( ( Bc7Tables . bcdec_bc7_sModeHasPBits & ( 1 << mode ) ) != 0 )
@@ -666,7 +666,7 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
666
666
int j = bstream . ReadBit ( ) ;
667
667
for ( int k = 0 ; k < 4 ; ++ k )
668
668
{
669
- endpoints [ i ] [ k ] |= j ;
669
+ endpoints [ i , k ] |= j ;
670
670
}
671
671
}
672
672
}
@@ -680,18 +680,18 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
680
680
for ( int k = 0 ; k < 3 ; ++ k )
681
681
{
682
682
// left shift endpoint components so that their MSB lies in bit 7
683
- endpoints [ i ] [ k ] = endpoints [ i ] [ k ] << ( 8 - j ) ;
683
+ endpoints [ i , k ] = endpoints [ i , k ] << ( 8 - j ) ;
684
684
// Replicate each component's MSB into the LSBs revealed by the left-shift operation above
685
- endpoints [ i ] [ k ] = endpoints [ i ] [ k ] | ( endpoints [ i ] [ k ] >> j ) ;
685
+ endpoints [ i , k ] = endpoints [ i , k ] | ( endpoints [ i , k ] >> j ) ;
686
686
}
687
687
688
688
// get alpha component precision including pbit
689
689
j = Bc7Tables . ActualBitsCount [ 1 ] [ mode ] + ( ( Bc7Tables . bcdec_bc7_sModeHasPBits >> mode ) & 1 ) ;
690
690
691
691
// left shift endpoint components so that their MSB lies in bit 7
692
- endpoints [ i ] [ 3 ] = endpoints [ i ] [ 3 ] << ( 8 - j ) ;
692
+ endpoints [ i , 3 ] = endpoints [ i , 3 ] << ( 8 - j ) ;
693
693
// Replicate each component's MSB into the LSBs revealed by the left-shift operation above
694
- endpoints [ i ] [ 3 ] = endpoints [ i ] [ 3 ] | ( endpoints [ i ] [ 3 ] >> j ) ;
694
+ endpoints [ i , 3 ] = endpoints [ i , 3 ] | ( endpoints [ i , 3 ] >> j ) ;
695
695
}
696
696
697
697
// If this mode does not explicitly define the alpha component
@@ -700,7 +700,7 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
700
700
{
701
701
for ( int j = 0 ; j < numEndpoints ; ++ j )
702
702
{
703
- endpoints [ j ] [ 3 ] = 0xFF ;
703
+ endpoints [ j , 3 ] = 0xFF ;
704
704
}
705
705
}
706
706
@@ -726,7 +726,7 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
726
726
indexBits -- ;
727
727
}
728
728
729
- indices [ i ] [ j ] = bstream . ReadBits ( indexBits ) ;
729
+ indices [ i , j ] = bstream . ReadBits ( indexBits ) ;
730
730
}
731
731
}
732
732
@@ -740,7 +740,7 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
740
740
: Bc7Tables . PartitionSets [ numPartitions - 2 ] [ partition ] [ i ] [ j ] ;
741
741
partitionSet &= 0x03 ;
742
742
743
- int index = indices [ i ] [ j ] ;
743
+ int index = indices [ i , j ] ;
744
744
745
745
int r ;
746
746
int g ;
@@ -749,10 +749,10 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
749
749
750
750
if ( indexBits2 == 0 )
751
751
{
752
- r = Interpolate ( endpoints [ partitionSet * 2 ] [ 0 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 0 ] , weights , index ) ;
753
- g = Interpolate ( endpoints [ partitionSet * 2 ] [ 1 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 1 ] , weights , index ) ;
754
- b = Interpolate ( endpoints [ partitionSet * 2 ] [ 2 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 2 ] , weights , index ) ;
755
- a = Interpolate ( endpoints [ partitionSet * 2 ] [ 3 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 3 ] , weights , index ) ;
752
+ r = Interpolate ( endpoints [ partitionSet * 2 , 0 ] , endpoints [ ( partitionSet * 2 ) + 1 , 0 ] , weights , index ) ;
753
+ g = Interpolate ( endpoints [ partitionSet * 2 , 1 ] , endpoints [ ( partitionSet * 2 ) + 1 , 1 ] , weights , index ) ;
754
+ b = Interpolate ( endpoints [ partitionSet * 2 , 2 ] , endpoints [ ( partitionSet * 2 ) + 1 , 2 ] , weights , index ) ;
755
+ a = Interpolate ( endpoints [ partitionSet * 2 , 3 ] , endpoints [ ( partitionSet * 2 ) + 1 , 3 ] , weights , index ) ;
756
756
}
757
757
else
758
758
{
@@ -764,17 +764,17 @@ public static void DecompressBc7(ReadOnlySpan<byte> compressedBlock, Span<byte>
764
764
// and from the primary index bits otherwise.
765
765
if ( indexSelectionBit == 0 )
766
766
{
767
- r = Interpolate ( endpoints [ partitionSet * 2 ] [ 0 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 0 ] , weights , index ) ;
768
- g = Interpolate ( endpoints [ partitionSet * 2 ] [ 1 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 1 ] , weights , index ) ;
769
- b = Interpolate ( endpoints [ partitionSet * 2 ] [ 2 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 2 ] , weights , index ) ;
770
- a = Interpolate ( endpoints [ partitionSet * 2 ] [ 3 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 3 ] , weights2 , index2 ) ;
767
+ r = Interpolate ( endpoints [ partitionSet * 2 , 0 ] , endpoints [ ( partitionSet * 2 ) + 1 , 0 ] , weights , index ) ;
768
+ g = Interpolate ( endpoints [ partitionSet * 2 , 1 ] , endpoints [ ( partitionSet * 2 ) + 1 , 1 ] , weights , index ) ;
769
+ b = Interpolate ( endpoints [ partitionSet * 2 , 2 ] , endpoints [ ( partitionSet * 2 ) + 1 , 2 ] , weights , index ) ;
770
+ a = Interpolate ( endpoints [ partitionSet * 2 , 3 ] , endpoints [ ( partitionSet * 2 ) + 1 , 3 ] , weights2 , index2 ) ;
771
771
}
772
772
else
773
773
{
774
- r = Interpolate ( endpoints [ partitionSet * 2 ] [ 0 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 0 ] , weights2 , index2 ) ;
775
- g = Interpolate ( endpoints [ partitionSet * 2 ] [ 1 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 1 ] , weights2 , index2 ) ;
776
- b = Interpolate ( endpoints [ partitionSet * 2 ] [ 2 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 2 ] , weights2 , index2 ) ;
777
- a = Interpolate ( endpoints [ partitionSet * 2 ] [ 3 ] , endpoints [ ( partitionSet * 2 ) + 1 ] [ 3 ] , weights , index ) ;
774
+ r = Interpolate ( endpoints [ partitionSet * 2 , 0 ] , endpoints [ ( partitionSet * 2 ) + 1 , 0 ] , weights2 , index2 ) ;
775
+ g = Interpolate ( endpoints [ partitionSet * 2 , 1 ] , endpoints [ ( partitionSet * 2 ) + 1 , 1 ] , weights2 , index2 ) ;
776
+ b = Interpolate ( endpoints [ partitionSet * 2 , 2 ] , endpoints [ ( partitionSet * 2 ) + 1 , 2 ] , weights2 , index2 ) ;
777
+ a = Interpolate ( endpoints [ partitionSet * 2 , 3 ] , endpoints [ ( partitionSet * 2 ) + 1 , 3 ] , weights , index ) ;
778
778
}
779
779
}
780
780
@@ -1056,15 +1056,4 @@ public static void SwapValues(ref int a, ref int b)
1056
1056
{
1057
1057
( a , b ) = ( b , a ) ;
1058
1058
}
1059
-
1060
- public static T [ ] [ ] CreateRectangularArray < T > ( int size1 , int size2 )
1061
- {
1062
- T [ ] [ ] newArray = new T [ size1 ] [ ] ;
1063
- for ( int array1 = 0 ; array1 < size1 ; array1 ++ )
1064
- {
1065
- newArray [ array1 ] = new T [ size2 ] ;
1066
- }
1067
-
1068
- return newArray ;
1069
- }
1070
1059
}
0 commit comments