mirror of
https://github.com/microsoft/DirectXTex
synced 2024-11-08 14:00:05 +00:00
Add support for HEIF and WEBP to command-line tools (#268)
This commit is contained in:
parent
2eb309d197
commit
1c20d528d4
@ -819,6 +819,7 @@ namespace DirectX
|
||||
WIC_CODEC_GIF, // Graphics Interchange Format (.gif)
|
||||
WIC_CODEC_WMP, // Windows Media Photo / HD Photo / JPEG XR (.hdp, .jxr, .wdp)
|
||||
WIC_CODEC_ICO, // Windows Icon (.ico)
|
||||
WIC_CODEC_HEIF, // High Efficiency Image File (.heif, .heic)
|
||||
};
|
||||
|
||||
REFGUID __cdecl GetWICCodec(_In_ WICCodecs codec) noexcept;
|
||||
|
@ -270,6 +270,10 @@ REFGUID DirectX::GetWICCodec(WICCodecs codec) noexcept
|
||||
case WIC_CODEC_ICO:
|
||||
return GUID_ContainerFormatIco;
|
||||
|
||||
case WIC_CODEC_HEIF:
|
||||
// This requires installing https://aka.ms/heif
|
||||
return GUID_ContainerFormatHeif;
|
||||
|
||||
default:
|
||||
return GUID_NULL;
|
||||
}
|
||||
|
@ -1569,7 +1569,7 @@ HRESULT DirectX::SaveToWICFile(
|
||||
if (FAILED(hr))
|
||||
{
|
||||
stream.Reset();
|
||||
DeleteFileW(szFile);
|
||||
std::ignore = DeleteFileW(szFile);
|
||||
return hr;
|
||||
}
|
||||
|
||||
@ -1611,7 +1611,7 @@ HRESULT DirectX::SaveToWICFile(
|
||||
if (FAILED(hr))
|
||||
{
|
||||
stream.Reset();
|
||||
DeleteFileW(szFile);
|
||||
std::ignore = DeleteFileW(szFile);
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
@ -709,9 +709,8 @@ namespace
|
||||
swprintf_s(desc, L": %ls", errorText);
|
||||
|
||||
size_t len = wcslen(desc);
|
||||
if (len >= 2)
|
||||
if (len >= 1)
|
||||
{
|
||||
desc[len - 2] = 0;
|
||||
desc[len - 1] = 0;
|
||||
}
|
||||
|
||||
@ -792,7 +791,14 @@ namespace
|
||||
#endif
|
||||
|
||||
default:
|
||||
return SaveToWICFile(img, WIC_FLAGS_NONE, GetWICCodec(static_cast<WICCodecs>(fileType)), szOutputFile);
|
||||
{
|
||||
HRESULT hr = SaveToWICFile(img, WIC_FLAGS_NONE, GetWICCodec(static_cast<WICCodecs>(fileType)), szOutputFile);
|
||||
if ((hr == static_cast<HRESULT>(0xc00d5212) /* MF_E_TOPO_CODEC_NOT_FOUND */) && (fileType == WIC_CODEC_HEIF))
|
||||
{
|
||||
wprintf(L"\nINFO: This format requires installing the HEIF Image Extensions - https://aka.ms/heif\n");
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1477,6 +1483,17 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
if (FAILED(hr))
|
||||
{
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
if (hr == static_cast<HRESULT>(0xc00d5212) /* MF_E_TOPO_CODEC_NOT_FOUND */)
|
||||
{
|
||||
if (_wcsicmp(ext, L".heic") == 0 || _wcsicmp(ext, L".heif") == 0)
|
||||
{
|
||||
wprintf(L"INFO: This format requires installing the HEIF Image Extensions - https://aka.ms/heif\n");
|
||||
}
|
||||
else if (_wcsicmp(ext, L".webp") == 0)
|
||||
{
|
||||
wprintf(L"INFO: This format requires installing the WEBP Image Extensions - https://www.microsoft.com/p/webp-image-extensions/9pg2dk419drg\n");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -443,6 +443,8 @@ namespace
|
||||
#ifdef USE_OPENEXR
|
||||
{ L"exr", CODEC_EXR },
|
||||
#endif
|
||||
{ L"heic", WIC_CODEC_HEIF },
|
||||
{ L"heif", WIC_CODEC_HEIF },
|
||||
{ nullptr, CODEC_DDS }
|
||||
};
|
||||
|
||||
@ -1000,9 +1002,8 @@ namespace
|
||||
swprintf_s(desc, L": %ls", errorText);
|
||||
|
||||
size_t len = wcslen(desc);
|
||||
if (len >= 2)
|
||||
if (len >= 1)
|
||||
{
|
||||
desc[len - 2] = 0;
|
||||
desc[len - 1] = 0;
|
||||
}
|
||||
|
||||
@ -2118,6 +2119,17 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
{
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
if (hr == static_cast<HRESULT>(0xc00d5212) /* MF_E_TOPO_CODEC_NOT_FOUND */)
|
||||
{
|
||||
if (_wcsicmp(ext, L".heic") == 0 || _wcsicmp(ext, L".heif") == 0)
|
||||
{
|
||||
wprintf(L"INFO: This format requires installing the HEIF Image Extensions - https://aka.ms/heif\n");
|
||||
}
|
||||
else if (_wcsicmp(ext, L".webp") == 0)
|
||||
{
|
||||
wprintf(L"INFO: This format requires installing the WEBP Image Extensions - https://www.microsoft.com/p/webp-image-extensions/9pg2dk419drg\n");
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -3691,6 +3703,10 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
||||
{
|
||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||
retVal = 1;
|
||||
if ((hr == static_cast<HRESULT>(0xc00d5212) /* MF_E_TOPO_CODEC_NOT_FOUND */) && (FileType == WIC_CODEC_HEIF))
|
||||
{
|
||||
wprintf(L"INFO: This format requires installing the HEIF Image Extensions - https://aka.ms/heif\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
wprintf(L"\n");
|
||||
|
@ -712,9 +712,8 @@ namespace
|
||||
swprintf_s(desc, L": %ls", errorText);
|
||||
|
||||
size_t len = wcslen(desc);
|
||||
if (len >= 2)
|
||||
if (len >= 1)
|
||||
{
|
||||
desc[len - 2] = 0;
|
||||
desc[len - 1] = 0;
|
||||
}
|
||||
|
||||
@ -799,7 +798,19 @@ namespace
|
||||
static_assert(static_cast<int>(WIC_FLAGS_FILTER_CUBIC) == static_cast<int>(TEX_FILTER_CUBIC), "WIC_FLAGS_* & TEX_FILTER_* should match");
|
||||
static_assert(static_cast<int>(WIC_FLAGS_FILTER_FANT) == static_cast<int>(TEX_FILTER_FANT), "WIC_FLAGS_* & TEX_FILTER_* should match");
|
||||
|
||||
return LoadFromWICFile(fileName, dwFilter | WIC_FLAGS_ALL_FRAMES, &info, *image);
|
||||
HRESULT hr = LoadFromWICFile(fileName, dwFilter | WIC_FLAGS_ALL_FRAMES, &info, *image);
|
||||
if (hr == static_cast<HRESULT>(0xc00d5212) /* MF_E_TOPO_CODEC_NOT_FOUND */)
|
||||
{
|
||||
if (_wcsicmp(ext, L".heic") == 0 || _wcsicmp(ext, L".heif") == 0)
|
||||
{
|
||||
wprintf(L"\nINFO: This format requires installing the HEIF Image Extensions - https://aka.ms/heif\n");
|
||||
}
|
||||
else if (_wcsicmp(ext, L".webp") == 0)
|
||||
{
|
||||
wprintf(L"\nINFO: This format requires installing the WEBP Image Extensions - https://www.microsoft.com/p/webp-image-extensions/9pg2dk419drg\n");
|
||||
}
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user