@@ -53,9 +53,6 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
53
53
54
54
private ArithmeticDecodingTable [ ] acDecodingTables ;
55
55
56
- // Use C#'s optimization to refer to assembly's data segment, no allocation occurs.
57
- private ReadOnlySpan < byte > fixedBin => new byte [ ] { 113 , 0 , 0 , 0 } ;
58
-
59
56
private readonly CancellationToken cancellationToken ;
60
57
61
58
private static readonly int [ ] ArithmeticTable =
@@ -232,7 +229,13 @@ public void InitDecodingTables(List<ArithmeticDecodingTable> arithmeticDecodingT
232
229
}
233
230
}
234
231
235
- private ref byte GetFixedBinReference ( ) => ref MemoryMarshal . GetReference ( fixedBin ) ;
232
+ private static ref byte GetFixedBinReference ( )
233
+ {
234
+ // This uses C#'s optimization to refer to the static data segment of the assembly.
235
+ // No allocation occurs.
236
+ ReadOnlySpan < byte > fixedBin = new byte [ ] { 113 , 0 , 0 , 0 } ;
237
+ return ref MemoryMarshal . GetReference ( fixedBin ) ;
238
+ }
236
239
237
240
/// <summary>
238
241
/// Decodes the entropy coded data.
@@ -776,7 +779,7 @@ private void DecodeBlockProgressiveDc(ArithmeticDecodingComponent component, ref
776
779
else
777
780
{
778
781
// Refinement scan.
779
- ref byte st = ref this . GetFixedBinReference ( ) ;
782
+ ref byte st = ref GetFixedBinReference ( ) ;
780
783
781
784
blockDataRef |= ( short ) ( this . DecodeBinaryDecision ( ref reader , ref st ) << this . SuccessiveLow ) ;
782
785
}
@@ -822,7 +825,7 @@ private void DecodeBlockProgressiveAc(ArithmeticDecodingComponent component, ref
822
825
823
826
// Figure F.21: Decoding nonzero value v.
824
827
// Figure F.22: Decoding the sign of v.
825
- int sign = this . DecodeBinaryDecision ( ref reader , ref this . GetFixedBinReference ( ) ) ;
828
+ int sign = this . DecodeBinaryDecision ( ref reader , ref GetFixedBinReference ( ) ) ;
826
829
st = ref Unsafe . Add ( ref st , 2 ) ;
827
830
828
831
// Figure F.23: Decoding the magnitude category of v.
@@ -918,7 +921,7 @@ private void ReadBlockProgressiveAcRefined(ArithmeticStatistics acStatistics, re
918
921
919
922
if ( this . DecodeBinaryDecision ( ref reader , ref Unsafe . Add ( ref st , 1 ) ) != 0 )
920
923
{
921
- bool flag = this . DecodeBinaryDecision ( ref reader , ref this . GetFixedBinReference ( ) ) != 0 ;
924
+ bool flag = this . DecodeBinaryDecision ( ref reader , ref GetFixedBinReference ( ) ) != 0 ;
922
925
coef = ( short ) ( coef + ( flag ? m1 : p1 ) ) ;
923
926
924
927
break ;
@@ -1048,7 +1051,7 @@ private void DecodeBlockBaseline(
1048
1051
1049
1052
// Figure F.21: Decoding nonzero value v.
1050
1053
// Figure F.22: Decoding the sign of v.
1051
- int sign = this . DecodeBinaryDecision ( ref reader , ref this . GetFixedBinReference ( ) ) ;
1054
+ int sign = this . DecodeBinaryDecision ( ref reader , ref GetFixedBinReference ( ) ) ;
1052
1055
st = ref Unsafe . Add ( ref st , 2 ) ;
1053
1056
1054
1057
// Figure F.23: Decoding the magnitude category of v.
0 commit comments