Skip to content

Commit c6d3236

Browse files
committed
Resolve #59
1 parent 34d8310 commit c6d3236

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

AssetRipper.TextureDecoder.Tests/AstcTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ private static void AssertCorrectDecompression<T>(int blockWidth, int blockHeigh
7575
ByteArrayDeviation.AssertMinimalDeviation(decompressedData, AndroidTextures.Logo_00.Data, maxMeanDeviation, maxStandardDeviation);
7676
}
7777

78-
[Ignore("Bug not yet fixed")]
7978
[TestCase(new byte[16] { 83, 1, 147, 104, 198, 173, 55, 116, 182, 66, 105, 11, 102, 43, 148, 125 }, 8, 8, TestName = "GetBits Should not throw in DecodeIntseq")]
8079
public void DecodesBlockWithoutThrowing(byte[] block, int blockWidth, int blockHeight)
8180
{

AssetRipper.TextureDecoder/Astc/AstcDecoder.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,19 @@ private static ulong BitReverseU64(ulong d, int bits)
883883
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
884884
private static int GetBits(ReadOnlySpan<byte> input, int bit, int len)
885885
{
886-
return (BinaryPrimitives.ReadInt32LittleEndian(input[(bit / 8)..]) >> (bit % 8)) & ((1 << len) - 1);
886+
ReadOnlySpan<byte> slice = input[(bit / 8)..];
887+
int bitBuffer;
888+
if (slice.Length >= sizeof(int))
889+
{
890+
bitBuffer = BinaryPrimitives.ReadInt32LittleEndian(slice);
891+
}
892+
else
893+
{
894+
Span<byte> temp = stackalloc byte[sizeof(int)];
895+
slice.CopyTo(temp);
896+
bitBuffer = BinaryPrimitives.ReadInt32LittleEndian(temp);
897+
}
898+
return (bitBuffer >> (bit % 8)) & ((1 << len) - 1);
887899
}
888900

889901
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]

0 commit comments

Comments
 (0)