Compare commits

...
Author SHA1 Message Date
ds5678 03713d8d57 Update version to 2.6.2 in Directory.Build.props
Bump the VersionPrefix property from 2.6.1 to 2.6.2 to prepare for the next release.
2026-06-02 14:44:26 -07:00
ds5678 3cf2170242 Ensure that blocks with all bits set do not throw 2026-06-02 14:32:22 -07:00
ds5678 0a8bae09cf Refactor: use Span.Fill for block color assignment
Replaced manual for loop with Span.Fill to efficiently assign a color value to the output span in ASTC block decoding. This improves code readability and performance.
2026-05-21 21:50:21 -07:00
3 changed files with 9 additions and 5 deletions

No files matched your search

@@ -77,6 +77,8 @@ public sealed class AstcTests
}
[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")]
[TestCase(new byte[16] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 8, 8, TestName = "Zero blocks should not throw", Description = "Blocks of all zeros are valid")]
[TestCase(new byte[16] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, 8, 8, TestName = "0xFF blocks should not throw", Description = "Blocks with all bits set are invalid, but should be handled gracefully")]
public void DecodesBlockWithoutThrowing(byte[] block, int blockWidth, int blockHeight)
{
Assert.DoesNotThrow(() => AstcDecoder.DecodeASTC<ColorBGRA<byte>, byte>(block, blockWidth, blockHeight, blockWidth, blockHeight, out _));
@@ -66,10 +66,7 @@ namespace AssetRipper.TextureDecoder.Astc
if (input[0] == 0xfc && (input[1] & 1) == 1)
{
ColorRGBA<byte> c = new(input[9], input[11], input[13], input[15]);
for (int i = 0; i < blockWidth * blockHeight; i++)
{
output[i] = c;
}
output[..(blockWidth * blockHeight)].Fill(c);
}
else
{
@@ -886,6 +883,11 @@ namespace AssetRipper.TextureDecoder.Astc
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private static int GetBits(ReadOnlySpan<byte> input, int bit, int len)
{
if (bit < 0 || input.Length * 8 < bit + len)
{
// Invalid input, but we should return something instead of throwing an exception
return default;
}
ReadOnlySpan<byte> slice = input[(bit / 8)..];
int bitBuffer;
if (slice.Length >= sizeof(int))
+1 -1
View File
@@ -6,7 +6,7 @@
<IsAotCompatible>true</IsAotCompatible>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<VersionPrefix>2.6.1</VersionPrefix>
<VersionPrefix>2.6.2</VersionPrefix>
<Copyright>Copyright © ds5678</Copyright>
<Authors>ds5678</Authors>
<Company>AssetRipper</Company>