@@ -37,10 +37,10 @@ internal static class EtcDecoder
37
37
38
38
public static void DecodeEtc1Block ( Span < byte > payload , Span < byte > decodedPixelSpan )
39
39
{
40
- var red = payload [ 0 ] ;
41
- var green = payload [ 1 ] ;
42
- var blue = payload [ 2 ] ;
43
- var codeWordsWithFlags = payload [ 3 ] ;
40
+ byte red = payload [ 0 ] ;
41
+ byte green = payload [ 1 ] ;
42
+ byte blue = payload [ 2 ] ;
43
+ byte codeWordsWithFlags = payload [ 3 ] ;
44
44
45
45
bool diffFlag = ( codeWordsWithFlags & 2 ) != 0 ;
46
46
bool flipFlag = ( codeWordsWithFlags & 1 ) != 0 ;
@@ -83,7 +83,7 @@ public static void DecodeEtc1Block(Span<byte> payload, Span<byte> decodedPixelSp
83
83
c1b = c1b4 | ( c1b4 << 4 ) ;
84
84
}
85
85
86
- var pixelIndexWord = BinaryPrimitives . ReadUInt32BigEndian ( payload . Slice ( 4 , 4 ) ) ;
86
+ uint pixelIndexWord = BinaryPrimitives . ReadUInt32BigEndian ( payload . Slice ( 4 , 4 ) ) ;
87
87
88
88
// Check if the sub-blocks are horizontal or vertical.
89
89
if ( ! flipFlag )
@@ -244,10 +244,10 @@ private static void ProcessBlockEtc2PlanarMode(Span<byte> payload, Span<byte> de
244
244
{
245
245
for ( int x = 0 ; x < 4 ; x ++ )
246
246
{
247
- var r = ( byte ) Helper . Clamp ( ( ( x * ( rh - ro ) ) + ( y * ( rv - ro ) ) + ( 4 * ro ) + 2 ) >> 2 , 0 , 255 ) ;
248
- var g = ( byte ) Helper . Clamp ( ( ( x * ( gh - go ) ) + ( y * ( gv - go ) ) + ( 4 * go ) + 2 ) >> 2 , 0 , 255 ) ;
249
- var b = ( byte ) Helper . Clamp ( ( ( x * ( bh - bo ) ) + ( y * ( bv - bo ) ) + ( 4 * bo ) + 2 ) >> 2 , 0 , 255 ) ;
250
- var pixelIdx = ( ( y * 4 ) + x ) * 3 ;
247
+ byte r = ( byte ) Helper . Clamp ( ( ( x * ( rh - ro ) ) + ( y * ( rv - ro ) ) + ( 4 * ro ) + 2 ) >> 2 , 0 , 255 ) ;
248
+ byte g = ( byte ) Helper . Clamp ( ( ( x * ( gh - go ) ) + ( y * ( gv - go ) ) + ( 4 * go ) + 2 ) >> 2 , 0 , 255 ) ;
249
+ byte b = ( byte ) Helper . Clamp ( ( ( x * ( bh - bo ) ) + ( y * ( bv - bo ) ) + ( 4 * bo ) + 2 ) >> 2 , 0 , 255 ) ;
250
+ int pixelIdx = ( ( y * 4 ) + x ) * 3 ;
251
251
decodedPixelSpan [ pixelIdx ] = r ;
252
252
decodedPixelSpan [ pixelIdx + 1 ] = g ;
253
253
decodedPixelSpan [ pixelIdx + 2 ] = b ;
@@ -261,20 +261,20 @@ private static void ProcessBlockEtc2TMode(Span<byte> payload, Span<byte> decoded
261
261
int [ ] paintColorG = new int [ 4 ] ;
262
262
int [ ] paintColorB = new int [ 4 ] ;
263
263
264
- var c0r = ( ( payload [ 0 ] & 0x18 ) >> 1 ) | ( payload [ 0 ] & 0x3 ) ;
264
+ int c0r = ( ( payload [ 0 ] & 0x18 ) >> 1 ) | ( payload [ 0 ] & 0x3 ) ;
265
265
c0r |= c0r << 4 ;
266
- var c0g = payload [ 1 ] & 0xF0 ;
266
+ int c0g = payload [ 1 ] & 0xF0 ;
267
267
c0g |= c0g >> 4 ;
268
- var c0b = payload [ 1 ] & 0x0F ;
268
+ int c0b = payload [ 1 ] & 0x0F ;
269
269
c0b |= c0b << 4 ;
270
- var c1r = payload [ 2 ] & 0xF0 ;
270
+ int c1r = payload [ 2 ] & 0xF0 ;
271
271
c1r |= c1r >> 4 ;
272
- var c1g = payload [ 2 ] & 0x0F ;
272
+ int c1g = payload [ 2 ] & 0x0F ;
273
273
c1g |= c1g << 4 ;
274
- var c1b = payload [ 3 ] & 0xF0 ;
274
+ int c1b = payload [ 3 ] & 0xF0 ;
275
275
c1b |= c1b >> 4 ;
276
276
277
- var distance = Etc2DistanceTable [ ( ( payload [ 3 ] & 0x0C ) >> 1 ) | ( payload [ 3 ] & 0x1 ) ] ;
277
+ int distance = Etc2DistanceTable [ ( ( payload [ 3 ] & 0x0C ) >> 1 ) | ( payload [ 3 ] & 0x1 ) ] ;
278
278
paintColorR [ 0 ] = c0r ;
279
279
paintColorG [ 0 ] = c0g ;
280
280
paintColorB [ 0 ] = c0b ;
@@ -289,7 +289,7 @@ private static void ProcessBlockEtc2TMode(Span<byte> payload, Span<byte> decoded
289
289
paintColorB [ 3 ] = Helper . Clamp ( c1b - distance , 0 , 255 ) ;
290
290
291
291
uint pixel_index_word = ( uint ) ( ( payload [ 4 ] << 24 ) | ( payload [ 5 ] << 16 ) | ( payload [ 6 ] << 8 ) | payload [ 7 ] ) ;
292
- var decodedPixelIdx = 0 ;
292
+ int decodedPixelIdx = 0 ;
293
293
for ( int i = 0 ; i < 16 ; i ++ )
294
294
{
295
295
uint pixel_index = ( uint ) ( ( ( pixel_index_word & ( 1 << i ) ) >> i ) | ( ( pixel_index_word & ( 0x10000 << i ) ) >> ( 16 + i - 1 ) ) ) ;
@@ -308,24 +308,24 @@ private static void ProcessBlockEtc2HMode(Span<byte> payload, Span<byte> decoded
308
308
int [ ] paintColorG = new int [ 4 ] ;
309
309
int [ ] paintColorB = new int [ 4 ] ;
310
310
311
- var c0r = ( payload [ 0 ] & 0x78 ) >> 3 ;
311
+ int c0r = ( payload [ 0 ] & 0x78 ) >> 3 ;
312
312
c0r |= c0r << 4 ;
313
- var c0g = ( ( payload [ 0 ] & 0x07 ) << 1 ) | ( ( payload [ 1 ] & 0x10 ) >> 4 ) ;
313
+ int c0g = ( ( payload [ 0 ] & 0x07 ) << 1 ) | ( ( payload [ 1 ] & 0x10 ) >> 4 ) ;
314
314
c0g |= c0g << 4 ;
315
- var c0b = ( payload [ 1 ] & 0x08 ) | ( ( payload [ 1 ] & 0x03 ) << 1 ) | ( ( payload [ 2 ] & 0x80 ) >> 7 ) ;
315
+ int c0b = ( payload [ 1 ] & 0x08 ) | ( ( payload [ 1 ] & 0x03 ) << 1 ) | ( ( payload [ 2 ] & 0x80 ) >> 7 ) ;
316
316
c0b |= c0b << 4 ;
317
- var c1r = ( payload [ 2 ] & 0x78 ) >> 3 ;
317
+ int c1r = ( payload [ 2 ] & 0x78 ) >> 3 ;
318
318
c1r |= c1r << 4 ;
319
- var c1g = ( ( payload [ 2 ] & 0x07 ) << 1 ) | ( ( payload [ 3 ] & 0x80 ) >> 7 ) ;
319
+ int c1g = ( ( payload [ 2 ] & 0x07 ) << 1 ) | ( ( payload [ 3 ] & 0x80 ) >> 7 ) ;
320
320
c1g |= c1g << 4 ;
321
- var c1b = ( payload [ 3 ] & 0x78 ) >> 3 ;
321
+ int c1b = ( payload [ 3 ] & 0x78 ) >> 3 ;
322
322
c1b |= c1b << 4 ;
323
323
324
324
int baseColor0Value = ( c0r << 16 ) + ( c0g << 8 ) + c0b ;
325
325
int baseColor1Value = ( c1r << 16 ) + ( c1g << 8 ) + c1b ;
326
326
int bit = baseColor0Value >= baseColor1Value ? 1 : 0 ;
327
327
328
- var distance = Etc2DistanceTable [ ( payload [ 3 ] & 0x04 ) | ( ( payload [ 3 ] & 0x01 ) << 1 ) | bit ] ;
328
+ int distance = Etc2DistanceTable [ ( payload [ 3 ] & 0x04 ) | ( ( payload [ 3 ] & 0x01 ) << 1 ) | bit ] ;
329
329
paintColorR [ 0 ] = Helper . Clamp ( c0r + distance , 0 , 255 ) ;
330
330
paintColorG [ 0 ] = Helper . Clamp ( c0g + distance , 0 , 255 ) ;
331
331
paintColorB [ 0 ] = Helper . Clamp ( c0b + distance , 0 , 255 ) ;
@@ -340,7 +340,7 @@ private static void ProcessBlockEtc2HMode(Span<byte> payload, Span<byte> decoded
340
340
paintColorB [ 3 ] = Helper . Clamp ( c1b - distance , 0 , 255 ) ;
341
341
342
342
uint pixel_index_word = ( uint ) ( ( payload [ 4 ] << 24 ) | ( payload [ 5 ] << 16 ) | ( payload [ 6 ] << 8 ) | payload [ 7 ] ) ;
343
- var decodedPixelIdx = 0 ;
343
+ int decodedPixelIdx = 0 ;
344
344
for ( int i = 0 ; i < 16 ; i ++ )
345
345
{
346
346
uint pixel_index = ( uint ) ( ( ( pixel_index_word & ( 1 << i ) ) >> i ) | ( ( pixel_index_word & ( 0x10000 << i ) ) >> ( 16 + i - 1 ) ) ) ;
@@ -356,7 +356,7 @@ private static void ProcessBlockEtc2HMode(Span<byte> payload, Span<byte> decoded
356
356
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
357
357
private static int FiveToEightBit ( int color )
358
358
{
359
- var c0r = color | ( ( color & 0xE0 ) >> 5 ) ;
359
+ int c0r = color | ( ( color & 0xE0 ) >> 5 ) ;
360
360
return c0r ;
361
361
}
362
362
@@ -372,7 +372,7 @@ private static int FiveToEightBit(int color)
372
372
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
373
373
private static void ProcessPixelEtc1 ( int i , uint pixelIndexWord , uint tableCodeword , byte redBaseColorSubBlock , byte greenBaseColorSubBlock , byte blueBaseColorSubBlock , Span < byte > pixelBuffer )
374
374
{
375
- var pixelIndex = ( ( pixelIndexWord & ( 1 << i ) ) >> i ) | ( ( pixelIndexWord & ( 0x10000 << i ) ) >> ( 16 + i - 1 ) ) ;
375
+ long pixelIndex = ( ( pixelIndexWord & ( 1 << i ) ) >> i ) | ( ( pixelIndexWord & ( 0x10000 << i ) ) >> ( 16 + i - 1 ) ) ;
376
376
int modifier = ModifierTable [ tableCodeword , pixelIndex ] ;
377
377
byte red = ( byte ) Helper . Clamp ( 0 , redBaseColorSubBlock + modifier , 255 ) ;
378
378
byte green = ( byte ) Helper . Clamp ( 0 , greenBaseColorSubBlock + modifier , 255 ) ;
0 commit comments