Skip to content

Commit 2025af4

Browse files
committed
Adjust width and height check to check block size
1 parent 7352bfa commit 2025af4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

main.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ bool dds2tex(const char* dds_path)
9999
DDS_HEADER dds_header;
100100
assert(fread(&dds_header, sizeof(DDS_HEADER), 1, dds_file) == 1);
101101

102-
if (dds_header.dwWidth % 4 != 0 || dds_header.dwHeight % 4 != 0) {
103-
if (dds_header.dwWidth % 4 != 0)
104-
fprintf(stderr, "Error: Cannot convert to tex when width (%d) isn't divisible by 4!\n", dds_header.dwWidth);
105-
if (dds_header.dwHeight % 4 != 0)
106-
fprintf(stderr, "Error: Cannot convert to tex when height (%d) isn't divisible by 4!\n", dds_header.dwHeight);
107-
fclose(dds_file);
108-
return false;
109-
}
110-
111102
TEX_HEADER tex_header = {
112103
.magic = tex_magic,
113104
.image_width = dds_header.dwWidth,
@@ -153,6 +144,17 @@ bool dds2tex(const char* dds_path)
153144
fclose(dds_file);
154145
return false;
155146
}
147+
148+
const int block_size = get_block_size(tex_header.tex_format);
149+
if (dds_header.dwWidth % block_size != 0 || dds_header.dwHeight % block_size != 0) {
150+
if (dds_header.dwWidth % block_size != 0)
151+
fprintf(stderr, "Error: Cannot convert to tex when width (%d) isn't divisible by %d!\n", dds_header.dwWidth, block_size);
152+
if (dds_header.dwHeight % block_size != 0)
153+
fprintf(stderr, "Error: Cannot convert to tex when height (%d) isn't divisible by %d!\n", dds_header.dwHeight, block_size);
154+
fclose(dds_file);
155+
return false;
156+
}
157+
156158
if (dds_header.dwMipMapCount > 1) { // this value may be set to 1, which is equivalent to leaving it at 0 (no mipmaps)
157159
tex_header.has_mipmaps = true;
158160
if (dds_header.dwMipMapCount != 32u - __builtin_clz(max(dds_header.dwWidth, dds_header.dwHeight))) {

0 commit comments

Comments
 (0)