From 24ead31a39e886b326a2466fd36c32a99f60ed6b Mon Sep 17 00:00:00 2001 From: walbourn_cp Date: Sat, 1 Jun 2013 10:55:18 -0700 Subject: [PATCH] Added error check to SaveWIC functions if requested optional targetFormat is not supported by the WIC codec --- DirectXTex/DirectXTexWIC.cpp | 6 ++++++ ScreenGrab/ScreenGrab.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/DirectXTex/DirectXTexWIC.cpp b/DirectXTex/DirectXTexWIC.cpp index b6a59f3..bc2516f 100644 --- a/DirectXTex/DirectXTexWIC.cpp +++ b/DirectXTex/DirectXTexWIC.cpp @@ -421,6 +421,12 @@ static HRESULT _EncodeImage( _In_ const Image& image, _In_ DWORD flags, _In_ IWI if ( FAILED(hr) ) return hr; + if ( targetFormat && memcmp( targetFormat, &targetGuid, sizeof(WICPixelFormatGUID) ) != 0 ) + { + // Requested output pixel format is not supported by the WIC codec + return E_FAIL; + } + if ( memcmp( &targetGuid, &pfGuid, sizeof(WICPixelFormatGUID) ) != 0 ) { // Conversion required to write diff --git a/ScreenGrab/ScreenGrab.cpp b/ScreenGrab/ScreenGrab.cpp index 437cf6b..dde8bc3 100644 --- a/ScreenGrab/ScreenGrab.cpp +++ b/ScreenGrab/ScreenGrab.cpp @@ -1031,6 +1031,12 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, if ( FAILED(hr) ) return hr; + if ( targetFormat && memcmp( targetFormat, &targetGuid, sizeof(WICPixelFormatGUID) ) != 0 ) + { + // Requested output pixel format is not supported by the WIC codec + return E_FAIL; + } + D3D11_MAPPED_SUBRESOURCE mapped; hr = pContext->Map( pStaging.Get(), 0, D3D11_MAP_READ, 0, &mapped ); if ( FAILED(hr) )