diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2021-12-30 13:10:54 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-30 17:10:54 +0100 |
| commit | c05c8e09d48eb36beef02fda885ec0fd36135463 (patch) | |
| tree | 7a83c260c275e9d445e0c2561c2894158b8620a5 /Ryujinx.Graphics.Texture | |
| parent | 1485780d90a554a9a71585ff1dd6e049b32b761e (diff) | |
Add support for the R4G4 texture format (#2956)
Diffstat (limited to 'Ryujinx.Graphics.Texture')
| -rw-r--r-- | Ryujinx.Graphics.Texture/PixelConverter.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Texture/PixelConverter.cs b/Ryujinx.Graphics.Texture/PixelConverter.cs new file mode 100644 index 00000000..d7e45a69 --- /dev/null +++ b/Ryujinx.Graphics.Texture/PixelConverter.cs @@ -0,0 +1,39 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; + +namespace Ryujinx.Graphics.Texture +{ + public static class PixelConverter + { + public unsafe static byte[] ConvertR4G4ToR4G4B4A4(ReadOnlySpan<byte> data) + { + byte[] output = new byte[data.Length * 2]; + int start = 0; + + if (Sse41.IsSupported) + { + int sizeTrunc = data.Length & ~7; + start = sizeTrunc; + + fixed (byte* inputPtr = data, outputPtr = output) + { + for (ulong offset = 0; offset < (ulong)sizeTrunc; offset += 8) + { + Sse2.Store(outputPtr + offset * 2, Sse41.ConvertToVector128Int16(inputPtr + offset).AsByte()); + } + } + } + + Span<ushort> outputSpan = MemoryMarshal.Cast<byte, ushort>(output); + + for (int i = start; i < data.Length; i++) + { + outputSpan[i] = (ushort)data[i]; + } + + return output; + } + } +} |
