Skip to content

Commit 0aba876

Browse files
committed
Use existing test utils for Astc tests
1 parent 6e58d6f commit 0aba876

36 files changed

Lines changed: 322 additions & 300 deletions

File tree

tests/ImageSharp.Textures.Tests/Enums/TestTextureFormat.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ public enum TestTextureFormat
1919
/// Khronos Texture, version 2.
2020
/// </summary>
2121
Ktx2,
22+
23+
/// <summary>
24+
/// Adaptive Scalable Texture Compression.
25+
/// </summary>
26+
Astc,
2227
}
2328
}

tests/ImageSharp.Textures.Tests/Enums/TestTextureTool.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public enum TestTextureTool
2323
/// <summary>
2424
/// The PVR tex tool cli.
2525
/// </summary>
26-
PvrTexToolCli
26+
PvrTexToolCli,
27+
28+
/// <summary>
29+
/// ARM ASTC encoder (astcenc).
30+
/// </summary>
31+
AstcEnc,
2732
}
2833
}

tests/ImageSharp.Textures.Tests/Formats/Astc/AstcDecoderTests.cs

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
using SixLabors.ImageSharp.Textures.Compression.Astc.Core;
88
using SixLabors.ImageSharp.Textures.Compression.Astc.IO;
99
using SixLabors.ImageSharp.Textures.Compression.Astc.TexelBlock;
10+
using SixLabors.ImageSharp.Textures.Formats.Ktx;
11+
using SixLabors.ImageSharp.Textures.Tests.Enums;
12+
using SixLabors.ImageSharp.Textures.Tests.TestUtilities;
13+
using SixLabors.ImageSharp.Textures.Tests.TestUtilities.Attributes;
1014
using SixLabors.ImageSharp.Textures.Tests.TestUtilities.ImageComparison;
15+
using SixLabors.ImageSharp.Textures.Tests.TestUtilities.TextureProviders;
1116

1217
namespace SixLabors.ImageSharp.Textures.Tests.Formats.Astc;
1318

1419
#nullable enable
20+
21+
[GroupOutput("Astc")]
22+
[Trait("Format", "Astc")]
1523
public class AstcDecoderTests
1624
{
1725
[Fact]
@@ -63,10 +71,10 @@ public void DecompressImage_WithMismatchedBlockCount_ShouldReturnEmpty()
6371
}
6472

6573
[Theory]
66-
[InlineData(TestImages.Astc.Atlas_Small_4x4)]
67-
[InlineData(TestImages.Astc.Atlas_Small_5x5)]
68-
[InlineData(TestImages.Astc.Atlas_Small_6x6)]
69-
[InlineData(TestImages.Astc.Atlas_Small_8x8)]
74+
[InlineData(TestImages.Astc.Rgba_4x4)]
75+
[InlineData(TestImages.Astc.Rgba_5x5)]
76+
[InlineData(TestImages.Astc.Rgba_6x6)]
77+
[InlineData(TestImages.Astc.Rgba_8x8)]
7078
[InlineData(TestImages.Astc.Checkerboard)]
7179
[InlineData(TestImages.Astc.Checkered_4)]
7280
[InlineData(TestImages.Astc.Checkered_5)]
@@ -98,7 +106,7 @@ public void DecompressImage_WithMismatchedBlockCount_ShouldReturnEmpty()
98106
[InlineData(TestImages.Astc.Rgb_12x12)]
99107
public void DecompressImage_WithTestdataFile_ShouldReturnExpectedByteCount(string inputFile)
100108
{
101-
string filePath = TestFile.GetInputFileFullPath(inputFile);
109+
string filePath = TestFile.GetInputFileFullPath(Path.Combine("Astc", inputFile));
102110
byte[] bytes = File.ReadAllBytes(filePath);
103111
AstcFile astc = AstcFile.FromMemory(bytes);
104112

@@ -108,17 +116,17 @@ public void DecompressImage_WithTestdataFile_ShouldReturnExpectedByteCount(strin
108116
}
109117

110118
[Theory]
111-
[InlineData(TestImages.Astc.Atlas_Small_4x4, FootprintType.Footprint4x4, 256, 256)]
112-
[InlineData(TestImages.Astc.Atlas_Small_5x5, FootprintType.Footprint5x5, 256, 256)]
113-
[InlineData(TestImages.Astc.Atlas_Small_6x6, FootprintType.Footprint6x6, 256, 256)]
114-
[InlineData(TestImages.Astc.Atlas_Small_8x8, FootprintType.Footprint8x8, 256, 256)]
119+
[InlineData(TestImages.Astc.Rgba_4x4, FootprintType.Footprint4x4, 256, 256)]
120+
[InlineData(TestImages.Astc.Rgba_5x5, FootprintType.Footprint5x5, 256, 256)]
121+
[InlineData(TestImages.Astc.Rgba_6x6, FootprintType.Footprint6x6, 256, 256)]
122+
[InlineData(TestImages.Astc.Rgba_8x8, FootprintType.Footprint8x8, 256, 256)]
115123
public void DecompressImage_WithValidData_ShouldDecodeAllBlocks(
116124
string inputFile,
117125
FootprintType footprintType,
118126
int width,
119127
int height)
120128
{
121-
byte[] astcData = TestFile.Create(inputFile).Bytes[16..];
129+
byte[] astcData = TestFile.Create(Path.Combine("Astc", inputFile)).Bytes[16..];
122130
Footprint footprint = Footprint.FromFootprintType(footprintType);
123131
int blockWidth = footprint.Width;
124132
int blockHeight = footprint.Height;
@@ -143,32 +151,47 @@ public void DecompressImage_WithValidData_ShouldDecodeAllBlocks(
143151
}
144152

145153
[Theory]
146-
[InlineData(TestImages.Astc.Atlas_Small_4x4, TestImages.Astc.Expected.Atlas_Small_4x4, FootprintType.Footprint4x4, 256, 256)]
147-
[InlineData(TestImages.Astc.Atlas_Small_5x5, TestImages.Astc.Expected.Atlas_Small_5x5, FootprintType.Footprint5x5, 256, 256)]
148-
[InlineData(TestImages.Astc.Atlas_Small_6x6, TestImages.Astc.Expected.Atlas_Small_6x6, FootprintType.Footprint6x6, 256, 256)]
149-
[InlineData(TestImages.Astc.Atlas_Small_8x8, TestImages.Astc.Expected.Atlas_Small_8x8, FootprintType.Footprint8x8, 256, 256)]
150-
public void DecompressImage_WithAstcFile_ShouldMatchExpected(
151-
string inputFile,
152-
string expectedFile,
153-
FootprintType footprint,
154-
int width,
155-
int height)
154+
[WithFile(TestTextureFormat.Astc, TestTextureType.Flat, TestTextureTool.AstcEnc, TestImages.Astc.Rgb_4x4)]
155+
[WithFile(TestTextureFormat.Astc, TestTextureType.Flat, TestTextureTool.AstcEnc, TestImages.Astc.Rgb_5x4)]
156+
[WithFile(TestTextureFormat.Astc, TestTextureType.Flat, TestTextureTool.AstcEnc, TestImages.Astc.Rgb_6x6)]
157+
[WithFile(TestTextureFormat.Astc, TestTextureType.Flat, TestTextureTool.AstcEnc, TestImages.Astc.Rgb_8x8)]
158+
[WithFile(TestTextureFormat.Astc, TestTextureType.Flat, TestTextureTool.AstcEnc, TestImages.Astc.Rgb_12x12)]
159+
public void DecompressImage_WithAstcRgbFile_ShouldMatchExpected(TestTextureProvider provider)
160+
{
161+
byte[] astcBytes = File.ReadAllBytes(provider.InputFile);
162+
AstcFile file = AstcFile.FromMemory(astcBytes);
163+
164+
string blockSize = $"{file.Footprint.Width}x{file.Footprint.Height}";
165+
166+
byte[] decodedPixels = AstcDecoder.DecompressImage(file).ToArray();
167+
using Image<Rgba32> actualImage = Image.LoadPixelData<Rgba32>(decodedPixels, file.Width, file.Height);
168+
actualImage.Mutate(x => x.Flip(FlipMode.Vertical));
169+
170+
actualImage.CompareToReferenceOutput(
171+
ImageComparer.TolerantPercentage(0.03f),
172+
provider,
173+
testOutputDetails: blockSize);
174+
}
175+
176+
[Theory]
177+
[WithFile(TestTextureFormat.Astc, TestTextureType.Flat, TestTextureTool.AstcEnc, TestImages.Astc.Rgba_4x4)]
178+
[WithFile(TestTextureFormat.Astc, TestTextureType.Flat, TestTextureTool.AstcEnc, TestImages.Astc.Rgba_5x5)]
179+
[WithFile(TestTextureFormat.Astc, TestTextureType.Flat, TestTextureTool.AstcEnc, TestImages.Astc.Rgba_6x6)]
180+
[WithFile(TestTextureFormat.Astc, TestTextureType.Flat, TestTextureTool.AstcEnc, TestImages.Astc.Rgba_8x8)]
181+
public void DecompressImage_WithAstcRgbaFile_ShouldMatchExpected(TestTextureProvider provider)
156182
{
157-
string astcPath = TestFile.GetInputFileFullPath(inputFile);
158-
byte[] astcBytes = File.ReadAllBytes(astcPath);
183+
byte[] astcBytes = File.ReadAllBytes(provider.InputFile);
159184
AstcFile file = AstcFile.FromMemory(astcBytes);
160185

161-
// Check file header
162-
Assert.Equal(footprint, file.Footprint.Type);
163-
Assert.Equal(width, file.Width);
164-
Assert.Equal(height, file.Height);
186+
string blockSize = $"{file.Footprint.Width}x{file.Footprint.Height}";
165187

166188
byte[] decodedPixels = AstcDecoder.DecompressImage(file).ToArray();
167-
using Image<Rgba32> actualImage = Image.LoadPixelData<Rgba32>(decodedPixels, width, height);
189+
using Image<Rgba32> actualImage = Image.LoadPixelData<Rgba32>(decodedPixels, file.Width, file.Height);
168190
actualImage.Mutate(x => x.Flip(FlipMode.Vertical));
169191

170-
string expectedImagePath = TestFile.GetInputFileFullPath(expectedFile);
171-
using Image<Rgba32> expectedImage = Image.Load<Rgba32>(expectedImagePath);
172-
ImageComparer.TolerantPercentage(0.1f).VerifySimilarity(expectedImage, actualImage);
192+
actualImage.CompareToReferenceOutput(
193+
ImageComparer.TolerantPercentage(0.03f),
194+
provider,
195+
testOutputDetails: blockSize);
173196
}
174197
}

tests/ImageSharp.Textures.Tests/Formats/Astc/EndpointCodecTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ private static int[] EncodeRgbBaseOffset(Rgba32 low, Rgba32 high)
323323
[Fact]
324324
public void DecodeCheckerboard_ShouldDecodeToGrayscaleEndpoints()
325325
{
326-
string astcFilePath = TestFile.GetInputFileFullPath(TestImages.Astc.Checkerboard);
326+
string astcFilePath = TestFile.GetInputFileFullPath(Path.Combine("Astc", TestImages.Astc.Checkerboard));
327327
byte[] astcData = File.ReadAllBytes(astcFilePath);
328328

329329
int blocksDecoded = 0;

0 commit comments

Comments
 (0)