diff --git a/AssetRipper.TextureDecoder/Bc/BcDecoder.cs b/AssetRipper.TextureDecoder/Bc/BcDecoder.cs index 95f995f..de2f4bf 100644 --- a/AssetRipper.TextureDecoder/Bc/BcDecoder.cs +++ b/AssetRipper.TextureDecoder/Bc/BcDecoder.cs @@ -162,18 +162,15 @@ namespace AssetRipper.TextureDecoder.Bc public unsafe static int DecompressBC7(ReadOnlySpan input, int width, int height, Span output) { int bytesRead; - fixed (byte* inputPtr = input) + fixed (byte* outputPtr = output) { - fixed (byte* outputPtr = output) - { - bytesRead = DecompressBC7(inputPtr, width, height, outputPtr); - } + bytesRead = DecompressBC7(input, width, height, outputPtr); } RgbConverter.Convert(output, width, height, output); return bytesRead; } - private unsafe static int DecompressBC7(byte* input, int width, int height, byte* output) + private unsafe static int DecompressBC7(ReadOnlySpan input, int width, int height, byte* output) { int inputOffset = 0; for (int i = 0; i < height; i += 4) @@ -181,7 +178,7 @@ namespace AssetRipper.TextureDecoder.Bc for (int j = 0; j < width; j += 4) { int outputOffset = ((i * width) + j) * Unsafe.SizeOf(); - BcHelpers.DecompressBc7(input + inputOffset, output + outputOffset, width * 4); + BcHelpers.DecompressBc7(input.Slice(inputOffset, 16), output + outputOffset, width * 4); inputOffset += DefineConstants.BCDEC_BC7_BLOCK_SIZE; } } diff --git a/AssetRipper.TextureDecoder/Bc/BcHelpers.cs b/AssetRipper.TextureDecoder/Bc/BcHelpers.cs index e13ab4a..a22dfe3 100644 --- a/AssetRipper.TextureDecoder/Bc/BcHelpers.cs +++ b/AssetRipper.TextureDecoder/Bc/BcHelpers.cs @@ -575,7 +575,7 @@ internal unsafe static class BcHelpers } } - public static void DecompressBc7(byte* compressedBlock, byte* decompressedBlock, int destinationPitch) + public static void DecompressBc7(ReadOnlySpan compressedBlock, byte* decompressedBlock, int destinationPitch) { BitStream bstream = new BitStream(); int mode; @@ -604,8 +604,9 @@ internal unsafe static class BcHelpers byte* decompressed = decompressedBlock; - bstream.low = ((ulong*)compressedBlock)[0]; - bstream.high = ((ulong*)compressedBlock)[1]; + ReadOnlySpan compressedBlockSpan = MemoryMarshal.Cast(compressedBlock); + bstream.low = compressedBlockSpan[0]; + bstream.high = compressedBlockSpan[1]; for (mode = 0; mode < 8 && (0 == bstream.ReadBit()); ++mode) {