mirror of
https://github.com/microsoft/DirectXTex
synced 2024-11-21 12:00:06 +00:00
.edtiorconfig driven reformat of source (#271)
This commit is contained in:
parent
091835fa86
commit
b1001d15b3
@ -1,9 +1,74 @@
|
|||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*.{cpp,h,inl,fx,hlsl}]
|
[*.{fx,fxh,hlsl,hlsli}]
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
indent_style = space
|
indent_style = space
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
end_of_line = crlf
|
end_of_line = crlf
|
||||||
charset = latin1
|
charset = latin1
|
||||||
|
cpp_space_before_function_open_parenthesis = remove
|
||||||
|
cpp_space_around_binary_operator = ignore
|
||||||
|
cpp_space_pointer_reference_alignment = ignore
|
||||||
|
|
||||||
|
[*.{cpp,h,hpp,inl}]
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
end_of_line = crlf
|
||||||
|
charset = latin1
|
||||||
|
cpp_indent_braces = false
|
||||||
|
cpp_indent_multi_line_relative_to = innermost_parenthesis
|
||||||
|
cpp_indent_within_parentheses = indent
|
||||||
|
cpp_indent_preserve_within_parentheses = false
|
||||||
|
cpp_indent_case_contents = true
|
||||||
|
cpp_indent_case_labels = false
|
||||||
|
cpp_indent_case_contents_when_block = true
|
||||||
|
cpp_indent_lambda_braces_when_parameter = true
|
||||||
|
cpp_indent_preprocessor = one_left
|
||||||
|
cpp_indent_access_specifiers = false
|
||||||
|
cpp_indent_namespace_contents = true
|
||||||
|
cpp_indent_preserve_comments = true
|
||||||
|
cpp_new_line_before_open_brace_namespace = new_line
|
||||||
|
cpp_new_line_before_open_brace_type = new_line
|
||||||
|
cpp_new_line_before_open_brace_function = new_line
|
||||||
|
cpp_new_line_before_open_brace_block = new_line
|
||||||
|
cpp_new_line_before_open_brace_lambda = new_line
|
||||||
|
cpp_new_line_scope_braces_on_separate_lines = true
|
||||||
|
cpp_new_line_close_brace_same_line_empty_type = true
|
||||||
|
cpp_new_line_close_brace_same_line_empty_function = true
|
||||||
|
cpp_new_line_before_catch = true
|
||||||
|
cpp_new_line_before_else = true
|
||||||
|
cpp_new_line_before_while_in_do_while = true
|
||||||
|
cpp_space_before_function_open_parenthesis = remove
|
||||||
|
cpp_space_within_parameter_list_parentheses = false
|
||||||
|
cpp_space_between_empty_parameter_list_parentheses = false
|
||||||
|
cpp_space_after_keywords_in_control_flow_statements = true
|
||||||
|
cpp_space_within_control_flow_statement_parentheses = false
|
||||||
|
cpp_space_before_lambda_open_parenthesis = false
|
||||||
|
cpp_space_within_cast_parentheses = false
|
||||||
|
cpp_space_after_cast_close_parenthesis = false
|
||||||
|
cpp_space_within_expression_parentheses = false
|
||||||
|
cpp_space_before_initializer_list_open_brace = false
|
||||||
|
cpp_space_within_initializer_list_braces = true
|
||||||
|
cpp_space_before_open_square_bracket = false
|
||||||
|
cpp_space_within_square_brackets = false
|
||||||
|
cpp_space_before_empty_square_brackets = false
|
||||||
|
cpp_space_between_empty_square_brackets = false
|
||||||
|
cpp_space_group_square_brackets = true
|
||||||
|
cpp_space_within_lambda_brackets = false
|
||||||
|
cpp_space_between_empty_lambda_brackets = false
|
||||||
|
cpp_space_before_comma = false
|
||||||
|
cpp_space_after_comma = true
|
||||||
|
cpp_space_remove_around_member_operators = true
|
||||||
|
cpp_space_before_inheritance_colon = true
|
||||||
|
cpp_space_before_constructor_colon = true
|
||||||
|
cpp_space_remove_before_semicolon = true
|
||||||
|
cpp_space_after_semicolon = false
|
||||||
|
cpp_space_remove_around_unary_operator = false
|
||||||
|
cpp_space_around_binary_operator = ignore
|
||||||
|
cpp_space_around_assignment_operator = insert
|
||||||
|
cpp_space_pointer_reference_alignment = ignore
|
||||||
|
cpp_space_around_ternary_operator = insert
|
||||||
|
cpp_wrap_preserve_blocks = one_liners
|
||||||
|
@ -43,7 +43,7 @@ using namespace DirectX;
|
|||||||
// Macros
|
// Macros
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#ifndef MAKEFOURCC
|
#ifndef MAKEFOURCC
|
||||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||||
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
||||||
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
||||||
#endif /* defined(MAKEFOURCC) */
|
#endif /* defined(MAKEFOURCC) */
|
||||||
@ -136,7 +136,7 @@ namespace
|
|||||||
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; }
|
||||||
|
|
||||||
template<UINT TNameLength>
|
template<UINT TNameLength>
|
||||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_ const char (&name)[TNameLength]) noexcept
|
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_ const char(&name)[TNameLength]) noexcept
|
||||||
{
|
{
|
||||||
#if defined(_DEBUG) || defined(PROFILE)
|
#if defined(_DEBUG) || defined(PROFILE)
|
||||||
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
||||||
@ -229,13 +229,13 @@ namespace
|
|||||||
*bitSize = 0;
|
*bitSize = 0;
|
||||||
|
|
||||||
// open the file
|
// open the file
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||||
ScopedHandle hFile(safe_handle(CreateFile2(fileName,
|
ScopedHandle hFile(safe_handle(CreateFile2(fileName,
|
||||||
GENERIC_READ,
|
GENERIC_READ,
|
||||||
FILE_SHARE_READ,
|
FILE_SHARE_READ,
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
nullptr)));
|
nullptr)));
|
||||||
#else
|
#else
|
||||||
ScopedHandle hFile(safe_handle(CreateFileW(fileName,
|
ScopedHandle hFile(safe_handle(CreateFileW(fileName,
|
||||||
GENERIC_READ,
|
GENERIC_READ,
|
||||||
FILE_SHARE_READ,
|
FILE_SHARE_READ,
|
||||||
@ -243,7 +243,7 @@ namespace
|
|||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
nullptr)));
|
nullptr)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!hFile)
|
if (!hFile)
|
||||||
{
|
{
|
||||||
@ -611,13 +611,13 @@ namespace
|
|||||||
numBytes = rowBytes * height;
|
numBytes = rowBytes * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
||||||
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
||||||
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
||||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||||
#else
|
#else
|
||||||
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (outNumBytes)
|
if (outNumBytes)
|
||||||
{
|
{
|
||||||
@ -637,7 +637,7 @@ namespace
|
|||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#define ISBITMASK( r,g,b,a ) ( ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a )
|
#define ISBITMASK( r,g,b,a ) ( ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a )
|
||||||
|
|
||||||
DXGI_FORMAT GetDXGIFormat(const DDS_PIXELFORMAT& ddpf) noexcept
|
DXGI_FORMAT GetDXGIFormat(const DDS_PIXELFORMAT& ddpf) noexcept
|
||||||
{
|
{
|
||||||
@ -904,10 +904,10 @@ namespace
|
|||||||
return DXGI_FORMAT_UNKNOWN;
|
return DXGI_FORMAT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef ISBITMASK
|
#undef ISBITMASK
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT format) noexcept
|
DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT format) noexcept
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
@ -1070,202 +1070,202 @@ namespace
|
|||||||
switch (resDim)
|
switch (resDim)
|
||||||
{
|
{
|
||||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
|
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
|
||||||
{
|
|
||||||
D3D11_TEXTURE1D_DESC desc;
|
|
||||||
desc.Width = static_cast<UINT>(width);
|
|
||||||
desc.MipLevels = static_cast<UINT>(mipCount);
|
|
||||||
desc.ArraySize = static_cast<UINT>(arraySize);
|
|
||||||
desc.Format = format;
|
|
||||||
desc.Usage = usage;
|
|
||||||
desc.BindFlags = bindFlags;
|
|
||||||
desc.CPUAccessFlags = cpuAccessFlags;
|
|
||||||
desc.MiscFlags = miscFlags & ~static_cast<unsigned int>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
|
||||||
|
|
||||||
ID3D11Texture1D* tex = nullptr;
|
|
||||||
hr = d3dDevice->CreateTexture1D(&desc,
|
|
||||||
initData,
|
|
||||||
&tex
|
|
||||||
);
|
|
||||||
if (SUCCEEDED(hr) && tex)
|
|
||||||
{
|
|
||||||
if (textureView)
|
|
||||||
{
|
|
||||||
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {};
|
|
||||||
SRVDesc.Format = format;
|
|
||||||
|
|
||||||
if (arraySize > 1)
|
|
||||||
{
|
|
||||||
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
|
|
||||||
SRVDesc.Texture1DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
|
||||||
SRVDesc.Texture1DArray.ArraySize = static_cast<UINT>(arraySize);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
|
|
||||||
SRVDesc.Texture1D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = d3dDevice->CreateShaderResourceView(tex,
|
|
||||||
&SRVDesc,
|
|
||||||
textureView
|
|
||||||
);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
tex->Release();
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (texture)
|
|
||||||
{
|
|
||||||
*texture = tex;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetDebugObjectName(tex, "DDSTextureLoader");
|
|
||||||
tex->Release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
|
|
||||||
{
|
|
||||||
D3D11_TEXTURE2D_DESC desc;
|
|
||||||
desc.Width = static_cast<UINT>(width);
|
|
||||||
desc.Height = static_cast<UINT>(height);
|
|
||||||
desc.MipLevels = static_cast<UINT>(mipCount);
|
|
||||||
desc.ArraySize = static_cast<UINT>(arraySize);
|
|
||||||
desc.Format = format;
|
|
||||||
desc.SampleDesc.Count = 1;
|
|
||||||
desc.SampleDesc.Quality = 0;
|
|
||||||
desc.Usage = usage;
|
|
||||||
desc.BindFlags = bindFlags;
|
|
||||||
desc.CPUAccessFlags = cpuAccessFlags;
|
|
||||||
if (isCubeMap)
|
|
||||||
{
|
|
||||||
desc.MiscFlags = miscFlags | D3D11_RESOURCE_MISC_TEXTURECUBE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
D3D11_TEXTURE1D_DESC desc;
|
||||||
|
desc.Width = static_cast<UINT>(width);
|
||||||
|
desc.MipLevels = static_cast<UINT>(mipCount);
|
||||||
|
desc.ArraySize = static_cast<UINT>(arraySize);
|
||||||
|
desc.Format = format;
|
||||||
|
desc.Usage = usage;
|
||||||
|
desc.BindFlags = bindFlags;
|
||||||
|
desc.CPUAccessFlags = cpuAccessFlags;
|
||||||
desc.MiscFlags = miscFlags & ~static_cast<unsigned int>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
desc.MiscFlags = miscFlags & ~static_cast<unsigned int>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
||||||
}
|
|
||||||
|
|
||||||
ID3D11Texture2D* tex = nullptr;
|
ID3D11Texture1D* tex = nullptr;
|
||||||
hr = d3dDevice->CreateTexture2D(&desc,
|
hr = d3dDevice->CreateTexture1D(&desc,
|
||||||
initData,
|
initData,
|
||||||
&tex
|
&tex
|
||||||
);
|
);
|
||||||
if (SUCCEEDED(hr) && tex)
|
if (SUCCEEDED(hr) && tex)
|
||||||
{
|
|
||||||
if (textureView)
|
|
||||||
{
|
{
|
||||||
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {};
|
if (textureView)
|
||||||
SRVDesc.Format = format;
|
|
||||||
|
|
||||||
if (isCubeMap)
|
|
||||||
{
|
{
|
||||||
if (arraySize > 6)
|
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {};
|
||||||
{
|
SRVDesc.Format = format;
|
||||||
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY;
|
|
||||||
SRVDesc.TextureCubeArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
|
||||||
|
|
||||||
// Earlier we set arraySize to (NumCubes * 6)
|
if (arraySize > 1)
|
||||||
SRVDesc.TextureCubeArray.NumCubes = static_cast<UINT>(arraySize / 6);
|
{
|
||||||
|
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
|
||||||
|
SRVDesc.Texture1DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
||||||
|
SRVDesc.Texture1DArray.ArraySize = static_cast<UINT>(arraySize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
|
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
|
||||||
SRVDesc.TextureCube.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
SRVDesc.Texture1D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = d3dDevice->CreateShaderResourceView(tex,
|
||||||
|
&SRVDesc,
|
||||||
|
textureView
|
||||||
|
);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
tex->Release();
|
||||||
|
return hr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (arraySize > 1)
|
|
||||||
|
if (texture)
|
||||||
{
|
{
|
||||||
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
|
*texture = tex;
|
||||||
SRVDesc.Texture2DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
|
||||||
SRVDesc.Texture2DArray.ArraySize = static_cast<UINT>(arraySize);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
SetDebugObjectName(tex, "DDSTextureLoader");
|
||||||
SRVDesc.Texture2D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = d3dDevice->CreateShaderResourceView(tex,
|
|
||||||
&SRVDesc,
|
|
||||||
textureView
|
|
||||||
);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
tex->Release();
|
tex->Release();
|
||||||
return hr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
if (texture)
|
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
|
||||||
|
{
|
||||||
|
D3D11_TEXTURE2D_DESC desc;
|
||||||
|
desc.Width = static_cast<UINT>(width);
|
||||||
|
desc.Height = static_cast<UINT>(height);
|
||||||
|
desc.MipLevels = static_cast<UINT>(mipCount);
|
||||||
|
desc.ArraySize = static_cast<UINT>(arraySize);
|
||||||
|
desc.Format = format;
|
||||||
|
desc.SampleDesc.Count = 1;
|
||||||
|
desc.SampleDesc.Quality = 0;
|
||||||
|
desc.Usage = usage;
|
||||||
|
desc.BindFlags = bindFlags;
|
||||||
|
desc.CPUAccessFlags = cpuAccessFlags;
|
||||||
|
if (isCubeMap)
|
||||||
{
|
{
|
||||||
*texture = tex;
|
desc.MiscFlags = miscFlags | D3D11_RESOURCE_MISC_TEXTURECUBE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetDebugObjectName(tex, "DDSTextureLoader");
|
desc.MiscFlags = miscFlags & ~static_cast<unsigned int>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
||||||
tex->Release();
|
}
|
||||||
|
|
||||||
|
ID3D11Texture2D* tex = nullptr;
|
||||||
|
hr = d3dDevice->CreateTexture2D(&desc,
|
||||||
|
initData,
|
||||||
|
&tex
|
||||||
|
);
|
||||||
|
if (SUCCEEDED(hr) && tex)
|
||||||
|
{
|
||||||
|
if (textureView)
|
||||||
|
{
|
||||||
|
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {};
|
||||||
|
SRVDesc.Format = format;
|
||||||
|
|
||||||
|
if (isCubeMap)
|
||||||
|
{
|
||||||
|
if (arraySize > 6)
|
||||||
|
{
|
||||||
|
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY;
|
||||||
|
SRVDesc.TextureCubeArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
||||||
|
|
||||||
|
// Earlier we set arraySize to (NumCubes * 6)
|
||||||
|
SRVDesc.TextureCubeArray.NumCubes = static_cast<UINT>(arraySize / 6);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
|
||||||
|
SRVDesc.TextureCube.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (arraySize > 1)
|
||||||
|
{
|
||||||
|
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
|
||||||
|
SRVDesc.Texture2DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
||||||
|
SRVDesc.Texture2DArray.ArraySize = static_cast<UINT>(arraySize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||||
|
SRVDesc.Texture2D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = d3dDevice->CreateShaderResourceView(tex,
|
||||||
|
&SRVDesc,
|
||||||
|
textureView
|
||||||
|
);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
tex->Release();
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texture)
|
||||||
|
{
|
||||||
|
*texture = tex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetDebugObjectName(tex, "DDSTextureLoader");
|
||||||
|
tex->Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
D3D11_TEXTURE3D_DESC desc;
|
|
||||||
desc.Width = static_cast<UINT>(width);
|
|
||||||
desc.Height = static_cast<UINT>(height);
|
|
||||||
desc.Depth = static_cast<UINT>(depth);
|
|
||||||
desc.MipLevels = static_cast<UINT>(mipCount);
|
|
||||||
desc.Format = format;
|
|
||||||
desc.Usage = usage;
|
|
||||||
desc.BindFlags = bindFlags;
|
|
||||||
desc.CPUAccessFlags = cpuAccessFlags;
|
|
||||||
desc.MiscFlags = miscFlags & ~static_cast<unsigned int>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
|
||||||
|
|
||||||
ID3D11Texture3D* tex = nullptr;
|
|
||||||
hr = d3dDevice->CreateTexture3D(&desc,
|
|
||||||
initData,
|
|
||||||
&tex
|
|
||||||
);
|
|
||||||
if (SUCCEEDED(hr) && tex)
|
|
||||||
{
|
{
|
||||||
if (textureView)
|
D3D11_TEXTURE3D_DESC desc;
|
||||||
|
desc.Width = static_cast<UINT>(width);
|
||||||
|
desc.Height = static_cast<UINT>(height);
|
||||||
|
desc.Depth = static_cast<UINT>(depth);
|
||||||
|
desc.MipLevels = static_cast<UINT>(mipCount);
|
||||||
|
desc.Format = format;
|
||||||
|
desc.Usage = usage;
|
||||||
|
desc.BindFlags = bindFlags;
|
||||||
|
desc.CPUAccessFlags = cpuAccessFlags;
|
||||||
|
desc.MiscFlags = miscFlags & ~static_cast<unsigned int>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
||||||
|
|
||||||
|
ID3D11Texture3D* tex = nullptr;
|
||||||
|
hr = d3dDevice->CreateTexture3D(&desc,
|
||||||
|
initData,
|
||||||
|
&tex
|
||||||
|
);
|
||||||
|
if (SUCCEEDED(hr) && tex)
|
||||||
{
|
{
|
||||||
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {};
|
if (textureView)
|
||||||
SRVDesc.Format = format;
|
|
||||||
|
|
||||||
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
|
|
||||||
SRVDesc.Texture3D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
|
||||||
|
|
||||||
hr = d3dDevice->CreateShaderResourceView(tex,
|
|
||||||
&SRVDesc,
|
|
||||||
textureView
|
|
||||||
);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
|
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {};
|
||||||
|
SRVDesc.Format = format;
|
||||||
|
|
||||||
|
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
|
||||||
|
SRVDesc.Texture3D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels;
|
||||||
|
|
||||||
|
hr = d3dDevice->CreateShaderResourceView(tex,
|
||||||
|
&SRVDesc,
|
||||||
|
textureView
|
||||||
|
);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
tex->Release();
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texture)
|
||||||
|
{
|
||||||
|
*texture = tex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetDebugObjectName(tex, "DDSTextureLoader");
|
||||||
tex->Release();
|
tex->Release();
|
||||||
return hr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texture)
|
|
||||||
{
|
|
||||||
*texture = tex;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetDebugObjectName(tex, "DDSTextureLoader");
|
|
||||||
tex->Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
@ -1434,8 +1434,8 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((arraySize > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) ||
|
else if ((arraySize > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) ||
|
||||||
(width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION) ||
|
(width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION) ||
|
||||||
(height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION))
|
(height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION))
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
||||||
}
|
}
|
||||||
@ -1682,7 +1682,7 @@ namespace
|
|||||||
_In_opt_ ID3D11Resource** texture,
|
_In_opt_ ID3D11Resource** texture,
|
||||||
_In_opt_ ID3D11ShaderResourceView** textureView) noexcept
|
_In_opt_ ID3D11ShaderResourceView** textureView) noexcept
|
||||||
{
|
{
|
||||||
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||||
if (texture || textureView)
|
if (texture || textureView)
|
||||||
{
|
{
|
||||||
CHAR strFileA[MAX_PATH];
|
CHAR strFileA[MAX_PATH];
|
||||||
@ -1724,11 +1724,11 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(fileName);
|
UNREFERENCED_PARAMETER(fileName);
|
||||||
UNREFERENCED_PARAMETER(texture);
|
UNREFERENCED_PARAMETER(texture);
|
||||||
UNREFERENCED_PARAMETER(textureView);
|
UNREFERENCED_PARAMETER(textureView);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
@ -30,11 +30,11 @@ namespace DirectX
|
|||||||
#define DDS_ALPHA_MODE_DEFINED
|
#define DDS_ALPHA_MODE_DEFINED
|
||||||
enum DDS_ALPHA_MODE : uint32_t
|
enum DDS_ALPHA_MODE : uint32_t
|
||||||
{
|
{
|
||||||
DDS_ALPHA_MODE_UNKNOWN = 0,
|
DDS_ALPHA_MODE_UNKNOWN = 0,
|
||||||
DDS_ALPHA_MODE_STRAIGHT = 1,
|
DDS_ALPHA_MODE_STRAIGHT = 1,
|
||||||
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
||||||
DDS_ALPHA_MODE_OPAQUE = 3,
|
DDS_ALPHA_MODE_OPAQUE = 3,
|
||||||
DDS_ALPHA_MODE_CUSTOM = 4,
|
DDS_ALPHA_MODE_CUSTOM = 4,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ using namespace DirectX;
|
|||||||
// Macros
|
// Macros
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#ifndef MAKEFOURCC
|
#ifndef MAKEFOURCC
|
||||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||||
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
||||||
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
||||||
#endif /* defined(MAKEFOURCC) */
|
#endif /* defined(MAKEFOURCC) */
|
||||||
@ -168,12 +168,12 @@ namespace
|
|||||||
template<UINT TNameLength>
|
template<UINT TNameLength>
|
||||||
inline void SetDebugObjectName(_In_ ID3D12DeviceChild* resource, _In_z_ const wchar_t(&name)[TNameLength]) noexcept
|
inline void SetDebugObjectName(_In_ ID3D12DeviceChild* resource, _In_z_ const wchar_t(&name)[TNameLength]) noexcept
|
||||||
{
|
{
|
||||||
#if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
#if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||||
resource->SetName(name);
|
resource->SetName(name);
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(resource);
|
UNREFERENCED_PARAMETER(resource);
|
||||||
UNREFERENCED_PARAMETER(name);
|
UNREFERENCED_PARAMETER(name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t CountMips(uint32_t width, uint32_t height) noexcept
|
inline uint32_t CountMips(uint32_t width, uint32_t height) noexcept
|
||||||
@ -274,8 +274,8 @@ namespace
|
|||||||
|
|
||||||
*bitSize = 0;
|
*bitSize = 0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// open the file
|
// open the file
|
||||||
ScopedHandle hFile(safe_handle(CreateFile2(fileName,
|
ScopedHandle hFile(safe_handle(CreateFile2(fileName,
|
||||||
GENERIC_READ,
|
GENERIC_READ,
|
||||||
FILE_SHARE_READ,
|
FILE_SHARE_READ,
|
||||||
@ -334,7 +334,7 @@ namespace
|
|||||||
|
|
||||||
size_t len = fileInfo.EndOfFile.LowPart;
|
size_t len = fileInfo.EndOfFile.LowPart;
|
||||||
|
|
||||||
#else // !WIN32
|
#else // !WIN32
|
||||||
std::ifstream inFile(std::filesystem::path(fileName), std::ios::in | std::ios::binary | std::ios::ate);
|
std::ifstream inFile(std::filesystem::path(fileName), std::ios::in | std::ios::binary | std::ios::ate);
|
||||||
if (!inFile)
|
if (!inFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
@ -358,17 +358,17 @@ namespace
|
|||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
inFile.read(reinterpret_cast<char*>(ddsData.get()), fileLen);
|
inFile.read(reinterpret_cast<char*>(ddsData.get()), fileLen);
|
||||||
if (!inFile)
|
if (!inFile)
|
||||||
{
|
{
|
||||||
ddsData.reset();
|
ddsData.reset();
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
inFile.close();
|
inFile.close();
|
||||||
|
|
||||||
size_t len = fileLen;
|
size_t len = fileLen;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// DDS files always start with the same magic number ("DDS ")
|
// DDS files always start with the same magic number ("DDS ")
|
||||||
auto const dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData.get());
|
auto const dwMagicNumber = *reinterpret_cast<const uint32_t*>(ddsData.get());
|
||||||
@ -690,13 +690,13 @@ namespace
|
|||||||
numBytes = rowBytes * height;
|
numBytes = rowBytes * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
||||||
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
||||||
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
||||||
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
||||||
#else
|
#else
|
||||||
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (outNumBytes)
|
if (outNumBytes)
|
||||||
{
|
{
|
||||||
@ -716,7 +716,7 @@ namespace
|
|||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#define ISBITMASK( r,g,b,a ) ( ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a )
|
#define ISBITMASK( r,g,b,a ) ( ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a )
|
||||||
|
|
||||||
DXGI_FORMAT GetDXGIFormat(const DDS_PIXELFORMAT& ddpf) noexcept
|
DXGI_FORMAT GetDXGIFormat(const DDS_PIXELFORMAT& ddpf) noexcept
|
||||||
{
|
{
|
||||||
@ -983,10 +983,10 @@ namespace
|
|||||||
return DXGI_FORMAT_UNKNOWN;
|
return DXGI_FORMAT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef ISBITMASK
|
#undef ISBITMASK
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT format) noexcept
|
DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT format) noexcept
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
@ -1405,8 +1405,8 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((arraySize > D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) ||
|
else if ((arraySize > D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) ||
|
||||||
(width > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION) ||
|
(width > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION) ||
|
||||||
(height > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION))
|
(height > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION))
|
||||||
{
|
{
|
||||||
return HRESULT_E_NOT_SUPPORTED;
|
return HRESULT_E_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
@ -1443,7 +1443,7 @@ namespace
|
|||||||
|
|
||||||
// Create the texture
|
// Create the texture
|
||||||
size_t numberOfResources = (resDim == D3D12_RESOURCE_DIMENSION_TEXTURE3D)
|
size_t numberOfResources = (resDim == D3D12_RESOURCE_DIMENSION_TEXTURE3D)
|
||||||
? 1 : arraySize;
|
? 1 : arraySize;
|
||||||
numberOfResources *= mipCount;
|
numberOfResources *= mipCount;
|
||||||
numberOfResources *= numberOfPlanes;
|
numberOfResources *= numberOfPlanes;
|
||||||
|
|
||||||
@ -1503,15 +1503,15 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
DDS_ALPHA_MODE GetAlphaMode( _In_ const DDS_HEADER* header ) noexcept
|
DDS_ALPHA_MODE GetAlphaMode(_In_ const DDS_HEADER* header) noexcept
|
||||||
{
|
{
|
||||||
if ( header->ddspf.flags & DDS_FOURCC )
|
if (header->ddspf.flags & DDS_FOURCC)
|
||||||
{
|
{
|
||||||
if ( MAKEFOURCC( 'D', 'X', '1', '0' ) == header->ddspf.fourCC )
|
if (MAKEFOURCC('D', 'X', '1', '0') == header->ddspf.fourCC)
|
||||||
{
|
{
|
||||||
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(reinterpret_cast<const uint8_t*>(header) + sizeof(DDS_HEADER));
|
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(reinterpret_cast<const uint8_t*>(header) + sizeof(DDS_HEADER));
|
||||||
auto const mode = static_cast<DDS_ALPHA_MODE>( d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK );
|
auto const mode = static_cast<DDS_ALPHA_MODE>(d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK);
|
||||||
switch( mode )
|
switch (mode)
|
||||||
{
|
{
|
||||||
case DDS_ALPHA_MODE_STRAIGHT:
|
case DDS_ALPHA_MODE_STRAIGHT:
|
||||||
case DDS_ALPHA_MODE_PREMULTIPLIED:
|
case DDS_ALPHA_MODE_PREMULTIPLIED:
|
||||||
@ -1524,8 +1524,8 @@ namespace
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( ( MAKEFOURCC( 'D', 'X', 'T', '2' ) == header->ddspf.fourCC )
|
else if ((MAKEFOURCC('D', 'X', 'T', '2') == header->ddspf.fourCC)
|
||||||
|| ( MAKEFOURCC( 'D', 'X', 'T', '4' ) == header->ddspf.fourCC ) )
|
|| (MAKEFOURCC('D', 'X', 'T', '4') == header->ddspf.fourCC))
|
||||||
{
|
{
|
||||||
return DDS_ALPHA_MODE_PREMULTIPLIED;
|
return DDS_ALPHA_MODE_PREMULTIPLIED;
|
||||||
}
|
}
|
||||||
@ -1539,7 +1539,7 @@ namespace
|
|||||||
_In_z_ const wchar_t* fileName,
|
_In_z_ const wchar_t* fileName,
|
||||||
_In_ ID3D12Resource** texture) noexcept
|
_In_ ID3D12Resource** texture) noexcept
|
||||||
{
|
{
|
||||||
#if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
#if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||||
if (texture && *texture)
|
if (texture && *texture)
|
||||||
{
|
{
|
||||||
const wchar_t* pstrName = wcsrchr(fileName, '\\');
|
const wchar_t* pstrName = wcsrchr(fileName, '\\');
|
||||||
@ -1554,10 +1554,10 @@ namespace
|
|||||||
|
|
||||||
(*texture)->SetName(pstrName);
|
(*texture)->SetName(pstrName);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(fileName);
|
UNREFERENCED_PARAMETER(fileName);
|
||||||
UNREFERENCED_PARAMETER(texture);
|
UNREFERENCED_PARAMETER(texture);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
@ -37,11 +37,11 @@ namespace DirectX
|
|||||||
#define DDS_ALPHA_MODE_DEFINED
|
#define DDS_ALPHA_MODE_DEFINED
|
||||||
enum DDS_ALPHA_MODE : uint32_t
|
enum DDS_ALPHA_MODE : uint32_t
|
||||||
{
|
{
|
||||||
DDS_ALPHA_MODE_UNKNOWN = 0,
|
DDS_ALPHA_MODE_UNKNOWN = 0,
|
||||||
DDS_ALPHA_MODE_STRAIGHT = 1,
|
DDS_ALPHA_MODE_STRAIGHT = 1,
|
||||||
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
||||||
DDS_ALPHA_MODE_OPAQUE = 3,
|
DDS_ALPHA_MODE_OPAQUE = 3,
|
||||||
DDS_ALPHA_MODE_CUSTOM = 4,
|
DDS_ALPHA_MODE_CUSTOM = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -51,9 +51,9 @@ namespace DirectX
|
|||||||
|
|
||||||
enum DDS_LOADER_FLAGS : uint32_t
|
enum DDS_LOADER_FLAGS : uint32_t
|
||||||
{
|
{
|
||||||
DDS_LOADER_DEFAULT = 0,
|
DDS_LOADER_DEFAULT = 0,
|
||||||
DDS_LOADER_FORCE_SRGB = 0x1,
|
DDS_LOADER_FORCE_SRGB = 0x1,
|
||||||
DDS_LOADER_MIP_RESERVE = 0x8,
|
DDS_LOADER_MIP_RESERVE = 0x8,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
|
@ -47,7 +47,7 @@ using Microsoft::WRL::ComPtr;
|
|||||||
// Macros
|
// Macros
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#ifndef MAKEFOURCC
|
#ifndef MAKEFOURCC
|
||||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||||
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
||||||
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
||||||
#endif /* defined(MAKEFOURCC) */
|
#endif /* defined(MAKEFOURCC) */
|
||||||
@ -199,13 +199,13 @@ namespace
|
|||||||
*bitSize = 0;
|
*bitSize = 0;
|
||||||
|
|
||||||
// open the file
|
// open the file
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||||
ScopedHandle hFile(safe_handle(CreateFile2(fileName,
|
ScopedHandle hFile(safe_handle(CreateFile2(fileName,
|
||||||
GENERIC_READ,
|
GENERIC_READ,
|
||||||
FILE_SHARE_READ,
|
FILE_SHARE_READ,
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
nullptr)));
|
nullptr)));
|
||||||
#else
|
#else
|
||||||
ScopedHandle hFile(safe_handle(CreateFileW(fileName,
|
ScopedHandle hFile(safe_handle(CreateFileW(fileName,
|
||||||
GENERIC_READ,
|
GENERIC_READ,
|
||||||
FILE_SHARE_READ,
|
FILE_SHARE_READ,
|
||||||
@ -213,7 +213,7 @@ namespace
|
|||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
nullptr)));
|
nullptr)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!hFile)
|
if (!hFile)
|
||||||
{
|
{
|
||||||
@ -338,9 +338,9 @@ namespace
|
|||||||
case D3DFMT_INDEX32:
|
case D3DFMT_INDEX32:
|
||||||
case D3DFMT_G16R16F:
|
case D3DFMT_G16R16F:
|
||||||
case D3DFMT_R32F:
|
case D3DFMT_R32F:
|
||||||
#if !defined(D3D_DISABLE_9EX)
|
#if !defined(D3D_DISABLE_9EX)
|
||||||
case D3DFMT_D32_LOCKABLE:
|
case D3DFMT_D32_LOCKABLE:
|
||||||
#endif
|
#endif
|
||||||
return 32;
|
return 32;
|
||||||
|
|
||||||
case D3DFMT_R8G8B8:
|
case D3DFMT_R8G8B8:
|
||||||
@ -383,9 +383,9 @@ namespace
|
|||||||
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directshow/htm/directxvideoaccelerationdxvavideosubtypes.asp
|
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directshow/htm/directxvideoaccelerationdxvavideosubtypes.asp
|
||||||
case MAKEFOURCC('A', 'I', '4', '4'):
|
case MAKEFOURCC('A', 'I', '4', '4'):
|
||||||
case MAKEFOURCC('I', 'A', '4', '4'):
|
case MAKEFOURCC('I', 'A', '4', '4'):
|
||||||
#if !defined(D3D_DISABLE_9EX)
|
#if !defined(D3D_DISABLE_9EX)
|
||||||
case D3DFMT_S8_LOCKABLE:
|
case D3DFMT_S8_LOCKABLE:
|
||||||
#endif
|
#endif
|
||||||
return 8;
|
return 8;
|
||||||
|
|
||||||
case D3DFMT_DXT1:
|
case D3DFMT_DXT1:
|
||||||
@ -394,10 +394,10 @@ namespace
|
|||||||
case MAKEFOURCC('Y', 'V', '1', '2'):
|
case MAKEFOURCC('Y', 'V', '1', '2'):
|
||||||
return 12;
|
return 12;
|
||||||
|
|
||||||
#if !defined(D3D_DISABLE_9EX)
|
#if !defined(D3D_DISABLE_9EX)
|
||||||
case D3DFMT_A1:
|
case D3DFMT_A1:
|
||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
@ -483,13 +483,13 @@ namespace
|
|||||||
numBytes = rowBytes * height;
|
numBytes = rowBytes * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
||||||
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
||||||
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
||||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||||
#else
|
#else
|
||||||
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (outNumBytes)
|
if (outNumBytes)
|
||||||
{
|
{
|
||||||
@ -509,7 +509,7 @@ namespace
|
|||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#define ISBITMASK( r,g,b,a ) ( ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a )
|
#define ISBITMASK( r,g,b,a ) ( ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a )
|
||||||
|
|
||||||
D3DFORMAT GetD3D9Format(const DDS_PIXELFORMAT& ddpf) noexcept
|
D3DFORMAT GetD3D9Format(const DDS_PIXELFORMAT& ddpf) noexcept
|
||||||
{
|
{
|
||||||
@ -766,10 +766,10 @@ namespace
|
|||||||
return D3DFMT_UNKNOWN;
|
return D3DFMT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef ISBITMASK
|
#undef ISBITMASK
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
HRESULT CreateTextureFromDDS(
|
HRESULT CreateTextureFromDDS(
|
||||||
_In_ LPDIRECT3DDEVICE9 device,
|
_In_ LPDIRECT3DDEVICE9 device,
|
||||||
_In_ const DDS_HEADER* header,
|
_In_ const DDS_HEADER* header,
|
||||||
|
@ -84,9 +84,9 @@ namespace
|
|||||||
|
|
||||||
for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
|
for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
|
||||||
{
|
{
|
||||||
#ifdef COLOR_WEIGHTS
|
#ifdef COLOR_WEIGHTS
|
||||||
if (pPoints[iPoint].a > 0.0f)
|
if (pPoints[iPoint].a > 0.0f)
|
||||||
#endif // COLOR_WEIGHTS
|
#endif // COLOR_WEIGHTS
|
||||||
{
|
{
|
||||||
if (pPoints[iPoint].r < X.r)
|
if (pPoints[iPoint].r < X.r)
|
||||||
X.r = pPoints[iPoint].r;
|
X.r = pPoints[iPoint].r;
|
||||||
@ -144,7 +144,7 @@ namespace
|
|||||||
|
|
||||||
float f;
|
float f;
|
||||||
|
|
||||||
#ifdef COLOR_WEIGHTS
|
#ifdef COLOR_WEIGHTS
|
||||||
f = Pt.r + Pt.g + Pt.b;
|
f = Pt.r + Pt.g + Pt.b;
|
||||||
fDir[0] += pPoints[iPoint].a * f * f;
|
fDir[0] += pPoints[iPoint].a * f * f;
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ namespace
|
|||||||
|
|
||||||
f = Pt.r - Pt.g - Pt.b;
|
f = Pt.r - Pt.g - Pt.b;
|
||||||
fDir[3] += pPoints[iPoint].a * f * f;
|
fDir[3] += pPoints[iPoint].a * f * f;
|
||||||
#else
|
#else
|
||||||
f = Pt.r + Pt.g + Pt.b;
|
f = Pt.r + Pt.g + Pt.b;
|
||||||
fDir[0] += f * f;
|
fDir[0] += f * f;
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ namespace
|
|||||||
|
|
||||||
f = Pt.r - Pt.g - Pt.b;
|
f = Pt.r - Pt.g - Pt.b;
|
||||||
fDir[3] += f * f;
|
fDir[3] += f * f;
|
||||||
#endif // COLOR_WEIGHTS
|
#endif // COLOR_WEIGHTS
|
||||||
}
|
}
|
||||||
|
|
||||||
float fDirMax = fDir[0];
|
float fDirMax = fDir[0];
|
||||||
@ -264,13 +264,13 @@ namespace
|
|||||||
Diff.b = pSteps[iStep].b - pPoints[iPoint].b;
|
Diff.b = pSteps[iStep].b - pPoints[iPoint].b;
|
||||||
Diff.a = 0.0f;
|
Diff.a = 0.0f;
|
||||||
|
|
||||||
#ifdef COLOR_WEIGHTS
|
#ifdef COLOR_WEIGHTS
|
||||||
const float fC = pC[iStep] * pPoints[iPoint].a * (1.0f / 8.0f);
|
const float fC = pC[iStep] * pPoints[iPoint].a * (1.0f / 8.0f);
|
||||||
const float fD = pD[iStep] * pPoints[iPoint].a * (1.0f / 8.0f);
|
const float fD = pD[iStep] * pPoints[iPoint].a * (1.0f / 8.0f);
|
||||||
#else
|
#else
|
||||||
const float fC = pC[iStep] * (1.0f / 8.0f);
|
const float fC = pC[iStep] * (1.0f / 8.0f);
|
||||||
const float fD = pD[iStep] * (1.0f / 8.0f);
|
const float fD = pD[iStep] * (1.0f / 8.0f);
|
||||||
#endif // COLOR_WEIGHTS
|
#endif // COLOR_WEIGHTS
|
||||||
|
|
||||||
d2X += fC * pC[iStep];
|
d2X += fC * pC[iStep];
|
||||||
dX.r += fC * Diff.r;
|
dX.r += fC * Diff.r;
|
||||||
@ -434,11 +434,11 @@ namespace
|
|||||||
Color[i].g = static_cast<float>(static_cast<int32_t>(Clr.g * 63.0f + 0.5f)) * (1.0f / 63.0f);
|
Color[i].g = static_cast<float>(static_cast<int32_t>(Clr.g * 63.0f + 0.5f)) * (1.0f / 63.0f);
|
||||||
Color[i].b = static_cast<float>(static_cast<int32_t>(Clr.b * 31.0f + 0.5f)) * (1.0f / 31.0f);
|
Color[i].b = static_cast<float>(static_cast<int32_t>(Clr.b * 31.0f + 0.5f)) * (1.0f / 31.0f);
|
||||||
|
|
||||||
#ifdef COLOR_WEIGHTS
|
#ifdef COLOR_WEIGHTS
|
||||||
Color[i].a = pColor[i].a;
|
Color[i].a = pColor[i].a;
|
||||||
#else
|
#else
|
||||||
Color[i].a = 1.0f;
|
Color[i].a = 1.0f;
|
||||||
#endif // COLOR_WEIGHTS
|
#endif // COLOR_WEIGHTS
|
||||||
|
|
||||||
if (flags & BC_FLAGS_DITHER_RGB)
|
if (flags & BC_FLAGS_DITHER_RGB)
|
||||||
{
|
{
|
||||||
@ -688,7 +688,7 @@ namespace
|
|||||||
#ifdef COLOR_WEIGHTS
|
#ifdef COLOR_WEIGHTS
|
||||||
void EncodeSolidBC1(_Out_ D3DX_BC1 *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA *pColor)
|
void EncodeSolidBC1(_Out_ D3DX_BC1 *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA *pColor)
|
||||||
{
|
{
|
||||||
#ifdef COLOR_AVG_0WEIGHTS
|
#ifdef COLOR_AVG_0WEIGHTS
|
||||||
// Compute avg color
|
// Compute avg color
|
||||||
HDRColorA Color;
|
HDRColorA Color;
|
||||||
Color.r = pColor[0].r;
|
Color.r = pColor[0].r;
|
||||||
@ -707,9 +707,9 @@ namespace
|
|||||||
Color.b *= 1.0f / 16.0f;
|
Color.b *= 1.0f / 16.0f;
|
||||||
|
|
||||||
const uint16_t wColor = Encode565(&Color);
|
const uint16_t wColor = Encode565(&Color);
|
||||||
#else
|
#else
|
||||||
const uint16_t wColor = 0x0000;
|
const uint16_t wColor = 0x0000;
|
||||||
#endif // COLOR_AVG_0WEIGHTS
|
#endif // COLOR_AVG_0WEIGHTS
|
||||||
|
|
||||||
// Encode solid block
|
// Encode solid block
|
||||||
pBC->rgb[0] = wColor;
|
pBC->rgb[0] = wColor;
|
||||||
@ -814,7 +814,7 @@ void DirectX::D3DXDecodeBC2(XMVECTOR *pColor, const uint8_t *pBC) noexcept
|
|||||||
|
|
||||||
for (size_t i = 0; i < 8; ++i, dw >>= 4)
|
for (size_t i = 0; i < 8; ++i, dw >>= 4)
|
||||||
{
|
{
|
||||||
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
||||||
pColor[i] = XMVectorSetW(pColor[i], static_cast<float>(dw & 0xf) * (1.0f / 15.0f));
|
pColor[i] = XMVectorSetW(pColor[i], static_cast<float>(dw & 0xf) * (1.0f / 15.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
546
DirectXTex/BC.h
546
DirectXTex/BC.h
@ -27,141 +27,151 @@ namespace DirectX
|
|||||||
// Constants
|
// Constants
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
enum BC_FLAGS : uint32_t
|
enum BC_FLAGS : uint32_t
|
||||||
{
|
|
||||||
BC_FLAGS_NONE = 0x0,
|
|
||||||
BC_FLAGS_DITHER_RGB = 0x10000, // Enables dithering for RGB colors for BC1-3
|
|
||||||
BC_FLAGS_DITHER_A = 0x20000, // Enables dithering for Alpha channel for BC1-3
|
|
||||||
BC_FLAGS_UNIFORM = 0x40000, // By default, uses perceptual weighting for BC1-3; this flag makes it a uniform weighting
|
|
||||||
BC_FLAGS_USE_3SUBSETS = 0x80000, // By default, BC7 skips mode 0 & 2; this flag adds those modes back
|
|
||||||
BC_FLAGS_FORCE_BC7_MODE6 = 0x100000, // BC7 should only use mode 6; skip other modes
|
|
||||||
};
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
|
||||||
// Structures
|
|
||||||
//-------------------------------------------------------------------------------------
|
|
||||||
class LDRColorA;
|
|
||||||
|
|
||||||
class HDRColorA
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
float r, g, b, a;
|
|
||||||
|
|
||||||
public:
|
|
||||||
HDRColorA() = default;
|
|
||||||
HDRColorA(float _r, float _g, float _b, float _a) noexcept : r(_r), g(_g), b(_b), a(_a) {}
|
|
||||||
HDRColorA(const HDRColorA& c) noexcept : r(c.r), g(c.g), b(c.b), a(c.a) {}
|
|
||||||
|
|
||||||
// binary operators
|
|
||||||
HDRColorA operator + (const HDRColorA& c) const noexcept
|
|
||||||
{
|
{
|
||||||
return HDRColorA(r + c.r, g + c.g, b + c.b, a + c.a);
|
BC_FLAGS_NONE = 0x0,
|
||||||
}
|
|
||||||
|
|
||||||
HDRColorA operator - (const HDRColorA& c) const noexcept
|
BC_FLAGS_DITHER_RGB = 0x10000,
|
||||||
|
// Enables dithering for RGB colors for BC1-3
|
||||||
|
|
||||||
|
BC_FLAGS_DITHER_A = 0x20000,
|
||||||
|
// Enables dithering for Alpha channel for BC1-3
|
||||||
|
|
||||||
|
BC_FLAGS_UNIFORM = 0x40000,
|
||||||
|
// By default, uses perceptual weighting for BC1-3; this flag makes it a uniform weighting
|
||||||
|
|
||||||
|
BC_FLAGS_USE_3SUBSETS = 0x80000,
|
||||||
|
// By default, BC7 skips mode 0 & 2; this flag adds those modes back
|
||||||
|
|
||||||
|
BC_FLAGS_FORCE_BC7_MODE6 = 0x100000,
|
||||||
|
// BC7 should only use mode 6; skip other modes
|
||||||
|
};
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
// Structures
|
||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
class LDRColorA;
|
||||||
|
|
||||||
|
class HDRColorA
|
||||||
{
|
{
|
||||||
return HDRColorA(r - c.r, g - c.g, b - c.b, a - c.a);
|
public:
|
||||||
}
|
float r, g, b, a;
|
||||||
|
|
||||||
HDRColorA operator * (float f) const noexcept
|
public:
|
||||||
|
HDRColorA() = default;
|
||||||
|
HDRColorA(float _r, float _g, float _b, float _a) noexcept : r(_r), g(_g), b(_b), a(_a) {}
|
||||||
|
HDRColorA(const HDRColorA& c) noexcept : r(c.r), g(c.g), b(c.b), a(c.a) {}
|
||||||
|
|
||||||
|
// binary operators
|
||||||
|
HDRColorA operator + (const HDRColorA& c) const noexcept
|
||||||
|
{
|
||||||
|
return HDRColorA(r + c.r, g + c.g, b + c.b, a + c.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
HDRColorA operator - (const HDRColorA& c) const noexcept
|
||||||
|
{
|
||||||
|
return HDRColorA(r - c.r, g - c.g, b - c.b, a - c.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
HDRColorA operator * (float f) const noexcept
|
||||||
|
{
|
||||||
|
return HDRColorA(r * f, g * f, b * f, a * f);
|
||||||
|
}
|
||||||
|
|
||||||
|
HDRColorA operator / (float f) const noexcept
|
||||||
|
{
|
||||||
|
const float fInv = 1.0f / f;
|
||||||
|
return HDRColorA(r * fInv, g * fInv, b * fInv, a * fInv);
|
||||||
|
}
|
||||||
|
|
||||||
|
float operator * (const HDRColorA& c) const noexcept
|
||||||
|
{
|
||||||
|
return r * c.r + g * c.g + b * c.b + a * c.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignment operators
|
||||||
|
HDRColorA& operator += (const HDRColorA& c) noexcept
|
||||||
|
{
|
||||||
|
r += c.r;
|
||||||
|
g += c.g;
|
||||||
|
b += c.b;
|
||||||
|
a += c.a;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
HDRColorA& operator -= (const HDRColorA& c) noexcept
|
||||||
|
{
|
||||||
|
r -= c.r;
|
||||||
|
g -= c.g;
|
||||||
|
b -= c.b;
|
||||||
|
a -= c.a;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
HDRColorA& operator *= (float f) noexcept
|
||||||
|
{
|
||||||
|
r *= f;
|
||||||
|
g *= f;
|
||||||
|
b *= f;
|
||||||
|
a *= f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
HDRColorA& operator /= (float f) noexcept
|
||||||
|
{
|
||||||
|
const float fInv = 1.0f / f;
|
||||||
|
r *= fInv;
|
||||||
|
g *= fInv;
|
||||||
|
b *= fInv;
|
||||||
|
a *= fInv;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
HDRColorA& Clamp(_In_ float fMin, _In_ float fMax) noexcept
|
||||||
|
{
|
||||||
|
r = std::min<float>(fMax, std::max<float>(fMin, r));
|
||||||
|
g = std::min<float>(fMax, std::max<float>(fMin, g));
|
||||||
|
b = std::min<float>(fMax, std::max<float>(fMin, b));
|
||||||
|
a = std::min<float>(fMax, std::max<float>(fMin, a));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
HDRColorA(const LDRColorA& c) noexcept;
|
||||||
|
HDRColorA& operator = (const LDRColorA& c) noexcept;
|
||||||
|
LDRColorA ToLDRColorA() const noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline HDRColorA* HDRColorALerp(_Out_ HDRColorA *pOut, _In_ const HDRColorA *pC1, _In_ const HDRColorA *pC2, _In_ float s) noexcept
|
||||||
{
|
{
|
||||||
return HDRColorA(r * f, g * f, b * f, a * f);
|
pOut->r = pC1->r + s * (pC2->r - pC1->r);
|
||||||
|
pOut->g = pC1->g + s * (pC2->g - pC1->g);
|
||||||
|
pOut->b = pC1->b + s * (pC2->b - pC1->b);
|
||||||
|
pOut->a = pC1->a + s * (pC2->a - pC1->a);
|
||||||
|
return pOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
HDRColorA operator / (float f) const noexcept
|
|
||||||
{
|
|
||||||
const float fInv = 1.0f / f;
|
|
||||||
return HDRColorA(r * fInv, g * fInv, b * fInv, a * fInv);
|
|
||||||
}
|
|
||||||
|
|
||||||
float operator * (const HDRColorA& c) const noexcept
|
|
||||||
{
|
|
||||||
return r * c.r + g * c.g + b * c.b + a * c.a;
|
|
||||||
}
|
|
||||||
|
|
||||||
// assignment operators
|
|
||||||
HDRColorA& operator += (const HDRColorA& c) noexcept
|
|
||||||
{
|
|
||||||
r += c.r;
|
|
||||||
g += c.g;
|
|
||||||
b += c.b;
|
|
||||||
a += c.a;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
HDRColorA& operator -= (const HDRColorA& c) noexcept
|
|
||||||
{
|
|
||||||
r -= c.r;
|
|
||||||
g -= c.g;
|
|
||||||
b -= c.b;
|
|
||||||
a -= c.a;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
HDRColorA& operator *= (float f) noexcept
|
|
||||||
{
|
|
||||||
r *= f;
|
|
||||||
g *= f;
|
|
||||||
b *= f;
|
|
||||||
a *= f;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
HDRColorA& operator /= (float f) noexcept
|
|
||||||
{
|
|
||||||
const float fInv = 1.0f / f;
|
|
||||||
r *= fInv;
|
|
||||||
g *= fInv;
|
|
||||||
b *= fInv;
|
|
||||||
a *= fInv;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
HDRColorA& Clamp(_In_ float fMin, _In_ float fMax) noexcept
|
|
||||||
{
|
|
||||||
r = std::min<float>(fMax, std::max<float>(fMin, r));
|
|
||||||
g = std::min<float>(fMax, std::max<float>(fMin, g));
|
|
||||||
b = std::min<float>(fMax, std::max<float>(fMin, b));
|
|
||||||
a = std::min<float>(fMax, std::max<float>(fMin, a));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
HDRColorA(const LDRColorA& c) noexcept;
|
|
||||||
HDRColorA& operator = (const LDRColorA& c) noexcept;
|
|
||||||
LDRColorA ToLDRColorA() const noexcept;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline HDRColorA* HDRColorALerp(_Out_ HDRColorA *pOut, _In_ const HDRColorA *pC1, _In_ const HDRColorA *pC2, _In_ float s) noexcept
|
|
||||||
{
|
|
||||||
pOut->r = pC1->r + s * (pC2->r - pC1->r);
|
|
||||||
pOut->g = pC1->g + s * (pC2->g - pC1->g);
|
|
||||||
pOut->b = pC1->b + s * (pC2->b - pC1->b);
|
|
||||||
pOut->a = pC1->a + s * (pC2->a - pC1->a);
|
|
||||||
return pOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma pack(push,1)
|
#pragma pack(push,1)
|
||||||
// BC1/DXT1 compression (4 bits per texel)
|
// BC1/DXT1 compression (4 bits per texel)
|
||||||
struct D3DX_BC1
|
struct D3DX_BC1
|
||||||
{
|
{
|
||||||
uint16_t rgb[2]; // 565 colors
|
uint16_t rgb[2]; // 565 colors
|
||||||
uint32_t bitmap; // 2bpp rgb bitmap
|
uint32_t bitmap; // 2bpp rgb bitmap
|
||||||
};
|
};
|
||||||
|
|
||||||
// BC2/DXT2/3 compression (8 bits per texel)
|
// BC2/DXT2/3 compression (8 bits per texel)
|
||||||
struct D3DX_BC2
|
struct D3DX_BC2
|
||||||
{
|
{
|
||||||
uint32_t bitmap[2]; // 4bpp alpha bitmap
|
uint32_t bitmap[2]; // 4bpp alpha bitmap
|
||||||
D3DX_BC1 bc1; // BC1 rgb data
|
D3DX_BC1 bc1; // BC1 rgb data
|
||||||
};
|
};
|
||||||
|
|
||||||
// BC3/DXT4/5 compression (8 bits per texel)
|
// BC3/DXT4/5 compression (8 bits per texel)
|
||||||
struct D3DX_BC3
|
struct D3DX_BC3
|
||||||
{
|
{
|
||||||
uint8_t alpha[2]; // alpha values
|
uint8_t alpha[2]; // alpha values
|
||||||
uint8_t bitmap[6]; // 3bpp alpha bitmap
|
uint8_t bitmap[6]; // 3bpp alpha bitmap
|
||||||
D3DX_BC1 bc1; // BC1 rgb data
|
D3DX_BC1 bc1; // BC1 rgb data
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
@ -169,162 +179,162 @@ struct D3DX_BC3
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4127)
|
#pragma warning(disable : 4127)
|
||||||
template <bool bRange> void OptimizeAlpha(float *pX, float *pY, const float *pPoints, uint32_t cSteps) noexcept
|
template <bool bRange> void OptimizeAlpha(float *pX, float *pY, const float *pPoints, uint32_t cSteps) noexcept
|
||||||
{
|
|
||||||
static const float pC6[] = { 5.0f / 5.0f, 4.0f / 5.0f, 3.0f / 5.0f, 2.0f / 5.0f, 1.0f / 5.0f, 0.0f / 5.0f };
|
|
||||||
static const float pD6[] = { 0.0f / 5.0f, 1.0f / 5.0f, 2.0f / 5.0f, 3.0f / 5.0f, 4.0f / 5.0f, 5.0f / 5.0f };
|
|
||||||
static const float pC8[] = { 7.0f / 7.0f, 6.0f / 7.0f, 5.0f / 7.0f, 4.0f / 7.0f, 3.0f / 7.0f, 2.0f / 7.0f, 1.0f / 7.0f, 0.0f / 7.0f };
|
|
||||||
static const float pD8[] = { 0.0f / 7.0f, 1.0f / 7.0f, 2.0f / 7.0f, 3.0f / 7.0f, 4.0f / 7.0f, 5.0f / 7.0f, 6.0f / 7.0f, 7.0f / 7.0f };
|
|
||||||
|
|
||||||
const float *pC = (6 == cSteps) ? pC6 : pC8;
|
|
||||||
const float *pD = (6 == cSteps) ? pD6 : pD8;
|
|
||||||
|
|
||||||
constexpr float MAX_VALUE = 1.0f;
|
|
||||||
constexpr float MIN_VALUE = (bRange) ? -1.0f : 0.0f;
|
|
||||||
|
|
||||||
// Find Min and Max points, as starting point
|
|
||||||
float fX = MAX_VALUE;
|
|
||||||
float fY = MIN_VALUE;
|
|
||||||
|
|
||||||
if (8 == cSteps)
|
|
||||||
{
|
{
|
||||||
for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
|
static const float pC6[] = { 5.0f / 5.0f, 4.0f / 5.0f, 3.0f / 5.0f, 2.0f / 5.0f, 1.0f / 5.0f, 0.0f / 5.0f };
|
||||||
{
|
static const float pD6[] = { 0.0f / 5.0f, 1.0f / 5.0f, 2.0f / 5.0f, 3.0f / 5.0f, 4.0f / 5.0f, 5.0f / 5.0f };
|
||||||
if (pPoints[iPoint] < fX)
|
static const float pC8[] = { 7.0f / 7.0f, 6.0f / 7.0f, 5.0f / 7.0f, 4.0f / 7.0f, 3.0f / 7.0f, 2.0f / 7.0f, 1.0f / 7.0f, 0.0f / 7.0f };
|
||||||
fX = pPoints[iPoint];
|
static const float pD8[] = { 0.0f / 7.0f, 1.0f / 7.0f, 2.0f / 7.0f, 3.0f / 7.0f, 4.0f / 7.0f, 5.0f / 7.0f, 6.0f / 7.0f, 7.0f / 7.0f };
|
||||||
|
|
||||||
if (pPoints[iPoint] > fY)
|
const float *pC = (6 == cSteps) ? pC6 : pC8;
|
||||||
fY = pPoints[iPoint];
|
const float *pD = (6 == cSteps) ? pD6 : pD8;
|
||||||
|
|
||||||
|
constexpr float MAX_VALUE = 1.0f;
|
||||||
|
constexpr float MIN_VALUE = (bRange) ? -1.0f : 0.0f;
|
||||||
|
|
||||||
|
// Find Min and Max points, as starting point
|
||||||
|
float fX = MAX_VALUE;
|
||||||
|
float fY = MIN_VALUE;
|
||||||
|
|
||||||
|
if (8 == cSteps)
|
||||||
|
{
|
||||||
|
for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
|
||||||
|
{
|
||||||
|
if (pPoints[iPoint] < fX)
|
||||||
|
fX = pPoints[iPoint];
|
||||||
|
|
||||||
|
if (pPoints[iPoint] > fY)
|
||||||
|
fY = pPoints[iPoint];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
|
||||||
|
{
|
||||||
|
if (pPoints[iPoint] < fX && pPoints[iPoint] > MIN_VALUE)
|
||||||
|
fX = pPoints[iPoint];
|
||||||
|
|
||||||
|
if (pPoints[iPoint] > fY && pPoints[iPoint] < MAX_VALUE)
|
||||||
|
fY = pPoints[iPoint];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fX == fY)
|
||||||
|
{
|
||||||
|
fY = MAX_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use Newton's Method to find local minima of sum-of-squares error.
|
||||||
|
auto const fSteps = static_cast<float>(cSteps - 1);
|
||||||
|
|
||||||
|
for (size_t iIteration = 0; iIteration < 8; iIteration++)
|
||||||
|
{
|
||||||
|
if ((fY - fX) < (1.0f / 256.0f))
|
||||||
|
break;
|
||||||
|
|
||||||
|
float const fScale = fSteps / (fY - fX);
|
||||||
|
|
||||||
|
// Calculate new steps
|
||||||
|
float pSteps[8];
|
||||||
|
|
||||||
|
for (size_t iStep = 0; iStep < cSteps; iStep++)
|
||||||
|
pSteps[iStep] = pC[iStep] * fX + pD[iStep] * fY;
|
||||||
|
|
||||||
|
if (6 == cSteps)
|
||||||
|
{
|
||||||
|
pSteps[6] = MIN_VALUE;
|
||||||
|
pSteps[7] = MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Evaluate function, and derivatives
|
||||||
|
float dX = 0.0f;
|
||||||
|
float dY = 0.0f;
|
||||||
|
float d2X = 0.0f;
|
||||||
|
float d2Y = 0.0f;
|
||||||
|
|
||||||
|
for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
|
||||||
|
{
|
||||||
|
const float fDot = (pPoints[iPoint] - fX) * fScale;
|
||||||
|
|
||||||
|
uint32_t iStep;
|
||||||
|
if (fDot <= 0.0f)
|
||||||
|
{
|
||||||
|
// D3DX10 / D3DX11 didn't take into account the proper minimum value for the bRange (BC4S/BC5S) case
|
||||||
|
iStep = ((6 == cSteps) && (pPoints[iPoint] <= (fX + MIN_VALUE) * 0.5f)) ? 6u : 0u;
|
||||||
|
}
|
||||||
|
else if (fDot >= fSteps)
|
||||||
|
{
|
||||||
|
iStep = ((6 == cSteps) && (pPoints[iPoint] >= (fY + MAX_VALUE) * 0.5f)) ? 7u : (cSteps - 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iStep = uint32_t(fDot + 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iStep < cSteps)
|
||||||
|
{
|
||||||
|
// D3DX had this computation backwards (pPoints[iPoint] - pSteps[iStep])
|
||||||
|
// this fix improves RMS of the alpha component
|
||||||
|
const float fDiff = pSteps[iStep] - pPoints[iPoint];
|
||||||
|
|
||||||
|
dX += pC[iStep] * fDiff;
|
||||||
|
d2X += pC[iStep] * pC[iStep];
|
||||||
|
|
||||||
|
dY += pD[iStep] * fDiff;
|
||||||
|
d2Y += pD[iStep] * pD[iStep];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move endpoints
|
||||||
|
if (d2X > 0.0f)
|
||||||
|
fX -= dX / d2X;
|
||||||
|
|
||||||
|
if (d2Y > 0.0f)
|
||||||
|
fY -= dY / d2Y;
|
||||||
|
|
||||||
|
if (fX > fY)
|
||||||
|
{
|
||||||
|
const float f = fX; fX = fY; fY = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((dX * dX < (1.0f / 64.0f)) && (dY * dY < (1.0f / 64.0f)))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pX = (fX < MIN_VALUE) ? MIN_VALUE : (fX > MAX_VALUE) ? MAX_VALUE : fX;
|
||||||
|
*pY = (fY < MIN_VALUE) ? MIN_VALUE : (fY > MAX_VALUE) ? MAX_VALUE : fY;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
|
|
||||||
{
|
|
||||||
if (pPoints[iPoint] < fX && pPoints[iPoint] > MIN_VALUE)
|
|
||||||
fX = pPoints[iPoint];
|
|
||||||
|
|
||||||
if (pPoints[iPoint] > fY && pPoints[iPoint] < MAX_VALUE)
|
|
||||||
fY = pPoints[iPoint];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fX == fY)
|
|
||||||
{
|
|
||||||
fY = MAX_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use Newton's Method to find local minima of sum-of-squares error.
|
|
||||||
auto const fSteps = static_cast<float>(cSteps - 1);
|
|
||||||
|
|
||||||
for (size_t iIteration = 0; iIteration < 8; iIteration++)
|
|
||||||
{
|
|
||||||
if ((fY - fX) < (1.0f / 256.0f))
|
|
||||||
break;
|
|
||||||
|
|
||||||
float const fScale = fSteps / (fY - fX);
|
|
||||||
|
|
||||||
// Calculate new steps
|
|
||||||
float pSteps[8];
|
|
||||||
|
|
||||||
for (size_t iStep = 0; iStep < cSteps; iStep++)
|
|
||||||
pSteps[iStep] = pC[iStep] * fX + pD[iStep] * fY;
|
|
||||||
|
|
||||||
if (6 == cSteps)
|
|
||||||
{
|
|
||||||
pSteps[6] = MIN_VALUE;
|
|
||||||
pSteps[7] = MAX_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate function, and derivatives
|
|
||||||
float dX = 0.0f;
|
|
||||||
float dY = 0.0f;
|
|
||||||
float d2X = 0.0f;
|
|
||||||
float d2Y = 0.0f;
|
|
||||||
|
|
||||||
for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++)
|
|
||||||
{
|
|
||||||
const float fDot = (pPoints[iPoint] - fX) * fScale;
|
|
||||||
|
|
||||||
uint32_t iStep;
|
|
||||||
if (fDot <= 0.0f)
|
|
||||||
{
|
|
||||||
// D3DX10 / D3DX11 didn't take into account the proper minimum value for the bRange (BC4S/BC5S) case
|
|
||||||
iStep = ((6 == cSteps) && (pPoints[iPoint] <= (fX + MIN_VALUE) * 0.5f)) ? 6u : 0u;
|
|
||||||
}
|
|
||||||
else if (fDot >= fSteps)
|
|
||||||
{
|
|
||||||
iStep = ((6 == cSteps) && (pPoints[iPoint] >= (fY + MAX_VALUE) * 0.5f)) ? 7u : (cSteps - 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iStep = uint32_t(fDot + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iStep < cSteps)
|
|
||||||
{
|
|
||||||
// D3DX had this computation backwards (pPoints[iPoint] - pSteps[iStep])
|
|
||||||
// this fix improves RMS of the alpha component
|
|
||||||
const float fDiff = pSteps[iStep] - pPoints[iPoint];
|
|
||||||
|
|
||||||
dX += pC[iStep] * fDiff;
|
|
||||||
d2X += pC[iStep] * pC[iStep];
|
|
||||||
|
|
||||||
dY += pD[iStep] * fDiff;
|
|
||||||
d2Y += pD[iStep] * pD[iStep];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move endpoints
|
|
||||||
if (d2X > 0.0f)
|
|
||||||
fX -= dX / d2X;
|
|
||||||
|
|
||||||
if (d2Y > 0.0f)
|
|
||||||
fY -= dY / d2Y;
|
|
||||||
|
|
||||||
if (fX > fY)
|
|
||||||
{
|
|
||||||
const float f = fX; fX = fY; fY = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((dX * dX < (1.0f / 64.0f)) && (dY * dY < (1.0f / 64.0f)))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
*pX = (fX < MIN_VALUE) ? MIN_VALUE : (fX > MAX_VALUE) ? MAX_VALUE : fX;
|
|
||||||
*pY = (fY < MIN_VALUE) ? MIN_VALUE : (fY > MAX_VALUE) ? MAX_VALUE : fY;
|
|
||||||
}
|
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
// Functions
|
// Functions
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
typedef void (*BC_DECODE)(XMVECTOR *pColor, const uint8_t *pBC);
|
typedef void (*BC_DECODE)(XMVECTOR *pColor, const uint8_t *pBC);
|
||||||
typedef void (*BC_ENCODE)(uint8_t *pDXT, const XMVECTOR *pColor, uint32_t flags);
|
typedef void (*BC_ENCODE)(uint8_t *pDXT, const XMVECTOR *pColor, uint32_t flags);
|
||||||
|
|
||||||
void D3DXDecodeBC1(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC1(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC) noexcept;
|
||||||
void D3DXDecodeBC2(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC2(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
||||||
void D3DXDecodeBC3(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC3(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
||||||
void D3DXDecodeBC4U(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC4U(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC) noexcept;
|
||||||
void D3DXDecodeBC4S(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC4S(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC) noexcept;
|
||||||
void D3DXDecodeBC5U(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC5U(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
||||||
void D3DXDecodeBC5S(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC5S(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
||||||
void D3DXDecodeBC6HU(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC6HU(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
||||||
void D3DXDecodeBC6HS(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC6HS(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
||||||
void D3DXDecodeBC7(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
void D3DXDecodeBC7(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept;
|
||||||
|
|
||||||
void D3DXEncodeBC1(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ float threshold, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC1(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ float threshold, _In_ uint32_t flags) noexcept;
|
||||||
// BC1 requires one additional parameter, so it doesn't match signature of BC_ENCODE above
|
// BC1 requires one additional parameter, so it doesn't match signature of BC_ENCODE above
|
||||||
|
|
||||||
void D3DXEncodeBC2(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC2(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
||||||
void D3DXEncodeBC3(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC3(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
||||||
void D3DXEncodeBC4U(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC4U(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
||||||
void D3DXEncodeBC4S(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC4S(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
||||||
void D3DXEncodeBC5U(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC5U(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
||||||
void D3DXEncodeBC5S(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC5S(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
||||||
void D3DXEncodeBC6HU(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC6HU(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
||||||
void D3DXEncodeBC6HS(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC6HS(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
||||||
void D3DXEncodeBC7(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
void D3DXEncodeBC7(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -395,7 +395,7 @@ void DirectX::D3DXDecodeBC4U(XMVECTOR *pColor, const uint8_t *pBC) noexcept
|
|||||||
|
|
||||||
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
||||||
{
|
{
|
||||||
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
||||||
pColor[i] = XMVectorSet(pBC4->R(i), 0, 0, 1.0f);
|
pColor[i] = XMVectorSet(pBC4->R(i), 0, 0, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -410,7 +410,7 @@ void DirectX::D3DXDecodeBC4S(XMVECTOR *pColor, const uint8_t *pBC) noexcept
|
|||||||
|
|
||||||
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
||||||
{
|
{
|
||||||
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
||||||
pColor[i] = XMVectorSet(pBC4->R(i), 0, 0, 1.0f);
|
pColor[i] = XMVectorSet(pBC4->R(i), 0, 0, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,7 +472,7 @@ void DirectX::D3DXDecodeBC5U(XMVECTOR *pColor, const uint8_t *pBC) noexcept
|
|||||||
|
|
||||||
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
||||||
{
|
{
|
||||||
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
||||||
pColor[i] = XMVectorSet(pBCR->R(i), pBCG->R(i), 0, 1.0f);
|
pColor[i] = XMVectorSet(pBCR->R(i), pBCG->R(i), 0, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -488,7 +488,7 @@ void DirectX::D3DXDecodeBC5S(XMVECTOR *pColor, const uint8_t *pBC) noexcept
|
|||||||
|
|
||||||
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
||||||
{
|
{
|
||||||
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
|
||||||
pColor[i] = XMVectorSet(pBCR->R(i), pBCG->R(i), 0, 1.0f);
|
pColor[i] = XMVectorSet(pBCR->R(i), pBCG->R(i), 0, 1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -660,8 +660,8 @@ namespace
|
|||||||
void Encode(_In_ bool bSigned, _In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA* const pIn) noexcept;
|
void Encode(_In_ bool bSigned, _In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA* const pIn) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4480)
|
#pragma warning(disable : 4480)
|
||||||
enum EField : uint8_t
|
enum EField : uint8_t
|
||||||
{
|
{
|
||||||
NA, // N/A
|
NA, // N/A
|
||||||
@ -680,7 +680,7 @@ namespace
|
|||||||
BY,
|
BY,
|
||||||
BZ,
|
BZ,
|
||||||
};
|
};
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
struct ModeDescriptor
|
struct ModeDescriptor
|
||||||
{
|
{
|
||||||
@ -697,8 +697,8 @@ namespace
|
|||||||
LDRColorA RGBAPrec[BC6H_MAX_REGIONS][2];
|
LDRColorA RGBAPrec[BC6H_MAX_REGIONS][2];
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4512)
|
#pragma warning(disable : 4512)
|
||||||
struct EncodeParams
|
struct EncodeParams
|
||||||
{
|
{
|
||||||
float fBestErr;
|
float fBestErr;
|
||||||
@ -718,7 +718,7 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
static int Quantize(_In_ int iValue, _In_ int prec, _In_ bool bSigned) noexcept;
|
static int Quantize(_In_ int iValue, _In_ int prec, _In_ bool bSigned) noexcept;
|
||||||
static int Unquantize(_In_ int comp, _In_ uint8_t uBitsPerComp, _In_ bool bSigned) noexcept;
|
static int Unquantize(_In_ int comp, _In_ uint8_t uBitsPerComp, _In_ bool bSigned) noexcept;
|
||||||
@ -777,8 +777,8 @@ namespace
|
|||||||
LDRColorA RGBAPrecWithP;
|
LDRColorA RGBAPrecWithP;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4512)
|
#pragma warning(disable : 4512)
|
||||||
struct EncodeParams
|
struct EncodeParams
|
||||||
{
|
{
|
||||||
uint8_t uMode;
|
uint8_t uMode;
|
||||||
@ -788,7 +788,7 @@ namespace
|
|||||||
|
|
||||||
EncodeParams(const HDRColorA* const aOriginal) noexcept : uMode(0), aEndPts{}, aLDRPixels{}, aHDRPixels(aOriginal) {}
|
EncodeParams(const HDRColorA* const aOriginal) noexcept : uMode(0), aEndPts{}, aLDRPixels{}, aHDRPixels(aOriginal) {}
|
||||||
};
|
};
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
static uint8_t Quantize(_In_ uint8_t comp, _In_ uint8_t uPrec) noexcept
|
static uint8_t Quantize(_In_ uint8_t comp, _In_ uint8_t uPrec) noexcept
|
||||||
{
|
{
|
||||||
@ -1035,20 +1035,20 @@ const D3DX_BC6H::ModeDescriptor D3DX_BC6H::ms_aDesc[14][82] =
|
|||||||
// Mode, Partitions, Transformed, IndexPrec, RGBAPrec
|
// Mode, Partitions, Transformed, IndexPrec, RGBAPrec
|
||||||
const D3DX_BC6H::ModeInfo D3DX_BC6H::ms_aInfo[] =
|
const D3DX_BC6H::ModeInfo D3DX_BC6H::ms_aInfo[] =
|
||||||
{
|
{
|
||||||
{0x00, 1, true, 3, { { LDRColorA(10,10,10,0), LDRColorA( 5, 5, 5,0) }, { LDRColorA(5,5,5,0), LDRColorA(5,5,5,0) } } }, // Mode 1
|
{0x00, 1, true, 3, { { LDRColorA(10,10,10,0), LDRColorA(5, 5, 5,0) }, { LDRColorA(5,5,5,0), LDRColorA(5,5,5,0) } } }, // Mode 1
|
||||||
{0x01, 1, true, 3, { { LDRColorA( 7, 7, 7,0), LDRColorA( 6, 6, 6,0) }, { LDRColorA(6,6,6,0), LDRColorA(6,6,6,0) } } }, // Mode 2
|
{0x01, 1, true, 3, { { LDRColorA(7, 7, 7,0), LDRColorA(6, 6, 6,0) }, { LDRColorA(6,6,6,0), LDRColorA(6,6,6,0) } } }, // Mode 2
|
||||||
{0x02, 1, true, 3, { { LDRColorA(11,11,11,0), LDRColorA( 5, 4, 4,0) }, { LDRColorA(5,4,4,0), LDRColorA(5,4,4,0) } } }, // Mode 3
|
{0x02, 1, true, 3, { { LDRColorA(11,11,11,0), LDRColorA(5, 4, 4,0) }, { LDRColorA(5,4,4,0), LDRColorA(5,4,4,0) } } }, // Mode 3
|
||||||
{0x06, 1, true, 3, { { LDRColorA(11,11,11,0), LDRColorA( 4, 5, 4,0) }, { LDRColorA(4,5,4,0), LDRColorA(4,5,4,0) } } }, // Mode 4
|
{0x06, 1, true, 3, { { LDRColorA(11,11,11,0), LDRColorA(4, 5, 4,0) }, { LDRColorA(4,5,4,0), LDRColorA(4,5,4,0) } } }, // Mode 4
|
||||||
{0x0a, 1, true, 3, { { LDRColorA(11,11,11,0), LDRColorA( 4, 4, 5,0) }, { LDRColorA(4,4,5,0), LDRColorA(4,4,5,0) } } }, // Mode 5
|
{0x0a, 1, true, 3, { { LDRColorA(11,11,11,0), LDRColorA(4, 4, 5,0) }, { LDRColorA(4,4,5,0), LDRColorA(4,4,5,0) } } }, // Mode 5
|
||||||
{0x0e, 1, true, 3, { { LDRColorA( 9, 9, 9,0), LDRColorA( 5, 5, 5,0) }, { LDRColorA(5,5,5,0), LDRColorA(5,5,5,0) } } }, // Mode 6
|
{0x0e, 1, true, 3, { { LDRColorA(9, 9, 9,0), LDRColorA(5, 5, 5,0) }, { LDRColorA(5,5,5,0), LDRColorA(5,5,5,0) } } }, // Mode 6
|
||||||
{0x12, 1, true, 3, { { LDRColorA( 8, 8, 8,0), LDRColorA( 6, 5, 5,0) }, { LDRColorA(6,5,5,0), LDRColorA(6,5,5,0) } } }, // Mode 7
|
{0x12, 1, true, 3, { { LDRColorA(8, 8, 8,0), LDRColorA(6, 5, 5,0) }, { LDRColorA(6,5,5,0), LDRColorA(6,5,5,0) } } }, // Mode 7
|
||||||
{0x16, 1, true, 3, { { LDRColorA( 8, 8, 8,0), LDRColorA( 5, 6, 5,0) }, { LDRColorA(5,6,5,0), LDRColorA(5,6,5,0) } } }, // Mode 8
|
{0x16, 1, true, 3, { { LDRColorA(8, 8, 8,0), LDRColorA(5, 6, 5,0) }, { LDRColorA(5,6,5,0), LDRColorA(5,6,5,0) } } }, // Mode 8
|
||||||
{0x1a, 1, true, 3, { { LDRColorA( 8, 8, 8,0), LDRColorA( 5, 5, 6,0) }, { LDRColorA(5,5,6,0), LDRColorA(5,5,6,0) } } }, // Mode 9
|
{0x1a, 1, true, 3, { { LDRColorA(8, 8, 8,0), LDRColorA(5, 5, 6,0) }, { LDRColorA(5,5,6,0), LDRColorA(5,5,6,0) } } }, // Mode 9
|
||||||
{0x1e, 1, false, 3, { { LDRColorA( 6, 6, 6,0), LDRColorA( 6, 6, 6,0) }, { LDRColorA(6,6,6,0), LDRColorA(6,6,6,0) } } }, // Mode 10
|
{0x1e, 1, false, 3, { { LDRColorA(6, 6, 6,0), LDRColorA(6, 6, 6,0) }, { LDRColorA(6,6,6,0), LDRColorA(6,6,6,0) } } }, // Mode 10
|
||||||
{0x03, 0, false, 4, { { LDRColorA(10,10,10,0), LDRColorA(10,10,10,0) }, { LDRColorA(0,0,0,0), LDRColorA(0,0,0,0) } } }, // Mode 11
|
{0x03, 0, false, 4, { { LDRColorA(10,10,10,0), LDRColorA(10,10,10,0) }, { LDRColorA(0,0,0,0), LDRColorA(0,0,0,0) } } }, // Mode 11
|
||||||
{0x07, 0, true, 4, { { LDRColorA(11,11,11,0), LDRColorA( 9, 9, 9,0) }, { LDRColorA(0,0,0,0), LDRColorA(0,0,0,0) } } }, // Mode 12
|
{0x07, 0, true, 4, { { LDRColorA(11,11,11,0), LDRColorA(9, 9, 9,0) }, { LDRColorA(0,0,0,0), LDRColorA(0,0,0,0) } } }, // Mode 12
|
||||||
{0x0b, 0, true, 4, { { LDRColorA(12,12,12,0), LDRColorA( 8, 8, 8,0) }, { LDRColorA(0,0,0,0), LDRColorA(0,0,0,0) } } }, // Mode 13
|
{0x0b, 0, true, 4, { { LDRColorA(12,12,12,0), LDRColorA(8, 8, 8,0) }, { LDRColorA(0,0,0,0), LDRColorA(0,0,0,0) } } }, // Mode 13
|
||||||
{0x0f, 0, true, 4, { { LDRColorA(16,16,16,0), LDRColorA( 4, 4, 4,0) }, { LDRColorA(0,0,0,0), LDRColorA(0,0,0,0) } } }, // Mode 14
|
{0x0f, 0, true, 4, { { LDRColorA(16,16,16,0), LDRColorA(4, 4, 4,0) }, { LDRColorA(0,0,0,0), LDRColorA(0,0,0,0) } } }, // Mode 14
|
||||||
};
|
};
|
||||||
|
|
||||||
const int D3DX_BC6H::ms_aModeToInfo[] =
|
const int D3DX_BC6H::ms_aModeToInfo[] =
|
||||||
@ -1628,13 +1628,13 @@ namespace
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// Use Magenta in debug as a highly-visible error color
|
// Use Magenta in debug as a highly-visible error color
|
||||||
pOut[i] = HDRColorA(1.0f, 0.0f, 1.0f, 1.0f);
|
pOut[i] = HDRColorA(1.0f, 0.0f, 1.0f, 1.0f);
|
||||||
#else
|
#else
|
||||||
// In production use, default to black
|
// In production use, default to black
|
||||||
pOut[i] = HDRColorA(0.0f, 0.0f, 0.0f, 1.0f);
|
pOut[i] = HDRColorA(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1694,13 +1694,13 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept
|
|||||||
case BY: aEndPts[1].A.b |= 1 << uint32_t(desc[uCurBit].m_uBit); break;
|
case BY: aEndPts[1].A.b |= 1 << uint32_t(desc[uCurBit].m_uBit); break;
|
||||||
case BZ: aEndPts[1].B.b |= 1 << uint32_t(desc[uCurBit].m_uBit); break;
|
case BZ: aEndPts[1].B.b |= 1 << uint32_t(desc[uCurBit].m_uBit); break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC6H: Invalid header bits encountered during decoding\n");
|
OutputDebugStringA("BC6H: Invalid header bits encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1739,9 +1739,9 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept
|
|||||||
const size_t uNumBits = IsFixUpOffset(info.uPartitions, uShape, i) ? info.uIndexPrec - 1u : info.uIndexPrec;
|
const size_t uNumBits = IsFixUpOffset(info.uPartitions, uShape, i) ? info.uIndexPrec - 1u : info.uIndexPrec;
|
||||||
if (uStartBit + uNumBits > 128)
|
if (uStartBit + uNumBits > 128)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC6H: Invalid block encountered during decoding\n");
|
OutputDebugStringA("BC6H: Invalid block encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1749,9 +1749,9 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept
|
|||||||
|
|
||||||
if (uIndex >= ((info.uPartitions > 0) ? 8 : 16))
|
if (uIndex >= ((info.uPartitions > 0) ? 8 : 16))
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC6H: Invalid index encountered during decoding\n");
|
OutputDebugStringA("BC6H: Invalid index encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1784,7 +1784,7 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
const char* warnstr = "BC6H: Invalid mode encountered during decoding\n";
|
const char* warnstr = "BC6H: Invalid mode encountered during decoding\n";
|
||||||
switch (uMode)
|
switch (uMode)
|
||||||
{
|
{
|
||||||
@ -1794,7 +1794,7 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept
|
|||||||
case 0x1F: warnstr = "BC6H: Reserved mode 11111 encountered during decoding\n"; break;
|
case 0x1F: warnstr = "BC6H: Reserved mode 11111 encountered during decoding\n"; break;
|
||||||
}
|
}
|
||||||
OutputDebugStringA(warnstr);
|
OutputDebugStringA(warnstr);
|
||||||
#endif
|
#endif
|
||||||
// Per the BC6H format spec, we must return opaque black
|
// Per the BC6H format spec, we must return opaque black
|
||||||
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
||||||
{
|
{
|
||||||
@ -2003,7 +2003,7 @@ void D3DX_BC6H::GeneratePaletteQuantized(const EncodeParams* pEP, const INTEndPn
|
|||||||
assert(false);
|
assert(false);
|
||||||
for (size_t i = 0; i < uNumIndices; ++i)
|
for (size_t i = 0; i < uNumIndices; ++i)
|
||||||
{
|
{
|
||||||
#pragma prefast(suppress:22102 22103, "writing blocks in two halves confuses tool")
|
#pragma prefast(suppress:22102 22103, "writing blocks in two halves confuses tool")
|
||||||
aPalette[i] = INTColor(0, 0, 0);
|
aPalette[i] = INTColor(0, 0, 0);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -2409,7 +2409,7 @@ void D3DX_BC6H::GeneratePaletteUnquantized(const EncodeParams* pEP, size_t uRegi
|
|||||||
assert(false);
|
assert(false);
|
||||||
for (size_t i = 0; i < uNumIndices; ++i)
|
for (size_t i = 0; i < uNumIndices; ++i)
|
||||||
{
|
{
|
||||||
#pragma prefast(suppress:22102 22103, "writing blocks in two halves confuses tool")
|
#pragma prefast(suppress:22102 22103, "writing blocks in two halves confuses tool")
|
||||||
aPalette[i] = INTColor(0, 0, 0);
|
aPalette[i] = INTColor(0, 0, 0);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -2558,9 +2558,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept
|
|||||||
{
|
{
|
||||||
if (uStartBit + RGBAPrec.r > 128)
|
if (uStartBit + RGBAPrec.r > 128)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2573,9 +2573,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept
|
|||||||
{
|
{
|
||||||
if (uStartBit + RGBAPrec.g > 128)
|
if (uStartBit + RGBAPrec.g > 128)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2588,9 +2588,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept
|
|||||||
{
|
{
|
||||||
if (uStartBit + RGBAPrec.b > 128)
|
if (uStartBit + RGBAPrec.b > 128)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2603,9 +2603,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept
|
|||||||
{
|
{
|
||||||
if (uStartBit + RGBAPrec.a > 128)
|
if (uStartBit + RGBAPrec.a > 128)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2620,9 +2620,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept
|
|||||||
{
|
{
|
||||||
if (uStartBit > 127)
|
if (uStartBit > 127)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2658,9 +2658,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept
|
|||||||
const size_t uNumBits = IsFixUpOffset(ms_aInfo[uMode].uPartitions, uShape, i) ? uIndexPrec - 1u : uIndexPrec;
|
const size_t uNumBits = IsFixUpOffset(ms_aInfo[uMode].uPartitions, uShape, i) ? uIndexPrec - 1u : uIndexPrec;
|
||||||
if (uStartBit + uNumBits > 128)
|
if (uStartBit + uNumBits > 128)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2675,9 +2675,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept
|
|||||||
const size_t uNumBits = i ? uIndexPrec2 : uIndexPrec2 - 1u;
|
const size_t uNumBits = i ? uIndexPrec2 : uIndexPrec2 - 1u;
|
||||||
if (uStartBit + uNumBits > 128)
|
if (uStartBit + uNumBits > 128)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
OutputDebugStringA("BC7: Invalid block encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
FillWithErrorColors(pOut);
|
FillWithErrorColors(pOut);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2717,9 +2717,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
OutputDebugStringA("BC7: Reserved mode 8 encountered during decoding\n");
|
OutputDebugStringA("BC7: Reserved mode 8 encountered during decoding\n");
|
||||||
#endif
|
#endif
|
||||||
// Per the BC7 format spec, we must return transparent black
|
// Per the BC7 format spec, we must return transparent black
|
||||||
memset(pOut, 0, sizeof(HDRColorA) * NUM_PIXELS_PER_BLOCK);
|
memset(pOut, 0, sizeof(HDRColorA) * NUM_PIXELS_PER_BLOCK);
|
||||||
}
|
}
|
||||||
@ -3201,7 +3201,7 @@ void D3DX_BC7::EmitBlock(const EncodeParams* pEP, size_t uShape, size_t uRotatio
|
|||||||
|
|
||||||
for (i = 0; i < uPBits; i++)
|
for (i = 0; i < uPBits; i++)
|
||||||
{
|
{
|
||||||
SetBits(uStartBit, 1, aPVote[i] > (aCount[i] >> 1) ? 1u : 0u);
|
SetBits(uStartBit, 1, (aPVote[i] >(aCount[i] >> 1)) ? 1u : 0u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -20,13 +20,13 @@ using Microsoft::WRL::ComPtr;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#include "BC7Encode_EncodeBlockCS.inc"
|
#include "BC7Encode_EncodeBlockCS.inc"
|
||||||
#include "BC7Encode_TryMode02CS.inc"
|
#include "BC7Encode_TryMode02CS.inc"
|
||||||
#include "BC7Encode_TryMode137CS.inc"
|
#include "BC7Encode_TryMode137CS.inc"
|
||||||
#include "BC7Encode_TryMode456CS.inc"
|
#include "BC7Encode_TryMode456CS.inc"
|
||||||
#include "BC6HEncode_EncodeBlockCS.inc"
|
#include "BC6HEncode_EncodeBlockCS.inc"
|
||||||
#include "BC6HEncode_TryModeG10CS.inc"
|
#include "BC6HEncode_TryModeG10CS.inc"
|
||||||
#include "BC6HEncode_TryModeLE10CS.inc"
|
#include "BC6HEncode_TryModeLE10CS.inc"
|
||||||
|
|
||||||
struct BufferBC6HBC7
|
struct BufferBC6HBC7
|
||||||
{
|
{
|
||||||
|
218
DirectXTex/DDS.h
218
DirectXTex/DDS.h
@ -25,19 +25,19 @@ namespace DirectX
|
|||||||
|
|
||||||
#pragma pack(push,1)
|
#pragma pack(push,1)
|
||||||
|
|
||||||
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
|
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
|
||||||
|
|
||||||
struct DDS_PIXELFORMAT
|
struct DDS_PIXELFORMAT
|
||||||
{
|
{
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
uint32_t fourCC;
|
uint32_t fourCC;
|
||||||
uint32_t RGBBitCount;
|
uint32_t RGBBitCount;
|
||||||
uint32_t RBitMask;
|
uint32_t RBitMask;
|
||||||
uint32_t GBitMask;
|
uint32_t GBitMask;
|
||||||
uint32_t BBitMask;
|
uint32_t BBitMask;
|
||||||
uint32_t ABitMask;
|
uint32_t ABitMask;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
||||||
#define DDS_RGB 0x00000040 // DDPF_RGB
|
#define DDS_RGB 0x00000040 // DDPF_RGB
|
||||||
@ -52,7 +52,7 @@ struct DDS_PIXELFORMAT
|
|||||||
// DDS_BUMPLUMINANCE 0x00040000
|
// DDS_BUMPLUMINANCE 0x00040000
|
||||||
|
|
||||||
#ifndef MAKEFOURCC
|
#ifndef MAKEFOURCC
|
||||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||||
(static_cast<uint32_t>(static_cast<uint8_t>(ch0)) \
|
(static_cast<uint32_t>(static_cast<uint8_t>(ch0)) \
|
||||||
| (static_cast<uint32_t>(static_cast<uint8_t>(ch1)) << 8) \
|
| (static_cast<uint32_t>(static_cast<uint8_t>(ch1)) << 8) \
|
||||||
| (static_cast<uint32_t>(static_cast<uint8_t>(ch2)) << 16) \
|
| (static_cast<uint32_t>(static_cast<uint8_t>(ch2)) << 16) \
|
||||||
@ -60,131 +60,131 @@ struct DDS_PIXELFORMAT
|
|||||||
#endif /* MAKEFOURCC */
|
#endif /* MAKEFOURCC */
|
||||||
|
|
||||||
#ifndef DDSGLOBALCONST
|
#ifndef DDSGLOBALCONST
|
||||||
#if defined(__GNUC__) && !defined(__MINGW32__)
|
#if defined(__GNUC__) && !defined(__MINGW32__)
|
||||||
#define DDSGLOBALCONST extern const __attribute__((weak))
|
#define DDSGLOBALCONST extern const __attribute__((weak))
|
||||||
#else
|
#else
|
||||||
#define DDSGLOBALCONST extern const __declspec(selectany)
|
#define DDSGLOBALCONST extern const __declspec(selectany)
|
||||||
#endif
|
#endif
|
||||||
#endif /* DDSGLOBALCONST */
|
#endif /* DDSGLOBALCONST */
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_DXT1 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_DXT2 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_DXT3 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_DXT4 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_DXT5 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_BC4_UNORM =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_BC4_SNORM =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_BC5_UNORM =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_BC5_SNORM =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_R8G8_B8G8 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_G8R8_G8B8 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_YUY2 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_UYVY =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_UYVY =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('U','Y','V','Y'), 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8R8G8B8 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_X8R8G8B8 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8B8G8R8 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_X8B8G8R8 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_G16R16 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_G16R16 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_R5G6B5 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A1R5G5B5 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_X1R5G5B5 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A4R4G4B4 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A4R4G4B4 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_X4R4G4B4 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_R8G8B8 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8R3G3B2 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_R3G3B2 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A4L4 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L8 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L8 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0, 0, 0 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0, 0, 0 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L16 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L16 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0, 0, 0 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0, 0, 0 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0, 0, 0xff00 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0, 0, 0xff00 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8_ALT =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8_ALT =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 8, 0x00ff, 0, 0, 0xff00 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 8, 0x00ff, 0, 0, 0xff00 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L8_NVTT1 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L8_NVTT1 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 8, 0xff, 0, 0, 0 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 8, 0xff, 0, 0, 0 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L16_NVTT1 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L16_NVTT1 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0xffff, 0, 0, 0 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0xffff, 0, 0, 0 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8_NVTT1 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8_NVTT1 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00ff, 0, 0, 0xff00 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00ff, 0, 0, 0xff00 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0, 0, 0, 0xff };
|
{ sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0, 0, 0, 0xff };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_V8U8 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_V8U8 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_Q8W8V8U8 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_Q8W8V8U8 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
|
||||||
|
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_V16U16 =
|
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_V16U16 =
|
||||||
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0 };
|
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0 };
|
||||||
|
|
||||||
// D3DFMT_A2R10G10B10/D3DFMT_A2B10G10R10 should be written using DX10 extension to avoid D3DX 10:10:10:2 reversal issue
|
// D3DFMT_A2R10G10B10/D3DFMT_A2B10G10R10 should be written using DX10 extension to avoid D3DX 10:10:10:2 reversal issue
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A2R10G10B10 =
|
DDSGLOBALCONST 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 };
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A2B10G10R10 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
// We do not support the following legacy Direct3D 9 formats:
|
// We do not support the following legacy Direct3D 9 formats:
|
||||||
@ -193,7 +193,7 @@ DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A2B10G10R10 =
|
|||||||
// DDSPF_X8L8V8U8 = { sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0 };
|
// DDSPF_X8L8V8U8 = { sizeof(DDS_PIXELFORMAT), DDS_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0 };
|
||||||
|
|
||||||
// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat)
|
// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat)
|
||||||
DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_DX10 =
|
DDSGLOBALCONST 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 };
|
||||||
|
|
||||||
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
||||||
@ -225,66 +225,66 @@ DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_DX10 =
|
|||||||
#define DDS_FLAGS_VOLUME 0x00200000 // DDSCAPS2_VOLUME
|
#define DDS_FLAGS_VOLUME 0x00200000 // DDSCAPS2_VOLUME
|
||||||
|
|
||||||
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
|
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
|
||||||
enum DDS_RESOURCE_DIMENSION : uint32_t
|
enum DDS_RESOURCE_DIMENSION : uint32_t
|
||||||
{
|
{
|
||||||
DDS_DIMENSION_TEXTURE1D = 2,
|
DDS_DIMENSION_TEXTURE1D = 2,
|
||||||
DDS_DIMENSION_TEXTURE2D = 3,
|
DDS_DIMENSION_TEXTURE2D = 3,
|
||||||
DDS_DIMENSION_TEXTURE3D = 4,
|
DDS_DIMENSION_TEXTURE3D = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
|
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
|
||||||
enum DDS_RESOURCE_MISC_FLAG : uint32_t
|
enum DDS_RESOURCE_MISC_FLAG : uint32_t
|
||||||
{
|
{
|
||||||
DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L,
|
DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DDS_MISC_FLAGS2 : uint32_t
|
enum DDS_MISC_FLAGS2 : uint32_t
|
||||||
{
|
{
|
||||||
DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L,
|
DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef DDS_ALPHA_MODE_DEFINED
|
#ifndef DDS_ALPHA_MODE_DEFINED
|
||||||
#define DDS_ALPHA_MODE_DEFINED
|
#define DDS_ALPHA_MODE_DEFINED
|
||||||
enum DDS_ALPHA_MODE : uint32_t
|
enum DDS_ALPHA_MODE : uint32_t
|
||||||
{
|
{
|
||||||
DDS_ALPHA_MODE_UNKNOWN = 0,
|
DDS_ALPHA_MODE_UNKNOWN = 0,
|
||||||
DDS_ALPHA_MODE_STRAIGHT = 1,
|
DDS_ALPHA_MODE_STRAIGHT = 1,
|
||||||
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
||||||
DDS_ALPHA_MODE_OPAQUE = 3,
|
DDS_ALPHA_MODE_OPAQUE = 3,
|
||||||
DDS_ALPHA_MODE_CUSTOM = 4,
|
DDS_ALPHA_MODE_CUSTOM = 4,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct DDS_HEADER
|
struct DDS_HEADER
|
||||||
{
|
{
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t pitchOrLinearSize;
|
uint32_t pitchOrLinearSize;
|
||||||
uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags
|
uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags
|
||||||
uint32_t mipMapCount;
|
uint32_t mipMapCount;
|
||||||
uint32_t reserved1[11];
|
uint32_t reserved1[11];
|
||||||
DDS_PIXELFORMAT ddspf;
|
DDS_PIXELFORMAT ddspf;
|
||||||
uint32_t caps;
|
uint32_t caps;
|
||||||
uint32_t caps2;
|
uint32_t caps2;
|
||||||
uint32_t caps3;
|
uint32_t caps3;
|
||||||
uint32_t caps4;
|
uint32_t caps4;
|
||||||
uint32_t reserved2;
|
uint32_t reserved2;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DDS_HEADER_DXT10
|
struct DDS_HEADER_DXT10
|
||||||
{
|
{
|
||||||
DXGI_FORMAT dxgiFormat;
|
DXGI_FORMAT dxgiFormat;
|
||||||
uint32_t resourceDimension;
|
uint32_t resourceDimension;
|
||||||
uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG
|
uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG
|
||||||
uint32_t arraySize;
|
uint32_t arraySize;
|
||||||
uint32_t miscFlags2; // see DDS_MISC_FLAGS2
|
uint32_t miscFlags2; // see DDS_MISC_FLAGS2
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
static_assert( sizeof(DDS_HEADER) == 124, "DDS Header size mismatch" );
|
static_assert(sizeof(DDS_HEADER) == 124, "DDS Header size mismatch");
|
||||||
static_assert( sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch");
|
static_assert(sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch");
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -85,16 +85,35 @@ namespace DirectX
|
|||||||
|
|
||||||
enum CP_FLAGS : unsigned long
|
enum CP_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
CP_FLAGS_NONE = 0x0, // Normal operation
|
CP_FLAGS_NONE = 0x0,
|
||||||
CP_FLAGS_LEGACY_DWORD = 0x1, // Assume pitch is DWORD aligned instead of BYTE aligned
|
// Normal operation
|
||||||
CP_FLAGS_PARAGRAPH = 0x2, // Assume pitch is 16-byte aligned instead of BYTE aligned
|
|
||||||
CP_FLAGS_YMM = 0x4, // Assume pitch is 32-byte aligned instead of BYTE aligned
|
CP_FLAGS_LEGACY_DWORD = 0x1,
|
||||||
CP_FLAGS_ZMM = 0x8, // Assume pitch is 64-byte aligned instead of BYTE aligned
|
// Assume pitch is DWORD aligned instead of BYTE aligned
|
||||||
CP_FLAGS_PAGE4K = 0x200, // Assume pitch is 4096-byte aligned instead of BYTE aligned
|
|
||||||
CP_FLAGS_BAD_DXTN_TAILS = 0x1000, // BC formats with malformed mipchain blocks smaller than 4x4
|
CP_FLAGS_PARAGRAPH = 0x2,
|
||||||
CP_FLAGS_24BPP = 0x10000, // Override with a legacy 24 bits-per-pixel format size
|
// Assume pitch is 16-byte aligned instead of BYTE aligned
|
||||||
CP_FLAGS_16BPP = 0x20000, // Override with a legacy 16 bits-per-pixel format size
|
|
||||||
CP_FLAGS_8BPP = 0x40000, // Override with a legacy 8 bits-per-pixel format size
|
CP_FLAGS_YMM = 0x4,
|
||||||
|
// Assume pitch is 32-byte aligned instead of BYTE aligned
|
||||||
|
|
||||||
|
CP_FLAGS_ZMM = 0x8,
|
||||||
|
// Assume pitch is 64-byte aligned instead of BYTE aligned
|
||||||
|
|
||||||
|
CP_FLAGS_PAGE4K = 0x200,
|
||||||
|
// Assume pitch is 4096-byte aligned instead of BYTE aligned
|
||||||
|
|
||||||
|
CP_FLAGS_BAD_DXTN_TAILS = 0x1000,
|
||||||
|
// BC formats with malformed mipchain blocks smaller than 4x4
|
||||||
|
|
||||||
|
CP_FLAGS_24BPP = 0x10000,
|
||||||
|
// Override with a legacy 24 bits-per-pixel format size
|
||||||
|
|
||||||
|
CP_FLAGS_16BPP = 0x20000,
|
||||||
|
// Override with a legacy 16 bits-per-pixel format size
|
||||||
|
|
||||||
|
CP_FLAGS_8BPP = 0x40000,
|
||||||
|
// Override with a legacy 8 bits-per-pixel format size
|
||||||
};
|
};
|
||||||
|
|
||||||
HRESULT __cdecl ComputePitch(
|
HRESULT __cdecl ComputePitch(
|
||||||
@ -113,9 +132,9 @@ namespace DirectX
|
|||||||
enum TEX_DIMENSION
|
enum TEX_DIMENSION
|
||||||
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
|
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
|
||||||
{
|
{
|
||||||
TEX_DIMENSION_TEXTURE1D = 2,
|
TEX_DIMENSION_TEXTURE1D = 2,
|
||||||
TEX_DIMENSION_TEXTURE2D = 3,
|
TEX_DIMENSION_TEXTURE2D = 3,
|
||||||
TEX_DIMENSION_TEXTURE3D = 4,
|
TEX_DIMENSION_TEXTURE3D = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum TEX_MISC_FLAG : unsigned long
|
enum TEX_MISC_FLAG : unsigned long
|
||||||
@ -132,11 +151,11 @@ namespace DirectX
|
|||||||
enum TEX_ALPHA_MODE
|
enum TEX_ALPHA_MODE
|
||||||
// Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2
|
// Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2
|
||||||
{
|
{
|
||||||
TEX_ALPHA_MODE_UNKNOWN = 0,
|
TEX_ALPHA_MODE_UNKNOWN = 0,
|
||||||
TEX_ALPHA_MODE_STRAIGHT = 1,
|
TEX_ALPHA_MODE_STRAIGHT = 1,
|
||||||
TEX_ALPHA_MODE_PREMULTIPLIED = 2,
|
TEX_ALPHA_MODE_PREMULTIPLIED = 2,
|
||||||
TEX_ALPHA_MODE_OPAQUE = 3,
|
TEX_ALPHA_MODE_OPAQUE = 3,
|
||||||
TEX_ALPHA_MODE_CUSTOM = 4,
|
TEX_ALPHA_MODE_CUSTOM = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TexMetadata
|
struct TexMetadata
|
||||||
@ -168,106 +187,106 @@ namespace DirectX
|
|||||||
|
|
||||||
enum DDS_FLAGS : unsigned long
|
enum DDS_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
DDS_FLAGS_NONE = 0x0,
|
DDS_FLAGS_NONE = 0x0,
|
||||||
|
|
||||||
DDS_FLAGS_LEGACY_DWORD = 0x1,
|
DDS_FLAGS_LEGACY_DWORD = 0x1,
|
||||||
// Assume pitch is DWORD aligned instead of BYTE aligned (used by some legacy DDS files)
|
// Assume pitch is DWORD aligned instead of BYTE aligned (used by some legacy DDS files)
|
||||||
|
|
||||||
DDS_FLAGS_NO_LEGACY_EXPANSION = 0x2,
|
DDS_FLAGS_NO_LEGACY_EXPANSION = 0x2,
|
||||||
// Do not implicitly convert legacy formats that result in larger pixel sizes (24 bpp, 3:3:2, A8L8, A4L4, P8, A8P8)
|
// Do not implicitly convert legacy formats that result in larger pixel sizes (24 bpp, 3:3:2, A8L8, A4L4, P8, A8P8)
|
||||||
|
|
||||||
DDS_FLAGS_NO_R10B10G10A2_FIXUP = 0x4,
|
DDS_FLAGS_NO_R10B10G10A2_FIXUP = 0x4,
|
||||||
// Do not use work-around for long-standing D3DX DDS file format issue which reversed the 10:10:10:2 color order masks
|
// Do not use work-around for long-standing D3DX DDS file format issue which reversed the 10:10:10:2 color order masks
|
||||||
|
|
||||||
DDS_FLAGS_FORCE_RGB = 0x8,
|
DDS_FLAGS_FORCE_RGB = 0x8,
|
||||||
// Convert DXGI 1.1 BGR formats to DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
|
// Convert DXGI 1.1 BGR formats to DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
|
||||||
|
|
||||||
DDS_FLAGS_NO_16BPP = 0x10,
|
DDS_FLAGS_NO_16BPP = 0x10,
|
||||||
// Conversions avoid use of 565, 5551, and 4444 formats and instead expand to 8888 to avoid use of optional WDDM 1.2 formats
|
// Conversions avoid use of 565, 5551, and 4444 formats and instead expand to 8888 to avoid use of optional WDDM 1.2 formats
|
||||||
|
|
||||||
DDS_FLAGS_EXPAND_LUMINANCE = 0x20,
|
DDS_FLAGS_EXPAND_LUMINANCE = 0x20,
|
||||||
// When loading legacy luminance formats expand replicating the color channels rather than leaving them packed (L8, L16, A8L8)
|
// When loading legacy luminance formats expand replicating the color channels rather than leaving them packed (L8, L16, A8L8)
|
||||||
|
|
||||||
DDS_FLAGS_BAD_DXTN_TAILS = 0x40,
|
DDS_FLAGS_BAD_DXTN_TAILS = 0x40,
|
||||||
// Some older DXTn DDS files incorrectly handle mipchain tails for blocks smaller than 4x4
|
// Some older DXTn DDS files incorrectly handle mipchain tails for blocks smaller than 4x4
|
||||||
|
|
||||||
DDS_FLAGS_FORCE_DX10_EXT = 0x10000,
|
DDS_FLAGS_FORCE_DX10_EXT = 0x10000,
|
||||||
// Always use the 'DX10' header extension for DDS writer (i.e. don't try to write DX9 compatible DDS files)
|
// Always use the 'DX10' header extension for DDS writer (i.e. don't try to write DX9 compatible DDS files)
|
||||||
|
|
||||||
DDS_FLAGS_FORCE_DX10_EXT_MISC2 = 0x20000,
|
DDS_FLAGS_FORCE_DX10_EXT_MISC2 = 0x20000,
|
||||||
// DDS_FLAGS_FORCE_DX10_EXT including miscFlags2 information (result may not be compatible with D3DX10 or D3DX11)
|
// DDS_FLAGS_FORCE_DX10_EXT including miscFlags2 information (result may not be compatible with D3DX10 or D3DX11)
|
||||||
|
|
||||||
DDS_FLAGS_FORCE_DX9_LEGACY = 0x40000,
|
DDS_FLAGS_FORCE_DX9_LEGACY = 0x40000,
|
||||||
// Force use of legacy header for DDS writer (will fail if unable to write as such)
|
// Force use of legacy header for DDS writer (will fail if unable to write as such)
|
||||||
|
|
||||||
DDS_FLAGS_ALLOW_LARGE_FILES = 0x1000000,
|
DDS_FLAGS_ALLOW_LARGE_FILES = 0x1000000,
|
||||||
// Enables the loader to read large dimension .dds files (i.e. greater than known hardware requirements)
|
// Enables the loader to read large dimension .dds files (i.e. greater than known hardware requirements)
|
||||||
};
|
};
|
||||||
|
|
||||||
enum TGA_FLAGS : unsigned long
|
enum TGA_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
TGA_FLAGS_NONE = 0x0,
|
TGA_FLAGS_NONE = 0x0,
|
||||||
|
|
||||||
TGA_FLAGS_BGR = 0x1,
|
TGA_FLAGS_BGR = 0x1,
|
||||||
// 24bpp files are returned as BGRX; 32bpp files are returned as BGRA
|
// 24bpp files are returned as BGRX; 32bpp files are returned as BGRA
|
||||||
|
|
||||||
TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA = 0x2,
|
TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA = 0x2,
|
||||||
// If the loaded image has an all zero alpha channel, normally we assume it should be opaque. This flag leaves it alone.
|
// If the loaded image has an all zero alpha channel, normally we assume it should be opaque. This flag leaves it alone.
|
||||||
|
|
||||||
TGA_FLAGS_IGNORE_SRGB = 0x10,
|
TGA_FLAGS_IGNORE_SRGB = 0x10,
|
||||||
// Ignores sRGB TGA 2.0 metadata if present in the file
|
// Ignores sRGB TGA 2.0 metadata if present in the file
|
||||||
|
|
||||||
TGA_FLAGS_FORCE_SRGB = 0x20,
|
TGA_FLAGS_FORCE_SRGB = 0x20,
|
||||||
// Writes sRGB metadata into the file reguardless of format (TGA 2.0 only)
|
// Writes sRGB metadata into the file reguardless of format (TGA 2.0 only)
|
||||||
|
|
||||||
TGA_FLAGS_FORCE_LINEAR = 0x40,
|
TGA_FLAGS_FORCE_LINEAR = 0x40,
|
||||||
// Writes linear gamma metadata into the file reguardless of format (TGA 2.0 only)
|
// Writes linear gamma metadata into the file reguardless of format (TGA 2.0 only)
|
||||||
|
|
||||||
TGA_FLAGS_DEFAULT_SRGB = 0x80,
|
TGA_FLAGS_DEFAULT_SRGB = 0x80,
|
||||||
// If no colorspace is specified in TGA 2.0 metadata, assume sRGB
|
// If no colorspace is specified in TGA 2.0 metadata, assume sRGB
|
||||||
};
|
};
|
||||||
|
|
||||||
enum WIC_FLAGS : unsigned long
|
enum WIC_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
WIC_FLAGS_NONE = 0x0,
|
WIC_FLAGS_NONE = 0x0,
|
||||||
|
|
||||||
WIC_FLAGS_FORCE_RGB = 0x1,
|
WIC_FLAGS_FORCE_RGB = 0x1,
|
||||||
// Loads DXGI 1.1 BGR formats as DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
|
// Loads DXGI 1.1 BGR formats as DXGI_FORMAT_R8G8B8A8_UNORM to avoid use of optional WDDM 1.1 formats
|
||||||
|
|
||||||
WIC_FLAGS_NO_X2_BIAS = 0x2,
|
WIC_FLAGS_NO_X2_BIAS = 0x2,
|
||||||
// Loads DXGI 1.1 X2 10:10:10:2 format as DXGI_FORMAT_R10G10B10A2_UNORM
|
// Loads DXGI 1.1 X2 10:10:10:2 format as DXGI_FORMAT_R10G10B10A2_UNORM
|
||||||
|
|
||||||
WIC_FLAGS_NO_16BPP = 0x4,
|
WIC_FLAGS_NO_16BPP = 0x4,
|
||||||
// Loads 565, 5551, and 4444 formats as 8888 to avoid use of optional WDDM 1.2 formats
|
// Loads 565, 5551, and 4444 formats as 8888 to avoid use of optional WDDM 1.2 formats
|
||||||
|
|
||||||
WIC_FLAGS_ALLOW_MONO = 0x8,
|
WIC_FLAGS_ALLOW_MONO = 0x8,
|
||||||
// Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit grayscale
|
// Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit grayscale
|
||||||
|
|
||||||
WIC_FLAGS_ALL_FRAMES = 0x10,
|
WIC_FLAGS_ALL_FRAMES = 0x10,
|
||||||
// Loads all images in a multi-frame file, converting/resizing to match the first frame as needed, defaults to 0th frame otherwise
|
// Loads all images in a multi-frame file, converting/resizing to match the first frame as needed, defaults to 0th frame otherwise
|
||||||
|
|
||||||
WIC_FLAGS_IGNORE_SRGB = 0x20,
|
WIC_FLAGS_IGNORE_SRGB = 0x20,
|
||||||
// Ignores sRGB metadata if present in the file
|
// Ignores sRGB metadata if present in the file
|
||||||
|
|
||||||
WIC_FLAGS_FORCE_SRGB = 0x40,
|
WIC_FLAGS_FORCE_SRGB = 0x40,
|
||||||
// Writes sRGB metadata into the file reguardless of format
|
// Writes sRGB metadata into the file reguardless of format
|
||||||
|
|
||||||
WIC_FLAGS_FORCE_LINEAR = 0x80,
|
WIC_FLAGS_FORCE_LINEAR = 0x80,
|
||||||
// Writes linear gamma metadata into the file reguardless of format
|
// Writes linear gamma metadata into the file reguardless of format
|
||||||
|
|
||||||
WIC_FLAGS_DEFAULT_SRGB = 0x100,
|
WIC_FLAGS_DEFAULT_SRGB = 0x100,
|
||||||
// If no colorspace is specified, assume sRGB
|
// If no colorspace is specified, assume sRGB
|
||||||
|
|
||||||
WIC_FLAGS_DITHER = 0x10000,
|
WIC_FLAGS_DITHER = 0x10000,
|
||||||
// Use ordered 4x4 dithering for any required conversions
|
// Use ordered 4x4 dithering for any required conversions
|
||||||
|
|
||||||
WIC_FLAGS_DITHER_DIFFUSION = 0x20000,
|
WIC_FLAGS_DITHER_DIFFUSION = 0x20000,
|
||||||
// Use error-diffusion dithering for any required conversions
|
// Use error-diffusion dithering for any required conversions
|
||||||
|
|
||||||
WIC_FLAGS_FILTER_POINT = 0x100000,
|
WIC_FLAGS_FILTER_POINT = 0x100000,
|
||||||
WIC_FLAGS_FILTER_LINEAR = 0x200000,
|
WIC_FLAGS_FILTER_LINEAR = 0x200000,
|
||||||
WIC_FLAGS_FILTER_CUBIC = 0x300000,
|
WIC_FLAGS_FILTER_CUBIC = 0x300000,
|
||||||
WIC_FLAGS_FILTER_FANT = 0x400000, // Combination of Linear and Box filter
|
WIC_FLAGS_FILTER_FANT = 0x400000, // Combination of Linear and Box filter
|
||||||
// Filtering mode to use for any required image resizing (only needed when loading arrays of differently sized images; defaults to Fant)
|
// Filtering mode to use for any required image resizing (only needed when loading arrays of differently sized images; defaults to Fant)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -515,12 +534,12 @@ namespace DirectX
|
|||||||
|
|
||||||
enum TEX_FR_FLAGS : unsigned long
|
enum TEX_FR_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
TEX_FR_ROTATE0 = 0x0,
|
TEX_FR_ROTATE0 = 0x0,
|
||||||
TEX_FR_ROTATE90 = 0x1,
|
TEX_FR_ROTATE90 = 0x1,
|
||||||
TEX_FR_ROTATE180 = 0x2,
|
TEX_FR_ROTATE180 = 0x2,
|
||||||
TEX_FR_ROTATE270 = 0x3,
|
TEX_FR_ROTATE270 = 0x3,
|
||||||
TEX_FR_FLIP_HORIZONTAL = 0x08,
|
TEX_FR_FLIP_HORIZONTAL = 0x08,
|
||||||
TEX_FR_FLIP_VERTICAL = 0x10,
|
TEX_FR_FLIP_VERTICAL = 0x10,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -533,60 +552,60 @@ namespace DirectX
|
|||||||
|
|
||||||
enum TEX_FILTER_FLAGS : unsigned long
|
enum TEX_FILTER_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
TEX_FILTER_DEFAULT = 0,
|
TEX_FILTER_DEFAULT = 0,
|
||||||
|
|
||||||
TEX_FILTER_WRAP_U = 0x1,
|
TEX_FILTER_WRAP_U = 0x1,
|
||||||
TEX_FILTER_WRAP_V = 0x2,
|
TEX_FILTER_WRAP_V = 0x2,
|
||||||
TEX_FILTER_WRAP_W = 0x4,
|
TEX_FILTER_WRAP_W = 0x4,
|
||||||
TEX_FILTER_WRAP = (TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W),
|
TEX_FILTER_WRAP = (TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W),
|
||||||
TEX_FILTER_MIRROR_U = 0x10,
|
TEX_FILTER_MIRROR_U = 0x10,
|
||||||
TEX_FILTER_MIRROR_V = 0x20,
|
TEX_FILTER_MIRROR_V = 0x20,
|
||||||
TEX_FILTER_MIRROR_W = 0x40,
|
TEX_FILTER_MIRROR_W = 0x40,
|
||||||
TEX_FILTER_MIRROR = (TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W),
|
TEX_FILTER_MIRROR = (TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W),
|
||||||
// Wrap vs. Mirror vs. Clamp filtering options
|
// Wrap vs. Mirror vs. Clamp filtering options
|
||||||
|
|
||||||
TEX_FILTER_SEPARATE_ALPHA = 0x100,
|
TEX_FILTER_SEPARATE_ALPHA = 0x100,
|
||||||
// Resize color and alpha channel independently
|
// Resize color and alpha channel independently
|
||||||
|
|
||||||
TEX_FILTER_FLOAT_X2BIAS = 0x200,
|
TEX_FILTER_FLOAT_X2BIAS = 0x200,
|
||||||
// Enable *2 - 1 conversion cases for unorm<->float and positive-only float formats
|
// Enable *2 - 1 conversion cases for unorm<->float and positive-only float formats
|
||||||
|
|
||||||
TEX_FILTER_RGB_COPY_RED = 0x1000,
|
TEX_FILTER_RGB_COPY_RED = 0x1000,
|
||||||
TEX_FILTER_RGB_COPY_GREEN = 0x2000,
|
TEX_FILTER_RGB_COPY_GREEN = 0x2000,
|
||||||
TEX_FILTER_RGB_COPY_BLUE = 0x4000,
|
TEX_FILTER_RGB_COPY_BLUE = 0x4000,
|
||||||
// When converting RGB to R, defaults to using grayscale. These flags indicate copying a specific channel instead
|
// When converting RGB to R, defaults to using grayscale. These flags indicate copying a specific channel instead
|
||||||
// When converting RGB to RG, defaults to copying RED | GREEN. These flags control which channels are selected instead.
|
// When converting RGB to RG, defaults to copying RED | GREEN. These flags control which channels are selected instead.
|
||||||
|
|
||||||
TEX_FILTER_DITHER = 0x10000,
|
TEX_FILTER_DITHER = 0x10000,
|
||||||
// Use ordered 4x4 dithering for any required conversions
|
// Use ordered 4x4 dithering for any required conversions
|
||||||
TEX_FILTER_DITHER_DIFFUSION = 0x20000,
|
TEX_FILTER_DITHER_DIFFUSION = 0x20000,
|
||||||
// Use error-diffusion dithering for any required conversions
|
// Use error-diffusion dithering for any required conversions
|
||||||
|
|
||||||
TEX_FILTER_POINT = 0x100000,
|
TEX_FILTER_POINT = 0x100000,
|
||||||
TEX_FILTER_LINEAR = 0x200000,
|
TEX_FILTER_LINEAR = 0x200000,
|
||||||
TEX_FILTER_CUBIC = 0x300000,
|
TEX_FILTER_CUBIC = 0x300000,
|
||||||
TEX_FILTER_BOX = 0x400000,
|
TEX_FILTER_BOX = 0x400000,
|
||||||
TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation
|
TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation
|
||||||
TEX_FILTER_TRIANGLE = 0x500000,
|
TEX_FILTER_TRIANGLE = 0x500000,
|
||||||
// Filtering mode to use for any required image resizing
|
// Filtering mode to use for any required image resizing
|
||||||
|
|
||||||
TEX_FILTER_SRGB_IN = 0x1000000,
|
TEX_FILTER_SRGB_IN = 0x1000000,
|
||||||
TEX_FILTER_SRGB_OUT = 0x2000000,
|
TEX_FILTER_SRGB_OUT = 0x2000000,
|
||||||
TEX_FILTER_SRGB = (TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT),
|
TEX_FILTER_SRGB = (TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT),
|
||||||
// sRGB <-> RGB for use in conversion operations
|
// sRGB <-> RGB for use in conversion operations
|
||||||
// if the input format type is IsSRGB(), then SRGB_IN is on by default
|
// if the input format type is IsSRGB(), then SRGB_IN is on by default
|
||||||
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
|
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
|
||||||
|
|
||||||
TEX_FILTER_FORCE_NON_WIC = 0x10000000,
|
TEX_FILTER_FORCE_NON_WIC = 0x10000000,
|
||||||
// Forces use of the non-WIC path when both are an option
|
// Forces use of the non-WIC path when both are an option
|
||||||
|
|
||||||
TEX_FILTER_FORCE_WIC = 0x20000000,
|
TEX_FILTER_FORCE_WIC = 0x20000000,
|
||||||
// Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option
|
// Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr unsigned long TEX_FILTER_DITHER_MASK = 0xF0000;
|
constexpr unsigned long TEX_FILTER_DITHER_MASK = 0xF0000;
|
||||||
constexpr unsigned long TEX_FILTER_MODE_MASK = 0xF00000;
|
constexpr unsigned long TEX_FILTER_MODE_MASK = 0xF00000;
|
||||||
constexpr unsigned long TEX_FILTER_SRGB_MASK = 0xF000000;
|
constexpr unsigned long TEX_FILTER_SRGB_MASK = 0xF000000;
|
||||||
|
|
||||||
HRESULT __cdecl Resize(
|
HRESULT __cdecl Resize(
|
||||||
_In_ const Image& srcImage, _In_ size_t width, _In_ size_t height,
|
_In_ const Image& srcImage, _In_ size_t width, _In_ size_t height,
|
||||||
@ -640,19 +659,19 @@ namespace DirectX
|
|||||||
|
|
||||||
enum TEX_PMALPHA_FLAGS : unsigned long
|
enum TEX_PMALPHA_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
TEX_PMALPHA_DEFAULT = 0,
|
TEX_PMALPHA_DEFAULT = 0,
|
||||||
|
|
||||||
TEX_PMALPHA_IGNORE_SRGB = 0x1,
|
TEX_PMALPHA_IGNORE_SRGB = 0x1,
|
||||||
// ignores sRGB colorspace conversions
|
// ignores sRGB colorspace conversions
|
||||||
|
|
||||||
TEX_PMALPHA_REVERSE = 0x2,
|
TEX_PMALPHA_REVERSE = 0x2,
|
||||||
// converts from premultiplied alpha back to straight alpha
|
// converts from premultiplied alpha back to straight alpha
|
||||||
|
|
||||||
TEX_PMALPHA_SRGB_IN = 0x1000000,
|
TEX_PMALPHA_SRGB_IN = 0x1000000,
|
||||||
TEX_PMALPHA_SRGB_OUT = 0x2000000,
|
TEX_PMALPHA_SRGB_OUT = 0x2000000,
|
||||||
TEX_PMALPHA_SRGB = (TEX_PMALPHA_SRGB_IN | TEX_PMALPHA_SRGB_OUT),
|
TEX_PMALPHA_SRGB = (TEX_PMALPHA_SRGB_IN | TEX_PMALPHA_SRGB_OUT),
|
||||||
// if the input format type is IsSRGB(), then SRGB_IN is on by default
|
// if the input format type is IsSRGB(), then SRGB_IN is on by default
|
||||||
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
|
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
|
||||||
};
|
};
|
||||||
|
|
||||||
HRESULT __cdecl PremultiplyAlpha(_In_ const Image& srcImage, _In_ TEX_PMALPHA_FLAGS flags, _Out_ ScratchImage& image) noexcept;
|
HRESULT __cdecl PremultiplyAlpha(_In_ const Image& srcImage, _In_ TEX_PMALPHA_FLAGS flags, _Out_ ScratchImage& image) noexcept;
|
||||||
@ -663,34 +682,34 @@ namespace DirectX
|
|||||||
|
|
||||||
enum TEX_COMPRESS_FLAGS : unsigned long
|
enum TEX_COMPRESS_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
TEX_COMPRESS_DEFAULT = 0,
|
TEX_COMPRESS_DEFAULT = 0,
|
||||||
|
|
||||||
TEX_COMPRESS_RGB_DITHER = 0x10000,
|
TEX_COMPRESS_RGB_DITHER = 0x10000,
|
||||||
// Enables dithering RGB colors for BC1-3 compression
|
// Enables dithering RGB colors for BC1-3 compression
|
||||||
|
|
||||||
TEX_COMPRESS_A_DITHER = 0x20000,
|
TEX_COMPRESS_A_DITHER = 0x20000,
|
||||||
// Enables dithering alpha for BC1-3 compression
|
// Enables dithering alpha for BC1-3 compression
|
||||||
|
|
||||||
TEX_COMPRESS_DITHER = 0x30000,
|
TEX_COMPRESS_DITHER = 0x30000,
|
||||||
// Enables both RGB and alpha dithering for BC1-3 compression
|
// Enables both RGB and alpha dithering for BC1-3 compression
|
||||||
|
|
||||||
TEX_COMPRESS_UNIFORM = 0x40000,
|
TEX_COMPRESS_UNIFORM = 0x40000,
|
||||||
// Uniform color weighting for BC1-3 compression; by default uses perceptual weighting
|
// Uniform color weighting for BC1-3 compression; by default uses perceptual weighting
|
||||||
|
|
||||||
TEX_COMPRESS_BC7_USE_3SUBSETS = 0x80000,
|
TEX_COMPRESS_BC7_USE_3SUBSETS = 0x80000,
|
||||||
// Enables exhaustive search for BC7 compress for mode 0 and 2; by default skips trying these modes
|
// Enables exhaustive search for BC7 compress for mode 0 and 2; by default skips trying these modes
|
||||||
|
|
||||||
TEX_COMPRESS_BC7_QUICK = 0x100000,
|
TEX_COMPRESS_BC7_QUICK = 0x100000,
|
||||||
// Minimal modes (usually mode 6) for BC7 compression
|
// Minimal modes (usually mode 6) for BC7 compression
|
||||||
|
|
||||||
TEX_COMPRESS_SRGB_IN = 0x1000000,
|
TEX_COMPRESS_SRGB_IN = 0x1000000,
|
||||||
TEX_COMPRESS_SRGB_OUT = 0x2000000,
|
TEX_COMPRESS_SRGB_OUT = 0x2000000,
|
||||||
TEX_COMPRESS_SRGB = (TEX_COMPRESS_SRGB_IN | TEX_COMPRESS_SRGB_OUT),
|
TEX_COMPRESS_SRGB = (TEX_COMPRESS_SRGB_IN | TEX_COMPRESS_SRGB_OUT),
|
||||||
// if the input format type is IsSRGB(), then SRGB_IN is on by default
|
// if the input format type is IsSRGB(), then SRGB_IN is on by default
|
||||||
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
|
// if the output format type is IsSRGB(), then SRGB_OUT is on by default
|
||||||
|
|
||||||
TEX_COMPRESS_PARALLEL = 0x10000000,
|
TEX_COMPRESS_PARALLEL = 0x10000000,
|
||||||
// Compress is free to use multithreading to improve performance (by default it does not use multithreading)
|
// Compress is free to use multithreading to improve performance (by default it does not use multithreading)
|
||||||
};
|
};
|
||||||
|
|
||||||
HRESULT __cdecl Compress(
|
HRESULT __cdecl Compress(
|
||||||
@ -721,26 +740,26 @@ namespace DirectX
|
|||||||
|
|
||||||
enum CNMAP_FLAGS : unsigned long
|
enum CNMAP_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
CNMAP_DEFAULT = 0,
|
CNMAP_DEFAULT = 0,
|
||||||
|
|
||||||
CNMAP_CHANNEL_RED = 0x1,
|
CNMAP_CHANNEL_RED = 0x1,
|
||||||
CNMAP_CHANNEL_GREEN = 0x2,
|
CNMAP_CHANNEL_GREEN = 0x2,
|
||||||
CNMAP_CHANNEL_BLUE = 0x3,
|
CNMAP_CHANNEL_BLUE = 0x3,
|
||||||
CNMAP_CHANNEL_ALPHA = 0x4,
|
CNMAP_CHANNEL_ALPHA = 0x4,
|
||||||
CNMAP_CHANNEL_LUMINANCE = 0x5,
|
CNMAP_CHANNEL_LUMINANCE = 0x5,
|
||||||
// Channel selection when evaluting color value for height
|
// Channel selection when evaluting color value for height
|
||||||
// Luminance is a combination of red, green, and blue
|
// Luminance is a combination of red, green, and blue
|
||||||
|
|
||||||
CNMAP_MIRROR_U = 0x1000,
|
CNMAP_MIRROR_U = 0x1000,
|
||||||
CNMAP_MIRROR_V = 0x2000,
|
CNMAP_MIRROR_V = 0x2000,
|
||||||
CNMAP_MIRROR = 0x3000,
|
CNMAP_MIRROR = 0x3000,
|
||||||
// Use mirror semantics for scanline references (defaults to wrap)
|
// Use mirror semantics for scanline references (defaults to wrap)
|
||||||
|
|
||||||
CNMAP_INVERT_SIGN = 0x4000,
|
CNMAP_INVERT_SIGN = 0x4000,
|
||||||
// Inverts normal sign
|
// Inverts normal sign
|
||||||
|
|
||||||
CNMAP_COMPUTE_OCCLUSION = 0x8000,
|
CNMAP_COMPUTE_OCCLUSION = 0x8000,
|
||||||
// Computes a crude occlusion term stored in the alpha channel
|
// Computes a crude occlusion term stored in the alpha channel
|
||||||
};
|
};
|
||||||
|
|
||||||
HRESULT __cdecl ComputeNormalMap(
|
HRESULT __cdecl ComputeNormalMap(
|
||||||
@ -770,21 +789,21 @@ namespace DirectX
|
|||||||
|
|
||||||
enum CMSE_FLAGS : unsigned long
|
enum CMSE_FLAGS : unsigned long
|
||||||
{
|
{
|
||||||
CMSE_DEFAULT = 0,
|
CMSE_DEFAULT = 0,
|
||||||
|
|
||||||
CMSE_IMAGE1_SRGB = 0x1,
|
CMSE_IMAGE1_SRGB = 0x1,
|
||||||
CMSE_IMAGE2_SRGB = 0x2,
|
CMSE_IMAGE2_SRGB = 0x2,
|
||||||
// Indicates that image needs gamma correction before comparision
|
// Indicates that image needs gamma correction before comparision
|
||||||
|
|
||||||
CMSE_IGNORE_RED = 0x10,
|
CMSE_IGNORE_RED = 0x10,
|
||||||
CMSE_IGNORE_GREEN = 0x20,
|
CMSE_IGNORE_GREEN = 0x20,
|
||||||
CMSE_IGNORE_BLUE = 0x40,
|
CMSE_IGNORE_BLUE = 0x40,
|
||||||
CMSE_IGNORE_ALPHA = 0x80,
|
CMSE_IGNORE_ALPHA = 0x80,
|
||||||
// Ignore the channel when computing MSE
|
// Ignore the channel when computing MSE
|
||||||
|
|
||||||
CMSE_IMAGE1_X2_BIAS = 0x100,
|
CMSE_IMAGE1_X2_BIAS = 0x100,
|
||||||
CMSE_IMAGE2_X2_BIAS = 0x200,
|
CMSE_IMAGE2_X2_BIAS = 0x200,
|
||||||
// Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM)
|
// Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM)
|
||||||
};
|
};
|
||||||
|
|
||||||
HRESULT __cdecl ComputeMSE(_In_ const Image& image1, _In_ const Image& image2, _Out_ float& mse, _Out_writes_opt_(4) float* mseV, _In_ CMSE_FLAGS flags = CMSE_DEFAULT) noexcept;
|
HRESULT __cdecl ComputeMSE(_In_ const Image& image1, _In_ const Image& image2, _Out_ float& mse, _Out_writes_opt_(4) float* mseV, _In_ CMSE_FLAGS flags = CMSE_DEFAULT) noexcept;
|
||||||
@ -799,12 +818,12 @@ namespace DirectX
|
|||||||
HRESULT __cdecl TransformImage(
|
HRESULT __cdecl TransformImage(
|
||||||
_In_ const Image& image,
|
_In_ const Image& image,
|
||||||
_In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
|
_In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
|
||||||
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
|
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
|
||||||
ScratchImage& result);
|
ScratchImage& result);
|
||||||
HRESULT __cdecl TransformImage(
|
HRESULT __cdecl TransformImage(
|
||||||
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
_In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata,
|
||||||
_In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
|
_In_ std::function<void __cdecl(_Out_writes_(width) XMVECTOR* outPixels,
|
||||||
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
|
_In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc,
|
||||||
ScratchImage& result);
|
ScratchImage& result);
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
|
@ -53,31 +53,31 @@ inline bool __cdecl IsCompressed(DXGI_FORMAT fmt) noexcept
|
|||||||
{
|
{
|
||||||
switch (fmt)
|
switch (fmt)
|
||||||
{
|
{
|
||||||
case DXGI_FORMAT_BC1_TYPELESS:
|
case DXGI_FORMAT_BC1_TYPELESS:
|
||||||
case DXGI_FORMAT_BC1_UNORM:
|
case DXGI_FORMAT_BC1_UNORM:
|
||||||
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
||||||
case DXGI_FORMAT_BC2_TYPELESS:
|
case DXGI_FORMAT_BC2_TYPELESS:
|
||||||
case DXGI_FORMAT_BC2_UNORM:
|
case DXGI_FORMAT_BC2_UNORM:
|
||||||
case DXGI_FORMAT_BC2_UNORM_SRGB:
|
case DXGI_FORMAT_BC2_UNORM_SRGB:
|
||||||
case DXGI_FORMAT_BC3_TYPELESS:
|
case DXGI_FORMAT_BC3_TYPELESS:
|
||||||
case DXGI_FORMAT_BC3_UNORM:
|
case DXGI_FORMAT_BC3_UNORM:
|
||||||
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
||||||
case DXGI_FORMAT_BC4_TYPELESS:
|
case DXGI_FORMAT_BC4_TYPELESS:
|
||||||
case DXGI_FORMAT_BC4_UNORM:
|
case DXGI_FORMAT_BC4_UNORM:
|
||||||
case DXGI_FORMAT_BC4_SNORM:
|
case DXGI_FORMAT_BC4_SNORM:
|
||||||
case DXGI_FORMAT_BC5_TYPELESS:
|
case DXGI_FORMAT_BC5_TYPELESS:
|
||||||
case DXGI_FORMAT_BC5_UNORM:
|
case DXGI_FORMAT_BC5_UNORM:
|
||||||
case DXGI_FORMAT_BC5_SNORM:
|
case DXGI_FORMAT_BC5_SNORM:
|
||||||
case DXGI_FORMAT_BC6H_TYPELESS:
|
case DXGI_FORMAT_BC6H_TYPELESS:
|
||||||
case DXGI_FORMAT_BC6H_UF16:
|
case DXGI_FORMAT_BC6H_UF16:
|
||||||
case DXGI_FORMAT_BC6H_SF16:
|
case DXGI_FORMAT_BC6H_SF16:
|
||||||
case DXGI_FORMAT_BC7_TYPELESS:
|
case DXGI_FORMAT_BC7_TYPELESS:
|
||||||
case DXGI_FORMAT_BC7_UNORM:
|
case DXGI_FORMAT_BC7_UNORM:
|
||||||
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,14 +86,14 @@ inline bool __cdecl IsPalettized(DXGI_FORMAT fmt) noexcept
|
|||||||
{
|
{
|
||||||
switch (fmt)
|
switch (fmt)
|
||||||
{
|
{
|
||||||
case DXGI_FORMAT_AI44:
|
case DXGI_FORMAT_AI44:
|
||||||
case DXGI_FORMAT_IA44:
|
case DXGI_FORMAT_IA44:
|
||||||
case DXGI_FORMAT_P8:
|
case DXGI_FORMAT_P8:
|
||||||
case DXGI_FORMAT_A8P8:
|
case DXGI_FORMAT_A8P8:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,17 +102,17 @@ inline bool __cdecl IsSRGB(DXGI_FORMAT fmt) noexcept
|
|||||||
{
|
{
|
||||||
switch (fmt)
|
switch (fmt)
|
||||||
{
|
{
|
||||||
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
||||||
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
case DXGI_FORMAT_BC1_UNORM_SRGB:
|
||||||
case DXGI_FORMAT_BC2_UNORM_SRGB:
|
case DXGI_FORMAT_BC2_UNORM_SRGB:
|
||||||
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
case DXGI_FORMAT_BC3_UNORM_SRGB:
|
||||||
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
|
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
|
||||||
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
|
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
|
||||||
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
case DXGI_FORMAT_BC7_UNORM_SRGB:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ namespace
|
|||||||
{
|
{
|
||||||
for (size_t s = pw; s < 4; ++s)
|
for (size_t s = pw; s < 4; ++s)
|
||||||
{
|
{
|
||||||
#pragma prefast(suppress: 26000, "PREFAST false positive")
|
#pragma prefast(suppress: 26000, "PREFAST false positive")
|
||||||
temp[(t << 2) | s] = temp[(t << 2) | uSrc[s]];
|
temp[(t << 2) | s] = temp[(t << 2) | uSrc[s]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ namespace
|
|||||||
{
|
{
|
||||||
for (size_t s = 0; s < 4; ++s)
|
for (size_t s = 0; s < 4; ++s)
|
||||||
{
|
{
|
||||||
#pragma prefast(suppress: 26000, "PREFAST false positive")
|
#pragma prefast(suppress: 26000, "PREFAST false positive")
|
||||||
temp[(t << 2) | s] = temp[(uSrc[t] << 2) | s];
|
temp[(t << 2) | s] = temp[(uSrc[t] << 2) | s];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ namespace
|
|||||||
|
|
||||||
bool fail = false;
|
bool fail = false;
|
||||||
|
|
||||||
#pragma omp parallel for
|
#pragma omp parallel for
|
||||||
for (int nb = 0; nb < static_cast<int>(nBlocks); ++nb)
|
for (int nb = 0; nb < static_cast<int>(nBlocks); ++nb)
|
||||||
{
|
{
|
||||||
const int nbWidth = std::max<int>(1, int((image.width + 3) / 4));
|
const int nbWidth = std::max<int>(1, int((image.width + 3) / 4));
|
||||||
@ -615,11 +615,11 @@ HRESULT DirectX::Compress(
|
|||||||
// Compress single image
|
// Compress single image
|
||||||
if (compress & TEX_COMPRESS_PARALLEL)
|
if (compress & TEX_COMPRESS_PARALLEL)
|
||||||
{
|
{
|
||||||
#ifndef _OPENMP
|
#ifndef _OPENMP
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
#else
|
#else
|
||||||
hr = CompressBC_Parallel(srcImage, *img, GetBCFlags(compress), GetSRGBFlags(compress), threshold);
|
hr = CompressBC_Parallel(srcImage, *img, GetBCFlags(compress), GetSRGBFlags(compress), threshold);
|
||||||
#endif // _OPENMP
|
#endif // _OPENMP
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -687,9 +687,9 @@ HRESULT DirectX::Compress(
|
|||||||
|
|
||||||
if ((compress & TEX_COMPRESS_PARALLEL))
|
if ((compress & TEX_COMPRESS_PARALLEL))
|
||||||
{
|
{
|
||||||
#ifndef _OPENMP
|
#ifndef _OPENMP
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
#else
|
#else
|
||||||
if (compress & TEX_COMPRESS_PARALLEL)
|
if (compress & TEX_COMPRESS_PARALLEL)
|
||||||
{
|
{
|
||||||
hr = CompressBC_Parallel(src, dest[index], GetBCFlags(compress), GetSRGBFlags(compress), threshold);
|
hr = CompressBC_Parallel(src, dest[index], GetBCFlags(compress), GetSRGBFlags(compress), threshold);
|
||||||
@ -699,7 +699,7 @@ HRESULT DirectX::Compress(
|
|||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // _OPENMP
|
#endif // _OPENMP
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -311,108 +311,108 @@ HRESULT DirectX::Compress(
|
|||||||
{
|
{
|
||||||
case TEX_DIMENSION_TEXTURE1D:
|
case TEX_DIMENSION_TEXTURE1D:
|
||||||
case TEX_DIMENSION_TEXTURE2D:
|
case TEX_DIMENSION_TEXTURE2D:
|
||||||
{
|
|
||||||
size_t w = metadata.width;
|
|
||||||
size_t h = metadata.height;
|
|
||||||
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
{
|
||||||
hr = gpubc->Prepare(w, h, compress, format, alphaWeight);
|
size_t w = metadata.width;
|
||||||
if (FAILED(hr))
|
size_t h = metadata.height;
|
||||||
|
|
||||||
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
{
|
{
|
||||||
cImages.Release();
|
hr = gpubc->Prepare(w, h, compress, format, alphaWeight);
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t item = 0; item < metadata.arraySize; ++item)
|
|
||||||
{
|
|
||||||
const size_t index = metadata.ComputeIndex(level, item, 0);
|
|
||||||
if (index >= nimages)
|
|
||||||
{
|
|
||||||
cImages.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(dest[index].format == format);
|
|
||||||
|
|
||||||
const Image& src = srcImages[index];
|
|
||||||
|
|
||||||
if (src.width != dest[index].width || src.height != dest[index].height)
|
|
||||||
{
|
|
||||||
cImages.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = GPUCompress(gpubc.get(), src, dest[index], compress);
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
cImages.Release();
|
cImages.Release();
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (size_t item = 0; item < metadata.arraySize; ++item)
|
||||||
|
{
|
||||||
|
const size_t index = metadata.ComputeIndex(level, item, 0);
|
||||||
|
if (index >= nimages)
|
||||||
|
{
|
||||||
|
cImages.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(dest[index].format == format);
|
||||||
|
|
||||||
|
const Image& src = srcImages[index];
|
||||||
|
|
||||||
|
if (src.width != dest[index].width || src.height != dest[index].height)
|
||||||
|
{
|
||||||
|
cImages.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = GPUCompress(gpubc.get(), src, dest[index], compress);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
cImages.Release();
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (h > 1)
|
||||||
|
h >>= 1;
|
||||||
|
|
||||||
|
if (w > 1)
|
||||||
|
w >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h > 1)
|
|
||||||
h >>= 1;
|
|
||||||
|
|
||||||
if (w > 1)
|
|
||||||
w >>= 1;
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TEX_DIMENSION_TEXTURE3D:
|
case TEX_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
size_t w = metadata.width;
|
|
||||||
size_t h = metadata.height;
|
|
||||||
size_t d = metadata.depth;
|
|
||||||
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
{
|
||||||
hr = gpubc->Prepare(w, h, compress, format, alphaWeight);
|
size_t w = metadata.width;
|
||||||
if (FAILED(hr))
|
size_t h = metadata.height;
|
||||||
|
size_t d = metadata.depth;
|
||||||
|
|
||||||
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
{
|
{
|
||||||
cImages.Release();
|
hr = gpubc->Prepare(w, h, compress, format, alphaWeight);
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t slice = 0; slice < d; ++slice)
|
|
||||||
{
|
|
||||||
const size_t index = metadata.ComputeIndex(level, 0, slice);
|
|
||||||
if (index >= nimages)
|
|
||||||
{
|
|
||||||
cImages.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(dest[index].format == format);
|
|
||||||
|
|
||||||
const Image& src = srcImages[index];
|
|
||||||
|
|
||||||
if (src.width != dest[index].width || src.height != dest[index].height)
|
|
||||||
{
|
|
||||||
cImages.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = GPUCompress(gpubc.get(), src, dest[index], compress);
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
cImages.Release();
|
cImages.Release();
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (size_t slice = 0; slice < d; ++slice)
|
||||||
|
{
|
||||||
|
const size_t index = metadata.ComputeIndex(level, 0, slice);
|
||||||
|
if (index >= nimages)
|
||||||
|
{
|
||||||
|
cImages.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(dest[index].format == format);
|
||||||
|
|
||||||
|
const Image& src = srcImages[index];
|
||||||
|
|
||||||
|
if (src.width != dest[index].width || src.height != dest[index].height)
|
||||||
|
{
|
||||||
|
cImages.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = GPUCompress(gpubc.get(), src, dest[index], compress);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
cImages.Release();
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (h > 1)
|
||||||
|
h >>= 1;
|
||||||
|
|
||||||
|
if (w > 1)
|
||||||
|
w >>= 1;
|
||||||
|
|
||||||
|
if (d > 1)
|
||||||
|
d >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h > 1)
|
|
||||||
h >>= 1;
|
|
||||||
|
|
||||||
if (w > 1)
|
|
||||||
w >>= 1;
|
|
||||||
|
|
||||||
if (d > 1)
|
|
||||||
d >>= 1;
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return HRESULT_E_NOT_SUPPORTED;
|
return HRESULT_E_NOT_SUPPORTED;
|
||||||
|
@ -69,7 +69,8 @@ namespace
|
|||||||
{
|
{
|
||||||
Exponent--;
|
Exponent--;
|
||||||
Mantissa <<= 1;
|
Mantissa <<= 1;
|
||||||
} while ((Mantissa & 0x80) == 0);
|
}
|
||||||
|
while ((Mantissa & 0x80) == 0);
|
||||||
|
|
||||||
Mantissa &= 0x7F;
|
Mantissa &= 0x7F;
|
||||||
}
|
}
|
||||||
@ -135,7 +136,8 @@ namespace
|
|||||||
{
|
{
|
||||||
Exponent--;
|
Exponent--;
|
||||||
Mantissa <<= 1;
|
Mantissa <<= 1;
|
||||||
} while ((Mantissa & 0x40) == 0);
|
}
|
||||||
|
while ((Mantissa & 0x40) == 0);
|
||||||
|
|
||||||
Mantissa &= 0x3F;
|
Mantissa &= 0x3F;
|
||||||
}
|
}
|
||||||
@ -190,9 +192,9 @@ namespace
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
const XMVECTORF32 g_Grayscale = { { { 0.2125f, 0.7154f, 0.0721f, 0.0f } } };
|
const XMVECTORF32 g_Grayscale = { { { 0.2125f, 0.7154f, 0.0721f, 0.0f } } };
|
||||||
const XMVECTORF32 g_HalfMin = { { { -65504.f, -65504.f, -65504.f, -65504.f } } };
|
const XMVECTORF32 g_HalfMin = { { { -65504.f, -65504.f, -65504.f, -65504.f } } };
|
||||||
const XMVECTORF32 g_HalfMax = { { { 65504.f, 65504.f, 65504.f, 65504.f } } };
|
const XMVECTORF32 g_HalfMax = { { { 65504.f, 65504.f, 65504.f, 65504.f } } };
|
||||||
const XMVECTORF32 g_8BitBias = { { { 0.5f / 255.f, 0.5f / 255.f, 0.5f / 255.f, 0.5f / 255.f } } };
|
const XMVECTORF32 g_8BitBias = { { { 0.5f / 255.f, 0.5f / 255.f, 0.5f / 255.f, 0.5f / 255.f } } };
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
@ -776,11 +778,11 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline(
|
|||||||
switch (static_cast<int>(format))
|
switch (static_cast<int>(format))
|
||||||
{
|
{
|
||||||
case DXGI_FORMAT_R32G32B32A32_FLOAT:
|
case DXGI_FORMAT_R32G32B32A32_FLOAT:
|
||||||
{
|
{
|
||||||
const size_t msize = (size > (sizeof(XMVECTOR)*count)) ? (sizeof(XMVECTOR)*count) : size;
|
const size_t msize = (size > (sizeof(XMVECTOR)*count)) ? (sizeof(XMVECTOR)*count) : size;
|
||||||
memcpy(dPtr, pSource, msize);
|
memcpy(dPtr, pSource, msize);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case DXGI_FORMAT_R32G32B32A32_UINT:
|
case DXGI_FORMAT_R32G32B32A32_UINT:
|
||||||
LOAD_SCANLINE(XMUINT4, XMLoadUInt4)
|
LOAD_SCANLINE(XMUINT4, XMLoadUInt4)
|
||||||
@ -822,6 +824,24 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline(
|
|||||||
LOAD_SCANLINE2(XMINT2, XMLoadSInt2, g_XMIdentityR3)
|
LOAD_SCANLINE2(XMINT2, XMLoadSInt2, g_XMIdentityR3)
|
||||||
|
|
||||||
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
|
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
|
||||||
|
{
|
||||||
|
constexpr size_t psize = sizeof(float) + sizeof(uint32_t);
|
||||||
|
if (size >= psize)
|
||||||
|
{
|
||||||
|
auto sPtr = static_cast<const float*>(pSource);
|
||||||
|
for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
|
||||||
|
{
|
||||||
|
auto ps8 = reinterpret_cast<const uint8_t*>(&sPtr[1]);
|
||||||
|
if (dPtr >= ePtr) break;
|
||||||
|
*(dPtr++) = XMVectorSet(sPtr[0], static_cast<float>(*ps8), 0.f, 1.f);
|
||||||
|
sPtr += 2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
|
||||||
{
|
{
|
||||||
constexpr size_t psize = sizeof(float) + sizeof(uint32_t);
|
constexpr size_t psize = sizeof(float) + sizeof(uint32_t);
|
||||||
if (size >= psize)
|
if (size >= psize)
|
||||||
@ -829,9 +849,8 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline(
|
|||||||
auto sPtr = static_cast<const float*>(pSource);
|
auto sPtr = static_cast<const float*>(pSource);
|
||||||
for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
|
for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
|
||||||
{
|
{
|
||||||
auto ps8 = reinterpret_cast<const uint8_t*>(&sPtr[1]);
|
|
||||||
if (dPtr >= ePtr) break;
|
if (dPtr >= ePtr) break;
|
||||||
*(dPtr++) = XMVectorSet(sPtr[0], static_cast<float>(*ps8), 0.f, 1.f);
|
*(dPtr++) = XMVectorSet(sPtr[0], 0.f /* typeless component assumed zero */, 0.f, 1.f);
|
||||||
sPtr += 2;
|
sPtr += 2;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -839,40 +858,23 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline(
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
|
|
||||||
{
|
|
||||||
constexpr size_t psize = sizeof(float) + sizeof(uint32_t);
|
|
||||||
if (size >= psize)
|
|
||||||
{
|
|
||||||
auto sPtr = static_cast<const float*>(pSource);
|
|
||||||
for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
|
|
||||||
{
|
|
||||||
if (dPtr >= ePtr) break;
|
|
||||||
*(dPtr++) = XMVectorSet(sPtr[0], 0.f /* typeless component assumed zero */, 0.f, 1.f);
|
|
||||||
sPtr += 2;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
|
case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
|
||||||
{
|
|
||||||
constexpr size_t psize = sizeof(float) + sizeof(uint32_t);
|
|
||||||
if (size >= psize)
|
|
||||||
{
|
{
|
||||||
auto sPtr = static_cast<const float*>(pSource);
|
constexpr size_t psize = sizeof(float) + sizeof(uint32_t);
|
||||||
for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
|
if (size >= psize)
|
||||||
{
|
{
|
||||||
auto pg8 = reinterpret_cast<const uint8_t*>(&sPtr[1]);
|
auto sPtr = static_cast<const float*>(pSource);
|
||||||
if (dPtr >= ePtr) break;
|
for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
|
||||||
*(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, static_cast<float>(*pg8), 0.f, 1.f);
|
{
|
||||||
sPtr += 2;
|
auto pg8 = reinterpret_cast<const uint8_t*>(&sPtr[1]);
|
||||||
|
if (dPtr >= ePtr) break;
|
||||||
|
*(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, static_cast<float>(*pg8), 0.f, 1.f);
|
||||||
|
sPtr += 2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
||||||
LOAD_SCANLINE(XMUDECN4, XMLoadUDecN4)
|
LOAD_SCANLINE(XMUDECN4, XMLoadUDecN4)
|
||||||
@ -1687,26 +1689,26 @@ bool DirectX::Internal::StoreScanline(
|
|||||||
STORE_SCANLINE(XMINT2, XMStoreSInt2)
|
STORE_SCANLINE(XMINT2, XMStoreSInt2)
|
||||||
|
|
||||||
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
|
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
|
||||||
{
|
|
||||||
constexpr size_t psize = sizeof(float) + sizeof(uint32_t);
|
|
||||||
if (size >= psize)
|
|
||||||
{
|
{
|
||||||
auto dPtr = static_cast<float*>(pDestination);
|
constexpr size_t psize = sizeof(float) + sizeof(uint32_t);
|
||||||
for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
|
if (size >= psize)
|
||||||
{
|
{
|
||||||
if (sPtr >= ePtr) break;
|
auto dPtr = static_cast<float*>(pDestination);
|
||||||
XMFLOAT4 f;
|
for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
|
||||||
XMStoreFloat4(&f, *sPtr++);
|
{
|
||||||
dPtr[0] = f.x;
|
if (sPtr >= ePtr) break;
|
||||||
auto ps8 = reinterpret_cast<uint8_t*>(&dPtr[1]);
|
XMFLOAT4 f;
|
||||||
ps8[0] = static_cast<uint8_t>(std::min<float>(255.f, std::max<float>(0.f, f.y)));
|
XMStoreFloat4(&f, *sPtr++);
|
||||||
ps8[1] = ps8[2] = ps8[3] = 0;
|
dPtr[0] = f.x;
|
||||||
dPtr += 2;
|
auto ps8 = reinterpret_cast<uint8_t*>(&dPtr[1]);
|
||||||
|
ps8[0] = static_cast<uint8_t>(std::min<float>(255.f, std::max<float>(0.f, f.y)));
|
||||||
|
ps8[1] = ps8[2] = ps8[3] = 0;
|
||||||
|
dPtr += 2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
||||||
STORE_SCANLINE(XMUDECN4, XMStoreUDecN4)
|
STORE_SCANLINE(XMUDECN4, XMStoreUDecN4)
|
||||||
@ -3227,28 +3229,28 @@ void DirectX::Internal::ConvertScanline(
|
|||||||
switch (flags & (TEX_FILTER_RGB_COPY_RED | TEX_FILTER_RGB_COPY_GREEN | TEX_FILTER_RGB_COPY_BLUE))
|
switch (flags & (TEX_FILTER_RGB_COPY_RED | TEX_FILTER_RGB_COPY_GREEN | TEX_FILTER_RGB_COPY_BLUE))
|
||||||
{
|
{
|
||||||
case TEX_FILTER_RGB_COPY_GREEN:
|
case TEX_FILTER_RGB_COPY_GREEN:
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
const XMVECTOR v1 = XMVectorSplatY(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1000);
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
const XMVECTOR v1 = XMVectorSplatY(v);
|
||||||
|
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TEX_FILTER_RGB_COPY_BLUE:
|
case TEX_FILTER_RGB_COPY_BLUE:
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
const XMVECTOR v1 = XMVectorSplatZ(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1000);
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
const XMVECTOR v1 = XMVectorSplatZ(v);
|
||||||
|
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ((in->flags & CONVF_UNORM) && ((in->flags & CONVF_RGB_MASK) == (CONVF_R | CONVF_G | CONVF_B)))
|
if ((in->flags & CONVF_UNORM) && ((in->flags & CONVF_RGB_MASK) == (CONVF_R | CONVF_G | CONVF_B)))
|
||||||
@ -3263,25 +3265,25 @@ void DirectX::Internal::ConvertScanline(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (__cplusplus >= 201703L)
|
#if (__cplusplus >= 201703L)
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
#elif defined(__clang__)
|
#elif defined(__clang__)
|
||||||
[[clang::fallthrough]];
|
[[clang::fallthrough]];
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
__fallthrough;
|
__fallthrough;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case TEX_FILTER_RGB_COPY_RED:
|
case TEX_FILTER_RGB_COPY_RED:
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
const XMVECTOR v1 = XMVectorSplatX(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1000);
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
const XMVECTOR v1 = XMVectorSplatX(v);
|
||||||
|
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finialize type conversion for depth (red channel)
|
// Finialize type conversion for depth (red channel)
|
||||||
@ -3520,26 +3522,26 @@ void DirectX::Internal::ConvertScanline(
|
|||||||
switch (flags & (TEX_FILTER_RGB_COPY_RED | TEX_FILTER_RGB_COPY_GREEN | TEX_FILTER_RGB_COPY_BLUE))
|
switch (flags & (TEX_FILTER_RGB_COPY_RED | TEX_FILTER_RGB_COPY_GREEN | TEX_FILTER_RGB_COPY_BLUE))
|
||||||
{
|
{
|
||||||
case TEX_FILTER_RGB_COPY_GREEN:
|
case TEX_FILTER_RGB_COPY_GREEN:
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
*ptr++ = XMVectorSplatY(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
*ptr++ = XMVectorSplatY(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TEX_FILTER_RGB_COPY_BLUE:
|
case TEX_FILTER_RGB_COPY_BLUE:
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
*ptr++ = XMVectorSplatZ(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
*ptr++ = XMVectorSplatZ(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ((in->flags & CONVF_UNORM) && ((in->flags & CONVF_RGB_MASK) == (CONVF_R | CONVF_G | CONVF_B)))
|
if ((in->flags & CONVF_UNORM) && ((in->flags & CONVF_RGB_MASK) == (CONVF_R | CONVF_G | CONVF_B)))
|
||||||
@ -3553,24 +3555,24 @@ void DirectX::Internal::ConvertScanline(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (__cplusplus >= 201703L)
|
#if (__cplusplus >= 201703L)
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
#elif defined(__clang__)
|
#elif defined(__clang__)
|
||||||
[[clang::fallthrough]];
|
[[clang::fallthrough]];
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
__fallthrough;
|
__fallthrough;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case TEX_FILTER_RGB_COPY_RED:
|
case TEX_FILTER_RGB_COPY_RED:
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
*ptr++ = XMVectorSplatX(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
*ptr++ = XMVectorSplatX(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (((in->flags & CONVF_RGBA_MASK) == CONVF_A) && !(out->flags & CONVF_A))
|
else if (((in->flags & CONVF_RGBA_MASK) == CONVF_A) && !(out->flags & CONVF_A))
|
||||||
@ -3616,28 +3618,28 @@ void DirectX::Internal::ConvertScanline(
|
|||||||
switch (flags & (TEX_FILTER_RGB_COPY_RED | TEX_FILTER_RGB_COPY_GREEN | TEX_FILTER_RGB_COPY_BLUE))
|
switch (flags & (TEX_FILTER_RGB_COPY_RED | TEX_FILTER_RGB_COPY_GREEN | TEX_FILTER_RGB_COPY_BLUE))
|
||||||
{
|
{
|
||||||
case TEX_FILTER_RGB_COPY_GREEN:
|
case TEX_FILTER_RGB_COPY_GREEN:
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
const XMVECTOR v1 = XMVectorSplatY(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1110);
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
const XMVECTOR v1 = XMVectorSplatY(v);
|
||||||
|
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1110);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TEX_FILTER_RGB_COPY_BLUE:
|
case TEX_FILTER_RGB_COPY_BLUE:
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
const XMVECTOR v1 = XMVectorSplatZ(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1110);
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
const XMVECTOR v1 = XMVectorSplatZ(v);
|
||||||
|
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1110);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (in->flags & CONVF_UNORM)
|
if (in->flags & CONVF_UNORM)
|
||||||
@ -3652,13 +3654,13 @@ void DirectX::Internal::ConvertScanline(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (__cplusplus >= 201703L)
|
#if (__cplusplus >= 201703L)
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
#elif defined(__clang__)
|
#elif defined(__clang__)
|
||||||
[[clang::fallthrough]];
|
[[clang::fallthrough]];
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
__fallthrough;
|
__fallthrough;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case TEX_FILTER_RGB_COPY_RED:
|
case TEX_FILTER_RGB_COPY_RED:
|
||||||
// Leave data unchanged and the store will handle this...
|
// Leave data unchanged and the store will handle this...
|
||||||
@ -3670,31 +3672,31 @@ void DirectX::Internal::ConvertScanline(
|
|||||||
// RGB format -> RG format
|
// RGB format -> RG format
|
||||||
switch (static_cast<int>(flags & (TEX_FILTER_RGB_COPY_RED | TEX_FILTER_RGB_COPY_GREEN | TEX_FILTER_RGB_COPY_BLUE)))
|
switch (static_cast<int>(flags & (TEX_FILTER_RGB_COPY_RED | TEX_FILTER_RGB_COPY_GREEN | TEX_FILTER_RGB_COPY_BLUE)))
|
||||||
{
|
{
|
||||||
case static_cast<int>(TEX_FILTER_RGB_COPY_RED) | static_cast<int>(TEX_FILTER_RGB_COPY_BLUE):
|
case (static_cast<int>(TEX_FILTER_RGB_COPY_RED) | static_cast<int>(TEX_FILTER_RGB_COPY_BLUE)):
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
const XMVECTOR v1 = XMVectorSwizzle<0, 2, 0, 2>(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1100);
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
const XMVECTOR v1 = XMVectorSwizzle<0, 2, 0, 2>(v);
|
||||||
|
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case static_cast<int>(TEX_FILTER_RGB_COPY_GREEN) | static_cast<int>(TEX_FILTER_RGB_COPY_BLUE):
|
case (static_cast<int>(TEX_FILTER_RGB_COPY_GREEN) | static_cast<int>(TEX_FILTER_RGB_COPY_BLUE)):
|
||||||
{
|
|
||||||
XMVECTOR* ptr = pBuffer;
|
|
||||||
for (size_t i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR v = *ptr;
|
XMVECTOR* ptr = pBuffer;
|
||||||
const XMVECTOR v1 = XMVectorSwizzle<1, 2, 3, 0>(v);
|
for (size_t i = 0; i < count; ++i)
|
||||||
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1100);
|
{
|
||||||
|
const XMVECTOR v = *ptr;
|
||||||
|
const XMVECTOR v1 = XMVectorSwizzle<1, 2, 3, 0>(v);
|
||||||
|
*ptr++ = XMVectorSelect(v, v1, g_XMSelect1100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case static_cast<int>(TEX_FILTER_RGB_COPY_RED) | static_cast<int>(TEX_FILTER_RGB_COPY_GREEN):
|
case (static_cast<int>(TEX_FILTER_RGB_COPY_RED) | static_cast<int>(TEX_FILTER_RGB_COPY_GREEN)):
|
||||||
default:
|
default:
|
||||||
// Leave data unchanged and the store will handle this...
|
// Leave data unchanged and the store will handle this...
|
||||||
break;
|
break;
|
||||||
@ -3733,15 +3735,15 @@ namespace
|
|||||||
-0.468750f, 0.031250f, -0.343750f, 0.156250f, -0.468750f, 0.031250f, -0.343750f, 0.156250f,
|
-0.468750f, 0.031250f, -0.343750f, 0.156250f, -0.468750f, 0.031250f, -0.343750f, 0.156250f,
|
||||||
};
|
};
|
||||||
|
|
||||||
const XMVECTORF32 g_Scale16pc = { { { 65535.f, 65535.f, 65535.f, 65535.f } } };
|
const XMVECTORF32 g_Scale16pc = { { { 65535.f, 65535.f, 65535.f, 65535.f } } };
|
||||||
const XMVECTORF32 g_Scale15pc = { { { 32767.f, 32767.f, 32767.f, 32767.f } } };
|
const XMVECTORF32 g_Scale15pc = { { { 32767.f, 32767.f, 32767.f, 32767.f } } };
|
||||||
const XMVECTORF32 g_Scale10pc = { { { 1023.f, 1023.f, 1023.f, 3.f } } };
|
const XMVECTORF32 g_Scale10pc = { { { 1023.f, 1023.f, 1023.f, 3.f } } };
|
||||||
const XMVECTORF32 g_Scale9pc = { { { 511.f, 511.f, 511.f, 3.f } } };
|
const XMVECTORF32 g_Scale9pc = { { { 511.f, 511.f, 511.f, 3.f } } };
|
||||||
const XMVECTORF32 g_Scale8pc = { { { 255.f, 255.f, 255.f, 255.f } } };
|
const XMVECTORF32 g_Scale8pc = { { { 255.f, 255.f, 255.f, 255.f } } };
|
||||||
const XMVECTORF32 g_Scale7pc = { { { 127.f, 127.f, 127.f, 127.f } } };
|
const XMVECTORF32 g_Scale7pc = { { { 127.f, 127.f, 127.f, 127.f } } };
|
||||||
const XMVECTORF32 g_Scale565pc = { { { 31.f, 63.f, 31.f, 1.f } } };
|
const XMVECTORF32 g_Scale565pc = { { { 31.f, 63.f, 31.f, 1.f } } };
|
||||||
const XMVECTORF32 g_Scale5551pc = { { { 31.f, 31.f, 31.f, 1.f } } };
|
const XMVECTORF32 g_Scale5551pc = { { { 31.f, 31.f, 31.f, 1.f } } };
|
||||||
const XMVECTORF32 g_Scale4pc = { { { 15.f, 15.f, 15.f, 15.f } } };
|
const XMVECTORF32 g_Scale4pc = { { { 15.f, 15.f, 15.f, 15.f } } };
|
||||||
|
|
||||||
const XMVECTORF32 g_ErrorWeight3 = { { { 3.f / 16.f, 3.f / 16.f, 3.f / 16.f, 3.f / 16.f } } };
|
const XMVECTORF32 g_ErrorWeight3 = { { { 3.f / 16.f, 3.f / 16.f, 3.f / 16.f, 3.f / 16.f } } };
|
||||||
const XMVECTORF32 g_ErrorWeight5 = { { { 5.f / 16.f, 5.f / 16.f, 5.f / 16.f, 5.f / 16.f } } };
|
const XMVECTORF32 g_ErrorWeight5 = { { { 5.f / 16.f, 5.f / 16.f, 5.f / 16.f, 5.f / 16.f } } };
|
||||||
@ -3997,7 +3999,7 @@ bool DirectX::Internal::StoreScanlineDither(
|
|||||||
if (size >= sizeof(XMUDEC4))
|
if (size >= sizeof(XMUDEC4))
|
||||||
{
|
{
|
||||||
static const XMVECTORF32 Scale = { { { 510.0f, 510.0f, 510.0f, 3.0f } } };
|
static const XMVECTORF32 Scale = { { { 510.0f, 510.0f, 510.0f, 3.0f } } };
|
||||||
static const XMVECTORF32 Bias = { { { 384.0f, 384.0f, 384.0f, 0.0f } } };
|
static const XMVECTORF32 Bias = { { { 384.0f, 384.0f, 384.0f, 0.0f } } };
|
||||||
static const XMVECTORF32 MinXR = { { { -0.7529f, -0.7529f, -0.7529f, 0.f } } };
|
static const XMVECTORF32 MinXR = { { { -0.7529f, -0.7529f, -0.7529f, 0.f } } };
|
||||||
static const XMVECTORF32 MaxXR = { { { 1.2529f, 1.2529f, 1.2529f, 1.0f } } };
|
static const XMVECTORF32 MaxXR = { { { 1.2529f, 1.2529f, 1.2529f, 1.0f } } };
|
||||||
|
|
||||||
@ -4018,8 +4020,8 @@ bool DirectX::Internal::StoreScanlineDither(
|
|||||||
vError = XMVectorDivide(vError, Scale);
|
vError = XMVectorDivide(vError, Scale);
|
||||||
|
|
||||||
// Distribute error to next scanline and next pixel
|
// Distribute error to next scanline and next pixel
|
||||||
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
||||||
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
||||||
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
||||||
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
||||||
}
|
}
|
||||||
@ -4075,8 +4077,8 @@ bool DirectX::Internal::StoreScanlineDither(
|
|||||||
case DXGI_FORMAT_D24_UNORM_S8_UINT:
|
case DXGI_FORMAT_D24_UNORM_S8_UINT:
|
||||||
if (size >= sizeof(uint32_t))
|
if (size >= sizeof(uint32_t))
|
||||||
{
|
{
|
||||||
static const XMVECTORF32 Clamp = { { { 1.f, 255.f, 0.f, 0.f } } };
|
static const XMVECTORF32 Clamp = { { { 1.f, 255.f, 0.f, 0.f } } };
|
||||||
static const XMVECTORF32 Scale = { { { 16777215.f, 1.f, 0.f, 0.f } } };
|
static const XMVECTORF32 Scale = { { { 16777215.f, 1.f, 0.f, 0.f } } };
|
||||||
static const XMVECTORF32 Scale2 = { { { 16777215.f, 255.f, 0.f, 0.f } } };
|
static const XMVECTORF32 Scale2 = { { { 16777215.f, 255.f, 0.f, 0.f } } };
|
||||||
|
|
||||||
uint32_t * __restrict dest = static_cast<uint32_t*>(pDestination);
|
uint32_t * __restrict dest = static_cast<uint32_t*>(pDestination);
|
||||||
@ -4097,8 +4099,8 @@ bool DirectX::Internal::StoreScanlineDither(
|
|||||||
vError = XMVectorDivide(vError, Scale);
|
vError = XMVectorDivide(vError, Scale);
|
||||||
|
|
||||||
// Distribute error to next scanline and next pixel
|
// Distribute error to next scanline and next pixel
|
||||||
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
||||||
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
||||||
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
||||||
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
||||||
}
|
}
|
||||||
@ -4185,8 +4187,8 @@ bool DirectX::Internal::StoreScanlineDither(
|
|||||||
vError = XMVectorDivide(vError, g_Scale565pc);
|
vError = XMVectorDivide(vError, g_Scale565pc);
|
||||||
|
|
||||||
// Distribute error to next scanline and next pixel
|
// Distribute error to next scanline and next pixel
|
||||||
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
||||||
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
||||||
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
||||||
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
||||||
}
|
}
|
||||||
@ -4234,8 +4236,8 @@ bool DirectX::Internal::StoreScanlineDither(
|
|||||||
vError = XMVectorDivide(vError, g_Scale5551pc);
|
vError = XMVectorDivide(vError, g_Scale5551pc);
|
||||||
|
|
||||||
// Distribute error to next scanline and next pixel
|
// Distribute error to next scanline and next pixel
|
||||||
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
||||||
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
||||||
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
||||||
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
||||||
}
|
}
|
||||||
@ -4289,8 +4291,8 @@ bool DirectX::Internal::StoreScanlineDither(
|
|||||||
vError = XMVectorDivide(vError, g_Scale8pc);
|
vError = XMVectorDivide(vError, g_Scale8pc);
|
||||||
|
|
||||||
// Distribute error to next scanline and next pixel
|
// Distribute error to next scanline and next pixel
|
||||||
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
||||||
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
||||||
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
||||||
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
||||||
}
|
}
|
||||||
@ -4344,8 +4346,8 @@ bool DirectX::Internal::StoreScanlineDither(
|
|||||||
vError = XMVectorDivide(vError, g_Scale4pc);
|
vError = XMVectorDivide(vError, g_Scale4pc);
|
||||||
|
|
||||||
// Distribute error to next scanline and next pixel
|
// Distribute error to next scanline and next pixel
|
||||||
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]);
|
||||||
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]);
|
||||||
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]);
|
||||||
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
vError = XMVectorMultiply(vError, g_ErrorWeight7);
|
||||||
}
|
}
|
||||||
@ -4392,14 +4394,14 @@ namespace
|
|||||||
_Out_ WICPixelFormatGUID& pfGUID,
|
_Out_ WICPixelFormatGUID& pfGUID,
|
||||||
_Out_ WICPixelFormatGUID& targetGUID) noexcept
|
_Out_ WICPixelFormatGUID& targetGUID) noexcept
|
||||||
{
|
{
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
UNREFERENCED_PARAMETER(filter);
|
UNREFERENCED_PARAMETER(filter);
|
||||||
UNREFERENCED_PARAMETER(sformat);
|
UNREFERENCED_PARAMETER(sformat);
|
||||||
UNREFERENCED_PARAMETER(tformat);
|
UNREFERENCED_PARAMETER(tformat);
|
||||||
UNREFERENCED_PARAMETER(pfGUID);
|
UNREFERENCED_PARAMETER(pfGUID);
|
||||||
UNREFERENCED_PARAMETER(targetGUID);
|
UNREFERENCED_PARAMETER(targetGUID);
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
memset(&pfGUID, 0, sizeof(GUID));
|
memset(&pfGUID, 0, sizeof(GUID));
|
||||||
memset(&targetGUID, 0, sizeof(GUID));
|
memset(&targetGUID, 0, sizeof(GUID));
|
||||||
|
|
||||||
@ -4434,7 +4436,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for special cases
|
// Check for special cases
|
||||||
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
||||||
if (sformat == DXGI_FORMAT_R16G16B16A16_FLOAT
|
if (sformat == DXGI_FORMAT_R16G16B16A16_FLOAT
|
||||||
|| sformat == DXGI_FORMAT_R16_FLOAT
|
|| sformat == DXGI_FORMAT_R16_FLOAT
|
||||||
|| tformat == DXGI_FORMAT_R16G16B16A16_FLOAT
|
|| tformat == DXGI_FORMAT_R16G16B16A16_FLOAT
|
||||||
@ -4443,7 +4445,7 @@ namespace
|
|||||||
// Use non-WIC code paths as these conversions are not supported by Xbox version of WIC
|
// Use non-WIC code paths as these conversions are not supported by Xbox version of WIC
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (sformat)
|
switch (sformat)
|
||||||
{
|
{
|
||||||
@ -4541,7 +4543,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
@ -4555,7 +4557,7 @@ namespace
|
|||||||
_In_ float threshold,
|
_In_ float threshold,
|
||||||
_In_ const Image& destImage)
|
_In_ const Image& destImage)
|
||||||
{
|
{
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
UNREFERENCED_PARAMETER(srcImage);
|
UNREFERENCED_PARAMETER(srcImage);
|
||||||
UNREFERENCED_PARAMETER(pfGUID);
|
UNREFERENCED_PARAMETER(pfGUID);
|
||||||
UNREFERENCED_PARAMETER(targetGUID);
|
UNREFERENCED_PARAMETER(targetGUID);
|
||||||
@ -4563,7 +4565,7 @@ namespace
|
|||||||
UNREFERENCED_PARAMETER(threshold);
|
UNREFERENCED_PARAMETER(threshold);
|
||||||
UNREFERENCED_PARAMETER(destImage);
|
UNREFERENCED_PARAMETER(destImage);
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
#else
|
#else
|
||||||
assert(srcImage.width == destImage.width);
|
assert(srcImage.width == destImage.width);
|
||||||
assert(srcImage.height == destImage.height);
|
assert(srcImage.height == destImage.height);
|
||||||
|
|
||||||
@ -4609,7 +4611,7 @@ namespace
|
|||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
@ -4773,6 +4775,10 @@ namespace
|
|||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic ignored "-Wextra-semi-stmt"
|
||||||
|
#endif
|
||||||
|
|
||||||
HRESULT ConvertToSinglePlane_(_In_ const Image& srcImage, _In_ const Image& destImage) noexcept
|
HRESULT ConvertToSinglePlane_(_In_ const Image& srcImage, _In_ const Image& destImage) noexcept
|
||||||
{
|
{
|
||||||
assert(srcImage.width == destImage.width);
|
assert(srcImage.width == destImage.width);
|
||||||
@ -4787,17 +4793,17 @@ namespace
|
|||||||
{
|
{
|
||||||
case DXGI_FORMAT_NV12:
|
case DXGI_FORMAT_NV12:
|
||||||
assert(destImage.format == DXGI_FORMAT_YUY2);
|
assert(destImage.format == DXGI_FORMAT_YUY2);
|
||||||
CONVERT_420_TO_422(uint8_t, XMUBYTEN4)
|
CONVERT_420_TO_422(uint8_t, XMUBYTEN4);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
||||||
case DXGI_FORMAT_P010:
|
case DXGI_FORMAT_P010:
|
||||||
assert(destImage.format == DXGI_FORMAT_Y210);
|
assert(destImage.format == DXGI_FORMAT_Y210);
|
||||||
CONVERT_420_TO_422(uint16_t, XMUSHORTN4)
|
CONVERT_420_TO_422(uint16_t, XMUSHORTN4);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
||||||
case DXGI_FORMAT_P016:
|
case DXGI_FORMAT_P016:
|
||||||
assert(destImage.format == DXGI_FORMAT_Y216);
|
assert(destImage.format == DXGI_FORMAT_Y216);
|
||||||
CONVERT_420_TO_422(uint16_t, XMUSHORTN4)
|
CONVERT_420_TO_422(uint16_t, XMUSHORTN4);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
||||||
case DXGI_FORMAT_NV11:
|
case DXGI_FORMAT_NV11:
|
||||||
@ -5007,62 +5013,62 @@ HRESULT DirectX::Convert(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TEX_DIMENSION_TEXTURE3D:
|
case TEX_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
size_t index = 0;
|
|
||||||
size_t d = metadata.depth;
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
{
|
||||||
for (size_t slice = 0; slice < d; ++slice, ++index)
|
size_t index = 0;
|
||||||
|
size_t d = metadata.depth;
|
||||||
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
{
|
{
|
||||||
if (index >= nimages)
|
for (size_t slice = 0; slice < d; ++slice, ++index)
|
||||||
{
|
{
|
||||||
result.Release();
|
if (index >= nimages)
|
||||||
return E_FAIL;
|
{
|
||||||
|
result.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Image& src = srcImages[index];
|
||||||
|
if (src.format != metadata.format)
|
||||||
|
{
|
||||||
|
result.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((src.width > UINT32_MAX) || (src.height > UINT32_MAX))
|
||||||
|
{
|
||||||
|
result.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Image& dst = dest[index];
|
||||||
|
assert(dst.format == format);
|
||||||
|
|
||||||
|
if (src.width != dst.width || src.height != dst.height)
|
||||||
|
{
|
||||||
|
result.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usewic)
|
||||||
|
{
|
||||||
|
hr = ConvertUsingWIC(src, pfGUID, targetGUID, filter, threshold, dst);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hr = ConvertCustom(src, filter, dst, threshold, slice);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
result.Release();
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Image& src = srcImages[index];
|
if (d > 1)
|
||||||
if (src.format != metadata.format)
|
d >>= 1;
|
||||||
{
|
|
||||||
result.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((src.width > UINT32_MAX) || (src.height > UINT32_MAX))
|
|
||||||
{
|
|
||||||
result.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Image& dst = dest[index];
|
|
||||||
assert(dst.format == format);
|
|
||||||
|
|
||||||
if (src.width != dst.width || src.height != dst.height)
|
|
||||||
{
|
|
||||||
result.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usewic)
|
|
||||||
{
|
|
||||||
hr = ConvertUsingWIC(src, pfGUID, targetGUID, filter, threshold, dst);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hr = ConvertCustom(src, filter, dst, threshold, slice);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
result.Release();
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d > 1)
|
|
||||||
d >>= 1;
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result.Release();
|
result.Release();
|
||||||
|
@ -39,7 +39,7 @@ namespace
|
|||||||
if (!pContext || !pSource || !result.GetPixels())
|
if (!pContext || !pSource || !result.GetPixels())
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
|
||||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||||
|
|
||||||
ComPtr<ID3D11Device> d3dDevice;
|
ComPtr<ID3D11Device> d3dDevice;
|
||||||
pContext->GetDevice(d3dDevice.GetAddressOf());
|
pContext->GetDevice(d3dDevice.GetAddressOf());
|
||||||
@ -64,7 +64,7 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (metadata.IsVolumemap())
|
if (metadata.IsVolumemap())
|
||||||
{
|
{
|
||||||
@ -546,59 +546,59 @@ HRESULT DirectX::CreateTextureEx(
|
|||||||
switch (metadata.dimension)
|
switch (metadata.dimension)
|
||||||
{
|
{
|
||||||
case TEX_DIMENSION_TEXTURE1D:
|
case TEX_DIMENSION_TEXTURE1D:
|
||||||
{
|
{
|
||||||
D3D11_TEXTURE1D_DESC desc = {};
|
D3D11_TEXTURE1D_DESC desc = {};
|
||||||
desc.Width = static_cast<UINT>(metadata.width);
|
desc.Width = static_cast<UINT>(metadata.width);
|
||||||
desc.MipLevels = static_cast<UINT>(metadata.mipLevels);
|
desc.MipLevels = static_cast<UINT>(metadata.mipLevels);
|
||||||
desc.ArraySize = static_cast<UINT>(metadata.arraySize);
|
desc.ArraySize = static_cast<UINT>(metadata.arraySize);
|
||||||
desc.Format = tformat;
|
desc.Format = tformat;
|
||||||
desc.Usage = usage;
|
desc.Usage = usage;
|
||||||
desc.BindFlags = bindFlags;
|
desc.BindFlags = bindFlags;
|
||||||
desc.CPUAccessFlags = cpuAccessFlags;
|
desc.CPUAccessFlags = cpuAccessFlags;
|
||||||
desc.MiscFlags = miscFlags & ~static_cast<uint32_t>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
|
||||||
|
|
||||||
hr = pDevice->CreateTexture1D(&desc, initData.get(), reinterpret_cast<ID3D11Texture1D**>(ppResource));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TEX_DIMENSION_TEXTURE2D:
|
|
||||||
{
|
|
||||||
D3D11_TEXTURE2D_DESC desc = {};
|
|
||||||
desc.Width = static_cast<UINT>(metadata.width);
|
|
||||||
desc.Height = static_cast<UINT>(metadata.height);
|
|
||||||
desc.MipLevels = static_cast<UINT>(metadata.mipLevels);
|
|
||||||
desc.ArraySize = static_cast<UINT>(metadata.arraySize);
|
|
||||||
desc.Format = tformat;
|
|
||||||
desc.SampleDesc.Count = 1;
|
|
||||||
desc.SampleDesc.Quality = 0;
|
|
||||||
desc.Usage = usage;
|
|
||||||
desc.BindFlags = bindFlags;
|
|
||||||
desc.CPUAccessFlags = cpuAccessFlags;
|
|
||||||
if (metadata.IsCubemap())
|
|
||||||
desc.MiscFlags = miscFlags | D3D11_RESOURCE_MISC_TEXTURECUBE;
|
|
||||||
else
|
|
||||||
desc.MiscFlags = miscFlags & ~static_cast<uint32_t>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
desc.MiscFlags = miscFlags & ~static_cast<uint32_t>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
||||||
|
|
||||||
hr = pDevice->CreateTexture2D(&desc, initData.get(), reinterpret_cast<ID3D11Texture2D**>(ppResource));
|
hr = pDevice->CreateTexture1D(&desc, initData.get(), reinterpret_cast<ID3D11Texture1D**>(ppResource));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TEX_DIMENSION_TEXTURE2D:
|
||||||
|
{
|
||||||
|
D3D11_TEXTURE2D_DESC desc = {};
|
||||||
|
desc.Width = static_cast<UINT>(metadata.width);
|
||||||
|
desc.Height = static_cast<UINT>(metadata.height);
|
||||||
|
desc.MipLevels = static_cast<UINT>(metadata.mipLevels);
|
||||||
|
desc.ArraySize = static_cast<UINT>(metadata.arraySize);
|
||||||
|
desc.Format = tformat;
|
||||||
|
desc.SampleDesc.Count = 1;
|
||||||
|
desc.SampleDesc.Quality = 0;
|
||||||
|
desc.Usage = usage;
|
||||||
|
desc.BindFlags = bindFlags;
|
||||||
|
desc.CPUAccessFlags = cpuAccessFlags;
|
||||||
|
if (metadata.IsCubemap())
|
||||||
|
desc.MiscFlags = miscFlags | D3D11_RESOURCE_MISC_TEXTURECUBE;
|
||||||
|
else
|
||||||
|
desc.MiscFlags = miscFlags & ~static_cast<uint32_t>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
||||||
|
|
||||||
|
hr = pDevice->CreateTexture2D(&desc, initData.get(), reinterpret_cast<ID3D11Texture2D**>(ppResource));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case TEX_DIMENSION_TEXTURE3D:
|
case TEX_DIMENSION_TEXTURE3D:
|
||||||
{
|
{
|
||||||
D3D11_TEXTURE3D_DESC desc = {};
|
D3D11_TEXTURE3D_DESC desc = {};
|
||||||
desc.Width = static_cast<UINT>(metadata.width);
|
desc.Width = static_cast<UINT>(metadata.width);
|
||||||
desc.Height = static_cast<UINT>(metadata.height);
|
desc.Height = static_cast<UINT>(metadata.height);
|
||||||
desc.Depth = static_cast<UINT>(metadata.depth);
|
desc.Depth = static_cast<UINT>(metadata.depth);
|
||||||
desc.MipLevels = static_cast<UINT>(metadata.mipLevels);
|
desc.MipLevels = static_cast<UINT>(metadata.mipLevels);
|
||||||
desc.Format = tformat;
|
desc.Format = tformat;
|
||||||
desc.Usage = usage;
|
desc.Usage = usage;
|
||||||
desc.BindFlags = bindFlags;
|
desc.BindFlags = bindFlags;
|
||||||
desc.CPUAccessFlags = cpuAccessFlags;
|
desc.CPUAccessFlags = cpuAccessFlags;
|
||||||
desc.MiscFlags = miscFlags & ~static_cast<uint32_t>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
desc.MiscFlags = miscFlags & ~static_cast<uint32_t>(D3D11_RESOURCE_MISC_TEXTURECUBE);
|
||||||
|
|
||||||
hr = pDevice->CreateTexture3D(&desc, initData.get(), reinterpret_cast<ID3D11Texture3D**>(ppResource));
|
hr = pDevice->CreateTexture3D(&desc, initData.get(), reinterpret_cast<ID3D11Texture3D**>(ppResource));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
@ -744,215 +744,215 @@ HRESULT DirectX::CaptureTexture(
|
|||||||
switch (resType)
|
switch (resType)
|
||||||
{
|
{
|
||||||
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
|
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
|
||||||
{
|
|
||||||
ComPtr<ID3D11Texture1D> pTexture;
|
|
||||||
hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf()));
|
|
||||||
if (FAILED(hr))
|
|
||||||
break;
|
|
||||||
|
|
||||||
assert(pTexture);
|
|
||||||
|
|
||||||
D3D11_TEXTURE1D_DESC desc;
|
|
||||||
pTexture->GetDesc(&desc);
|
|
||||||
|
|
||||||
ComPtr<ID3D11Texture1D> pStaging;
|
|
||||||
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
|
ComPtr<ID3D11Texture1D> pTexture;
|
||||||
pStaging = pTexture;
|
hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf()));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
desc.BindFlags = 0;
|
|
||||||
desc.MiscFlags = 0;
|
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
|
||||||
desc.Usage = D3D11_USAGE_STAGING;
|
|
||||||
|
|
||||||
hr = pDevice->CreateTexture1D(&desc, nullptr, pStaging.GetAddressOf());
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
assert(pStaging);
|
assert(pTexture);
|
||||||
|
|
||||||
pContext->CopyResource(pStaging.Get(), pSource);
|
D3D11_TEXTURE1D_DESC desc;
|
||||||
|
pTexture->GetDesc(&desc);
|
||||||
|
|
||||||
|
ComPtr<ID3D11Texture1D> pStaging;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
desc.BindFlags = 0;
|
||||||
|
desc.MiscFlags = 0;
|
||||||
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
|
||||||
|
hr = pDevice->CreateTexture1D(&desc, nullptr, pStaging.GetAddressOf());
|
||||||
|
if (FAILED(hr))
|
||||||
|
break;
|
||||||
|
|
||||||
|
assert(pStaging);
|
||||||
|
|
||||||
|
pContext->CopyResource(pStaging.Get(), pSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
TexMetadata mdata;
|
||||||
|
mdata.width = desc.Width;
|
||||||
|
mdata.height = mdata.depth = 1;
|
||||||
|
mdata.arraySize = desc.ArraySize;
|
||||||
|
mdata.mipLevels = desc.MipLevels;
|
||||||
|
mdata.miscFlags = 0;
|
||||||
|
mdata.miscFlags2 = 0;
|
||||||
|
mdata.format = desc.Format;
|
||||||
|
mdata.dimension = TEX_DIMENSION_TEXTURE1D;
|
||||||
|
|
||||||
|
hr = result.Initialize(mdata);
|
||||||
|
if (FAILED(hr))
|
||||||
|
break;
|
||||||
|
|
||||||
|
hr = Capture(pContext, pStaging.Get(), mdata, result);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
TexMetadata mdata;
|
|
||||||
mdata.width = desc.Width;
|
|
||||||
mdata.height = mdata.depth = 1;
|
|
||||||
mdata.arraySize = desc.ArraySize;
|
|
||||||
mdata.mipLevels = desc.MipLevels;
|
|
||||||
mdata.miscFlags = 0;
|
|
||||||
mdata.miscFlags2 = 0;
|
|
||||||
mdata.format = desc.Format;
|
|
||||||
mdata.dimension = TEX_DIMENSION_TEXTURE1D;
|
|
||||||
|
|
||||||
hr = result.Initialize(mdata);
|
|
||||||
if (FAILED(hr))
|
|
||||||
break;
|
|
||||||
|
|
||||||
hr = Capture(pContext, pStaging.Get(), mdata, result);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
|
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
|
||||||
{
|
|
||||||
ComPtr<ID3D11Texture2D> pTexture;
|
|
||||||
hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf()));
|
|
||||||
if (FAILED(hr))
|
|
||||||
break;
|
|
||||||
|
|
||||||
assert(pTexture);
|
|
||||||
|
|
||||||
D3D11_TEXTURE2D_DESC desc;
|
|
||||||
pTexture->GetDesc(&desc);
|
|
||||||
|
|
||||||
ComPtr<ID3D11Texture2D> pStaging;
|
|
||||||
if (desc.SampleDesc.Count > 1)
|
|
||||||
{
|
{
|
||||||
desc.SampleDesc.Count = 1;
|
ComPtr<ID3D11Texture2D> pTexture;
|
||||||
desc.SampleDesc.Quality = 0;
|
hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf()));
|
||||||
|
|
||||||
ComPtr<ID3D11Texture2D> pTemp;
|
|
||||||
hr = pDevice->CreateTexture2D(&desc, nullptr, pTemp.GetAddressOf());
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
assert(pTemp);
|
assert(pTexture);
|
||||||
|
|
||||||
DXGI_FORMAT fmt = desc.Format;
|
D3D11_TEXTURE2D_DESC desc;
|
||||||
if (IsTypeless(fmt))
|
pTexture->GetDesc(&desc);
|
||||||
|
|
||||||
|
ComPtr<ID3D11Texture2D> pStaging;
|
||||||
|
if (desc.SampleDesc.Count > 1)
|
||||||
{
|
{
|
||||||
// Assume a UNORM if it exists otherwise use FLOAT
|
desc.SampleDesc.Count = 1;
|
||||||
fmt = MakeTypelessUNORM(fmt);
|
desc.SampleDesc.Quality = 0;
|
||||||
fmt = MakeTypelessFLOAT(fmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
UINT support = 0;
|
ComPtr<ID3D11Texture2D> pTemp;
|
||||||
hr = pDevice->CheckFormatSupport(fmt, &support);
|
hr = pDevice->CreateTexture2D(&desc, nullptr, pTemp.GetAddressOf());
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!(support & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE))
|
assert(pTemp);
|
||||||
{
|
|
||||||
hr = E_FAIL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (UINT item = 0; item < desc.ArraySize; ++item)
|
DXGI_FORMAT fmt = desc.Format;
|
||||||
{
|
if (IsTypeless(fmt))
|
||||||
for (UINT level = 0; level < desc.MipLevels; ++level)
|
|
||||||
{
|
{
|
||||||
const UINT index = D3D11CalcSubresource(level, item, desc.MipLevels);
|
// Assume a UNORM if it exists otherwise use FLOAT
|
||||||
pContext->ResolveSubresource(pTemp.Get(), index, pSource, index, fmt);
|
fmt = MakeTypelessUNORM(fmt);
|
||||||
|
fmt = MakeTypelessFLOAT(fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UINT support = 0;
|
||||||
|
hr = pDevice->CheckFormatSupport(fmt, &support);
|
||||||
|
if (FAILED(hr))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!(support & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE))
|
||||||
|
{
|
||||||
|
hr = E_FAIL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (UINT item = 0; item < desc.ArraySize; ++item)
|
||||||
|
{
|
||||||
|
for (UINT level = 0; level < desc.MipLevels; ++level)
|
||||||
|
{
|
||||||
|
const UINT index = D3D11CalcSubresource(level, item, desc.MipLevels);
|
||||||
|
pContext->ResolveSubresource(pTemp.Get(), index, pSource, index, fmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
desc.BindFlags = 0;
|
||||||
|
desc.MiscFlags &= D3D11_RESOURCE_MISC_TEXTURECUBE;
|
||||||
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
|
||||||
|
hr = pDevice->CreateTexture2D(&desc, nullptr, pStaging.GetAddressOf());
|
||||||
|
if (FAILED(hr))
|
||||||
|
break;
|
||||||
|
|
||||||
|
assert(pStaging);
|
||||||
|
|
||||||
|
pContext->CopyResource(pStaging.Get(), pTemp.Get());
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
desc.BindFlags = 0;
|
||||||
|
desc.MiscFlags &= D3D11_RESOURCE_MISC_TEXTURECUBE;
|
||||||
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
|
||||||
|
hr = pDevice->CreateTexture2D(&desc, nullptr, &pStaging);
|
||||||
|
if (FAILED(hr))
|
||||||
|
break;
|
||||||
|
|
||||||
|
assert(pStaging);
|
||||||
|
|
||||||
|
pContext->CopyResource(pStaging.Get(), pSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
desc.BindFlags = 0;
|
TexMetadata mdata;
|
||||||
desc.MiscFlags &= D3D11_RESOURCE_MISC_TEXTURECUBE;
|
mdata.width = desc.Width;
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
mdata.height = desc.Height;
|
||||||
desc.Usage = D3D11_USAGE_STAGING;
|
mdata.depth = 1;
|
||||||
|
mdata.arraySize = desc.ArraySize;
|
||||||
|
mdata.mipLevels = desc.MipLevels;
|
||||||
|
mdata.miscFlags = (desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE) ? TEX_MISC_TEXTURECUBE : 0u;
|
||||||
|
mdata.miscFlags2 = 0;
|
||||||
|
mdata.format = desc.Format;
|
||||||
|
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
|
||||||
|
|
||||||
hr = pDevice->CreateTexture2D(&desc, nullptr, pStaging.GetAddressOf());
|
hr = result.Initialize(mdata);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
assert(pStaging);
|
hr = Capture(pContext, pStaging.Get(), mdata, result);
|
||||||
|
|
||||||
pContext->CopyResource(pStaging.Get(), pTemp.Get());
|
|
||||||
}
|
}
|
||||||
else if ((desc.Usage == D3D11_USAGE_STAGING) && (desc.CPUAccessFlags & D3D11_CPU_ACCESS_READ))
|
break;
|
||||||
{
|
|
||||||
// Handle case where the source is already a staging texture we can use directly
|
|
||||||
pStaging = pTexture;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
desc.BindFlags = 0;
|
|
||||||
desc.MiscFlags &= D3D11_RESOURCE_MISC_TEXTURECUBE;
|
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
|
||||||
desc.Usage = D3D11_USAGE_STAGING;
|
|
||||||
|
|
||||||
hr = pDevice->CreateTexture2D(&desc, nullptr, &pStaging);
|
|
||||||
if (FAILED(hr))
|
|
||||||
break;
|
|
||||||
|
|
||||||
assert(pStaging);
|
|
||||||
|
|
||||||
pContext->CopyResource(pStaging.Get(), pSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
TexMetadata mdata;
|
|
||||||
mdata.width = desc.Width;
|
|
||||||
mdata.height = desc.Height;
|
|
||||||
mdata.depth = 1;
|
|
||||||
mdata.arraySize = desc.ArraySize;
|
|
||||||
mdata.mipLevels = desc.MipLevels;
|
|
||||||
mdata.miscFlags = (desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE) ? TEX_MISC_TEXTURECUBE : 0u;
|
|
||||||
mdata.miscFlags2 = 0;
|
|
||||||
mdata.format = desc.Format;
|
|
||||||
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
|
|
||||||
|
|
||||||
hr = result.Initialize(mdata);
|
|
||||||
if (FAILED(hr))
|
|
||||||
break;
|
|
||||||
|
|
||||||
hr = Capture(pContext, pStaging.Get(), mdata, result);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
ComPtr<ID3D11Texture3D> pTexture;
|
|
||||||
hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf()));
|
|
||||||
if (FAILED(hr))
|
|
||||||
break;
|
|
||||||
|
|
||||||
assert(pTexture);
|
|
||||||
|
|
||||||
D3D11_TEXTURE3D_DESC desc;
|
|
||||||
pTexture->GetDesc(&desc);
|
|
||||||
|
|
||||||
ComPtr<ID3D11Texture3D> pStaging;
|
|
||||||
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
|
ComPtr<ID3D11Texture3D> pTexture;
|
||||||
pStaging = pTexture;
|
hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf()));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
desc.BindFlags = 0;
|
|
||||||
desc.MiscFlags = 0;
|
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
|
||||||
desc.Usage = D3D11_USAGE_STAGING;
|
|
||||||
|
|
||||||
hr = pDevice->CreateTexture3D(&desc, nullptr, pStaging.GetAddressOf());
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
assert(pStaging);
|
assert(pTexture);
|
||||||
|
|
||||||
pContext->CopyResource(pStaging.Get(), pSource);
|
D3D11_TEXTURE3D_DESC desc;
|
||||||
|
pTexture->GetDesc(&desc);
|
||||||
|
|
||||||
|
ComPtr<ID3D11Texture3D> pStaging;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
desc.BindFlags = 0;
|
||||||
|
desc.MiscFlags = 0;
|
||||||
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
|
||||||
|
hr = pDevice->CreateTexture3D(&desc, nullptr, pStaging.GetAddressOf());
|
||||||
|
if (FAILED(hr))
|
||||||
|
break;
|
||||||
|
|
||||||
|
assert(pStaging);
|
||||||
|
|
||||||
|
pContext->CopyResource(pStaging.Get(), pSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
TexMetadata mdata;
|
||||||
|
mdata.width = desc.Width;
|
||||||
|
mdata.height = desc.Height;
|
||||||
|
mdata.depth = desc.Depth;
|
||||||
|
mdata.arraySize = 1;
|
||||||
|
mdata.mipLevels = desc.MipLevels;
|
||||||
|
mdata.miscFlags = 0;
|
||||||
|
mdata.miscFlags2 = 0;
|
||||||
|
mdata.format = desc.Format;
|
||||||
|
mdata.dimension = TEX_DIMENSION_TEXTURE3D;
|
||||||
|
|
||||||
|
hr = result.Initialize(mdata);
|
||||||
|
if (FAILED(hr))
|
||||||
|
break;
|
||||||
|
|
||||||
|
hr = Capture(pContext, pStaging.Get(), mdata, result);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
TexMetadata mdata;
|
|
||||||
mdata.width = desc.Width;
|
|
||||||
mdata.height = desc.Height;
|
|
||||||
mdata.depth = desc.Depth;
|
|
||||||
mdata.arraySize = 1;
|
|
||||||
mdata.mipLevels = desc.MipLevels;
|
|
||||||
mdata.miscFlags = 0;
|
|
||||||
mdata.miscFlags2 = 0;
|
|
||||||
mdata.format = desc.Format;
|
|
||||||
mdata.dimension = TEX_DIMENSION_TEXTURE3D;
|
|
||||||
|
|
||||||
hr = result.Initialize(mdata);
|
|
||||||
if (FAILED(hr))
|
|
||||||
break;
|
|
||||||
|
|
||||||
hr = Capture(pContext, pStaging.Get(), mdata, result);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
hr = E_FAIL;
|
hr = E_FAIL;
|
||||||
|
@ -144,7 +144,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
numberOfResources = (desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D)
|
numberOfResources = (desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D)
|
||||||
? 1u : desc.DepthOrArraySize;
|
? 1u : desc.DepthOrArraySize;
|
||||||
numberOfResources *= desc.MipLevels;
|
numberOfResources *= desc.MipLevels;
|
||||||
numberOfResources *= numberOfPlanes;
|
numberOfResources *= numberOfPlanes;
|
||||||
|
|
||||||
@ -304,11 +304,11 @@ namespace
|
|||||||
// Block until the copy is complete
|
// Block until the copy is complete
|
||||||
while (fence->GetCompletedValue() < 1)
|
while (fence->GetCompletedValue() < 1)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
SwitchToThread();
|
SwitchToThread();
|
||||||
#else
|
#else
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
@ -477,8 +477,8 @@ HRESULT DirectX::CreateTextureEx(
|
|||||||
desc.Height = static_cast<UINT>(metadata.height);
|
desc.Height = static_cast<UINT>(metadata.height);
|
||||||
desc.MipLevels = static_cast<UINT16>(metadata.mipLevels);
|
desc.MipLevels = static_cast<UINT16>(metadata.mipLevels);
|
||||||
desc.DepthOrArraySize = (metadata.dimension == TEX_DIMENSION_TEXTURE3D)
|
desc.DepthOrArraySize = (metadata.dimension == TEX_DIMENSION_TEXTURE3D)
|
||||||
? static_cast<UINT16>(metadata.depth)
|
? static_cast<UINT16>(metadata.depth)
|
||||||
: static_cast<UINT16>(metadata.arraySize);
|
: static_cast<UINT16>(metadata.arraySize);
|
||||||
desc.Format = format;
|
desc.Format = format;
|
||||||
desc.Flags = resFlags;
|
desc.Flags = resFlags;
|
||||||
desc.SampleDesc.Count = 1;
|
desc.SampleDesc.Count = 1;
|
||||||
@ -524,7 +524,7 @@ HRESULT DirectX::PrepareUpload(
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t numberOfResources = (metadata.dimension == TEX_DIMENSION_TEXTURE3D)
|
size_t numberOfResources = (metadata.dimension == TEX_DIMENSION_TEXTURE3D)
|
||||||
? 1u : metadata.arraySize;
|
? 1u : metadata.arraySize;
|
||||||
numberOfResources *= metadata.mipLevels;
|
numberOfResources *= metadata.mipLevels;
|
||||||
numberOfResources *= numberOfPlanes;
|
numberOfResources *= numberOfPlanes;
|
||||||
|
|
||||||
@ -691,7 +691,7 @@ HRESULT DirectX::CaptureTexture(
|
|||||||
|
|
||||||
switch (desc.Dimension)
|
switch (desc.Dimension)
|
||||||
{
|
{
|
||||||
case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
|
case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
|
||||||
{
|
{
|
||||||
TexMetadata mdata;
|
TexMetadata mdata;
|
||||||
mdata.width = static_cast<size_t>(desc.Width);
|
mdata.width = static_cast<size_t>(desc.Width);
|
||||||
|
@ -1305,198 +1305,198 @@ namespace
|
|||||||
{
|
{
|
||||||
case TEX_DIMENSION_TEXTURE1D:
|
case TEX_DIMENSION_TEXTURE1D:
|
||||||
case TEX_DIMENSION_TEXTURE2D:
|
case TEX_DIMENSION_TEXTURE2D:
|
||||||
{
|
|
||||||
size_t index = 0;
|
|
||||||
for (size_t item = 0; item < metadata.arraySize; ++item)
|
|
||||||
{
|
{
|
||||||
size_t lastgood = 0;
|
size_t index = 0;
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level, ++index)
|
for (size_t item = 0; item < metadata.arraySize; ++item)
|
||||||
{
|
{
|
||||||
if (index >= nimages)
|
size_t lastgood = 0;
|
||||||
return E_FAIL;
|
for (size_t level = 0; level < metadata.mipLevels; ++level, ++index)
|
||||||
|
|
||||||
if (images[index].height != timages[index].height)
|
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
size_t dpitch = images[index].rowPitch;
|
|
||||||
const size_t spitch = timages[index].rowPitch;
|
|
||||||
|
|
||||||
const uint8_t *pSrc = timages[index].pixels;
|
|
||||||
if (!pSrc)
|
|
||||||
return E_POINTER;
|
|
||||||
|
|
||||||
uint8_t *pDest = images[index].pixels;
|
|
||||||
if (!pDest)
|
|
||||||
return E_POINTER;
|
|
||||||
|
|
||||||
if (IsCompressed(metadata.format))
|
|
||||||
{
|
{
|
||||||
size_t csize = std::min<size_t>(images[index].slicePitch, timages[index].slicePitch);
|
if (index >= nimages)
|
||||||
memcpy(pDest, pSrc, csize);
|
return E_FAIL;
|
||||||
|
|
||||||
if (cpFlags & CP_FLAGS_BAD_DXTN_TAILS)
|
if (images[index].height != timages[index].height)
|
||||||
{
|
return E_FAIL;
|
||||||
if (images[index].width < 4 || images[index].height < 4)
|
|
||||||
{
|
|
||||||
csize = std::min<size_t>(images[index].slicePitch, timages[lastgood].slicePitch);
|
|
||||||
memcpy(pDest, timages[lastgood].pixels, csize);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lastgood = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (IsPlanar(metadata.format))
|
|
||||||
{
|
|
||||||
const size_t count = ComputeScanlines(metadata.format, images[index].height);
|
|
||||||
if (!count)
|
|
||||||
return E_UNEXPECTED;
|
|
||||||
|
|
||||||
const size_t csize = std::min<size_t>(dpitch, spitch);
|
size_t dpitch = images[index].rowPitch;
|
||||||
for (size_t h = 0; h < count; ++h)
|
const size_t spitch = timages[index].rowPitch;
|
||||||
|
|
||||||
|
const uint8_t *pSrc = timages[index].pixels;
|
||||||
|
if (!pSrc)
|
||||||
|
return E_POINTER;
|
||||||
|
|
||||||
|
uint8_t *pDest = images[index].pixels;
|
||||||
|
if (!pDest)
|
||||||
|
return E_POINTER;
|
||||||
|
|
||||||
|
if (IsCompressed(metadata.format))
|
||||||
{
|
{
|
||||||
|
size_t csize = std::min<size_t>(images[index].slicePitch, timages[index].slicePitch);
|
||||||
memcpy(pDest, pSrc, csize);
|
memcpy(pDest, pSrc, csize);
|
||||||
pSrc += spitch;
|
|
||||||
pDest += dpitch;
|
if (cpFlags & CP_FLAGS_BAD_DXTN_TAILS)
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (size_t h = 0; h < images[index].height; ++h)
|
|
||||||
{
|
|
||||||
if (convFlags & CONV_FLAGS_EXPAND)
|
|
||||||
{
|
{
|
||||||
if (convFlags & (CONV_FLAGS_565 | CONV_FLAGS_5551 | CONV_FLAGS_4444))
|
if (images[index].width < 4 || images[index].height < 4)
|
||||||
{
|
{
|
||||||
if (!ExpandScanline(pDest, dpitch, DXGI_FORMAT_R8G8B8A8_UNORM,
|
csize = std::min<size_t>(images[index].slicePitch, timages[lastgood].slicePitch);
|
||||||
pSrc, spitch,
|
memcpy(pDest, timages[lastgood].pixels, csize);
|
||||||
(convFlags & CONV_FLAGS_565) ? DXGI_FORMAT_B5G6R5_UNORM : DXGI_FORMAT_B5G5R5A1_UNORM,
|
|
||||||
tflags))
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags);
|
lastgood = index;
|
||||||
if (!LegacyExpandScanline(pDest, dpitch, metadata.format,
|
|
||||||
pSrc, spitch, lformat, pal8,
|
|
||||||
tflags))
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (convFlags & CONV_FLAGS_SWIZZLE)
|
}
|
||||||
{
|
else if (IsPlanar(metadata.format))
|
||||||
SwizzleScanline(pDest, dpitch, pSrc, spitch,
|
{
|
||||||
metadata.format, tflags);
|
const size_t count = ComputeScanlines(metadata.format, images[index].height);
|
||||||
}
|
if (!count)
|
||||||
else
|
return E_UNEXPECTED;
|
||||||
{
|
|
||||||
CopyScanline(pDest, dpitch, pSrc, spitch,
|
|
||||||
metadata.format, tflags);
|
|
||||||
}
|
|
||||||
|
|
||||||
pSrc += spitch;
|
const size_t csize = std::min<size_t>(dpitch, spitch);
|
||||||
pDest += dpitch;
|
for (size_t h = 0; h < count; ++h)
|
||||||
|
{
|
||||||
|
memcpy(pDest, pSrc, csize);
|
||||||
|
pSrc += spitch;
|
||||||
|
pDest += dpitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (size_t h = 0; h < images[index].height; ++h)
|
||||||
|
{
|
||||||
|
if (convFlags & CONV_FLAGS_EXPAND)
|
||||||
|
{
|
||||||
|
if (convFlags & (CONV_FLAGS_565 | CONV_FLAGS_5551 | CONV_FLAGS_4444))
|
||||||
|
{
|
||||||
|
if (!ExpandScanline(pDest, dpitch, DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
|
pSrc, spitch,
|
||||||
|
(convFlags & CONV_FLAGS_565) ? DXGI_FORMAT_B5G6R5_UNORM : DXGI_FORMAT_B5G5R5A1_UNORM,
|
||||||
|
tflags))
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags);
|
||||||
|
if (!LegacyExpandScanline(pDest, dpitch, metadata.format,
|
||||||
|
pSrc, spitch, lformat, pal8,
|
||||||
|
tflags))
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (convFlags & CONV_FLAGS_SWIZZLE)
|
||||||
|
{
|
||||||
|
SwizzleScanline(pDest, dpitch, pSrc, spitch,
|
||||||
|
metadata.format, tflags);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CopyScanline(pDest, dpitch, pSrc, spitch,
|
||||||
|
metadata.format, tflags);
|
||||||
|
}
|
||||||
|
|
||||||
|
pSrc += spitch;
|
||||||
|
pDest += dpitch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case TEX_DIMENSION_TEXTURE3D:
|
case TEX_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
size_t index = 0;
|
|
||||||
size_t d = metadata.depth;
|
|
||||||
|
|
||||||
size_t lastgood = 0;
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
{
|
||||||
for (size_t slice = 0; slice < d; ++slice, ++index)
|
size_t index = 0;
|
||||||
|
size_t d = metadata.depth;
|
||||||
|
|
||||||
|
size_t lastgood = 0;
|
||||||
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
{
|
{
|
||||||
if (index >= nimages)
|
for (size_t slice = 0; slice < d; ++slice, ++index)
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
if (images[index].height != timages[index].height)
|
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
size_t dpitch = images[index].rowPitch;
|
|
||||||
const size_t spitch = timages[index].rowPitch;
|
|
||||||
|
|
||||||
const uint8_t *pSrc = timages[index].pixels;
|
|
||||||
if (!pSrc)
|
|
||||||
return E_POINTER;
|
|
||||||
|
|
||||||
uint8_t *pDest = images[index].pixels;
|
|
||||||
if (!pDest)
|
|
||||||
return E_POINTER;
|
|
||||||
|
|
||||||
if (IsCompressed(metadata.format))
|
|
||||||
{
|
{
|
||||||
size_t csize = std::min<size_t>(images[index].slicePitch, timages[index].slicePitch);
|
if (index >= nimages)
|
||||||
memcpy(pDest, pSrc, csize);
|
return E_FAIL;
|
||||||
|
|
||||||
if (cpFlags & CP_FLAGS_BAD_DXTN_TAILS)
|
if (images[index].height != timages[index].height)
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
|
size_t dpitch = images[index].rowPitch;
|
||||||
|
const size_t spitch = timages[index].rowPitch;
|
||||||
|
|
||||||
|
const uint8_t *pSrc = timages[index].pixels;
|
||||||
|
if (!pSrc)
|
||||||
|
return E_POINTER;
|
||||||
|
|
||||||
|
uint8_t *pDest = images[index].pixels;
|
||||||
|
if (!pDest)
|
||||||
|
return E_POINTER;
|
||||||
|
|
||||||
|
if (IsCompressed(metadata.format))
|
||||||
{
|
{
|
||||||
if (images[index].width < 4 || images[index].height < 4)
|
size_t csize = std::min<size_t>(images[index].slicePitch, timages[index].slicePitch);
|
||||||
|
memcpy(pDest, pSrc, csize);
|
||||||
|
|
||||||
|
if (cpFlags & CP_FLAGS_BAD_DXTN_TAILS)
|
||||||
{
|
{
|
||||||
csize = std::min<size_t>(images[index].slicePitch, timages[lastgood + slice].slicePitch);
|
if (images[index].width < 4 || images[index].height < 4)
|
||||||
memcpy(pDest, timages[lastgood + slice].pixels, csize);
|
{
|
||||||
}
|
csize = std::min<size_t>(images[index].slicePitch, timages[lastgood + slice].slicePitch);
|
||||||
else if (!slice)
|
memcpy(pDest, timages[lastgood + slice].pixels, csize);
|
||||||
{
|
}
|
||||||
lastgood = index;
|
else if (!slice)
|
||||||
|
{
|
||||||
|
lastgood = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (IsPlanar(metadata.format))
|
||||||
else if (IsPlanar(metadata.format))
|
|
||||||
{
|
|
||||||
// Direct3D does not support any planar formats for Texture3D
|
|
||||||
return HRESULT_E_NOT_SUPPORTED;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (size_t h = 0; h < images[index].height; ++h)
|
|
||||||
{
|
{
|
||||||
if (convFlags & CONV_FLAGS_EXPAND)
|
// Direct3D does not support any planar formats for Texture3D
|
||||||
|
return HRESULT_E_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (size_t h = 0; h < images[index].height; ++h)
|
||||||
{
|
{
|
||||||
if (convFlags & (CONV_FLAGS_565 | CONV_FLAGS_5551 | CONV_FLAGS_4444))
|
if (convFlags & CONV_FLAGS_EXPAND)
|
||||||
{
|
{
|
||||||
if (!ExpandScanline(pDest, dpitch, DXGI_FORMAT_R8G8B8A8_UNORM,
|
if (convFlags & (CONV_FLAGS_565 | CONV_FLAGS_5551 | CONV_FLAGS_4444))
|
||||||
pSrc, spitch,
|
{
|
||||||
(convFlags & CONV_FLAGS_565) ? DXGI_FORMAT_B5G6R5_UNORM : DXGI_FORMAT_B5G5R5A1_UNORM,
|
if (!ExpandScanline(pDest, dpitch, DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
tflags))
|
pSrc, spitch,
|
||||||
return E_FAIL;
|
(convFlags & CONV_FLAGS_565) ? DXGI_FORMAT_B5G6R5_UNORM : DXGI_FORMAT_B5G5R5A1_UNORM,
|
||||||
|
tflags))
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags);
|
||||||
|
if (!LegacyExpandScanline(pDest, dpitch, metadata.format,
|
||||||
|
pSrc, spitch, lformat, pal8,
|
||||||
|
tflags))
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (convFlags & CONV_FLAGS_SWIZZLE)
|
||||||
|
{
|
||||||
|
SwizzleScanline(pDest, dpitch, pSrc, spitch, metadata.format, tflags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags);
|
CopyScanline(pDest, dpitch, pSrc, spitch, metadata.format, tflags);
|
||||||
if (!LegacyExpandScanline(pDest, dpitch, metadata.format,
|
|
||||||
pSrc, spitch, lformat, pal8,
|
|
||||||
tflags))
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (convFlags & CONV_FLAGS_SWIZZLE)
|
|
||||||
{
|
|
||||||
SwizzleScanline(pDest, dpitch, pSrc, spitch, metadata.format, tflags);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CopyScanline(pDest, dpitch, pSrc, spitch, metadata.format, tflags);
|
|
||||||
}
|
|
||||||
|
|
||||||
pSrc += spitch;
|
pSrc += spitch;
|
||||||
pDest += dpitch;
|
pDest += dpitch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (d > 1)
|
if (d > 1)
|
||||||
d >>= 1;
|
d >>= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
@ -1824,18 +1824,18 @@ HRESULT DirectX::LoadFromDDSFile(
|
|||||||
|
|
||||||
if (!(convFlags & CONV_FLAGS_DX10))
|
if (!(convFlags & CONV_FLAGS_DX10))
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// Must reset file position since we read more than the standard header above
|
// Must reset file position since we read more than the standard header above
|
||||||
const LARGE_INTEGER filePos = { { sizeof(uint32_t) + sizeof(DDS_HEADER), 0 } };
|
const LARGE_INTEGER filePos = { { sizeof(uint32_t) + sizeof(DDS_HEADER), 0 } };
|
||||||
if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN))
|
if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN))
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
inFile.seekg(sizeof(uint32_t) + sizeof(DDS_HEADER), std::ios::beg);
|
inFile.seekg(sizeof(uint32_t) + sizeof(DDS_HEADER), std::ios::beg);
|
||||||
if (!inFile)
|
if (!inFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
offset = sizeof(uint32_t) + sizeof(DDS_HEADER);
|
offset = sizeof(uint32_t) + sizeof(DDS_HEADER);
|
||||||
}
|
}
|
||||||
@ -1849,7 +1849,7 @@ HRESULT DirectX::LoadFromDDSFile(
|
|||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (!ReadFile(hFile.get(), pal8.get(), 256 * sizeof(uint32_t), &bytesRead, nullptr))
|
if (!ReadFile(hFile.get(), pal8.get(), 256 * sizeof(uint32_t), &bytesRead, nullptr))
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
@ -1859,11 +1859,11 @@ HRESULT DirectX::LoadFromDDSFile(
|
|||||||
{
|
{
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
inFile.read(reinterpret_cast<char*>(pal8.get()), 256 * sizeof(uint32_t));
|
inFile.read(reinterpret_cast<char*>(pal8.get()), 256 * sizeof(uint32_t));
|
||||||
if (!inFile)
|
if (!inFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
offset += (256 * sizeof(uint32_t));
|
offset += (256 * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
@ -1885,7 +1885,7 @@ HRESULT DirectX::LoadFromDDSFile(
|
|||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (!ReadFile(hFile.get(), temp.get(), static_cast<DWORD>(remaining), &bytesRead, nullptr))
|
if (!ReadFile(hFile.get(), temp.get(), static_cast<DWORD>(remaining), &bytesRead, nullptr))
|
||||||
{
|
{
|
||||||
image.Release();
|
image.Release();
|
||||||
@ -1897,14 +1897,14 @@ HRESULT DirectX::LoadFromDDSFile(
|
|||||||
image.Release();
|
image.Release();
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
inFile.read(reinterpret_cast<char*>(temp.get()), remaining);
|
inFile.read(reinterpret_cast<char*>(temp.get()), remaining);
|
||||||
if (!inFile)
|
if (!inFile)
|
||||||
{
|
{
|
||||||
image.Release();
|
image.Release();
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CP_FLAGS cflags = CP_FLAGS_NONE;
|
CP_FLAGS cflags = CP_FLAGS_NONE;
|
||||||
if (flags & DDS_FLAGS_LEGACY_DWORD)
|
if (flags & DDS_FLAGS_LEGACY_DWORD)
|
||||||
@ -1943,20 +1943,20 @@ HRESULT DirectX::LoadFromDDSFile(
|
|||||||
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (!ReadFile(hFile.get(), image.GetPixels(), static_cast<DWORD>(image.GetPixelsSize()), &bytesRead, nullptr))
|
if (!ReadFile(hFile.get(), image.GetPixels(), static_cast<DWORD>(image.GetPixelsSize()), &bytesRead, nullptr))
|
||||||
{
|
{
|
||||||
image.Release();
|
image.Release();
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
inFile.read(reinterpret_cast<char*>(image.GetPixels()), image.GetPixelsSize());
|
inFile.read(reinterpret_cast<char*>(image.GetPixels()), image.GetPixelsSize());
|
||||||
if (!inFile)
|
if (!inFile)
|
||||||
{
|
{
|
||||||
image.Release();
|
image.Release();
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (convFlags & (CONV_FLAGS_SWIZZLE | CONV_FLAGS_NOALPHA))
|
if (convFlags & (CONV_FLAGS_SWIZZLE | CONV_FLAGS_NOALPHA))
|
||||||
{
|
{
|
||||||
@ -2054,143 +2054,143 @@ HRESULT DirectX::SaveToDDSMemory(
|
|||||||
{
|
{
|
||||||
case DDS_DIMENSION_TEXTURE1D:
|
case DDS_DIMENSION_TEXTURE1D:
|
||||||
case DDS_DIMENSION_TEXTURE2D:
|
case DDS_DIMENSION_TEXTURE2D:
|
||||||
{
|
|
||||||
size_t index = 0;
|
|
||||||
for (size_t item = 0; item < metadata.arraySize; ++item)
|
|
||||||
{
|
{
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
size_t index = 0;
|
||||||
|
for (size_t item = 0; item < metadata.arraySize; ++item)
|
||||||
{
|
{
|
||||||
if (index >= nimages)
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
{
|
{
|
||||||
blob.Release();
|
if (index >= nimages)
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fastpath)
|
|
||||||
{
|
|
||||||
size_t pixsize = images[index].slicePitch;
|
|
||||||
memcpy(pDestination, images[index].pixels, pixsize);
|
|
||||||
|
|
||||||
pDestination += pixsize;
|
|
||||||
remaining -= pixsize;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size_t ddsRowPitch, ddsSlicePitch;
|
|
||||||
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
blob.Release();
|
blob.Release();
|
||||||
return hr;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t rowPitch = images[index].rowPitch;
|
if (fastpath)
|
||||||
|
|
||||||
const uint8_t * __restrict sPtr = images[index].pixels;
|
|
||||||
uint8_t * __restrict dPtr = pDestination;
|
|
||||||
|
|
||||||
const size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
|
||||||
const size_t csize = std::min<size_t>(rowPitch, ddsRowPitch);
|
|
||||||
size_t tremaining = remaining;
|
|
||||||
for (size_t j = 0; j < lines; ++j)
|
|
||||||
{
|
{
|
||||||
if (tremaining < csize)
|
size_t pixsize = images[index].slicePitch;
|
||||||
|
memcpy(pDestination, images[index].pixels, pixsize);
|
||||||
|
|
||||||
|
pDestination += pixsize;
|
||||||
|
remaining -= pixsize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t ddsRowPitch, ddsSlicePitch;
|
||||||
|
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||||
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
blob.Release();
|
blob.Release();
|
||||||
return E_FAIL;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(dPtr, sPtr, csize);
|
const size_t rowPitch = images[index].rowPitch;
|
||||||
|
|
||||||
sPtr += rowPitch;
|
const uint8_t * __restrict sPtr = images[index].pixels;
|
||||||
dPtr += ddsRowPitch;
|
uint8_t * __restrict dPtr = pDestination;
|
||||||
tremaining -= ddsRowPitch;
|
|
||||||
|
const size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
||||||
|
const size_t csize = std::min<size_t>(rowPitch, ddsRowPitch);
|
||||||
|
size_t tremaining = remaining;
|
||||||
|
for (size_t j = 0; j < lines; ++j)
|
||||||
|
{
|
||||||
|
if (tremaining < csize)
|
||||||
|
{
|
||||||
|
blob.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(dPtr, sPtr, csize);
|
||||||
|
|
||||||
|
sPtr += rowPitch;
|
||||||
|
dPtr += ddsRowPitch;
|
||||||
|
tremaining -= ddsRowPitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
pDestination += ddsSlicePitch;
|
||||||
|
remaining -= ddsSlicePitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
pDestination += ddsSlicePitch;
|
++index;
|
||||||
remaining -= ddsSlicePitch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case DDS_DIMENSION_TEXTURE3D:
|
case DDS_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
if (metadata.arraySize != 1)
|
|
||||||
{
|
{
|
||||||
blob.Release();
|
if (metadata.arraySize != 1)
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t d = metadata.depth;
|
|
||||||
|
|
||||||
size_t index = 0;
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
|
||||||
for (size_t slice = 0; slice < d; ++slice)
|
|
||||||
{
|
{
|
||||||
if (index >= nimages)
|
blob.Release();
|
||||||
{
|
return E_FAIL;
|
||||||
blob.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fastpath)
|
|
||||||
{
|
|
||||||
size_t pixsize = images[index].slicePitch;
|
|
||||||
memcpy(pDestination, images[index].pixels, pixsize);
|
|
||||||
|
|
||||||
pDestination += pixsize;
|
|
||||||
remaining -= pixsize;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size_t ddsRowPitch, ddsSlicePitch;
|
|
||||||
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
blob.Release();
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t rowPitch = images[index].rowPitch;
|
|
||||||
|
|
||||||
const uint8_t * __restrict sPtr = images[index].pixels;
|
|
||||||
uint8_t * __restrict dPtr = pDestination;
|
|
||||||
|
|
||||||
const size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
|
||||||
const size_t csize = std::min<size_t>(rowPitch, ddsRowPitch);
|
|
||||||
size_t tremaining = remaining;
|
|
||||||
for (size_t j = 0; j < lines; ++j)
|
|
||||||
{
|
|
||||||
if (tremaining < csize)
|
|
||||||
{
|
|
||||||
blob.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(dPtr, sPtr, csize);
|
|
||||||
|
|
||||||
sPtr += rowPitch;
|
|
||||||
dPtr += ddsRowPitch;
|
|
||||||
tremaining -= ddsRowPitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
pDestination += ddsSlicePitch;
|
|
||||||
remaining -= ddsSlicePitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d > 1)
|
size_t d = metadata.depth;
|
||||||
d >>= 1;
|
|
||||||
|
size_t index = 0;
|
||||||
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
|
{
|
||||||
|
for (size_t slice = 0; slice < d; ++slice)
|
||||||
|
{
|
||||||
|
if (index >= nimages)
|
||||||
|
{
|
||||||
|
blob.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fastpath)
|
||||||
|
{
|
||||||
|
size_t pixsize = images[index].slicePitch;
|
||||||
|
memcpy(pDestination, images[index].pixels, pixsize);
|
||||||
|
|
||||||
|
pDestination += pixsize;
|
||||||
|
remaining -= pixsize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t ddsRowPitch, ddsSlicePitch;
|
||||||
|
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
blob.Release();
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t rowPitch = images[index].rowPitch;
|
||||||
|
|
||||||
|
const uint8_t * __restrict sPtr = images[index].pixels;
|
||||||
|
uint8_t * __restrict dPtr = pDestination;
|
||||||
|
|
||||||
|
const size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
||||||
|
const size_t csize = std::min<size_t>(rowPitch, ddsRowPitch);
|
||||||
|
size_t tremaining = remaining;
|
||||||
|
for (size_t j = 0; j < lines; ++j)
|
||||||
|
{
|
||||||
|
if (tremaining < csize)
|
||||||
|
{
|
||||||
|
blob.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(dPtr, sPtr, csize);
|
||||||
|
|
||||||
|
sPtr += rowPitch;
|
||||||
|
dPtr += ddsRowPitch;
|
||||||
|
tremaining -= ddsRowPitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
pDestination += ddsSlicePitch;
|
||||||
|
remaining -= ddsSlicePitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d > 1)
|
||||||
|
d >>= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
blob.Release();
|
blob.Release();
|
||||||
@ -2263,171 +2263,171 @@ HRESULT DirectX::SaveToDDSFile(
|
|||||||
{
|
{
|
||||||
case DDS_DIMENSION_TEXTURE1D:
|
case DDS_DIMENSION_TEXTURE1D:
|
||||||
case DDS_DIMENSION_TEXTURE2D:
|
case DDS_DIMENSION_TEXTURE2D:
|
||||||
{
|
|
||||||
size_t index = 0;
|
|
||||||
for (size_t item = 0; item < metadata.arraySize; ++item)
|
|
||||||
{
|
{
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level, ++index)
|
size_t index = 0;
|
||||||
|
for (size_t item = 0; item < metadata.arraySize; ++item)
|
||||||
{
|
{
|
||||||
if (index >= nimages)
|
for (size_t level = 0; level < metadata.mipLevels; ++level, ++index)
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
if (!images[index].pixels)
|
|
||||||
return E_POINTER;
|
|
||||||
|
|
||||||
assert(images[index].rowPitch > 0);
|
|
||||||
assert(images[index].slicePitch > 0);
|
|
||||||
|
|
||||||
size_t ddsRowPitch, ddsSlicePitch;
|
|
||||||
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
if ((images[index].slicePitch == ddsSlicePitch) && (ddsSlicePitch <= UINT32_MAX))
|
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
if (index >= nimages)
|
||||||
if (!WriteFile(hFile.get(), images[index].pixels, static_cast<DWORD>(ddsSlicePitch), &bytesWritten, nullptr))
|
|
||||||
{
|
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytesWritten != ddsSlicePitch)
|
|
||||||
{
|
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
|
||||||
#else
|
if (!images[index].pixels)
|
||||||
outFile.write(reinterpret_cast<char*>(images[index].pixels), static_cast<std::streamsize>(ddsSlicePitch));
|
return E_POINTER;
|
||||||
if (!outFile)
|
|
||||||
return E_FAIL;
|
assert(images[index].rowPitch > 0);
|
||||||
#endif
|
assert(images[index].slicePitch > 0);
|
||||||
}
|
|
||||||
else
|
size_t ddsRowPitch, ddsSlicePitch;
|
||||||
{
|
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||||
const size_t rowPitch = images[index].rowPitch;
|
if (FAILED(hr))
|
||||||
if (rowPitch < ddsRowPitch)
|
return hr;
|
||||||
|
|
||||||
|
if ((images[index].slicePitch == ddsSlicePitch) && (ddsSlicePitch <= UINT32_MAX))
|
||||||
{
|
{
|
||||||
// DDS uses 1-byte alignment, so if this is happening then the input pitch isn't actually a full line of data
|
#ifdef WIN32
|
||||||
return E_FAIL;
|
if (!WriteFile(hFile.get(), images[index].pixels, static_cast<DWORD>(ddsSlicePitch), &bytesWritten, nullptr))
|
||||||
}
|
|
||||||
|
|
||||||
if (ddsRowPitch > UINT32_MAX)
|
|
||||||
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
|
||||||
|
|
||||||
const uint8_t * __restrict sPtr = images[index].pixels;
|
|
||||||
|
|
||||||
const size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
|
||||||
for (size_t j = 0; j < lines; ++j)
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
if (!WriteFile(hFile.get(), sPtr, static_cast<DWORD>(ddsRowPitch), &bytesWritten, nullptr))
|
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesWritten != ddsRowPitch)
|
if (bytesWritten != ddsSlicePitch)
|
||||||
{
|
{
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
outFile.write(reinterpret_cast<const char*>(sPtr), static_cast<std::streamsize>(ddsRowPitch));
|
outFile.write(reinterpret_cast<char*>(images[index].pixels), static_cast<std::streamsize>(ddsSlicePitch));
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const size_t rowPitch = images[index].rowPitch;
|
||||||
|
if (rowPitch < ddsRowPitch)
|
||||||
|
{
|
||||||
|
// DDS uses 1-byte alignment, so if this is happening then the input pitch isn't actually a full line of data
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
sPtr += rowPitch;
|
if (ddsRowPitch > UINT32_MAX)
|
||||||
|
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
||||||
|
|
||||||
|
const uint8_t * __restrict sPtr = images[index].pixels;
|
||||||
|
|
||||||
|
const size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
||||||
|
for (size_t j = 0; j < lines; ++j)
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
if (!WriteFile(hFile.get(), sPtr, static_cast<DWORD>(ddsRowPitch), &bytesWritten, nullptr))
|
||||||
|
{
|
||||||
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytesWritten != ddsRowPitch)
|
||||||
|
{
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
outFile.write(reinterpret_cast<const char*>(sPtr), static_cast<std::streamsize>(ddsRowPitch));
|
||||||
|
if (!outFile)
|
||||||
|
return E_FAIL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sPtr += rowPitch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case DDS_DIMENSION_TEXTURE3D:
|
case DDS_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
if (metadata.arraySize != 1)
|
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
size_t d = metadata.depth;
|
|
||||||
|
|
||||||
size_t index = 0;
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
{
|
||||||
for (size_t slice = 0; slice < d; ++slice, ++index)
|
if (metadata.arraySize != 1)
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
|
size_t d = metadata.depth;
|
||||||
|
|
||||||
|
size_t index = 0;
|
||||||
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
{
|
{
|
||||||
if (index >= nimages)
|
for (size_t slice = 0; slice < d; ++slice, ++index)
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
if (!images[index].pixels)
|
|
||||||
return E_POINTER;
|
|
||||||
|
|
||||||
assert(images[index].rowPitch > 0);
|
|
||||||
assert(images[index].slicePitch > 0);
|
|
||||||
|
|
||||||
size_t ddsRowPitch, ddsSlicePitch;
|
|
||||||
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
if ((images[index].slicePitch == ddsSlicePitch) && (ddsSlicePitch <= UINT32_MAX))
|
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
if (index >= nimages)
|
||||||
if (!WriteFile(hFile.get(), images[index].pixels, static_cast<DWORD>(ddsSlicePitch), &bytesWritten, nullptr))
|
|
||||||
{
|
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytesWritten != ddsSlicePitch)
|
|
||||||
{
|
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
|
||||||
#else
|
if (!images[index].pixels)
|
||||||
outFile.write(reinterpret_cast<char*>(images[index].pixels), static_cast<std::streamsize>(ddsSlicePitch));
|
return E_POINTER;
|
||||||
if (!outFile)
|
|
||||||
return E_FAIL;
|
assert(images[index].rowPitch > 0);
|
||||||
#endif
|
assert(images[index].slicePitch > 0);
|
||||||
}
|
|
||||||
else
|
size_t ddsRowPitch, ddsSlicePitch;
|
||||||
{
|
hr = ComputePitch(metadata.format, images[index].width, images[index].height, ddsRowPitch, ddsSlicePitch, CP_FLAGS_NONE);
|
||||||
const size_t rowPitch = images[index].rowPitch;
|
if (FAILED(hr))
|
||||||
if (rowPitch < ddsRowPitch)
|
return hr;
|
||||||
|
|
||||||
|
if ((images[index].slicePitch == ddsSlicePitch) && (ddsSlicePitch <= UINT32_MAX))
|
||||||
{
|
{
|
||||||
// DDS uses 1-byte alignment, so if this is happening then the input pitch isn't actually a full line of data
|
#ifdef WIN32
|
||||||
return E_FAIL;
|
if (!WriteFile(hFile.get(), images[index].pixels, static_cast<DWORD>(ddsSlicePitch), &bytesWritten, nullptr))
|
||||||
}
|
|
||||||
|
|
||||||
if (ddsRowPitch > UINT32_MAX)
|
|
||||||
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
|
||||||
|
|
||||||
const uint8_t * __restrict sPtr = images[index].pixels;
|
|
||||||
|
|
||||||
const size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
|
||||||
for (size_t j = 0; j < lines; ++j)
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
if (!WriteFile(hFile.get(), sPtr, static_cast<DWORD>(ddsRowPitch), &bytesWritten, nullptr))
|
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesWritten != ddsRowPitch)
|
if (bytesWritten != ddsSlicePitch)
|
||||||
{
|
{
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
outFile.write(reinterpret_cast<const char*>(sPtr), static_cast<std::streamsize>(ddsRowPitch));
|
outFile.write(reinterpret_cast<char*>(images[index].pixels), static_cast<std::streamsize>(ddsSlicePitch));
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#endif
|
#endif
|
||||||
sPtr += rowPitch;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const size_t rowPitch = images[index].rowPitch;
|
||||||
|
if (rowPitch < ddsRowPitch)
|
||||||
|
{
|
||||||
|
// DDS uses 1-byte alignment, so if this is happening then the input pitch isn't actually a full line of data
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ddsRowPitch > UINT32_MAX)
|
||||||
|
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
||||||
|
|
||||||
|
const uint8_t * __restrict sPtr = images[index].pixels;
|
||||||
|
|
||||||
|
const size_t lines = ComputeScanlines(metadata.format, images[index].height);
|
||||||
|
for (size_t j = 0; j < lines; ++j)
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
if (!WriteFile(hFile.get(), sPtr, static_cast<DWORD>(ddsRowPitch), &bytesWritten, nullptr))
|
||||||
|
{
|
||||||
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytesWritten != ddsRowPitch)
|
||||||
|
{
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
outFile.write(reinterpret_cast<const char*>(sPtr), static_cast<std::streamsize>(ddsRowPitch));
|
||||||
|
if (!outFile)
|
||||||
|
return E_FAIL;
|
||||||
|
#endif
|
||||||
|
sPtr += rowPitch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (d > 1)
|
if (d > 1)
|
||||||
d >>= 1;
|
d >>= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
|
@ -79,7 +79,7 @@ namespace
|
|||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
template<size_t sizeOfBuffer>
|
template<size_t sizeOfBuffer>
|
||||||
inline int sprintf_s(char (&buffer)[sizeOfBuffer], const char* format, ...)
|
inline int sprintf_s(char(&buffer)[sizeOfBuffer], const char* format, ...)
|
||||||
{
|
{
|
||||||
// This is adapter code. It is not a full implementation of sprintf_s!
|
// This is adapter code. It is not a full implementation of sprintf_s!
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -400,7 +400,7 @@ namespace
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WRITE_OLD_COLORS
|
#ifdef WRITE_OLD_COLORS
|
||||||
size_t encSize = 0;
|
size_t encSize = 0;
|
||||||
|
|
||||||
const uint8_t* scanPtr = rgbe;
|
const uint8_t* scanPtr = rgbe;
|
||||||
@ -502,7 +502,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
return encSize;
|
return encSize;
|
||||||
#else
|
#else
|
||||||
enc[0] = 2;
|
enc[0] = 2;
|
||||||
enc[1] = 2;
|
enc[1] = 2;
|
||||||
enc[2] = uint8_t(width >> 8);
|
enc[2] = uint8_t(width >> 8);
|
||||||
@ -569,7 +569,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
return encSize;
|
return encSize;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -748,7 +748,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
|
|||||||
for (int channel = 0; channel < 4; ++channel)
|
for (int channel = 0; channel < 4; ++channel)
|
||||||
{
|
{
|
||||||
auto pixelLoc = scanLine + channel;
|
auto pixelLoc = scanLine + channel;
|
||||||
for(size_t pixelCount = 0; pixelCount < mdata.width;)
|
for (size_t pixelCount = 0; pixelCount < mdata.width;)
|
||||||
{
|
{
|
||||||
if (pixelLen < 2)
|
if (pixelLen < 2)
|
||||||
{
|
{
|
||||||
@ -1163,7 +1163,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
|
|||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
// Write blob
|
// Write blob
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
auto const bytesToWrite = static_cast<const DWORD>(blob.GetBufferSize());
|
auto const bytesToWrite = static_cast<const DWORD>(blob.GetBufferSize());
|
||||||
DWORD bytesWritten;
|
DWORD bytesWritten;
|
||||||
if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr))
|
if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr))
|
||||||
@ -1175,13 +1175,13 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
|
|||||||
{
|
{
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
outFile.write(reinterpret_cast<char*>(blob.GetBufferPointer()),
|
outFile.write(reinterpret_cast<char*>(blob.GetBufferPointer()),
|
||||||
static_cast<std::streamsize>(blob.GetBufferSize()));
|
static_cast<std::streamsize>(blob.GetBufferSize()));
|
||||||
|
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1196,7 +1196,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
|
|||||||
char header[256] = {};
|
char header[256] = {};
|
||||||
sprintf_s(header, g_Header, image.height, image.width);
|
sprintf_s(header, g_Header, image.height, image.width);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
auto const headerLen = static_cast<DWORD>(strlen(header));
|
auto const headerLen = static_cast<DWORD>(strlen(header));
|
||||||
|
|
||||||
DWORD bytesWritten;
|
DWORD bytesWritten;
|
||||||
@ -1207,21 +1207,21 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
|
|||||||
|
|
||||||
if (bytesWritten != headerLen)
|
if (bytesWritten != headerLen)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#else
|
#else
|
||||||
outFile.write(reinterpret_cast<char*>(header), static_cast<std::streamsize>(strlen(header)));
|
outFile.write(reinterpret_cast<char*>(header), static_cast<std::streamsize>(strlen(header)));
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DISABLE_COMPRESS
|
#ifdef DISABLE_COMPRESS
|
||||||
// Uncompressed write
|
// Uncompressed write
|
||||||
auto sPtr = reinterpret_cast<const uint8_t*>(image.pixels);
|
auto sPtr = reinterpret_cast<const uint8_t*>(image.pixels);
|
||||||
for (size_t scan = 0; scan < image.height; ++scan)
|
for (size_t scan = 0; scan < image.height; ++scan)
|
||||||
{
|
{
|
||||||
FloatToRGBE(rgbe, reinterpret_cast<const float*>(sPtr), image.width, fpp);
|
FloatToRGBE(rgbe, reinterpret_cast<const float*>(sPtr), image.width, fpp);
|
||||||
sPtr += image.rowPitch;
|
sPtr += image.rowPitch;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (!WriteFile(hFile.get(), rgbe, static_cast<DWORD>(rowPitch), &bytesWritten, nullptr))
|
if (!WriteFile(hFile.get(), rgbe, static_cast<DWORD>(rowPitch), &bytesWritten, nullptr))
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
@ -1229,20 +1229,20 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
|
|||||||
|
|
||||||
if (bytesWritten != rowPitch)
|
if (bytesWritten != rowPitch)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#else
|
#else
|
||||||
outFile.write(reinterpret_cast<char*>(rgbe), static_cast<std::streamsize>(rowPitch));
|
outFile.write(reinterpret_cast<char*>(rgbe), static_cast<std::streamsize>(rowPitch));
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
auto enc = temp.get() + rowPitch;
|
auto enc = temp.get() + rowPitch;
|
||||||
|
|
||||||
const uint8_t* sPtr = image.pixels;
|
const uint8_t* sPtr = image.pixels;
|
||||||
for (size_t scan = 0; scan < image.height; ++scan)
|
for (size_t scan = 0; scan < image.height; ++scan)
|
||||||
{
|
{
|
||||||
if (image.format == DXGI_FORMAT_R32G32B32A32_FLOAT || image.format == DXGI_FORMAT_R32G32B32_FLOAT)
|
if (image.format == DXGI_FORMAT_R32G32B32A32_FLOAT || image.format == DXGI_FORMAT_R32G32B32_FLOAT)
|
||||||
{
|
{
|
||||||
FloatToRGBE(rgbe, reinterpret_cast<const float*>(sPtr), image.width, fpp);
|
FloatToRGBE(rgbe, reinterpret_cast<const float*>(sPtr), image.width, fpp);
|
||||||
}
|
}
|
||||||
@ -1258,7 +1258,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
|
|||||||
if (encSize > UINT32_MAX)
|
if (encSize > UINT32_MAX)
|
||||||
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (!WriteFile(hFile.get(), enc, static_cast<DWORD>(encSize), &bytesWritten, nullptr))
|
if (!WriteFile(hFile.get(), enc, static_cast<DWORD>(encSize), &bytesWritten, nullptr))
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
@ -1266,15 +1266,15 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
|
|||||||
|
|
||||||
if (bytesWritten != encSize)
|
if (bytesWritten != encSize)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#else
|
#else
|
||||||
outFile.write(reinterpret_cast<char*>(enc), static_cast<std::streamsize>(encSize));
|
outFile.write(reinterpret_cast<char*>(enc), static_cast<std::streamsize>(encSize));
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (!WriteFile(hFile.get(), rgbe, static_cast<DWORD>(rowPitch), &bytesWritten, nullptr))
|
if (!WriteFile(hFile.get(), rgbe, static_cast<DWORD>(rowPitch), &bytesWritten, nullptr))
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
@ -1282,14 +1282,14 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce
|
|||||||
|
|
||||||
if (bytesWritten != rowPitch)
|
if (bytesWritten != rowPitch)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#else
|
#else
|
||||||
outFile.write(reinterpret_cast<char*>(rgbe), static_cast<std::streamsize>(rowPitch));
|
outFile.write(reinterpret_cast<char*>(rgbe), static_cast<std::streamsize>(rowPitch));
|
||||||
if (!outFile)
|
if (!outFile)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -23,7 +23,7 @@ namespace
|
|||||||
return std::aligned_alloc(alignment, size);
|
return std::aligned_alloc(alignment, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define _aligned_free free
|
#define _aligned_free free
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -75,37 +75,37 @@ bool DirectX::Internal::DetermineImageArray(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TEX_DIMENSION_TEXTURE3D:
|
case TEX_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
size_t w = metadata.width;
|
|
||||||
size_t h = metadata.height;
|
|
||||||
size_t d = metadata.depth;
|
|
||||||
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
{
|
||||||
size_t rowPitch, slicePitch;
|
size_t w = metadata.width;
|
||||||
if (FAILED(ComputePitch(metadata.format, w, h, rowPitch, slicePitch, cpFlags)))
|
size_t h = metadata.height;
|
||||||
|
size_t d = metadata.depth;
|
||||||
|
|
||||||
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
{
|
{
|
||||||
nImages = pixelSize = 0;
|
size_t rowPitch, slicePitch;
|
||||||
return false;
|
if (FAILED(ComputePitch(metadata.format, w, h, rowPitch, slicePitch, cpFlags)))
|
||||||
|
{
|
||||||
|
nImages = pixelSize = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t slice = 0; slice < d; ++slice)
|
||||||
|
{
|
||||||
|
totalPixelSize += uint64_t(slicePitch);
|
||||||
|
++nimages;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (h > 1)
|
||||||
|
h >>= 1;
|
||||||
|
|
||||||
|
if (w > 1)
|
||||||
|
w >>= 1;
|
||||||
|
|
||||||
|
if (d > 1)
|
||||||
|
d >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t slice = 0; slice < d; ++slice)
|
|
||||||
{
|
|
||||||
totalPixelSize += uint64_t(slicePitch);
|
|
||||||
++nimages;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (h > 1)
|
|
||||||
h >>= 1;
|
|
||||||
|
|
||||||
if (w > 1)
|
|
||||||
w >>= 1;
|
|
||||||
|
|
||||||
if (d > 1)
|
|
||||||
d >>= 1;
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
nImages = pixelSize = 0;
|
nImages = pixelSize = 0;
|
||||||
@ -202,57 +202,57 @@ bool DirectX::Internal::SetupImageArray(
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case TEX_DIMENSION_TEXTURE3D:
|
case TEX_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
if (metadata.mipLevels == 0 || metadata.depth == 0)
|
|
||||||
{
|
{
|
||||||
return false;
|
if (metadata.mipLevels == 0 || metadata.depth == 0)
|
||||||
}
|
|
||||||
|
|
||||||
size_t w = metadata.width;
|
|
||||||
size_t h = metadata.height;
|
|
||||||
size_t d = metadata.depth;
|
|
||||||
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
|
||||||
size_t rowPitch, slicePitch;
|
|
||||||
if (FAILED(ComputePitch(metadata.format, w, h, rowPitch, slicePitch, cpFlags)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for (size_t slice = 0; slice < d; ++slice)
|
|
||||||
{
|
{
|
||||||
if (index >= nImages)
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We use the same memory organization that Direct3D 11 needs for D3D11_SUBRESOURCE_DATA
|
|
||||||
// with all slices of a given miplevel being continuous in memory
|
|
||||||
images[index].width = w;
|
|
||||||
images[index].height = h;
|
|
||||||
images[index].format = metadata.format;
|
|
||||||
images[index].rowPitch = rowPitch;
|
|
||||||
images[index].slicePitch = slicePitch;
|
|
||||||
images[index].pixels = pixels;
|
|
||||||
++index;
|
|
||||||
|
|
||||||
pixels += slicePitch;
|
|
||||||
if (pixels > pEndBits)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h > 1)
|
size_t w = metadata.width;
|
||||||
h >>= 1;
|
size_t h = metadata.height;
|
||||||
|
size_t d = metadata.depth;
|
||||||
|
|
||||||
if (w > 1)
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
w >>= 1;
|
{
|
||||||
|
size_t rowPitch, slicePitch;
|
||||||
|
if (FAILED(ComputePitch(metadata.format, w, h, rowPitch, slicePitch, cpFlags)))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (d > 1)
|
for (size_t slice = 0; slice < d; ++slice)
|
||||||
d >>= 1;
|
{
|
||||||
|
if (index >= nImages)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We use the same memory organization that Direct3D 11 needs for D3D11_SUBRESOURCE_DATA
|
||||||
|
// with all slices of a given miplevel being continuous in memory
|
||||||
|
images[index].width = w;
|
||||||
|
images[index].height = h;
|
||||||
|
images[index].format = metadata.format;
|
||||||
|
images[index].rowPitch = rowPitch;
|
||||||
|
images[index].slicePitch = slicePitch;
|
||||||
|
images[index].pixels = pixels;
|
||||||
|
++index;
|
||||||
|
|
||||||
|
pixels += slicePitch;
|
||||||
|
if (pixels > pEndBits)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (h > 1)
|
||||||
|
h >>= 1;
|
||||||
|
|
||||||
|
if (w > 1)
|
||||||
|
w >>= 1;
|
||||||
|
|
||||||
|
if (d > 1)
|
||||||
|
d >>= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -801,7 +801,7 @@ bool ScratchImage::IsAlphaAllOpaque() const noexcept
|
|||||||
|
|
||||||
for (size_t index = 0; index < m_nimages; ++index)
|
for (size_t index = 0; index < m_nimages; ++index)
|
||||||
{
|
{
|
||||||
#pragma warning( suppress : 6011 )
|
#pragma warning( suppress : 6011 )
|
||||||
const Image& img = m_image[index];
|
const Image& img = m_image[index];
|
||||||
|
|
||||||
const uint8_t *pPixels = img.pixels;
|
const uint8_t *pPixels = img.pixels;
|
||||||
|
@ -305,10 +305,10 @@ namespace
|
|||||||
|
|
||||||
|
|
||||||
HRESULT EstimateAlphaScaleForCoverage(
|
HRESULT EstimateAlphaScaleForCoverage(
|
||||||
const Image& srcImage,
|
const Image& srcImage,
|
||||||
float alphaReference,
|
float alphaReference,
|
||||||
float targetCoverage,
|
float targetCoverage,
|
||||||
float& alphaScale) noexcept
|
float& alphaScale) noexcept
|
||||||
{
|
{
|
||||||
float minAlphaScale = 0.0f;
|
float minAlphaScale = 0.0f;
|
||||||
float maxAlphaScale = 4.0f;
|
float maxAlphaScale = 4.0f;
|
||||||
@ -454,16 +454,16 @@ HRESULT DirectX::Internal::ResizeSeparateColorAndAlpha(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
if (iswic2)
|
if (iswic2)
|
||||||
{
|
{
|
||||||
colorBytesInPixel = colorBytesPerPixel = 12;
|
colorBytesInPixel = colorBytesPerPixel = 12;
|
||||||
colorPixelFormat = GUID_WICPixelFormat96bppRGBFloat;
|
colorPixelFormat = GUID_WICPixelFormat96bppRGBFloat;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(iswic2);
|
UNREFERENCED_PARAMETER(iswic2);
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
colorBytesInPixel = 12;
|
colorBytesInPixel = 12;
|
||||||
colorBytesPerPixel = 16;
|
colorBytesPerPixel = 16;
|
||||||
@ -593,7 +593,7 @@ HRESULT DirectX::Internal::ResizeSeparateColorAndAlpha(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#pragma warning( suppress : 26014 6386 ) // No overflow possible here
|
#pragma warning( suppress : 26014 6386 ) // No overflow possible here
|
||||||
memcpy_s(colorWithAlphaData + colorWithAlphaIndex, colorWithAlphaBytesPerPixel, colorData + colorIndex, colorBytesInPixel);
|
memcpy_s(colorWithAlphaData + colorWithAlphaIndex, colorWithAlphaBytesPerPixel, colorData + colorIndex, colorBytesInPixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -642,14 +642,14 @@ namespace
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
||||||
if (format == DXGI_FORMAT_R16G16B16A16_FLOAT
|
if (format == DXGI_FORMAT_R16G16B16A16_FLOAT
|
||||||
|| format == DXGI_FORMAT_R16_FLOAT)
|
|| format == DXGI_FORMAT_R16_FLOAT)
|
||||||
{
|
{
|
||||||
// Use non-WIC code paths as these conversions are not supported by Xbox version of WIC
|
// Use non-WIC code paths as these conversions are not supported by Xbox version of WIC
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static_assert(TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MODE_MASK");
|
static_assert(TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MODE_MASK");
|
||||||
|
|
||||||
@ -921,9 +921,9 @@ namespace
|
|||||||
// Resize base image to each target mip level
|
// Resize base image to each target mip level
|
||||||
for (size_t level = 1; level < levels; ++level)
|
for (size_t level = 1; level < levels; ++level)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row, 0xCD, sizeof(XMVECTOR)*width);
|
memset(row, 0xCD, sizeof(XMVECTOR)*width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 2D point filter
|
// 2D point filter
|
||||||
const Image* src = mipChain.GetImage(level - 1, item, 0);
|
const Image* src = mipChain.GetImage(level - 1, item, 0);
|
||||||
@ -1129,10 +1129,10 @@ namespace
|
|||||||
const size_t nheight = (height > 1) ? (height >> 1) : 1;
|
const size_t nheight = (height > 1) ? (height >> 1) : 1;
|
||||||
CreateLinearFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, lfY);
|
CreateLinearFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, lfY);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row0, 0xCD, sizeof(XMVECTOR)*width);
|
memset(row0, 0xCD, sizeof(XMVECTOR)*width);
|
||||||
memset(row1, 0xDD, sizeof(XMVECTOR)*width);
|
memset(row1, 0xDD, sizeof(XMVECTOR)*width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t u0 = size_t(-1);
|
size_t u0 = size_t(-1);
|
||||||
size_t u1 = size_t(-1);
|
size_t u1 = size_t(-1);
|
||||||
@ -1190,6 +1190,10 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--- 2D Cubic Filter ---
|
//--- 2D Cubic Filter ---
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic ignored "-Wextra-semi-stmt"
|
||||||
|
#endif
|
||||||
|
|
||||||
HRESULT Generate2DMipsCubicFilter(size_t levels, TEX_FILTER_FLAGS filter, const ScratchImage& mipChain, size_t item) noexcept
|
HRESULT Generate2DMipsCubicFilter(size_t levels, TEX_FILTER_FLAGS filter, const ScratchImage& mipChain, size_t item) noexcept
|
||||||
{
|
{
|
||||||
using namespace DirectX::Filters;
|
using namespace DirectX::Filters;
|
||||||
@ -1244,12 +1248,12 @@ namespace
|
|||||||
const size_t nheight = (height > 1) ? (height >> 1) : 1;
|
const size_t nheight = (height > 1) ? (height >> 1) : 1;
|
||||||
CreateCubicFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, (filter & TEX_FILTER_MIRROR_V) != 0, cfY);
|
CreateCubicFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, (filter & TEX_FILTER_MIRROR_V) != 0, cfY);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row0, 0xCD, sizeof(XMVECTOR)*width);
|
memset(row0, 0xCD, sizeof(XMVECTOR)*width);
|
||||||
memset(row1, 0xDD, sizeof(XMVECTOR)*width);
|
memset(row1, 0xDD, sizeof(XMVECTOR)*width);
|
||||||
memset(row2, 0xED, sizeof(XMVECTOR)*width);
|
memset(row2, 0xED, sizeof(XMVECTOR)*width);
|
||||||
memset(row3, 0xFD, sizeof(XMVECTOR)*width);
|
memset(row3, 0xFD, sizeof(XMVECTOR)*width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t u0 = size_t(-1);
|
size_t u0 = size_t(-1);
|
||||||
size_t u1 = size_t(-1);
|
size_t u1 = size_t(-1);
|
||||||
@ -1353,12 +1357,12 @@ namespace
|
|||||||
|
|
||||||
XMVECTOR C0, C1, C2, C3;
|
XMVECTOR C0, C1, C2, C3;
|
||||||
|
|
||||||
CUBIC_INTERPOLATE(C0, toX.x, row0[toX.u0], row0[toX.u1], row0[toX.u2], row0[toX.u3])
|
CUBIC_INTERPOLATE(C0, toX.x, row0[toX.u0], row0[toX.u1], row0[toX.u2], row0[toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C1, toX.x, row1[toX.u0], row1[toX.u1], row1[toX.u2], row1[toX.u3])
|
CUBIC_INTERPOLATE(C1, toX.x, row1[toX.u0], row1[toX.u1], row1[toX.u2], row1[toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C2, toX.x, row2[toX.u0], row2[toX.u1], row2[toX.u2], row2[toX.u3])
|
CUBIC_INTERPOLATE(C2, toX.x, row2[toX.u0], row2[toX.u1], row2[toX.u2], row2[toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C3, toX.x, row3[toX.u0], row3[toX.u1], row3[toX.u2], row3[toX.u3])
|
CUBIC_INTERPOLATE(C3, toX.x, row3[toX.u0], row3[toX.u1], row3[toX.u2], row3[toX.u3]);
|
||||||
|
|
||||||
CUBIC_INTERPOLATE(target[x], toY.x, C0, C1, C2, C3)
|
CUBIC_INTERPOLATE(target[x], toY.x, C0, C1, C2, C3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StoreScanlineLinear(pDest, dest->rowPitch, dest->format, target, nwidth, filter))
|
if (!StoreScanlineLinear(pDest, dest->rowPitch, dest->format, target, nwidth, filter))
|
||||||
@ -1433,9 +1437,9 @@ namespace
|
|||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row, 0xCD, sizeof(XMVECTOR)*width);
|
memset(row, 0xCD, sizeof(XMVECTOR)*width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto xFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfX.get()) + tfX->sizeInBytes);
|
auto xFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfX.get()) + tfX->sizeInBytes);
|
||||||
auto yFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfY.get()) + tfY->sizeInBytes);
|
auto yFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfY.get()) + tfY->sizeInBytes);
|
||||||
@ -1550,18 +1554,18 @@ namespace
|
|||||||
{
|
{
|
||||||
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
||||||
case DXGI_FORMAT_R10G10B10A2_UINT:
|
case DXGI_FORMAT_R10G10B10A2_UINT:
|
||||||
{
|
|
||||||
// Need to slightly bias results for floating-point error accumulation which can
|
|
||||||
// be visible with harshly quantized values
|
|
||||||
static const XMVECTORF32 Bias = { { { 0.f, 0.f, 0.f, 0.1f } } };
|
|
||||||
|
|
||||||
XMVECTOR* ptr = pAccSrc;
|
|
||||||
for (size_t i = 0; i < dest->width; ++i, ++ptr)
|
|
||||||
{
|
{
|
||||||
*ptr = XMVectorAdd(*ptr, Bias);
|
// Need to slightly bias results for floating-point error accumulation which can
|
||||||
|
// be visible with harshly quantized values
|
||||||
|
static const XMVECTORF32 Bias = { { { 0.f, 0.f, 0.f, 0.1f } } };
|
||||||
|
|
||||||
|
XMVECTOR* ptr = pAccSrc;
|
||||||
|
for (size_t i = 0; i < dest->width; ++i, ++ptr)
|
||||||
|
{
|
||||||
|
*ptr = XMVectorAdd(*ptr, Bias);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -1673,9 +1677,9 @@ namespace
|
|||||||
// Resize base image to each target mip level
|
// Resize base image to each target mip level
|
||||||
for (size_t level = 1; level < levels; ++level)
|
for (size_t level = 1; level < levels; ++level)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row, 0xCD, sizeof(XMVECTOR)*width);
|
memset(row, 0xCD, sizeof(XMVECTOR)*width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (depth > 1)
|
if (depth > 1)
|
||||||
{
|
{
|
||||||
@ -2012,12 +2016,12 @@ namespace
|
|||||||
const size_t nheight = (height > 1) ? (height >> 1) : 1;
|
const size_t nheight = (height > 1) ? (height >> 1) : 1;
|
||||||
CreateLinearFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, lfY);
|
CreateLinearFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, lfY);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(urow0, 0xCD, sizeof(XMVECTOR)*width);
|
memset(urow0, 0xCD, sizeof(XMVECTOR)*width);
|
||||||
memset(urow1, 0xDD, sizeof(XMVECTOR)*width);
|
memset(urow1, 0xDD, sizeof(XMVECTOR)*width);
|
||||||
memset(vrow0, 0xED, sizeof(XMVECTOR)*width);
|
memset(vrow0, 0xED, sizeof(XMVECTOR)*width);
|
||||||
memset(vrow1, 0xFD, sizeof(XMVECTOR)*width);
|
memset(vrow1, 0xFD, sizeof(XMVECTOR)*width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (depth > 1)
|
if (depth > 1)
|
||||||
{
|
{
|
||||||
@ -2216,7 +2220,7 @@ namespace
|
|||||||
const size_t nheight = (height > 1) ? (height >> 1) : 1;
|
const size_t nheight = (height > 1) ? (height >> 1) : 1;
|
||||||
CreateCubicFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, (filter & TEX_FILTER_MIRROR_V) != 0, cfY);
|
CreateCubicFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, (filter & TEX_FILTER_MIRROR_V) != 0, cfY);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
for (size_t j = 0; j < 4; ++j)
|
for (size_t j = 0; j < 4; ++j)
|
||||||
{
|
{
|
||||||
memset(urow[j], 0xCD, sizeof(XMVECTOR)*width);
|
memset(urow[j], 0xCD, sizeof(XMVECTOR)*width);
|
||||||
@ -2224,7 +2228,7 @@ namespace
|
|||||||
memset(srow[j], 0xED, sizeof(XMVECTOR)*width);
|
memset(srow[j], 0xED, sizeof(XMVECTOR)*width);
|
||||||
memset(trow[j], 0xFD, sizeof(XMVECTOR)*width);
|
memset(trow[j], 0xFD, sizeof(XMVECTOR)*width);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (depth > 1)
|
if (depth > 1)
|
||||||
{
|
{
|
||||||
@ -2384,15 +2388,15 @@ namespace
|
|||||||
for (size_t j = 0; j < 4; ++j)
|
for (size_t j = 0; j < 4; ++j)
|
||||||
{
|
{
|
||||||
XMVECTOR C0, C1, C2, C3;
|
XMVECTOR C0, C1, C2, C3;
|
||||||
CUBIC_INTERPOLATE(C0, toX.x, urow[j][toX.u0], urow[j][toX.u1], urow[j][toX.u2], urow[j][toX.u3])
|
CUBIC_INTERPOLATE(C0, toX.x, urow[j][toX.u0], urow[j][toX.u1], urow[j][toX.u2], urow[j][toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C1, toX.x, vrow[j][toX.u0], vrow[j][toX.u1], vrow[j][toX.u2], vrow[j][toX.u3])
|
CUBIC_INTERPOLATE(C1, toX.x, vrow[j][toX.u0], vrow[j][toX.u1], vrow[j][toX.u2], vrow[j][toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C2, toX.x, srow[j][toX.u0], srow[j][toX.u1], srow[j][toX.u2], srow[j][toX.u3])
|
CUBIC_INTERPOLATE(C2, toX.x, srow[j][toX.u0], srow[j][toX.u1], srow[j][toX.u2], srow[j][toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C3, toX.x, trow[j][toX.u0], trow[j][toX.u1], trow[j][toX.u2], trow[j][toX.u3])
|
CUBIC_INTERPOLATE(C3, toX.x, trow[j][toX.u0], trow[j][toX.u1], trow[j][toX.u2], trow[j][toX.u3]);
|
||||||
|
|
||||||
CUBIC_INTERPOLATE(D[j], toY.x, C0, C1, C2, C3)
|
CUBIC_INTERPOLATE(D[j], toY.x, C0, C1, C2, C3);
|
||||||
}
|
}
|
||||||
|
|
||||||
CUBIC_INTERPOLATE(target[x], toZ.x, D[0], D[1], D[2], D[3])
|
CUBIC_INTERPOLATE(target[x], toZ.x, D[0], D[1], D[2], D[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StoreScanlineLinear(pDest, dest->rowPitch, dest->format, target, nwidth, filter))
|
if (!StoreScanlineLinear(pDest, dest->rowPitch, dest->format, target, nwidth, filter))
|
||||||
@ -2516,12 +2520,12 @@ namespace
|
|||||||
auto const& toX = cfX[x];
|
auto const& toX = cfX[x];
|
||||||
|
|
||||||
XMVECTOR C0, C1, C2, C3;
|
XMVECTOR C0, C1, C2, C3;
|
||||||
CUBIC_INTERPOLATE(C0, toX.x, urow[0][toX.u0], urow[0][toX.u1], urow[0][toX.u2], urow[0][toX.u3])
|
CUBIC_INTERPOLATE(C0, toX.x, urow[0][toX.u0], urow[0][toX.u1], urow[0][toX.u2], urow[0][toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C1, toX.x, vrow[0][toX.u0], vrow[0][toX.u1], vrow[0][toX.u2], vrow[0][toX.u3])
|
CUBIC_INTERPOLATE(C1, toX.x, vrow[0][toX.u0], vrow[0][toX.u1], vrow[0][toX.u2], vrow[0][toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C2, toX.x, srow[0][toX.u0], srow[0][toX.u1], srow[0][toX.u2], srow[0][toX.u3])
|
CUBIC_INTERPOLATE(C2, toX.x, srow[0][toX.u0], srow[0][toX.u1], srow[0][toX.u2], srow[0][toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C3, toX.x, trow[0][toX.u0], trow[0][toX.u1], trow[0][toX.u2], trow[0][toX.u3])
|
CUBIC_INTERPOLATE(C3, toX.x, trow[0][toX.u0], trow[0][toX.u1], trow[0][toX.u2], trow[0][toX.u3]);
|
||||||
|
|
||||||
CUBIC_INTERPOLATE(target[x], toY.x, C0, C1, C2, C3)
|
CUBIC_INTERPOLATE(target[x], toY.x, C0, C1, C2, C3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StoreScanlineLinear(pDest, dest->rowPitch, dest->format, target, nwidth, filter))
|
if (!StoreScanlineLinear(pDest, dest->rowPitch, dest->format, target, nwidth, filter))
|
||||||
@ -2592,9 +2596,9 @@ namespace
|
|||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row, 0xCD, sizeof(XMVECTOR)*width);
|
memset(row, 0xCD, sizeof(XMVECTOR)*width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto xFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfX.get()) + tfX->sizeInBytes);
|
auto xFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfX.get()) + tfX->sizeInBytes);
|
||||||
auto yFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfY.get()) + tfY->sizeInBytes);
|
auto yFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfY.get()) + tfY->sizeInBytes);
|
||||||
@ -2739,18 +2743,18 @@ namespace
|
|||||||
{
|
{
|
||||||
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
||||||
case DXGI_FORMAT_R10G10B10A2_UINT:
|
case DXGI_FORMAT_R10G10B10A2_UINT:
|
||||||
{
|
|
||||||
// Need to slightly bias results for floating-point error accumulation which can
|
|
||||||
// be visible with harshly quantized values
|
|
||||||
static const XMVECTORF32 Bias = { { { 0.f, 0.f, 0.f, 0.1f } } };
|
|
||||||
|
|
||||||
XMVECTOR* ptr = pAccSrc;
|
|
||||||
for (size_t i = 0; i < dest->width; ++i, ++ptr)
|
|
||||||
{
|
{
|
||||||
*ptr = XMVectorAdd(*ptr, Bias);
|
// Need to slightly bias results for floating-point error accumulation which can
|
||||||
|
// be visible with harshly quantized values
|
||||||
|
static const XMVECTORF32 Bias = { { { 0.f, 0.f, 0.f, 0.1f } } };
|
||||||
|
|
||||||
|
XMVECTOR* ptr = pAccSrc;
|
||||||
|
for (size_t i = 0; i < dest->width; ++i, ++ptr)
|
||||||
|
{
|
||||||
|
*ptr = XMVectorAdd(*ptr, Bias);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -2854,56 +2858,56 @@ HRESULT DirectX::GenerateMipMaps(
|
|||||||
case TEX_FILTER_FANT: // Equivalent to Box filter
|
case TEX_FILTER_FANT: // Equivalent to Box filter
|
||||||
case TEX_FILTER_LINEAR:
|
case TEX_FILTER_LINEAR:
|
||||||
case TEX_FILTER_CUBIC:
|
case TEX_FILTER_CUBIC:
|
||||||
{
|
|
||||||
static_assert(TEX_FILTER_FANT == TEX_FILTER_BOX, "TEX_FILTER_ flag alias mismatch");
|
|
||||||
|
|
||||||
if (wicpf)
|
|
||||||
{
|
{
|
||||||
// Case 1: Base image format is supported by Windows Imaging Component
|
static_assert(TEX_FILTER_FANT == TEX_FILTER_BOX, "TEX_FILTER_ flag alias mismatch");
|
||||||
hr = (baseImage.height > 1 || !allow1D)
|
|
||||||
? mipChain.Initialize2D(baseImage.format, baseImage.width, baseImage.height, 1, levels)
|
|
||||||
: mipChain.Initialize1D(baseImage.format, baseImage.width, 1, levels);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
return GenerateMipMapsUsingWIC(baseImage, filter, levels, pfGUID, mipChain, 0);
|
if (wicpf)
|
||||||
|
{
|
||||||
|
// Case 1: Base image format is supported by Windows Imaging Component
|
||||||
|
hr = (baseImage.height > 1 || !allow1D)
|
||||||
|
? mipChain.Initialize2D(baseImage.format, baseImage.width, baseImage.height, 1, levels)
|
||||||
|
: mipChain.Initialize1D(baseImage.format, baseImage.width, 1, levels);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
return GenerateMipMapsUsingWIC(baseImage, filter, levels, pfGUID, mipChain, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Case 2: Base image format is not supported by WIC, so we have to convert, generate, and convert back
|
||||||
|
assert(baseImage.format != DXGI_FORMAT_R32G32B32A32_FLOAT);
|
||||||
|
ScratchImage temp;
|
||||||
|
hr = ConvertToR32G32B32A32(baseImage, temp);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
const Image *timg = temp.GetImage(0, 0, 0);
|
||||||
|
if (!timg)
|
||||||
|
return E_POINTER;
|
||||||
|
|
||||||
|
ScratchImage tMipChain;
|
||||||
|
hr = (baseImage.height > 1 || !allow1D)
|
||||||
|
? tMipChain.Initialize2D(DXGI_FORMAT_R32G32B32A32_FLOAT, baseImage.width, baseImage.height, 1, levels)
|
||||||
|
: tMipChain.Initialize1D(DXGI_FORMAT_R32G32B32A32_FLOAT, baseImage.width, 1, levels);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
hr = GenerateMipMapsUsingWIC(*timg, filter, levels, GUID_WICPixelFormat128bppRGBAFloat, tMipChain, 0);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
temp.Release();
|
||||||
|
|
||||||
|
return ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), baseImage.format, mipChain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Case 2: Base image format is not supported by WIC, so we have to convert, generate, and convert back
|
|
||||||
assert(baseImage.format != DXGI_FORMAT_R32G32B32A32_FLOAT);
|
|
||||||
ScratchImage temp;
|
|
||||||
hr = ConvertToR32G32B32A32(baseImage, temp);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
const Image *timg = temp.GetImage(0, 0, 0);
|
|
||||||
if (!timg)
|
|
||||||
return E_POINTER;
|
|
||||||
|
|
||||||
ScratchImage tMipChain;
|
|
||||||
hr = (baseImage.height > 1 || !allow1D)
|
|
||||||
? tMipChain.Initialize2D(DXGI_FORMAT_R32G32B32A32_FLOAT, baseImage.width, baseImage.height, 1, levels)
|
|
||||||
: tMipChain.Initialize1D(DXGI_FORMAT_R32G32B32A32_FLOAT, baseImage.width, 1, levels);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
hr = GenerateMipMapsUsingWIC(*timg, filter, levels, GUID_WICPixelFormat128bppRGBAFloat, tMipChain, 0);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
temp.Release();
|
|
||||||
|
|
||||||
return ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), baseImage.format, mipChain);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return HRESULT_E_NOT_SUPPORTED;
|
return HRESULT_E_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
{
|
{
|
||||||
//--- Use custom filters to generate mipmaps ----------------------------------
|
//--- Use custom filters to generate mipmaps ----------------------------------
|
||||||
TexMetadata mdata = {};
|
TexMetadata mdata = {};
|
||||||
@ -3069,69 +3073,69 @@ HRESULT DirectX::GenerateMipMaps(
|
|||||||
case TEX_FILTER_FANT: // Equivalent to Box filter
|
case TEX_FILTER_FANT: // Equivalent to Box filter
|
||||||
case TEX_FILTER_LINEAR:
|
case TEX_FILTER_LINEAR:
|
||||||
case TEX_FILTER_CUBIC:
|
case TEX_FILTER_CUBIC:
|
||||||
{
|
|
||||||
static_assert(TEX_FILTER_FANT == TEX_FILTER_BOX, "TEX_FILTER_ flag alias mismatch");
|
|
||||||
|
|
||||||
if (wicpf)
|
|
||||||
{
|
{
|
||||||
// Case 1: Base image format is supported by Windows Imaging Component
|
static_assert(TEX_FILTER_FANT == TEX_FILTER_BOX, "TEX_FILTER_ flag alias mismatch");
|
||||||
TexMetadata mdata2 = metadata;
|
|
||||||
mdata2.mipLevels = levels;
|
|
||||||
hr = mipChain.Initialize(mdata2);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
for (size_t item = 0; item < metadata.arraySize; ++item)
|
if (wicpf)
|
||||||
{
|
{
|
||||||
hr = GenerateMipMapsUsingWIC(baseImages[item], filter, levels, pfGUID, mipChain, item);
|
// Case 1: Base image format is supported by Windows Imaging Component
|
||||||
|
TexMetadata mdata2 = metadata;
|
||||||
|
mdata2.mipLevels = levels;
|
||||||
|
hr = mipChain.Initialize(mdata2);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
for (size_t item = 0; item < metadata.arraySize; ++item)
|
||||||
{
|
{
|
||||||
mipChain.Release();
|
hr = GenerateMipMapsUsingWIC(baseImages[item], filter, levels, pfGUID, mipChain, item);
|
||||||
return hr;
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
mipChain.Release();
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Case 2: Base image format is not supported by WIC, so we have to convert, generate, and convert back
|
|
||||||
assert(metadata.format != DXGI_FORMAT_R32G32B32A32_FLOAT);
|
|
||||||
|
|
||||||
TexMetadata mdata2 = metadata;
|
|
||||||
mdata2.mipLevels = levels;
|
|
||||||
mdata2.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
|
||||||
ScratchImage tMipChain;
|
|
||||||
hr = tMipChain.Initialize(mdata2);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
for (size_t item = 0; item < metadata.arraySize; ++item)
|
|
||||||
{
|
{
|
||||||
ScratchImage temp;
|
// Case 2: Base image format is not supported by WIC, so we have to convert, generate, and convert back
|
||||||
hr = ConvertToR32G32B32A32(baseImages[item], temp);
|
assert(metadata.format != DXGI_FORMAT_R32G32B32A32_FLOAT);
|
||||||
|
|
||||||
|
TexMetadata mdata2 = metadata;
|
||||||
|
mdata2.mipLevels = levels;
|
||||||
|
mdata2.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||||
|
ScratchImage tMipChain;
|
||||||
|
hr = tMipChain.Initialize(mdata2);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
const Image *timg = temp.GetImage(0, 0, 0);
|
for (size_t item = 0; item < metadata.arraySize; ++item)
|
||||||
if (!timg)
|
{
|
||||||
return E_POINTER;
|
ScratchImage temp;
|
||||||
|
hr = ConvertToR32G32B32A32(baseImages[item], temp);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
hr = GenerateMipMapsUsingWIC(*timg, filter, levels, GUID_WICPixelFormat128bppRGBAFloat, tMipChain, item);
|
const Image *timg = temp.GetImage(0, 0, 0);
|
||||||
if (FAILED(hr))
|
if (!timg)
|
||||||
return hr;
|
return E_POINTER;
|
||||||
|
|
||||||
|
hr = GenerateMipMapsUsingWIC(*timg, filter, levels, GUID_WICPixelFormat128bppRGBAFloat, tMipChain, item);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), metadata.format, mipChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), metadata.format, mipChain);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return HRESULT_E_NOT_SUPPORTED;
|
return HRESULT_E_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
{
|
{
|
||||||
//--- Use custom filters to generate mipmaps ----------------------------------
|
//--- Use custom filters to generate mipmaps ----------------------------------
|
||||||
TexMetadata mdata2 = metadata;
|
TexMetadata mdata2 = metadata;
|
||||||
|
@ -246,9 +246,9 @@ namespace
|
|||||||
if (!LoadScanline(sScanline, width, pSrc, spitch, srcImage.format))
|
if (!LoadScanline(sScanline, width, pSrc, spitch, srcImage.format))
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(dScanline, 0xCD, sizeof(XMVECTOR)*width);
|
memset(dScanline, 0xCD, sizeof(XMVECTOR)*width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pixelFunc(dScanline, sScanline, width, h);
|
pixelFunc(dScanline, sScanline, width, h);
|
||||||
|
|
||||||
@ -563,33 +563,33 @@ HRESULT DirectX::EvaluateImage(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TEX_DIMENSION_TEXTURE3D:
|
case TEX_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
size_t index = 0;
|
|
||||||
size_t d = metadata.depth;
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
{
|
||||||
for (size_t slice = 0; slice < d; ++slice, ++index)
|
size_t index = 0;
|
||||||
|
size_t d = metadata.depth;
|
||||||
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
{
|
{
|
||||||
if (index >= nimages)
|
for (size_t slice = 0; slice < d; ++slice, ++index)
|
||||||
return E_FAIL;
|
{
|
||||||
|
if (index >= nimages)
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
const Image& img = images[index];
|
const Image& img = images[index];
|
||||||
if (img.format != format)
|
if (img.format != format)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
|
|
||||||
if ((img.width > UINT32_MAX) || (img.height > UINT32_MAX))
|
if ((img.width > UINT32_MAX) || (img.height > UINT32_MAX))
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
|
|
||||||
HRESULT hr = EvaluateImage_(img, pixelFunc);
|
HRESULT hr = EvaluateImage_(img, pixelFunc);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d > 1)
|
||||||
|
d >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d > 1)
|
|
||||||
d >>= 1;
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
@ -710,53 +710,53 @@ HRESULT DirectX::TransformImage(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TEX_DIMENSION_TEXTURE3D:
|
case TEX_DIMENSION_TEXTURE3D:
|
||||||
{
|
|
||||||
size_t index = 0;
|
|
||||||
size_t d = metadata.depth;
|
|
||||||
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
|
||||||
{
|
{
|
||||||
for (size_t slice = 0; slice < d; ++slice, ++index)
|
size_t index = 0;
|
||||||
|
size_t d = metadata.depth;
|
||||||
|
for (size_t level = 0; level < metadata.mipLevels; ++level)
|
||||||
{
|
{
|
||||||
if (index >= nimages)
|
for (size_t slice = 0; slice < d; ++slice, ++index)
|
||||||
{
|
{
|
||||||
result.Release();
|
if (index >= nimages)
|
||||||
return E_FAIL;
|
{
|
||||||
|
result.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Image& src = srcImages[index];
|
||||||
|
if (src.format != metadata.format)
|
||||||
|
{
|
||||||
|
result.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((src.width > UINT32_MAX) || (src.height > UINT32_MAX))
|
||||||
|
{
|
||||||
|
result.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Image& dst = dest[index];
|
||||||
|
|
||||||
|
if (src.width != dst.width || src.height != dst.height)
|
||||||
|
{
|
||||||
|
result.Release();
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = TransformImage_(src, pixelFunc, dst);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
result.Release();
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Image& src = srcImages[index];
|
if (d > 1)
|
||||||
if (src.format != metadata.format)
|
d >>= 1;
|
||||||
{
|
|
||||||
result.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((src.width > UINT32_MAX) || (src.height > UINT32_MAX))
|
|
||||||
{
|
|
||||||
result.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Image& dst = dest[index];
|
|
||||||
|
|
||||||
if (src.width != dst.width || src.height != dst.height)
|
|
||||||
{
|
|
||||||
result.Release();
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = TransformImage_(src, pixelFunc, dst);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
result.Release();
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d > 1)
|
|
||||||
d >>= 1;
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result.Release();
|
result.Release();
|
||||||
|
@ -34,11 +34,11 @@ namespace
|
|||||||
case CNMAP_CHANNEL_ALPHA: return XMVectorGetW(val);
|
case CNMAP_CHANNEL_ALPHA: return XMVectorGetW(val);
|
||||||
|
|
||||||
case CNMAP_CHANNEL_LUMINANCE:
|
case CNMAP_CHANNEL_LUMINANCE:
|
||||||
{
|
{
|
||||||
const XMVECTOR v = XMVectorMultiply(val, lScale);
|
const XMVECTOR v = XMVectorMultiply(val, lScale);
|
||||||
XMStoreFloat4A(&f, v);
|
XMStoreFloat4A(&f, v);
|
||||||
return f.x + f.y + f.z;
|
return f.x + f.y + f.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -210,7 +210,7 @@ namespace DirectX
|
|||||||
{
|
{
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// WIC helper functions
|
// WIC helper functions
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
DXGI_FORMAT __cdecl WICToDXGI(_In_ const GUID& guid) noexcept;
|
DXGI_FORMAT __cdecl WICToDXGI(_In_ const GUID& guid) noexcept;
|
||||||
bool __cdecl DXGIToWIC(_In_ DXGI_FORMAT format, _Out_ GUID& guid, _In_ bool ignoreRGBvsBGR = false) noexcept;
|
bool __cdecl DXGIToWIC(_In_ DXGI_FORMAT format, _Out_ GUID& guid, _In_ bool ignoreRGBvsBGR = false) noexcept;
|
||||||
|
|
||||||
@ -295,7 +295,7 @@ namespace DirectX
|
|||||||
return WICBitmapInterpolationModeFant;
|
return WICBitmapInterpolationModeFant;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
// Image helper functions
|
// Image helper functions
|
||||||
@ -313,32 +313,36 @@ namespace DirectX
|
|||||||
|
|
||||||
enum TEXP_SCANLINE_FLAGS : uint32_t
|
enum TEXP_SCANLINE_FLAGS : uint32_t
|
||||||
{
|
{
|
||||||
TEXP_SCANLINE_NONE = 0,
|
TEXP_SCANLINE_NONE = 0,
|
||||||
TEXP_SCANLINE_SETALPHA = 0x1, // Set alpha channel to known opaque value
|
|
||||||
TEXP_SCANLINE_LEGACY = 0x2, // Enables specific legacy format conversion cases
|
TEXP_SCANLINE_SETALPHA = 0x1,
|
||||||
|
// Set alpha channel to known opaque value
|
||||||
|
|
||||||
|
TEXP_SCANLINE_LEGACY = 0x2,
|
||||||
|
// Enables specific legacy format conversion cases
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CONVERT_FLAGS : uint32_t
|
enum CONVERT_FLAGS : uint32_t
|
||||||
{
|
{
|
||||||
CONVF_FLOAT = 0x1,
|
CONVF_FLOAT = 0x1,
|
||||||
CONVF_UNORM = 0x2,
|
CONVF_UNORM = 0x2,
|
||||||
CONVF_UINT = 0x4,
|
CONVF_UINT = 0x4,
|
||||||
CONVF_SNORM = 0x8,
|
CONVF_SNORM = 0x8,
|
||||||
CONVF_SINT = 0x10,
|
CONVF_SINT = 0x10,
|
||||||
CONVF_DEPTH = 0x20,
|
CONVF_DEPTH = 0x20,
|
||||||
CONVF_STENCIL = 0x40,
|
CONVF_STENCIL = 0x40,
|
||||||
CONVF_SHAREDEXP = 0x80,
|
CONVF_SHAREDEXP = 0x80,
|
||||||
CONVF_BGR = 0x100,
|
CONVF_BGR = 0x100,
|
||||||
CONVF_XR = 0x200,
|
CONVF_XR = 0x200,
|
||||||
CONVF_PACKED = 0x400,
|
CONVF_PACKED = 0x400,
|
||||||
CONVF_BC = 0x800,
|
CONVF_BC = 0x800,
|
||||||
CONVF_YUV = 0x1000,
|
CONVF_YUV = 0x1000,
|
||||||
CONVF_POS_ONLY = 0x2000,
|
CONVF_POS_ONLY = 0x2000,
|
||||||
CONVF_R = 0x10000,
|
CONVF_R = 0x10000,
|
||||||
CONVF_G = 0x20000,
|
CONVF_G = 0x20000,
|
||||||
CONVF_B = 0x40000,
|
CONVF_B = 0x40000,
|
||||||
CONVF_A = 0x80000,
|
CONVF_A = 0x80000,
|
||||||
CONVF_RGB_MASK = 0x70000,
|
CONVF_RGB_MASK = 0x70000,
|
||||||
CONVF_RGBA_MASK = 0xF0000,
|
CONVF_RGBA_MASK = 0xF0000,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -413,13 +417,13 @@ namespace DirectX
|
|||||||
bool __cdecl CalculateMipLevels3D(_In_ size_t width, _In_ size_t height, _In_ size_t depth,
|
bool __cdecl CalculateMipLevels3D(_In_ size_t width, _In_ size_t height, _In_ size_t depth,
|
||||||
_Inout_ size_t& mipLevels) noexcept;
|
_Inout_ size_t& mipLevels) noexcept;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HRESULT __cdecl ResizeSeparateColorAndAlpha(_In_ IWICImagingFactory* pWIC,
|
HRESULT __cdecl ResizeSeparateColorAndAlpha(_In_ IWICImagingFactory* pWIC,
|
||||||
_In_ bool iswic2,
|
_In_ bool iswic2,
|
||||||
_In_ IWICBitmap* original,
|
_In_ IWICBitmap* original,
|
||||||
_In_ size_t newWidth, _In_ size_t newHeight, _In_ TEX_FILTER_FLAGS filter,
|
_In_ size_t newWidth, _In_ size_t newHeight, _In_ TEX_FILTER_FLAGS filter,
|
||||||
_Inout_ const Image* img) noexcept;
|
_Inout_ const Image* img) noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace DirectX
|
} // namespace DirectX
|
||||||
|
@ -189,14 +189,14 @@ namespace
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
||||||
if (format == DXGI_FORMAT_R16G16B16A16_FLOAT
|
if (format == DXGI_FORMAT_R16G16B16A16_FLOAT
|
||||||
|| format == DXGI_FORMAT_R16_FLOAT)
|
|| format == DXGI_FORMAT_R16_FLOAT)
|
||||||
{
|
{
|
||||||
// Use non-WIC code paths as these conversions are not supported by Xbox version of WIC
|
// Use non-WIC code paths as these conversions are not supported by Xbox version of WIC
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static_assert(TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK");
|
static_assert(TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK");
|
||||||
|
|
||||||
@ -258,9 +258,9 @@ namespace
|
|||||||
|
|
||||||
XMVECTOR* row = target + destImage.width;
|
XMVECTOR* row = target + destImage.width;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
memset(row, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const uint8_t* pSrc = srcImage.pixels;
|
const uint8_t* pSrc = srcImage.pixels;
|
||||||
uint8_t* pDest = destImage.pixels;
|
uint8_t* pDest = destImage.pixels;
|
||||||
@ -321,10 +321,10 @@ namespace
|
|||||||
XMVECTOR* urow0 = target + destImage.width;
|
XMVECTOR* urow0 = target + destImage.width;
|
||||||
XMVECTOR* urow1 = urow0 + srcImage.width;
|
XMVECTOR* urow1 = urow0 + srcImage.width;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(urow0, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
memset(urow0, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
||||||
memset(urow1, 0xDD, sizeof(XMVECTOR)*srcImage.width);
|
memset(urow1, 0xDD, sizeof(XMVECTOR)*srcImage.width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const XMVECTOR* urow2 = urow0 + 1;
|
const XMVECTOR* urow2 = urow0 + 1;
|
||||||
const XMVECTOR* urow3 = urow1 + 1;
|
const XMVECTOR* urow3 = urow1 + 1;
|
||||||
@ -391,10 +391,10 @@ namespace
|
|||||||
XMVECTOR* row0 = target + destImage.width;
|
XMVECTOR* row0 = target + destImage.width;
|
||||||
XMVECTOR* row1 = row0 + srcImage.width;
|
XMVECTOR* row1 = row0 + srcImage.width;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row0, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
memset(row0, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
||||||
memset(row1, 0xDD, sizeof(XMVECTOR)*srcImage.width);
|
memset(row1, 0xDD, sizeof(XMVECTOR)*srcImage.width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const uint8_t* pSrc = srcImage.pixels;
|
const uint8_t* pSrc = srcImage.pixels;
|
||||||
uint8_t* pDest = destImage.pixels;
|
uint8_t* pDest = destImage.pixels;
|
||||||
@ -451,6 +451,10 @@ namespace
|
|||||||
|
|
||||||
|
|
||||||
//--- Cubic Filter ---
|
//--- Cubic Filter ---
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic ignored "-Wextra-semi-stmt"
|
||||||
|
#endif
|
||||||
|
|
||||||
HRESULT ResizeCubicFilter(const Image& srcImage, TEX_FILTER_FLAGS filter, const Image& destImage) noexcept
|
HRESULT ResizeCubicFilter(const Image& srcImage, TEX_FILTER_FLAGS filter, const Image& destImage) noexcept
|
||||||
{
|
{
|
||||||
using namespace DirectX::Filters;
|
using namespace DirectX::Filters;
|
||||||
@ -480,12 +484,12 @@ namespace
|
|||||||
XMVECTOR* row2 = row0 + srcImage.width * 2;
|
XMVECTOR* row2 = row0 + srcImage.width * 2;
|
||||||
XMVECTOR* row3 = row0 + srcImage.width * 3;
|
XMVECTOR* row3 = row0 + srcImage.width * 3;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row0, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
memset(row0, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
||||||
memset(row1, 0xDD, sizeof(XMVECTOR)*srcImage.width);
|
memset(row1, 0xDD, sizeof(XMVECTOR)*srcImage.width);
|
||||||
memset(row2, 0xED, sizeof(XMVECTOR)*srcImage.width);
|
memset(row2, 0xED, sizeof(XMVECTOR)*srcImage.width);
|
||||||
memset(row3, 0xFD, sizeof(XMVECTOR)*srcImage.width);
|
memset(row3, 0xFD, sizeof(XMVECTOR)*srcImage.width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const uint8_t* pSrc = srcImage.pixels;
|
const uint8_t* pSrc = srcImage.pixels;
|
||||||
uint8_t* pDest = destImage.pixels;
|
uint8_t* pDest = destImage.pixels;
|
||||||
@ -594,12 +598,12 @@ namespace
|
|||||||
|
|
||||||
XMVECTOR C0, C1, C2, C3;
|
XMVECTOR C0, C1, C2, C3;
|
||||||
|
|
||||||
CUBIC_INTERPOLATE(C0, toX.x, row0[toX.u0], row0[toX.u1], row0[toX.u2], row0[toX.u3])
|
CUBIC_INTERPOLATE(C0, toX.x, row0[toX.u0], row0[toX.u1], row0[toX.u2], row0[toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C1, toX.x, row1[toX.u0], row1[toX.u1], row1[toX.u2], row1[toX.u3])
|
CUBIC_INTERPOLATE(C1, toX.x, row1[toX.u0], row1[toX.u1], row1[toX.u2], row1[toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C2, toX.x, row2[toX.u0], row2[toX.u1], row2[toX.u2], row2[toX.u3])
|
CUBIC_INTERPOLATE(C2, toX.x, row2[toX.u0], row2[toX.u1], row2[toX.u2], row2[toX.u3]);
|
||||||
CUBIC_INTERPOLATE(C3, toX.x, row3[toX.u0], row3[toX.u1], row3[toX.u2], row3[toX.u3])
|
CUBIC_INTERPOLATE(C3, toX.x, row3[toX.u0], row3[toX.u1], row3[toX.u2], row3[toX.u3]);
|
||||||
|
|
||||||
CUBIC_INTERPOLATE(target[x], toY.x, C0, C1, C2, C3)
|
CUBIC_INTERPOLATE(target[x], toY.x, C0, C1, C2, C3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StoreScanlineLinear(pDest, destImage.rowPitch, destImage.format, target, destImage.width, filter))
|
if (!StoreScanlineLinear(pDest, destImage.rowPitch, destImage.format, target, destImage.width, filter))
|
||||||
@ -642,9 +646,9 @@ namespace
|
|||||||
|
|
||||||
XMVECTOR* row = scanline.get();
|
XMVECTOR* row = scanline.get();
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
memset(row, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
memset(row, 0xCD, sizeof(XMVECTOR)*srcImage.width);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto xFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfX.get()) + tfX->sizeInBytes);
|
auto xFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfX.get()) + tfX->sizeInBytes);
|
||||||
auto yFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfY.get()) + tfY->sizeInBytes);
|
auto yFromEnd = reinterpret_cast<const FilterFrom*>(reinterpret_cast<const uint8_t*>(tfY.get()) + tfY->sizeInBytes);
|
||||||
@ -757,18 +761,18 @@ namespace
|
|||||||
{
|
{
|
||||||
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
||||||
case DXGI_FORMAT_R10G10B10A2_UINT:
|
case DXGI_FORMAT_R10G10B10A2_UINT:
|
||||||
{
|
|
||||||
// Need to slightly bias results for floating-point error accumulation which can
|
|
||||||
// be visible with harshly quantized values
|
|
||||||
static const XMVECTORF32 Bias = { { { 0.f, 0.f, 0.f, 0.1f } } };
|
|
||||||
|
|
||||||
XMVECTOR* ptr = pAccSrc;
|
|
||||||
for (size_t i = 0; i < destImage.width; ++i, ++ptr)
|
|
||||||
{
|
{
|
||||||
*ptr = XMVectorAdd(*ptr, Bias);
|
// Need to slightly bias results for floating-point error accumulation which can
|
||||||
|
// be visible with harshly quantized values
|
||||||
|
static const XMVECTORF32 Bias = { { { 0.f, 0.f, 0.f, 0.1f } } };
|
||||||
|
|
||||||
|
XMVECTOR* ptr = pAccSrc;
|
||||||
|
for (size_t i = 0; i < destImage.width; ++i, ++ptr)
|
||||||
|
{
|
||||||
|
*ptr = XMVectorAdd(*ptr, Bias);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -908,7 +912,7 @@ HRESULT DirectX::Resize(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// Case 3: not using WIC resizing
|
// Case 3: not using WIC resizing
|
||||||
hr = PerformResizeUsingCustomFilters(srcImage, filter, *rimage);
|
hr = PerformResizeUsingCustomFilters(srcImage, filter, *rimage);
|
||||||
@ -1007,7 +1011,7 @@ HRESULT DirectX::Resize(
|
|||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (usewic)
|
if (usewic)
|
||||||
{
|
{
|
||||||
if (wicpf)
|
if (wicpf)
|
||||||
@ -1022,7 +1026,7 @@ HRESULT DirectX::Resize(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// Case 3: not using WIC resizing
|
// Case 3: not using WIC resizing
|
||||||
hr = PerformResizeUsingCustomFilters(*srcimg, filter, *destimg);
|
hr = PerformResizeUsingCustomFilters(*srcimg, filter, *destimg);
|
||||||
@ -1068,7 +1072,7 @@ HRESULT DirectX::Resize(
|
|||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (usewic)
|
if (usewic)
|
||||||
{
|
{
|
||||||
if (wicpf)
|
if (wicpf)
|
||||||
@ -1083,7 +1087,7 @@ HRESULT DirectX::Resize(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// Case 3: not using WIC resizing
|
// Case 3: not using WIC resizing
|
||||||
hr = PerformResizeUsingCustomFilters(*srcimg, filter, *destimg);
|
hr = PerformResizeUsingCustomFilters(*srcimg, filter, *destimg);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -122,7 +122,7 @@ namespace
|
|||||||
return std::aligned_alloc(alignment, size);
|
return std::aligned_alloc(alignment, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define _aligned_free free
|
#define _aligned_free free
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,56 +157,56 @@ bool DirectX::Internal::DXGIToWIC(DXGI_FORMAT format, GUID& guid, bool ignoreRGB
|
|||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
||||||
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
||||||
if (ignoreRGBvsBGR)
|
if (ignoreRGBvsBGR)
|
||||||
{
|
{
|
||||||
// If we are not doing conversion so don't really care about BGR vs RGB color-order,
|
// If we are not doing conversion so don't really care about BGR vs RGB color-order,
|
||||||
// we can use the canonical WIC 32bppBGRA format which avoids an extra format conversion when using the WIC scaler
|
// we can use the canonical WIC 32bppBGRA format which avoids an extra format conversion when using the WIC scaler
|
||||||
memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memcpy(&guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case DXGI_FORMAT_D32_FLOAT:
|
|
||||||
memcpy(&guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID));
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case DXGI_FORMAT_D16_UNORM:
|
|
||||||
memcpy(&guid, &GUID_WICPixelFormat16bppGray, sizeof(GUID));
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
|
|
||||||
memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
|
memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
|
||||||
return true;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(&guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
|
case DXGI_FORMAT_D32_FLOAT:
|
||||||
memcpy(&guid, &GUID_WICPixelFormat32bppBGR, sizeof(GUID));
|
memcpy(&guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
case DXGI_FORMAT_D16_UNORM:
|
||||||
case DXGI_FORMAT_R32G32B32_FLOAT:
|
memcpy(&guid, &GUID_WICPixelFormat16bppGray, sizeof(GUID));
|
||||||
if (g_WIC2)
|
return true;
|
||||||
|
|
||||||
|
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
|
||||||
|
memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
|
||||||
|
memcpy(&guid, &GUID_WICPixelFormat32bppBGR, sizeof(GUID));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
#if (_WIN32_WINNT >= _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 < std::size(g_WICFormats); ++i)
|
||||||
|
{
|
||||||
|
if (g_WICFormats[i].format == format)
|
||||||
{
|
{
|
||||||
memcpy(&guid, &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID));
|
memcpy(&guid, &g_WICFormats[i].wic, sizeof(GUID));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
#endif
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
for (size_t i = 0; i < std::size(g_WICFormats); ++i)
|
|
||||||
{
|
|
||||||
if (g_WICFormats[i].format == format)
|
|
||||||
{
|
|
||||||
memcpy(&guid, &g_WICFormats[i].wic, sizeof(GUID));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&guid, 0, sizeof(GUID));
|
memset(&guid, 0, sizeof(GUID));
|
||||||
@ -317,14 +317,14 @@ void DirectX::SetWICFactory(_In_opt_ IWICImagingFactory* pWIC) noexcept
|
|||||||
bool iswic2 = false;
|
bool iswic2 = false;
|
||||||
if (pWIC)
|
if (pWIC)
|
||||||
{
|
{
|
||||||
#if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
ComPtr<IWICImagingFactory2> wic2;
|
ComPtr<IWICImagingFactory2> wic2;
|
||||||
HRESULT hr = pWIC->QueryInterface(IID_PPV_ARGS(wic2.GetAddressOf()));
|
HRESULT hr = pWIC->QueryInterface(IID_PPV_ARGS(wic2.GetAddressOf()));
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
iswic2 = true;
|
iswic2 = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
pWIC->AddRef();
|
pWIC->AddRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ namespace
|
|||||||
{
|
{
|
||||||
if (memcmp(&GUID_WICPixelFormat96bppRGBFixedPoint, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0)
|
if (memcmp(&GUID_WICPixelFormat96bppRGBFixedPoint, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0)
|
||||||
{
|
{
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
if (iswic2)
|
if (iswic2)
|
||||||
{
|
{
|
||||||
if (pConvert)
|
if (pConvert)
|
||||||
@ -114,9 +114,9 @@ namespace
|
|||||||
format = DXGI_FORMAT_R32G32B32_FLOAT;
|
format = DXGI_FORMAT_R32G32B32_FLOAT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(iswic2);
|
UNREFERENCED_PARAMETER(iswic2);
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (pConvert)
|
if (pConvert)
|
||||||
memcpy_s(pConvert, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat128bppRGBAFloat, sizeof(GUID));
|
memcpy_s(pConvert, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat128bppRGBAFloat, sizeof(GUID));
|
||||||
@ -600,7 +600,7 @@ namespace
|
|||||||
sRGB = (flags & WIC_FLAGS_DEFAULT_SRGB) != 0;
|
sRGB = (flags & WIC_FLAGS_DEFAULT_SRGB) != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
||||||
else if (memcmp(&containerFormat, &GUID_ContainerFormatJpeg, sizeof(GUID)) == 0)
|
else if (memcmp(&containerFormat, &GUID_ContainerFormatJpeg, sizeof(GUID)) == 0)
|
||||||
{
|
{
|
||||||
if (SUCCEEDED(metareader->GetMetadataByName(L"/app1/ifd/exif/{ushort=40961}", &value)) && value.vt == VT_UI2)
|
if (SUCCEEDED(metareader->GetMetadataByName(L"/app1/ifd/exif/{ushort=40961}", &value)) && value.vt == VT_UI2)
|
||||||
@ -623,7 +623,7 @@ namespace
|
|||||||
sRGB = (flags & WIC_FLAGS_DEFAULT_SRGB) != 0;
|
sRGB = (flags & WIC_FLAGS_DEFAULT_SRGB) != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
else if (SUCCEEDED(metareader->GetMetadataByName(L"System.Image.ColorSpace", &value)) && value.vt == VT_UI2)
|
else if (SUCCEEDED(metareader->GetMetadataByName(L"System.Image.ColorSpace", &value)) && value.vt == VT_UI2)
|
||||||
{
|
{
|
||||||
sRGB = (value.uiVal == 1);
|
sRGB = (value.uiVal == 1);
|
||||||
@ -632,7 +632,7 @@ namespace
|
|||||||
{
|
{
|
||||||
sRGB = (flags & WIC_FLAGS_DEFAULT_SRGB) != 0;
|
sRGB = (flags & WIC_FLAGS_DEFAULT_SRGB) != 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::ignore = PropVariantClear(&value);
|
std::ignore = PropVariantClear(&value);
|
||||||
|
|
||||||
@ -913,7 +913,7 @@ namespace
|
|||||||
std::ignore = metawriter->RemoveMetadataByName(L"/sRGB/RenderingIntent");
|
std::ignore = metawriter->RemoveMetadataByName(L"/sRGB/RenderingIntent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
#if (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
|
||||||
else if (memcmp(&containerFormat, &GUID_ContainerFormatJpeg, sizeof(GUID)) == 0)
|
else if (memcmp(&containerFormat, &GUID_ContainerFormatJpeg, sizeof(GUID)) == 0)
|
||||||
{
|
{
|
||||||
// Set Software name
|
// Set Software name
|
||||||
@ -940,7 +940,7 @@ namespace
|
|||||||
std::ignore = metawriter->SetMetadataByName(L"/ifd/exif/{ushort=40961}", &value);
|
std::ignore = metawriter->SetMetadataByName(L"/ifd/exif/{ushort=40961}", &value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Set Software name
|
// Set Software name
|
||||||
@ -954,7 +954,7 @@ namespace
|
|||||||
std::ignore = metawriter->SetMetadataByName(L"System.Image.ColorSpace", &value);
|
std::ignore = metawriter->SetMetadataByName(L"System.Image.ColorSpace", &value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (hr == WINCODEC_ERR_UNSUPPORTEDOPERATION)
|
else if (hr == WINCODEC_ERR_UNSUPPORTEDOPERATION)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#define MAX_INT asint(0x7FFFFFFF)
|
#define MAX_INT asint(0x7FFFFFFF)
|
||||||
#define MIN_INT asint(0x80000000)
|
#define MIN_INT asint(0x80000000)
|
||||||
|
|
||||||
cbuffer cbCS : register( b0 )
|
cbuffer cbCS : register(b0)
|
||||||
{
|
{
|
||||||
uint g_tex_width;
|
uint g_tex_width;
|
||||||
uint g_num_block_x;
|
uint g_num_block_x;
|
||||||
@ -73,14 +73,14 @@ static const uint candidateFixUpIndex1D[32] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
//0, 9, 18, 27, 37, 46, 55, 64
|
//0, 9, 18, 27, 37, 46, 55, 64
|
||||||
static const uint aStep1[64] = {0,0,0,0,0,1,1,1,
|
static const uint aStep1[64] = { 0,0,0,0,0,1,1,1,
|
||||||
1,1,1,1,1,1,2,2,
|
1,1,1,1,1,1,2,2,
|
||||||
2,2,2,2,2,2,2,3,
|
2,2,2,2,2,2,2,3,
|
||||||
3,3,3,3,3,3,3,3,
|
3,3,3,3,3,3,3,3,
|
||||||
3,4,4,4,4,4,4,4,
|
3,4,4,4,4,4,4,4,
|
||||||
4,4,5,5,5,5,5,5,
|
4,4,5,5,5,5,5,5,
|
||||||
5,5,5,6,6,6,6,6,
|
5,5,5,6,6,6,6,6,
|
||||||
6,6,6,6,7,7,7,7};
|
6,6,6,6,7,7,7,7 };
|
||||||
|
|
||||||
//0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64
|
//0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64
|
||||||
static const uint aStep2[64] = { 0, 0, 0, 1, 1, 1, 1, 2,
|
static const uint aStep2[64] = { 0, 0, 0, 1, 1, 1, 1, 2,
|
||||||
@ -90,7 +90,7 @@ static const uint aStep2[64] = { 0, 0, 0, 1, 1, 1, 1, 2,
|
|||||||
7, 8, 8, 8, 8, 9, 9, 9,
|
7, 8, 8, 8, 8, 9, 9, 9,
|
||||||
9,10,10,10,10,10,11,11,
|
9,10,10,10,10,10,11,11,
|
||||||
11,11,12,12,12,12,13,13,
|
11,11,12,12,12,12,13,13,
|
||||||
13,13,14,14,14,14,15,15};
|
13,13,14,14,14,14,15,15 };
|
||||||
|
|
||||||
static const float3 RGB2LUM = float3(0.2126f, 0.7152f, 0.0722f);
|
static const float3 RGB2LUM = float3(0.2126f, 0.7152f, 0.0722f);
|
||||||
|
|
||||||
@ -101,23 +101,23 @@ static const float3 RGB2LUM = float3(0.2126f, 0.7152f, 0.0722f);
|
|||||||
|
|
||||||
|
|
||||||
//Forward declaration
|
//Forward declaration
|
||||||
uint3 float2half( float3 pixel_f );
|
uint3 float2half(float3 pixel_f);
|
||||||
int3 start_quantize( uint3 pixel_h );
|
int3 start_quantize(uint3 pixel_h);
|
||||||
void quantize( inout int2x3 endPoint, uint prec );
|
void quantize(inout int2x3 endPoint, uint prec);
|
||||||
void finish_quantize_0( inout int bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed );
|
void finish_quantize_0(inout int bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed);
|
||||||
void finish_quantize_1( inout int bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed );
|
void finish_quantize_1(inout int bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed);
|
||||||
void finish_quantize( out bool bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed );
|
void finish_quantize(out bool bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed);
|
||||||
|
|
||||||
void start_unquantize( inout int2x3 endPoint[2], uint4 prec, bool transformed );
|
void start_unquantize(inout int2x3 endPoint[2], uint4 prec, bool transformed);
|
||||||
void start_unquantize( inout int2x3 endPoint, uint4 prec, bool transformed );
|
void start_unquantize(inout int2x3 endPoint, uint4 prec, bool transformed);
|
||||||
void unquantize( inout int2x3 color, uint prec );
|
void unquantize(inout int2x3 color, uint prec);
|
||||||
uint3 finish_unquantize( int3 color );
|
uint3 finish_unquantize(int3 color);
|
||||||
void generate_palette_unquantized8( out uint3 palette, int3 low, int3 high, int i );
|
void generate_palette_unquantized8(out uint3 palette, int3 low, int3 high, int i);
|
||||||
void generate_palette_unquantized16( out uint3 palette, int3 low, int3 high, int i );
|
void generate_palette_unquantized16(out uint3 palette, int3 low, int3 high, int i);
|
||||||
float3 half2float(uint3 color_h );
|
float3 half2float(uint3 color_h);
|
||||||
|
|
||||||
void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint partition_index );
|
void block_package(inout uint4 block, int2x3 endPoint[2], uint mode_type, uint partition_index);
|
||||||
void block_package( inout uint4 block, int2x3 endPoint, uint mode_type );
|
void block_package(inout uint4 block, int2x3 endPoint, uint mode_type);
|
||||||
|
|
||||||
void swap(inout int3 lhs, inout int3 rhs)
|
void swap(inout int3 lhs, inout int3 rhs)
|
||||||
{
|
{
|
||||||
@ -126,10 +126,10 @@ void swap(inout int3 lhs, inout int3 rhs)
|
|||||||
rhs = tmp;
|
rhs = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D<float4> g_Input : register( t0 );
|
Texture2D<float4> g_Input : register(t0);
|
||||||
StructuredBuffer<uint4> g_InBuff : register( t1 );
|
StructuredBuffer<uint4> g_InBuff : register(t1);
|
||||||
|
|
||||||
RWStructuredBuffer<uint4> g_OutBuff : register( u0 );
|
RWStructuredBuffer<uint4> g_OutBuff : register(u0);
|
||||||
|
|
||||||
struct SharedData
|
struct SharedData
|
||||||
{
|
{
|
||||||
@ -148,8 +148,8 @@ struct SharedData
|
|||||||
|
|
||||||
groupshared SharedData shared_temp[THREAD_GROUP_SIZE];
|
groupshared SharedData shared_temp[THREAD_GROUP_SIZE];
|
||||||
|
|
||||||
[numthreads( THREAD_GROUP_SIZE, 1, 1 )]
|
[numthreads(THREAD_GROUP_SIZE, 1, 1)]
|
||||||
void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
void TryModeG10CS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
||||||
{
|
{
|
||||||
const uint MAX_USED_THREAD = 16;
|
const uint MAX_USED_THREAD = 16;
|
||||||
uint BLOCK_IN_GROUP = THREAD_GROUP_SIZE / MAX_USED_THREAD;
|
uint BLOCK_IN_GROUP = THREAD_GROUP_SIZE / MAX_USED_THREAD;
|
||||||
@ -172,11 +172,11 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
|
|
||||||
if (threadInBlock < 16)
|
if (threadInBlock < 16)
|
||||||
{
|
{
|
||||||
shared_temp[GI].pixel = g_Input.Load( uint3( base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0 ) ).rgb;
|
shared_temp[GI].pixel = g_Input.Load(uint3(base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0)).rgb;
|
||||||
uint3 pixel_h = float2half( shared_temp[GI].pixel );
|
uint3 pixel_h = float2half(shared_temp[GI].pixel);
|
||||||
shared_temp[GI].pixel_hr = half2float(pixel_h);
|
shared_temp[GI].pixel_hr = half2float(pixel_h);
|
||||||
shared_temp[GI].pixel_lum = dot(shared_temp[GI].pixel_hr, RGB2LUM);
|
shared_temp[GI].pixel_lum = dot(shared_temp[GI].pixel_hr, RGB2LUM);
|
||||||
shared_temp[GI].pixel_ph = start_quantize( pixel_h );
|
shared_temp[GI].pixel_ph = start_quantize(pixel_h);
|
||||||
|
|
||||||
shared_temp[GI].endPoint_low = shared_temp[GI].pixel_ph;
|
shared_temp[GI].endPoint_low = shared_temp[GI].pixel_ph;
|
||||||
shared_temp[GI].endPoint_high = shared_temp[GI].pixel_ph;
|
shared_temp[GI].endPoint_high = shared_temp[GI].pixel_ph;
|
||||||
@ -253,7 +253,7 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//ergod mode_type 11:14
|
//ergod mode_type 11:14
|
||||||
if ( threadInBlock == 0 )
|
if (threadInBlock == 0)
|
||||||
{
|
{
|
||||||
int2x3 endPoint;
|
int2x3 endPoint;
|
||||||
// find_axis
|
// find_axis
|
||||||
@ -262,9 +262,9 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
|
|
||||||
//compute_index
|
//compute_index
|
||||||
float3 span = endPoint[1] - endPoint[0];// fixed a bug in v0.2
|
float3 span = endPoint[1] - endPoint[0];// fixed a bug in v0.2
|
||||||
float span_norm_sqr = dot( span, span );// fixed a bug in v0.2
|
float span_norm_sqr = dot(span, span);// fixed a bug in v0.2
|
||||||
float dotProduct = dot( span, shared_temp[threadBase + 0].pixel_ph - endPoint[0] );// fixed a bug in v0.2
|
float dotProduct = dot(span, shared_temp[threadBase + 0].pixel_ph - endPoint[0]);// fixed a bug in v0.2
|
||||||
if ( span_norm_sqr > 0 && dotProduct >= 0 && uint( dotProduct * 63.49999 / span_norm_sqr ) > 32 )
|
if (span_norm_sqr > 0 && dotProduct >= 0 && uint(dotProduct * 63.49999 / span_norm_sqr) > 32)
|
||||||
{
|
{
|
||||||
swap(endPoint[0], endPoint[1]);
|
swap(endPoint[0], endPoint[1]);
|
||||||
|
|
||||||
@ -283,11 +283,11 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
endPoint[1] = shared_temp[threadBase + 0].endPoint_high;
|
endPoint[1] = shared_temp[threadBase + 0].endPoint_high;
|
||||||
|
|
||||||
float3 span = endPoint[1] - endPoint[0];
|
float3 span = endPoint[1] - endPoint[0];
|
||||||
float span_norm_sqr = dot( span, span );
|
float span_norm_sqr = dot(span, span);
|
||||||
|
|
||||||
uint4 prec = candidateModePrec[threadInBlock + 10];
|
uint4 prec = candidateModePrec[threadInBlock + 10];
|
||||||
int2x3 endPoint_q = endPoint;
|
int2x3 endPoint_q = endPoint;
|
||||||
quantize( endPoint_q, prec.x );
|
quantize(endPoint_q, prec.x);
|
||||||
|
|
||||||
bool transformed = candidateModeTransformed[threadInBlock + 10];
|
bool transformed = candidateModeTransformed[threadInBlock + 10];
|
||||||
if (transformed)
|
if (transformed)
|
||||||
@ -296,26 +296,26 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool bBadQuantize;
|
bool bBadQuantize;
|
||||||
finish_quantize( bBadQuantize, endPoint_q, prec, transformed );
|
finish_quantize(bBadQuantize, endPoint_q, prec, transformed);
|
||||||
|
|
||||||
start_unquantize( endPoint_q, prec, transformed );
|
start_unquantize(endPoint_q, prec, transformed);
|
||||||
|
|
||||||
unquantize( endPoint_q, prec.x );
|
unquantize(endPoint_q, prec.x);
|
||||||
|
|
||||||
float error = 0;
|
float error = 0;
|
||||||
[loop]for ( uint j = 0; j < 16; j ++ )
|
[loop] for (uint j = 0; j < 16; j++)
|
||||||
{
|
{
|
||||||
float dotProduct = dot( span, shared_temp[threadBase + j].pixel_ph - endPoint[0] );// fixed a bug in v0.2
|
float dotProduct = dot(span, shared_temp[threadBase + j].pixel_ph - endPoint[0]);// fixed a bug in v0.2
|
||||||
uint index = ( span_norm_sqr <= 0 || dotProduct <= 0 ) ? 0
|
uint index = (span_norm_sqr <= 0 || dotProduct <= 0) ? 0
|
||||||
: ( ( dotProduct < span_norm_sqr ) ? aStep2[ uint( dotProduct * 63.49999 / span_norm_sqr ) ] : aStep2[63] );
|
: ((dotProduct < span_norm_sqr) ? aStep2[uint(dotProduct * 63.49999 / span_norm_sqr)] : aStep2[63]);
|
||||||
|
|
||||||
uint3 pixel_rh;
|
uint3 pixel_rh;
|
||||||
generate_palette_unquantized16( pixel_rh, endPoint_q[0], endPoint_q[1], index );
|
generate_palette_unquantized16(pixel_rh, endPoint_q[0], endPoint_q[1], index);
|
||||||
float3 pixel_r = half2float( pixel_rh );
|
float3 pixel_r = half2float(pixel_rh);
|
||||||
pixel_r -= shared_temp[threadBase + j].pixel_hr;
|
pixel_r -= shared_temp[threadBase + j].pixel_hr;
|
||||||
error += dot(pixel_r, pixel_r);
|
error += dot(pixel_r, pixel_r);
|
||||||
}
|
}
|
||||||
if ( bBadQuantize )
|
if (bBadQuantize)
|
||||||
error = 1e20f;
|
error = 1e20f;
|
||||||
|
|
||||||
shared_temp[GI].error = error;
|
shared_temp[GI].error = error;
|
||||||
@ -327,7 +327,7 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
|
|
||||||
if (threadInBlock < 2)
|
if (threadInBlock < 2)
|
||||||
{
|
{
|
||||||
if ( shared_temp[GI].error > shared_temp[GI + 2].error )
|
if (shared_temp[GI].error > shared_temp[GI + 2].error)
|
||||||
{
|
{
|
||||||
shared_temp[GI].error = shared_temp[GI + 2].error;
|
shared_temp[GI].error = shared_temp[GI + 2].error;
|
||||||
shared_temp[GI].best_mode = shared_temp[GI + 2].best_mode;
|
shared_temp[GI].best_mode = shared_temp[GI + 2].best_mode;
|
||||||
@ -338,7 +338,7 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
#endif
|
#endif
|
||||||
if (threadInBlock < 1)
|
if (threadInBlock < 1)
|
||||||
{
|
{
|
||||||
if ( shared_temp[GI].error > shared_temp[GI + 1].error )
|
if (shared_temp[GI].error > shared_temp[GI + 1].error)
|
||||||
{
|
{
|
||||||
shared_temp[GI].error = shared_temp[GI + 1].error;
|
shared_temp[GI].error = shared_temp[GI + 1].error;
|
||||||
shared_temp[GI].best_mode = shared_temp[GI + 1].best_mode;
|
shared_temp[GI].best_mode = shared_temp[GI + 1].best_mode;
|
||||||
@ -348,8 +348,8 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[numthreads( THREAD_GROUP_SIZE, 1, 1 )]
|
[numthreads(THREAD_GROUP_SIZE, 1, 1)]
|
||||||
void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
void TryModeLE10CS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
||||||
{
|
{
|
||||||
const uint MAX_USED_THREAD = 32;
|
const uint MAX_USED_THREAD = 32;
|
||||||
uint BLOCK_IN_GROUP = THREAD_GROUP_SIZE / MAX_USED_THREAD;
|
uint BLOCK_IN_GROUP = THREAD_GROUP_SIZE / MAX_USED_THREAD;
|
||||||
@ -378,11 +378,11 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
|
|
||||||
if (threadInBlock < 16)
|
if (threadInBlock < 16)
|
||||||
{
|
{
|
||||||
shared_temp[GI].pixel = g_Input.Load( uint3( base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0 ) ).rgb;
|
shared_temp[GI].pixel = g_Input.Load(uint3(base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0)).rgb;
|
||||||
uint3 pixel_h = float2half( shared_temp[GI].pixel );
|
uint3 pixel_h = float2half(shared_temp[GI].pixel);
|
||||||
shared_temp[GI].pixel_hr = half2float(pixel_h);
|
shared_temp[GI].pixel_hr = half2float(pixel_h);
|
||||||
shared_temp[GI].pixel_lum = dot(shared_temp[GI].pixel_hr, RGB2LUM);
|
shared_temp[GI].pixel_lum = dot(shared_temp[GI].pixel_hr, RGB2LUM);
|
||||||
shared_temp[GI].pixel_ph = start_quantize( pixel_h );
|
shared_temp[GI].pixel_ph = start_quantize(pixel_h);
|
||||||
}
|
}
|
||||||
#ifdef REF_DEVICE
|
#ifdef REF_DEVICE
|
||||||
GroupMemoryBarrierWithGroupSync();
|
GroupMemoryBarrierWithGroupSync();
|
||||||
@ -405,11 +405,11 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
endPoint_lum[1][1] = MIN_FLOAT;
|
endPoint_lum[1][1] = MIN_FLOAT;
|
||||||
|
|
||||||
uint bit = candidateSectionBit[threadInBlock];
|
uint bit = candidateSectionBit[threadInBlock];
|
||||||
for ( uint i = 0; i < 16; i ++ )
|
for (uint i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
int3 pixel_ph = shared_temp[threadBase + i].pixel_ph;
|
int3 pixel_ph = shared_temp[threadBase + i].pixel_ph;
|
||||||
float pixel_lum = shared_temp[threadBase + i].pixel_lum;
|
float pixel_lum = shared_temp[threadBase + i].pixel_lum;
|
||||||
if ( (bit >> i) & 1 ) //It gets error when using "candidateSection" as "endPoint_ph" index
|
if ((bit >> i) & 1) //It gets error when using "candidateSection" as "endPoint_ph" index
|
||||||
{
|
{
|
||||||
if (endPoint_lum[1][0] > pixel_lum)
|
if (endPoint_lum[1][0] > pixel_lum)
|
||||||
{
|
{
|
||||||
@ -441,13 +441,13 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
float3 span[2];// fixed a bug in v0.2
|
float3 span[2];// fixed a bug in v0.2
|
||||||
float span_norm_sqr[2];// fixed a bug in v0.2
|
float span_norm_sqr[2];// fixed a bug in v0.2
|
||||||
[unroll]
|
[unroll]
|
||||||
for (uint p = 0; p < 2; ++ p)
|
for (uint p = 0; p < 2; ++p)
|
||||||
{
|
{
|
||||||
span[p] = endPoint[p][1] - endPoint[p][0];
|
span[p] = endPoint[p][1] - endPoint[p][0];
|
||||||
span_norm_sqr[p] = dot( span[p], span[p] );
|
span_norm_sqr[p] = dot(span[p], span[p]);
|
||||||
|
|
||||||
float dotProduct = dot( span[p], shared_temp[threadBase + (0 == p ? 0 : candidateFixUpIndex1D[threadInBlock])].pixel_ph - endPoint[p][0] );// fixed a bug in v0.2
|
float dotProduct = dot(span[p], shared_temp[threadBase + (0 == p ? 0 : candidateFixUpIndex1D[threadInBlock])].pixel_ph - endPoint[p][0]);// fixed a bug in v0.2
|
||||||
if ( span_norm_sqr[p] > 0 && dotProduct >= 0 && uint( dotProduct * 63.49999 / span_norm_sqr[p] ) > 32 )
|
if (span_norm_sqr[p] > 0 && dotProduct >= 0 && uint(dotProduct * 63.49999 / span_norm_sqr[p]) > 32)
|
||||||
{
|
{
|
||||||
span[p] = -span[p];
|
span[p] = -span[p];
|
||||||
swap(endPoint[p][0], endPoint[p][1]);
|
swap(endPoint[p][0], endPoint[p][1]);
|
||||||
@ -456,8 +456,8 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
|
|
||||||
uint4 prec = candidateModePrec[g_mode_id];
|
uint4 prec = candidateModePrec[g_mode_id];
|
||||||
int2x3 endPoint_q[2] = endPoint;
|
int2x3 endPoint_q[2] = endPoint;
|
||||||
quantize( endPoint_q[0], prec.x );
|
quantize(endPoint_q[0], prec.x);
|
||||||
quantize( endPoint_q[1], prec.x );
|
quantize(endPoint_q[1], prec.x);
|
||||||
|
|
||||||
bool transformed = candidateModeTransformed[g_mode_id];
|
bool transformed = candidateModeTransformed[g_mode_id];
|
||||||
if (transformed)
|
if (transformed)
|
||||||
@ -468,38 +468,38 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
}
|
}
|
||||||
|
|
||||||
int bBadQuantize = 0;
|
int bBadQuantize = 0;
|
||||||
finish_quantize_0( bBadQuantize, endPoint_q[0], prec, transformed );
|
finish_quantize_0(bBadQuantize, endPoint_q[0], prec, transformed);
|
||||||
finish_quantize_1( bBadQuantize, endPoint_q[1], prec, transformed );
|
finish_quantize_1(bBadQuantize, endPoint_q[1], prec, transformed);
|
||||||
|
|
||||||
start_unquantize( endPoint_q, prec, transformed );
|
start_unquantize(endPoint_q, prec, transformed);
|
||||||
|
|
||||||
unquantize( endPoint_q[0], prec.x );
|
unquantize(endPoint_q[0], prec.x);
|
||||||
unquantize( endPoint_q[1], prec.x );
|
unquantize(endPoint_q[1], prec.x);
|
||||||
|
|
||||||
float error = 0;
|
float error = 0;
|
||||||
for ( uint j = 0; j < 16; j ++ )
|
for (uint j = 0; j < 16; j++)
|
||||||
{
|
{
|
||||||
uint3 pixel_rh;
|
uint3 pixel_rh;
|
||||||
if ((bit >> j) & 1)
|
if ((bit >> j) & 1)
|
||||||
{
|
{
|
||||||
float dotProduct = dot( span[1], shared_temp[threadBase + j].pixel_ph - endPoint[1][0] );// fixed a bug in v0.2
|
float dotProduct = dot(span[1], shared_temp[threadBase + j].pixel_ph - endPoint[1][0]);// fixed a bug in v0.2
|
||||||
uint index = ( span_norm_sqr[1] <= 0 || dotProduct <= 0 ) ? 0
|
uint index = (span_norm_sqr[1] <= 0 || dotProduct <= 0) ? 0
|
||||||
: ( ( dotProduct < span_norm_sqr[1] ) ? aStep1[ uint( dotProduct * 63.49999 / span_norm_sqr[1] ) ] : aStep1[63] );
|
: ((dotProduct < span_norm_sqr[1]) ? aStep1[uint(dotProduct * 63.49999 / span_norm_sqr[1])] : aStep1[63]);
|
||||||
generate_palette_unquantized8( pixel_rh, endPoint_q[1][0], endPoint_q[1][1], index );
|
generate_palette_unquantized8(pixel_rh, endPoint_q[1][0], endPoint_q[1][1], index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float dotProduct = dot( span[0], shared_temp[threadBase + j].pixel_ph - endPoint[0][0] );// fixed a bug in v0.2
|
float dotProduct = dot(span[0], shared_temp[threadBase + j].pixel_ph - endPoint[0][0]);// fixed a bug in v0.2
|
||||||
uint index = ( span_norm_sqr[0] <= 0 || dotProduct <= 0 ) ? 0
|
uint index = (span_norm_sqr[0] <= 0 || dotProduct <= 0) ? 0
|
||||||
: ( ( dotProduct < span_norm_sqr[0] ) ? aStep1[ uint( dotProduct * 63.49999 / span_norm_sqr[0] ) ] : aStep1[63] );
|
: ((dotProduct < span_norm_sqr[0]) ? aStep1[uint(dotProduct * 63.49999 / span_norm_sqr[0])] : aStep1[63]);
|
||||||
generate_palette_unquantized8( pixel_rh, endPoint_q[0][0], endPoint_q[0][1], index );
|
generate_palette_unquantized8(pixel_rh, endPoint_q[0][0], endPoint_q[0][1], index);
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 pixel_r = half2float( pixel_rh );
|
float3 pixel_r = half2float(pixel_rh);
|
||||||
pixel_r -= shared_temp[threadBase + j].pixel_hr;
|
pixel_r -= shared_temp[threadBase + j].pixel_hr;
|
||||||
error += dot(pixel_r, pixel_r);
|
error += dot(pixel_r, pixel_r);
|
||||||
}
|
}
|
||||||
if ( bBadQuantize )
|
if (bBadQuantize)
|
||||||
error = 1e20f;
|
error = 1e20f;
|
||||||
|
|
||||||
shared_temp[GI].error = error;
|
shared_temp[GI].error = error;
|
||||||
@ -512,7 +512,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
|
|
||||||
if (threadInBlock < 16)
|
if (threadInBlock < 16)
|
||||||
{
|
{
|
||||||
if ( shared_temp[GI].error > shared_temp[GI + 16].error )
|
if (shared_temp[GI].error > shared_temp[GI + 16].error)
|
||||||
{
|
{
|
||||||
shared_temp[GI].error = shared_temp[GI + 16].error;
|
shared_temp[GI].error = shared_temp[GI + 16].error;
|
||||||
shared_temp[GI].best_mode = shared_temp[GI + 16].best_mode;
|
shared_temp[GI].best_mode = shared_temp[GI + 16].best_mode;
|
||||||
@ -524,7 +524,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
#endif
|
#endif
|
||||||
if (threadInBlock < 8)
|
if (threadInBlock < 8)
|
||||||
{
|
{
|
||||||
if ( shared_temp[GI].error > shared_temp[GI + 8].error )
|
if (shared_temp[GI].error > shared_temp[GI + 8].error)
|
||||||
{
|
{
|
||||||
shared_temp[GI].error = shared_temp[GI + 8].error;
|
shared_temp[GI].error = shared_temp[GI + 8].error;
|
||||||
shared_temp[GI].best_mode = shared_temp[GI + 8].best_mode;
|
shared_temp[GI].best_mode = shared_temp[GI + 8].best_mode;
|
||||||
@ -536,7 +536,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
#endif
|
#endif
|
||||||
if (threadInBlock < 4)
|
if (threadInBlock < 4)
|
||||||
{
|
{
|
||||||
if ( shared_temp[GI].error > shared_temp[GI + 4].error )
|
if (shared_temp[GI].error > shared_temp[GI + 4].error)
|
||||||
{
|
{
|
||||||
shared_temp[GI].error = shared_temp[GI + 4].error;
|
shared_temp[GI].error = shared_temp[GI + 4].error;
|
||||||
shared_temp[GI].best_mode = shared_temp[GI + 4].best_mode;
|
shared_temp[GI].best_mode = shared_temp[GI + 4].best_mode;
|
||||||
@ -548,7 +548,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
#endif
|
#endif
|
||||||
if (threadInBlock < 2)
|
if (threadInBlock < 2)
|
||||||
{
|
{
|
||||||
if ( shared_temp[GI].error > shared_temp[GI + 2].error )
|
if (shared_temp[GI].error > shared_temp[GI + 2].error)
|
||||||
{
|
{
|
||||||
shared_temp[GI].error = shared_temp[GI + 2].error;
|
shared_temp[GI].error = shared_temp[GI + 2].error;
|
||||||
shared_temp[GI].best_mode = shared_temp[GI + 2].best_mode;
|
shared_temp[GI].best_mode = shared_temp[GI + 2].best_mode;
|
||||||
@ -560,7 +560,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
#endif
|
#endif
|
||||||
if (threadInBlock < 1)
|
if (threadInBlock < 1)
|
||||||
{
|
{
|
||||||
if ( shared_temp[GI].error > shared_temp[GI + 1].error )
|
if (shared_temp[GI].error > shared_temp[GI + 1].error)
|
||||||
{
|
{
|
||||||
shared_temp[GI].error = shared_temp[GI + 1].error;
|
shared_temp[GI].error = shared_temp[GI + 1].error;
|
||||||
shared_temp[GI].best_mode = shared_temp[GI + 1].best_mode;
|
shared_temp[GI].best_mode = shared_temp[GI + 1].best_mode;
|
||||||
@ -578,7 +578,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[numthreads( THREAD_GROUP_SIZE, 1, 1 )]
|
[numthreads(THREAD_GROUP_SIZE, 1, 1)]
|
||||||
void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
||||||
{
|
{
|
||||||
const uint MAX_USED_THREAD = 32;
|
const uint MAX_USED_THREAD = 32;
|
||||||
@ -602,10 +602,10 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
|||||||
|
|
||||||
if (threadInBlock < 16)
|
if (threadInBlock < 16)
|
||||||
{
|
{
|
||||||
shared_temp[GI].pixel = g_Input.Load( uint3( base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0 ) ).rgb;
|
shared_temp[GI].pixel = g_Input.Load(uint3(base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0)).rgb;
|
||||||
shared_temp[GI].pixel_lum = dot(shared_temp[GI].pixel, RGB2LUM);
|
shared_temp[GI].pixel_lum = dot(shared_temp[GI].pixel, RGB2LUM);
|
||||||
uint3 pixel_h = float2half( shared_temp[GI].pixel );
|
uint3 pixel_h = float2half(shared_temp[GI].pixel);
|
||||||
shared_temp[GI].pixel_ph = start_quantize( pixel_h );
|
shared_temp[GI].pixel_ph = start_quantize(pixel_h);
|
||||||
}
|
}
|
||||||
#ifdef REF_DEVICE
|
#ifdef REF_DEVICE
|
||||||
GroupMemoryBarrierWithGroupSync();
|
GroupMemoryBarrierWithGroupSync();
|
||||||
@ -750,9 +750,9 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
float3 span = endPoint[1] - endPoint[0];
|
float3 span = endPoint[1] - endPoint[0];
|
||||||
float span_norm_sqr = dot( span, span );
|
float span_norm_sqr = dot(span, span);
|
||||||
float dotProduct = dot( span, shared_temp[threadBase + fixup].pixel_ph - endPoint[0] );
|
float dotProduct = dot(span, shared_temp[threadBase + fixup].pixel_ph - endPoint[0]);
|
||||||
if ( span_norm_sqr > 0 && dotProduct >= 0 && uint( dotProduct * 63.49999 / span_norm_sqr ) > 32 )
|
if (span_norm_sqr > 0 && dotProduct >= 0 && uint(dotProduct * 63.49999 / span_norm_sqr) > 32)
|
||||||
{
|
{
|
||||||
swap(endPoint[0], endPoint[1]);
|
swap(endPoint[0], endPoint[1]);
|
||||||
}
|
}
|
||||||
@ -781,19 +781,19 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
|||||||
if ((bits >> threadInBlock) & 1)
|
if ((bits >> threadInBlock) & 1)
|
||||||
{
|
{
|
||||||
span = shared_temp[threadBase + 1].endPoint_high - shared_temp[threadBase + 1].endPoint_low;
|
span = shared_temp[threadBase + 1].endPoint_high - shared_temp[threadBase + 1].endPoint_low;
|
||||||
dotProduct = dot( span, shared_temp[threadBase + threadInBlock].pixel_ph - shared_temp[threadBase + 1].endPoint_low );
|
dotProduct = dot(span, shared_temp[threadBase + threadInBlock].pixel_ph - shared_temp[threadBase + 1].endPoint_low);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
span = shared_temp[threadBase + 0].endPoint_high - shared_temp[threadBase + 0].endPoint_low;
|
span = shared_temp[threadBase + 0].endPoint_high - shared_temp[threadBase + 0].endPoint_low;
|
||||||
dotProduct = dot( span, shared_temp[threadBase + threadInBlock].pixel_ph - shared_temp[threadBase + 0].endPoint_low );
|
dotProduct = dot(span, shared_temp[threadBase + threadInBlock].pixel_ph - shared_temp[threadBase + 0].endPoint_low);
|
||||||
}
|
}
|
||||||
float span_norm_sqr = dot( span, span );
|
float span_norm_sqr = dot(span, span);
|
||||||
|
|
||||||
if (best_mode > 10)
|
if (best_mode > 10)
|
||||||
{
|
{
|
||||||
uint index = ( span_norm_sqr <= 0 || dotProduct <= 0 ) ? 0
|
uint index = (span_norm_sqr <= 0 || dotProduct <= 0) ? 0
|
||||||
: ( ( dotProduct < span_norm_sqr ) ? aStep2[ uint( dotProduct * 63.49999 / span_norm_sqr ) ] : aStep2[63] );
|
: ((dotProduct < span_norm_sqr) ? aStep2[uint(dotProduct * 63.49999 / span_norm_sqr)] : aStep2[63]);
|
||||||
if (threadInBlock == 0)
|
if (threadInBlock == 0)
|
||||||
{
|
{
|
||||||
block.z |= index << 1;
|
block.z |= index << 1;
|
||||||
@ -809,8 +809,8 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint index = ( span_norm_sqr <= 0 || dotProduct <= 0 ) ? 0
|
uint index = (span_norm_sqr <= 0 || dotProduct <= 0) ? 0
|
||||||
: ( ( dotProduct < span_norm_sqr ) ? aStep1[ uint( dotProduct * 63.49999 / span_norm_sqr ) ] : aStep1[63] );
|
: ((dotProduct < span_norm_sqr) ? aStep1[uint(dotProduct * 63.49999 / span_norm_sqr)] : aStep1[63]);
|
||||||
|
|
||||||
uint fixup = candidateFixUpIndex1D[best_partition];
|
uint fixup = candidateFixUpIndex1D[best_partition];
|
||||||
int2 offset = int2((fixup != 2), (fixup == 15));
|
int2 offset = int2((fixup != 2), (fixup == 15));
|
||||||
@ -889,7 +889,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
|||||||
endPoint_q[0] = shared_temp[threadBase + 0].endPoint_low;
|
endPoint_q[0] = shared_temp[threadBase + 0].endPoint_low;
|
||||||
endPoint_q[1] = shared_temp[threadBase + 0].endPoint_high;
|
endPoint_q[1] = shared_temp[threadBase + 0].endPoint_high;
|
||||||
|
|
||||||
quantize( endPoint_q, prec.x );
|
quantize(endPoint_q, prec.x);
|
||||||
if (transformed)
|
if (transformed)
|
||||||
{
|
{
|
||||||
endPoint_q[1] -= endPoint_q[0];
|
endPoint_q[1] -= endPoint_q[0];
|
||||||
@ -910,7 +910,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
|||||||
|
|
||||||
if (best_mode <= 10)
|
if (best_mode <= 10)
|
||||||
{
|
{
|
||||||
quantize( endPoint_q, prec.x );
|
quantize(endPoint_q, prec.x);
|
||||||
if (transformed)
|
if (transformed)
|
||||||
{
|
{
|
||||||
endPoint_q[0] -= ep0;
|
endPoint_q[0] -= ep0;
|
||||||
@ -936,18 +936,18 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
|||||||
{
|
{
|
||||||
if (best_mode > 10)
|
if (best_mode > 10)
|
||||||
{
|
{
|
||||||
finish_quantize( bBadQuantize, endPoint_q, prec, transformed );
|
finish_quantize(bBadQuantize, endPoint_q, prec, transformed);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
finish_quantize_0( bBadQuantize, endPoint_q, prec, transformed );
|
finish_quantize_0(bBadQuantize, endPoint_q, prec, transformed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // if (threadInBlock == 1)
|
else // if (threadInBlock == 1)
|
||||||
{
|
{
|
||||||
if (best_mode <= 10)
|
if (best_mode <= 10)
|
||||||
{
|
{
|
||||||
finish_quantize_1( bBadQuantize, endPoint_q, prec, transformed );
|
finish_quantize_1(bBadQuantize, endPoint_q, prec, transformed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -958,7 +958,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
|||||||
GroupMemoryBarrierWithGroupSync();
|
GroupMemoryBarrierWithGroupSync();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( threadInBlock == 0 )
|
if (threadInBlock == 0)
|
||||||
{
|
{
|
||||||
int2x3 endPoint_q[2];
|
int2x3 endPoint_q[2];
|
||||||
endPoint_q[0][0] = shared_temp[threadBase + 0].endPoint_low;
|
endPoint_q[0][0] = shared_temp[threadBase + 0].endPoint_low;
|
||||||
@ -966,20 +966,20 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID)
|
|||||||
endPoint_q[1][0] = shared_temp[threadBase + 1].endPoint_low;
|
endPoint_q[1][0] = shared_temp[threadBase + 1].endPoint_low;
|
||||||
endPoint_q[1][1] = shared_temp[threadBase + 1].endPoint_high;
|
endPoint_q[1][1] = shared_temp[threadBase + 1].endPoint_high;
|
||||||
|
|
||||||
if ( best_mode > 10 )
|
if (best_mode > 10)
|
||||||
{
|
{
|
||||||
block_package( block, endPoint_q[0], best_mode );
|
block_package(block, endPoint_q[0], best_mode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
block_package( block, endPoint_q, best_mode, best_partition );
|
block_package(block, endPoint_q, best_mode, best_partition);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_OutBuff[blockID] = block;
|
g_OutBuff[blockID] = block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint float2half1( float f )
|
uint float2half1(float f)
|
||||||
{
|
{
|
||||||
uint Result;
|
uint Result;
|
||||||
|
|
||||||
@ -1012,7 +1012,7 @@ uint float2half1( float f )
|
|||||||
return (Result|Sign);
|
return (Result|Sign);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint3 float2half( float3 endPoint_f )
|
uint3 float2half(float3 endPoint_f)
|
||||||
{
|
{
|
||||||
//uint3 sign = asuint(endPoint_f) & 0x80000000;
|
//uint3 sign = asuint(endPoint_f) & 0x80000000;
|
||||||
//uint3 expo = asuint(endPoint_f) & 0x7F800000;
|
//uint3 expo = asuint(endPoint_f) & 0x7F800000;
|
||||||
@ -1027,140 +1027,140 @@ uint3 float2half( float3 endPoint_f )
|
|||||||
// : ( ( sign >> 16 ) | ( ( ( expo - 0x38000000 ) | base ) >> 13 ) ) ) );
|
// : ( ( sign >> 16 ) | ( ( ( expo - 0x38000000 ) | base ) >> 13 ) ) ) );
|
||||||
|
|
||||||
|
|
||||||
return uint3( float2half1( endPoint_f.x ), float2half1( endPoint_f.y ), float2half1( endPoint_f.z ) );
|
return uint3(float2half1(endPoint_f.x), float2half1(endPoint_f.y), float2half1(endPoint_f.z));
|
||||||
}
|
}
|
||||||
int3 start_quantize( uint3 pixel_h )
|
int3 start_quantize(uint3 pixel_h)
|
||||||
{
|
{
|
||||||
if ( g_format == UNSIGNED_F16 )
|
if (g_format == UNSIGNED_F16)
|
||||||
{
|
{
|
||||||
return asint( ( pixel_h << 6 ) / 31 );
|
return asint((pixel_h << 6) / 31);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ( pixel_h < 0x8000 ) ? ( ( pixel_h == 0x7bff ) ? 0x7fff : asint( ( pixel_h << 5 ) / 31 ) )// fixed a bug in v0.2
|
return (pixel_h < 0x8000) ? ((pixel_h == 0x7bff) ? 0x7fff : asint((pixel_h << 5) / 31))// fixed a bug in v0.2
|
||||||
: ( ( pixel_h == 0x7bff ) ? 0xffff8001 : -asint( ( ( 0x00007fff & pixel_h ) << 5 ) / 31 ) );// fixed a bug in v0.2
|
: ((pixel_h == 0x7bff) ? 0xffff8001 : -asint(((0x00007fff & pixel_h) << 5) / 31));// fixed a bug in v0.2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void quantize( inout int2x3 endPoint, uint prec )
|
void quantize(inout int2x3 endPoint, uint prec)
|
||||||
{
|
{
|
||||||
int iprec = asint( prec );
|
int iprec = asint(prec);
|
||||||
if ( g_format == UNSIGNED_F16 )
|
if (g_format == UNSIGNED_F16)
|
||||||
{
|
{
|
||||||
endPoint = ( ( iprec >= 15 ) | ( endPoint == 0 ) ) ? endPoint
|
endPoint = ((iprec >= 15) | (endPoint == 0)) ? endPoint
|
||||||
: ( ( endPoint == asint(0xFFFF) ) ? ( ( 1 << iprec ) - 1 )
|
: ((endPoint == asint(0xFFFF)) ? ((1 << iprec) - 1)
|
||||||
: ( ( ( endPoint << iprec ) + asint(0x0000) ) >> 16 ) );
|
: (((endPoint << iprec) + asint(0x0000)) >> 16));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
endPoint = ( ( iprec >= 16 ) | ( endPoint == 0 ) ) ? endPoint
|
endPoint = ((iprec >= 16) | (endPoint == 0)) ? endPoint
|
||||||
: ( ( endPoint >= 0 ) ? ( ( endPoint == asint(0x7FFF) ) ? ( ( 1 << ( iprec - 1 ) ) - 1 ) : ( ( ( endPoint << ( iprec - 1 ) ) + asint(0x0000) ) >> 15 ) )
|
: ((endPoint >= 0) ? ((endPoint == asint(0x7FFF)) ? ((1 << (iprec - 1)) - 1) : (((endPoint << (iprec - 1)) + asint(0x0000)) >> 15))
|
||||||
: ( ( -endPoint == asint(0x7FFF) ) ? -( ( 1 << ( iprec - 1 ) ) - 1 ) : -( ( ( -endPoint << ( iprec - 1 ) ) + asint(0x0000) ) >> 15 ) ) );
|
: ((-endPoint == asint(0x7FFF)) ? -((1 << (iprec - 1)) - 1) : -(((-endPoint << (iprec - 1)) + asint(0x0000)) >> 15)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void finish_quantize_0( inout int bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed )
|
void finish_quantize_0(inout int bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed)
|
||||||
{
|
{
|
||||||
if ( transformed )
|
if (transformed)
|
||||||
{
|
{
|
||||||
bool3 bBadComponent = ( endPoint[1] >= 0 ) ? ( endPoint[1] >= ( 1 << ( prec.yzw - 1 ) ) )
|
bool3 bBadComponent = (endPoint[1] >= 0) ? (endPoint[1] >= (1 << (prec.yzw - 1)))
|
||||||
: ( -endPoint[1] > ( 1 << ( prec.yzw - 1 ) ) );
|
: (-endPoint[1] > (1 << (prec.yzw - 1)));
|
||||||
bBadQuantize |= any(bBadComponent);
|
bBadQuantize |= any(bBadComponent);
|
||||||
|
|
||||||
endPoint[0] = endPoint[0] & ( ( 1 << prec.x ) - 1 );
|
endPoint[0] = endPoint[0] & ((1 << prec.x) - 1);
|
||||||
endPoint[1] = ( endPoint[1] >= 0 ) ? ( ( endPoint[1] >= ( 1 << ( prec.yzw - 1 ) ) ) ? ( ( 1 << ( prec.yzw - 1 ) ) - 1 ) : endPoint[1] )
|
endPoint[1] = (endPoint[1] >= 0) ? ((endPoint[1] >= (1 << (prec.yzw - 1))) ? ((1 << (prec.yzw - 1)) - 1) : endPoint[1])
|
||||||
: ( ( -endPoint[1] > ( 1 << ( prec.yzw - 1 ) ) ) ? ( 1 << ( prec.yzw - 1 ) ) : ( endPoint[1] & ( ( 1 << prec.yzw ) - 1 ) ) );
|
: ((-endPoint[1] > (1 << (prec.yzw - 1))) ? (1 << (prec.yzw - 1)) : (endPoint[1] & ((1 << prec.yzw) - 1)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
endPoint &= ( ( 1 << prec.x ) - 1 );
|
endPoint &= ((1 << prec.x) - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void finish_quantize_1( inout int bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed )
|
void finish_quantize_1(inout int bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed)
|
||||||
{
|
{
|
||||||
if ( transformed )
|
if (transformed)
|
||||||
{
|
{
|
||||||
bool2x3 bBadComponent;
|
bool2x3 bBadComponent;
|
||||||
bBadComponent[0] = ( endPoint[0] >= 0 ) ? ( endPoint[0] >= ( 1 << ( prec.yzw - 1 ) ) )
|
bBadComponent[0] = (endPoint[0] >= 0) ? (endPoint[0] >= (1 << (prec.yzw - 1)))
|
||||||
: ( -endPoint[0] > ( 1 << ( prec.yzw - 1 ) ) );
|
: (-endPoint[0] > (1 << (prec.yzw - 1)));
|
||||||
bBadComponent[1] = ( endPoint[1] >= 0 ) ? ( endPoint[1] >= ( 1 << ( prec.yzw - 1 ) ) )
|
bBadComponent[1] = (endPoint[1] >= 0) ? (endPoint[1] >= (1 << (prec.yzw - 1)))
|
||||||
: ( -endPoint[1] > ( 1 << ( prec.yzw - 1 ) ) );
|
: (-endPoint[1] > (1 << (prec.yzw - 1)));
|
||||||
bBadQuantize |= any(bBadComponent);
|
bBadQuantize |= any(bBadComponent);
|
||||||
|
|
||||||
endPoint[0] = ( endPoint[0] >= 0 ) ? ( ( endPoint[0] >= ( 1 << ( prec.yzw - 1 ) ) ) ? ( ( 1 << ( prec.yzw - 1 ) ) - 1 ) : endPoint[0] )
|
endPoint[0] = (endPoint[0] >= 0) ? ((endPoint[0] >= (1 << (prec.yzw - 1))) ? ((1 << (prec.yzw - 1)) - 1) : endPoint[0])
|
||||||
: ( ( -endPoint[0] > ( 1 << ( prec.yzw - 1 ) ) ) ? ( 1 << ( prec.yzw - 1 ) ) : ( endPoint[0] & ( ( 1 << prec.yzw ) - 1 ) ) );
|
: ((-endPoint[0] > (1 << (prec.yzw - 1))) ? (1 << (prec.yzw - 1)) : (endPoint[0] & ((1 << prec.yzw) - 1)));
|
||||||
endPoint[1] = ( endPoint[1] >= 0 ) ? ( ( endPoint[1] >= ( 1 << ( prec.yzw - 1 ) ) ) ? ( ( 1 << ( prec.yzw - 1 ) ) - 1 ) : endPoint[1] )
|
endPoint[1] = (endPoint[1] >= 0) ? ((endPoint[1] >= (1 << (prec.yzw - 1))) ? ((1 << (prec.yzw - 1)) - 1) : endPoint[1])
|
||||||
: ( ( -endPoint[1] > ( 1 << ( prec.yzw - 1 ) ) ) ? ( 1 << ( prec.yzw - 1 ) ) : ( endPoint[1] & ( ( 1 << prec.yzw ) - 1 ) ) );
|
: ((-endPoint[1] > (1 << (prec.yzw - 1))) ? (1 << (prec.yzw - 1)) : (endPoint[1] & ((1 << prec.yzw) - 1)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
endPoint &= ( ( 1 << prec.x ) - 1 );
|
endPoint &= ((1 << prec.x) - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void finish_quantize( out bool bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed )
|
void finish_quantize(out bool bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed)
|
||||||
{
|
{
|
||||||
if ( transformed )
|
if (transformed)
|
||||||
{
|
{
|
||||||
bool3 bBadComponent;
|
bool3 bBadComponent;
|
||||||
bBadComponent = ( endPoint[1] >= 0 ) ? ( endPoint[1] >= ( 1 << ( prec.yzw - 1 ) ) )
|
bBadComponent = (endPoint[1] >= 0) ? (endPoint[1] >= (1 << (prec.yzw - 1)))
|
||||||
: ( -endPoint[1] > ( 1 << ( prec.yzw - 1 ) ) );
|
: (-endPoint[1] > (1 << (prec.yzw - 1)));
|
||||||
bBadQuantize = any( bBadComponent );
|
bBadQuantize = any(bBadComponent);
|
||||||
|
|
||||||
endPoint[0] = endPoint[0] & ( ( 1 << prec.x ) - 1 );
|
endPoint[0] = endPoint[0] & ((1 << prec.x) - 1);
|
||||||
endPoint[1] = ( endPoint[1] >= 0 ) ? ( ( endPoint[1] >= ( 1 << ( prec.yzw - 1 ) ) ) ? ( ( 1 << ( prec.yzw - 1 ) ) - 1 ) : endPoint[1] )
|
endPoint[1] = (endPoint[1] >= 0) ? ((endPoint[1] >= (1 << (prec.yzw - 1))) ? ((1 << (prec.yzw - 1)) - 1) : endPoint[1])
|
||||||
: ( ( -endPoint[1] > ( 1 << ( prec.yzw - 1 ) ) ) ? ( 1 << ( prec.yzw - 1 ) ) : ( endPoint[1] & ( ( 1 << prec.yzw ) - 1 ) ) );
|
: ((-endPoint[1] > (1 << (prec.yzw - 1))) ? (1 << (prec.yzw - 1)) : (endPoint[1] & ((1 << prec.yzw) - 1)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
endPoint &= ( ( 1 << prec.x ) - 1 );
|
endPoint &= ((1 << prec.x) - 1);
|
||||||
|
|
||||||
bBadQuantize = 0;
|
bBadQuantize = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SIGN_EXTEND( uint3 prec, inout int3 color )
|
void SIGN_EXTEND(uint3 prec, inout int3 color)
|
||||||
{
|
{
|
||||||
uint3 p = 1 << (prec - 1);
|
uint3 p = 1 << (prec - 1);
|
||||||
color = (color & p) ? (color & (p - 1)) - p : color;
|
color = (color & p) ? (color & (p - 1)) - p : color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sign_extend( bool transformed, uint4 prec, inout int2x3 endPoint )
|
void sign_extend(bool transformed, uint4 prec, inout int2x3 endPoint)
|
||||||
{
|
{
|
||||||
if ( g_format == SIGNED_F16 )
|
if (g_format == SIGNED_F16)
|
||||||
SIGN_EXTEND( prec.x, endPoint[0] );
|
SIGN_EXTEND(prec.x, endPoint[0]);
|
||||||
if ( g_format == SIGNED_F16 || transformed )
|
if (g_format == SIGNED_F16 || transformed)
|
||||||
SIGN_EXTEND( prec.yzw, endPoint[1] );
|
SIGN_EXTEND(prec.yzw, endPoint[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sign_extend( bool transformed, uint4 prec, inout int2x3 endPoint[2] )
|
void sign_extend(bool transformed, uint4 prec, inout int2x3 endPoint[2])
|
||||||
{
|
{
|
||||||
if ( g_format == SIGNED_F16 )
|
if (g_format == SIGNED_F16)
|
||||||
SIGN_EXTEND( prec.x, endPoint[0][0] );
|
SIGN_EXTEND(prec.x, endPoint[0][0]);
|
||||||
if ( g_format == SIGNED_F16 || transformed )
|
if (g_format == SIGNED_F16 || transformed)
|
||||||
{
|
{
|
||||||
SIGN_EXTEND( prec.yzw, endPoint[0][1] );
|
SIGN_EXTEND(prec.yzw, endPoint[0][1]);
|
||||||
SIGN_EXTEND( prec.yzw, endPoint[1][0] );
|
SIGN_EXTEND(prec.yzw, endPoint[1][0]);
|
||||||
SIGN_EXTEND( prec.yzw, endPoint[1][1] );
|
SIGN_EXTEND(prec.yzw, endPoint[1][1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void start_unquantize( inout int2x3 endPoint[2], uint4 prec, bool transformed )
|
void start_unquantize(inout int2x3 endPoint[2], uint4 prec, bool transformed)
|
||||||
{
|
{
|
||||||
sign_extend( transformed, prec, endPoint );
|
sign_extend(transformed, prec, endPoint);
|
||||||
if ( transformed )
|
if (transformed)
|
||||||
{
|
{
|
||||||
endPoint[0][1] += endPoint[0][0];
|
endPoint[0][1] += endPoint[0][0];
|
||||||
endPoint[1][0] += endPoint[0][0];
|
endPoint[1][0] += endPoint[0][0];
|
||||||
endPoint[1][1] += endPoint[0][0];
|
endPoint[1][1] += endPoint[0][0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void start_unquantize( inout int2x3 endPoint, uint4 prec, bool transformed )
|
void start_unquantize(inout int2x3 endPoint, uint4 prec, bool transformed)
|
||||||
{
|
{
|
||||||
sign_extend( transformed, prec, endPoint );
|
sign_extend(transformed, prec, endPoint);
|
||||||
if ( transformed )
|
if (transformed)
|
||||||
endPoint[1] += endPoint[0];
|
endPoint[1] += endPoint[0];
|
||||||
}
|
}
|
||||||
void unquantize( inout int2x3 color, uint prec )
|
void unquantize(inout int2x3 color, uint prec)
|
||||||
{
|
{
|
||||||
int iprec = asint( prec );
|
int iprec = asint(prec);
|
||||||
if (g_format == UNSIGNED_F16 )
|
if (g_format == UNSIGNED_F16)
|
||||||
{
|
{
|
||||||
if (prec < 15)
|
if (prec < 15)
|
||||||
{
|
{
|
||||||
@ -1178,33 +1178,33 @@ void unquantize( inout int2x3 color, uint prec )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint3 finish_unquantize( int3 color )
|
uint3 finish_unquantize(int3 color)
|
||||||
{
|
{
|
||||||
if ( g_format == UNSIGNED_F16 )
|
if (g_format == UNSIGNED_F16)
|
||||||
color = ( color * 31 ) >> 6;
|
color = (color * 31) >> 6;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
color = ( color < 0 ) ? -( ( -color * 31 ) >> 5 ) : ( color * 31 ) >> 5;
|
color = (color < 0) ? -((-color * 31) >> 5) : (color * 31) >> 5;
|
||||||
color = ( color < 0 ) ? ( ( -color ) | 0x8000 ) : color;
|
color = (color < 0) ? ((-color) | 0x8000) : color;
|
||||||
}
|
}
|
||||||
return asuint(color);
|
return asuint(color);
|
||||||
}
|
}
|
||||||
void generate_palette_unquantized8( out uint3 palette, int3 low, int3 high, int i )
|
void generate_palette_unquantized8(out uint3 palette, int3 low, int3 high, int i)
|
||||||
{
|
{
|
||||||
static const int aWeight3[] = {0, 9, 18, 27, 37, 46, 55, 64};
|
static const int aWeight3[] = { 0, 9, 18, 27, 37, 46, 55, 64 };
|
||||||
|
|
||||||
int3 tmp = ( low * ( 64 - aWeight3[i] ) + high * aWeight3[i] + 32 ) >> 6;
|
int3 tmp = (low * (64 - aWeight3[i]) + high * aWeight3[i] + 32) >> 6;
|
||||||
palette = finish_unquantize( tmp );
|
palette = finish_unquantize(tmp);
|
||||||
}
|
}
|
||||||
void generate_palette_unquantized16( out uint3 palette, int3 low, int3 high, int i )
|
void generate_palette_unquantized16(out uint3 palette, int3 low, int3 high, int i)
|
||||||
{
|
{
|
||||||
static const int aWeight4[] = {0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64};
|
static const int aWeight4[] = { 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64 };
|
||||||
|
|
||||||
int3 tmp = ( low * ( 64 - aWeight4[i] ) + high * aWeight4[i] + 32 ) >> 6;
|
int3 tmp = (low * (64 - aWeight4[i]) + high * aWeight4[i] + 32) >> 6;
|
||||||
palette = finish_unquantize( tmp );
|
palette = finish_unquantize(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
float half2float1( uint Value )
|
float half2float1(uint Value)
|
||||||
{
|
{
|
||||||
uint Mantissa = (uint)(Value & 0x03FF);
|
uint Mantissa = (uint)(Value & 0x03FF);
|
||||||
|
|
||||||
@ -1232,13 +1232,13 @@ float half2float1( uint Value )
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint Result = ((Value & 0x8000) << 16) | // Sign
|
uint Result = ((Value & 0x8000) << 16) | // Sign
|
||||||
((Exponent + 112) << 23) | // Exponent
|
((Exponent + 112) << 23) | // Exponent
|
||||||
(Mantissa << 13); // Mantissa
|
(Mantissa << 13); // Mantissa
|
||||||
|
|
||||||
return asfloat(Result);
|
return asfloat(Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 half2float(uint3 color_h )
|
float3 half2float(uint3 color_h)
|
||||||
{
|
{
|
||||||
//uint3 sign = color_h & 0x8000;
|
//uint3 sign = color_h & 0x8000;
|
||||||
//uint3 expo = color_h & 0x7C00;
|
//uint3 expo = color_h & 0x7C00;
|
||||||
@ -1246,17 +1246,17 @@ float3 half2float(uint3 color_h )
|
|||||||
//return ( expo == 0 ) ? asfloat( ( sign << 16 ) | asuint( float3(base) / 16777216 ) ) //16777216 = 2^24
|
//return ( expo == 0 ) ? asfloat( ( sign << 16 ) | asuint( float3(base) / 16777216 ) ) //16777216 = 2^24
|
||||||
// : asfloat( ( sign << 16 ) | ( ( ( expo + 0x1C000 ) | base ) << 13 ) ); //0x1C000 = 0x1FC00 - 0x3C00
|
// : asfloat( ( sign << 16 ) | ( ( ( expo + 0x1C000 ) | base ) << 13 ) ); //0x1C000 = 0x1FC00 - 0x3C00
|
||||||
|
|
||||||
return float3( half2float1( color_h.x ), half2float1( color_h.y ), half2float1( color_h.z ) );
|
return float3(half2float1(color_h.x), half2float1(color_h.y), half2float1(color_h.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint partition_index ) // for mode 1 - 10
|
void block_package(inout uint4 block, int2x3 endPoint[2], uint mode_type, uint partition_index) // for mode 1 - 10
|
||||||
{
|
{
|
||||||
block.xy = 0;
|
block.xy = 0;
|
||||||
block.z &= 0xFFFC0000;
|
block.z &= 0xFFFC0000;
|
||||||
|
|
||||||
//block.z |= (partition_index & 0x1f) << 13;
|
//block.z |= (partition_index & 0x1f) << 13;
|
||||||
|
|
||||||
if ( mode_type == candidateModeFlag[0])
|
if (mode_type == candidateModeFlag[0])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[0];
|
/*block.x = candidateModeMemory[0];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
||||||
@ -1355,7 +1355,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 3) & 1) << 16;
|
block.z |= ((partition_index >> 3) & 1) << 16;
|
||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
else if ( mode_type == candidateModeFlag[1])
|
else if (mode_type == candidateModeFlag[1])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[1];
|
/*block.x = candidateModeMemory[1];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00000FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x003F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00000FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x003F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
||||||
@ -1453,7 +1453,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 3) & 1) << 16;
|
block.z |= ((partition_index >> 3) & 1) << 16;
|
||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
else if ( mode_type == candidateModeFlag[2])
|
else if (mode_type == candidateModeFlag[2])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[2];
|
/*block.x = candidateModeMemory[2];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
||||||
@ -1550,7 +1550,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 3) & 1) << 16;
|
block.z |= ((partition_index >> 3) & 1) << 16;
|
||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
else if ( mode_type == candidateModeFlag[3])
|
else if (mode_type == candidateModeFlag[3])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[3];
|
/*block.x = candidateModeMemory[3];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
||||||
@ -1651,7 +1651,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 3) & 1) << 16;
|
block.z |= ((partition_index >> 3) & 1) << 16;
|
||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
else if ( mode_type == candidateModeFlag[4])
|
else if (mode_type == candidateModeFlag[4])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[4];
|
/*block.x = candidateModeMemory[4];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
||||||
@ -1750,7 +1750,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 3) & 1) << 16;
|
block.z |= ((partition_index >> 3) & 1) << 16;
|
||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
else if ( mode_type == candidateModeFlag[5])
|
else if (mode_type == candidateModeFlag[5])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[5];
|
/*block.x = candidateModeMemory[5];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00003FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x00FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000);
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00003FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x00FF8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000);
|
||||||
@ -1849,7 +1849,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 3) & 1) << 16;
|
block.z |= ((partition_index >> 3) & 1) << 16;
|
||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
else if ( mode_type == candidateModeFlag[6])
|
else if (mode_type == candidateModeFlag[6])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[6];
|
/*block.x = candidateModeMemory[6];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00001FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x007F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00001FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x007F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
||||||
@ -1947,7 +1947,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 3) & 1) << 16;
|
block.z |= ((partition_index >> 3) & 1) << 16;
|
||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
else if ( mode_type == candidateModeFlag[7])
|
else if (mode_type == candidateModeFlag[7])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[7];
|
/*block.x = candidateModeMemory[7];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00001FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x007F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00001FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x007F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
||||||
@ -2047,7 +2047,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 3) & 1) << 16;
|
block.z |= ((partition_index >> 3) & 1) << 16;
|
||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
else if ( mode_type == candidateModeFlag[8])
|
else if (mode_type == candidateModeFlag[8])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[8];
|
/*block.x = candidateModeMemory[8];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00001FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x007F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x00001FE0 ) | ( ( endPoint[0][0].g << 15 ) & 0x007F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0xFE000000 );
|
||||||
@ -2147,7 +2147,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 3) & 1) << 16;
|
block.z |= ((partition_index >> 3) & 1) << 16;
|
||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
else if ( mode_type == candidateModeFlag[9])
|
else if (mode_type == candidateModeFlag[9])
|
||||||
{
|
{
|
||||||
/*block.x = candidateModeMemory[9];
|
/*block.x = candidateModeMemory[9];
|
||||||
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x000007E0 ) | ( ( endPoint[0][0].g << 15 ) & 0x001F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0x7E000000 );
|
block.x |= ( ( endPoint[0][0].r << 5 ) & 0x000007E0 ) | ( ( endPoint[0][0].g << 15 ) & 0x001F8000 ) | ( ( endPoint[0][0].b << 25 ) & 0x7E000000 );
|
||||||
@ -2246,7 +2246,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint
|
|||||||
block.z |= ((partition_index >> 4) & 1) << 17;
|
block.z |= ((partition_index >> 4) & 1) << 17;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void block_package( inout uint4 block, int2x3 endPoint, uint mode_type ) // for mode 11 - 14
|
void block_package(inout uint4 block, int2x3 endPoint, uint mode_type) // for mode 11 - 14
|
||||||
{
|
{
|
||||||
/*block.x = ( ( endPoint[0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0].b << 25 ) & 0xFE000000 );
|
/*block.x = ( ( endPoint[0].r << 5 ) & 0x00007FE0 ) | ( ( endPoint[0].g << 15 ) & 0x01FF8000 ) | ( ( endPoint[0].b << 25 ) & 0xFE000000 );
|
||||||
block.y |= ( endPoint[0].b >> 7 ) & 0x00000007;*/
|
block.y |= ( endPoint[0].b >> 7 ) & 0x00000007;*/
|
||||||
@ -2255,11 +2255,11 @@ void block_package( inout uint4 block, int2x3 endPoint, uint mode_type ) // for
|
|||||||
block.z &= 0xFFFFFFFE;
|
block.z &= 0xFFFFFFFE;
|
||||||
|
|
||||||
|
|
||||||
if ( mode_type == candidateModeFlag[10])
|
if (mode_type == candidateModeFlag[10])
|
||||||
{
|
{
|
||||||
/* block.x |= candidateModeMemory[10];
|
/* block.x |= candidateModeMemory[10];
|
||||||
block.y |= ( ( endPoint[1].r << 3 ) & 0x00001FF8 ) | ( ( endPoint[1].g << 13 ) & 0x007FE000 ) | ( ( endPoint[1].b << 23 ) & 0xFF800000 );
|
block.y |= ( ( endPoint[1].r << 3 ) & 0x00001FF8 ) | ( ( endPoint[1].g << 13 ) & 0x007FE000 ) | ( ( endPoint[1].b << 23 ) & 0xFF800000 );
|
||||||
block.z |= ( endPoint[1].b >> 9 ) & 0x00000001;*/
|
block.z |= ( endPoint[1].b >> 9 ) & 0x00000001;*/
|
||||||
|
|
||||||
block.x |= ((candidateModeMemory[10] >> 0) & 1) << 0;
|
block.x |= ((candidateModeMemory[10] >> 0) & 1) << 0;
|
||||||
block.x |= ((candidateModeMemory[10] >> 1) & 1) << 1;
|
block.x |= ((candidateModeMemory[10] >> 1) & 1) << 1;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,7 @@ namespace DirectX
|
|||||||
XMGLOBALCONST XMVECTORF32 g_boxScale = { { { 0.25f, 0.25f, 0.25f, 0.25f } } };
|
XMGLOBALCONST XMVECTORF32 g_boxScale = { { { 0.25f, 0.25f, 0.25f, 0.25f } } };
|
||||||
XMGLOBALCONST XMVECTORF32 g_boxScale3D = { { { 0.125f, 0.125f, 0.125f, 0.125f } } };
|
XMGLOBALCONST XMVECTORF32 g_boxScale3D = { { { 0.125f, 0.125f, 0.125f, 0.125f } } };
|
||||||
|
|
||||||
#define AVERAGE4( res, p0, p1, p2, p3 ) \
|
#define AVERAGE4( res, p0, p1, p2, p3 ) \
|
||||||
{ \
|
{ \
|
||||||
XMVECTOR v = XMVectorAdd((p0), (p1)); \
|
XMVECTOR v = XMVectorAdd((p0), (p1)); \
|
||||||
v = XMVectorAdd(v, (p2)); \
|
v = XMVectorAdd(v, (p2)); \
|
||||||
@ -36,7 +36,7 @@ namespace DirectX
|
|||||||
res = XMVectorMultiply(v, g_boxScale); \
|
res = XMVectorMultiply(v, g_boxScale); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define AVERAGE8( res, p0, p1, p2, p3, p4, p5, p6, p7) \
|
#define AVERAGE8( res, p0, p1, p2, p3, p4, p5, p6, p7) \
|
||||||
{ \
|
{ \
|
||||||
XMVECTOR v = XMVectorAdd((p0), (p1)); \
|
XMVECTOR v = XMVectorAdd((p0), (p1)); \
|
||||||
v = XMVectorAdd(v, (p2)); \
|
v = XMVectorAdd(v, (p2)); \
|
||||||
@ -99,11 +99,11 @@ namespace DirectX
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BILINEAR_INTERPOLATE( res, x, y, r0, r1 ) \
|
#define BILINEAR_INTERPOLATE( res, x, y, r0, r1 ) \
|
||||||
res = XMVectorAdd(XMVectorScale(XMVectorAdd(XMVectorScale((r0)[ x.u0 ], x.weight0), XMVectorScale((r0)[ x.u1 ], x.weight1)), y.weight0), \
|
res = XMVectorAdd(XMVectorScale(XMVectorAdd(XMVectorScale((r0)[ x.u0 ], x.weight0), XMVectorScale((r0)[ x.u1 ], x.weight1)), y.weight0), \
|
||||||
XMVectorScale(XMVectorAdd(XMVectorScale((r1)[ x.u0 ], x.weight0), XMVectorScale((r1)[ x.u1 ], x.weight1)), y.weight1) );
|
XMVectorScale(XMVectorAdd(XMVectorScale((r1)[ x.u0 ], x.weight0), XMVectorScale((r1)[ x.u1 ], x.weight1)), y.weight1) );
|
||||||
|
|
||||||
#define TRILINEAR_INTERPOLATE( res, x, y, z, r0, r1, r2, r3 ) \
|
#define TRILINEAR_INTERPOLATE( res, x, y, z, r0, r1, r2, r3 ) \
|
||||||
{\
|
{\
|
||||||
const XMVECTOR a0 = XMVectorScale(XMVectorAdd(XMVectorScale((r0)[ x.u0 ], x.weight0 ), XMVectorScale((r0)[ x.u1 ], x.weight1)), y.weight0); \
|
const XMVECTOR a0 = XMVectorScale(XMVectorAdd(XMVectorScale((r0)[ x.u0 ], x.weight0 ), XMVectorScale((r0)[ x.u1 ], x.weight1)), y.weight0); \
|
||||||
const XMVECTOR a1 = XMVectorScale(XMVectorAdd(XMVectorScale((r1)[ x.u0 ], x.weight0 ), XMVectorScale((r1)[ x.u1 ], x.weight1)), y.weight1); \
|
const XMVECTOR a1 = XMVectorScale(XMVectorAdd(XMVectorScale((r1)[ x.u0 ], x.weight0 ), XMVectorScale((r1)[ x.u1 ], x.weight1)), y.weight1); \
|
||||||
@ -189,7 +189,7 @@ namespace DirectX
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CUBIC_INTERPOLATE( res, dx, p0, p1, p2, p3 ) \
|
#define CUBIC_INTERPOLATE( res, dx, p0, p1, p2, p3 ) \
|
||||||
{ \
|
{ \
|
||||||
const XMVECTOR a0 = (p1); \
|
const XMVECTOR a0 = (p1); \
|
||||||
const XMVECTOR d0 = XMVectorSubtract(p0, a0); \
|
const XMVECTOR d0 = XMVectorSubtract(p0, a0); \
|
||||||
|
@ -29,7 +29,7 @@ inline ScopedAlignedArrayFloat make_AlignedArrayFloat(uint64_t count)
|
|||||||
if (size > static_cast<uint64_t>(UINT32_MAX))
|
if (size > static_cast<uint64_t>(UINT32_MAX))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto ptr = aligned_alloc(16, static_cast<size_t>(size) );
|
auto ptr = aligned_alloc(16, static_cast<size_t>(size));
|
||||||
return ScopedAlignedArrayFloat(static_cast<float*>(ptr));
|
return ScopedAlignedArrayFloat(static_cast<float*>(ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ using Microsoft::WRL::ComPtr;
|
|||||||
// Macros
|
// Macros
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#ifndef MAKEFOURCC
|
#ifndef MAKEFOURCC
|
||||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||||
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
||||||
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
||||||
#endif /* defined(MAKEFOURCC) */
|
#endif /* defined(MAKEFOURCC) */
|
||||||
@ -69,9 +69,9 @@ using Microsoft::WRL::ComPtr;
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#pragma pack(push,1)
|
#pragma pack(push,1)
|
||||||
|
|
||||||
#define DDS_MAGIC 0x20534444 // "DDS "
|
#define DDS_MAGIC 0x20534444 // "DDS "
|
||||||
|
|
||||||
struct DDS_PIXELFORMAT
|
struct DDS_PIXELFORMAT
|
||||||
{
|
{
|
||||||
@ -85,20 +85,20 @@ namespace
|
|||||||
uint32_t ABitMask;
|
uint32_t ABitMask;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
||||||
#define DDS_RGB 0x00000040 // DDPF_RGB
|
#define DDS_RGB 0x00000040 // DDPF_RGB
|
||||||
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
||||||
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
||||||
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
||||||
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
||||||
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
|
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
|
||||||
|
|
||||||
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
||||||
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
||||||
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
||||||
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
||||||
|
|
||||||
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
||||||
|
|
||||||
struct DDS_HEADER
|
struct DDS_HEADER
|
||||||
{
|
{
|
||||||
@ -127,7 +127,7 @@ namespace
|
|||||||
uint32_t reserved;
|
uint32_t reserved;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
const DDS_PIXELFORMAT DDSPF_DXT1 =
|
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 };
|
||||||
@ -574,13 +574,13 @@ namespace
|
|||||||
numBytes = rowBytes * height;
|
numBytes = rowBytes * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
||||||
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
||||||
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
||||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||||
#else
|
#else
|
||||||
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (outNumBytes)
|
if (outNumBytes)
|
||||||
{
|
{
|
||||||
@ -732,7 +732,7 @@ namespace
|
|||||||
|
|
||||||
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
|
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
|
||||||
{
|
{
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
HRESULT hr = CoCreateInstance(
|
HRESULT hr = CoCreateInstance(
|
||||||
CLSID_WICImagingFactory2,
|
CLSID_WICImagingFactory2,
|
||||||
nullptr,
|
nullptr,
|
||||||
@ -758,14 +758,14 @@ namespace
|
|||||||
);
|
);
|
||||||
return SUCCEEDED(hr) ? TRUE : FALSE;
|
return SUCCEEDED(hr) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return SUCCEEDED(CoCreateInstance(
|
return SUCCEEDED(CoCreateInstance(
|
||||||
CLSID_WICImagingFactory,
|
CLSID_WICImagingFactory,
|
||||||
nullptr,
|
nullptr,
|
||||||
CLSCTX_INPROC_SERVER,
|
CLSCTX_INPROC_SERVER,
|
||||||
__uuidof(IWICImagingFactory),
|
__uuidof(IWICImagingFactory),
|
||||||
ifactory)) ? TRUE : FALSE;
|
ifactory)) ? TRUE : FALSE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
IWICImagingFactory* GetWIC() noexcept
|
IWICImagingFactory* GetWIC() noexcept
|
||||||
@ -1092,7 +1092,7 @@ HRESULT DirectX::SaveWICTextureToFile(
|
|||||||
// Screenshots don't typically include the alpha channel of the render target
|
// 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)
|
#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:
|
case DXGI_FORMAT_R16G16B16A16_FLOAT:
|
||||||
if (g_WIC2)
|
if (g_WIC2)
|
||||||
@ -1104,7 +1104,7 @@ HRESULT DirectX::SaveWICTextureToFile(
|
|||||||
targetGuid = GUID_WICPixelFormat24bppBGR;
|
targetGuid = GUID_WICPixelFormat24bppBGR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case DXGI_FORMAT_R16G16B16A16_UNORM: targetGuid = GUID_WICPixelFormat48bppBGR; break;
|
case DXGI_FORMAT_R16G16B16A16_UNORM: targetGuid = GUID_WICPixelFormat48bppBGR; break;
|
||||||
case DXGI_FORMAT_B5G5R5A1_UNORM: targetGuid = GUID_WICPixelFormat16bppBGR555; break;
|
case DXGI_FORMAT_B5G5R5A1_UNORM: targetGuid = GUID_WICPixelFormat16bppBGR555; break;
|
||||||
|
@ -91,9 +91,9 @@ using Microsoft::WRL::ComPtr;
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#pragma pack(push,1)
|
#pragma pack(push,1)
|
||||||
|
|
||||||
#define DDS_MAGIC 0x20534444 // "DDS "
|
#define DDS_MAGIC 0x20534444 // "DDS "
|
||||||
|
|
||||||
struct DDS_PIXELFORMAT
|
struct DDS_PIXELFORMAT
|
||||||
{
|
{
|
||||||
@ -107,20 +107,20 @@ namespace
|
|||||||
uint32_t ABitMask;
|
uint32_t ABitMask;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
||||||
#define DDS_RGB 0x00000040 // DDPF_RGB
|
#define DDS_RGB 0x00000040 // DDPF_RGB
|
||||||
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
||||||
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
||||||
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
||||||
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
||||||
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
|
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
|
||||||
|
|
||||||
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
||||||
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
||||||
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
||||||
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
||||||
|
|
||||||
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
||||||
|
|
||||||
struct DDS_HEADER
|
struct DDS_HEADER
|
||||||
{
|
{
|
||||||
@ -149,7 +149,7 @@ namespace
|
|||||||
uint32_t reserved;
|
uint32_t reserved;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
const DDS_PIXELFORMAT DDSPF_DXT1 =
|
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 };
|
||||||
@ -602,13 +602,13 @@ namespace
|
|||||||
numBytes = rowBytes * height;
|
numBytes = rowBytes * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
||||||
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
||||||
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
||||||
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
||||||
#else
|
#else
|
||||||
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (outNumBytes)
|
if (outNumBytes)
|
||||||
{
|
{
|
||||||
@ -842,11 +842,11 @@ namespace
|
|||||||
// Block until the copy is complete
|
// Block until the copy is complete
|
||||||
while (fence->GetCompletedValue() < 1)
|
while (fence->GetCompletedValue() < 1)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
SwitchToThread();
|
SwitchToThread();
|
||||||
#else
|
#else
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
@ -51,7 +51,7 @@ using Microsoft::WRL::ComPtr;
|
|||||||
// Macros
|
// Macros
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
#ifndef MAKEFOURCC
|
#ifndef MAKEFOURCC
|
||||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||||
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
||||||
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
||||||
#endif /* defined(MAKEFOURCC) */
|
#endif /* defined(MAKEFOURCC) */
|
||||||
@ -63,9 +63,9 @@ using Microsoft::WRL::ComPtr;
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
#pragma pack(push,1)
|
#pragma pack(push,1)
|
||||||
|
|
||||||
#define DDS_MAGIC 0x20534444 // "DDS "
|
#define DDS_MAGIC 0x20534444 // "DDS "
|
||||||
|
|
||||||
struct DDS_PIXELFORMAT
|
struct DDS_PIXELFORMAT
|
||||||
{
|
{
|
||||||
@ -79,21 +79,21 @@ namespace
|
|||||||
uint32_t ABitMask;
|
uint32_t ABitMask;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
||||||
#define DDS_RGB 0x00000040 // DDPF_RGB
|
#define DDS_RGB 0x00000040 // DDPF_RGB
|
||||||
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
||||||
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
||||||
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
||||||
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
||||||
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
|
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
|
||||||
#define DDS_BUMPLUMINANCE 0x00040000 // DDPF_BUMPLUMINANCE
|
#define DDS_BUMPLUMINANCE 0x00040000 // DDPF_BUMPLUMINANCE
|
||||||
|
|
||||||
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
||||||
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
||||||
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
||||||
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
||||||
|
|
||||||
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
||||||
|
|
||||||
struct DDS_HEADER
|
struct DDS_HEADER
|
||||||
{
|
{
|
||||||
@ -113,7 +113,7 @@ namespace
|
|||||||
uint32_t reserved2;
|
uint32_t reserved2;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
const DDS_PIXELFORMAT DDSPF_DXT1 =
|
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 };
|
||||||
@ -316,9 +316,9 @@ namespace
|
|||||||
case D3DFMT_INDEX32:
|
case D3DFMT_INDEX32:
|
||||||
case D3DFMT_G16R16F:
|
case D3DFMT_G16R16F:
|
||||||
case D3DFMT_R32F:
|
case D3DFMT_R32F:
|
||||||
#if !defined(D3D_DISABLE_9EX)
|
#if !defined(D3D_DISABLE_9EX)
|
||||||
case D3DFMT_D32_LOCKABLE:
|
case D3DFMT_D32_LOCKABLE:
|
||||||
#endif
|
#endif
|
||||||
return 32;
|
return 32;
|
||||||
|
|
||||||
case D3DFMT_R8G8B8:
|
case D3DFMT_R8G8B8:
|
||||||
@ -354,9 +354,9 @@ namespace
|
|||||||
case D3DFMT_P8:
|
case D3DFMT_P8:
|
||||||
case D3DFMT_L8:
|
case D3DFMT_L8:
|
||||||
case D3DFMT_A4L4:
|
case D3DFMT_A4L4:
|
||||||
#if !defined(D3D_DISABLE_9EX)
|
#if !defined(D3D_DISABLE_9EX)
|
||||||
case D3DFMT_S8_LOCKABLE:
|
case D3DFMT_S8_LOCKABLE:
|
||||||
#endif
|
#endif
|
||||||
return 8;
|
return 8;
|
||||||
|
|
||||||
case D3DFMT_DXT1:
|
case D3DFMT_DXT1:
|
||||||
@ -374,10 +374,10 @@ namespace
|
|||||||
case MAKEFOURCC('Y', 'V', '1', '2'):
|
case MAKEFOURCC('Y', 'V', '1', '2'):
|
||||||
return 12;
|
return 12;
|
||||||
|
|
||||||
#if !defined(D3D_DISABLE_9EX)
|
#if !defined(D3D_DISABLE_9EX)
|
||||||
case D3DFMT_A1:
|
case D3DFMT_A1:
|
||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
@ -483,13 +483,13 @@ namespace
|
|||||||
numBytes = rowBytes * height;
|
numBytes = rowBytes * height;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
#if defined(_M_IX86) || defined(_M_ARM) || defined(_M_HYBRID_X86_ARM64)
|
||||||
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
static_assert(sizeof(size_t) == 4, "Not a 32-bit platform!");
|
||||||
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX)
|
||||||
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
|
||||||
#else
|
#else
|
||||||
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (outNumBytes)
|
if (outNumBytes)
|
||||||
{
|
{
|
||||||
@ -513,7 +513,7 @@ namespace
|
|||||||
|
|
||||||
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
|
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
|
||||||
{
|
{
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
HRESULT hr = CoCreateInstance(
|
HRESULT hr = CoCreateInstance(
|
||||||
CLSID_WICImagingFactory2,
|
CLSID_WICImagingFactory2,
|
||||||
nullptr,
|
nullptr,
|
||||||
@ -539,14 +539,14 @@ namespace
|
|||||||
);
|
);
|
||||||
return SUCCEEDED(hr) ? TRUE : FALSE;
|
return SUCCEEDED(hr) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return SUCCEEDED(CoCreateInstance(
|
return SUCCEEDED(CoCreateInstance(
|
||||||
CLSID_WICImagingFactory,
|
CLSID_WICImagingFactory,
|
||||||
nullptr,
|
nullptr,
|
||||||
CLSCTX_INPROC_SERVER,
|
CLSCTX_INPROC_SERVER,
|
||||||
__uuidof(IWICImagingFactory),
|
__uuidof(IWICImagingFactory),
|
||||||
ifactory)) ? TRUE : FALSE;
|
ifactory)) ? TRUE : FALSE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
IWICImagingFactory* GetWIC()
|
IWICImagingFactory* GetWIC()
|
||||||
@ -795,14 +795,14 @@ HRESULT DirectX::SaveWICTextureToFile(
|
|||||||
case D3DFMT_R32F: pfGuid = GUID_WICPixelFormat32bppGrayFloat; break;
|
case D3DFMT_R32F: pfGuid = GUID_WICPixelFormat32bppGrayFloat; break;
|
||||||
case D3DFMT_A32B32G32R32F: pfGuid = GUID_WICPixelFormat128bppRGBAFloat; break;
|
case D3DFMT_A32B32G32R32F: pfGuid = GUID_WICPixelFormat128bppRGBAFloat; break;
|
||||||
|
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
case D3DFMT_X8B8G8R8:
|
case D3DFMT_X8B8G8R8:
|
||||||
if (g_WIC2)
|
if (g_WIC2)
|
||||||
pfGuid = GUID_WICPixelFormat32bppRGB;
|
pfGuid = GUID_WICPixelFormat32bppRGB;
|
||||||
else
|
else
|
||||||
HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
|
||||||
@ -874,7 +874,7 @@ HRESULT DirectX::SaveWICTextureToFile(
|
|||||||
// Screenshots don't typically include the alpha channel of the render target
|
// 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)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
case D3DFMT_A32B32G32R32F:
|
case D3DFMT_A32B32G32R32F:
|
||||||
case D3DFMT_A16B16G16R16F:
|
case D3DFMT_A16B16G16R16F:
|
||||||
if (g_WIC2)
|
if (g_WIC2)
|
||||||
@ -886,7 +886,7 @@ HRESULT DirectX::SaveWICTextureToFile(
|
|||||||
targetGuid = GUID_WICPixelFormat24bppBGR;
|
targetGuid = GUID_WICPixelFormat24bppBGR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case D3DFMT_A16B16G16R16: targetGuid = GUID_WICPixelFormat48bppBGR; break;
|
case D3DFMT_A16B16G16R16: targetGuid = GUID_WICPixelFormat48bppBGR; break;
|
||||||
case D3DFMT_R5G6B5: targetGuid = GUID_WICPixelFormat16bppBGR565; break;
|
case D3DFMT_R5G6B5: targetGuid = GUID_WICPixelFormat16bppBGR565; break;
|
||||||
|
@ -686,9 +686,9 @@ namespace
|
|||||||
|
|
||||||
wprintf(L"Microsoft (R) DirectX Texture Assembler [DirectXTex] Version %ls\n", version);
|
wprintf(L"Microsoft (R) DirectX Texture Assembler [DirectXTex] Version %ls\n", version);
|
||||||
wprintf(L"Copyright (C) Microsoft Corp.\n");
|
wprintf(L"Copyright (C) Microsoft Corp.\n");
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
wprintf(L"*** Debug build ***\n");
|
wprintf(L"*** Debug build ***\n");
|
||||||
#endif
|
#endif
|
||||||
wprintf(L"\n");
|
wprintf(L"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,20 +785,20 @@ namespace
|
|||||||
case CODEC_HDR:
|
case CODEC_HDR:
|
||||||
return SaveToHDRFile(img, szOutputFile);
|
return SaveToHDRFile(img, szOutputFile);
|
||||||
|
|
||||||
#ifdef USE_OPENEXR
|
#ifdef USE_OPENEXR
|
||||||
case CODEC_EXR:
|
case CODEC_EXR:
|
||||||
return SaveToEXRFile(img, szOutputFile);
|
return SaveToEXRFile(img, szOutputFile);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
|
||||||
HRESULT hr = SaveToWICFile(img, WIC_FLAGS_NONE, GetWICCodec(static_cast<WICCodecs>(fileType)), szOutputFile);
|
|
||||||
if ((hr == static_cast<HRESULT>(0xc00d5212) /* MF_E_TOPO_CODEC_NOT_FOUND */) && (fileType == WIC_CODEC_HEIF))
|
|
||||||
{
|
{
|
||||||
wprintf(L"\nINFO: This format requires installing the HEIF Image Extensions - https://aka.ms/heif\n");
|
HRESULT hr = SaveToWICFile(img, WIC_FLAGS_NONE, GetWICCodec(static_cast<WICCodecs>(fileType)), szOutputFile);
|
||||||
|
if ((hr == static_cast<HRESULT>(0xc00d5212) /* MF_E_TOPO_CODEC_NOT_FOUND */) && (fileType == WIC_CODEC_HEIF))
|
||||||
|
{
|
||||||
|
wprintf(L"\nINFO: This format requires installing the HEIF Image Extensions - https://aka.ms/heif\n");
|
||||||
|
}
|
||||||
|
return hr;
|
||||||
}
|
}
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1113,33 +1113,33 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OPT_OUTPUTFILE:
|
case OPT_OUTPUTFILE:
|
||||||
{
|
|
||||||
wcscpy_s(szOutputFile, MAX_PATH, pValue);
|
|
||||||
|
|
||||||
wchar_t ext[_MAX_EXT] = {};
|
|
||||||
_wsplitpath_s(szOutputFile, nullptr, 0, nullptr, 0, nullptr, 0, ext, _MAX_EXT);
|
|
||||||
|
|
||||||
fileType = LookupByName(ext, g_pExtFileTypes);
|
|
||||||
|
|
||||||
switch (dwCommand)
|
|
||||||
{
|
{
|
||||||
case CMD_H_CROSS:
|
wcscpy_s(szOutputFile, MAX_PATH, pValue);
|
||||||
case CMD_V_CROSS:
|
|
||||||
case CMD_H_STRIP:
|
|
||||||
case CMD_V_STRIP:
|
|
||||||
case CMD_MERGE:
|
|
||||||
case CMD_ARRAY_STRIP:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
wchar_t ext[_MAX_EXT] = {};
|
||||||
if (fileType != CODEC_DDS)
|
_wsplitpath_s(szOutputFile, nullptr, 0, nullptr, 0, nullptr, 0, ext, _MAX_EXT);
|
||||||
|
|
||||||
|
fileType = LookupByName(ext, g_pExtFileTypes);
|
||||||
|
|
||||||
|
switch (dwCommand)
|
||||||
{
|
{
|
||||||
wprintf(L"Assembled output file must be a dds\n");
|
case CMD_H_CROSS:
|
||||||
return 1;
|
case CMD_V_CROSS:
|
||||||
|
case CMD_H_STRIP:
|
||||||
|
case CMD_V_STRIP:
|
||||||
|
case CMD_MERGE:
|
||||||
|
case CMD_ARRAY_STRIP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (fileType != CODEC_DDS)
|
||||||
|
{
|
||||||
|
wprintf(L"Assembled output file must be a dds\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case OPT_TA_WRAP:
|
case OPT_TA_WRAP:
|
||||||
if (dwFilterOpts & TEX_FILTER_MIRROR)
|
if (dwFilterOpts & TEX_FILTER_MIRROR)
|
||||||
@ -1162,19 +1162,19 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OPT_FILELIST:
|
case OPT_FILELIST:
|
||||||
{
|
|
||||||
std::wifstream inFile(pValue);
|
|
||||||
if (!inFile)
|
|
||||||
{
|
{
|
||||||
wprintf(L"Error opening -flist file %ls\n", pValue);
|
std::wifstream inFile(pValue);
|
||||||
return 1;
|
if (!inFile)
|
||||||
|
{
|
||||||
|
wprintf(L"Error opening -flist file %ls\n", pValue);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inFile.imbue(std::locale::classic());
|
||||||
|
|
||||||
|
ProcessFileList(inFile, conversion);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
inFile.imbue(std::locale::classic());
|
|
||||||
|
|
||||||
ProcessFileList(inFile, conversion);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OPT_FEATURE_LEVEL:
|
case OPT_FEATURE_LEVEL:
|
||||||
maxSize = LookupByName(pValue, g_pFeatureLevels);
|
maxSize = LookupByName(pValue, g_pFeatureLevels);
|
||||||
@ -1458,7 +1458,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef USE_OPENEXR
|
#ifdef USE_OPENEXR
|
||||||
else if (_wcsicmp(ext, L".exr") == 0)
|
else if (_wcsicmp(ext, L".exr") == 0)
|
||||||
{
|
{
|
||||||
hr = LoadFromEXRFile(pConv->szSrc, &info, *image);
|
hr = LoadFromEXRFile(pConv->szSrc, &info, *image);
|
||||||
@ -1468,7 +1468,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// WIC shares the same filter values for mode and dither
|
// WIC shares the same filter values for mode and dither
|
||||||
@ -1779,9 +1779,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto& tinfo = timage->GetMetadata();
|
auto& tinfo = timage->GetMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(info.width == tinfo.width);
|
assert(info.width == tinfo.width);
|
||||||
assert(info.height == tinfo.height);
|
assert(info.height == tinfo.height);
|
||||||
@ -1879,402 +1879,402 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
case CMD_V_CROSS:
|
case CMD_V_CROSS:
|
||||||
case CMD_H_STRIP:
|
case CMD_H_STRIP:
|
||||||
case CMD_V_STRIP:
|
case CMD_V_STRIP:
|
||||||
{
|
|
||||||
size_t twidth = 0;
|
|
||||||
size_t theight = 0;
|
|
||||||
|
|
||||||
switch (dwCommand)
|
|
||||||
{
|
{
|
||||||
case CMD_H_CROSS:
|
size_t twidth = 0;
|
||||||
// posy
|
size_t theight = 0;
|
||||||
// negx posz posx negz
|
|
||||||
// negy
|
|
||||||
twidth = width * 4;
|
|
||||||
theight = height * 3;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_V_CROSS:
|
|
||||||
// posy
|
|
||||||
// posz posx negz
|
|
||||||
// negy
|
|
||||||
// negx
|
|
||||||
twidth = width * 3;
|
|
||||||
theight = height * 4;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_H_STRIP:
|
|
||||||
twidth = width * 6;
|
|
||||||
theight = height;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_V_STRIP:
|
|
||||||
twidth = width;
|
|
||||||
theight = height * 6;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScratchImage result;
|
|
||||||
hr = result.Initialize2D(format, twidth, theight, 1, 1);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
wprintf(L"FAILED setting up result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(result.GetPixels(), 0, result.GetPixelsSize());
|
|
||||||
|
|
||||||
auto src = loadedImages.cbegin();
|
|
||||||
auto dest = result.GetImage(0, 0, 0);
|
|
||||||
|
|
||||||
for (size_t index = 0; index < 6; ++index)
|
|
||||||
{
|
|
||||||
auto img = (*src)->GetImage(0, index, 0);
|
|
||||||
if (!img)
|
|
||||||
{
|
|
||||||
wprintf(L"FAILED: Unexpected error\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Rect rect(0, 0, width, height);
|
|
||||||
|
|
||||||
size_t offsetx = 0;
|
|
||||||
size_t offsety = 0;
|
|
||||||
|
|
||||||
switch (dwCommand)
|
switch (dwCommand)
|
||||||
{
|
{
|
||||||
case CMD_H_CROSS:
|
case CMD_H_CROSS:
|
||||||
{
|
|
||||||
// posy
|
// posy
|
||||||
// negx posz posx negz
|
// negx posz posx negz
|
||||||
// negy
|
// negy
|
||||||
|
twidth = width * 4;
|
||||||
static const size_t s_offsetx[6] = { 2, 0, 1, 1, 1, 3 };
|
theight = height * 3;
|
||||||
static const size_t s_offsety[6] = { 1, 1, 0, 2, 1, 1 };
|
|
||||||
|
|
||||||
offsetx = s_offsetx[index] * width;
|
|
||||||
offsety = s_offsety[index] * height;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case CMD_V_CROSS:
|
case CMD_V_CROSS:
|
||||||
{
|
|
||||||
// posy
|
// posy
|
||||||
// posz posx negz
|
// posz posx negz
|
||||||
// negy
|
// negy
|
||||||
// negx
|
// negx
|
||||||
|
twidth = width * 3;
|
||||||
static const size_t s_offsetx[6] = { 1, 1, 1, 1, 0, 2 };
|
theight = height * 4;
|
||||||
static const size_t s_offsety[6] = { 1, 3, 0, 2, 1, 1 };
|
|
||||||
|
|
||||||
offsetx = s_offsetx[index] * width;
|
|
||||||
offsety = s_offsety[index] * height;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case CMD_H_STRIP:
|
case CMD_H_STRIP:
|
||||||
// posx, negx, posy, negy, posz, negz
|
twidth = width * 6;
|
||||||
offsetx = index * width;
|
theight = height;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_V_STRIP:
|
case CMD_V_STRIP:
|
||||||
// posx, negx, posy, negy, posz, negz
|
twidth = width;
|
||||||
offsety = index * height;
|
theight = height * 6;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = CopyRectangle(*img, rect, *dest, dwFilter | dwFilterOpts, offsetx, offsety);
|
ScratchImage result;
|
||||||
|
hr = result.Initialize2D(format, twidth, theight, 1, 1);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
wprintf(L"FAILED building result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
wprintf(L"FAILED setting up result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Write cross/strip
|
memset(result.GetPixels(), 0, result.GetPixelsSize());
|
||||||
wprintf(L"\nWriting %ls ", szOutputFile);
|
|
||||||
PrintInfo(result.GetMetadata());
|
|
||||||
wprintf(L"\n");
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
if (dwOptions & (1 << OPT_TOLOWER))
|
auto src = loadedImages.cbegin();
|
||||||
{
|
auto dest = result.GetImage(0, 0, 0);
|
||||||
std::ignore = _wcslwr_s(szOutputFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (~dwOptions & (1 << OPT_OVERWRITE))
|
for (size_t index = 0; index < 6; ++index)
|
||||||
{
|
|
||||||
if (GetFileAttributesW(szOutputFile) != INVALID_FILE_ATTRIBUTES)
|
|
||||||
{
|
{
|
||||||
wprintf(L"\nERROR: Output file already exists, use -y to overwrite\n");
|
auto img = (*src)->GetImage(0, index, 0);
|
||||||
|
if (!img)
|
||||||
|
{
|
||||||
|
wprintf(L"FAILED: Unexpected error\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Rect rect(0, 0, width, height);
|
||||||
|
|
||||||
|
size_t offsetx = 0;
|
||||||
|
size_t offsety = 0;
|
||||||
|
|
||||||
|
switch (dwCommand)
|
||||||
|
{
|
||||||
|
case CMD_H_CROSS:
|
||||||
|
{
|
||||||
|
// posy
|
||||||
|
// negx posz posx negz
|
||||||
|
// negy
|
||||||
|
|
||||||
|
static const size_t s_offsetx[6] = { 2, 0, 1, 1, 1, 3 };
|
||||||
|
static const size_t s_offsety[6] = { 1, 1, 0, 2, 1, 1 };
|
||||||
|
|
||||||
|
offsetx = s_offsetx[index] * width;
|
||||||
|
offsety = s_offsety[index] * height;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CMD_V_CROSS:
|
||||||
|
{
|
||||||
|
// posy
|
||||||
|
// posz posx negz
|
||||||
|
// negy
|
||||||
|
// negx
|
||||||
|
|
||||||
|
static const size_t s_offsetx[6] = { 1, 1, 1, 1, 0, 2 };
|
||||||
|
static const size_t s_offsety[6] = { 1, 3, 0, 2, 1, 1 };
|
||||||
|
|
||||||
|
offsetx = s_offsetx[index] * width;
|
||||||
|
offsety = s_offsety[index] * height;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CMD_H_STRIP:
|
||||||
|
// posx, negx, posy, negy, posz, negz
|
||||||
|
offsetx = index * width;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_V_STRIP:
|
||||||
|
// posx, negx, posy, negy, posz, negz
|
||||||
|
offsety = index * height;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = CopyRectangle(*img, rect, *dest, dwFilter | dwFilterOpts, offsetx, offsety);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
wprintf(L"FAILED building result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write cross/strip
|
||||||
|
wprintf(L"\nWriting %ls ", szOutputFile);
|
||||||
|
PrintInfo(result.GetMetadata());
|
||||||
|
wprintf(L"\n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
if (dwOptions & (1 << OPT_TOLOWER))
|
||||||
|
{
|
||||||
|
std::ignore = _wcslwr_s(szOutputFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (~dwOptions & (1 << OPT_OVERWRITE))
|
||||||
|
{
|
||||||
|
if (GetFileAttributesW(szOutputFile) != INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
wprintf(L"\nERROR: Output file already exists, use -y to overwrite\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = SaveImageFile(*dest, fileType, szOutputFile);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = SaveImageFile(*dest, fileType, szOutputFile);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case CMD_MERGE:
|
case CMD_MERGE:
|
||||||
{
|
|
||||||
// Capture data from our second source image
|
|
||||||
ScratchImage tempImage;
|
|
||||||
hr = Convert(*loadedImages[1]->GetImage(0, 0, 0), DXGI_FORMAT_R32G32B32A32_FLOAT,
|
|
||||||
dwFilter | dwFilterOpts | dwSRGB, TEX_THRESHOLD_DEFAULT, tempImage);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
wprintf(L" FAILED [convert second input] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
// Capture data from our second source image
|
||||||
return 1;
|
ScratchImage tempImage;
|
||||||
}
|
hr = Convert(*loadedImages[1]->GetImage(0, 0, 0), DXGI_FORMAT_R32G32B32A32_FLOAT,
|
||||||
|
dwFilter | dwFilterOpts | dwSRGB, TEX_THRESHOLD_DEFAULT, tempImage);
|
||||||
const Image& img = *tempImage.GetImage(0, 0, 0);
|
if (FAILED(hr))
|
||||||
|
|
||||||
// Merge with our first source image
|
|
||||||
const Image& rgb = *loadedImages[0]->GetImage(0, 0, 0);
|
|
||||||
|
|
||||||
const XMVECTOR zc = XMVectorSelectControl(zeroElements[0], zeroElements[1], zeroElements[2], zeroElements[3]);
|
|
||||||
const XMVECTOR oc = XMVectorSelectControl(oneElements[0], oneElements[1], oneElements[2], oneElements[3]);
|
|
||||||
|
|
||||||
ScratchImage result;
|
|
||||||
hr = TransformImage(rgb, [&, zc, oc](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR *inPixels2 = reinterpret_cast<XMVECTOR*>(img.pixels + img.rowPitch * y);
|
wprintf(L" FAILED [convert second input] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
|
|
||||||
for (size_t j = 0; j < w; ++j)
|
|
||||||
{
|
|
||||||
XMVECTOR pixel = XMVectorPermute(inPixels[j], inPixels2[j],
|
|
||||||
permuteElements[0], permuteElements[1], permuteElements[2], permuteElements[3]);
|
|
||||||
pixel = XMVectorSelect(pixel, g_XMZero, zc);
|
|
||||||
outPixels[j] = XMVectorSelect(pixel, g_XMOne, oc);
|
|
||||||
}
|
|
||||||
}, result);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
wprintf(L" FAILED [merge image] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write merged texture
|
|
||||||
wprintf(L"\nWriting %ls ", szOutputFile);
|
|
||||||
PrintInfo(result.GetMetadata());
|
|
||||||
wprintf(L"\n");
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
if (dwOptions & (1 << OPT_TOLOWER))
|
|
||||||
{
|
|
||||||
std::ignore = _wcslwr_s(szOutputFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (~dwOptions & (1 << OPT_OVERWRITE))
|
|
||||||
{
|
|
||||||
if (GetFileAttributesW(szOutputFile) != INVALID_FILE_ATTRIBUTES)
|
|
||||||
{
|
|
||||||
wprintf(L"\nERROR: Output file already exists, use -y to overwrite\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
hr = SaveImageFile(*result.GetImage(0, 0, 0), fileType, szOutputFile);
|
const Image& img = *tempImage.GetImage(0, 0, 0);
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
// Merge with our first source image
|
||||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
const Image& rgb = *loadedImages[0]->GetImage(0, 0, 0);
|
||||||
return 1;
|
|
||||||
|
const XMVECTOR zc = XMVectorSelectControl(zeroElements[0], zeroElements[1], zeroElements[2], zeroElements[3]);
|
||||||
|
const XMVECTOR oc = XMVectorSelectControl(oneElements[0], oneElements[1], oneElements[2], oneElements[3]);
|
||||||
|
|
||||||
|
ScratchImage result;
|
||||||
|
hr = TransformImage(rgb, [&, zc, oc](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
|
||||||
|
{
|
||||||
|
const XMVECTOR *inPixels2 = reinterpret_cast<XMVECTOR*>(img.pixels + img.rowPitch * y);
|
||||||
|
|
||||||
|
for (size_t j = 0; j < w; ++j)
|
||||||
|
{
|
||||||
|
XMVECTOR pixel = XMVectorPermute(inPixels[j], inPixels2[j],
|
||||||
|
permuteElements[0], permuteElements[1], permuteElements[2], permuteElements[3]);
|
||||||
|
pixel = XMVectorSelect(pixel, g_XMZero, zc);
|
||||||
|
outPixels[j] = XMVectorSelect(pixel, g_XMOne, oc);
|
||||||
|
}
|
||||||
|
}, result);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
wprintf(L" FAILED [merge image] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write merged texture
|
||||||
|
wprintf(L"\nWriting %ls ", szOutputFile);
|
||||||
|
PrintInfo(result.GetMetadata());
|
||||||
|
wprintf(L"\n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
if (dwOptions & (1 << OPT_TOLOWER))
|
||||||
|
{
|
||||||
|
std::ignore = _wcslwr_s(szOutputFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (~dwOptions & (1 << OPT_OVERWRITE))
|
||||||
|
{
|
||||||
|
if (GetFileAttributesW(szOutputFile) != INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
wprintf(L"\nERROR: Output file already exists, use -y to overwrite\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = SaveImageFile(*result.GetImage(0, 0, 0), fileType, szOutputFile);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case CMD_ARRAY_STRIP:
|
case CMD_ARRAY_STRIP:
|
||||||
{
|
|
||||||
const size_t twidth = width;
|
|
||||||
const size_t theight = height * images;
|
|
||||||
|
|
||||||
ScratchImage result;
|
|
||||||
hr = result.Initialize2D(format, twidth, theight, 1, 1);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
wprintf(L"FAILED setting up result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
const size_t twidth = width;
|
||||||
return 1;
|
const size_t theight = height * images;
|
||||||
}
|
|
||||||
|
|
||||||
memset(result.GetPixels(), 0, result.GetPixelsSize());
|
ScratchImage result;
|
||||||
|
hr = result.Initialize2D(format, twidth, theight, 1, 1);
|
||||||
auto src = loadedImages.cbegin();
|
if (FAILED(hr))
|
||||||
auto dest = result.GetImage(0, 0, 0);
|
|
||||||
|
|
||||||
for (size_t index = 0; index < images; ++index)
|
|
||||||
{
|
|
||||||
auto img = (*src)->GetImage(0, index, 0);
|
|
||||||
if (!img)
|
|
||||||
{
|
{
|
||||||
wprintf(L"FAILED: Unexpected error\n");
|
wprintf(L"FAILED setting up result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Rect rect(0, 0, width, height);
|
memset(result.GetPixels(), 0, result.GetPixelsSize());
|
||||||
|
|
||||||
constexpr size_t offsetx = 0;
|
auto src = loadedImages.cbegin();
|
||||||
size_t offsety = 0;
|
auto dest = result.GetImage(0, 0, 0);
|
||||||
|
|
||||||
offsety = index * height;
|
for (size_t index = 0; index < images; ++index)
|
||||||
|
{
|
||||||
|
auto img = (*src)->GetImage(0, index, 0);
|
||||||
|
if (!img)
|
||||||
|
{
|
||||||
|
wprintf(L"FAILED: Unexpected error\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Rect rect(0, 0, width, height);
|
||||||
|
|
||||||
|
constexpr size_t offsetx = 0;
|
||||||
|
size_t offsety = 0;
|
||||||
|
|
||||||
|
offsety = index * height;
|
||||||
|
|
||||||
|
hr = CopyRectangle(*img, rect, *dest, dwFilter | dwFilterOpts, offsetx, offsety);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
wprintf(L"FAILED building result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write array strip
|
||||||
|
wprintf(L"\nWriting %ls ", szOutputFile);
|
||||||
|
PrintInfo(result.GetMetadata());
|
||||||
|
wprintf(L"\n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
if (dwOptions & (1 << OPT_TOLOWER))
|
||||||
|
{
|
||||||
|
std::ignore = _wcslwr_s(szOutputFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (~dwOptions & (1 << OPT_OVERWRITE))
|
||||||
|
{
|
||||||
|
if (GetFileAttributesW(szOutputFile) != INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
wprintf(L"\nERROR: Output file already exists, use -y to overwrite\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = SaveImageFile(*dest, fileType, szOutputFile);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
std::vector<Image> imageArray;
|
||||||
|
imageArray.reserve(images);
|
||||||
|
|
||||||
|
for (auto it = loadedImages.cbegin(); it != loadedImages.cend(); ++it)
|
||||||
|
{
|
||||||
|
const ScratchImage* simage = it->get();
|
||||||
|
assert(simage != nullptr);
|
||||||
|
for (size_t j = 0; j < simage->GetMetadata().arraySize; ++j)
|
||||||
|
{
|
||||||
|
const Image* img = simage->GetImage(0, j, 0);
|
||||||
|
assert(img != nullptr);
|
||||||
|
imageArray.push_back(*img);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (dwCommand)
|
||||||
|
{
|
||||||
|
case CMD_CUBE:
|
||||||
|
if (imageArray[0].width > maxCube || imageArray[0].height > maxCube)
|
||||||
|
{
|
||||||
|
wprintf(L"\nWARNING: Target size exceeds maximum cube dimensions for feature level (%u)\n", maxCube);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_VOLUME:
|
||||||
|
if (imageArray[0].width > maxVolume || imageArray[0].height > maxVolume || imageArray.size() > maxVolume)
|
||||||
|
{
|
||||||
|
wprintf(L"\nWARNING: Target size exceeds volume extent for feature level (%u)\n", maxVolume);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_ARRAY:
|
||||||
|
if (imageArray[0].width > maxSize || imageArray[0].height > maxSize || imageArray.size() > maxArray)
|
||||||
|
{
|
||||||
|
wprintf(L"\nWARNING: Target size exceeds maximum size for feature level (size %u, array %u)\n", maxSize, maxArray);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_CUBEARRAY:
|
||||||
|
if (imageArray[0].width > maxCube || imageArray[0].height > maxCube || imageArray.size() > maxArray)
|
||||||
|
{
|
||||||
|
wprintf(L"\nWARNING: Target size exceeds maximum cube dimensions for feature level (size %u, array %u)\n", maxCube, maxArray);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (imageArray[0].width > maxSize || imageArray[0].height > maxSize)
|
||||||
|
{
|
||||||
|
wprintf(L"\nWARNING: Target size exceeds maximum size for feature level (%u)\n", maxSize);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScratchImage result;
|
||||||
|
switch (dwCommand)
|
||||||
|
{
|
||||||
|
case CMD_VOLUME:
|
||||||
|
hr = result.Initialize3DFromImages(&imageArray[0], imageArray.size());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_ARRAY:
|
||||||
|
case CMD_GIF:
|
||||||
|
hr = result.InitializeArrayFromImages(&imageArray[0], imageArray.size(), (dwOptions & (1 << OPT_USE_DX10)) != 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_CUBE:
|
||||||
|
case CMD_CUBEARRAY:
|
||||||
|
hr = result.InitializeCubeFromImages(&imageArray[0], imageArray.size());
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
hr = CopyRectangle(*img, rect, *dest, dwFilter | dwFilterOpts, offsetx, offsety);
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
wprintf(L"FAILED building result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
wprintf(L"FAILED building result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Write array strip
|
// Write texture
|
||||||
wprintf(L"\nWriting %ls ", szOutputFile);
|
wprintf(L"\nWriting %ls ", szOutputFile);
|
||||||
PrintInfo(result.GetMetadata());
|
PrintInfo(result.GetMetadata());
|
||||||
wprintf(L"\n");
|
wprintf(L"\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (dwOptions & (1 << OPT_TOLOWER))
|
if (dwOptions & (1 << OPT_TOLOWER))
|
||||||
{
|
|
||||||
std::ignore = _wcslwr_s(szOutputFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (~dwOptions & (1 << OPT_OVERWRITE))
|
|
||||||
{
|
|
||||||
if (GetFileAttributesW(szOutputFile) != INVALID_FILE_ATTRIBUTES)
|
|
||||||
{
|
{
|
||||||
wprintf(L"\nERROR: Output file already exists, use -y to overwrite\n");
|
std::ignore = _wcslwr_s(szOutputFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (~dwOptions & (1 << OPT_OVERWRITE))
|
||||||
|
{
|
||||||
|
if (GetFileAttributesW(szOutputFile) != INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
wprintf(L"\nERROR: Output file already exists, use -y to overwrite\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = SaveToDDSFile(result.GetImages(), result.GetImageCount(), result.GetMetadata(),
|
||||||
|
(dwOptions & (1 << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE,
|
||||||
|
szOutputFile);
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
wprintf(L"\nFAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
hr = SaveImageFile(*dest, fileType, szOutputFile);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
std::vector<Image> imageArray;
|
|
||||||
imageArray.reserve(images);
|
|
||||||
|
|
||||||
for (auto it = loadedImages.cbegin(); it != loadedImages.cend(); ++it)
|
|
||||||
{
|
|
||||||
const ScratchImage* simage = it->get();
|
|
||||||
assert(simage != nullptr);
|
|
||||||
for (size_t j = 0; j < simage->GetMetadata().arraySize; ++j)
|
|
||||||
{
|
|
||||||
const Image* img = simage->GetImage(0, j, 0);
|
|
||||||
assert(img != nullptr);
|
|
||||||
imageArray.push_back(*img);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (dwCommand)
|
|
||||||
{
|
|
||||||
case CMD_CUBE:
|
|
||||||
if (imageArray[0].width > maxCube || imageArray[0].height > maxCube)
|
|
||||||
{
|
|
||||||
wprintf(L"\nWARNING: Target size exceeds maximum cube dimensions for feature level (%u)\n", maxCube);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_VOLUME:
|
|
||||||
if (imageArray[0].width > maxVolume || imageArray[0].height > maxVolume || imageArray.size() > maxVolume)
|
|
||||||
{
|
|
||||||
wprintf(L"\nWARNING: Target size exceeds volume extent for feature level (%u)\n", maxVolume);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_ARRAY:
|
|
||||||
if (imageArray[0].width > maxSize || imageArray[0].height > maxSize || imageArray.size() > maxArray)
|
|
||||||
{
|
|
||||||
wprintf(L"\nWARNING: Target size exceeds maximum size for feature level (size %u, array %u)\n", maxSize, maxArray);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_CUBEARRAY:
|
|
||||||
if (imageArray[0].width > maxCube || imageArray[0].height > maxCube || imageArray.size() > maxArray)
|
|
||||||
{
|
|
||||||
wprintf(L"\nWARNING: Target size exceeds maximum cube dimensions for feature level (size %u, array %u)\n", maxCube, maxArray);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (imageArray[0].width > maxSize || imageArray[0].height > maxSize)
|
|
||||||
{
|
|
||||||
wprintf(L"\nWARNING: Target size exceeds maximum size for feature level (%u)\n", maxSize);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScratchImage result;
|
|
||||||
switch (dwCommand)
|
|
||||||
{
|
|
||||||
case CMD_VOLUME:
|
|
||||||
hr = result.Initialize3DFromImages(&imageArray[0], imageArray.size());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_ARRAY:
|
|
||||||
case CMD_GIF:
|
|
||||||
hr = result.InitializeArrayFromImages(&imageArray[0], imageArray.size(), (dwOptions & (1 << OPT_USE_DX10)) != 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CMD_CUBE:
|
|
||||||
case CMD_CUBEARRAY:
|
|
||||||
hr = result.InitializeCubeFromImages(&imageArray[0], imageArray.size());
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
wprintf(L"FAILED building result image (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write texture
|
|
||||||
wprintf(L"\nWriting %ls ", szOutputFile);
|
|
||||||
PrintInfo(result.GetMetadata());
|
|
||||||
wprintf(L"\n");
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
if (dwOptions & (1 << OPT_TOLOWER))
|
|
||||||
{
|
|
||||||
std::ignore = _wcslwr_s(szOutputFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (~dwOptions & (1 << OPT_OVERWRITE))
|
|
||||||
{
|
|
||||||
if (GetFileAttributesW(szOutputFile) != INVALID_FILE_ATTRIBUTES)
|
|
||||||
{
|
|
||||||
wprintf(L"\nERROR: Output file already exists, use -y to overwrite\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = SaveToDDSFile(result.GetImages(), result.GetImageCount(), result.GetMetadata(),
|
|
||||||
(dwOptions & (1 << OPT_USE_DX10)) ? (DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2) : DDS_FLAGS_NONE,
|
|
||||||
szOutputFile);
|
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
|
||||||
wprintf(L"\nFAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -45,12 +45,12 @@ namespace
|
|||||||
{
|
{
|
||||||
blob.reset();
|
blob.reset();
|
||||||
|
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||||
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
|
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
|
||||||
#else
|
#else
|
||||||
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
|
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
|
||||||
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
|
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
|
||||||
#endif
|
#endif
|
||||||
if (!hFile)
|
if (!hFile)
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
|
@ -82,12 +82,12 @@ namespace
|
|||||||
{
|
{
|
||||||
blob.reset();
|
blob.reset();
|
||||||
|
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
|
||||||
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
|
ScopedHandle hFile(safe_handle(CreateFile2(szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr)));
|
||||||
#else
|
#else
|
||||||
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
|
ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
|
||||||
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
|
FILE_FLAG_SEQUENTIAL_SCAN, nullptr)));
|
||||||
#endif
|
#endif
|
||||||
if (!hFile)
|
if (!hFile)
|
||||||
{
|
{
|
||||||
return HRESULT_FROM_WIN32(GetLastError());
|
return HRESULT_FROM_WIN32(GetLastError());
|
||||||
@ -257,30 +257,30 @@ HRESULT __cdecl LoadFromPortablePixMap(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PPM_HEIGHT:
|
case PPM_HEIGHT:
|
||||||
{
|
|
||||||
if (u == 0)
|
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
if (metadata)
|
|
||||||
{
|
{
|
||||||
*metadata = {};
|
if (u == 0)
|
||||||
metadata->width = width;
|
return E_FAIL;
|
||||||
metadata->height = u;
|
|
||||||
metadata->depth = metadata->arraySize = metadata->mipLevels = 1;
|
if (metadata)
|
||||||
metadata->format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
{
|
||||||
metadata->dimension = TEX_DIMENSION_TEXTURE2D;
|
*metadata = {};
|
||||||
|
metadata->width = width;
|
||||||
|
metadata->height = u;
|
||||||
|
metadata->depth = metadata->arraySize = metadata->mipLevels = 1;
|
||||||
|
metadata->format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
metadata->dimension = TEX_DIMENSION_TEXTURE2D;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = image.Initialize2D(DXGI_FORMAT_R8G8B8A8_UNORM, width, u, 1, 1);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
auto img = image.GetImage(0, 0, 0);
|
||||||
|
|
||||||
|
pixels = reinterpret_cast<uint32_t*>(img->pixels);
|
||||||
|
pixelEnd = pixels + width * u;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
hr = image.Initialize2D(DXGI_FORMAT_R8G8B8A8_UNORM, width, u, 1, 1);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
auto img = image.GetImage(0, 0, 0);
|
|
||||||
|
|
||||||
pixels = reinterpret_cast<uint32_t*>(img->pixels);
|
|
||||||
pixelEnd = pixels + width * u;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PPM_MAX:
|
case PPM_MAX:
|
||||||
if (u == 0)
|
if (u == 0)
|
||||||
|
@ -839,9 +839,9 @@ namespace
|
|||||||
|
|
||||||
wprintf(L"Microsoft (R) DirectX Texture Converter [DirectXTex] Version %ls\n", version);
|
wprintf(L"Microsoft (R) DirectX Texture Converter [DirectXTex] Version %ls\n", version);
|
||||||
wprintf(L"Copyright (C) Microsoft Corp.\n");
|
wprintf(L"Copyright (C) Microsoft Corp.\n");
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
wprintf(L"*** Debug build ***\n");
|
wprintf(L"*** Debug build ***\n");
|
||||||
#endif
|
#endif
|
||||||
wprintf(L"\n");
|
wprintf(L"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -928,9 +928,9 @@ namespace
|
|||||||
wprintf(L" -wicmulti When writing images with WIC encode multiframe images\n");
|
wprintf(L" -wicmulti When writing images with WIC encode multiframe images\n");
|
||||||
wprintf(L"\n -nologo suppress copyright message\n");
|
wprintf(L"\n -nologo suppress copyright message\n");
|
||||||
wprintf(L" -timing Display elapsed processing time\n\n");
|
wprintf(L" -timing Display elapsed processing time\n\n");
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
wprintf(L" -singleproc Do not use multi-threaded compression\n");
|
wprintf(L" -singleproc Do not use multi-threaded compression\n");
|
||||||
#endif
|
#endif
|
||||||
wprintf(L" -gpu <adapter> Select GPU for DirectCompute-based codecs (0 is default)\n");
|
wprintf(L" -gpu <adapter> Select GPU for DirectCompute-based codecs (0 is default)\n");
|
||||||
wprintf(L" -nogpu Do not use DirectCompute-based codecs\n");
|
wprintf(L" -nogpu Do not use DirectCompute-based codecs\n");
|
||||||
wprintf(
|
wprintf(
|
||||||
@ -1043,9 +1043,9 @@ namespace
|
|||||||
};
|
};
|
||||||
|
|
||||||
UINT createDeviceFlags = 0;
|
UINT createDeviceFlags = 0;
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ComPtr<IDXGIAdapter> pAdapter;
|
ComPtr<IDXGIAdapter> pAdapter;
|
||||||
if (adapter >= 0)
|
if (adapter >= 0)
|
||||||
@ -1614,62 +1614,62 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OPT_NORMAL_MAP:
|
case OPT_NORMAL_MAP:
|
||||||
{
|
{
|
||||||
dwNormalMap = CNMAP_DEFAULT;
|
dwNormalMap = CNMAP_DEFAULT;
|
||||||
|
|
||||||
if (wcschr(pValue, L'l'))
|
if (wcschr(pValue, L'l'))
|
||||||
{
|
|
||||||
dwNormalMap |= CNMAP_CHANNEL_LUMINANCE;
|
|
||||||
}
|
|
||||||
else if (wcschr(pValue, L'r'))
|
|
||||||
{
|
|
||||||
dwNormalMap |= CNMAP_CHANNEL_RED;
|
|
||||||
}
|
|
||||||
else if (wcschr(pValue, L'g'))
|
|
||||||
{
|
|
||||||
dwNormalMap |= CNMAP_CHANNEL_GREEN;
|
|
||||||
}
|
|
||||||
else if (wcschr(pValue, L'b'))
|
|
||||||
{
|
|
||||||
dwNormalMap |= CNMAP_CHANNEL_BLUE;
|
|
||||||
}
|
|
||||||
else if (wcschr(pValue, L'a'))
|
|
||||||
{
|
|
||||||
dwNormalMap |= CNMAP_CHANNEL_ALPHA;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wprintf(L"Invalid value specified for -nmap (%ls), missing l, r, g, b, or a\n\n", pValue);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wcschr(pValue, L'm'))
|
|
||||||
{
|
|
||||||
dwNormalMap |= CNMAP_MIRROR;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (wcschr(pValue, L'u'))
|
|
||||||
{
|
{
|
||||||
dwNormalMap |= CNMAP_MIRROR_U;
|
dwNormalMap |= CNMAP_CHANNEL_LUMINANCE;
|
||||||
}
|
}
|
||||||
if (wcschr(pValue, L'v'))
|
else if (wcschr(pValue, L'r'))
|
||||||
{
|
{
|
||||||
dwNormalMap |= CNMAP_MIRROR_V;
|
dwNormalMap |= CNMAP_CHANNEL_RED;
|
||||||
|
}
|
||||||
|
else if (wcschr(pValue, L'g'))
|
||||||
|
{
|
||||||
|
dwNormalMap |= CNMAP_CHANNEL_GREEN;
|
||||||
|
}
|
||||||
|
else if (wcschr(pValue, L'b'))
|
||||||
|
{
|
||||||
|
dwNormalMap |= CNMAP_CHANNEL_BLUE;
|
||||||
|
}
|
||||||
|
else if (wcschr(pValue, L'a'))
|
||||||
|
{
|
||||||
|
dwNormalMap |= CNMAP_CHANNEL_ALPHA;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wprintf(L"Invalid value specified for -nmap (%ls), missing l, r, g, b, or a\n\n", pValue);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wcschr(pValue, L'm'))
|
||||||
|
{
|
||||||
|
dwNormalMap |= CNMAP_MIRROR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (wcschr(pValue, L'u'))
|
||||||
|
{
|
||||||
|
dwNormalMap |= CNMAP_MIRROR_U;
|
||||||
|
}
|
||||||
|
if (wcschr(pValue, L'v'))
|
||||||
|
{
|
||||||
|
dwNormalMap |= CNMAP_MIRROR_V;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wcschr(pValue, L'i'))
|
||||||
|
{
|
||||||
|
dwNormalMap |= CNMAP_INVERT_SIGN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wcschr(pValue, L'o'))
|
||||||
|
{
|
||||||
|
dwNormalMap |= CNMAP_COMPUTE_OCCLUSION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
if (wcschr(pValue, L'i'))
|
|
||||||
{
|
|
||||||
dwNormalMap |= CNMAP_INVERT_SIGN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wcschr(pValue, L'o'))
|
|
||||||
{
|
|
||||||
dwNormalMap |= CNMAP_COMPUTE_OCCLUSION;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OPT_NORMAL_MAP_AMPLITUDE:
|
case OPT_NORMAL_MAP_AMPLITUDE:
|
||||||
if (!dwNormalMap)
|
if (!dwNormalMap)
|
||||||
@ -1750,48 +1750,48 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OPT_BC_COMPRESS:
|
case OPT_BC_COMPRESS:
|
||||||
{
|
|
||||||
dwCompress = TEX_COMPRESS_DEFAULT;
|
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
if (wcschr(pValue, L'u'))
|
|
||||||
{
|
{
|
||||||
dwCompress |= TEX_COMPRESS_UNIFORM;
|
dwCompress = TEX_COMPRESS_DEFAULT;
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wcschr(pValue, L'd'))
|
bool found = false;
|
||||||
{
|
if (wcschr(pValue, L'u'))
|
||||||
dwCompress |= TEX_COMPRESS_DITHER;
|
{
|
||||||
found = true;
|
dwCompress |= TEX_COMPRESS_UNIFORM;
|
||||||
}
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (wcschr(pValue, L'q'))
|
if (wcschr(pValue, L'd'))
|
||||||
{
|
{
|
||||||
dwCompress |= TEX_COMPRESS_BC7_QUICK;
|
dwCompress |= TEX_COMPRESS_DITHER;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wcschr(pValue, L'x'))
|
if (wcschr(pValue, L'q'))
|
||||||
{
|
{
|
||||||
dwCompress |= TEX_COMPRESS_BC7_USE_3SUBSETS;
|
dwCompress |= TEX_COMPRESS_BC7_QUICK;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dwCompress & (TEX_COMPRESS_BC7_QUICK | TEX_COMPRESS_BC7_USE_3SUBSETS)) == (TEX_COMPRESS_BC7_QUICK | TEX_COMPRESS_BC7_USE_3SUBSETS))
|
if (wcschr(pValue, L'x'))
|
||||||
{
|
{
|
||||||
wprintf(L"Can't use -bc x (max) and -bc q (quick) at same time\n\n");
|
dwCompress |= TEX_COMPRESS_BC7_USE_3SUBSETS;
|
||||||
PrintUsage();
|
found = true;
|
||||||
return 1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
if ((dwCompress & (TEX_COMPRESS_BC7_QUICK | TEX_COMPRESS_BC7_USE_3SUBSETS)) == (TEX_COMPRESS_BC7_QUICK | TEX_COMPRESS_BC7_USE_3SUBSETS))
|
||||||
{
|
{
|
||||||
wprintf(L"Invalid value specified for -bc (%ls), missing d, u, q, or x\n\n", pValue);
|
wprintf(L"Can't use -bc x (max) and -bc q (quick) at same time\n\n");
|
||||||
return 1;
|
PrintUsage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
wprintf(L"Invalid value specified for -bc (%ls), missing d, u, q, or x\n\n", pValue);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case OPT_WIC_QUALITY:
|
case OPT_WIC_QUALITY:
|
||||||
if (swscanf_s(pValue, L"%f", &wicQuality) != 1
|
if (swscanf_s(pValue, L"%f", &wicQuality) != 1
|
||||||
@ -1856,19 +1856,19 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OPT_FILELIST:
|
case OPT_FILELIST:
|
||||||
{
|
|
||||||
std::wifstream inFile(pValue);
|
|
||||||
if (!inFile)
|
|
||||||
{
|
{
|
||||||
wprintf(L"Error opening -flist file %ls\n", pValue);
|
std::wifstream inFile(pValue);
|
||||||
return 1;
|
if (!inFile)
|
||||||
|
{
|
||||||
|
wprintf(L"Error opening -flist file %ls\n", pValue);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inFile.imbue(std::locale::classic());
|
||||||
|
|
||||||
|
ProcessFileList(inFile, conversion);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
inFile.imbue(std::locale::classic());
|
|
||||||
|
|
||||||
ProcessFileList(inFile, conversion);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OPT_PAPER_WHITE_NITS:
|
case OPT_PAPER_WHITE_NITS:
|
||||||
if (swscanf_s(pValue, L"%f", &paperWhiteNits) != 1)
|
if (swscanf_s(pValue, L"%f", &paperWhiteNits) != 1)
|
||||||
@ -2088,7 +2088,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef USE_OPENEXR
|
#ifdef USE_OPENEXR
|
||||||
else if (_wcsicmp(ext, L".exr") == 0)
|
else if (_wcsicmp(ext, L".exr") == 0)
|
||||||
{
|
{
|
||||||
hr = LoadFromEXRFile(pConv->szSrc, &info, *image);
|
hr = LoadFromEXRFile(pConv->szSrc, &info, *image);
|
||||||
@ -2099,7 +2099,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// WIC shares the same filter values for mode and dither
|
// WIC shares the same filter values for mode and dither
|
||||||
@ -2489,9 +2489,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto& tinfo = timage->GetMetadata();
|
auto& tinfo = timage->GetMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(info.width == tinfo.width);
|
assert(info.width == tinfo.width);
|
||||||
assert(info.height == tinfo.height);
|
assert(info.height == tinfo.height);
|
||||||
@ -2526,9 +2526,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto& tinfo = timage->GetMetadata();
|
auto& tinfo = timage->GetMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(tinfo.format == DXGI_FORMAT_R16G16B16A16_FLOAT);
|
assert(tinfo.format == DXGI_FORMAT_R16G16B16A16_FLOAT);
|
||||||
info.format = DXGI_FORMAT_R16G16B16A16_FLOAT;
|
info.format = DXGI_FORMAT_R16G16B16A16_FLOAT;
|
||||||
@ -2759,9 +2759,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto& tinfo = timage->GetMetadata();
|
auto& tinfo = timage->GetMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(info.width == tinfo.width);
|
assert(info.width == tinfo.width);
|
||||||
assert(info.height == tinfo.height);
|
assert(info.height == tinfo.height);
|
||||||
@ -2839,9 +2839,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto& tinfo = timage->GetMetadata();
|
auto& tinfo = timage->GetMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(info.width == tinfo.width);
|
assert(info.width == tinfo.width);
|
||||||
assert(info.height == tinfo.height);
|
assert(info.height == tinfo.height);
|
||||||
@ -2986,9 +2986,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto& tinfo = timage->GetMetadata();
|
auto& tinfo = timage->GetMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(info.width == tinfo.width);
|
assert(info.width == tinfo.width);
|
||||||
assert(info.height == tinfo.height);
|
assert(info.height == tinfo.height);
|
||||||
@ -3035,9 +3035,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto& tinfo = timage->GetMetadata();
|
auto& tinfo = timage->GetMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(info.width == tinfo.width);
|
assert(info.width == tinfo.width);
|
||||||
assert(info.height == tinfo.height);
|
assert(info.height == tinfo.height);
|
||||||
@ -3066,39 +3066,39 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
|
|
||||||
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
|
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
|
||||||
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
|
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
|
||||||
{
|
|
||||||
static const XMVECTORU32 s_selectz = { { { XM_SELECT_0, XM_SELECT_0, XM_SELECT_1, XM_SELECT_0 } } };
|
|
||||||
|
|
||||||
UNREFERENCED_PARAMETER(y);
|
|
||||||
|
|
||||||
for (size_t j = 0; j < w; ++j)
|
|
||||||
{
|
{
|
||||||
const XMVECTOR value = inPixels[j];
|
static const XMVECTORU32 s_selectz = { { { XM_SELECT_0, XM_SELECT_0, XM_SELECT_1, XM_SELECT_0 } } };
|
||||||
|
|
||||||
XMVECTOR z;
|
UNREFERENCED_PARAMETER(y);
|
||||||
if (isunorm)
|
|
||||||
{
|
|
||||||
XMVECTOR x2 = XMVectorMultiplyAdd(value, g_XMTwo, g_XMNegativeOne);
|
|
||||||
x2 = XMVectorSqrt(XMVectorSubtract(g_XMOne, XMVector2Dot(x2, x2)));
|
|
||||||
z = XMVectorMultiplyAdd(x2, g_XMOneHalf, g_XMOneHalf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
z = XMVectorSqrt(XMVectorSubtract(g_XMOne, XMVector2Dot(value, value)));
|
|
||||||
}
|
|
||||||
|
|
||||||
outPixels[j] = XMVectorSelect(value, z, s_selectz);
|
for (size_t j = 0; j < w; ++j)
|
||||||
}
|
{
|
||||||
}, *timage);
|
const XMVECTOR value = inPixels[j];
|
||||||
|
|
||||||
|
XMVECTOR z;
|
||||||
|
if (isunorm)
|
||||||
|
{
|
||||||
|
XMVECTOR x2 = XMVectorMultiplyAdd(value, g_XMTwo, g_XMNegativeOne);
|
||||||
|
x2 = XMVectorSqrt(XMVectorSubtract(g_XMOne, XMVector2Dot(x2, x2)));
|
||||||
|
z = XMVectorMultiplyAdd(x2, g_XMOneHalf, g_XMOneHalf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
z = XMVectorSqrt(XMVectorSubtract(g_XMOne, XMVector2Dot(value, value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
outPixels[j] = XMVectorSelect(value, z, s_selectz);
|
||||||
|
}
|
||||||
|
}, *timage);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
wprintf(L" FAILED [reconstructz] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
wprintf(L" FAILED [reconstructz] (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto& tinfo = timage->GetMetadata();
|
auto& tinfo = timage->GetMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(info.width == tinfo.width);
|
assert(info.width == tinfo.width);
|
||||||
assert(info.height == tinfo.height);
|
assert(info.height == tinfo.height);
|
||||||
@ -3298,9 +3298,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto& tinfo = timage->GetMetadata();
|
auto& tinfo = timage->GetMetadata();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(info.width == tinfo.width);
|
assert(info.width == tinfo.width);
|
||||||
assert(info.height == tinfo.height);
|
assert(info.height == tinfo.height);
|
||||||
@ -3435,12 +3435,12 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEX_COMPRESS_FLAGS cflags = dwCompress;
|
TEX_COMPRESS_FLAGS cflags = dwCompress;
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
if (!(dwOptions & (uint64_t(1) << OPT_FORCE_SINGLEPROC)))
|
if (!(dwOptions & (uint64_t(1) << OPT_FORCE_SINGLEPROC)))
|
||||||
{
|
{
|
||||||
cflags |= TEX_COMPRESS_PARALLEL;
|
cflags |= TEX_COMPRESS_PARALLEL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((img->width % 4) != 0 || (img->height % 4) != 0)
|
if ((img->width % 4) != 0 || (img->height % 4) != 0)
|
||||||
{
|
{
|
||||||
@ -3592,20 +3592,20 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
switch (FileType)
|
switch (FileType)
|
||||||
{
|
{
|
||||||
case CODEC_DDS:
|
case CODEC_DDS:
|
||||||
{
|
|
||||||
DDS_FLAGS ddsFlags = DDS_FLAGS_NONE;
|
|
||||||
if (dwOptions & (uint64_t(1) << OPT_USE_DX10))
|
|
||||||
{
|
{
|
||||||
ddsFlags |= DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2;
|
DDS_FLAGS ddsFlags = DDS_FLAGS_NONE;
|
||||||
}
|
if (dwOptions & (uint64_t(1) << OPT_USE_DX10))
|
||||||
else if (dwOptions & (uint64_t(1) << OPT_USE_DX9))
|
{
|
||||||
{
|
ddsFlags |= DDS_FLAGS_FORCE_DX10_EXT | DDS_FLAGS_FORCE_DX10_EXT_MISC2;
|
||||||
ddsFlags |= DDS_FLAGS_FORCE_DX9_LEGACY;
|
}
|
||||||
}
|
else if (dwOptions & (uint64_t(1) << OPT_USE_DX9))
|
||||||
|
{
|
||||||
|
ddsFlags |= DDS_FLAGS_FORCE_DX9_LEGACY;
|
||||||
|
}
|
||||||
|
|
||||||
hr = SaveToDDSFile(img, nimg, info, ddsFlags, szDest);
|
hr = SaveToDDSFile(img, nimg, info, ddsFlags, szDest);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CODEC_TGA:
|
case CODEC_TGA:
|
||||||
hr = SaveToTGAFile(img[0], TGA_FLAGS_NONE, szDest, (dwOptions & (uint64_t(1) << OPT_TGA20)) ? &info : nullptr);
|
hr = SaveToTGAFile(img[0], TGA_FLAGS_NONE, szDest, (dwOptions & (uint64_t(1) << OPT_TGA20)) ? &info : nullptr);
|
||||||
@ -3623,80 +3623,80 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
hr = SaveToPortablePixMapHDR(img[0], szDest);
|
hr = SaveToPortablePixMapHDR(img[0], szDest);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef USE_OPENEXR
|
#ifdef USE_OPENEXR
|
||||||
case CODEC_EXR:
|
case CODEC_EXR:
|
||||||
hr = SaveToEXRFile(img[0], szDest);
|
hr = SaveToEXRFile(img[0], szDest);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
const WICCodecs codec = (FileType == CODEC_HDP || FileType == CODEC_JXR) ? WIC_CODEC_WMP : static_cast<WICCodecs>(FileType);
|
const WICCodecs codec = (FileType == CODEC_HDP || FileType == CODEC_JXR) ? WIC_CODEC_WMP : static_cast<WICCodecs>(FileType);
|
||||||
const size_t nimages = (dwOptions & (uint64_t(1) << OPT_WIC_MULTIFRAME)) ? nimg : 1;
|
const size_t nimages = (dwOptions & (uint64_t(1) << OPT_WIC_MULTIFRAME)) ? nimg : 1;
|
||||||
hr = SaveToWICFile(img, nimages, WIC_FLAGS_NONE, GetWICCodec(codec), szDest, nullptr,
|
hr = SaveToWICFile(img, nimages, WIC_FLAGS_NONE, GetWICCodec(codec), szDest, nullptr,
|
||||||
[&](IPropertyBag2* props)
|
[&](IPropertyBag2* props)
|
||||||
{
|
|
||||||
const bool wicLossless = (dwOptions & (uint64_t(1) << OPT_WIC_LOSSLESS)) != 0;
|
|
||||||
|
|
||||||
switch (FileType)
|
|
||||||
{
|
{
|
||||||
case WIC_CODEC_JPEG:
|
const bool wicLossless = (dwOptions & (uint64_t(1) << OPT_WIC_LOSSLESS)) != 0;
|
||||||
if (wicLossless || wicQuality >= 0.f)
|
|
||||||
{
|
|
||||||
PROPBAG2 options = {};
|
|
||||||
VARIANT varValues = {};
|
|
||||||
options.pstrName = const_cast<wchar_t*>(L"ImageQuality");
|
|
||||||
varValues.vt = VT_R4;
|
|
||||||
varValues.fltVal = (wicLossless) ? 1.f : wicQuality;
|
|
||||||
std::ignore = props->Write(1, &options, &varValues);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WIC_CODEC_TIFF:
|
switch (FileType)
|
||||||
{
|
|
||||||
PROPBAG2 options = {};
|
|
||||||
VARIANT varValues = {};
|
|
||||||
if (wicLossless)
|
|
||||||
{
|
{
|
||||||
options.pstrName = const_cast<wchar_t*>(L"TiffCompressionMethod");
|
case WIC_CODEC_JPEG:
|
||||||
varValues.vt = VT_UI1;
|
if (wicLossless || wicQuality >= 0.f)
|
||||||
varValues.bVal = WICTiffCompressionNone;
|
{
|
||||||
}
|
PROPBAG2 options = {};
|
||||||
else if (wicQuality >= 0.f)
|
VARIANT varValues = {};
|
||||||
{
|
options.pstrName = const_cast<wchar_t*>(L"ImageQuality");
|
||||||
options.pstrName = const_cast<wchar_t*>(L"CompressionQuality");
|
varValues.vt = VT_R4;
|
||||||
varValues.vt = VT_R4;
|
varValues.fltVal = (wicLossless) ? 1.f : wicQuality;
|
||||||
varValues.fltVal = wicQuality;
|
std::ignore = props->Write(1, &options, &varValues);
|
||||||
}
|
}
|
||||||
std::ignore = props->Write(1, &options, &varValues);
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WIC_CODEC_WMP:
|
case WIC_CODEC_TIFF:
|
||||||
case CODEC_HDP:
|
{
|
||||||
case CODEC_JXR:
|
PROPBAG2 options = {};
|
||||||
{
|
VARIANT varValues = {};
|
||||||
PROPBAG2 options = {};
|
if (wicLossless)
|
||||||
VARIANT varValues = {};
|
{
|
||||||
if (wicLossless)
|
options.pstrName = const_cast<wchar_t*>(L"TiffCompressionMethod");
|
||||||
{
|
varValues.vt = VT_UI1;
|
||||||
options.pstrName = const_cast<wchar_t*>(L"Lossless");
|
varValues.bVal = WICTiffCompressionNone;
|
||||||
varValues.vt = VT_BOOL;
|
}
|
||||||
varValues.bVal = TRUE;
|
else if (wicQuality >= 0.f)
|
||||||
|
{
|
||||||
|
options.pstrName = const_cast<wchar_t*>(L"CompressionQuality");
|
||||||
|
varValues.vt = VT_R4;
|
||||||
|
varValues.fltVal = wicQuality;
|
||||||
|
}
|
||||||
|
std::ignore = props->Write(1, &options, &varValues);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WIC_CODEC_WMP:
|
||||||
|
case CODEC_HDP:
|
||||||
|
case CODEC_JXR:
|
||||||
|
{
|
||||||
|
PROPBAG2 options = {};
|
||||||
|
VARIANT varValues = {};
|
||||||
|
if (wicLossless)
|
||||||
|
{
|
||||||
|
options.pstrName = const_cast<wchar_t*>(L"Lossless");
|
||||||
|
varValues.vt = VT_BOOL;
|
||||||
|
varValues.bVal = TRUE;
|
||||||
|
}
|
||||||
|
else if (wicQuality >= 0.f)
|
||||||
|
{
|
||||||
|
options.pstrName = const_cast<wchar_t*>(L"ImageQuality");
|
||||||
|
varValues.vt = VT_R4;
|
||||||
|
varValues.fltVal = wicQuality;
|
||||||
|
}
|
||||||
|
std::ignore = props->Write(1, &options, &varValues);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (wicQuality >= 0.f)
|
});
|
||||||
{
|
}
|
||||||
options.pstrName = const_cast<wchar_t*>(L"ImageQuality");
|
break;
|
||||||
varValues.vt = VT_R4;
|
|
||||||
varValues.fltVal = wicQuality;
|
|
||||||
}
|
|
||||||
std::ignore = props->Write(1, &options, &varValues);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
|
2222
Texdiag/texdiag.cpp
2222
Texdiag/texdiag.cpp
File diff suppressed because it is too large
Load Diff
@ -65,12 +65,12 @@ namespace
|
|||||||
template<UINT TNameLength>
|
template<UINT TNameLength>
|
||||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_ const char(&name)[TNameLength]) noexcept
|
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_ const char(&name)[TNameLength]) noexcept
|
||||||
{
|
{
|
||||||
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||||
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(resource);
|
UNREFERENCED_PARAMETER(resource);
|
||||||
UNREFERENCED_PARAMETER(name);
|
UNREFERENCED_PARAMETER(name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
@ -116,7 +116,7 @@ namespace
|
|||||||
const GUID& target;
|
const GUID& target;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr WICConvert g_WICConvert [] =
|
constexpr WICConvert g_WICConvert[] =
|
||||||
{
|
{
|
||||||
// Note target GUID in this conversion table must be one of those directly supported formats (above).
|
// Note target GUID in this conversion table must be one of those directly supported formats (above).
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ namespace
|
|||||||
|
|
||||||
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID *ifactory) noexcept
|
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID *ifactory) noexcept
|
||||||
{
|
{
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
HRESULT hr = CoCreateInstance(
|
HRESULT hr = CoCreateInstance(
|
||||||
CLSID_WICImagingFactory2,
|
CLSID_WICImagingFactory2,
|
||||||
nullptr,
|
nullptr,
|
||||||
@ -206,14 +206,14 @@ namespace
|
|||||||
);
|
);
|
||||||
return SUCCEEDED(hr) ? TRUE : FALSE;
|
return SUCCEEDED(hr) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return SUCCEEDED(CoCreateInstance(
|
return SUCCEEDED(CoCreateInstance(
|
||||||
CLSID_WICImagingFactory,
|
CLSID_WICImagingFactory,
|
||||||
nullptr,
|
nullptr,
|
||||||
CLSCTX_INPROC_SERVER,
|
CLSCTX_INPROC_SERVER,
|
||||||
__uuidof(IWICImagingFactory),
|
__uuidof(IWICImagingFactory),
|
||||||
ifactory)) ? TRUE : FALSE;
|
ifactory)) ? TRUE : FALSE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
IWICImagingFactory* GetWIC() noexcept
|
IWICImagingFactory* GetWIC() noexcept
|
||||||
@ -242,13 +242,13 @@ namespace
|
|||||||
return g_WICFormats[i].format;
|
return g_WICFormats[i].format;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
if (g_WIC2)
|
if (g_WIC2)
|
||||||
{
|
{
|
||||||
if (memcmp(&GUID_WICPixelFormat96bppRGBFloat, &guid, sizeof(GUID)) == 0)
|
if (memcmp(&GUID_WICPixelFormat96bppRGBFloat, &guid, sizeof(GUID)) == 0)
|
||||||
return DXGI_FORMAT_R32G32B32_FLOAT;
|
return DXGI_FORMAT_R32G32B32_FLOAT;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return DXGI_FORMAT_UNKNOWN;
|
return DXGI_FORMAT_UNKNOWN;
|
||||||
}
|
}
|
||||||
@ -454,7 +454,7 @@ namespace
|
|||||||
{
|
{
|
||||||
if (memcmp(&GUID_WICPixelFormat96bppRGBFixedPoint, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0)
|
if (memcmp(&GUID_WICPixelFormat96bppRGBFixedPoint, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0)
|
||||||
{
|
{
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
if (g_WIC2)
|
if (g_WIC2)
|
||||||
{
|
{
|
||||||
memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID));
|
memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID));
|
||||||
@ -462,7 +462,7 @@ namespace
|
|||||||
bpp = 96;
|
bpp = 96;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat128bppRGBAFloat, sizeof(GUID));
|
memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat128bppRGBAFloat, sizeof(GUID));
|
||||||
format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||||
@ -493,7 +493,7 @@ namespace
|
|||||||
bpp = WICBitsPerPixel(pixelFormat);
|
bpp = WICBitsPerPixel(pixelFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
if ((format == DXGI_FORMAT_R32G32B32_FLOAT) && d3dContext && textureView)
|
if ((format == DXGI_FORMAT_R32G32B32_FLOAT) && d3dContext && textureView)
|
||||||
{
|
{
|
||||||
// Special case test for optional device support for autogen mipchains for R32G32B32_FLOAT
|
// Special case test for optional device support for autogen mipchains for R32G32B32_FLOAT
|
||||||
@ -507,7 +507,7 @@ namespace
|
|||||||
bpp = 128;
|
bpp = 128;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (loadFlags & WIC_LOADER_FORCE_RGBA32)
|
if (loadFlags & WIC_LOADER_FORCE_RGBA32)
|
||||||
{
|
{
|
||||||
@ -773,7 +773,7 @@ namespace
|
|||||||
_In_opt_ ID3D11Resource** texture,
|
_In_opt_ ID3D11Resource** texture,
|
||||||
_In_opt_ ID3D11ShaderResourceView** textureView) noexcept
|
_In_opt_ ID3D11ShaderResourceView** textureView) noexcept
|
||||||
{
|
{
|
||||||
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||||
if (texture || textureView)
|
if (texture || textureView)
|
||||||
{
|
{
|
||||||
CHAR strFileA[MAX_PATH];
|
CHAR strFileA[MAX_PATH];
|
||||||
@ -815,11 +815,11 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(fileName);
|
UNREFERENCED_PARAMETER(fileName);
|
||||||
UNREFERENCED_PARAMETER(texture);
|
UNREFERENCED_PARAMETER(texture);
|
||||||
UNREFERENCED_PARAMETER(textureView);
|
UNREFERENCED_PARAMETER(textureView);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
@ -37,12 +37,12 @@ namespace DirectX
|
|||||||
#define WIC_LOADER_FLAGS_DEFINED
|
#define WIC_LOADER_FLAGS_DEFINED
|
||||||
enum WIC_LOADER_FLAGS : uint32_t
|
enum WIC_LOADER_FLAGS : uint32_t
|
||||||
{
|
{
|
||||||
WIC_LOADER_DEFAULT = 0,
|
WIC_LOADER_DEFAULT = 0,
|
||||||
WIC_LOADER_FORCE_SRGB = 0x1,
|
WIC_LOADER_FORCE_SRGB = 0x1,
|
||||||
WIC_LOADER_IGNORE_SRGB = 0x2,
|
WIC_LOADER_IGNORE_SRGB = 0x2,
|
||||||
WIC_LOADER_SRGB_DEFAULT = 0x4,
|
WIC_LOADER_SRGB_DEFAULT = 0x4,
|
||||||
WIC_LOADER_FIT_POW2 = 0x20,
|
WIC_LOADER_FIT_POW2 = 0x20,
|
||||||
WIC_LOADER_MAKE_SQUARE = 0x40,
|
WIC_LOADER_MAKE_SQUARE = 0x40,
|
||||||
WIC_LOADER_FORCE_RGBA32 = 0x80,
|
WIC_LOADER_FORCE_RGBA32 = 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ namespace
|
|||||||
const GUID& target;
|
const GUID& target;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr WICConvert g_WICConvert [] =
|
constexpr WICConvert g_WICConvert[] =
|
||||||
{
|
{
|
||||||
// Note target GUID in this conversion table must be one of those directly supported formats (above).
|
// Note target GUID in this conversion table must be one of those directly supported formats (above).
|
||||||
|
|
||||||
@ -198,12 +198,12 @@ namespace
|
|||||||
template<UINT TNameLength>
|
template<UINT TNameLength>
|
||||||
inline void SetDebugObjectName(_In_ ID3D12DeviceChild* resource, _In_z_ const wchar_t(&name)[TNameLength]) noexcept
|
inline void SetDebugObjectName(_In_ ID3D12DeviceChild* resource, _In_z_ const wchar_t(&name)[TNameLength]) noexcept
|
||||||
{
|
{
|
||||||
#if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
#if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||||
resource->SetName(name);
|
resource->SetName(name);
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(resource);
|
UNREFERENCED_PARAMETER(resource);
|
||||||
UNREFERENCED_PARAMETER(name);
|
UNREFERENCED_PARAMETER(name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t CountMips(uint32_t width, uint32_t height) noexcept
|
inline uint32_t CountMips(uint32_t width, uint32_t height) noexcept
|
||||||
@ -634,7 +634,7 @@ namespace
|
|||||||
_In_z_ const wchar_t* fileName,
|
_In_z_ const wchar_t* fileName,
|
||||||
_In_ ID3D12Resource** texture) noexcept
|
_In_ ID3D12Resource** texture) noexcept
|
||||||
{
|
{
|
||||||
#if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
#if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||||
if (texture && *texture)
|
if (texture && *texture)
|
||||||
{
|
{
|
||||||
const wchar_t* pstrName = wcsrchr(fileName, '\\');
|
const wchar_t* pstrName = wcsrchr(fileName, '\\');
|
||||||
@ -649,10 +649,10 @@ namespace
|
|||||||
|
|
||||||
(*texture)->SetName(pstrName);
|
(*texture)->SetName(pstrName);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
UNREFERENCED_PARAMETER(fileName);
|
UNREFERENCED_PARAMETER(fileName);
|
||||||
UNREFERENCED_PARAMETER(texture);
|
UNREFERENCED_PARAMETER(texture);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
@ -36,14 +36,14 @@ namespace DirectX
|
|||||||
#define WIC_LOADER_FLAGS_DEFINED
|
#define WIC_LOADER_FLAGS_DEFINED
|
||||||
enum WIC_LOADER_FLAGS : uint32_t
|
enum WIC_LOADER_FLAGS : uint32_t
|
||||||
{
|
{
|
||||||
WIC_LOADER_DEFAULT = 0,
|
WIC_LOADER_DEFAULT = 0,
|
||||||
WIC_LOADER_FORCE_SRGB = 0x1,
|
WIC_LOADER_FORCE_SRGB = 0x1,
|
||||||
WIC_LOADER_IGNORE_SRGB = 0x2,
|
WIC_LOADER_IGNORE_SRGB = 0x2,
|
||||||
WIC_LOADER_SRGB_DEFAULT = 0x4,
|
WIC_LOADER_SRGB_DEFAULT = 0x4,
|
||||||
WIC_LOADER_MIP_AUTOGEN = 0x8,
|
WIC_LOADER_MIP_AUTOGEN = 0x8,
|
||||||
WIC_LOADER_MIP_RESERVE = 0x10,
|
WIC_LOADER_MIP_RESERVE = 0x10,
|
||||||
WIC_LOADER_FIT_POW2 = 0x20,
|
WIC_LOADER_FIT_POW2 = 0x20,
|
||||||
WIC_LOADER_MAKE_SQUARE = 0x40,
|
WIC_LOADER_MAKE_SQUARE = 0x40,
|
||||||
WIC_LOADER_FORCE_RGBA32 = 0x80,
|
WIC_LOADER_FORCE_RGBA32 = 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ namespace
|
|||||||
const GUID& target;
|
const GUID& target;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr WICConvert g_WICConvert [] =
|
constexpr WICConvert g_WICConvert[] =
|
||||||
{
|
{
|
||||||
// Note target GUID in this conversion table must be one of those directly supported formats (above).
|
// Note target GUID in this conversion table must be one of those directly supported formats (above).
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ namespace
|
|||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
|
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID* ifactory) noexcept
|
||||||
{
|
{
|
||||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
|
||||||
HRESULT hr = CoCreateInstance(
|
HRESULT hr = CoCreateInstance(
|
||||||
CLSID_WICImagingFactory2,
|
CLSID_WICImagingFactory2,
|
||||||
nullptr,
|
nullptr,
|
||||||
@ -187,14 +187,14 @@ namespace
|
|||||||
);
|
);
|
||||||
return SUCCEEDED(hr) ? TRUE : FALSE;
|
return SUCCEEDED(hr) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return SUCCEEDED(CoCreateInstance(
|
return SUCCEEDED(CoCreateInstance(
|
||||||
CLSID_WICImagingFactory,
|
CLSID_WICImagingFactory,
|
||||||
nullptr,
|
nullptr,
|
||||||
CLSCTX_INPROC_SERVER,
|
CLSCTX_INPROC_SERVER,
|
||||||
__uuidof(IWICImagingFactory),
|
__uuidof(IWICImagingFactory),
|
||||||
ifactory)) ? TRUE : FALSE;
|
ifactory)) ? TRUE : FALSE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
IWICImagingFactory* GetWIC() noexcept
|
IWICImagingFactory* GetWIC() noexcept
|
||||||
|
@ -35,10 +35,10 @@ namespace DirectX
|
|||||||
#define WIC_LOADER_FLAGS_DEFINED
|
#define WIC_LOADER_FLAGS_DEFINED
|
||||||
enum WIC_LOADER_FLAGS : uint32_t
|
enum WIC_LOADER_FLAGS : uint32_t
|
||||||
{
|
{
|
||||||
WIC_LOADER_DEFAULT = 0,
|
WIC_LOADER_DEFAULT = 0,
|
||||||
WIC_LOADER_MIP_AUTOGEN = 0x8,
|
WIC_LOADER_MIP_AUTOGEN = 0x8,
|
||||||
WIC_LOADER_FIT_POW2 = 0x20,
|
WIC_LOADER_FIT_POW2 = 0x20,
|
||||||
WIC_LOADER_MAKE_SQUARE = 0x40,
|
WIC_LOADER_MAKE_SQUARE = 0x40,
|
||||||
WIC_LOADER_FORCE_RGBA32 = 0x80,
|
WIC_LOADER_FORCE_RGBA32 = 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user