|
1 | | -namespace AssetRipper.TextureDecoder.Tests |
| 1 | +using AssetRipper.TextureDecoder.Pvrtc; |
| 2 | + |
| 3 | +namespace AssetRipper.TextureDecoder.Tests; |
| 4 | + |
| 5 | +public sealed class PvrtcTests |
2 | 6 | { |
3 | | - public sealed class PvrtcTests |
| 7 | + [Test] |
| 8 | + public void DecompressPVRTCTest() |
4 | 9 | { |
5 | | - [Test] |
6 | | - public void DecompressPVRTCTest() |
| 10 | + ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.PvrtcTestFiles + "test.pvrtc4"); |
| 11 | + int totalBytesRead = 0; |
| 12 | + foreach (int size in new int[] { 512, 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
7 | 13 | { |
8 | | - ReadOnlySpan<byte> data = File.ReadAllBytes(TestFileFolders.PvrtcTestFiles + "test.pvrtc4"); |
9 | | - int totalBytesRead = 0; |
10 | | - foreach (int size in new int[] { 512, 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps |
11 | | - { |
12 | | - int bytesRead = Pvrtc.PvrtcDecoder.DecompressPVRTC(data, size, size, false, out _); |
13 | | - totalBytesRead += bytesRead; |
14 | | - } |
15 | | - Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
| 14 | + int bytesRead = PvrtcDecoder.DecompressPVRTC(data, size, size, false, out _); |
| 15 | + totalBytesRead += bytesRead; |
16 | 16 | } |
| 17 | + Assert.That(totalBytesRead, Is.EqualTo(data.Length)); |
| 18 | + } |
| 19 | + |
| 20 | + private const double MaxMeanDeviation4 = 0.05; |
| 21 | + private const double MaxStandardDeviation4 = 1.4; |
| 22 | + |
| 23 | + private const double MaxMeanDeviation2 = 0.10; |
| 24 | + private const double MaxStandardDeviation2 = 2.6; |
| 25 | + |
| 26 | + [Test] |
| 27 | + public void Decompress_4() => AssertCorrectDecompression<AndroidTextures.Logo_13>(false, MaxMeanDeviation4, MaxStandardDeviation4); |
| 28 | + |
| 29 | + [Test] |
| 30 | + public void Decompress_2() => AssertCorrectDecompression<AndroidTextures.Logo_14>(true, MaxMeanDeviation2, MaxStandardDeviation2); |
| 31 | + |
| 32 | + private static void AssertCorrectDecompression<T>(bool do2bitMode, double maxMeanDeviation, double maxStandardDeviation) where T : ITexture |
| 33 | + { |
| 34 | + ReadOnlySpan<byte> data = T.Data; |
| 35 | + int bytesRead = PvrtcDecoder.DecompressPVRTC(data, T.Width, T.Height, do2bitMode, out byte[] decompressedData); |
| 36 | + if (!T.Mips) |
| 37 | + { |
| 38 | + Assert.That(bytesRead, Is.EqualTo(data.Length)); |
| 39 | + } |
| 40 | + ByteArrayDeviation.AssertMinimalDeviation(decompressedData, AndroidTextures.Logo_00.Data, maxMeanDeviation, maxStandardDeviation); |
17 | 41 | } |
18 | 42 | } |
0 commit comments