mirror of
https://github.com/microsoft/DirectXTex
synced 2024-11-21 12:00:06 +00:00
DirectXTex: Added WIC2 support for downlevel builds to support Windows 8 and Windows 7 with KB 2670838 isntalled
This commit is contained in:
parent
a8fb2168c9
commit
6a905106f2
@ -193,14 +193,20 @@ HRESULT _ResizeSeparateColorAndAlpha( _In_ IWICImagingFactory* pWIC, _In_ IWICBi
|
||||
}
|
||||
else
|
||||
{
|
||||
#if(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
colorBytesInPixel = colorBytesPerPixel = 12;
|
||||
colorPixelFormat = GUID_WICPixelFormat96bppRGBFloat;
|
||||
#else
|
||||
colorBytesInPixel = 12;
|
||||
colorBytesPerPixel = 16;
|
||||
colorPixelFormat = GUID_WICPixelFormat128bppRGBFloat;
|
||||
#endif
|
||||
#if(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
if ( _IsWIC2() )
|
||||
{
|
||||
colorBytesInPixel = colorBytesPerPixel = 12;
|
||||
colorPixelFormat = GUID_WICPixelFormat96bppRGBFloat;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
colorBytesInPixel = 12;
|
||||
colorBytesPerPixel = 16;
|
||||
colorPixelFormat = GUID_WICPixelFormat128bppRGBFloat;
|
||||
}
|
||||
|
||||
colorWithAlphaBytesPerPixel = 16;
|
||||
colorWithAlphaPixelFormat = GUID_WICPixelFormat128bppRGBAFloat;
|
||||
}
|
||||
|
@ -39,6 +39,10 @@
|
||||
|
||||
#include <ole2.h>
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
#include <d2d1.h>
|
||||
#endif
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4005)
|
||||
#include <wincodec.h>
|
||||
@ -65,6 +69,8 @@ namespace DirectX
|
||||
|
||||
IWICImagingFactory* _GetWIC();
|
||||
|
||||
bool _IsWIC2();
|
||||
|
||||
inline WICBitmapDitherType _GetWICDither( _In_ DWORD flags )
|
||||
{
|
||||
static_assert( TEX_FILTER_DITHER == 0x10000, "TEX_FILTER_DITHER* flag values don't match mask" );
|
||||
|
@ -50,12 +50,10 @@ static WICTranslate g_WICFormats[] =
|
||||
{ GUID_WICPixelFormat8bppAlpha, DXGI_FORMAT_A8_UNORM },
|
||||
|
||||
{ GUID_WICPixelFormatBlackWhite, DXGI_FORMAT_R1_UNORM },
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
{ GUID_WICPixelFormat96bppRGBFloat, DXGI_FORMAT_R32G32B32_FLOAT },
|
||||
#endif
|
||||
};
|
||||
|
||||
static bool g_WIC2 = false;
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
|
||||
@ -71,21 +69,19 @@ DXGI_FORMAT _WICToDXGI( const GUID& guid )
|
||||
return g_WICFormats[i].format;
|
||||
}
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
if ( g_WIC2 )
|
||||
{
|
||||
if ( memcmp( &GUID_WICPixelFormat96bppRGBFloat, &guid, sizeof(GUID) ) == 0 )
|
||||
return DXGI_FORMAT_R32G32B32_FLOAT;
|
||||
}
|
||||
#endif
|
||||
|
||||
return DXGI_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
bool _DXGIToWIC( DXGI_FORMAT format, GUID& guid )
|
||||
{
|
||||
for( size_t i=0; i < _countof(g_WICFormats); ++i )
|
||||
{
|
||||
if ( g_WICFormats[i].format == format )
|
||||
{
|
||||
memcpy( &guid, &g_WICFormats[i].wic, sizeof(GUID) );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Special cases
|
||||
switch( format )
|
||||
{
|
||||
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
||||
@ -107,12 +103,38 @@ bool _DXGIToWIC( DXGI_FORMAT format, GUID& guid )
|
||||
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
|
||||
memcpy( &guid, &GUID_WICPixelFormat32bppBGR, sizeof(GUID) );
|
||||
return true;
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
case DXGI_FORMAT_R32G32B32_FLOAT:
|
||||
if ( g_WIC2 )
|
||||
{
|
||||
memcpy( &guid, &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID) );
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
for( size_t i=0; i < _countof(g_WICFormats); ++i )
|
||||
{
|
||||
if ( g_WICFormats[i].format == format )
|
||||
{
|
||||
memcpy( &guid, &g_WICFormats[i].wic, sizeof(GUID) );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy( &guid, &GUID_NULL, sizeof(GUID) );
|
||||
return false;
|
||||
}
|
||||
|
||||
bool _IsWIC2()
|
||||
{
|
||||
return g_WIC2;
|
||||
}
|
||||
|
||||
IWICImagingFactory* _GetWIC()
|
||||
{
|
||||
static IWICImagingFactory* s_Factory = nullptr;
|
||||
@ -120,6 +142,36 @@ IWICImagingFactory* _GetWIC()
|
||||
if ( s_Factory )
|
||||
return s_Factory;
|
||||
|
||||
#if(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
HRESULT hr = CoCreateInstance(
|
||||
CLSID_WICImagingFactory2,
|
||||
nullptr,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
__uuidof(IWICImagingFactory2),
|
||||
(LPVOID*)&s_Factory
|
||||
);
|
||||
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
g_WIC2 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = CoCreateInstance(
|
||||
CLSID_WICImagingFactory1,
|
||||
nullptr,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
__uuidof(IWICImagingFactory),
|
||||
(LPVOID*)&s_Factory
|
||||
);
|
||||
|
||||
if ( FAILED(hr) )
|
||||
{
|
||||
s_Factory = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#else
|
||||
HRESULT hr = CoCreateInstance(
|
||||
CLSID_WICImagingFactory,
|
||||
nullptr,
|
||||
@ -133,6 +185,7 @@ IWICImagingFactory* _GetWIC()
|
||||
s_Factory = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return s_Factory;
|
||||
}
|
||||
|
@ -73,13 +73,10 @@ static WICConvert g_WICConvert[] =
|
||||
{ GUID_WICPixelFormat40bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
|
||||
{ GUID_WICPixelFormat80bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
{ GUID_WICPixelFormat32bppRGB, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
|
||||
{ GUID_WICPixelFormat64bppRGB, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
|
||||
{ GUID_WICPixelFormat64bppPRGBAHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
|
||||
{ GUID_WICPixelFormat96bppRGBFixedPoint, GUID_WICPixelFormat96bppRGBFloat }, // DXGI_FORMAT_R32G32B32_FLOAT
|
||||
#else
|
||||
{ GUID_WICPixelFormat96bppRGBFixedPoint, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
|
||||
#endif
|
||||
|
||||
// We don't support n-channel formats
|
||||
@ -101,16 +98,36 @@ static DXGI_FORMAT _DetermineFormat( _In_ const WICPixelFormatGUID& pixelFormat,
|
||||
|
||||
if ( format == DXGI_FORMAT_UNKNOWN )
|
||||
{
|
||||
for( size_t i=0; i < _countof(g_WICConvert); ++i )
|
||||
if ( memcmp( &GUID_WICPixelFormat96bppRGBFixedPoint, &pixelFormat, sizeof(WICPixelFormatGUID) ) == 0 )
|
||||
{
|
||||
if ( memcmp( &g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID) ) == 0 )
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
if ( _IsWIC2() )
|
||||
{
|
||||
if ( pConvert )
|
||||
memcpy( pConvert, &g_WICConvert[i].target, sizeof(WICPixelFormatGUID) );
|
||||
memcpy( pConvert, &GUID_WICPixelFormat96bppRGBFloat, sizeof(WICPixelFormatGUID) );
|
||||
format = DXGI_FORMAT_R32G32B32_FLOAT;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if ( pConvert )
|
||||
memcpy( pConvert, &GUID_WICPixelFormat128bppRGBAFloat, sizeof(WICPixelFormatGUID) );
|
||||
format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( size_t i=0; i < _countof(g_WICConvert); ++i )
|
||||
{
|
||||
if ( memcmp( &g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID) ) == 0 )
|
||||
{
|
||||
if ( pConvert )
|
||||
memcpy( pConvert, &g_WICConvert[i].target, sizeof(WICPixelFormatGUID) );
|
||||
|
||||
format = _WICToDXGI( g_WICConvert[i].target );
|
||||
assert( format != DXGI_FORMAT_UNKNOWN );
|
||||
break;
|
||||
format = _WICToDXGI( g_WICConvert[i].target );
|
||||
assert( format != DXGI_FORMAT_UNKNOWN );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;_DEBUG;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;_DEBUG;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
@ -184,7 +184,7 @@
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;_DEBUG;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;_DEBUG;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
|
||||
@ -226,7 +226,7 @@
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
@ -268,7 +268,7 @@
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
@ -311,7 +311,7 @@
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;PROFILE;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;PROFILE;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
@ -353,7 +353,7 @@
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
<AdditionalIncludeDirectories>..\XNAMath;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;PROFILE;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_UNICODE;UNICODE;WIN32;NDEBUG;PROFILE;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>DirectXTexP.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
|
Loading…
Reference in New Issue
Block a user