Input span for Bc7

This commit is contained in:
Jeremy Pritts committed 2022-10-23 22:38:03 -04:00
1 parent 099daf3044
commit c019bc5a04
2 files changed
+8 -10

No files matched your search

+4 -7
View File
@@ -162,18 +162,15 @@ namespace AssetRipper.TextureDecoder.Bc
public unsafe static int DecompressBC7(ReadOnlySpan<byte> input, int width, int height, Span<byte> 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<ColorRGBA32, byte, ColorBGRA32, byte>(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<byte> 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<ColorRGBA32>();
BcHelpers.DecompressBc7(input + inputOffset, output + outputOffset, width * 4);
BcHelpers.DecompressBc7(input.Slice(inputOffset, 16), output + outputOffset, width * 4);
inputOffset += DefineConstants.BCDEC_BC7_BLOCK_SIZE;
}
}
+4 -3
View File
@@ -575,7 +575,7 @@ internal unsafe static class BcHelpers
}
}
public static void DecompressBc7(byte* compressedBlock, byte* decompressedBlock, int destinationPitch)
public static void DecompressBc7(ReadOnlySpan<byte> 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<ulong> compressedBlockSpan = MemoryMarshal.Cast<byte, ulong>(compressedBlock);
bstream.low = compressedBlockSpan[0];
bstream.high = compressedBlockSpan[1];
for (mode = 0; mode < 8 && (0 == bstream.ReadBit()); ++mode)
{