77using SixLabors . ImageSharp . Textures . Compression . Astc . Core ;
88using SixLabors . ImageSharp . Textures . Compression . Astc . IO ;
99using 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 ;
1014using SixLabors . ImageSharp . Textures . Tests . TestUtilities . ImageComparison ;
15+ using SixLabors . ImageSharp . Textures . Tests . TestUtilities . TextureProviders ;
1116
1217namespace SixLabors . ImageSharp . Textures . Tests . Formats . Astc ;
1318
1419#nullable enable
20+
21+ [ GroupOutput ( "Astc" ) ]
22+ [ Trait ( "Format" , "Astc" ) ]
1523public 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}
0 commit comments