mirror of
https://github.com/microsoft/DirectXTex
synced 2024-11-21 20:10:05 +00:00
DirectXTex: WIC2 support for ScreenGrab & WICTextureLoader
This commit is contained in:
parent
6a905106f2
commit
72a1f29d1f
@ -153,6 +153,7 @@ IWICImagingFactory* _GetWIC()
|
||||
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
// WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed
|
||||
g_WIC2 = true;
|
||||
}
|
||||
else
|
||||
|
@ -624,6 +624,8 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext,
|
||||
//--------------------------------------------------------------------------------------
|
||||
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
|
||||
|
||||
static bool g_WIC2 = false;
|
||||
|
||||
static IWICImagingFactory* _GetWIC()
|
||||
{
|
||||
static IWICImagingFactory* s_Factory = nullptr;
|
||||
@ -631,6 +633,37 @@ static 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) )
|
||||
{
|
||||
// WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed
|
||||
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,
|
||||
@ -644,10 +677,10 @@ static IWICImagingFactory* _GetWIC()
|
||||
s_Factory = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return s_Factory;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -923,11 +956,18 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
|
||||
// Screenshots don’t typically include the alpha channel of the render target
|
||||
switch ( desc.Format )
|
||||
{
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
case DXGI_FORMAT_R32G32B32A32_FLOAT:
|
||||
case DXGI_FORMAT_R16G16B16A16_FLOAT:
|
||||
case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
|
||||
if ( g_WIC2 )
|
||||
{
|
||||
targetGuid = GUID_WICPixelFormat96bppRGBFloat;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetGuid = GUID_WICPixelFormat24bppBGR;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
@ -126,10 +126,6 @@ static WICTranslate g_WICFormats[] =
|
||||
{ GUID_WICPixelFormat8bppGray, DXGI_FORMAT_R8_UNORM },
|
||||
|
||||
{ GUID_WICPixelFormat8bppAlpha, DXGI_FORMAT_A8_UNORM },
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
{ GUID_WICPixelFormat96bppRGBFloat, DXGI_FORMAT_R32G32B32_FLOAT },
|
||||
#endif
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
@ -202,18 +198,17 @@ 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
|
||||
};
|
||||
|
||||
static bool g_WIC2 = false;
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
static IWICImagingFactory* _GetWIC()
|
||||
{
|
||||
@ -222,6 +217,37 @@ static 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) )
|
||||
{
|
||||
// WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed
|
||||
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,
|
||||
@ -235,6 +261,7 @@ static IWICImagingFactory* _GetWIC()
|
||||
s_Factory = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return s_Factory;
|
||||
}
|
||||
@ -248,6 +275,14 @@ static 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;
|
||||
}
|
||||
|
||||
@ -360,6 +395,23 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
|
||||
|
||||
DXGI_FORMAT format = _WICToDXGI( pixelFormat );
|
||||
if ( format == DXGI_FORMAT_UNKNOWN )
|
||||
{
|
||||
if ( memcmp( &GUID_WICPixelFormat96bppRGBFixedPoint, &pixelFormat, sizeof(WICPixelFormatGUID) ) == 0 )
|
||||
{
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
if ( g_WIC2 )
|
||||
{
|
||||
memcpy( &convertGUID, &GUID_WICPixelFormat96bppRGBFloat, sizeof(WICPixelFormatGUID) );
|
||||
format = DXGI_FORMAT_R32G32B32_FLOAT;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
memcpy( &convertGUID, &GUID_WICPixelFormat128bppRGBAFloat, sizeof(WICPixelFormatGUID) );
|
||||
format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( size_t i=0; i < _countof(g_WICConvert); ++i )
|
||||
{
|
||||
@ -373,6 +425,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( format == DXGI_FORMAT_UNKNOWN )
|
||||
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
|
||||
@ -382,7 +435,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
|
||||
bpp = _WICBitsPerPixel( pixelFormat );
|
||||
}
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
|
||||
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(_WIN7_PLATFORM_UPDATE)
|
||||
if ( (format == DXGI_FORMAT_R32G32B32_FLOAT) && d3dContext != 0 && textureView != 0 )
|
||||
{
|
||||
// Special case test for optional device support for autogen mipchains for R32G32B32_FLOAT
|
||||
|
Loading…
Reference in New Issue
Block a user