Add support for reading Unreal Tournament 2004 DDS files (#371)

This commit is contained in:
Nicholas Hayes 2023-07-06 14:52:02 -06:00 committed by GitHub
parent 70909fd6be
commit 83ea5ee1bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -191,6 +191,22 @@ namespace
constexpr size_t MAP_SIZE = sizeof(g_LegacyDDSMap) / sizeof(LegacyDDS);
size_t index = 0;
if (ddpf.size == 0 && ddpf.flags == 0 && ddpf.fourCC != 0)
{
// Handle some DDS files where the DDPF_PIXELFORMAT is mostly zero
for (index = 0; index < MAP_SIZE; ++index)
{
const LegacyDDS* entry = &g_LegacyDDSMap[index];
if (entry->ddpf.flags & DDS_FOURCC)
{
if (ddpf.fourCC == entry->ddpf.fourCC)
break;
}
}
}
else
{
for (index = 0; index < MAP_SIZE; ++index)
{
const LegacyDDS* entry = &g_LegacyDDSMap[index];
@ -263,6 +279,7 @@ namespace
}
}
}
}
if (index >= MAP_SIZE)
return DXGI_FORMAT_UNKNOWN;
@ -289,7 +306,6 @@ namespace
return format;
}
//-------------------------------------------------------------------------------------
// Decodes DDS header including optional DX10 extended header
//-------------------------------------------------------------------------------------
@ -320,8 +336,12 @@ namespace
auto pHeader = reinterpret_cast<const DDS_HEADER*>(static_cast<const uint8_t*>(pSource) + sizeof(uint32_t));
// Verify header to validate DDS file
if (pHeader->size != sizeof(DDS_HEADER)
|| pHeader->ddspf.size != sizeof(DDS_PIXELFORMAT))
if (pHeader->size != sizeof(DDS_HEADER))
{
return E_FAIL;
}
if (pHeader->ddspf.size != 0 && pHeader->ddspf.size != sizeof(DDS_PIXELFORMAT))
{
return E_FAIL;
}