Skip to content

Commit b39200e

Browse files
committed
Generic methods for Etc decoding
1 parent ed8ffde commit b39200e

File tree

3 files changed

+234
-145
lines changed

3 files changed

+234
-145
lines changed

AssetRipper.TextureDecoder.ConsoleApp/Program.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,28 +208,28 @@ private static void DecodeEtc(ReadOnlySpan<byte> input, int width, int height, s
208208
switch (mode)
209209
{
210210
case 0:
211-
EtcDecoder.DecompressETC(input, width, height, output);
211+
EtcDecoder.DecompressETC<ColorBGRA32, byte>(input, width, height, output);
212212
break;
213213
case 1:
214-
EtcDecoder.DecompressETC2(input, width, height, output);
214+
EtcDecoder.DecompressETC2<ColorBGRA32, byte>(input, width, height, output);
215215
break;
216216
case 2:
217-
EtcDecoder.DecompressETC2A1(input, width, height, output);
217+
EtcDecoder.DecompressETC2A1<ColorBGRA32, byte>(input, width, height, output);
218218
break;
219219
case 3:
220-
EtcDecoder.DecompressETC2A8(input, width, height, output);
220+
EtcDecoder.DecompressETC2A8<ColorBGRA32, byte>(input, width, height, output);
221221
break;
222222
case 4:
223-
EtcDecoder.DecompressEACRUnsigned(input, width, height, output);
223+
EtcDecoder.DecompressEACRUnsigned<ColorBGRA32, byte>(input, width, height, output);
224224
break;
225225
case 5:
226-
EtcDecoder.DecompressEACRSigned(input, width, height, output);
226+
EtcDecoder.DecompressEACRSigned<ColorBGRA32, byte>(input, width, height, output);
227227
break;
228228
case 6:
229-
EtcDecoder.DecompressEACRGUnsigned(input, width, height, output);
229+
EtcDecoder.DecompressEACRGUnsigned<ColorBGRA32, byte>(input, width, height, output);
230230
break;
231231
case 7:
232-
EtcDecoder.DecompressEACRGSigned(input, width, height, output);
232+
EtcDecoder.DecompressEACRGSigned<ColorBGRA32, byte>(input, width, height, output);
233233
break;
234234

235235
default:

AssetRipper.TextureDecoder.Tests/EtcTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ namespace AssetRipper.TextureDecoder.Tests;
66

77
public sealed class EtcTests
88
{
9-
private static DecodingDelegate ETCDelegate { get; } = (ArraySegment<byte> data, int width, int height, out byte[] decompressedData) => EtcDecoder.DecompressETC(data, width, height, out decompressedData);
10-
private static DecodingDelegate ETC2Delegate { get; } = (ArraySegment<byte> data, int width, int height, out byte[] decompressedData) => EtcDecoder.DecompressETC2(data, width, height, out decompressedData);
11-
private static DecodingDelegate ETC2A1Delegate { get; } = (ArraySegment<byte> data, int width, int height, out byte[] decompressedData) => EtcDecoder.DecompressETC2A1(data, width, height, out decompressedData);
12-
private static DecodingDelegate ETC2A8Delegate { get; } = (ArraySegment<byte> data, int width, int height, out byte[] decompressedData) => EtcDecoder.DecompressETC2A8(data, width, height, out decompressedData);
13-
private static DecodingDelegate EACRSignedDelegate { get; } = (ArraySegment<byte> data, int width, int height, out byte[] decompressedData) => EtcDecoder.DecompressEACRSigned(data, width, height, out decompressedData);
14-
private static DecodingDelegate EACRUnsignedDelegate { get; } = (ArraySegment<byte> data, int width, int height, out byte[] decompressedData) => EtcDecoder.DecompressEACRUnsigned(data, width, height, out decompressedData);
15-
private static DecodingDelegate EACRGSignedDelegate { get; } = (ArraySegment<byte> data, int width, int height, out byte[] decompressedData) => EtcDecoder.DecompressEACRGSigned(data, width, height, out decompressedData);
16-
private static DecodingDelegate EACRGUnsignedDelegate { get; } = (ArraySegment<byte> data, int width, int height, out byte[] decompressedData) => EtcDecoder.DecompressEACRGUnsigned(data, width, height, out decompressedData);
9+
private static DecodingDelegate ETCDelegate { get; } = EtcDecoder.DecompressETC<ColorBGRA32, byte>;
10+
private static DecodingDelegate ETC2Delegate { get; } = EtcDecoder.DecompressETC2<ColorBGRA32, byte>;
11+
private static DecodingDelegate ETC2A1Delegate { get; } = EtcDecoder.DecompressETC2A1<ColorBGRA32, byte>;
12+
private static DecodingDelegate ETC2A8Delegate { get; } = EtcDecoder.DecompressETC2A8<ColorBGRA32, byte>;
13+
private static DecodingDelegate EACRSignedDelegate { get; } = EtcDecoder.DecompressEACRSigned<ColorBGRA32, byte>;
14+
private static DecodingDelegate EACRUnsignedDelegate { get; } = EtcDecoder.DecompressEACRUnsigned<ColorBGRA32, byte>;
15+
private static DecodingDelegate EACRGSignedDelegate { get; } = EtcDecoder.DecompressEACRGSigned<ColorBGRA32, byte>;
16+
private static DecodingDelegate EACRGUnsignedDelegate { get; } = EtcDecoder.DecompressEACRGUnsigned<ColorBGRA32, byte>;
1717

1818
[Test]
1919
public void DecompressETCTest() => AssertCorrectByteCountReadFor256SquareWithMips(TestFileFolders.EtcTestFiles + "test.etc", ETCDelegate);
@@ -57,15 +57,15 @@ public sealed class EtcTests
5757
[Test]
5858
public void CorrectnessEACRGUnsignedTest() => AssertCorrectDecompression<AndroidTextures.Logo_15, ColorRG<byte>>(EACRGUnsignedDelegate, .1, .6);
5959

60-
private delegate int DecodingDelegate(ArraySegment<byte> data, int width, int height, out byte[] decompressedData);
60+
private delegate int DecodingDelegate(ReadOnlySpan<byte> data, int width, int height, out byte[] decompressedData);
6161

6262
private static void AssertCorrectByteCountReadFor256SquareWithMips(string path, DecodingDelegate decoder)
6363
{
6464
byte[] data = File.ReadAllBytes(path);
6565
int totalBytesRead = 0;
6666
foreach (int size in new int[] { 256, 128, 64, 32, 16, 8, 4, 2, 1 }) //mip maps
6767
{
68-
int bytesRead = decoder.Invoke(new ArraySegment<byte>(data, totalBytesRead, data.Length - totalBytesRead), size, size, out _);
68+
int bytesRead = decoder.Invoke(new ReadOnlySpan<byte>(data, totalBytesRead, data.Length - totalBytesRead), size, size, out _);
6969
totalBytesRead += bytesRead;
7070
}
7171
Assert.That(totalBytesRead, Is.EqualTo(data.Length));
@@ -79,7 +79,7 @@ private static void AssertCorrectDecompression<T>(DecodingDelegate decoder, doub
7979
private static void AssertCorrectDecompression<TTexture, TColor>(DecodingDelegate decoder, double maxMeanDeviation, double maxStandardDeviation) where TTexture : ITexture where TColor : unmanaged, IColor<TColor, byte>
8080
{
8181
byte[] data = TTexture.Data;
82-
int bytesRead = decoder.Invoke(new ArraySegment<byte>(data), TTexture.Width, TTexture.Height, out byte[] decompressedData);
82+
int bytesRead = decoder.Invoke(new ReadOnlySpan<byte>(data), TTexture.Width, TTexture.Height, out byte[] decompressedData);
8383
if (!TTexture.Mips)
8484
{
8585
Assert.That(bytesRead, Is.EqualTo(data.Length));

0 commit comments

Comments
 (0)