Games for Windows and the DirectX SDK blog

Technical tips, tricks, and news about game development for Microsoft platforms including desktop, Xbox, and UWP

Project maintained by walbourn Hosted on GitHub Pages — Theme by mattgraham
Home | Posts by Tag | Posts by Month

Windows Imaging Component and Windows 8

win7, win8, xbox

Originally posted to Chuck Walbourn's Blog on MSDN,

There are a number of new features and some bugs fixed in the Windows Imaging Component for Windows 8. With the installation of KB 2670838 this new version of WIC is also available on Windows 7 Service Pack 1.

The Windows 8.0 SDK contains the latest version of the headers needed to build with the new version of WIC. The behavior of wincodec.h changes depending your build-settings. If you build with _WIN32_WINNT set to 0x602 or later, then WINCODEC_SDK_VERSION, CLSID_WICImagingFactory, and CLSID_WICPngDecoder are set to use “WIC2” by default. Otherwise, it uses the old “WIC1” version. This means Windows Store apps and Win32 desktop applications built for Windows 8 only are already using the new version of WIC. No muss. No fuss. Win32 desktop applications built for older versions of Windows continue to use “WIC1” and the old behaviors are maintained.

If, however, you want to use “WIC2” when it is available but successfully fall back to “WIC1” on Windows Vista or Windows 7 without the KB 2670838 update, then things get a little tricky. The _WIN7_PLATFORM_UPDATE define ‘opts-in’ to the Windows 8 header behavior without requiring you set your _WIN32_WINNT define in a way that doesn’t support older versions of Windows. You will want to avoid using WINCODEC_SDK_VERSION, CLSID_WICImagingFactory, and CLSID_WICPngDecoder and instead use the explicit ‘version’ ones. You also need to be careful when using the four new WIC pixel format GUIDs (GUID_WICPixelFormat32bppRGB, GUID_WICPixelFormat64bppRGB, GUID_WICPixelFormat96bppRGBFloat, and GUID_WICPixelFormat64bppPRGBAHalf) as they are not valid for use with “WIC1” APIs.</p>

For example, here is how you should be creating the WIC factory for Win32 desktop applications that support older versions of Windows: ```cpp #define _WIN7_PLATFORM_UPDATE #include // CoInitializeEx needs called at some point before this IWICImagingFactory* wicFactory = nullptr; HRESULT hr = CoCreateInstance( CLSID_WICImagingFactory2, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWICImagingFactory2), reinterpret_cast<LPVOID*>( &wicFactory ) ); if ( SUCCEEDED(hr) ) { // WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed // Note you only need to QI IWICImagingFactory2 if you need to call CreateImageEncoder } else { hr = CoCreateInstance( CLSID_WICImagingFactory1, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWICImagingFactory), reinterpret_cast<LPVOID*>( &wicFactory ) ); } ``` This results in the application using the new "WIC2" behaviors when available, but falls back to the older versions of WIC when it's not available. DirectXTK and DirectXTex were both recently updated to support "WIC2" when it is available. This includes use of new WIC pixel formats ( GUID_WICPixelFormat96bppRGBFloat is the most useful since it matches DXGI_FORMAT_R32G32B32_FLOAT ), opts into the new Windows BMP BITMAPV5HEADER support (which encodes 32-bit with alpha channels for GUID_WICPixelFormat32bppBGRA and reads such BMP files as well), and can make use of the fix to the TIFF decoder for 96bpp floating-point images (which load as GUID_WICPixelFormat96bppRGBFloat). Windows phone: Note that the Windows phone 8.0 platform does not support the WIC API, but Windows phone 8.1 does include it. Xbox One: The Xbox One platform includes "WIC2". The HD Photo / JPEG XR codec is not currently supported for Xbox One XDK development. VS 2012 Update 1: When building with the "v110_xp" Platform Toolset, the WIC2 header content is not available so avoid the use of ``_WIN7_PLATFORM_UPDATE`` for these configurations. Windows 8.1: There are a few additional changes to WIC with Windows 8.1 including support for a limited ``DDS`` codec. See Microsoft Docs.