1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-21 12:00:06 +00:00

Reformat code

This commit is contained in:
Chuck Walbourn 2020-05-09 17:41:45 -07:00
parent 45fb8623d2
commit 91d783dc22
8 changed files with 410 additions and 404 deletions

View File

@ -863,6 +863,8 @@ namespace
return DXGI_FORMAT_UNKNOWN;
}
#undef ISBITMASK
//--------------------------------------------------------------------------------------
DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT format) noexcept

View File

@ -880,6 +880,8 @@ namespace
return DXGI_FORMAT_UNKNOWN;
}
#undef ISBITMASK
//--------------------------------------------------------------------------------------
DXGI_FORMAT MakeSRGB( _In_ DXGI_FORMAT format ) noexcept

View File

@ -111,7 +111,7 @@ namespace
using ScopedHandle = std::unique_ptr<void, handle_closer>;
inline HANDLE safe_handle( HANDLE h ) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
inline HANDLE safe_handle(HANDLE h) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
//--------------------------------------------------------------------------------------
HRESULT LoadTextureDataFromMemory(
@ -525,7 +525,7 @@ namespace
// the RED/BLUE masks for 10:10:10:2 formats. We assume
// below that the 'backwards' header mask is being used since it is most
// likely written by D3DX.
// For 'correct' writers this should be 0x3ff00000,0x000ffc00,0x000003ff for BGR data
if (ISBITMASK(0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000))
{
@ -730,6 +730,8 @@ namespace
return D3DFMT_UNKNOWN;
}
#undef ISBITMASK
//--------------------------------------------------------------------------------------
HRESULT CreateTextureFromDDS(
@ -805,7 +807,7 @@ namespace
if (NumBytes > UINT32_MAX || RowBytes > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
if ((pSrcBits + (NumBytes*iDepth)) > pEndBits)
if ((pSrcBits + (NumBytes * iDepth)) > pEndBits)
{
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
@ -816,8 +818,8 @@ namespace
for (UINT j = 0; j < iDepth; ++j)
{
uint8_t *dptr = pDestBits;
const uint8_t *sptr = pSrcBits;
uint8_t* dptr = pDestBits;
const uint8_t* sptr = pSrcBits;
// Copy stride line by line
for (size_t h = 0; h < NumRows; h++)
@ -1026,7 +1028,7 @@ HRESULT DirectX::CreateDDSTextureFromMemory(
{
*texture = nullptr;
}
if (!d3dDevice || !ddsData || !texture)
{
return E_INVALIDARG;

View File

@ -117,89 +117,89 @@ namespace
#pragma pack(pop)
const DDS_PIXELFORMAT DDSPF_DXT1 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_DXT3 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_DXT5 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_BC4_UNORM =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','U'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','U'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_BC4_SNORM =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','S'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','S'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_BC5_UNORM =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','U'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','U'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_BC5_SNORM =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','S'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','S'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_R8G8_B8G8 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_G8R8_G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_YUY2 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_A8R8G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
const DDS_PIXELFORMAT DDSPF_X8R8G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 };
const DDS_PIXELFORMAT DDSPF_A8B8G8R8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
const DDS_PIXELFORMAT DDSPF_G16R16 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
const DDS_PIXELFORMAT DDSPF_R5G6B5 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 };
const DDS_PIXELFORMAT DDSPF_A1R5G5B5 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000 };
const DDS_PIXELFORMAT DDSPF_A4R4G4B4 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000 };
const DDS_PIXELFORMAT DDSPF_L8 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00 };
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00 };
const DDS_PIXELFORMAT DDSPF_L16 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000 };
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000 };
const DDS_PIXELFORMAT DDSPF_A8L8 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00 };
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00 };
const DDS_PIXELFORMAT DDSPF_A8 =
{ sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff };
{ sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff };
const DDS_PIXELFORMAT DDSPF_V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0x0000, 0x0000 };
const DDS_PIXELFORMAT DDSPF_V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0x0000, 0x0000 };
const DDS_PIXELFORMAT DDSPF_Q8W8V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
const DDS_PIXELFORMAT DDSPF_Q8W8V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
const DDS_PIXELFORMAT DDSPF_V16U16 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
const DDS_PIXELFORMAT DDSPF_V16U16 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
// DXGI_FORMAT_R10G10B10A2_UNORM should be written using DX10 extension to avoid D3DX 10:10:10:2 reversal issue
// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat)
const DDS_PIXELFORMAT DDSPF_DX10 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','1','0'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','1','0'), 0, 0, 0, 0, 0 };
//-----------------------------------------------------------------------------
struct handle_closer { void operator()(HANDLE h) noexcept { if (h) CloseHandle(h); } };
using ScopedHandle = std::unique_ptr<void, handle_closer>;
inline HANDLE safe_handle( HANDLE h ) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
inline HANDLE safe_handle(HANDLE h) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
class auto_delete_file
{
@ -256,9 +256,9 @@ namespace
//--------------------------------------------------------------------------------------
// Return the BPP for a particular format
//--------------------------------------------------------------------------------------
size_t BitsPerPixel( _In_ DXGI_FORMAT fmt ) noexcept
size_t BitsPerPixel(_In_ DXGI_FORMAT fmt) noexcept
{
switch( fmt )
switch (fmt)
{
case DXGI_FORMAT_R32G32B32A32_TYPELESS:
case DXGI_FORMAT_R32G32B32A32_FLOAT:
@ -406,9 +406,9 @@ namespace
//--------------------------------------------------------------------------------------
// Determines if the format is block compressed
//--------------------------------------------------------------------------------------
bool IsCompressed( _In_ DXGI_FORMAT fmt ) noexcept
bool IsCompressed(_In_ DXGI_FORMAT fmt) noexcept
{
switch ( fmt )
switch (fmt)
{
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
@ -589,10 +589,10 @@ namespace
//--------------------------------------------------------------------------------------
DXGI_FORMAT EnsureNotTypeless( DXGI_FORMAT fmt ) noexcept
DXGI_FORMAT EnsureNotTypeless(DXGI_FORMAT fmt) noexcept
{
// Assumes UNORM or FLOAT; doesn't use UINT or SINT
switch( fmt )
switch (fmt)
{
case DXGI_FORMAT_R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_FLOAT;
case DXGI_FORMAT_R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_FLOAT;
@ -623,58 +623,58 @@ namespace
_In_ ID3D11DeviceContext* pContext,
_In_ ID3D11Resource* pSource,
D3D11_TEXTURE2D_DESC& desc,
ComPtr<ID3D11Texture2D>& pStaging ) noexcept
ComPtr<ID3D11Texture2D>& pStaging) noexcept
{
if ( !pContext || !pSource )
if (!pContext || !pSource)
return E_INVALIDARG;
D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN;
pSource->GetType( &resType );
pSource->GetType(&resType);
if ( resType != D3D11_RESOURCE_DIMENSION_TEXTURE2D )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
if (resType != D3D11_RESOURCE_DIMENSION_TEXTURE2D)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
ComPtr<ID3D11Texture2D> pTexture;
HRESULT hr = pSource->QueryInterface(IID_ID3D11Texture2D, reinterpret_cast<void**>(pTexture.GetAddressOf()));
if ( FAILED(hr) )
if (FAILED(hr))
return hr;
assert( pTexture );
assert(pTexture);
pTexture->GetDesc( &desc );
pTexture->GetDesc(&desc);
ComPtr<ID3D11Device> d3dDevice;
pContext->GetDevice( d3dDevice.GetAddressOf() );
pContext->GetDevice(d3dDevice.GetAddressOf());
if ( desc.SampleDesc.Count > 1 )
if (desc.SampleDesc.Count > 1)
{
// MSAA content must be resolved before being copied to a staging texture
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
ComPtr<ID3D11Texture2D> pTemp;
hr = d3dDevice->CreateTexture2D( &desc, nullptr, pTemp.GetAddressOf() );
if ( FAILED(hr) )
hr = d3dDevice->CreateTexture2D(&desc, nullptr, pTemp.GetAddressOf());
if (FAILED(hr))
return hr;
assert( pTemp );
assert(pTemp);
DXGI_FORMAT fmt = EnsureNotTypeless( desc.Format );
DXGI_FORMAT fmt = EnsureNotTypeless(desc.Format);
UINT support = 0;
hr = d3dDevice->CheckFormatSupport( fmt, &support );
if ( FAILED(hr) )
hr = d3dDevice->CheckFormatSupport(fmt, &support);
if (FAILED(hr))
return hr;
if ( !(support & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE) )
if (!(support & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE))
return E_FAIL;
for( UINT item = 0; item < desc.ArraySize; ++item )
for (UINT item = 0; item < desc.ArraySize; ++item)
{
for( UINT level = 0; level < desc.MipLevels; ++level )
for (UINT level = 0; level < desc.MipLevels; ++level)
{
UINT index = D3D11CalcSubresource( level, item, desc.MipLevels );
pContext->ResolveSubresource( pTemp.Get(), index, pSource, index, fmt );
UINT index = D3D11CalcSubresource(level, item, desc.MipLevels);
pContext->ResolveSubresource(pTemp.Get(), index, pSource, index, fmt);
}
}
@ -684,14 +684,14 @@ namespace
desc.Usage = D3D11_USAGE_STAGING;
hr = d3dDevice->CreateTexture2D(&desc, nullptr, pStaging.ReleaseAndGetAddressOf());
if ( FAILED(hr) )
if (FAILED(hr))
return hr;
assert( pStaging );
assert(pStaging);
pContext->CopyResource( pStaging.Get(), pTemp.Get() );
pContext->CopyResource(pStaging.Get(), pTemp.Get());
}
else if ( (desc.Usage == D3D11_USAGE_STAGING) && (desc.CPUAccessFlags & D3D11_CPU_ACCESS_READ) )
else if ((desc.Usage == D3D11_USAGE_STAGING) && (desc.CPUAccessFlags & D3D11_CPU_ACCESS_READ))
{
// Handle case where the source is already a staging texture we can use directly
pStaging = pTexture;
@ -705,12 +705,12 @@ namespace
desc.Usage = D3D11_USAGE_STAGING;
hr = d3dDevice->CreateTexture2D(&desc, nullptr, pStaging.ReleaseAndGetAddressOf());
if ( FAILED(hr) )
if (FAILED(hr))
return hr;
assert( pStaging );
assert(pStaging);
pContext->CopyResource( pStaging.Get(), pSource );
pContext->CopyResource(pStaging.Get(), pSource);
}
return S_OK;
@ -780,25 +780,25 @@ _Use_decl_annotations_
HRESULT DirectX::SaveDDSTextureToFile(
ID3D11DeviceContext* pContext,
ID3D11Resource* pSource,
const wchar_t* fileName ) noexcept
const wchar_t* fileName) noexcept
{
if ( !fileName )
if (!fileName)
return E_INVALIDARG;
D3D11_TEXTURE2D_DESC desc = {};
ComPtr<ID3D11Texture2D> pStaging;
HRESULT hr = CaptureTexture( pContext, pSource, desc, pStaging );
if ( FAILED(hr) )
HRESULT hr = CaptureTexture(pContext, pSource, desc, pStaging);
if (FAILED(hr))
return hr;
// Create file
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile( safe_handle( CreateFile2( fileName, GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS, nullptr ) ) );
ScopedHandle hFile(safe_handle(CreateFile2(fileName, GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS, nullptr)));
#else
ScopedHandle hFile( safe_handle( CreateFileW( fileName, GENERIC_WRITE | DELETE, 0, nullptr, CREATE_ALWAYS, 0, nullptr ) ) );
ScopedHandle hFile(safe_handle(CreateFileW(fileName, GENERIC_WRITE | DELETE, 0, nullptr, CREATE_ALWAYS, 0, nullptr)));
#endif
if ( !hFile )
return HRESULT_FROM_WIN32( GetLastError() );
if (!hFile)
return HRESULT_FROM_WIN32(GetLastError());
auto_delete_file delonfail(hFile.get());
@ -810,7 +810,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
auto header = reinterpret_cast<DDS_HEADER*>(&fileHeader[0] + sizeof(uint32_t));
size_t headerSize = sizeof(uint32_t) + sizeof(DDS_HEADER);
header->size = sizeof( DDS_HEADER );
header->size = sizeof(DDS_HEADER);
header->flags = DDS_HEADER_FLAGS_TEXTURE | DDS_HEADER_FLAGS_MIPMAP;
header->height = desc.Height;
header->width = desc.Width;
@ -819,32 +819,32 @@ HRESULT DirectX::SaveDDSTextureToFile(
// Try to use a legacy .DDS pixel format for better tools support, otherwise fallback to 'DX10' header extension
DDS_HEADER_DXT10* extHeader = nullptr;
switch( desc.Format )
switch (desc.Format)
{
case DXGI_FORMAT_R8G8B8A8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A8B8G8R8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R16G16_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_G16R16, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8G8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A8L8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R16_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_L16, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_L8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_A8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8G8_B8G8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_R8G8_B8G8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_G8R8_G8B8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_G8R8_G8B8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC1_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_DXT1, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC2_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_DXT3, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC3_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_DXT5, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC4_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_BC4_UNORM, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC4_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_BC4_SNORM, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC5_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_BC5_UNORM, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC5_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_BC5_SNORM, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_B5G6R5_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_R5G6B5, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_B5G5R5A1_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A1R5G5B5, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8G8_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_V8U8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8G8B8A8_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_Q8W8V8U8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R16G16_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_V16U16, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_B8G8R8A8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A8R8G8B8, sizeof(DDS_PIXELFORMAT) ); break; // DXGI 1.1
case DXGI_FORMAT_B8G8R8X8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_X8R8G8B8, sizeof(DDS_PIXELFORMAT) ); break; // DXGI 1.1
case DXGI_FORMAT_YUY2: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_YUY2, sizeof(DDS_PIXELFORMAT) ); break; // DXGI 1.2
case DXGI_FORMAT_B4G4R4A4_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A4R4G4B4, sizeof(DDS_PIXELFORMAT) ); break; // DXGI 1.2
case DXGI_FORMAT_R8G8B8A8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A8B8G8R8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R16G16_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_G16R16, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8G8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A8L8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R16_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_L16, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_L8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_A8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8G8_B8G8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_R8G8_B8G8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_G8R8_G8B8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_G8R8_G8B8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC1_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DXT1, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC2_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DXT3, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC3_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DXT5, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC4_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_BC4_UNORM, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC4_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_BC4_SNORM, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC5_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_BC5_UNORM, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC5_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_BC5_SNORM, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_B5G6R5_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_R5G6B5, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_B5G5R5A1_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A1R5G5B5, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8G8_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_V8U8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8G8B8A8_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_Q8W8V8U8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R16G16_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_V16U16, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_B8G8R8A8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A8R8G8B8, sizeof(DDS_PIXELFORMAT)); break; // DXGI 1.1
case DXGI_FORMAT_B8G8R8X8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_X8R8G8B8, sizeof(DDS_PIXELFORMAT)); break; // DXGI 1.1
case DXGI_FORMAT_YUY2: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_YUY2, sizeof(DDS_PIXELFORMAT)); break; // DXGI 1.2
case DXGI_FORMAT_B4G4R4A4_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A4R4G4B4, sizeof(DDS_PIXELFORMAT)); break; // DXGI 1.2
// Legacy D3DX formats using D3DFMT enum value as FourCC
case DXGI_FORMAT_R32G32B32A32_FLOAT: header->ddspf.size = sizeof(DDS_PIXELFORMAT); header->ddspf.flags = DDS_FOURCC; header->ddspf.fourCC = 116; break; // D3DFMT_A32B32G32R32F
@ -860,7 +860,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
case DXGI_FORMAT_IA44:
case DXGI_FORMAT_P8:
case DXGI_FORMAT_A8P8:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
default:
memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DX10, sizeof(DDS_PIXELFORMAT));
@ -874,65 +874,65 @@ HRESULT DirectX::SaveDDSTextureToFile(
}
size_t rowPitch, slicePitch, rowCount;
hr = GetSurfaceInfo( desc.Width, desc.Height, desc.Format, &slicePitch, &rowPitch, &rowCount );
hr = GetSurfaceInfo(desc.Width, desc.Height, desc.Format, &slicePitch, &rowPitch, &rowCount);
if (FAILED(hr))
return hr;
if (rowPitch > UINT32_MAX || slicePitch > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
if ( IsCompressed( desc.Format ) )
if (IsCompressed(desc.Format))
{
header->flags |= DDS_HEADER_FLAGS_LINEARSIZE;
header->pitchOrLinearSize = static_cast<uint32_t>( slicePitch );
header->pitchOrLinearSize = static_cast<uint32_t>(slicePitch);
}
else
{
header->flags |= DDS_HEADER_FLAGS_PITCH;
header->pitchOrLinearSize = static_cast<uint32_t>( rowPitch );
header->pitchOrLinearSize = static_cast<uint32_t>(rowPitch);
}
// Setup pixels
std::unique_ptr<uint8_t[]> pixels( new (std::nothrow) uint8_t[ slicePitch ] );
std::unique_ptr<uint8_t[]> pixels(new (std::nothrow) uint8_t[slicePitch]);
if (!pixels)
return E_OUTOFMEMORY;
D3D11_MAPPED_SUBRESOURCE mapped;
hr = pContext->Map( pStaging.Get(), 0, D3D11_MAP_READ, 0, &mapped );
if ( FAILED(hr) )
hr = pContext->Map(pStaging.Get(), 0, D3D11_MAP_READ, 0, &mapped);
if (FAILED(hr))
return hr;
auto sptr = static_cast<const uint8_t*>( mapped.pData );
if ( !sptr )
auto sptr = static_cast<const uint8_t*>(mapped.pData);
if (!sptr)
{
pContext->Unmap( pStaging.Get(), 0 );
pContext->Unmap(pStaging.Get(), 0);
return E_POINTER;
}
uint8_t* dptr = pixels.get();
size_t msize = std::min<size_t>( rowPitch, mapped.RowPitch );
for( size_t h = 0; h < rowCount; ++h )
size_t msize = std::min<size_t>(rowPitch, mapped.RowPitch);
for (size_t h = 0; h < rowCount; ++h)
{
memcpy_s( dptr, rowPitch, sptr, msize );
memcpy_s(dptr, rowPitch, sptr, msize);
sptr += mapped.RowPitch;
dptr += rowPitch;
}
pContext->Unmap( pStaging.Get(), 0 );
pContext->Unmap(pStaging.Get(), 0);
// Write header & pixels
DWORD bytesWritten;
if ( !WriteFile( hFile.get(), fileHeader, static_cast<DWORD>( headerSize ), &bytesWritten, nullptr ) )
return HRESULT_FROM_WIN32( GetLastError() );
if (!WriteFile(hFile.get(), fileHeader, static_cast<DWORD>(headerSize), &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
if ( bytesWritten != headerSize )
if (bytesWritten != headerSize)
return E_FAIL;
if ( !WriteFile( hFile.get(), pixels.get(), static_cast<DWORD>( slicePitch ), &bytesWritten, nullptr ) )
return HRESULT_FROM_WIN32( GetLastError() );
if (!WriteFile(hFile.get(), pixels.get(), static_cast<DWORD>(slicePitch), &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
if ( bytesWritten != slicePitch )
if (bytesWritten != slicePitch)
return E_FAIL;
delonfail.clear();
@ -951,19 +951,19 @@ HRESULT DirectX::SaveWICTextureToFile(
std::function<void(IPropertyBag2*)> setCustomProps,
bool forceSRGB) noexcept
{
if ( !fileName )
if (!fileName)
return E_INVALIDARG;
D3D11_TEXTURE2D_DESC desc = {};
ComPtr<ID3D11Texture2D> pStaging;
HRESULT hr = CaptureTexture( pContext, pSource, desc, pStaging );
if ( FAILED(hr) )
HRESULT hr = CaptureTexture(pContext, pSource, desc, pStaging);
if (FAILED(hr))
return hr;
// Determine source format's WIC equivalent
WICPixelFormatGUID pfGuid = {};
bool sRGB = forceSRGB;
switch ( desc.Format )
switch (desc.Format)
{
case DXGI_FORMAT_R32G32B32A32_FLOAT: pfGuid = GUID_WICPixelFormat128bppRGBAFloat; break;
case DXGI_FORMAT_R16G16B16A16_FLOAT: pfGuid = GUID_WICPixelFormat64bppRGBAHalf; break;
@ -998,45 +998,45 @@ HRESULT DirectX::SaveWICTextureToFile(
case DXGI_FORMAT_B8G8R8X8_UNORM: // DXGI 1.1
pfGuid = GUID_WICPixelFormat32bppBGR;
break;
break;
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: // DXGI 1.1
pfGuid = GUID_WICPixelFormat32bppBGR;
sRGB = true;
break;
break;
default:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
auto pWIC = _GetWIC();
if ( !pWIC )
if (!pWIC)
return E_NOINTERFACE;
ComPtr<IWICStream> stream;
hr = pWIC->CreateStream( stream.GetAddressOf() );
if ( FAILED(hr) )
hr = pWIC->CreateStream(stream.GetAddressOf());
if (FAILED(hr))
return hr;
hr = stream->InitializeFromFilename( fileName, GENERIC_WRITE );
if ( FAILED(hr) )
hr = stream->InitializeFromFilename(fileName, GENERIC_WRITE);
if (FAILED(hr))
return hr;
auto_delete_file_wic delonfail(stream, fileName);
ComPtr<IWICBitmapEncoder> encoder;
hr = pWIC->CreateEncoder( guidContainerFormat, nullptr, encoder.GetAddressOf() );
if ( FAILED(hr) )
hr = pWIC->CreateEncoder(guidContainerFormat, nullptr, encoder.GetAddressOf());
if (FAILED(hr))
return hr;
hr = encoder->Initialize( stream.Get(), WICBitmapEncoderNoCache );
if ( FAILED(hr) )
hr = encoder->Initialize(stream.Get(), WICBitmapEncoderNoCache);
if (FAILED(hr))
return hr;
ComPtr<IWICBitmapFrameEncode> frame;
ComPtr<IPropertyBag2> props;
hr = encoder->CreateNewFrame( frame.GetAddressOf(), props.GetAddressOf() );
if ( FAILED(hr) )
hr = encoder->CreateNewFrame(frame.GetAddressOf(), props.GetAddressOf());
if (FAILED(hr))
return hr;
if (targetFormat && memcmp(&guidContainerFormat, &GUID_ContainerFormatBmp, sizeof(WICPixelFormatGUID)) == 0 && g_WIC2)
@ -1051,36 +1051,36 @@ HRESULT DirectX::SaveWICTextureToFile(
(void)props->Write(1, &option, &varValue);
}
if ( setCustomProps )
if (setCustomProps)
{
setCustomProps( props.Get() );
setCustomProps(props.Get());
}
hr = frame->Initialize( props.Get() );
if ( FAILED(hr) )
hr = frame->Initialize(props.Get());
if (FAILED(hr))
return hr;
hr = frame->SetSize( desc.Width , desc.Height );
if ( FAILED(hr) )
hr = frame->SetSize(desc.Width, desc.Height);
if (FAILED(hr))
return hr;
hr = frame->SetResolution( 72, 72 );
if ( FAILED(hr) )
hr = frame->SetResolution(72, 72);
if (FAILED(hr))
return hr;
// Pick a target format
WICPixelFormatGUID targetGuid = {};
if ( targetFormat )
if (targetFormat)
{
targetGuid = *targetFormat;
}
else
{
// Screenshots don't typically include the alpha channel of the render target
switch ( desc.Format )
switch (desc.Format)
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
case DXGI_FORMAT_R32G32B32A32_FLOAT:
case DXGI_FORMAT_R32G32B32A32_FLOAT:
case DXGI_FORMAT_R16G16B16A16_FLOAT:
if (g_WIC2)
{
@ -1111,11 +1111,11 @@ HRESULT DirectX::SaveWICTextureToFile(
}
}
hr = frame->SetPixelFormat( &targetGuid );
if ( FAILED(hr) )
hr = frame->SetPixelFormat(&targetGuid);
if (FAILED(hr))
return hr;
if ( targetFormat && memcmp( targetFormat, &targetGuid, sizeof(WICPixelFormatGUID) ) != 0 )
if (targetFormat && memcmp(targetFormat, &targetGuid, sizeof(WICPixelFormatGUID)) != 0)
{
// Requested output pixel format is not supported by the WIC codec
return E_FAIL;
@ -1123,18 +1123,18 @@ HRESULT DirectX::SaveWICTextureToFile(
// Encode WIC metadata
ComPtr<IWICMetadataQueryWriter> metawriter;
if ( SUCCEEDED( frame->GetMetadataQueryWriter( metawriter.GetAddressOf() ) ) )
if (SUCCEEDED(frame->GetMetadataQueryWriter(metawriter.GetAddressOf())))
{
PROPVARIANT value;
PropVariantInit( &value );
PropVariantInit(&value);
value.vt = VT_LPSTR;
value.pszVal = const_cast<char*>("DirectXTK");
if ( memcmp( &guidContainerFormat, &GUID_ContainerFormatPng, sizeof(GUID) ) == 0 )
if (memcmp(&guidContainerFormat, &GUID_ContainerFormatPng, sizeof(GUID)) == 0)
{
// Set Software name
(void)metawriter->SetMetadataByName( L"/tEXt/{str=Software}", &value );
(void)metawriter->SetMetadataByName(L"/tEXt/{str=Software}", &value);
// Set sRGB chunk
if (sRGB)
@ -1157,21 +1157,21 @@ HRESULT DirectX::SaveWICTextureToFile(
else
{
// Set Software name
(void)metawriter->SetMetadataByName( L"System.ApplicationName", &value );
(void)metawriter->SetMetadataByName(L"System.ApplicationName", &value);
if ( sRGB )
if (sRGB)
{
// Set EXIF Colorspace of sRGB
value.vt = VT_UI2;
value.uiVal = 1;
(void)metawriter->SetMetadataByName( L"System.Image.ColorSpace", &value );
(void)metawriter->SetMetadataByName(L"System.Image.ColorSpace", &value);
}
}
}
D3D11_MAPPED_SUBRESOURCE mapped;
hr = pContext->Map( pStaging.Get(), 0, D3D11_MAP_READ, 0, &mapped );
if ( FAILED(hr) )
hr = pContext->Map(pStaging.Get(), 0, D3D11_MAP_READ, 0, &mapped);
if (FAILED(hr))
return hr;
uint64_t imageSize = uint64_t(mapped.RowPitch) * uint64_t(desc.Height);
@ -1181,7 +1181,7 @@ HRESULT DirectX::SaveWICTextureToFile(
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
}
if ( memcmp( &targetGuid, &pfGuid, sizeof(WICPixelFormatGUID) ) != 0 )
if (memcmp(&targetGuid, &pfGuid, sizeof(WICPixelFormatGUID)) != 0)
{
// Conversion required to write
ComPtr<IWICBitmap> source;
@ -1189,55 +1189,55 @@ HRESULT DirectX::SaveWICTextureToFile(
pfGuid,
mapped.RowPitch, static_cast<UINT>(imageSize),
static_cast<BYTE*>(mapped.pData), source.GetAddressOf());
if ( FAILED(hr) )
if (FAILED(hr))
{
pContext->Unmap( pStaging.Get(), 0 );
pContext->Unmap(pStaging.Get(), 0);
return hr;
}
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
hr = pWIC->CreateFormatConverter(FC.GetAddressOf());
if (FAILED(hr))
{
pContext->Unmap( pStaging.Get(), 0 );
pContext->Unmap(pStaging.Get(), 0);
return hr;
}
BOOL canConvert = FALSE;
hr = FC->CanConvert( pfGuid, targetGuid, &canConvert );
if ( FAILED(hr) || !canConvert )
hr = FC->CanConvert(pfGuid, targetGuid, &canConvert);
if (FAILED(hr) || !canConvert)
{
pContext->Unmap( pStaging.Get(), 0 );
pContext->Unmap(pStaging.Get(), 0);
return E_UNEXPECTED;
}
hr = FC->Initialize( source.Get(), targetGuid, WICBitmapDitherTypeNone, nullptr, 0, WICBitmapPaletteTypeMedianCut );
if ( FAILED(hr) )
hr = FC->Initialize(source.Get(), targetGuid, WICBitmapDitherTypeNone, nullptr, 0, WICBitmapPaletteTypeMedianCut);
if (FAILED(hr))
{
pContext->Unmap( pStaging.Get(), 0 );
pContext->Unmap(pStaging.Get(), 0);
return hr;
}
WICRect rect = { 0, 0, static_cast<INT>( desc.Width ), static_cast<INT>( desc.Height ) };
hr = frame->WriteSource( FC.Get(), &rect );
WICRect rect = { 0, 0, static_cast<INT>(desc.Width), static_cast<INT>(desc.Height) };
hr = frame->WriteSource(FC.Get(), &rect);
}
else
{
// No conversion required
hr = frame->WritePixels( desc.Height, mapped.RowPitch, static_cast<UINT>(imageSize), static_cast<BYTE*>( mapped.pData ) );
hr = frame->WritePixels(desc.Height, mapped.RowPitch, static_cast<UINT>(imageSize), static_cast<BYTE*>(mapped.pData));
}
pContext->Unmap( pStaging.Get(), 0 );
pContext->Unmap(pStaging.Get(), 0);
if (FAILED(hr))
return hr;
hr = frame->Commit();
if ( FAILED(hr) )
if (FAILED(hr))
return hr;
hr = encoder->Commit();
if ( FAILED(hr) )
if (FAILED(hr))
return hr;
delonfail.clear();

View File

@ -202,7 +202,7 @@ namespace
using ScopedHandle = std::unique_ptr<void, handle_closer>;
inline HANDLE safe_handle( HANDLE h ) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
inline HANDLE safe_handle(HANDLE h) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
class auto_delete_file
{
@ -259,9 +259,9 @@ namespace
//--------------------------------------------------------------------------------------
// Return the BPP for a particular format
//--------------------------------------------------------------------------------------
size_t BitsPerPixel( _In_ DXGI_FORMAT fmt ) noexcept
size_t BitsPerPixel(_In_ DXGI_FORMAT fmt) noexcept
{
switch( fmt )
switch (fmt)
{
case DXGI_FORMAT_R32G32B32A32_TYPELESS:
case DXGI_FORMAT_R32G32B32A32_FLOAT:
@ -412,9 +412,9 @@ namespace
//--------------------------------------------------------------------------------------
// Determines if the format is block compressed
//--------------------------------------------------------------------------------------
bool IsCompressed( _In_ DXGI_FORMAT fmt ) noexcept
bool IsCompressed(_In_ DXGI_FORMAT fmt) noexcept
{
switch ( fmt )
switch (fmt)
{
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
@ -596,10 +596,10 @@ namespace
//--------------------------------------------------------------------------------------
DXGI_FORMAT EnsureNotTypeless( DXGI_FORMAT fmt ) noexcept
DXGI_FORMAT EnsureNotTypeless(DXGI_FORMAT fmt) noexcept
{
// Assumes UNORM or FLOAT; doesn't use UINT or SINT
switch( fmt )
switch (fmt)
{
case DXGI_FORMAT_R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_FLOAT;
case DXGI_FORMAT_R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_FLOAT;
@ -856,7 +856,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
D3D12_RESOURCE_STATES beforeState,
D3D12_RESOURCE_STATES afterState) noexcept
{
if ( !fileName )
if (!fileName)
return E_INVALIDARG;
ComPtr<ID3D12Device> device;
@ -889,14 +889,14 @@ HRESULT DirectX::SaveDDSTextureToFile(
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
ComPtr<ID3D12Resource> pStaging;
HRESULT hr = CaptureTexture( device.Get(), pCommandQ, pSource, dstRowPitch, desc, pStaging, beforeState, afterState );
if ( FAILED(hr) )
HRESULT hr = CaptureTexture(device.Get(), pCommandQ, pSource, dstRowPitch, desc, pStaging, beforeState, afterState);
if (FAILED(hr))
return hr;
// Create file
ScopedHandle hFile( safe_handle( CreateFile2( fileName, GENERIC_WRITE, 0, CREATE_ALWAYS, nullptr ) ) );
if ( !hFile )
return HRESULT_FROM_WIN32( GetLastError() );
ScopedHandle hFile(safe_handle(CreateFile2(fileName, GENERIC_WRITE, 0, CREATE_ALWAYS, nullptr)));
if (!hFile)
return HRESULT_FROM_WIN32(GetLastError());
auto_delete_file delonfail(hFile.get());
@ -908,7 +908,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
auto header = reinterpret_cast<DDS_HEADER*>(&fileHeader[0] + sizeof(uint32_t));
size_t headerSize = sizeof(uint32_t) + sizeof(DDS_HEADER);
header->size = sizeof( DDS_HEADER );
header->size = sizeof(DDS_HEADER);
header->flags = DDS_HEADER_FLAGS_TEXTURE | DDS_HEADER_FLAGS_MIPMAP;
header->height = desc.Height;
header->width = static_cast<uint32_t>(desc.Width);
@ -917,34 +917,34 @@ HRESULT DirectX::SaveDDSTextureToFile(
// Try to use a legacy .DDS pixel format for better tools support, otherwise fallback to 'DX10' header extension
DDS_HEADER_DXT10* extHeader = nullptr;
switch( desc.Format )
switch (desc.Format)
{
case DXGI_FORMAT_R8G8B8A8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A8B8G8R8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R16G16_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_G16R16, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8G8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A8L8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R16_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_L16, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_L8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_A8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8G8_B8G8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_R8G8_B8G8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_G8R8_G8B8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_G8R8_G8B8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC1_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_DXT1, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC2_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_DXT3, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC3_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_DXT5, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC4_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_BC4_UNORM, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC4_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_BC4_SNORM, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC5_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_BC5_UNORM, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_BC5_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_BC5_SNORM, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_B5G6R5_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_R5G6B5, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_B5G5R5A1_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A1R5G5B5, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8G8_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_V8U8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8G8B8A8_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_Q8W8V8U8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R16G16_SNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_V16U16, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_B8G8R8A8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A8R8G8B8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_B8G8R8X8_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_X8R8G8B8, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_YUY2: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_YUY2, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_B4G4R4A4_UNORM: memcpy_s( &header->ddspf, sizeof(header->ddspf), &DDSPF_A4R4G4B4, sizeof(DDS_PIXELFORMAT) ); break;
case DXGI_FORMAT_R8G8B8A8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A8B8G8R8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R16G16_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_G16R16, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8G8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A8L8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R16_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_L16, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_L8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_A8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8G8_B8G8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_R8G8_B8G8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_G8R8_G8B8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_G8R8_G8B8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC1_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DXT1, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC2_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DXT3, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC3_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DXT5, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC4_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_BC4_UNORM, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC4_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_BC4_SNORM, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC5_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_BC5_UNORM, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_BC5_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_BC5_SNORM, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_B5G6R5_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_R5G6B5, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_B5G5R5A1_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A1R5G5B5, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8G8_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_V8U8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R8G8B8A8_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_Q8W8V8U8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_R16G16_SNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_V16U16, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_B8G8R8A8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A8R8G8B8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_B8G8R8X8_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_X8R8G8B8, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_YUY2: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_YUY2, sizeof(DDS_PIXELFORMAT)); break;
case DXGI_FORMAT_B4G4R4A4_UNORM: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A4R4G4B4, sizeof(DDS_PIXELFORMAT)); break;
// Legacy D3DX formats using D3DFMT enum value as FourCC
// Legacy D3DX formats using D3DFMT enum value as FourCC
case DXGI_FORMAT_R32G32B32A32_FLOAT: header->ddspf.size = sizeof(DDS_PIXELFORMAT); header->ddspf.flags = DDS_FOURCC; header->ddspf.fourCC = 116; break; // D3DFMT_A32B32G32R32F
case DXGI_FORMAT_R16G16B16A16_FLOAT: header->ddspf.size = sizeof(DDS_PIXELFORMAT); header->ddspf.flags = DDS_FOURCC; header->ddspf.fourCC = 113; break; // D3DFMT_A16B16G16R16F
case DXGI_FORMAT_R16G16B16A16_UNORM: header->ddspf.size = sizeof(DDS_PIXELFORMAT); header->ddspf.flags = DDS_FOURCC; header->ddspf.fourCC = 36; break; // D3DFMT_A16B16G16R16
@ -958,7 +958,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
case DXGI_FORMAT_IA44:
case DXGI_FORMAT_P8:
case DXGI_FORMAT_A8P8:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
default:
memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DX10, sizeof(DDS_PIXELFORMAT));
@ -979,19 +979,19 @@ HRESULT DirectX::SaveDDSTextureToFile(
if (rowPitch > UINT32_MAX || slicePitch > UINT32_MAX)
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
if ( IsCompressed( desc.Format ) )
if (IsCompressed(desc.Format))
{
header->flags |= DDS_HEADER_FLAGS_LINEARSIZE;
header->pitchOrLinearSize = static_cast<uint32_t>( slicePitch );
header->pitchOrLinearSize = static_cast<uint32_t>(slicePitch);
}
else
{
header->flags |= DDS_HEADER_FLAGS_PITCH;
header->pitchOrLinearSize = static_cast<uint32_t>( rowPitch );
header->pitchOrLinearSize = static_cast<uint32_t>(rowPitch);
}
// Setup pixels
std::unique_ptr<uint8_t[]> pixels( new (std::nothrow) uint8_t[ slicePitch ] );
std::unique_ptr<uint8_t[]> pixels(new (std::nothrow) uint8_t[slicePitch]);
if (!pixels)
return E_OUTOFMEMORY;
@ -1005,12 +1005,12 @@ HRESULT DirectX::SaveDDSTextureToFile(
void* pMappedMemory = nullptr;
D3D12_RANGE readRange = { 0, static_cast<SIZE_T>(imageSize) };
D3D12_RANGE writeRange = { 0, 0 };
hr = pStaging->Map(0, &readRange, &pMappedMemory );
if ( FAILED(hr) )
hr = pStaging->Map(0, &readRange, &pMappedMemory);
if (FAILED(hr))
return hr;
auto sptr = static_cast<const uint8_t*>(pMappedMemory);
if ( !sptr )
if (!sptr)
{
pStaging->Unmap(0, &writeRange);
return E_POINTER;
@ -1018,28 +1018,28 @@ HRESULT DirectX::SaveDDSTextureToFile(
uint8_t* dptr = pixels.get();
size_t msize = std::min<size_t>( rowPitch, rowPitch );
for( size_t h = 0; h < rowCount; ++h )
size_t msize = std::min<size_t>(rowPitch, rowPitch);
for (size_t h = 0; h < rowCount; ++h)
{
memcpy_s( dptr, rowPitch, sptr, msize );
memcpy_s(dptr, rowPitch, sptr, msize);
sptr += dstRowPitch;
dptr += rowPitch;
}
pStaging->Unmap( 0, &writeRange );
pStaging->Unmap(0, &writeRange);
// Write header & pixels
DWORD bytesWritten;
if ( !WriteFile( hFile.get(), fileHeader, static_cast<DWORD>( headerSize ), &bytesWritten, nullptr ) )
return HRESULT_FROM_WIN32( GetLastError() );
if (!WriteFile(hFile.get(), fileHeader, static_cast<DWORD>(headerSize), &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
if ( bytesWritten != headerSize )
if (bytesWritten != headerSize)
return E_FAIL;
if ( !WriteFile( hFile.get(), pixels.get(), static_cast<DWORD>( slicePitch ), &bytesWritten, nullptr ) )
return HRESULT_FROM_WIN32( GetLastError() );
if (!WriteFile(hFile.get(), pixels.get(), static_cast<DWORD>(slicePitch), &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
if ( bytesWritten != slicePitch )
if (bytesWritten != slicePitch)
return E_FAIL;
delonfail.clear();
@ -1052,7 +1052,7 @@ _Use_decl_annotations_
HRESULT DirectX::SaveWICTextureToFile(
ID3D12CommandQueue* pCommandQ,
ID3D12Resource* pSource,
REFGUID guidContainerFormat,
REFGUID guidContainerFormat,
const wchar_t* fileName,
D3D12_RESOURCE_STATES beforeState,
D3D12_RESOURCE_STATES afterState,
@ -1060,7 +1060,7 @@ HRESULT DirectX::SaveWICTextureToFile(
std::function<void(IPropertyBag2*)> setCustomProps,
bool forceSRGB) noexcept
{
if ( !fileName )
if (!fileName)
return E_INVALIDARG;
ComPtr<ID3D12Device> device;
@ -1100,7 +1100,7 @@ HRESULT DirectX::SaveWICTextureToFile(
// Determine source format's WIC equivalent
WICPixelFormatGUID pfGuid = {};
bool sRGB = forceSRGB;
switch ( desc.Format )
switch (desc.Format)
{
case DXGI_FORMAT_R32G32B32A32_FLOAT: pfGuid = GUID_WICPixelFormat128bppRGBAFloat; break;
case DXGI_FORMAT_R16G16B16A16_FLOAT: pfGuid = GUID_WICPixelFormat64bppRGBAHalf; break;
@ -1135,88 +1135,88 @@ HRESULT DirectX::SaveWICTextureToFile(
case DXGI_FORMAT_B8G8R8X8_UNORM:
pfGuid = GUID_WICPixelFormat32bppBGR;
break;
break;
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
pfGuid = GUID_WICPixelFormat32bppBGR;
sRGB = true;
break;
break;
default:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
auto pWIC = _GetWIC();
if ( !pWIC )
if (!pWIC)
return E_NOINTERFACE;
ComPtr<IWICStream> stream;
hr = pWIC->CreateStream( stream.GetAddressOf() );
if ( FAILED(hr) )
hr = pWIC->CreateStream(stream.GetAddressOf());
if (FAILED(hr))
return hr;
hr = stream->InitializeFromFilename( fileName, GENERIC_WRITE );
if ( FAILED(hr) )
hr = stream->InitializeFromFilename(fileName, GENERIC_WRITE);
if (FAILED(hr))
return hr;
auto_delete_file_wic delonfail(stream, fileName);
ComPtr<IWICBitmapEncoder> encoder;
hr = pWIC->CreateEncoder( guidContainerFormat, nullptr, encoder.GetAddressOf() );
if ( FAILED(hr) )
hr = pWIC->CreateEncoder(guidContainerFormat, nullptr, encoder.GetAddressOf());
if (FAILED(hr))
return hr;
hr = encoder->Initialize( stream.Get(), WICBitmapEncoderNoCache );
if ( FAILED(hr) )
hr = encoder->Initialize(stream.Get(), WICBitmapEncoderNoCache);
if (FAILED(hr))
return hr;
ComPtr<IWICBitmapFrameEncode> frame;
ComPtr<IPropertyBag2> props;
hr = encoder->CreateNewFrame( frame.GetAddressOf(), props.GetAddressOf() );
if ( FAILED(hr) )
hr = encoder->CreateNewFrame(frame.GetAddressOf(), props.GetAddressOf());
if (FAILED(hr))
return hr;
if ( targetFormat && memcmp( &guidContainerFormat, &GUID_ContainerFormatBmp, sizeof(WICPixelFormatGUID) ) == 0 )
if (targetFormat && memcmp(&guidContainerFormat, &GUID_ContainerFormatBmp, sizeof(WICPixelFormatGUID)) == 0)
{
// Opt-in to the WIC2 support for writing 32-bit Windows BMP files with an alpha channel
PROPBAG2 option = {};
option.pstrName = const_cast<wchar_t*>(L"EnableV5Header32bppBGRA");
VARIANT varValue;
VARIANT varValue;
varValue.vt = VT_BOOL;
varValue.boolVal = VARIANT_TRUE;
(void)props->Write( 1, &option, &varValue );
varValue.boolVal = VARIANT_TRUE;
(void)props->Write(1, &option, &varValue);
}
if ( setCustomProps )
if (setCustomProps)
{
setCustomProps( props.Get() );
setCustomProps(props.Get());
}
hr = frame->Initialize( props.Get() );
if ( FAILED(hr) )
hr = frame->Initialize(props.Get());
if (FAILED(hr))
return hr;
hr = frame->SetSize(static_cast<UINT>(desc.Width), desc.Height );
if ( FAILED(hr) )
hr = frame->SetSize(static_cast<UINT>(desc.Width), desc.Height);
if (FAILED(hr))
return hr;
hr = frame->SetResolution( 72, 72 );
if ( FAILED(hr) )
hr = frame->SetResolution(72, 72);
if (FAILED(hr))
return hr;
// Pick a target format
WICPixelFormatGUID targetGuid = {};
if ( targetFormat )
if (targetFormat)
{
targetGuid = *targetFormat;
}
else
{
// Screenshots don't typically include the alpha channel of the render target
switch ( desc.Format )
switch (desc.Format)
{
case DXGI_FORMAT_R32G32B32A32_FLOAT:
case DXGI_FORMAT_R32G32B32A32_FLOAT:
case DXGI_FORMAT_R16G16B16A16_FLOAT:
targetGuid = GUID_WICPixelFormat96bppRGBFloat; // WIC 2
break;
@ -1239,11 +1239,11 @@ HRESULT DirectX::SaveWICTextureToFile(
}
}
hr = frame->SetPixelFormat( &targetGuid );
if ( FAILED(hr) )
hr = frame->SetPixelFormat(&targetGuid);
if (FAILED(hr))
return hr;
if ( targetFormat && memcmp( targetFormat, &targetGuid, sizeof(WICPixelFormatGUID) ) != 0 )
if (targetFormat && memcmp(targetFormat, &targetGuid, sizeof(WICPixelFormatGUID)) != 0)
{
// Requested output pixel format is not supported by the WIC codec
return E_FAIL;
@ -1251,18 +1251,18 @@ HRESULT DirectX::SaveWICTextureToFile(
// Encode WIC metadata
ComPtr<IWICMetadataQueryWriter> metawriter;
if ( SUCCEEDED( frame->GetMetadataQueryWriter( metawriter.GetAddressOf() ) ) )
if (SUCCEEDED(frame->GetMetadataQueryWriter(metawriter.GetAddressOf())))
{
PROPVARIANT value;
PropVariantInit( &value );
PropVariantInit(&value);
value.vt = VT_LPSTR;
value.pszVal = const_cast<char*>("DirectXTK");
if ( memcmp( &guidContainerFormat, &GUID_ContainerFormatPng, sizeof(GUID) ) == 0 )
if (memcmp(&guidContainerFormat, &GUID_ContainerFormatPng, sizeof(GUID)) == 0)
{
// Set Software name
(void)metawriter->SetMetadataByName( L"/tEXt/{str=Software}", &value );
(void)metawriter->SetMetadataByName(L"/tEXt/{str=Software}", &value);
// Set sRGB chunk
if (sRGB)
@ -1285,14 +1285,14 @@ HRESULT DirectX::SaveWICTextureToFile(
else
{
// Set Software name
(void)metawriter->SetMetadataByName( L"System.ApplicationName", &value );
(void)metawriter->SetMetadataByName(L"System.ApplicationName", &value);
if ( sRGB )
if (sRGB)
{
// Set EXIF Colorspace of sRGB
value.vt = VT_UI2;
value.uiVal = 1;
(void)metawriter->SetMetadataByName( L"System.Image.ColorSpace", &value );
(void)metawriter->SetMetadataByName(L"System.Image.ColorSpace", &value);
}
}
}
@ -1302,50 +1302,50 @@ HRESULT DirectX::SaveWICTextureToFile(
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
void* pMappedMemory = nullptr;
D3D12_RANGE readRange = {0, static_cast<SIZE_T>(imageSize)};
D3D12_RANGE writeRange = {0, 0};
D3D12_RANGE readRange = { 0, static_cast<SIZE_T>(imageSize) };
D3D12_RANGE writeRange = { 0, 0 };
hr = pStaging->Map(0, &readRange, &pMappedMemory);
if (FAILED(hr))
return hr;
if ( memcmp( &targetGuid, &pfGuid, sizeof(WICPixelFormatGUID) ) != 0 )
if (memcmp(&targetGuid, &pfGuid, sizeof(WICPixelFormatGUID)) != 0)
{
// Conversion required to write
ComPtr<IWICBitmap> source;
hr = pWIC->CreateBitmapFromMemory(static_cast<UINT>(desc.Width), desc.Height, pfGuid,
static_cast<UINT>(dstRowPitch), static_cast<UINT>(imageSize),
static_cast<BYTE*>(pMappedMemory), source.GetAddressOf() );
if ( FAILED(hr) )
static_cast<UINT>(dstRowPitch), static_cast<UINT>(imageSize),
static_cast<BYTE*>(pMappedMemory), source.GetAddressOf());
if (FAILED(hr))
{
pStaging->Unmap( 0, &writeRange );
pStaging->Unmap(0, &writeRange);
return hr;
}
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
hr = pWIC->CreateFormatConverter(FC.GetAddressOf());
if (FAILED(hr))
{
pStaging->Unmap(0, &writeRange);
return hr;
}
BOOL canConvert = FALSE;
hr = FC->CanConvert( pfGuid, targetGuid, &canConvert );
if ( FAILED(hr) || !canConvert )
hr = FC->CanConvert(pfGuid, targetGuid, &canConvert);
if (FAILED(hr) || !canConvert)
{
return E_UNEXPECTED;
}
hr = FC->Initialize( source.Get(), targetGuid, WICBitmapDitherTypeNone, nullptr, 0, WICBitmapPaletteTypeMedianCut );
if ( FAILED(hr) )
hr = FC->Initialize(source.Get(), targetGuid, WICBitmapDitherTypeNone, nullptr, 0, WICBitmapPaletteTypeMedianCut);
if (FAILED(hr))
{
pStaging->Unmap(0, &writeRange);
return hr;
}
WICRect rect = { 0, 0, static_cast<INT>( desc.Width ), static_cast<INT>( desc.Height ) };
hr = frame->WriteSource( FC.Get(), &rect );
if ( FAILED(hr) )
WICRect rect = { 0, 0, static_cast<INT>(desc.Width), static_cast<INT>(desc.Height) };
hr = frame->WriteSource(FC.Get(), &rect);
if (FAILED(hr))
{
pStaging->Unmap(0, &writeRange);
return hr;
@ -1354,19 +1354,19 @@ HRESULT DirectX::SaveWICTextureToFile(
else
{
// No conversion required
hr = frame->WritePixels( desc.Height, static_cast<UINT>(dstRowPitch), static_cast<UINT>(imageSize), static_cast<BYTE*>( pMappedMemory ) );
if ( FAILED(hr) )
hr = frame->WritePixels(desc.Height, static_cast<UINT>(dstRowPitch), static_cast<UINT>(imageSize), static_cast<BYTE*>(pMappedMemory));
if (FAILED(hr))
return hr;
}
pStaging->Unmap(0, &writeRange);
hr = frame->Commit();
if ( FAILED(hr) )
if (FAILED(hr))
return hr;
hr = encoder->Commit();
if ( FAILED(hr) )
if (FAILED(hr))
return hr;
delonfail.clear();

View File

@ -102,116 +102,116 @@ namespace
#pragma pack(pop)
const DDS_PIXELFORMAT DDSPF_DXT1 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_DXT2 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_DXT3 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_DXT4 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_DXT5 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_R8G8_B8G8 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_G8R8_G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_YUY2 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_UYVY =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_UYVY =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0 };
const DDS_PIXELFORMAT DDSPF_A8R8G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
const DDS_PIXELFORMAT DDSPF_X8R8G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0 };
const DDS_PIXELFORMAT DDSPF_A8B8G8R8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
const DDS_PIXELFORMAT DDSPF_X8B8G8R8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0 };
const DDS_PIXELFORMAT DDSPF_G16R16 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
const DDS_PIXELFORMAT DDSPF_R5G6B5 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0 };
const DDS_PIXELFORMAT DDSPF_A1R5G5B5 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000 };
const DDS_PIXELFORMAT DDSPF_X1R5G5B5 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x7c00, 0x03e0, 0x001f, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x7c00, 0x03e0, 0x001f, 0 };
const DDS_PIXELFORMAT DDSPF_A4R4G4B4 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x0f00, 0x00f0, 0x0000f, 0xf000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x0f00, 0x00f0, 0x0000f, 0xf000 };
const DDS_PIXELFORMAT DDSPF_X4R4G4B4 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0f00, 0x00f0, 0x000f, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0f00, 0x00f0, 0x000f, 0 };
const DDS_PIXELFORMAT DDSPF_R8G8B8 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0 };
const DDS_PIXELFORMAT DDSPF_A8R3G3B2 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00 };
const DDS_PIXELFORMAT DDSPF_R3G3B2 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0 };
const DDS_PIXELFORMAT DDSPF_A4L4 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 8, 0x0f, 0, 0, 0xf0 };
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 8, 0x0f, 0, 0, 0xf0 };
const DDS_PIXELFORMAT DDSPF_L8 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00 };
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00 };
const DDS_PIXELFORMAT DDSPF_L16 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000 };
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000 };
const DDS_PIXELFORMAT DDSPF_A8L8 =
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00 };
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00 };
const DDS_PIXELFORMAT DDSPF_A8 =
{ sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff };
{ sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff };
const DDS_PIXELFORMAT DDSPF_V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0x0000, 0x0000 };
const DDS_PIXELFORMAT DDSPF_V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0x0000, 0x0000 };
const DDS_PIXELFORMAT DDSPF_Q8W8V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
const DDS_PIXELFORMAT DDSPF_Q8W8V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
const DDS_PIXELFORMAT DDSPF_V16U16 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
const DDS_PIXELFORMAT DDSPF_V16U16 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
const DDS_PIXELFORMAT DDSPF_A2W10V10U10 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 };
const DDS_PIXELFORMAT DDSPF_L6V5U5 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 16, 0x001f, 0x03e0, 0xfc00, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 16, 0x001f, 0x03e0, 0xfc00, 0 };
const DDS_PIXELFORMAT DDSPF_X8L8V8U8 =
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0 };
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0 };
// Note these 10:10:10:2 format RGB masks are reversed to support a long-standing bug in D3DX
const DDS_PIXELFORMAT DDSPF_A2R10G10B10 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000 };
const DDS_PIXELFORMAT DDSPF_A2B10G10R10 =
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 };
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 };
//-----------------------------------------------------------------------------
struct handle_closer { void operator()(HANDLE h) noexcept { if (h) CloseHandle(h); } };
using ScopedHandle = std::unique_ptr<void, handle_closer>;
inline HANDLE safe_handle( HANDLE h ) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
inline HANDLE safe_handle(HANDLE h) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; }
class auto_delete_file
{
@ -561,9 +561,9 @@ namespace
_Use_decl_annotations_
HRESULT DirectX::SaveDDSTextureToFile(
LPDIRECT3DSURFACE9 pSource,
const wchar_t* fileName ) noexcept
const wchar_t* fileName) noexcept
{
if ( !pSource|| !fileName )
if (!pSource || !fileName)
return E_INVALIDARG;
D3DSURFACE_DESC desc = {};
@ -583,12 +583,12 @@ HRESULT DirectX::SaveDDSTextureToFile(
// Create file
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
ScopedHandle hFile( safe_handle( CreateFile2( fileName, GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS, nullptr ) ) );
ScopedHandle hFile(safe_handle(CreateFile2(fileName, GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS, nullptr)));
#else
ScopedHandle hFile( safe_handle( CreateFileW( fileName, GENERIC_WRITE | DELETE, 0, nullptr, CREATE_ALWAYS, 0, nullptr ) ) );
ScopedHandle hFile(safe_handle(CreateFileW(fileName, GENERIC_WRITE | DELETE, 0, nullptr, CREATE_ALWAYS, 0, nullptr)));
#endif
if ( !hFile )
return HRESULT_FROM_WIN32( GetLastError() );
if (!hFile)
return HRESULT_FROM_WIN32(GetLastError());
auto_delete_file delonfail(hFile.get());
@ -607,7 +607,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
header->mipMapCount = 1;
header->caps = DDS_SURFACE_FLAGS_TEXTURE;
switch( desc.Format )
switch (desc.Format)
{
case D3DFMT_R8G8B8: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_R8G8B8, sizeof(DDS_PIXELFORMAT)); break;
case D3DFMT_A8R8G8B8: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A8R8G8B8, sizeof(DDS_PIXELFORMAT)); break;
@ -636,7 +636,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
case D3DFMT_A2W10V10U10: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_A2W10V10U10, sizeof(DDS_PIXELFORMAT)); break;
case D3DFMT_L16: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_L16, sizeof(DDS_PIXELFORMAT)); break;
// FourCC formats
// FourCC formats
case D3DFMT_UYVY: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_UYVY, sizeof(DDS_PIXELFORMAT)); break;
case D3DFMT_R8G8_B8G8: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_R8G8_B8G8, sizeof(DDS_PIXELFORMAT)); break;
case D3DFMT_YUY2: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_YUY2, sizeof(DDS_PIXELFORMAT)); break;
@ -647,7 +647,7 @@ HRESULT DirectX::SaveDDSTextureToFile(
case D3DFMT_DXT4: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DXT4, sizeof(DDS_PIXELFORMAT)); break;
case D3DFMT_DXT5: memcpy_s(&header->ddspf, sizeof(header->ddspf), &DDSPF_DXT5, sizeof(DDS_PIXELFORMAT)); break;
// Legacy D3DX formats using D3DFMT enum value as FourCC
// Legacy D3DX formats using D3DFMT enum value as FourCC
case D3DFMT_A16B16G16R16: header->ddspf.size = sizeof(DDS_PIXELFORMAT); header->ddspf.flags = DDS_FOURCC; header->ddspf.fourCC = 36; break;
case D3DFMT_Q16W16V16U16: header->ddspf.size = sizeof(DDS_PIXELFORMAT); header->ddspf.flags = DDS_FOURCC; header->ddspf.fourCC = 110; break;
case D3DFMT_R16F: header->ddspf.size = sizeof(DDS_PIXELFORMAT); header->ddspf.flags = DDS_FOURCC; header->ddspf.fourCC = 111; break;
@ -702,9 +702,9 @@ HRESULT DirectX::SaveDDSTextureToFile(
uint8_t* dptr = pixels.get();
size_t msize = std::min<size_t>(rowPitch, static_cast<size_t>(lockedRect.Pitch));
for( size_t h = 0; h < rowCount; ++h )
for (size_t h = 0; h < rowCount; ++h)
{
memcpy_s( dptr, rowPitch, sptr, msize );
memcpy_s(dptr, rowPitch, sptr, msize);
sptr += lockedRect.Pitch;
dptr += rowPitch;
}
@ -713,16 +713,16 @@ HRESULT DirectX::SaveDDSTextureToFile(
// Write header & pixels
DWORD bytesWritten;
if ( !WriteFile( hFile.get(), fileHeader, static_cast<DWORD>( headerSize ), &bytesWritten, nullptr ) )
return HRESULT_FROM_WIN32( GetLastError() );
if (!WriteFile(hFile.get(), fileHeader, static_cast<DWORD>(headerSize), &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
if ( bytesWritten != headerSize )
if (bytesWritten != headerSize)
return E_FAIL;
if ( !WriteFile( hFile.get(), pixels.get(), static_cast<DWORD>( slicePitch ), &bytesWritten, nullptr ) )
return HRESULT_FROM_WIN32( GetLastError() );
if (!WriteFile(hFile.get(), pixels.get(), static_cast<DWORD>(slicePitch), &bytesWritten, nullptr))
return HRESULT_FROM_WIN32(GetLastError());
if ( bytesWritten != slicePitch )
if (bytesWritten != slicePitch)
return E_FAIL;
delonfail.clear();
@ -764,7 +764,7 @@ HRESULT DirectX::SaveWICTextureToFile(
// Determine source format's WIC equivalent
WICPixelFormatGUID pfGuid = {};
switch ( desc.Format )
switch (desc.Format)
{
case D3DFMT_R8G8B8: pfGuid = GUID_WICPixelFormat24bppBGR; break;
case D3DFMT_A8R8G8B8: pfGuid = GUID_WICPixelFormat32bppBGRA; break;
@ -793,33 +793,33 @@ HRESULT DirectX::SaveWICTextureToFile(
#endif
default:
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
ComPtr<IWICStream> stream;
hr = pWIC->CreateStream( stream.GetAddressOf() );
if ( FAILED(hr) )
hr = pWIC->CreateStream(stream.GetAddressOf());
if (FAILED(hr))
return hr;
hr = stream->InitializeFromFilename( fileName, GENERIC_WRITE );
if ( FAILED(hr) )
hr = stream->InitializeFromFilename(fileName, GENERIC_WRITE);
if (FAILED(hr))
return hr;
auto_delete_file_wic delonfail(stream, fileName);
ComPtr<IWICBitmapEncoder> encoder;
hr = pWIC->CreateEncoder( guidContainerFormat, nullptr, encoder.GetAddressOf() );
if ( FAILED(hr) )
hr = pWIC->CreateEncoder(guidContainerFormat, nullptr, encoder.GetAddressOf());
if (FAILED(hr))
return hr;
hr = encoder->Initialize( stream.Get(), WICBitmapEncoderNoCache );
if ( FAILED(hr) )
hr = encoder->Initialize(stream.Get(), WICBitmapEncoderNoCache);
if (FAILED(hr))
return hr;
ComPtr<IWICBitmapFrameEncode> frame;
ComPtr<IPropertyBag2> props;
hr = encoder->CreateNewFrame( frame.GetAddressOf(), props.GetAddressOf() );
if ( FAILED(hr) )
hr = encoder->CreateNewFrame(frame.GetAddressOf(), props.GetAddressOf());
if (FAILED(hr))
return hr;
if (targetFormat && memcmp(&guidContainerFormat, &GUID_ContainerFormatBmp, sizeof(WICPixelFormatGUID)) == 0 && g_WIC2)
@ -834,33 +834,33 @@ HRESULT DirectX::SaveWICTextureToFile(
(void)props->Write(1, &option, &varValue);
}
if ( setCustomProps )
if (setCustomProps)
{
setCustomProps( props.Get() );
setCustomProps(props.Get());
}
hr = frame->Initialize( props.Get() );
if ( FAILED(hr) )
hr = frame->Initialize(props.Get());
if (FAILED(hr))
return hr;
hr = frame->SetSize( desc.Width , desc.Height );
if ( FAILED(hr) )
hr = frame->SetSize(desc.Width, desc.Height);
if (FAILED(hr))
return hr;
hr = frame->SetResolution( 72, 72 );
if ( FAILED(hr) )
hr = frame->SetResolution(72, 72);
if (FAILED(hr))
return hr;
// Pick a target format
WICPixelFormatGUID targetGuid = {};
if ( targetFormat )
if (targetFormat)
{
targetGuid = *targetFormat;
}
else
{
// Screenshots don't typically include the alpha channel of the render target
switch ( desc.Format )
switch (desc.Format)
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
case D3DFMT_A32B32G32R32F:
@ -900,11 +900,11 @@ HRESULT DirectX::SaveWICTextureToFile(
}
}
hr = frame->SetPixelFormat( &targetGuid );
if ( FAILED(hr) )
hr = frame->SetPixelFormat(&targetGuid);
if (FAILED(hr))
return hr;
if ( targetFormat && memcmp( targetFormat, &targetGuid, sizeof(WICPixelFormatGUID) ) != 0 )
if (targetFormat && memcmp(targetFormat, &targetGuid, sizeof(WICPixelFormatGUID)) != 0)
{
// Requested output pixel format is not supported by the WIC codec
return E_FAIL;
@ -912,23 +912,23 @@ HRESULT DirectX::SaveWICTextureToFile(
// Encode WIC metadata
ComPtr<IWICMetadataQueryWriter> metawriter;
if ( SUCCEEDED( frame->GetMetadataQueryWriter( metawriter.GetAddressOf() ) ) )
if (SUCCEEDED(frame->GetMetadataQueryWriter(metawriter.GetAddressOf())))
{
PROPVARIANT value;
PropVariantInit( &value );
PropVariantInit(&value);
value.vt = VT_LPSTR;
value.pszVal = const_cast<char*>("DirectXTK");
if ( memcmp( &guidContainerFormat, &GUID_ContainerFormatPng, sizeof(GUID) ) == 0 )
if (memcmp(&guidContainerFormat, &GUID_ContainerFormatPng, sizeof(GUID)) == 0)
{
// Set Software name
(void)metawriter->SetMetadataByName( L"/tEXt/{str=Software}", &value );
(void)metawriter->SetMetadataByName(L"/tEXt/{str=Software}", &value);
}
else
{
// Set Software name
(void)metawriter->SetMetadataByName( L"System.ApplicationName", &value );
(void)metawriter->SetMetadataByName(L"System.ApplicationName", &value);
}
}
@ -944,44 +944,44 @@ HRESULT DirectX::SaveWICTextureToFile(
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
}
if ( memcmp( &targetGuid, &pfGuid, sizeof(WICPixelFormatGUID) ) != 0 )
if (memcmp(&targetGuid, &pfGuid, sizeof(WICPixelFormatGUID)) != 0)
{
// Conversion required to write
ComPtr<IWICBitmap> source;
hr = pWIC->CreateBitmapFromMemory(desc.Width, desc.Height, pfGuid,
static_cast<UINT>(lockedRect.Pitch), static_cast<UINT>(imageSize),
static_cast<BYTE*>(lockedRect.pBits), source.GetAddressOf());
if ( FAILED(hr) )
if (FAILED(hr))
{
pSource->UnlockRect();
return hr;
}
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
hr = pWIC->CreateFormatConverter(FC.GetAddressOf());
if (FAILED(hr))
{
pSource->UnlockRect();
return hr;
}
BOOL canConvert = FALSE;
hr = FC->CanConvert( pfGuid, targetGuid, &canConvert );
if ( FAILED(hr) || !canConvert )
hr = FC->CanConvert(pfGuid, targetGuid, &canConvert);
if (FAILED(hr) || !canConvert)
{
pSource->UnlockRect();
return E_UNEXPECTED;
}
hr = FC->Initialize( source.Get(), targetGuid, WICBitmapDitherTypeNone, nullptr, 0, WICBitmapPaletteTypeMedianCut );
if ( FAILED(hr) )
hr = FC->Initialize(source.Get(), targetGuid, WICBitmapDitherTypeNone, nullptr, 0, WICBitmapPaletteTypeMedianCut);
if (FAILED(hr))
{
pSource->UnlockRect();
return hr;
}
WICRect rect = { 0, 0, static_cast<INT>( desc.Width ), static_cast<INT>( desc.Height ) };
hr = frame->WriteSource( FC.Get(), &rect );
WICRect rect = { 0, 0, static_cast<INT>(desc.Width), static_cast<INT>(desc.Height) };
hr = frame->WriteSource(FC.Get(), &rect);
}
else
{
@ -997,11 +997,11 @@ HRESULT DirectX::SaveWICTextureToFile(
return hr;
hr = frame->Commit();
if ( FAILED(hr) )
if (FAILED(hr))
return hr;
hr = encoder->Commit();
if ( FAILED(hr) )
if (FAILED(hr))
return hr;
delonfail.clear();

View File

@ -346,7 +346,7 @@ namespace
//---------------------------------------------------------------------------------
HRESULT CreateTextureFromWIC(_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_ IWICBitmapFrameDecode *frame,
_In_ IWICBitmapFrameDecode* frame,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,

View File

@ -259,7 +259,7 @@ namespace
//---------------------------------------------------------------------------------
HRESULT CreateTextureFromWIC(
_In_ LPDIRECT3DDEVICE9 device,
_In_ IWICBitmapFrameDecode *frame,
_In_ IWICBitmapFrameDecode* frame,
_In_ size_t maxsize,
_In_ unsigned int loadFlags,
_Outptr_ LPDIRECT3DTEXTURE9* texture) noexcept