@@ -41,17 +41,23 @@ void dds2tex(const char* dds_path)
41
41
DDS_HEADER dds_header ;
42
42
assert (fread (& dds_header , sizeof (DDS_HEADER ), 1 , dds_file ) == 1 );
43
43
44
- const uint8_t * tex_format ;
44
+ TEX_HEADER tex_header = {
45
+ .magic = tex_magic ,
46
+ .image_width = dds_header .dwWidth ,
47
+ .image_height = dds_header .dwHeight ,
48
+ .unk1 = 1 // this is always set to 1 in original tex files; no idea what it stands for
49
+ };
45
50
if (memcmp (dds_header .ddspf .dwFourCC , "DXT1" , 4 ) == 0 ) {
46
- tex_format = tex_dxt1_format ;
51
+ tex_header . tex_format = tex_format_dxt1 ;
47
52
} else if (memcmp (dds_header .ddspf .dwFourCC , "DXT5" , 4 ) == 0 ) {
48
- tex_format = tex_dxt5_format ;
53
+ tex_header . tex_format = tex_format_dxt5 ;
49
54
} else {
50
55
fprintf (stderr , "Error: dds file needs to be in either DXT1 or DXT5 format!\n" );
51
56
fclose (dds_file );
52
57
return ;
53
58
}
54
59
if (dds_header .dwMipMapCount > 1 ) { // this value may be set to 1, which is equivalent to leaving it at 0 (no mipmaps)
60
+ tex_header .has_mipmaps = true;
55
61
if (dds_header .dwMipMapCount != 32u - __builtin_clz (max (dds_header .dwWidth , dds_header .dwHeight ))) {
56
62
fprintf (stderr , "Error: DDS mipmap count mismatch; expected %u mipmaps, got %u\n" , 32 - __builtin_clz (max (dds_header .dwWidth , dds_header .dwHeight )), dds_header .dwMipMapCount );
57
63
fclose (dds_file );
@@ -70,13 +76,6 @@ void dds2tex(const char* dds_path)
70
76
fclose (dds_file );
71
77
return ;
72
78
}
73
- TEX_HEADER tex_header = {
74
- .magic = tex_magic ,
75
- .image_width = dds_header .dwWidth ,
76
- .image_height = dds_header .dwHeight ,
77
- .has_mipmaps = dds_header .dwMipMapCount > 1
78
- };
79
- memcpy (tex_header .tex_format , tex_format , 2 );
80
79
fwrite (& tex_header , sizeof (TEX_HEADER ), 1 , tex_file );
81
80
82
81
printf ("Info: Converting %ux%u DDS file \"%s\" to TEX file \"%s\".\n" , tex_header .image_width , tex_header .image_height , dds_path , tex_path );
@@ -131,9 +130,9 @@ void tex2dds(const char* tex_path)
131
130
assert (fread ((uint8_t * ) & tex_header + 4 , sizeof (TEX_HEADER ) - 4 , 1 , tex_file ) == 1 );
132
131
133
132
const char * dds_format ;
134
- if (memcmp ( tex_header .tex_format , tex_dxt1_format , 2 ) == 0 ) {
133
+ if (tex_header .tex_format == tex_format_dxt1 ) {
135
134
dds_format = "DXT1" ;
136
- } else if (memcmp ( tex_header .tex_format , tex_dxt5_format , 2 ) == 0 ) {
135
+ } else if (tex_header .tex_format == tex_format_dxt5 ) {
137
136
dds_format = "DXT5" ;
138
137
} else {
139
138
fprintf (stderr , "Error: tex file needs to be in either DXT1 or DXT5 format!\n" );
0 commit comments