using AssetRipper.TextureDecoder.Rgb; using AssetRipper.TextureDecoder.Rgb.Formats; namespace AssetRipper.TextureDecoder.Tests { public sealed class RgbConsistencyTests { [Test] public void ConvertA8Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.alpha8"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = OldRgbConverter.A8ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData); RgbConverter.Convert, byte, ColorBGRA, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData); totalBytesRead += bytesRead; Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertARGB16Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.argb4444"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = RgbConverter.Convert, byte>(data.Slice(totalBytesRead), size, size, out _); totalBytesRead += bytesRead; } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertRGB24Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb24"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = OldRgbConverter.RGB24ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData); RgbConverter.Convert, byte, ColorBGRA, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData); totalBytesRead += bytesRead; Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertRGBA32Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgba32"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = OldRgbConverter.RGBA32ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData); RgbConverter.Convert, byte, ColorBGRA, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData); totalBytesRead += bytesRead; Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertARGB32Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.argb32"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = OldRgbConverter.ARGB32ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData); RgbConverter.Convert, byte, ColorBGRA, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData); totalBytesRead += bytesRead; Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertRGB16Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb565"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = OldRgbConverter.RGB16ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData); RgbConverter.Convert, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData); totalBytesRead += bytesRead; Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertR16Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.r16"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = RgbConverter.Convert, ushort, ColorBGRA, byte>(data.Slice(totalBytesRead), size, size, out _); totalBytesRead += bytesRead; } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertRGBA16Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgba4444"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = RgbConverter.Convert, byte>(data.Slice(totalBytesRead), size, size, out _); totalBytesRead += bytesRead; } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertRG16Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rg16"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = OldRgbConverter.RG16ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData); RgbConverter.Convert, byte, ColorBGRA, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData); totalBytesRead += bytesRead; Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertR8Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.r8"); int totalBytesRead = 0; foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps { int bytesRead = OldRgbConverter.R8ToBGRA32(data.Slice(totalBytesRead), size, size, out byte[] originalDecodedData); RgbConverter.Convert, byte, ColorBGRA, byte>(data.Slice(totalBytesRead), size, size, out byte[] newDecodedData); totalBytesRead += bytesRead; Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } Assert.That(totalBytesRead, Is.EqualTo(data.Length)); } [Test] public void ConvertRHalfTest() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rhalf"); OldRgbConverter.RHalfToBGRA32(data, 256, 256, out byte[] originalDecodedData); RgbConverter.Convert, Half, ColorBGRA, byte>(data, 256, 256, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } [Test] public void ConvertRGHalfTest() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rghalf"); OldRgbConverter.RGHalfToBGRA32(data, 256, 256, out byte[] originalDecodedData); RgbConverter.Convert, Half, ColorBGRA, byte>(data, 256, 256, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } [Test] public void ConvertRGBAHalfTest() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgbahalf"); OldRgbConverter.RGBAHalfToBGRA32(data, 256, 256, out byte[] originalDecodedData); RgbConverter.Convert, Half, ColorBGRA, byte>(data, 256, 256, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } [Test] public void ConvertRFloatTest() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rfloat"); OldRgbConverter.RFloatToBGRA32(data, 256, 256, out byte[] originalDecodedData); RgbConverter.Convert, float, ColorBGRA, byte>(data, 256, 256, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } [Test] public void ConvertRGFloatTest() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgfloat"); OldRgbConverter.RGFloatToBGRA32(data, 256, 256, out byte[] originalDecodedData); RgbConverter.Convert, float, ColorBGRA, byte>(data, 256, 256, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } [Test] public void ConvertRGBAFloatTest() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgbafloat"); OldRgbConverter.RGBAFloatToBGRA32(data, 256, 256, out byte[] originalDecodedData); RgbConverter.Convert, float, ColorBGRA, byte>(data, 256, 256, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } [Test] public void ConvertRGB9e5FloatTest() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb9e5float"); OldRgbConverter.RGB9e5FloatToBGRA32(data, 256, 256, out byte[] originalDecodedData); RgbConverter.Convert, byte>(data, 256, 256, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } [Test] public void ConvertRG32Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rg32"); OldRgbConverter.RG32ToBGRA32(data, 512, 512, out byte[] originalDecodedData); RgbConverter.Convert, ushort, ColorBGRA, byte>(data, 512, 512, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } [Test] public void ConvertRGB48Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgb48"); OldRgbConverter.RGB48ToBGRA32(data, 512, 512, out byte[] originalDecodedData); RgbConverter.Convert, ushort, ColorBGRA, byte>(data, 512, 512, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } [Test] public void ConvertRGBA64Test() { ReadOnlySpan data = File.ReadAllBytes(TestFileFolders.RgbTestFiles + "test.rgba64"); OldRgbConverter.RGBA64ToBGRA32(data, 512, 512, out byte[] originalDecodedData); RgbConverter.Convert, ushort, ColorBGRA, byte>(data, 512, 512, out byte[] newDecodedData); Assert.That(originalDecodedData, Is.EqualTo(newDecodedData)); } } }