forked from MeloNX/MeloNX
* dotnet format style --severity info Some changes were manually reverted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0059 warnings * Address or silence dotnet format CA2208 warnings * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Address IDE0251 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * Address review feedback * Update src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
77 lines
2.0 KiB
C#
77 lines
2.0 KiB
C#
namespace Ryujinx.Graphics.Texture.Astc
|
|
{
|
|
internal static class Bits
|
|
{
|
|
public static readonly ushort[] Replicate8_16Table;
|
|
public static readonly byte[] Replicate1_7Table;
|
|
|
|
static Bits()
|
|
{
|
|
Replicate8_16Table = new ushort[0x200];
|
|
Replicate1_7Table = new byte[0x200];
|
|
|
|
for (int i = 0; i < 0x200; i++)
|
|
{
|
|
Replicate8_16Table[i] = (ushort)Replicate(i, 8, 16);
|
|
Replicate1_7Table[i] = (byte)Replicate(i, 1, 7);
|
|
}
|
|
}
|
|
|
|
public static int Replicate8_16(int value)
|
|
{
|
|
return Replicate8_16Table[value];
|
|
}
|
|
|
|
public static int Replicate1_7(int value)
|
|
{
|
|
return Replicate1_7Table[value];
|
|
}
|
|
|
|
public static int Replicate(int value, int numberBits, int toBit)
|
|
{
|
|
if (numberBits == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
if (toBit == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int tempValue = value & ((1 << numberBits) - 1);
|
|
int retValue = tempValue;
|
|
int resLength = numberBits;
|
|
|
|
while (resLength < toBit)
|
|
{
|
|
int comp = 0;
|
|
if (numberBits > toBit - resLength)
|
|
{
|
|
int newShift = toBit - resLength;
|
|
comp = numberBits - newShift;
|
|
numberBits = newShift;
|
|
}
|
|
retValue <<= numberBits;
|
|
retValue |= tempValue >> comp;
|
|
resLength += numberBits;
|
|
}
|
|
|
|
return retValue;
|
|
}
|
|
|
|
// Transfers a bit as described in C.2.14
|
|
public static void BitTransferSigned(ref int a, ref int b)
|
|
{
|
|
b >>= 1;
|
|
b |= a & 0x80;
|
|
a >>= 1;
|
|
a &= 0x3F;
|
|
if ((a & 0x20) != 0)
|
|
{
|
|
a -= 0x40;
|
|
}
|
|
}
|
|
}
|
|
}
|