DDSTextureLoader improved validation for video formats (#17)

This commit is contained in:
Chuck Walbourn 2023-02-01 13:49:24 -08:00 коммит произвёл GitHub
Родитель 4a494b727d
Коммит 9631ca3b6c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 107 добавлений и 59 удалений

Просмотреть файл

@ -542,12 +542,22 @@ namespace
case DXGI_FORMAT_NV12:
case DXGI_FORMAT_420_OPAQUE:
if ((height % 2) != 0)
{
// Requires a height alignment of 2.
return E_INVALIDARG;
}
planar = true;
bpe = 2;
break;
case DXGI_FORMAT_P010:
case DXGI_FORMAT_P016:
if ((height % 2) != 0)
{
// Requires a height alignment of 2.
return E_INVALIDARG;
}
planar = true;
bpe = 4;
break;
@ -1343,6 +1353,34 @@ namespace
switch (d3d10ext->dxgiFormat)
{
case DXGI_FORMAT_NV12:
case DXGI_FORMAT_P010:
case DXGI_FORMAT_P016:
case DXGI_FORMAT_420_OPAQUE:
if ((d3d10ext->resourceDimension != D3D11_RESOURCE_DIMENSION_TEXTURE2D)
|| (width % 2) != 0 || (height % 2) != 0)
{
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
break;
case DXGI_FORMAT_YUY2:
case DXGI_FORMAT_Y210:
case DXGI_FORMAT_Y216:
case DXGI_FORMAT_P208:
if ((width % 2) != 0)
{
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
break;
case DXGI_FORMAT_NV11:
if ((width % 4) != 0)
{
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
break;
case DXGI_FORMAT_AI44:
case DXGI_FORMAT_IA44:
case DXGI_FORMAT_P8:

Просмотреть файл

@ -36,30 +36,18 @@ namespace DirectX
};
#endif
#ifndef DDS_LOADER_FLAGS_DEFINED
#define DDS_LOADER_FLAGS_DEFINED
enum DDS_LOADER_FLAGS : uint32_t
inline namespace DX11
{
DDS_LOADER_DEFAULT = 0,
DDS_LOADER_FORCE_SRGB = 0x1,
DDS_LOADER_IGNORE_SRGB = 0x2,
};
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#endif
DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
enum DDS_LOADER_FLAGS : uint32_t
{
DDS_LOADER_DEFAULT = 0,
DDS_LOADER_FORCE_SRGB = 0x1,
DDS_LOADER_IGNORE_SRGB = 0x2,
};
}
// Standard version
HRESULT CreateDDSTextureFromMemory(
HRESULT __cdecl CreateDDSTextureFromMemory(
_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t ddsDataSize,
@ -68,7 +56,7 @@ namespace DirectX
_In_ size_t maxsize = 0,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
HRESULT CreateDDSTextureFromFile(
HRESULT __cdecl CreateDDSTextureFromFile(
_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Outptr_opt_ ID3D11Resource** texture,
@ -77,7 +65,7 @@ namespace DirectX
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
// Standard version with optional auto-gen mipmap support
HRESULT CreateDDSTextureFromMemory(
HRESULT __cdecl CreateDDSTextureFromMemory(
_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
@ -87,7 +75,7 @@ namespace DirectX
_In_ size_t maxsize = 0,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
HRESULT CreateDDSTextureFromFile(
HRESULT __cdecl CreateDDSTextureFromFile(
_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_z_ const wchar_t* szFileName,
@ -97,7 +85,7 @@ namespace DirectX
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
// Extended version
HRESULT CreateDDSTextureFromMemoryEx(
HRESULT __cdecl CreateDDSTextureFromMemoryEx(
_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t ddsDataSize,
@ -111,7 +99,7 @@ namespace DirectX
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
HRESULT CreateDDSTextureFromFileEx(
HRESULT __cdecl CreateDDSTextureFromFileEx(
_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_In_ size_t maxsize,
@ -125,7 +113,7 @@ namespace DirectX
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
// Extended version with optional auto-gen mipmap support
HRESULT CreateDDSTextureFromMemoryEx(
HRESULT __cdecl CreateDDSTextureFromMemoryEx(
_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
@ -140,7 +128,7 @@ namespace DirectX
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
HRESULT CreateDDSTextureFromFileEx(
HRESULT __cdecl CreateDDSTextureFromFileEx(
_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_z_ const wchar_t* szFileName,
@ -153,4 +141,18 @@ namespace DirectX
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#endif
inline namespace DX11
{
DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS);
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}

Просмотреть файл

@ -19,7 +19,12 @@
#include <d3d11_1.h>
#if defined(NTDDI_WIN10_FE) || defined(__MINGW32__)
#include <ocidl.h>
#else
#include <OCIdl.h>
#endif
#include <functional>

Просмотреть файл

@ -30,33 +30,22 @@
namespace DirectX
{
#ifndef WIC_LOADER_FLAGS_DEFINED
#define WIC_LOADER_FLAGS_DEFINED
enum WIC_LOADER_FLAGS : uint32_t
inline namespace DX11
{
WIC_LOADER_DEFAULT = 0,
WIC_LOADER_FORCE_SRGB = 0x1,
WIC_LOADER_IGNORE_SRGB = 0x2,
WIC_LOADER_SRGB_DEFAULT = 0x4,
WIC_LOADER_FIT_POW2 = 0x20,
WIC_LOADER_MAKE_SQUARE = 0x40,
WIC_LOADER_FORCE_RGBA32 = 0x80,
};
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#endif
DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
enum WIC_LOADER_FLAGS : uint32_t
{
WIC_LOADER_DEFAULT = 0,
WIC_LOADER_FORCE_SRGB = 0x1,
WIC_LOADER_IGNORE_SRGB = 0x2,
WIC_LOADER_SRGB_DEFAULT = 0x4,
WIC_LOADER_FIT_POW2 = 0x20,
WIC_LOADER_MAKE_SQUARE = 0x40,
WIC_LOADER_FORCE_RGBA32 = 0x80,
};
}
// Standard version
HRESULT CreateWICTextureFromMemory(
HRESULT __cdecl CreateWICTextureFromMemory(
_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
@ -64,7 +53,7 @@ namespace DirectX
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0) noexcept;
HRESULT CreateWICTextureFromFile(
HRESULT __cdecl CreateWICTextureFromFile(
_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Outptr_opt_ ID3D11Resource** texture,
@ -72,7 +61,7 @@ namespace DirectX
_In_ size_t maxsize = 0) noexcept;
// Standard version with optional auto-gen mipmap support
HRESULT CreateWICTextureFromMemory(
HRESULT __cdecl CreateWICTextureFromMemory(
_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
@ -81,7 +70,7 @@ namespace DirectX
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0) noexcept;
HRESULT CreateWICTextureFromFile(
HRESULT __cdecl CreateWICTextureFromFile(
_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_z_ const wchar_t* szFileName,
@ -90,7 +79,7 @@ namespace DirectX
_In_ size_t maxsize = 0) noexcept;
// Extended version
HRESULT CreateWICTextureFromMemoryEx(
HRESULT __cdecl CreateWICTextureFromMemoryEx(
_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
@ -103,7 +92,7 @@ namespace DirectX
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
HRESULT CreateWICTextureFromFileEx(
HRESULT __cdecl CreateWICTextureFromFileEx(
_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_In_ size_t maxsize,
@ -116,7 +105,7 @@ namespace DirectX
_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
// Extended version with optional auto-gen mipmap support
HRESULT CreateWICTextureFromMemoryEx(
HRESULT __cdecl CreateWICTextureFromMemoryEx(
_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
@ -130,7 +119,7 @@ namespace DirectX
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
HRESULT CreateWICTextureFromFileEx(
HRESULT __cdecl CreateWICTextureFromFileEx(
_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_z_ const wchar_t* szFileName,
@ -142,4 +131,18 @@ namespace DirectX
_In_ WIC_LOADER_FLAGS loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#endif
inline namespace DX11
{
DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS);
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}