diff --git a/DirectXTex/DirectXTexMipmaps.cpp b/DirectXTex/DirectXTexMipmaps.cpp index dadddf0..9d27361 100644 --- a/DirectXTex/DirectXTexMipmaps.cpp +++ b/DirectXTex/DirectXTexMipmaps.cpp @@ -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; } diff --git a/DirectXTex/DirectXTexP.h b/DirectXTex/DirectXTexP.h index 422e8d3..dec2b8c 100644 --- a/DirectXTex/DirectXTexP.h +++ b/DirectXTex/DirectXTexP.h @@ -39,6 +39,10 @@ #include +#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE) +#include +#endif + #pragma warning(push) #pragma warning(disable : 4005) #include @@ -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" ); diff --git a/DirectXTex/DirectXTexUtil.cpp b/DirectXTex/DirectXTexUtil.cpp index e5ce2a0..5e4f496 100644 --- a/DirectXTex/DirectXTexUtil.cpp +++ b/DirectXTex/DirectXTexUtil.cpp @@ -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; } diff --git a/DirectXTex/DirectXTexWIC.cpp b/DirectXTex/DirectXTexWIC.cpp index cb54dfa..0c11f5d 100644 --- a/DirectXTex/DirectXTexWIC.cpp +++ b/DirectXTex/DirectXTexWIC.cpp @@ -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; + } } } } diff --git a/DirectXTex/DirectXTex_Desktop_2012.vcxproj b/DirectXTex/DirectXTex_Desktop_2012.vcxproj index 90e2830..26a6e43 100644 --- a/DirectXTex/DirectXTex_Desktop_2012.vcxproj +++ b/DirectXTex/DirectXTex_Desktop_2012.vcxproj @@ -143,7 +143,7 @@ Sync ..\XNAMath;%(AdditionalIncludeDirectories) %(AdditionalOptions) - _UNICODE;UNICODE;WIN32;_DEBUG;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) + _UNICODE;UNICODE;WIN32;_DEBUG;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) EditAndContinue EnableFastChecks Use @@ -184,7 +184,7 @@ Sync ..\XNAMath;%(AdditionalIncludeDirectories) %(AdditionalOptions) - _UNICODE;UNICODE;WIN32;_DEBUG;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) + _UNICODE;UNICODE;WIN32;_DEBUG;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) EnableFastChecks Use DirectXTexP.h @@ -226,7 +226,7 @@ Sync ..\XNAMath;%(AdditionalIncludeDirectories) %(AdditionalOptions) - _UNICODE;UNICODE;WIN32;NDEBUG;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) + _UNICODE;UNICODE;WIN32;NDEBUG;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) Use DirectXTexP.h @@ -268,7 +268,7 @@ Sync ..\XNAMath;%(AdditionalIncludeDirectories) %(AdditionalOptions) - _UNICODE;UNICODE;WIN32;NDEBUG;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) + _UNICODE;UNICODE;WIN32;NDEBUG;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) Use DirectXTexP.h @@ -311,7 +311,7 @@ Sync ..\XNAMath;%(AdditionalIncludeDirectories) %(AdditionalOptions) - _UNICODE;UNICODE;WIN32;NDEBUG;PROFILE;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) + _UNICODE;UNICODE;WIN32;NDEBUG;PROFILE;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) Use DirectXTexP.h @@ -353,7 +353,7 @@ Sync ..\XNAMath;%(AdditionalIncludeDirectories) %(AdditionalOptions) - _UNICODE;UNICODE;WIN32;NDEBUG;PROFILE;_LIB;DXGI_1_2_FORMATS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) + _UNICODE;UNICODE;WIN32;NDEBUG;PROFILE;_LIB;DXGI_1_2_FORMATS;_WIN7_PLATFORM_UPDATE;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) Use DirectXTexP.h