Skip to content

Commit 76a8b2f

Browse files
committed
Update PvrtcTests to assess correctness
1 parent c113649 commit 76a8b2f

1 file changed

Lines changed: 36 additions & 12 deletions

File tree

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
1-
namespace AssetRipper.TextureDecoder.Tests
1+
using AssetRipper.TextureDecoder.Pvrtc;
2+
3+
namespace AssetRipper.TextureDecoder.Tests;
4+
5+
public sealed class PvrtcTests
26
{
3-
public sealed class PvrtcTests
7+
[Test]
8+
public void DecompressPVRTCTest()
49
{
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
713
{
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;
1616
}
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);
1741
}
1842
}

0 commit comments

Comments
 (0)