@@ -30,7 +30,7 @@ public static class AstcDecoder
3030 /// <exception cref="InvalidOperationException">If decompression fails for any block</exception>
3131 public static Span < byte > DecompressImage ( ReadOnlySpan < byte > astcData , int width , int height , Footprint footprint )
3232 {
33- var imageBuffer = new byte [ width * height * BytesPerPixelUnorm8 ] ;
33+ byte [ ] imageBuffer = new byte [ width * height * BytesPerPixelUnorm8 ] ;
3434
3535 return DecompressImage ( astcData , width , height , footprint , imageBuffer )
3636 ? imageBuffer
@@ -54,13 +54,13 @@ public static bool DecompressImage(ReadOnlySpan<byte> astcData, int width, int h
5454 return false ;
5555 }
5656
57- var decodedBlock = Array . Empty < byte > ( ) ;
57+ byte [ ] decodedBlock = [ ] ;
5858
5959 try
6060 {
6161 // Create a buffer once for fallback blocks; fast path writes directly to image
6262 decodedBlock = ArrayPool . Rent ( footprint . Width * footprint . Height * BytesPerPixelUnorm8 ) ;
63- var decodedPixels = decodedBlock . AsSpan ( ) ;
63+ Span < byte > decodedPixels = decodedBlock . AsSpan ( ) ;
6464 int blockIndex = 0 ;
6565 int footprintWidth = footprint . Width ;
6666 int footprintHeight = footprint . Height ;
@@ -75,16 +75,16 @@ public static bool DecompressImage(ReadOnlySpan<byte> astcData, int width, int h
7575 continue ;
7676 }
7777
78- ulong low = BinaryPrimitives . ReadUInt64LittleEndian ( astcData . Slice ( blockDataOffset ) ) ;
79- ulong high = BinaryPrimitives . ReadUInt64LittleEndian ( astcData . Slice ( blockDataOffset + 8 ) ) ;
80- var blockBits = new UInt128 ( high , low ) ;
78+ ulong low = BinaryPrimitives . ReadUInt64LittleEndian ( astcData [ blockDataOffset .. ] ) ;
79+ ulong high = BinaryPrimitives . ReadUInt64LittleEndian ( astcData [ ( blockDataOffset + 8 ) .. ] ) ;
80+ UInt128 blockBits = new ( high , low ) ;
8181
8282 int dstBaseX = blockX * footprintWidth ;
8383 int dstBaseY = blockY * footprintHeight ;
8484 int copyWidth = Math . Min ( footprintWidth , width - dstBaseX ) ;
8585 int copyHeight = Math . Min ( footprintHeight , height - dstBaseY ) ;
8686
87- var info = BlockInfo . Decode ( blockBits ) ;
87+ BlockInfo info = BlockInfo . Decode ( blockBits ) ;
8888 if ( ! info . IsValid )
8989 {
9090 continue ;
@@ -114,7 +114,7 @@ public static bool DecompressImage(ReadOnlySpan<byte> astcData, int width, int h
114114 }
115115 else
116116 {
117- var logicalBlock = LogicalBlock . UnpackLogicalBlock ( footprint , blockBits , in info ) ;
117+ LogicalBlock ? logicalBlock = LogicalBlock . UnpackLogicalBlock ( footprint , blockBits , in info ) ;
118118 if ( logicalBlock is null )
119119 {
120120 continue ;
@@ -150,11 +150,11 @@ public static bool DecompressImage(ReadOnlySpan<byte> astcData, int width, int h
150150 /// <returns>The decoded block of pixels as RGBA values</returns>
151151 public static Span < byte > DecompressBlock ( ReadOnlySpan < byte > blockData , Footprint footprint )
152152 {
153- var decodedPixels = Array . Empty < byte > ( ) ;
153+ byte [ ] decodedPixels = [ ] ;
154154 try
155155 {
156156 decodedPixels = ArrayPool . Rent ( footprint . Width * footprint . Height * BytesPerPixelUnorm8 ) ;
157- var decodedPixelBuffer = decodedPixels . AsSpan ( ) ;
157+ Span < byte > decodedPixelBuffer = decodedPixels . AsSpan ( ) ;
158158
159159 DecompressBlock ( blockData , footprint , decodedPixelBuffer ) ;
160160 }
@@ -176,10 +176,10 @@ public static void DecompressBlock(ReadOnlySpan<byte> blockData, Footprint footp
176176 {
177177 // Read the 16 bytes that make up the ASTC block as a 128-bit value
178178 ulong low = BinaryPrimitives . ReadUInt64LittleEndian ( blockData ) ;
179- ulong high = BinaryPrimitives . ReadUInt64LittleEndian ( blockData . Slice ( 8 ) ) ;
180- var blockBits = new UInt128 ( high , low ) ;
179+ ulong high = BinaryPrimitives . ReadUInt64LittleEndian ( blockData [ 8 .. ] ) ;
180+ UInt128 blockBits = new ( high , low ) ;
181181
182- var info = BlockInfo . Decode ( blockBits ) ;
182+ BlockInfo info = BlockInfo . Decode ( blockBits ) ;
183183 if ( ! info . IsValid )
184184 {
185185 return ;
@@ -194,7 +194,7 @@ public static void DecompressBlock(ReadOnlySpan<byte> blockData, Footprint footp
194194 }
195195
196196 // Fallback for void extent, multi-partition, dual plane, HDR
197- var logicalBlock = LogicalBlock . UnpackLogicalBlock ( footprint , blockBits , in info ) ;
197+ LogicalBlock ? logicalBlock = LogicalBlock . UnpackLogicalBlock ( footprint , blockBits , in info ) ;
198198 if ( logicalBlock is null )
199199 {
200200 return ;
@@ -216,7 +216,7 @@ public static void DecompressBlock(ReadOnlySpan<byte> blockData, Footprint footp
216216 public static Span < float > DecompressHdrImage ( ReadOnlySpan < byte > astcData , int width , int height , Footprint footprint )
217217 {
218218 const int channelsPerPixel = 4 ;
219- var imageBuffer = new float [ width * height * channelsPerPixel ] ;
219+ float [ ] imageBuffer = new float [ width * height * channelsPerPixel ] ;
220220 if ( ! DecompressHdrImage ( astcData , width , height , footprint , imageBuffer ) )
221221 {
222222 return [ ] ;
@@ -243,13 +243,13 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
243243 }
244244
245245 const int channelsPerPixel = 4 ;
246- var decodedBlock = Array . Empty < float > ( ) ;
246+ float [ ] decodedBlock = [ ] ;
247247
248248 try
249249 {
250250 // Create a buffer once for fallback blocks; fast path writes directly to image
251251 decodedBlock = ArrayPool < float > . Shared . Rent ( footprint . Width * footprint . Height * channelsPerPixel ) ;
252- var decodedPixels = decodedBlock . AsSpan ( ) ;
252+ Span < float > decodedPixels = decodedBlock . AsSpan ( ) ;
253253 int blockIndex = 0 ;
254254 int footprintWidth = footprint . Width ;
255255 int footprintHeight = footprint . Height ;
@@ -264,16 +264,16 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
264264 continue ;
265265 }
266266
267- ulong low = BinaryPrimitives . ReadUInt64LittleEndian ( astcData . Slice ( blockDataOffset ) ) ;
268- ulong high = BinaryPrimitives . ReadUInt64LittleEndian ( astcData . Slice ( blockDataOffset + 8 ) ) ;
269- var blockBits = new UInt128 ( high , low ) ;
267+ ulong low = BinaryPrimitives . ReadUInt64LittleEndian ( astcData [ blockDataOffset .. ] ) ;
268+ ulong high = BinaryPrimitives . ReadUInt64LittleEndian ( astcData [ ( blockDataOffset + 8 ) .. ] ) ;
269+ UInt128 blockBits = new ( high , low ) ;
270270
271271 int dstBaseX = blockX * footprintWidth ;
272272 int dstBaseY = blockY * footprintHeight ;
273273 int copyWidth = Math . Min ( footprintWidth , width - dstBaseX ) ;
274274 int copyHeight = Math . Min ( footprintHeight , height - dstBaseY ) ;
275275
276- var info = BlockInfo . Decode ( blockBits ) ;
276+ BlockInfo info = BlockInfo . Decode ( blockBits ) ;
277277 if ( ! info . IsValid )
278278 {
279279 continue ;
@@ -302,7 +302,7 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
302302 else
303303 {
304304 // Fallback: LogicalBlock path for void extent, multi-partition, dual plane
305- var logicalBlock = LogicalBlock . UnpackLogicalBlock ( footprint , blockBits , in info ) ;
305+ LogicalBlock ? logicalBlock = LogicalBlock . UnpackLogicalBlock ( footprint , blockBits , in info ) ;
306306 if ( logicalBlock is null )
307307 {
308308 continue ;
@@ -312,7 +312,7 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
312312 {
313313 for ( int column = 0 ; column < footprintWidth ; ++ column )
314314 {
315- var pixelOffset = ( footprintWidth * row * channelsPerPixel ) + ( column * channelsPerPixel ) ;
315+ int pixelOffset = ( footprintWidth * row * channelsPerPixel ) + ( column * channelsPerPixel ) ;
316316 logicalBlock . WriteHdrPixel ( column , row , decodedPixels . Slice ( pixelOffset , channelsPerPixel ) ) ;
317317 }
318318 }
@@ -349,7 +349,7 @@ public static bool DecompressHdrImage(ReadOnlySpan<byte> astcData, int width, in
349349 /// </returns>
350350 public static Span < float > DecompressHdrImage ( ReadOnlySpan < byte > astcData , int width , int height , FootprintType footprint )
351351 {
352- var footPrint = Footprint . FromFootprintType ( footprint ) ;
352+ Footprint footPrint = Footprint . FromFootprintType ( footprint ) ;
353353 return DecompressHdrImage ( astcData , width , height , footPrint ) ;
354354 }
355355
@@ -363,10 +363,10 @@ public static void DecompressHdrBlock(ReadOnlySpan<byte> blockData, Footprint fo
363363 {
364364 // Read the 16 bytes that make up the ASTC block as a 128-bit value
365365 ulong low = BinaryPrimitives . ReadUInt64LittleEndian ( blockData ) ;
366- ulong high = BinaryPrimitives . ReadUInt64LittleEndian ( blockData . Slice ( 8 ) ) ;
367- var blockBits = new UInt128 ( high , low ) ;
366+ ulong high = BinaryPrimitives . ReadUInt64LittleEndian ( blockData [ 8 .. ] ) ;
367+ UInt128 blockBits = new ( high , low ) ;
368368
369- var info = BlockInfo . Decode ( blockBits ) ;
369+ BlockInfo info = BlockInfo . Decode ( blockBits ) ;
370370 if ( ! info . IsValid )
371371 {
372372 return ;
@@ -380,7 +380,7 @@ public static void DecompressHdrBlock(ReadOnlySpan<byte> blockData, Footprint fo
380380 }
381381
382382 // Fallback for void extent, multi-partition, dual plane
383- var logicalBlock = LogicalBlock . UnpackLogicalBlock ( footprint , blockBits , in info ) ;
383+ LogicalBlock ? logicalBlock = LogicalBlock . UnpackLogicalBlock ( footprint , blockBits , in info ) ;
384384 if ( logicalBlock is null )
385385 {
386386 return ;
@@ -391,7 +391,7 @@ public static void DecompressHdrBlock(ReadOnlySpan<byte> blockData, Footprint fo
391391 {
392392 for ( int column = 0 ; column < footprint . Width ; ++ column )
393393 {
394- var pixelOffset = ( footprint . Width * row * channelsPerPixel ) + ( column * channelsPerPixel ) ;
394+ int pixelOffset = ( footprint . Width * row * channelsPerPixel ) + ( column * channelsPerPixel ) ;
395395 logicalBlock . WriteHdrPixel ( column , row , buffer . Slice ( pixelOffset , channelsPerPixel ) ) ;
396396 }
397397 }
@@ -406,7 +406,7 @@ internal static Span<byte> DecompressImage(AstcFile file)
406406
407407 internal static Span < byte > DecompressImage ( ReadOnlySpan < byte > astcData , int width , int height , FootprintType footprint )
408408 {
409- var footPrint = Footprint . FromFootprintType ( footprint ) ;
409+ Footprint footPrint = Footprint . FromFootprintType ( footprint ) ;
410410
411411 return DecompressImage ( astcData , width , height , footPrint ) ;
412412 }
0 commit comments