1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
+ using System . Runtime . InteropServices ;
4
5
using System . Text ;
5
6
using System . Threading . Tasks ;
7
+ using ImageFramework . DirectX ;
6
8
using ImageFramework . ImageLoader ;
7
9
using ImageFramework . Model ;
10
+ using ImageFramework . Utility ;
8
11
using Microsoft . VisualStudio . TestTools . UnitTesting ;
9
12
using SharpDX . DXGI ;
10
13
@@ -17,13 +20,31 @@ public class KtxSamples
17
20
18
21
public static string ImportBadDir = TestData . Directory + "ktx-software\\ badktx2\\ " ;
19
22
23
+ public static string ExportDir = TestData . Directory + "export/" ;
24
+
25
+ [ ClassInitialize ]
26
+ public static void Init ( TestContext context )
27
+ {
28
+ TestData . CreateOutputDirectory ( ExportDir ) ;
29
+ }
30
+
31
+ private static string [ ] RemoveUnsupportedFile ( string [ ] files )
32
+ {
33
+ // remove all files that have 'eac' or 'etc' in their name (these compressions are not supported yet)
34
+ return files . Where ( f =>
35
+ ! f . Contains ( "eac" ) && ! f . Contains ( "EAC" ) &&
36
+ ! f . Contains ( "etc" ) && ! f . Contains ( "ETC" )
37
+ ) . ToArray ( ) ;
38
+ }
39
+
20
40
[ TestMethod ]
21
41
public void ImportTestImagesKtx ( )
22
42
{
23
43
// get all files in the directory
24
44
var files = System . IO . Directory . GetFiles ( ImportDir , "*.ktx" , System . IO . SearchOption . TopDirectoryOnly ) ;
25
45
// filter files so they only end with .ktx (not ktx2)
26
46
files = files . Where ( f => f . EndsWith ( ".ktx" ) ) . ToArray ( ) ;
47
+ files = RemoveUnsupportedFile ( files ) ;
27
48
TryImportAllFiles ( files ) ;
28
49
}
29
50
@@ -32,9 +53,41 @@ public void ImportTestImagesKtx2()
32
53
{
33
54
// get all files in the directory
34
55
var files = System . IO . Directory . GetFiles ( ImportDir , "*.ktx2" , System . IO . SearchOption . TopDirectoryOnly ) ;
56
+ files = RemoveUnsupportedFile ( files ) ;
35
57
TryImportAllFiles ( files ) ;
36
58
}
37
59
60
+ [ TestMethod ]
61
+ public void AlignmentKtx ( )
62
+ {
63
+ // this file uses the RGB format and the width of each row is not a multiple of 4 (this can be tricky to import/export)
64
+ var filename = ImportDir + "hi_mark_sq.ktx" ;
65
+ var model = new Models ( ) ;
66
+ model . AddImageFromFile ( filename ) ;
67
+
68
+ // the following needs to be fulfilled:
69
+ Assert . AreEqual ( 145 , model . Images . GetWidth ( 0 ) ) ;
70
+ Assert . AreEqual ( model . Images . Images [ 0 ] . OriginalFormat , GliFormat . RGB8_UNORM ) ;
71
+
72
+ // export and reimport
73
+ var filename2 = ExportDir + "hi_mark_sq" ;
74
+ model . ExportPipelineImage ( filename2 , "ktx" , GliFormat . RGB8_UNORM ) ;
75
+
76
+ // reimport
77
+ model . AddImageFromFile ( filename2 + ".ktx" ) ;
78
+
79
+ // compare colors
80
+ var srcImg = model . Images . Images [ 0 ] . Image as TextureArray2D ;
81
+ var expImg = model . Images . Images [ 1 ] . Image as TextureArray2D ;
82
+ Assert . IsNotNull ( srcImg ) ;
83
+ Assert . IsNotNull ( expImg ) ;
84
+
85
+ var srcColors = srcImg . GetPixelColors ( LayerMipmapSlice . Mip0 ) ;
86
+ var expColors = expImg . GetPixelColors ( LayerMipmapSlice . Mip0 ) ;
87
+
88
+ TestData . CompareColors ( srcColors , expColors ) ;
89
+ }
90
+
38
91
void TryImportAllFiles ( string [ ] files )
39
92
{
40
93
string errors = "" ;
0 commit comments