From 58b113e1e01b429e4f82c1bb53d31922c4e33cd0 Mon Sep 17 00:00:00 2001 From: Jeremy Pritts <49847914+ds5678@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:28:59 -0400 Subject: [PATCH] Remove some unnecessary variable assignments --- AssetRipper.TextureDecoder/Bc/BcHelpers.cs | 30 +++++++++------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/AssetRipper.TextureDecoder/Bc/BcHelpers.cs b/AssetRipper.TextureDecoder/Bc/BcHelpers.cs index c46b0b3..378221a 100644 --- a/AssetRipper.TextureDecoder/Bc/BcHelpers.cs +++ b/AssetRipper.TextureDecoder/Bc/BcHelpers.cs @@ -65,8 +65,8 @@ internal unsafe static class BcHelpers public static void DecompressBc6h_Half(ReadOnlySpan compressedBlock, Span decompressedBlock, int destinationPitch, bool isSigned) { BitStream bstream = new(); - Span r = stackalloc int[4]; // wxyz - Span g = stackalloc int[4]; + Span r = stackalloc int[4]; // wxyz + Span g = stackalloc int[4]; Span b = stackalloc int[4]; int decompressedOffset = 0; @@ -85,7 +85,7 @@ internal unsafe static class BcHelpers mode |= bstream.ReadBits(3) << 2; } - int partition = default; + int partition; switch (mode) { // mode 1 @@ -413,6 +413,7 @@ internal unsafe static class BcHelpers r[1] |= bstream.ReadBits(10); // rx[9:0] g[1] |= bstream.ReadBits(10); // gx[9:0] b[1] |= bstream.ReadBits(10); // bx[9:0] + partition = 0; mode = 10; } break; @@ -432,6 +433,7 @@ internal unsafe static class BcHelpers g[0] |= bstream.ReadBit() << 10; // gw[10] b[1] |= bstream.ReadBits(9); // bx[8:0] b[0] |= bstream.ReadBit() << 10; // bw[10] + partition = 0; mode = 11; } break; @@ -451,6 +453,7 @@ internal unsafe static class BcHelpers g[0] |= bstream.ReadBitsReversed(2) << 10; // gx[10:11] b[1] |= bstream.ReadBits(8); // bx[7:0] b[0] |= bstream.ReadBitsReversed(2) << 10; // bx[10:11] + partition = 0; mode = 12; } break; @@ -470,6 +473,7 @@ internal unsafe static class BcHelpers g[0] |= bstream.ReadBitsReversed(6) << 10; // gw[10:15] b[1] |= bstream.ReadBits(4); // bx[3:0] b[0] |= bstream.ReadBitsReversed(6) << 10; // bw[10:15] + partition = 0; mode = 13; } break; @@ -495,17 +499,7 @@ internal unsafe static class BcHelpers } } - int numPartitions; - if (mode >= 10) - { - partition = 0; - numPartitions = 0; - } - else - { - numPartitions = 1; - } - + int numPartitions = mode >= 10 ? 0 : 1; if (isSigned) { r[0] = ExtendSign(r[0], Bc6hTables.ActualBitsCount[0][mode]); @@ -533,7 +527,7 @@ internal unsafe static class BcHelpers g[i] = TransformInverse(g[i], g[0], Bc6hTables.ActualBitsCount[0][mode], isSigned); b[i] = TransformInverse(b[i], b[0], Bc6hTables.ActualBitsCount[0][mode], isSigned); } - } + } for (int i = 0; i < 4; ++i) { @@ -550,9 +544,9 @@ internal unsafe static class BcHelpers } partitionSet &= 0x01; - int index = bstream.ReadBits(indexBits); - - // endpoints A and B + int index = bstream.ReadBits(indexBits); + + // endpoints A and B int epR0 = Unquantize(r[(partitionSet * 2) + 0], Bc6hTables.ActualBitsCount[0][mode], isSigned); int epG0 = Unquantize(g[(partitionSet * 2) + 0], Bc6hTables.ActualBitsCount[0][mode], isSigned); int epB0 = Unquantize(b[(partitionSet * 2) + 0], Bc6hTables.ActualBitsCount[0][mode], isSigned);