diff --git a/.editorconfig b/.editorconfig index 927467c..174669d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,9 +1,74 @@ root = true -[*.{cpp,h,inl,fx,hlsl}] +[*.{fx,fxh,hlsl,hlsli}] indent_size = 4 indent_style = space trim_trailing_whitespace = true insert_final_newline = true end_of_line = crlf 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 diff --git a/DDSTextureLoader/DDSTextureLoader11.cpp b/DDSTextureLoader/DDSTextureLoader11.cpp index d05099c..1cc1026 100644 --- a/DDSTextureLoader/DDSTextureLoader11.cpp +++ b/DDSTextureLoader/DDSTextureLoader11.cpp @@ -43,7 +43,7 @@ using namespace DirectX; // Macros //-------------------------------------------------------------------------------------- #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)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 )) #endif /* defined(MAKEFOURCC) */ @@ -136,7 +136,7 @@ namespace inline HANDLE safe_handle(HANDLE h) noexcept { return (h == INVALID_HANDLE_VALUE) ? nullptr : h; } template - 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) resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); @@ -229,13 +229,13 @@ namespace *bitSize = 0; // open the file -#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) + #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) ScopedHandle hFile(safe_handle(CreateFile2(fileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr))); -#else + #else ScopedHandle hFile(safe_handle(CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, @@ -243,7 +243,7 @@ namespace OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr))); -#endif + #endif if (!hFile) { @@ -611,13 +611,13 @@ namespace 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!"); if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX) return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); -#else + #else static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!"); -#endif + #endif 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 { @@ -904,10 +904,10 @@ namespace return DXGI_FORMAT_UNKNOWN; } - #undef ISBITMASK +#undef ISBITMASK - //-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT format) noexcept { switch (format) @@ -1070,202 +1070,202 @@ namespace switch (resDim) { case D3D11_RESOURCE_DIMENSION_TEXTURE1D: - { - D3D11_TEXTURE1D_DESC desc; - desc.Width = static_cast(width); - desc.MipLevels = static_cast(mipCount); - desc.ArraySize = static_cast(arraySize); - desc.Format = format; - desc.Usage = usage; - desc.BindFlags = bindFlags; - desc.CPUAccessFlags = cpuAccessFlags; - desc.MiscFlags = miscFlags & ~static_cast(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(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(width); - desc.Height = static_cast(height); - desc.MipLevels = static_cast(mipCount); - desc.ArraySize = static_cast(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(width); + desc.MipLevels = static_cast(mipCount); + desc.ArraySize = static_cast(arraySize); + desc.Format = format; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpuAccessFlags; desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); - } - ID3D11Texture2D* tex = nullptr; - hr = d3dDevice->CreateTexture2D(&desc, - initData, - &tex - ); - if (SUCCEEDED(hr) && tex) - { - if (textureView) + ID3D11Texture1D* tex = nullptr; + hr = d3dDevice->CreateTexture1D(&desc, + initData, + &tex + ); + if (SUCCEEDED(hr) && tex) { - D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; - SRVDesc.Format = format; - - if (isCubeMap) + if (textureView) { - if (arraySize > 6) - { - SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY; - SRVDesc.TextureCubeArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; + D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = {}; + SRVDesc.Format = format; - // Earlier we set arraySize to (NumCubes * 6) - SRVDesc.TextureCubeArray.NumCubes = static_cast(arraySize / 6); + if (arraySize > 1) + { + SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY; + SRVDesc.Texture1DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; + SRVDesc.Texture1DArray.ArraySize = static_cast(arraySize); } else { - SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - SRVDesc.TextureCube.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; + 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; } } - else if (arraySize > 1) + + if (texture) { - SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - SRVDesc.Texture2DArray.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; - SRVDesc.Texture2DArray.ArraySize = static_cast(arraySize); + *texture = tex; } else { - SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - SRVDesc.Texture2D.MipLevels = (!mipCount) ? UINT(-1) : desc.MipLevels; - } - - hr = d3dDevice->CreateShaderResourceView(tex, - &SRVDesc, - textureView - ); - if (FAILED(hr)) - { + SetDebugObjectName(tex, "DDSTextureLoader"); tex->Release(); - return hr; } } + } + break; - if (texture) + case D3D11_RESOURCE_DIMENSION_TEXTURE2D: + { + D3D11_TEXTURE2D_DESC desc; + desc.Width = static_cast(width); + desc.Height = static_cast(height); + desc.MipLevels = static_cast(mipCount); + desc.ArraySize = static_cast(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 { - SetDebugObjectName(tex, "DDSTextureLoader"); - tex->Release(); + desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); + } + + 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(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(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: - { - D3D11_TEXTURE3D_DESC desc; - desc.Width = static_cast(width); - desc.Height = static_cast(height); - desc.Depth = static_cast(depth); - desc.MipLevels = static_cast(mipCount); - desc.Format = format; - desc.Usage = usage; - desc.BindFlags = bindFlags; - desc.CPUAccessFlags = cpuAccessFlags; - desc.MiscFlags = miscFlags & ~static_cast(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(width); + desc.Height = static_cast(height); + desc.Depth = static_cast(depth); + desc.MipLevels = static_cast(mipCount); + desc.Format = format; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpuAccessFlags; + desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); + + ID3D11Texture3D* tex = nullptr; + hr = d3dDevice->CreateTexture3D(&desc, + initData, + &tex + ); + if (SUCCEEDED(hr) && tex) { - 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)) + if (textureView) { + 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(); - return hr; } } - - if (texture) - { - *texture = tex; - } - else - { - SetDebugObjectName(tex, "DDSTextureLoader"); - tex->Release(); - } } - } - break; + break; } return hr; @@ -1434,8 +1434,8 @@ namespace } } else if ((arraySize > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) || - (width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION) || - (height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) + (width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION) || + (height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) { return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); } @@ -1682,7 +1682,7 @@ namespace _In_opt_ ID3D11Resource** texture, _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) { CHAR strFileA[MAX_PATH]; @@ -1724,11 +1724,11 @@ namespace } } } -#else + #else UNREFERENCED_PARAMETER(fileName); UNREFERENCED_PARAMETER(texture); UNREFERENCED_PARAMETER(textureView); -#endif + #endif } } // anonymous namespace diff --git a/DDSTextureLoader/DDSTextureLoader11.h b/DDSTextureLoader/DDSTextureLoader11.h index db72261..f81d9a7 100644 --- a/DDSTextureLoader/DDSTextureLoader11.h +++ b/DDSTextureLoader/DDSTextureLoader11.h @@ -30,11 +30,11 @@ namespace DirectX #define DDS_ALPHA_MODE_DEFINED enum DDS_ALPHA_MODE : uint32_t { - DDS_ALPHA_MODE_UNKNOWN = 0, - DDS_ALPHA_MODE_STRAIGHT = 1, + DDS_ALPHA_MODE_UNKNOWN = 0, + DDS_ALPHA_MODE_STRAIGHT = 1, DDS_ALPHA_MODE_PREMULTIPLIED = 2, - DDS_ALPHA_MODE_OPAQUE = 3, - DDS_ALPHA_MODE_CUSTOM = 4, + DDS_ALPHA_MODE_OPAQUE = 3, + DDS_ALPHA_MODE_CUSTOM = 4, }; #endif diff --git a/DDSTextureLoader/DDSTextureLoader12.cpp b/DDSTextureLoader/DDSTextureLoader12.cpp index 924672e..f82fdf1 100644 --- a/DDSTextureLoader/DDSTextureLoader12.cpp +++ b/DDSTextureLoader/DDSTextureLoader12.cpp @@ -59,7 +59,7 @@ using namespace DirectX; // Macros //-------------------------------------------------------------------------------------- #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)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 )) #endif /* defined(MAKEFOURCC) */ @@ -168,12 +168,12 @@ namespace template inline void SetDebugObjectName(_In_ ID3D12DeviceChild* resource, _In_z_ const wchar_t(&name)[TNameLength]) noexcept { - #if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) - resource->SetName(name); - #else - UNREFERENCED_PARAMETER(resource); - UNREFERENCED_PARAMETER(name); - #endif + #if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) + resource->SetName(name); + #else + UNREFERENCED_PARAMETER(resource); + UNREFERENCED_PARAMETER(name); + #endif } inline uint32_t CountMips(uint32_t width, uint32_t height) noexcept @@ -274,8 +274,8 @@ namespace *bitSize = 0; -#ifdef WIN32 - // open the file + #ifdef WIN32 + // open the file ScopedHandle hFile(safe_handle(CreateFile2(fileName, GENERIC_READ, FILE_SHARE_READ, @@ -334,7 +334,7 @@ namespace 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); if (!inFile) return E_FAIL; @@ -358,17 +358,17 @@ namespace return E_FAIL; } - inFile.read(reinterpret_cast(ddsData.get()), fileLen); - if (!inFile) - { - ddsData.reset(); - return E_FAIL; - } + inFile.read(reinterpret_cast(ddsData.get()), fileLen); + if (!inFile) + { + ddsData.reset(); + return E_FAIL; + } - inFile.close(); + inFile.close(); - size_t len = fileLen; -#endif + size_t len = fileLen; + #endif // DDS files always start with the same magic number ("DDS ") auto const dwMagicNumber = *reinterpret_cast(ddsData.get()); @@ -690,13 +690,13 @@ namespace 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!"); if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; -#else + #else static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!"); -#endif + #endif 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 { @@ -983,10 +983,10 @@ namespace return DXGI_FORMAT_UNKNOWN; } - #undef ISBITMASK +#undef ISBITMASK - //-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- DXGI_FORMAT MakeSRGB(_In_ DXGI_FORMAT format) noexcept { switch (format) @@ -1405,8 +1405,8 @@ namespace } } else if ((arraySize > D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) || - (width > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION) || - (height > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION)) + (width > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION) || + (height > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION)) { return HRESULT_E_NOT_SUPPORTED; } @@ -1443,7 +1443,7 @@ namespace // Create the texture size_t numberOfResources = (resDim == D3D12_RESOURCE_DIMENSION_TEXTURE3D) - ? 1 : arraySize; + ? 1 : arraySize; numberOfResources *= mipCount; 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(reinterpret_cast(header) + sizeof(DDS_HEADER)); - auto const mode = static_cast( d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK ); - switch( mode ) + auto const mode = static_cast(d3d10ext->miscFlags2 & DDS_MISC_FLAGS2_ALPHA_MODE_MASK); + switch (mode) { case DDS_ALPHA_MODE_STRAIGHT: case DDS_ALPHA_MODE_PREMULTIPLIED: @@ -1524,8 +1524,8 @@ namespace break; } } - else if ( ( MAKEFOURCC( 'D', 'X', 'T', '2' ) == header->ddspf.fourCC ) - || ( MAKEFOURCC( 'D', 'X', 'T', '4' ) == header->ddspf.fourCC ) ) + else if ((MAKEFOURCC('D', 'X', 'T', '2') == header->ddspf.fourCC) + || (MAKEFOURCC('D', 'X', 'T', '4') == header->ddspf.fourCC)) { return DDS_ALPHA_MODE_PREMULTIPLIED; } @@ -1539,7 +1539,7 @@ namespace _In_z_ const wchar_t* fileName, _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) { const wchar_t* pstrName = wcsrchr(fileName, '\\'); @@ -1554,10 +1554,10 @@ namespace (*texture)->SetName(pstrName); } -#else + #else UNREFERENCED_PARAMETER(fileName); UNREFERENCED_PARAMETER(texture); -#endif + #endif } } // anonymous namespace diff --git a/DDSTextureLoader/DDSTextureLoader12.h b/DDSTextureLoader/DDSTextureLoader12.h index bc0141d..4806277 100644 --- a/DDSTextureLoader/DDSTextureLoader12.h +++ b/DDSTextureLoader/DDSTextureLoader12.h @@ -37,11 +37,11 @@ namespace DirectX #define DDS_ALPHA_MODE_DEFINED enum DDS_ALPHA_MODE : uint32_t { - DDS_ALPHA_MODE_UNKNOWN = 0, - DDS_ALPHA_MODE_STRAIGHT = 1, + DDS_ALPHA_MODE_UNKNOWN = 0, + DDS_ALPHA_MODE_STRAIGHT = 1, DDS_ALPHA_MODE_PREMULTIPLIED = 2, - DDS_ALPHA_MODE_OPAQUE = 3, - DDS_ALPHA_MODE_CUSTOM = 4, + DDS_ALPHA_MODE_OPAQUE = 3, + DDS_ALPHA_MODE_CUSTOM = 4, }; #endif @@ -51,9 +51,9 @@ namespace DirectX enum DDS_LOADER_FLAGS : uint32_t { - DDS_LOADER_DEFAULT = 0, - DDS_LOADER_FORCE_SRGB = 0x1, - DDS_LOADER_MIP_RESERVE = 0x8, + DDS_LOADER_DEFAULT = 0, + DDS_LOADER_FORCE_SRGB = 0x1, + DDS_LOADER_MIP_RESERVE = 0x8, }; #ifdef __clang__ diff --git a/DDSTextureLoader/DDSTextureLoader9.cpp b/DDSTextureLoader/DDSTextureLoader9.cpp index 2144f95..2d532ee 100644 --- a/DDSTextureLoader/DDSTextureLoader9.cpp +++ b/DDSTextureLoader/DDSTextureLoader9.cpp @@ -47,7 +47,7 @@ using Microsoft::WRL::ComPtr; // Macros //-------------------------------------------------------------------------------------- #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)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 )) #endif /* defined(MAKEFOURCC) */ @@ -199,13 +199,13 @@ namespace *bitSize = 0; // open the file -#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) + #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) ScopedHandle hFile(safe_handle(CreateFile2(fileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr))); -#else + #else ScopedHandle hFile(safe_handle(CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, @@ -213,7 +213,7 @@ namespace OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr))); -#endif + #endif if (!hFile) { @@ -338,9 +338,9 @@ namespace case D3DFMT_INDEX32: case D3DFMT_G16R16F: case D3DFMT_R32F: -#if !defined(D3D_DISABLE_9EX) + #if !defined(D3D_DISABLE_9EX) case D3DFMT_D32_LOCKABLE: -#endif + #endif return 32; case D3DFMT_R8G8B8: @@ -383,9 +383,9 @@ namespace // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directshow/htm/directxvideoaccelerationdxvavideosubtypes.asp case MAKEFOURCC('A', 'I', '4', '4'): case MAKEFOURCC('I', 'A', '4', '4'): -#if !defined(D3D_DISABLE_9EX) + #if !defined(D3D_DISABLE_9EX) case D3DFMT_S8_LOCKABLE: -#endif + #endif return 8; case D3DFMT_DXT1: @@ -394,10 +394,10 @@ namespace case MAKEFOURCC('Y', 'V', '1', '2'): return 12; -#if !defined(D3D_DISABLE_9EX) + #if !defined(D3D_DISABLE_9EX) case D3DFMT_A1: return 1; -#endif + #endif default: return 0; @@ -483,13 +483,13 @@ namespace 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!"); if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX) return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); -#else + #else static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!"); -#endif + #endif 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 { @@ -766,10 +766,10 @@ namespace return D3DFMT_UNKNOWN; } - #undef ISBITMASK +#undef ISBITMASK - //-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- HRESULT CreateTextureFromDDS( _In_ LPDIRECT3DDEVICE9 device, _In_ const DDS_HEADER* header, diff --git a/DirectXTex/BC.cpp b/DirectXTex/BC.cpp index d037567..e730550 100644 --- a/DirectXTex/BC.cpp +++ b/DirectXTex/BC.cpp @@ -84,9 +84,9 @@ namespace for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++) { -#ifdef COLOR_WEIGHTS + #ifdef COLOR_WEIGHTS if (pPoints[iPoint].a > 0.0f) -#endif // COLOR_WEIGHTS + #endif // COLOR_WEIGHTS { if (pPoints[iPoint].r < X.r) X.r = pPoints[iPoint].r; @@ -144,7 +144,7 @@ namespace float f; -#ifdef COLOR_WEIGHTS + #ifdef COLOR_WEIGHTS f = Pt.r + Pt.g + Pt.b; fDir[0] += pPoints[iPoint].a * f * f; @@ -156,7 +156,7 @@ namespace f = Pt.r - Pt.g - Pt.b; fDir[3] += pPoints[iPoint].a * f * f; -#else + #else f = Pt.r + Pt.g + Pt.b; fDir[0] += f * f; @@ -168,7 +168,7 @@ namespace f = Pt.r - Pt.g - Pt.b; fDir[3] += f * f; -#endif // COLOR_WEIGHTS + #endif // COLOR_WEIGHTS } float fDirMax = fDir[0]; @@ -264,13 +264,13 @@ namespace Diff.b = pSteps[iStep].b - pPoints[iPoint].b; Diff.a = 0.0f; -#ifdef COLOR_WEIGHTS + #ifdef COLOR_WEIGHTS const float fC = pC[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 fD = pD[iStep] * (1.0f / 8.0f); -#endif // COLOR_WEIGHTS + #endif // COLOR_WEIGHTS d2X += fC * pC[iStep]; dX.r += fC * Diff.r; @@ -434,11 +434,11 @@ namespace Color[i].g = static_cast(static_cast(Clr.g * 63.0f + 0.5f)) * (1.0f / 63.0f); Color[i].b = static_cast(static_cast(Clr.b * 31.0f + 0.5f)) * (1.0f / 31.0f); -#ifdef COLOR_WEIGHTS + #ifdef COLOR_WEIGHTS Color[i].a = pColor[i].a; -#else + #else Color[i].a = 1.0f; -#endif // COLOR_WEIGHTS + #endif // COLOR_WEIGHTS if (flags & BC_FLAGS_DITHER_RGB) { @@ -688,7 +688,7 @@ namespace #ifdef COLOR_WEIGHTS 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 HDRColorA Color; Color.r = pColor[0].r; @@ -707,9 +707,9 @@ namespace Color.b *= 1.0f / 16.0f; const uint16_t wColor = Encode565(&Color); -#else + #else const uint16_t wColor = 0x0000; -#endif // COLOR_AVG_0WEIGHTS + #endif // COLOR_AVG_0WEIGHTS // Encode solid block 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) { -#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(dw & 0xf) * (1.0f / 15.0f)); } diff --git a/DirectXTex/BC.h b/DirectXTex/BC.h index aff2f7a..44482b4 100644 --- a/DirectXTex/BC.h +++ b/DirectXTex/BC.h @@ -27,141 +27,151 @@ namespace DirectX // Constants //------------------------------------------------------------------------------------- -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 + enum BC_FLAGS : uint32_t { - 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(fMax, std::max(fMin, r)); + g = std::min(fMax, std::max(fMin, g)); + b = std::min(fMax, std::max(fMin, b)); + a = std::min(fMax, std::max(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(fMax, std::max(fMin, r)); - g = std::min(fMax, std::max(fMin, g)); - b = std::min(fMax, std::max(fMin, b)); - a = std::min(fMax, std::max(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) // BC1/DXT1 compression (4 bits per texel) -struct D3DX_BC1 -{ - uint16_t rgb[2]; // 565 colors - uint32_t bitmap; // 2bpp rgb bitmap -}; + struct D3DX_BC1 + { + uint16_t rgb[2]; // 565 colors + uint32_t bitmap; // 2bpp rgb bitmap + }; -// BC2/DXT2/3 compression (8 bits per texel) -struct D3DX_BC2 -{ - uint32_t bitmap[2]; // 4bpp alpha bitmap - D3DX_BC1 bc1; // BC1 rgb data -}; + // BC2/DXT2/3 compression (8 bits per texel) + struct D3DX_BC2 + { + uint32_t bitmap[2]; // 4bpp alpha bitmap + D3DX_BC1 bc1; // BC1 rgb data + }; -// BC3/DXT4/5 compression (8 bits per texel) -struct D3DX_BC3 -{ - uint8_t alpha[2]; // alpha values - uint8_t bitmap[6]; // 3bpp alpha bitmap - D3DX_BC1 bc1; // BC1 rgb data -}; + // BC3/DXT4/5 compression (8 bits per texel) + struct D3DX_BC3 + { + uint8_t alpha[2]; // alpha values + uint8_t bitmap[6]; // 3bpp alpha bitmap + D3DX_BC1 bc1; // BC1 rgb data + }; #pragma pack(pop) //------------------------------------------------------------------------------------- @@ -169,162 +179,162 @@ struct D3DX_BC3 //------------------------------------------------------------------------------------- #pragma warning(push) #pragma warning(disable : 4127) -template 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) + template void OptimizeAlpha(float *pX, float *pY, const float *pPoints, uint32_t cSteps) noexcept { - for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++) - { - if (pPoints[iPoint] < fX) - fX = pPoints[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 }; + 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 }; - if (pPoints[iPoint] > fY) - fY = pPoints[iPoint]; + 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++) + { + 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(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(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) //------------------------------------------------------------------------------------- // Functions //------------------------------------------------------------------------------------- -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_DECODE)(XMVECTOR *pColor, const uint8_t *pBC); + 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 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 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 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 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 D3DXDecodeBC7(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) 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 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 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 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 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 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 + 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 -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 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 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 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 D3DXEncodeBC7(_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 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 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 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 D3DXEncodeBC7(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept; } // namespace diff --git a/DirectXTex/BC4BC5.cpp b/DirectXTex/BC4BC5.cpp index 7f533bd..263db98 100644 --- a/DirectXTex/BC4BC5.cpp +++ b/DirectXTex/BC4BC5.cpp @@ -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) { -#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); } } @@ -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) { -#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); } } @@ -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) { -#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); } } @@ -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) { -#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); } } diff --git a/DirectXTex/BC6HBC7.cpp b/DirectXTex/BC6HBC7.cpp index 4b815be..2a889d8 100644 --- a/DirectXTex/BC6HBC7.cpp +++ b/DirectXTex/BC6HBC7.cpp @@ -660,8 +660,8 @@ namespace void Encode(_In_ bool bSigned, _In_reads_(NUM_PIXELS_PER_BLOCK) const HDRColorA* const pIn) noexcept; private: -#pragma warning(push) -#pragma warning(disable : 4480) + #pragma warning(push) + #pragma warning(disable : 4480) enum EField : uint8_t { NA, // N/A @@ -680,7 +680,7 @@ namespace BY, BZ, }; -#pragma warning(pop) + #pragma warning(pop) struct ModeDescriptor { @@ -697,8 +697,8 @@ namespace LDRColorA RGBAPrec[BC6H_MAX_REGIONS][2]; }; -#pragma warning(push) -#pragma warning(disable : 4512) + #pragma warning(push) + #pragma warning(disable : 4512) struct EncodeParams { 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 Unquantize(_In_ int comp, _In_ uint8_t uBitsPerComp, _In_ bool bSigned) noexcept; @@ -777,8 +777,8 @@ namespace LDRColorA RGBAPrecWithP; }; -#pragma warning(push) -#pragma warning(disable : 4512) + #pragma warning(push) + #pragma warning(disable : 4512) struct EncodeParams { uint8_t uMode; @@ -788,7 +788,7 @@ namespace 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 { @@ -1035,20 +1035,20 @@ const D3DX_BC6H::ModeDescriptor D3DX_BC6H::ms_aDesc[14][82] = // Mode, Partitions, Transformed, IndexPrec, RGBAPrec 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 - {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 - {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 - {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 - {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 - {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 + {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 + {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 + {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 + {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 + {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 {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 - {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 + {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 + {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[] = @@ -1628,13 +1628,13 @@ namespace { 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 pOut[i] = HDRColorA(1.0f, 0.0f, 1.0f, 1.0f); -#else + #else // In production use, default to black 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 BZ: aEndPts[1].B.b |= 1 << uint32_t(desc[uCurBit].m_uBit); break; default: - { -#ifdef _DEBUG - OutputDebugStringA("BC6H: Invalid header bits encountered during decoding\n"); -#endif - FillWithErrorColors(pOut); - return; - } + { + #ifdef _DEBUG + OutputDebugStringA("BC6H: Invalid header bits encountered during decoding\n"); + #endif + FillWithErrorColors(pOut); + 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; if (uStartBit + uNumBits > 128) { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC6H: Invalid block encountered during decoding\n"); -#endif + #endif FillWithErrorColors(pOut); return; } @@ -1749,9 +1749,9 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept if (uIndex >= ((info.uPartitions > 0) ? 8 : 16)) { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC6H: Invalid index encountered during decoding\n"); -#endif + #endif FillWithErrorColors(pOut); return; } @@ -1784,7 +1784,7 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept } else { -#ifdef _DEBUG + #ifdef _DEBUG const char* warnstr = "BC6H: Invalid mode encountered during decoding\n"; 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; } OutputDebugStringA(warnstr); -#endif + #endif // Per the BC6H format spec, we must return opaque black 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); 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); } return; @@ -2409,7 +2409,7 @@ void D3DX_BC6H::GeneratePaletteUnquantized(const EncodeParams* pEP, size_t uRegi assert(false); 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); } return; @@ -2558,9 +2558,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept { if (uStartBit + RGBAPrec.r > 128) { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC7: Invalid block encountered during decoding\n"); -#endif + #endif FillWithErrorColors(pOut); return; } @@ -2573,9 +2573,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept { if (uStartBit + RGBAPrec.g > 128) { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC7: Invalid block encountered during decoding\n"); -#endif + #endif FillWithErrorColors(pOut); return; } @@ -2588,9 +2588,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept { if (uStartBit + RGBAPrec.b > 128) { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC7: Invalid block encountered during decoding\n"); -#endif + #endif FillWithErrorColors(pOut); return; } @@ -2603,9 +2603,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept { if (uStartBit + RGBAPrec.a > 128) { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC7: Invalid block encountered during decoding\n"); -#endif + #endif FillWithErrorColors(pOut); return; } @@ -2620,9 +2620,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept { if (uStartBit > 127) { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC7: Invalid block encountered during decoding\n"); -#endif + #endif FillWithErrorColors(pOut); 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; if (uStartBit + uNumBits > 128) { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC7: Invalid block encountered during decoding\n"); -#endif + #endif FillWithErrorColors(pOut); return; } @@ -2675,9 +2675,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept const size_t uNumBits = i ? uIndexPrec2 : uIndexPrec2 - 1u; if (uStartBit + uNumBits > 128) { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC7: Invalid block encountered during decoding\n"); -#endif + #endif FillWithErrorColors(pOut); return; } @@ -2717,9 +2717,9 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept } else { -#ifdef _DEBUG + #ifdef _DEBUG OutputDebugStringA("BC7: Reserved mode 8 encountered during decoding\n"); -#endif + #endif // Per the BC7 format spec, we must return transparent black 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++) { - SetBits(uStartBit, 1, aPVote[i] > (aCount[i] >> 1) ? 1u : 0u); + SetBits(uStartBit, 1, (aPVote[i] >(aCount[i] >> 1)) ? 1u : 0u); } } else diff --git a/DirectXTex/BCDirectCompute.cpp b/DirectXTex/BCDirectCompute.cpp index b7aaa09..a98ef8b 100644 --- a/DirectXTex/BCDirectCompute.cpp +++ b/DirectXTex/BCDirectCompute.cpp @@ -20,13 +20,13 @@ using Microsoft::WRL::ComPtr; namespace { - #include "BC7Encode_EncodeBlockCS.inc" - #include "BC7Encode_TryMode02CS.inc" - #include "BC7Encode_TryMode137CS.inc" - #include "BC7Encode_TryMode456CS.inc" - #include "BC6HEncode_EncodeBlockCS.inc" - #include "BC6HEncode_TryModeG10CS.inc" - #include "BC6HEncode_TryModeLE10CS.inc" +#include "BC7Encode_EncodeBlockCS.inc" +#include "BC7Encode_TryMode02CS.inc" +#include "BC7Encode_TryMode137CS.inc" +#include "BC7Encode_TryMode456CS.inc" +#include "BC6HEncode_EncodeBlockCS.inc" +#include "BC6HEncode_TryModeG10CS.inc" +#include "BC6HEncode_TryModeLE10CS.inc" struct BufferBC6HBC7 { diff --git a/DirectXTex/DDS.h b/DirectXTex/DDS.h index 25fe3e5..a88f14a 100644 --- a/DirectXTex/DDS.h +++ b/DirectXTex/DDS.h @@ -25,19 +25,19 @@ namespace DirectX #pragma pack(push,1) -constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS " + constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS " -struct DDS_PIXELFORMAT -{ - uint32_t size; - uint32_t flags; - uint32_t fourCC; - uint32_t RGBBitCount; - uint32_t RBitMask; - uint32_t GBitMask; - uint32_t BBitMask; - uint32_t ABitMask; -}; + struct DDS_PIXELFORMAT + { + uint32_t size; + uint32_t flags; + uint32_t fourCC; + uint32_t RGBBitCount; + uint32_t RBitMask; + uint32_t GBitMask; + uint32_t BBitMask; + uint32_t ABitMask; + }; #define DDS_FOURCC 0x00000004 // DDPF_FOURCC #define DDS_RGB 0x00000040 // DDPF_RGB @@ -52,7 +52,7 @@ struct DDS_PIXELFORMAT // DDS_BUMPLUMINANCE 0x00040000 #ifndef MAKEFOURCC - #define MAKEFOURCC(ch0, ch1, ch2, ch3) \ +#define MAKEFOURCC(ch0, ch1, ch2, ch3) \ (static_cast(static_cast(ch0)) \ | (static_cast(static_cast(ch1)) << 8) \ | (static_cast(static_cast(ch2)) << 16) \ @@ -60,131 +60,131 @@ struct DDS_PIXELFORMAT #endif /* MAKEFOURCC */ #ifndef DDSGLOBALCONST - #if defined(__GNUC__) && !defined(__MINGW32__) - #define DDSGLOBALCONST extern const __attribute__((weak)) - #else - #define DDSGLOBALCONST extern const __declspec(selectany) - #endif +#if defined(__GNUC__) && !defined(__MINGW32__) +#define DDSGLOBALCONST extern const __attribute__((weak)) +#else +#define DDSGLOBALCONST extern const __declspec(selectany) +#endif #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 }; -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 }; -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 }; -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 }; -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 }; -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 }; -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 }; -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 }; -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 }; -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 }; -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 }; -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 }; -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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8R8G8B8 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8R8G8B8 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8B8G8R8 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8B8G8R8 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_G16R16 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_G16R16 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A1R5G5B5 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A1R5G5B5 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A4R4G4B4 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A4R4G4B4 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_R8G8B8 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_R8G8B8 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_R3G3B2 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_R3G3B2 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L8 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L8 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L8_NVTT1 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_L8_NVTT1 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8_NVTT1 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A8L8_NVTT1 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_V8U8 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_V8U8 = { 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 }; -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_V16U16 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_V16U16 = { 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 -DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A2R10G10B10 = + DDSGLOBALCONST DDS_PIXELFORMAT DDSPF_A2R10G10B10 = { 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 }; // 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 }; // 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 }; #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 // Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION -enum DDS_RESOURCE_DIMENSION : uint32_t -{ - DDS_DIMENSION_TEXTURE1D = 2, - DDS_DIMENSION_TEXTURE2D = 3, - DDS_DIMENSION_TEXTURE3D = 4, -}; + enum DDS_RESOURCE_DIMENSION : uint32_t + { + DDS_DIMENSION_TEXTURE1D = 2, + DDS_DIMENSION_TEXTURE2D = 3, + DDS_DIMENSION_TEXTURE3D = 4, + }; -// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG -enum DDS_RESOURCE_MISC_FLAG : uint32_t -{ - DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L, -}; + // Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG + enum DDS_RESOURCE_MISC_FLAG : uint32_t + { + DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L, + }; -enum DDS_MISC_FLAGS2 : uint32_t -{ - DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L, -}; + enum DDS_MISC_FLAGS2 : uint32_t + { + DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L, + }; #ifndef DDS_ALPHA_MODE_DEFINED #define DDS_ALPHA_MODE_DEFINED -enum DDS_ALPHA_MODE : uint32_t -{ - DDS_ALPHA_MODE_UNKNOWN = 0, - DDS_ALPHA_MODE_STRAIGHT = 1, - DDS_ALPHA_MODE_PREMULTIPLIED = 2, - DDS_ALPHA_MODE_OPAQUE = 3, - DDS_ALPHA_MODE_CUSTOM = 4, -}; + enum DDS_ALPHA_MODE : uint32_t + { + DDS_ALPHA_MODE_UNKNOWN = 0, + DDS_ALPHA_MODE_STRAIGHT = 1, + DDS_ALPHA_MODE_PREMULTIPLIED = 2, + DDS_ALPHA_MODE_OPAQUE = 3, + DDS_ALPHA_MODE_CUSTOM = 4, + }; #endif -struct DDS_HEADER -{ - uint32_t size; - uint32_t flags; - uint32_t height; - uint32_t width; - uint32_t pitchOrLinearSize; - uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags - uint32_t mipMapCount; - uint32_t reserved1[11]; - DDS_PIXELFORMAT ddspf; - uint32_t caps; - uint32_t caps2; - uint32_t caps3; - uint32_t caps4; - uint32_t reserved2; -}; + struct DDS_HEADER + { + uint32_t size; + uint32_t flags; + uint32_t height; + uint32_t width; + uint32_t pitchOrLinearSize; + uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags + uint32_t mipMapCount; + uint32_t reserved1[11]; + DDS_PIXELFORMAT ddspf; + uint32_t caps; + uint32_t caps2; + uint32_t caps3; + uint32_t caps4; + uint32_t reserved2; + }; -struct DDS_HEADER_DXT10 -{ - DXGI_FORMAT dxgiFormat; - uint32_t resourceDimension; - uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG - uint32_t arraySize; - uint32_t miscFlags2; // see DDS_MISC_FLAGS2 -}; + struct DDS_HEADER_DXT10 + { + DXGI_FORMAT dxgiFormat; + uint32_t resourceDimension; + uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG + uint32_t arraySize; + uint32_t miscFlags2; // see DDS_MISC_FLAGS2 + }; #pragma pack(pop) -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) == 124, "DDS Header size mismatch"); + static_assert(sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch"); } // namespace diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index 2587d87..d9205e7 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -85,16 +85,35 @@ namespace DirectX enum CP_FLAGS : unsigned long { - CP_FLAGS_NONE = 0x0, // Normal operation - CP_FLAGS_LEGACY_DWORD = 0x1, // Assume pitch is DWORD aligned instead of BYTE aligned - 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_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 + CP_FLAGS_NONE = 0x0, + // Normal operation + + CP_FLAGS_LEGACY_DWORD = 0x1, + // Assume pitch is DWORD aligned instead of BYTE aligned + + 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_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( @@ -113,9 +132,9 @@ namespace DirectX enum TEX_DIMENSION // Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION { - TEX_DIMENSION_TEXTURE1D = 2, - TEX_DIMENSION_TEXTURE2D = 3, - TEX_DIMENSION_TEXTURE3D = 4, + TEX_DIMENSION_TEXTURE1D = 2, + TEX_DIMENSION_TEXTURE2D = 3, + TEX_DIMENSION_TEXTURE3D = 4, }; enum TEX_MISC_FLAG : unsigned long @@ -132,11 +151,11 @@ namespace DirectX enum TEX_ALPHA_MODE // Matches DDS_ALPHA_MODE, encoded in MISC_FLAGS2 { - TEX_ALPHA_MODE_UNKNOWN = 0, - TEX_ALPHA_MODE_STRAIGHT = 1, + TEX_ALPHA_MODE_UNKNOWN = 0, + TEX_ALPHA_MODE_STRAIGHT = 1, TEX_ALPHA_MODE_PREMULTIPLIED = 2, - TEX_ALPHA_MODE_OPAQUE = 3, - TEX_ALPHA_MODE_CUSTOM = 4, + TEX_ALPHA_MODE_OPAQUE = 3, + TEX_ALPHA_MODE_CUSTOM = 4, }; struct TexMetadata @@ -168,106 +187,106 @@ namespace DirectX enum DDS_FLAGS : unsigned long { - DDS_FLAGS_NONE = 0x0, + DDS_FLAGS_NONE = 0x0, - DDS_FLAGS_LEGACY_DWORD = 0x1, - // Assume pitch is DWORD aligned instead of BYTE aligned (used by some legacy DDS files) + DDS_FLAGS_LEGACY_DWORD = 0x1, + // Assume pitch is DWORD aligned instead of BYTE aligned (used by some legacy DDS files) - 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) + 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) - 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 + 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 - 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 + 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 - 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 + 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 - DDS_FLAGS_EXPAND_LUMINANCE = 0x20, - // When loading legacy luminance formats expand replicating the color channels rather than leaving them packed (L8, L16, A8L8) + DDS_FLAGS_EXPAND_LUMINANCE = 0x20, + // When loading legacy luminance formats expand replicating the color channels rather than leaving them packed (L8, L16, A8L8) - DDS_FLAGS_BAD_DXTN_TAILS = 0x40, - // Some older DXTn DDS files incorrectly handle mipchain tails for blocks smaller than 4x4 + DDS_FLAGS_BAD_DXTN_TAILS = 0x40, + // Some older DXTn DDS files incorrectly handle mipchain tails for blocks smaller than 4x4 - 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) + 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) - 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_MISC2 = 0x20000, + // DDS_FLAGS_FORCE_DX10_EXT including miscFlags2 information (result may not be compatible with D3DX10 or D3DX11) - DDS_FLAGS_FORCE_DX9_LEGACY = 0x40000, - // Force use of legacy header for DDS writer (will fail if unable to write as such) + DDS_FLAGS_FORCE_DX9_LEGACY = 0x40000, + // Force use of legacy header for DDS writer (will fail if unable to write as such) - DDS_FLAGS_ALLOW_LARGE_FILES = 0x1000000, - // Enables the loader to read large dimension .dds files (i.e. greater than known hardware requirements) + DDS_FLAGS_ALLOW_LARGE_FILES = 0x1000000, + // Enables the loader to read large dimension .dds files (i.e. greater than known hardware requirements) }; enum TGA_FLAGS : unsigned long { - TGA_FLAGS_NONE = 0x0, + TGA_FLAGS_NONE = 0x0, - TGA_FLAGS_BGR = 0x1, - // 24bpp files are returned as BGRX; 32bpp files are returned as BGRA + TGA_FLAGS_BGR = 0x1, + // 24bpp files are returned as BGRX; 32bpp files are returned as BGRA 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, - // Ignores sRGB TGA 2.0 metadata if present in the file + TGA_FLAGS_IGNORE_SRGB = 0x10, + // Ignores sRGB TGA 2.0 metadata if present in the file - TGA_FLAGS_FORCE_SRGB = 0x20, - // Writes sRGB metadata into the file reguardless of format (TGA 2.0 only) + TGA_FLAGS_FORCE_SRGB = 0x20, + // Writes sRGB metadata into the file reguardless of format (TGA 2.0 only) - TGA_FLAGS_FORCE_LINEAR = 0x40, - // Writes linear gamma metadata into the file reguardless of format (TGA 2.0 only) + TGA_FLAGS_FORCE_LINEAR = 0x40, + // Writes linear gamma metadata into the file reguardless of format (TGA 2.0 only) - TGA_FLAGS_DEFAULT_SRGB = 0x80, - // If no colorspace is specified in TGA 2.0 metadata, assume sRGB + TGA_FLAGS_DEFAULT_SRGB = 0x80, + // If no colorspace is specified in TGA 2.0 metadata, assume sRGB }; enum WIC_FLAGS : unsigned long { - WIC_FLAGS_NONE = 0x0, + WIC_FLAGS_NONE = 0x0, - 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 + 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 - WIC_FLAGS_NO_X2_BIAS = 0x2, - // Loads DXGI 1.1 X2 10:10:10:2 format as DXGI_FORMAT_R10G10B10A2_UNORM + WIC_FLAGS_NO_X2_BIAS = 0x2, + // Loads DXGI 1.1 X2 10:10:10:2 format as DXGI_FORMAT_R10G10B10A2_UNORM - WIC_FLAGS_NO_16BPP = 0x4, - // Loads 565, 5551, and 4444 formats as 8888 to avoid use of optional WDDM 1.2 formats + WIC_FLAGS_NO_16BPP = 0x4, + // Loads 565, 5551, and 4444 formats as 8888 to avoid use of optional WDDM 1.2 formats - WIC_FLAGS_ALLOW_MONO = 0x8, - // Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit grayscale + WIC_FLAGS_ALLOW_MONO = 0x8, + // Loads 1-bit monochrome (black & white) as R1_UNORM rather than 8-bit grayscale - 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 + 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 - WIC_FLAGS_IGNORE_SRGB = 0x20, - // Ignores sRGB metadata if present in the file + WIC_FLAGS_IGNORE_SRGB = 0x20, + // Ignores sRGB metadata if present in the file - WIC_FLAGS_FORCE_SRGB = 0x40, - // Writes sRGB metadata into the file reguardless of format + WIC_FLAGS_FORCE_SRGB = 0x40, + // Writes sRGB metadata into the file reguardless of format - WIC_FLAGS_FORCE_LINEAR = 0x80, - // Writes linear gamma metadata into the file reguardless of format + WIC_FLAGS_FORCE_LINEAR = 0x80, + // Writes linear gamma metadata into the file reguardless of format - WIC_FLAGS_DEFAULT_SRGB = 0x100, - // If no colorspace is specified, assume sRGB + WIC_FLAGS_DEFAULT_SRGB = 0x100, + // If no colorspace is specified, assume sRGB - WIC_FLAGS_DITHER = 0x10000, - // Use ordered 4x4 dithering for any required conversions + WIC_FLAGS_DITHER = 0x10000, + // Use ordered 4x4 dithering for any required conversions - WIC_FLAGS_DITHER_DIFFUSION = 0x20000, - // Use error-diffusion dithering for any required conversions + WIC_FLAGS_DITHER_DIFFUSION = 0x20000, + // Use error-diffusion dithering for any required conversions - WIC_FLAGS_FILTER_POINT = 0x100000, - WIC_FLAGS_FILTER_LINEAR = 0x200000, - WIC_FLAGS_FILTER_CUBIC = 0x300000, - WIC_FLAGS_FILTER_FANT = 0x400000, // Combination of Linear and Box filter + WIC_FLAGS_FILTER_POINT = 0x100000, + WIC_FLAGS_FILTER_LINEAR = 0x200000, + WIC_FLAGS_FILTER_CUBIC = 0x300000, + 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) }; @@ -515,12 +534,12 @@ namespace DirectX enum TEX_FR_FLAGS : unsigned long { - TEX_FR_ROTATE0 = 0x0, - TEX_FR_ROTATE90 = 0x1, - TEX_FR_ROTATE180 = 0x2, - TEX_FR_ROTATE270 = 0x3, - TEX_FR_FLIP_HORIZONTAL = 0x08, - TEX_FR_FLIP_VERTICAL = 0x10, + TEX_FR_ROTATE0 = 0x0, + TEX_FR_ROTATE90 = 0x1, + TEX_FR_ROTATE180 = 0x2, + TEX_FR_ROTATE270 = 0x3, + TEX_FR_FLIP_HORIZONTAL = 0x08, + TEX_FR_FLIP_VERTICAL = 0x10, }; #ifdef WIN32 @@ -533,60 +552,60 @@ namespace DirectX enum TEX_FILTER_FLAGS : unsigned long { - TEX_FILTER_DEFAULT = 0, + TEX_FILTER_DEFAULT = 0, - TEX_FILTER_WRAP_U = 0x1, - TEX_FILTER_WRAP_V = 0x2, - TEX_FILTER_WRAP_W = 0x4, - TEX_FILTER_WRAP = (TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W), - TEX_FILTER_MIRROR_U = 0x10, - TEX_FILTER_MIRROR_V = 0x20, - TEX_FILTER_MIRROR_W = 0x40, - TEX_FILTER_MIRROR = (TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W), - // Wrap vs. Mirror vs. Clamp filtering options + TEX_FILTER_WRAP_U = 0x1, + TEX_FILTER_WRAP_V = 0x2, + TEX_FILTER_WRAP_W = 0x4, + TEX_FILTER_WRAP = (TEX_FILTER_WRAP_U | TEX_FILTER_WRAP_V | TEX_FILTER_WRAP_W), + TEX_FILTER_MIRROR_U = 0x10, + TEX_FILTER_MIRROR_V = 0x20, + TEX_FILTER_MIRROR_W = 0x40, + TEX_FILTER_MIRROR = (TEX_FILTER_MIRROR_U | TEX_FILTER_MIRROR_V | TEX_FILTER_MIRROR_W), + // Wrap vs. Mirror vs. Clamp filtering options - TEX_FILTER_SEPARATE_ALPHA = 0x100, - // Resize color and alpha channel independently + TEX_FILTER_SEPARATE_ALPHA = 0x100, + // Resize color and alpha channel independently - TEX_FILTER_FLOAT_X2BIAS = 0x200, - // Enable *2 - 1 conversion cases for unorm<->float and positive-only float formats + TEX_FILTER_FLOAT_X2BIAS = 0x200, + // Enable *2 - 1 conversion cases for unorm<->float and positive-only float formats - TEX_FILTER_RGB_COPY_RED = 0x1000, - TEX_FILTER_RGB_COPY_GREEN = 0x2000, - 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 RG, defaults to copying RED | GREEN. These flags control which channels are selected instead. + TEX_FILTER_RGB_COPY_RED = 0x1000, + TEX_FILTER_RGB_COPY_GREEN = 0x2000, + 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 RG, defaults to copying RED | GREEN. These flags control which channels are selected instead. - TEX_FILTER_DITHER = 0x10000, - // Use ordered 4x4 dithering for any required conversions + TEX_FILTER_DITHER = 0x10000, + // Use ordered 4x4 dithering for any required conversions 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_LINEAR = 0x200000, - TEX_FILTER_CUBIC = 0x300000, - TEX_FILTER_BOX = 0x400000, - TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation - TEX_FILTER_TRIANGLE = 0x500000, - // Filtering mode to use for any required image resizing + TEX_FILTER_POINT = 0x100000, + TEX_FILTER_LINEAR = 0x200000, + TEX_FILTER_CUBIC = 0x300000, + TEX_FILTER_BOX = 0x400000, + TEX_FILTER_FANT = 0x400000, // Equiv to Box filtering for mipmap generation + TEX_FILTER_TRIANGLE = 0x500000, + // Filtering mode to use for any required image resizing - TEX_FILTER_SRGB_IN = 0x1000000, - TEX_FILTER_SRGB_OUT = 0x2000000, - TEX_FILTER_SRGB = (TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT), - // sRGB <-> RGB for use in conversion operations - // 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 + TEX_FILTER_SRGB_IN = 0x1000000, + TEX_FILTER_SRGB_OUT = 0x2000000, + TEX_FILTER_SRGB = (TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT), + // sRGB <-> RGB for use in conversion operations + // 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 - TEX_FILTER_FORCE_NON_WIC = 0x10000000, - // Forces use of the non-WIC path when both are an option + TEX_FILTER_FORCE_NON_WIC = 0x10000000, + // Forces use of the non-WIC path when both are an option - 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 + 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 }; - constexpr unsigned long TEX_FILTER_DITHER_MASK = 0xF0000; - constexpr unsigned long TEX_FILTER_MODE_MASK = 0xF00000; - constexpr unsigned long TEX_FILTER_SRGB_MASK = 0xF000000; + constexpr unsigned long TEX_FILTER_DITHER_MASK = 0xF0000; + constexpr unsigned long TEX_FILTER_MODE_MASK = 0xF00000; + constexpr unsigned long TEX_FILTER_SRGB_MASK = 0xF000000; HRESULT __cdecl Resize( _In_ const Image& srcImage, _In_ size_t width, _In_ size_t height, @@ -640,19 +659,19 @@ namespace DirectX enum TEX_PMALPHA_FLAGS : unsigned long { - TEX_PMALPHA_DEFAULT = 0, + TEX_PMALPHA_DEFAULT = 0, - TEX_PMALPHA_IGNORE_SRGB = 0x1, - // ignores sRGB colorspace conversions + TEX_PMALPHA_IGNORE_SRGB = 0x1, + // ignores sRGB colorspace conversions - TEX_PMALPHA_REVERSE = 0x2, - // converts from premultiplied alpha back to straight alpha + TEX_PMALPHA_REVERSE = 0x2, + // converts from premultiplied alpha back to straight alpha - TEX_PMALPHA_SRGB_IN = 0x1000000, - TEX_PMALPHA_SRGB_OUT = 0x2000000, - 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 output format type is IsSRGB(), then SRGB_OUT is on by default + TEX_PMALPHA_SRGB_IN = 0x1000000, + TEX_PMALPHA_SRGB_OUT = 0x2000000, + 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 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; @@ -663,34 +682,34 @@ namespace DirectX enum TEX_COMPRESS_FLAGS : unsigned long { - TEX_COMPRESS_DEFAULT = 0, + TEX_COMPRESS_DEFAULT = 0, - TEX_COMPRESS_RGB_DITHER = 0x10000, - // Enables dithering RGB colors for BC1-3 compression + TEX_COMPRESS_RGB_DITHER = 0x10000, + // Enables dithering RGB colors for BC1-3 compression - TEX_COMPRESS_A_DITHER = 0x20000, - // Enables dithering alpha for BC1-3 compression + TEX_COMPRESS_A_DITHER = 0x20000, + // Enables dithering alpha for BC1-3 compression - TEX_COMPRESS_DITHER = 0x30000, - // Enables both RGB and alpha dithering for BC1-3 compression + TEX_COMPRESS_DITHER = 0x30000, + // Enables both RGB and alpha dithering for BC1-3 compression - TEX_COMPRESS_UNIFORM = 0x40000, - // Uniform color weighting for BC1-3 compression; by default uses perceptual weighting + TEX_COMPRESS_UNIFORM = 0x40000, + // Uniform color weighting for BC1-3 compression; by default uses perceptual weighting - TEX_COMPRESS_BC7_USE_3SUBSETS = 0x80000, - // Enables exhaustive search for BC7 compress for mode 0 and 2; by default skips trying these modes + TEX_COMPRESS_BC7_USE_3SUBSETS = 0x80000, + // Enables exhaustive search for BC7 compress for mode 0 and 2; by default skips trying these modes - TEX_COMPRESS_BC7_QUICK = 0x100000, - // Minimal modes (usually mode 6) for BC7 compression + TEX_COMPRESS_BC7_QUICK = 0x100000, + // Minimal modes (usually mode 6) for BC7 compression - TEX_COMPRESS_SRGB_IN = 0x1000000, - TEX_COMPRESS_SRGB_OUT = 0x2000000, - 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 output format type is IsSRGB(), then SRGB_OUT is on by default + TEX_COMPRESS_SRGB_IN = 0x1000000, + TEX_COMPRESS_SRGB_OUT = 0x2000000, + 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 output format type is IsSRGB(), then SRGB_OUT is on by default - TEX_COMPRESS_PARALLEL = 0x10000000, - // Compress is free to use multithreading to improve performance (by default it does not use multithreading) + TEX_COMPRESS_PARALLEL = 0x10000000, + // Compress is free to use multithreading to improve performance (by default it does not use multithreading) }; HRESULT __cdecl Compress( @@ -721,26 +740,26 @@ namespace DirectX enum CNMAP_FLAGS : unsigned long { - CNMAP_DEFAULT = 0, + CNMAP_DEFAULT = 0, - CNMAP_CHANNEL_RED = 0x1, - CNMAP_CHANNEL_GREEN = 0x2, - CNMAP_CHANNEL_BLUE = 0x3, - CNMAP_CHANNEL_ALPHA = 0x4, + CNMAP_CHANNEL_RED = 0x1, + CNMAP_CHANNEL_GREEN = 0x2, + CNMAP_CHANNEL_BLUE = 0x3, + CNMAP_CHANNEL_ALPHA = 0x4, CNMAP_CHANNEL_LUMINANCE = 0x5, - // Channel selection when evaluting color value for height - // Luminance is a combination of red, green, and blue + // Channel selection when evaluting color value for height + // Luminance is a combination of red, green, and blue - CNMAP_MIRROR_U = 0x1000, - CNMAP_MIRROR_V = 0x2000, - CNMAP_MIRROR = 0x3000, - // Use mirror semantics for scanline references (defaults to wrap) + CNMAP_MIRROR_U = 0x1000, + CNMAP_MIRROR_V = 0x2000, + CNMAP_MIRROR = 0x3000, + // Use mirror semantics for scanline references (defaults to wrap) - CNMAP_INVERT_SIGN = 0x4000, - // Inverts normal sign + CNMAP_INVERT_SIGN = 0x4000, + // Inverts normal sign 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( @@ -770,21 +789,21 @@ namespace DirectX enum CMSE_FLAGS : unsigned long { - CMSE_DEFAULT = 0, + CMSE_DEFAULT = 0, - CMSE_IMAGE1_SRGB = 0x1, - CMSE_IMAGE2_SRGB = 0x2, - // Indicates that image needs gamma correction before comparision + CMSE_IMAGE1_SRGB = 0x1, + CMSE_IMAGE2_SRGB = 0x2, + // Indicates that image needs gamma correction before comparision - CMSE_IGNORE_RED = 0x10, - CMSE_IGNORE_GREEN = 0x20, - CMSE_IGNORE_BLUE = 0x40, - CMSE_IGNORE_ALPHA = 0x80, - // Ignore the channel when computing MSE + CMSE_IGNORE_RED = 0x10, + CMSE_IGNORE_GREEN = 0x20, + CMSE_IGNORE_BLUE = 0x40, + CMSE_IGNORE_ALPHA = 0x80, + // Ignore the channel when computing MSE - CMSE_IMAGE1_X2_BIAS = 0x100, - CMSE_IMAGE2_X2_BIAS = 0x200, - // Indicates that image should be scaled and biased before comparison (i.e. UNORM -> SNORM) + CMSE_IMAGE1_X2_BIAS = 0x100, + CMSE_IMAGE2_X2_BIAS = 0x200, + // 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; @@ -799,12 +818,12 @@ namespace DirectX HRESULT __cdecl TransformImage( _In_ const Image& image, _In_ std::function pixelFunc, + _In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc, ScratchImage& result); HRESULT __cdecl TransformImage( _In_reads_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ std::function pixelFunc, + _In_reads_(width) const XMVECTOR* inPixels, size_t width, size_t y)> pixelFunc, ScratchImage& result); //--------------------------------------------------------------------------------- diff --git a/DirectXTex/DirectXTex.inl b/DirectXTex/DirectXTex.inl index 6b28431..c5aeede 100644 --- a/DirectXTex/DirectXTex.inl +++ b/DirectXTex/DirectXTex.inl @@ -53,31 +53,31 @@ inline bool __cdecl IsCompressed(DXGI_FORMAT fmt) noexcept { switch (fmt) { - case DXGI_FORMAT_BC1_TYPELESS: - case DXGI_FORMAT_BC1_UNORM: - case DXGI_FORMAT_BC1_UNORM_SRGB: - case DXGI_FORMAT_BC2_TYPELESS: - case DXGI_FORMAT_BC2_UNORM: - case DXGI_FORMAT_BC2_UNORM_SRGB: - case DXGI_FORMAT_BC3_TYPELESS: - case DXGI_FORMAT_BC3_UNORM: - case DXGI_FORMAT_BC3_UNORM_SRGB: - case DXGI_FORMAT_BC4_TYPELESS: - case DXGI_FORMAT_BC4_UNORM: - case DXGI_FORMAT_BC4_SNORM: - case DXGI_FORMAT_BC5_TYPELESS: - case DXGI_FORMAT_BC5_UNORM: - case DXGI_FORMAT_BC5_SNORM: - case DXGI_FORMAT_BC6H_TYPELESS: - case DXGI_FORMAT_BC6H_UF16: - case DXGI_FORMAT_BC6H_SF16: - case DXGI_FORMAT_BC7_TYPELESS: - case DXGI_FORMAT_BC7_UNORM: - case DXGI_FORMAT_BC7_UNORM_SRGB: - return true; + case DXGI_FORMAT_BC1_TYPELESS: + case DXGI_FORMAT_BC1_UNORM: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC2_TYPELESS: + case DXGI_FORMAT_BC2_UNORM: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_TYPELESS: + case DXGI_FORMAT_BC3_UNORM: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_BC4_TYPELESS: + case DXGI_FORMAT_BC4_UNORM: + case DXGI_FORMAT_BC4_SNORM: + case DXGI_FORMAT_BC5_TYPELESS: + case DXGI_FORMAT_BC5_UNORM: + case DXGI_FORMAT_BC5_SNORM: + case DXGI_FORMAT_BC6H_TYPELESS: + case DXGI_FORMAT_BC6H_UF16: + case DXGI_FORMAT_BC6H_SF16: + case DXGI_FORMAT_BC7_TYPELESS: + case DXGI_FORMAT_BC7_UNORM: + case DXGI_FORMAT_BC7_UNORM_SRGB: + return true; - default: - return false; + default: + return false; } } @@ -86,14 +86,14 @@ inline bool __cdecl IsPalettized(DXGI_FORMAT fmt) noexcept { switch (fmt) { - case DXGI_FORMAT_AI44: - case DXGI_FORMAT_IA44: - case DXGI_FORMAT_P8: - case DXGI_FORMAT_A8P8: - return true; + case DXGI_FORMAT_AI44: + case DXGI_FORMAT_IA44: + case DXGI_FORMAT_P8: + case DXGI_FORMAT_A8P8: + return true; - default: - return false; + default: + return false; } } @@ -102,17 +102,17 @@ inline bool __cdecl IsSRGB(DXGI_FORMAT fmt) noexcept { switch (fmt) { - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - case DXGI_FORMAT_BC1_UNORM_SRGB: - case DXGI_FORMAT_BC2_UNORM_SRGB: - case DXGI_FORMAT_BC3_UNORM_SRGB: - case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - case DXGI_FORMAT_BC7_UNORM_SRGB: - return true; + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: + case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: + case DXGI_FORMAT_BC7_UNORM_SRGB: + return true; - default: - return false; + default: + return false; } } diff --git a/DirectXTex/DirectXTexCompress.cpp b/DirectXTex/DirectXTexCompress.cpp index af6a9a2..99385a9 100644 --- a/DirectXTex/DirectXTexCompress.cpp +++ b/DirectXTex/DirectXTexCompress.cpp @@ -158,7 +158,7 @@ namespace { 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]]; } } @@ -170,7 +170,7 @@ namespace { 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]; } } @@ -239,7 +239,7 @@ namespace bool fail = false; -#pragma omp parallel for + #pragma omp parallel for for (int nb = 0; nb < static_cast(nBlocks); ++nb) { const int nbWidth = std::max(1, int((image.width + 3) / 4)); @@ -615,11 +615,11 @@ HRESULT DirectX::Compress( // Compress single image if (compress & TEX_COMPRESS_PARALLEL) { -#ifndef _OPENMP + #ifndef _OPENMP return E_NOTIMPL; -#else + #else hr = CompressBC_Parallel(srcImage, *img, GetBCFlags(compress), GetSRGBFlags(compress), threshold); -#endif // _OPENMP + #endif // _OPENMP } else { @@ -687,9 +687,9 @@ HRESULT DirectX::Compress( if ((compress & TEX_COMPRESS_PARALLEL)) { -#ifndef _OPENMP + #ifndef _OPENMP return E_NOTIMPL; -#else + #else if (compress & TEX_COMPRESS_PARALLEL) { hr = CompressBC_Parallel(src, dest[index], GetBCFlags(compress), GetSRGBFlags(compress), threshold); @@ -699,7 +699,7 @@ HRESULT DirectX::Compress( return hr; } } -#endif // _OPENMP + #endif // _OPENMP } else { diff --git a/DirectXTex/DirectXTexCompressGPU.cpp b/DirectXTex/DirectXTexCompressGPU.cpp index e4575e0..fb9d84d 100644 --- a/DirectXTex/DirectXTexCompressGPU.cpp +++ b/DirectXTex/DirectXTexCompressGPU.cpp @@ -311,108 +311,108 @@ HRESULT DirectX::Compress( { case TEX_DIMENSION_TEXTURE1D: 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); - if (FAILED(hr)) + size_t w = metadata.width; + size_t h = metadata.height; + + for (size_t level = 0; level < metadata.mipLevels; ++level) { - cImages.Release(); - 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); + hr = gpubc->Prepare(w, h, compress, format, alphaWeight); if (FAILED(hr)) { cImages.Release(); 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: - { - 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); - if (FAILED(hr)) + size_t w = metadata.width; + size_t h = metadata.height; + size_t d = metadata.depth; + + for (size_t level = 0; level < metadata.mipLevels; ++level) { - cImages.Release(); - 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); + hr = gpubc->Prepare(w, h, compress, format, alphaWeight); if (FAILED(hr)) { cImages.Release(); 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: return HRESULT_E_NOT_SUPPORTED; diff --git a/DirectXTex/DirectXTexConvert.cpp b/DirectXTex/DirectXTexConvert.cpp index 13df775..d39e6a1 100644 --- a/DirectXTex/DirectXTexConvert.cpp +++ b/DirectXTex/DirectXTexConvert.cpp @@ -69,7 +69,8 @@ namespace { Exponent--; Mantissa <<= 1; - } while ((Mantissa & 0x80) == 0); + } + while ((Mantissa & 0x80) == 0); Mantissa &= 0x7F; } @@ -135,7 +136,8 @@ namespace { Exponent--; Mantissa <<= 1; - } while ((Mantissa & 0x40) == 0); + } + while ((Mantissa & 0x40) == 0); Mantissa &= 0x3F; } @@ -190,9 +192,9 @@ namespace #endif 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_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_HalfMin = { { { -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 } } }; } //------------------------------------------------------------------------------------- @@ -776,11 +778,11 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( switch (static_cast(format)) { case DXGI_FORMAT_R32G32B32A32_FLOAT: - { - const size_t msize = (size > (sizeof(XMVECTOR)*count)) ? (sizeof(XMVECTOR)*count) : size; - memcpy(dPtr, pSource, msize); - } - return true; + { + const size_t msize = (size > (sizeof(XMVECTOR)*count)) ? (sizeof(XMVECTOR)*count) : size; + memcpy(dPtr, pSource, msize); + } + return true; case DXGI_FORMAT_R32G32B32A32_UINT: LOAD_SCANLINE(XMUINT4, XMLoadUInt4) @@ -822,6 +824,24 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( LOAD_SCANLINE2(XMINT2, XMLoadSInt2, g_XMIdentityR3) case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: + { + constexpr size_t psize = sizeof(float) + sizeof(uint32_t); + if (size >= psize) + { + auto sPtr = static_cast(pSource); + for (size_t icount = 0; icount < (size - psize + 1); icount += psize) + { + auto ps8 = reinterpret_cast(&sPtr[1]); + if (dPtr >= ePtr) break; + *(dPtr++) = XMVectorSet(sPtr[0], static_cast(*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); if (size >= psize) @@ -829,9 +849,8 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( auto sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - psize + 1); icount += psize) { - auto ps8 = reinterpret_cast(&sPtr[1]); if (dPtr >= ePtr) break; - *(dPtr++) = XMVectorSet(sPtr[0], static_cast(*ps8), 0.f, 1.f); + *(dPtr++) = XMVectorSet(sPtr[0], 0.f /* typeless component assumed zero */, 0.f, 1.f); sPtr += 2; } return true; @@ -839,40 +858,23 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( } 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(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: - { - constexpr size_t psize = sizeof(float) + sizeof(uint32_t); - if (size >= psize) { - auto sPtr = static_cast(pSource); - for (size_t icount = 0; icount < (size - psize + 1); icount += psize) + constexpr size_t psize = sizeof(float) + sizeof(uint32_t); + if (size >= psize) { - auto pg8 = reinterpret_cast(&sPtr[1]); - if (dPtr >= ePtr) break; - *(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, static_cast(*pg8), 0.f, 1.f); - sPtr += 2; + auto sPtr = static_cast(pSource); + for (size_t icount = 0; icount < (size - psize + 1); icount += psize) + { + auto pg8 = reinterpret_cast(&sPtr[1]); + if (dPtr >= ePtr) break; + *(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, static_cast(*pg8), 0.f, 1.f); + sPtr += 2; + } + return true; } - return true; } - } - return false; + return false; case DXGI_FORMAT_R10G10B10A2_UNORM: LOAD_SCANLINE(XMUDECN4, XMLoadUDecN4) @@ -1687,26 +1689,26 @@ bool DirectX::Internal::StoreScanline( STORE_SCANLINE(XMINT2, XMStoreSInt2) case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: - { - constexpr size_t psize = sizeof(float) + sizeof(uint32_t); - if (size >= psize) { - auto dPtr = static_cast(pDestination); - for (size_t icount = 0; icount < (size - psize + 1); icount += psize) + constexpr size_t psize = sizeof(float) + sizeof(uint32_t); + if (size >= psize) { - if (sPtr >= ePtr) break; - XMFLOAT4 f; - XMStoreFloat4(&f, *sPtr++); - dPtr[0] = f.x; - auto ps8 = reinterpret_cast(&dPtr[1]); - ps8[0] = static_cast(std::min(255.f, std::max(0.f, f.y))); - ps8[1] = ps8[2] = ps8[3] = 0; - dPtr += 2; + auto dPtr = static_cast(pDestination); + for (size_t icount = 0; icount < (size - psize + 1); icount += psize) + { + if (sPtr >= ePtr) break; + XMFLOAT4 f; + XMStoreFloat4(&f, *sPtr++); + dPtr[0] = f.x; + auto ps8 = reinterpret_cast(&dPtr[1]); + ps8[0] = static_cast(std::min(255.f, std::max(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: 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)) { case TEX_FILTER_RGB_COPY_GREEN: - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) { - const XMVECTOR v = *ptr; - const XMVECTOR v1 = XMVectorSplatY(v); - *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); + XMVECTOR* ptr = pBuffer; + for (size_t i = 0; i < count; ++i) + { + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatY(v); + *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); + } } - } - break; + break; case TEX_FILTER_RGB_COPY_BLUE: - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) { - const XMVECTOR v = *ptr; - const XMVECTOR v1 = XMVectorSplatZ(v); - *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); + XMVECTOR* ptr = pBuffer; + for (size_t i = 0; i < count; ++i) + { + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatZ(v); + *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); + } } - } - break; + break; default: 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; } -#if (__cplusplus >= 201703L) + #if (__cplusplus >= 201703L) [[fallthrough]]; -#elif defined(__clang__) + #elif defined(__clang__) [[clang::fallthrough]]; -#elif defined(_MSC_VER) + #elif defined(_MSC_VER) __fallthrough; -#endif + #endif case TEX_FILTER_RGB_COPY_RED: - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) { - const XMVECTOR v = *ptr; - const XMVECTOR v1 = XMVectorSplatX(v); - *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); + XMVECTOR* ptr = pBuffer; + for (size_t i = 0; i < count; ++i) + { + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatX(v); + *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); + } } - } - break; + break; } // 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)) { case TEX_FILTER_RGB_COPY_GREEN: - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) { - const XMVECTOR v = *ptr; - *ptr++ = XMVectorSplatY(v); + XMVECTOR* ptr = pBuffer; + for (size_t i = 0; i < count; ++i) + { + const XMVECTOR v = *ptr; + *ptr++ = XMVectorSplatY(v); + } } - } - break; + break; case TEX_FILTER_RGB_COPY_BLUE: - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) { - const XMVECTOR v = *ptr; - *ptr++ = XMVectorSplatZ(v); + XMVECTOR* ptr = pBuffer; + for (size_t i = 0; i < count; ++i) + { + const XMVECTOR v = *ptr; + *ptr++ = XMVectorSplatZ(v); + } } - } - break; + break; default: 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; } -#if (__cplusplus >= 201703L) + #if (__cplusplus >= 201703L) [[fallthrough]]; -#elif defined(__clang__) + #elif defined(__clang__) [[clang::fallthrough]]; -#elif defined(_MSC_VER) + #elif defined(_MSC_VER) __fallthrough; -#endif + #endif case TEX_FILTER_RGB_COPY_RED: - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) { - const XMVECTOR v = *ptr; - *ptr++ = XMVectorSplatX(v); + XMVECTOR* ptr = pBuffer; + 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)) @@ -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)) { case TEX_FILTER_RGB_COPY_GREEN: - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) { - const XMVECTOR v = *ptr; - const XMVECTOR v1 = XMVectorSplatY(v); - *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); + XMVECTOR* ptr = pBuffer; + for (size_t i = 0; i < count; ++i) + { + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatY(v); + *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); + } } - } - break; + break; case TEX_FILTER_RGB_COPY_BLUE: - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) { - const XMVECTOR v = *ptr; - const XMVECTOR v1 = XMVectorSplatZ(v); - *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); + XMVECTOR* ptr = pBuffer; + for (size_t i = 0; i < count; ++i) + { + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatZ(v); + *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); + } } - } - break; + break; default: if (in->flags & CONVF_UNORM) @@ -3652,13 +3654,13 @@ void DirectX::Internal::ConvertScanline( break; } -#if (__cplusplus >= 201703L) + #if (__cplusplus >= 201703L) [[fallthrough]]; -#elif defined(__clang__) + #elif defined(__clang__) [[clang::fallthrough]]; -#elif defined(_MSC_VER) + #elif defined(_MSC_VER) __fallthrough; -#endif + #endif case TEX_FILTER_RGB_COPY_RED: // Leave data unchanged and the store will handle this... @@ -3670,31 +3672,31 @@ void DirectX::Internal::ConvertScanline( // RGB format -> RG format switch (static_cast(flags & (TEX_FILTER_RGB_COPY_RED | TEX_FILTER_RGB_COPY_GREEN | TEX_FILTER_RGB_COPY_BLUE))) { - case static_cast(TEX_FILTER_RGB_COPY_RED) | static_cast(TEX_FILTER_RGB_COPY_BLUE): - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) + case (static_cast(TEX_FILTER_RGB_COPY_RED) | static_cast(TEX_FILTER_RGB_COPY_BLUE)): { - const XMVECTOR v = *ptr; - const XMVECTOR v1 = XMVectorSwizzle<0, 2, 0, 2>(v); - *ptr++ = XMVectorSelect(v, v1, g_XMSelect1100); + XMVECTOR* ptr = pBuffer; + for (size_t i = 0; i < count; ++i) + { + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSwizzle<0, 2, 0, 2>(v); + *ptr++ = XMVectorSelect(v, v1, g_XMSelect1100); + } } - } - break; + break; - case static_cast(TEX_FILTER_RGB_COPY_GREEN) | static_cast(TEX_FILTER_RGB_COPY_BLUE): - { - XMVECTOR* ptr = pBuffer; - for (size_t i = 0; i < count; ++i) + case (static_cast(TEX_FILTER_RGB_COPY_GREEN) | static_cast(TEX_FILTER_RGB_COPY_BLUE)): { - const XMVECTOR v = *ptr; - const XMVECTOR v1 = XMVectorSwizzle<1, 2, 3, 0>(v); - *ptr++ = XMVectorSelect(v, v1, g_XMSelect1100); + XMVECTOR* ptr = pBuffer; + for (size_t i = 0; i < count; ++i) + { + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSwizzle<1, 2, 3, 0>(v); + *ptr++ = XMVectorSelect(v, v1, g_XMSelect1100); + } } - } - break; + break; - case static_cast(TEX_FILTER_RGB_COPY_RED) | static_cast(TEX_FILTER_RGB_COPY_GREEN): + case (static_cast(TEX_FILTER_RGB_COPY_RED) | static_cast(TEX_FILTER_RGB_COPY_GREEN)): default: // Leave data unchanged and the store will handle this... break; @@ -3733,15 +3735,15 @@ namespace -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_Scale15pc = { { { 32767.f, 32767.f, 32767.f, 32767.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_Scale8pc = { { { 255.f, 255.f, 255.f, 255.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_Scale16pc = { { { 65535.f, 65535.f, 65535.f, 65535.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_Scale9pc = { { { 511.f, 511.f, 511.f, 3.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_Scale565pc = { { { 31.f, 63.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_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)) { 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 MaxXR = { { { 1.2529f, 1.2529f, 1.2529f, 1.0f } } }; @@ -4018,8 +4020,8 @@ bool DirectX::Internal::StoreScanlineDither( vError = XMVectorDivide(vError, Scale); // Distribute error to next scanline and next pixel - pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); - pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); + pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); + pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]); vError = XMVectorMultiply(vError, g_ErrorWeight7); } @@ -4075,8 +4077,8 @@ bool DirectX::Internal::StoreScanlineDither( case DXGI_FORMAT_D24_UNORM_S8_UINT: if (size >= sizeof(uint32_t)) { - 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 Clamp = { { { 1.f, 255.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 } } }; uint32_t * __restrict dest = static_cast(pDestination); @@ -4097,8 +4099,8 @@ bool DirectX::Internal::StoreScanlineDither( vError = XMVectorDivide(vError, Scale); // Distribute error to next scanline and next pixel - pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); - pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); + pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); + pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]); vError = XMVectorMultiply(vError, g_ErrorWeight7); } @@ -4185,8 +4187,8 @@ bool DirectX::Internal::StoreScanlineDither( vError = XMVectorDivide(vError, g_Scale565pc); // Distribute error to next scanline and next pixel - pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); - pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); + pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); + pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]); vError = XMVectorMultiply(vError, g_ErrorWeight7); } @@ -4234,8 +4236,8 @@ bool DirectX::Internal::StoreScanlineDither( vError = XMVectorDivide(vError, g_Scale5551pc); // Distribute error to next scanline and next pixel - pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); - pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); + pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); + pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]); vError = XMVectorMultiply(vError, g_ErrorWeight7); } @@ -4289,8 +4291,8 @@ bool DirectX::Internal::StoreScanlineDither( vError = XMVectorDivide(vError, g_Scale8pc); // Distribute error to next scanline and next pixel - pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); - pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); + pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); + pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]); vError = XMVectorMultiply(vError, g_ErrorWeight7); } @@ -4344,8 +4346,8 @@ bool DirectX::Internal::StoreScanlineDither( vError = XMVectorDivide(vError, g_Scale4pc); // Distribute error to next scanline and next pixel - pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); - pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); + pDiffusionErrors[index - delta] = XMVectorMultiplyAdd(g_ErrorWeight3, vError, pDiffusionErrors[index - delta]); + pDiffusionErrors[index + 1] = XMVectorMultiplyAdd(g_ErrorWeight5, vError, pDiffusionErrors[index + 1]); pDiffusionErrors[index + 2 + delta] = XMVectorMultiplyAdd(g_ErrorWeight1, vError, pDiffusionErrors[index + 2 + delta]); vError = XMVectorMultiply(vError, g_ErrorWeight7); } @@ -4392,14 +4394,14 @@ namespace _Out_ WICPixelFormatGUID& pfGUID, _Out_ WICPixelFormatGUID& targetGUID) noexcept { -#ifndef WIN32 + #ifndef WIN32 UNREFERENCED_PARAMETER(filter); UNREFERENCED_PARAMETER(sformat); UNREFERENCED_PARAMETER(tformat); UNREFERENCED_PARAMETER(pfGUID); UNREFERENCED_PARAMETER(targetGUID); return false; -#else + #else memset(&pfGUID, 0, sizeof(GUID)); memset(&targetGUID, 0, sizeof(GUID)); @@ -4434,7 +4436,7 @@ namespace } // 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 || sformat == DXGI_FORMAT_R16_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 return false; } -#endif + #endif switch (sformat) { @@ -4541,7 +4543,7 @@ namespace } return true; -#endif // WIN32 + #endif // WIN32 } //------------------------------------------------------------------------------------- @@ -4555,7 +4557,7 @@ namespace _In_ float threshold, _In_ const Image& destImage) { -#ifndef WIN32 + #ifndef WIN32 UNREFERENCED_PARAMETER(srcImage); UNREFERENCED_PARAMETER(pfGUID); UNREFERENCED_PARAMETER(targetGUID); @@ -4563,7 +4565,7 @@ namespace UNREFERENCED_PARAMETER(threshold); UNREFERENCED_PARAMETER(destImage); return E_NOTIMPL; -#else + #else assert(srcImage.width == destImage.width); assert(srcImage.height == destImage.height); @@ -4609,7 +4611,7 @@ namespace return hr; 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 { assert(srcImage.width == destImage.width); @@ -4787,17 +4793,17 @@ namespace { case DXGI_FORMAT_NV12: assert(destImage.format == DXGI_FORMAT_YUY2); - CONVERT_420_TO_422(uint8_t, XMUBYTEN4) + CONVERT_420_TO_422(uint8_t, XMUBYTEN4); return S_OK; case DXGI_FORMAT_P010: assert(destImage.format == DXGI_FORMAT_Y210); - CONVERT_420_TO_422(uint16_t, XMUSHORTN4) + CONVERT_420_TO_422(uint16_t, XMUSHORTN4); return S_OK; case DXGI_FORMAT_P016: assert(destImage.format == DXGI_FORMAT_Y216); - CONVERT_420_TO_422(uint16_t, XMUSHORTN4) + CONVERT_420_TO_422(uint16_t, XMUSHORTN4); return S_OK; case DXGI_FORMAT_NV11: @@ -5007,62 +5013,62 @@ HRESULT DirectX::Convert( break; 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(); - return E_FAIL; + if (index >= nimages) + { + 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 (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; - } + if (d > 1) + d >>= 1; } - - if (d > 1) - d >>= 1; } - } - break; + break; default: result.Release(); diff --git a/DirectXTex/DirectXTexD3D11.cpp b/DirectXTex/DirectXTexD3D11.cpp index 54fb2c8..254e7b3 100644 --- a/DirectXTex/DirectXTexD3D11.cpp +++ b/DirectXTex/DirectXTexD3D11.cpp @@ -39,7 +39,7 @@ namespace if (!pContext || !pSource || !result.GetPixels()) return E_POINTER; -#if defined(_XBOX_ONE) && defined(_TITLE) + #if defined(_XBOX_ONE) && defined(_TITLE) ComPtr d3dDevice; pContext->GetDevice(d3dDevice.GetAddressOf()); @@ -64,7 +64,7 @@ namespace } } -#endif + #endif if (metadata.IsVolumemap()) { @@ -546,59 +546,59 @@ HRESULT DirectX::CreateTextureEx( switch (metadata.dimension) { case TEX_DIMENSION_TEXTURE1D: - { - D3D11_TEXTURE1D_DESC desc = {}; - desc.Width = static_cast(metadata.width); - desc.MipLevels = static_cast(metadata.mipLevels); - desc.ArraySize = static_cast(metadata.arraySize); - desc.Format = tformat; - desc.Usage = usage; - desc.BindFlags = bindFlags; - desc.CPUAccessFlags = cpuAccessFlags; - desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); - - hr = pDevice->CreateTexture1D(&desc, initData.get(), reinterpret_cast(ppResource)); - } - break; - - case TEX_DIMENSION_TEXTURE2D: - { - D3D11_TEXTURE2D_DESC desc = {}; - desc.Width = static_cast(metadata.width); - desc.Height = static_cast(metadata.height); - desc.MipLevels = static_cast(metadata.mipLevels); - desc.ArraySize = static_cast(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 + { + D3D11_TEXTURE1D_DESC desc = {}; + desc.Width = static_cast(metadata.width); + desc.MipLevels = static_cast(metadata.mipLevels); + desc.ArraySize = static_cast(metadata.arraySize); + desc.Format = tformat; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpuAccessFlags; desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); - hr = pDevice->CreateTexture2D(&desc, initData.get(), reinterpret_cast(ppResource)); - } - break; + hr = pDevice->CreateTexture1D(&desc, initData.get(), reinterpret_cast(ppResource)); + } + break; + + case TEX_DIMENSION_TEXTURE2D: + { + D3D11_TEXTURE2D_DESC desc = {}; + desc.Width = static_cast(metadata.width); + desc.Height = static_cast(metadata.height); + desc.MipLevels = static_cast(metadata.mipLevels); + desc.ArraySize = static_cast(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(D3D11_RESOURCE_MISC_TEXTURECUBE); + + hr = pDevice->CreateTexture2D(&desc, initData.get(), reinterpret_cast(ppResource)); + } + break; case TEX_DIMENSION_TEXTURE3D: - { - D3D11_TEXTURE3D_DESC desc = {}; - desc.Width = static_cast(metadata.width); - desc.Height = static_cast(metadata.height); - desc.Depth = static_cast(metadata.depth); - desc.MipLevels = static_cast(metadata.mipLevels); - desc.Format = tformat; - desc.Usage = usage; - desc.BindFlags = bindFlags; - desc.CPUAccessFlags = cpuAccessFlags; - desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); + { + D3D11_TEXTURE3D_DESC desc = {}; + desc.Width = static_cast(metadata.width); + desc.Height = static_cast(metadata.height); + desc.Depth = static_cast(metadata.depth); + desc.MipLevels = static_cast(metadata.mipLevels); + desc.Format = tformat; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpuAccessFlags; + desc.MiscFlags = miscFlags & ~static_cast(D3D11_RESOURCE_MISC_TEXTURECUBE); - hr = pDevice->CreateTexture3D(&desc, initData.get(), reinterpret_cast(ppResource)); - } - break; + hr = pDevice->CreateTexture3D(&desc, initData.get(), reinterpret_cast(ppResource)); + } + break; } return hr; @@ -744,215 +744,215 @@ HRESULT DirectX::CaptureTexture( switch (resType) { case D3D11_RESOURCE_DIMENSION_TEXTURE1D: - { - ComPtr pTexture; - hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf())); - if (FAILED(hr)) - break; - - assert(pTexture); - - D3D11_TEXTURE1D_DESC desc; - pTexture->GetDesc(&desc); - - ComPtr 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()); + ComPtr pTexture; + hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf())); if (FAILED(hr)) break; - assert(pStaging); + assert(pTexture); - pContext->CopyResource(pStaging.Get(), pSource); + D3D11_TEXTURE1D_DESC desc; + pTexture->GetDesc(&desc); + + ComPtr 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); } - - 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; + break; case D3D11_RESOURCE_DIMENSION_TEXTURE2D: - { - ComPtr pTexture; - hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf())); - if (FAILED(hr)) - break; - - assert(pTexture); - - D3D11_TEXTURE2D_DESC desc; - pTexture->GetDesc(&desc); - - ComPtr pStaging; - if (desc.SampleDesc.Count > 1) { - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - - ComPtr pTemp; - hr = pDevice->CreateTexture2D(&desc, nullptr, pTemp.GetAddressOf()); + ComPtr pTexture; + hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf())); if (FAILED(hr)) break; - assert(pTemp); + assert(pTexture); - DXGI_FORMAT fmt = desc.Format; - if (IsTypeless(fmt)) + D3D11_TEXTURE2D_DESC desc; + pTexture->GetDesc(&desc); + + ComPtr pStaging; + if (desc.SampleDesc.Count > 1) { - // Assume a UNORM if it exists otherwise use FLOAT - fmt = MakeTypelessUNORM(fmt); - fmt = MakeTypelessFLOAT(fmt); - } + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; - UINT support = 0; - hr = pDevice->CheckFormatSupport(fmt, &support); - if (FAILED(hr)) - break; + ComPtr pTemp; + hr = pDevice->CreateTexture2D(&desc, nullptr, pTemp.GetAddressOf()); + if (FAILED(hr)) + break; - if (!(support & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE)) - { - hr = E_FAIL; - break; - } + assert(pTemp); - for (UINT item = 0; item < desc.ArraySize; ++item) - { - for (UINT level = 0; level < desc.MipLevels; ++level) + DXGI_FORMAT fmt = desc.Format; + if (IsTypeless(fmt)) { - const UINT index = D3D11CalcSubresource(level, item, desc.MipLevels); - pContext->ResolveSubresource(pTemp.Get(), index, pSource, index, fmt); + // Assume a UNORM if it exists otherwise use FLOAT + 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; - desc.MiscFlags &= D3D11_RESOURCE_MISC_TEXTURECUBE; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - desc.Usage = D3D11_USAGE_STAGING; + 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 = pDevice->CreateTexture2D(&desc, nullptr, pStaging.GetAddressOf()); + hr = result.Initialize(mdata); if (FAILED(hr)) break; - assert(pStaging); - - pContext->CopyResource(pStaging.Get(), pTemp.Get()); + hr = Capture(pContext, pStaging.Get(), mdata, result); } - 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); - } - - 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; + break; case D3D11_RESOURCE_DIMENSION_TEXTURE3D: - { - ComPtr pTexture; - hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf())); - if (FAILED(hr)) - break; - - assert(pTexture); - - D3D11_TEXTURE3D_DESC desc; - pTexture->GetDesc(&desc); - - ComPtr 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()); + ComPtr pTexture; + hr = pSource->QueryInterface(IID_GRAPHICS_PPV_ARGS(pTexture.GetAddressOf())); if (FAILED(hr)) break; - assert(pStaging); + assert(pTexture); - pContext->CopyResource(pStaging.Get(), pSource); + D3D11_TEXTURE3D_DESC desc; + pTexture->GetDesc(&desc); + + ComPtr 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); } - - 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; + break; default: hr = E_FAIL; diff --git a/DirectXTex/DirectXTexD3D12.cpp b/DirectXTex/DirectXTexD3D12.cpp index a0c9a25..81a0eeb 100644 --- a/DirectXTex/DirectXTexD3D12.cpp +++ b/DirectXTex/DirectXTexD3D12.cpp @@ -144,7 +144,7 @@ namespace } numberOfResources = (desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) - ? 1u : desc.DepthOrArraySize; + ? 1u : desc.DepthOrArraySize; numberOfResources *= desc.MipLevels; numberOfResources *= numberOfPlanes; @@ -304,11 +304,11 @@ namespace // Block until the copy is complete while (fence->GetCompletedValue() < 1) { -#ifdef WIN32 + #ifdef WIN32 SwitchToThread(); -#else + #else std::this_thread::yield(); -#endif + #endif } return S_OK; @@ -477,8 +477,8 @@ HRESULT DirectX::CreateTextureEx( desc.Height = static_cast(metadata.height); desc.MipLevels = static_cast(metadata.mipLevels); desc.DepthOrArraySize = (metadata.dimension == TEX_DIMENSION_TEXTURE3D) - ? static_cast(metadata.depth) - : static_cast(metadata.arraySize); + ? static_cast(metadata.depth) + : static_cast(metadata.arraySize); desc.Format = format; desc.Flags = resFlags; desc.SampleDesc.Count = 1; @@ -524,7 +524,7 @@ HRESULT DirectX::PrepareUpload( } size_t numberOfResources = (metadata.dimension == TEX_DIMENSION_TEXTURE3D) - ? 1u : metadata.arraySize; + ? 1u : metadata.arraySize; numberOfResources *= metadata.mipLevels; numberOfResources *= numberOfPlanes; @@ -691,7 +691,7 @@ HRESULT DirectX::CaptureTexture( switch (desc.Dimension) { - case D3D12_RESOURCE_DIMENSION_TEXTURE1D: + case D3D12_RESOURCE_DIMENSION_TEXTURE1D: { TexMetadata mdata; mdata.width = static_cast(desc.Width); diff --git a/DirectXTex/DirectXTexDDS.cpp b/DirectXTex/DirectXTexDDS.cpp index 8b76092..b89a9e2 100644 --- a/DirectXTex/DirectXTexDDS.cpp +++ b/DirectXTex/DirectXTexDDS.cpp @@ -1305,198 +1305,198 @@ namespace { case TEX_DIMENSION_TEXTURE1D: case TEX_DIMENSION_TEXTURE2D: - { - size_t index = 0; - for (size_t item = 0; item < metadata.arraySize; ++item) { - size_t lastgood = 0; - 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) - 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 lastgood = 0; + for (size_t level = 0; level < metadata.mipLevels; ++level, ++index) { - size_t csize = std::min(images[index].slicePitch, timages[index].slicePitch); - memcpy(pDest, pSrc, csize); + if (index >= nimages) + return E_FAIL; - if (cpFlags & CP_FLAGS_BAD_DXTN_TAILS) - { - if (images[index].width < 4 || images[index].height < 4) - { - csize = std::min(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; + if (images[index].height != timages[index].height) + return E_FAIL; - const size_t csize = std::min(dpitch, spitch); - for (size_t h = 0; h < count; ++h) + 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(images[index].slicePitch, timages[index].slicePitch); 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 (cpFlags & CP_FLAGS_BAD_DXTN_TAILS) { - 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, - pSrc, spitch, - (convFlags & CONV_FLAGS_565) ? DXGI_FORMAT_B5G6R5_UNORM : DXGI_FORMAT_B5G5R5A1_UNORM, - tflags)) - return E_FAIL; + csize = std::min(images[index].slicePitch, timages[lastgood].slicePitch); + memcpy(pDest, timages[lastgood].pixels, csize); } else { - const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags); - if (!LegacyExpandScanline(pDest, dpitch, metadata.format, - pSrc, spitch, lformat, pal8, - tflags)) - return E_FAIL; + lastgood = index; } } - else if (convFlags & CONV_FLAGS_SWIZZLE) - { - SwizzleScanline(pDest, dpitch, pSrc, spitch, - metadata.format, tflags); - } - else - { - CopyScanline(pDest, dpitch, pSrc, spitch, - metadata.format, tflags); - } + } + else if (IsPlanar(metadata.format)) + { + const size_t count = ComputeScanlines(metadata.format, images[index].height); + if (!count) + return E_UNEXPECTED; - pSrc += spitch; - pDest += dpitch; + const size_t csize = std::min(dpitch, spitch); + 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: - { - 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) - 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)) + for (size_t slice = 0; slice < d; ++slice, ++index) { - size_t csize = std::min(images[index].slicePitch, timages[index].slicePitch); - memcpy(pDest, pSrc, csize); + if (index >= nimages) + 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(images[index].slicePitch, timages[index].slicePitch); + memcpy(pDest, pSrc, csize); + + if (cpFlags & CP_FLAGS_BAD_DXTN_TAILS) { - csize = std::min(images[index].slicePitch, timages[lastgood + slice].slicePitch); - memcpy(pDest, timages[lastgood + slice].pixels, csize); - } - else if (!slice) - { - lastgood = index; + if (images[index].width < 4 || images[index].height < 4) + { + csize = std::min(images[index].slicePitch, timages[lastgood + slice].slicePitch); + memcpy(pDest, timages[lastgood + slice].pixels, csize); + } + else if (!slice) + { + lastgood = index; + } } } - } - 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) + else if (IsPlanar(metadata.format)) { - 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, - pSrc, spitch, - (convFlags & CONV_FLAGS_565) ? DXGI_FORMAT_B5G6R5_UNORM : DXGI_FORMAT_B5G5R5A1_UNORM, - tflags)) - return E_FAIL; + 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 { - const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags); - if (!LegacyExpandScanline(pDest, dpitch, metadata.format, - pSrc, spitch, lformat, pal8, - tflags)) - return E_FAIL; + CopyScanline(pDest, dpitch, pSrc, spitch, metadata.format, tflags); } - } - 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; + pSrc += spitch; + pDest += dpitch; + } } } - } - if (d > 1) - d >>= 1; + if (d > 1) + d >>= 1; + } } - } - break; + break; default: return E_FAIL; @@ -1824,18 +1824,18 @@ HRESULT DirectX::LoadFromDDSFile( if (!(convFlags & CONV_FLAGS_DX10)) { -#ifdef WIN32 - // Must reset file position since we read more than the standard header above + #ifdef WIN32 + // Must reset file position since we read more than the standard header above const LARGE_INTEGER filePos = { { sizeof(uint32_t) + sizeof(DDS_HEADER), 0 } }; if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { return HRESULT_FROM_WIN32(GetLastError()); } -#else + #else inFile.seekg(sizeof(uint32_t) + sizeof(DDS_HEADER), std::ios::beg); if (!inFile) return E_FAIL; -#endif + #endif offset = sizeof(uint32_t) + sizeof(DDS_HEADER); } @@ -1849,7 +1849,7 @@ HRESULT DirectX::LoadFromDDSFile( return E_OUTOFMEMORY; } -#ifdef WIN32 + #ifdef WIN32 if (!ReadFile(hFile.get(), pal8.get(), 256 * sizeof(uint32_t), &bytesRead, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); @@ -1859,11 +1859,11 @@ HRESULT DirectX::LoadFromDDSFile( { return E_FAIL; } -#else + #else inFile.read(reinterpret_cast(pal8.get()), 256 * sizeof(uint32_t)); if (!inFile) return E_FAIL; -#endif + #endif offset += (256 * sizeof(uint32_t)); } @@ -1885,7 +1885,7 @@ HRESULT DirectX::LoadFromDDSFile( return E_OUTOFMEMORY; } -#ifdef WIN32 + #ifdef WIN32 if (!ReadFile(hFile.get(), temp.get(), static_cast(remaining), &bytesRead, nullptr)) { image.Release(); @@ -1897,14 +1897,14 @@ HRESULT DirectX::LoadFromDDSFile( image.Release(); return E_FAIL; } -#else + #else inFile.read(reinterpret_cast(temp.get()), remaining); if (!inFile) { image.Release(); return E_FAIL; } -#endif + #endif CP_FLAGS cflags = CP_FLAGS_NONE; if (flags & DDS_FLAGS_LEGACY_DWORD) @@ -1943,20 +1943,20 @@ HRESULT DirectX::LoadFromDDSFile( return HRESULT_E_ARITHMETIC_OVERFLOW; } -#ifdef WIN32 + #ifdef WIN32 if (!ReadFile(hFile.get(), image.GetPixels(), static_cast(image.GetPixelsSize()), &bytesRead, nullptr)) { image.Release(); return HRESULT_FROM_WIN32(GetLastError()); } -#else + #else inFile.read(reinterpret_cast(image.GetPixels()), image.GetPixelsSize()); if (!inFile) { image.Release(); return E_FAIL; } -#endif + #endif if (convFlags & (CONV_FLAGS_SWIZZLE | CONV_FLAGS_NOALPHA)) { @@ -2054,143 +2054,143 @@ HRESULT DirectX::SaveToDDSMemory( { case DDS_DIMENSION_TEXTURE1D: 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(); - 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)) + if (index >= nimages) { blob.Release(); - return hr; + return E_FAIL; } - 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(rowPitch, ddsRowPitch); - size_t tremaining = remaining; - for (size_t j = 0; j < lines; ++j) + if (fastpath) { - 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(); - return E_FAIL; + return hr; } - memcpy(dPtr, sPtr, csize); + const size_t rowPitch = images[index].rowPitch; - sPtr += rowPitch; - dPtr += ddsRowPitch; - tremaining -= ddsRowPitch; + 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(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; - remaining -= ddsSlicePitch; + ++index; } - - ++index; } } - } - break; + break; case DDS_DIMENSION_TEXTURE3D: - { - if (metadata.arraySize != 1) { - blob.Release(); - 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 (metadata.arraySize != 1) { - 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(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; + blob.Release(); + return E_FAIL; } - if (d > 1) - d >>= 1; + 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; + } + + 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(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: blob.Release(); @@ -2263,171 +2263,171 @@ HRESULT DirectX::SaveToDDSFile( { case DDS_DIMENSION_TEXTURE1D: 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) - 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)) + for (size_t level = 0; level < metadata.mipLevels; ++level, ++index) { -#ifdef WIN32 - if (!WriteFile(hFile.get(), images[index].pixels, static_cast(ddsSlicePitch), &bytesWritten, nullptr)) - { - return HRESULT_FROM_WIN32(GetLastError()); - } - - if (bytesWritten != ddsSlicePitch) - { + if (index >= nimages) return E_FAIL; - } -#else - outFile.write(reinterpret_cast(images[index].pixels), static_cast(ddsSlicePitch)); - if (!outFile) - return E_FAIL; -#endif - } - else - { - const size_t rowPitch = images[index].rowPitch; - if (rowPitch < ddsRowPitch) + + 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)) { - // 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(ddsRowPitch), &bytesWritten, nullptr)) + #ifdef WIN32 + if (!WriteFile(hFile.get(), images[index].pixels, static_cast(ddsSlicePitch), &bytesWritten, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); } - if (bytesWritten != ddsRowPitch) + if (bytesWritten != ddsSlicePitch) { return E_FAIL; } -#else - outFile.write(reinterpret_cast(sPtr), static_cast(ddsRowPitch)); + #else + outFile.write(reinterpret_cast(images[index].pixels), static_cast(ddsSlicePitch)); if (!outFile) 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(ddsRowPitch), &bytesWritten, nullptr)) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (bytesWritten != ddsRowPitch) + { + return E_FAIL; + } + #else + outFile.write(reinterpret_cast(sPtr), static_cast(ddsRowPitch)); + if (!outFile) + return E_FAIL; + #endif + + sPtr += rowPitch; + } } } } } - } - break; + break; 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) - 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)) + for (size_t slice = 0; slice < d; ++slice, ++index) { -#ifdef WIN32 - if (!WriteFile(hFile.get(), images[index].pixels, static_cast(ddsSlicePitch), &bytesWritten, nullptr)) - { - return HRESULT_FROM_WIN32(GetLastError()); - } - - if (bytesWritten != ddsSlicePitch) - { + if (index >= nimages) return E_FAIL; - } -#else - outFile.write(reinterpret_cast(images[index].pixels), static_cast(ddsSlicePitch)); - if (!outFile) - return E_FAIL; -#endif - } - else - { - const size_t rowPitch = images[index].rowPitch; - if (rowPitch < ddsRowPitch) + + 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)) { - // 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(ddsRowPitch), &bytesWritten, nullptr)) + #ifdef WIN32 + if (!WriteFile(hFile.get(), images[index].pixels, static_cast(ddsSlicePitch), &bytesWritten, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); } - if (bytesWritten != ddsRowPitch) + if (bytesWritten != ddsSlicePitch) { return E_FAIL; } -#else - outFile.write(reinterpret_cast(sPtr), static_cast(ddsRowPitch)); + #else + outFile.write(reinterpret_cast(images[index].pixels), static_cast(ddsSlicePitch)); if (!outFile) return E_FAIL; -#endif - sPtr += rowPitch; + #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; + } + + 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(ddsRowPitch), &bytesWritten, nullptr)) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (bytesWritten != ddsRowPitch) + { + return E_FAIL; + } + #else + outFile.write(reinterpret_cast(sPtr), static_cast(ddsRowPitch)); + if (!outFile) + return E_FAIL; + #endif + sPtr += rowPitch; + } } } - } - if (d > 1) - d >>= 1; + if (d > 1) + d >>= 1; + } } - } - break; + break; default: return E_FAIL; diff --git a/DirectXTex/DirectXTexHDR.cpp b/DirectXTex/DirectXTexHDR.cpp index b67489c..c4a76a2 100644 --- a/DirectXTex/DirectXTexHDR.cpp +++ b/DirectXTex/DirectXTexHDR.cpp @@ -79,7 +79,7 @@ namespace #ifndef WIN32 template - 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! va_list ap; @@ -400,7 +400,7 @@ namespace return 0; } -#ifdef WRITE_OLD_COLORS + #ifdef WRITE_OLD_COLORS size_t encSize = 0; const uint8_t* scanPtr = rgbe; @@ -502,7 +502,7 @@ namespace } return encSize; -#else + #else enc[0] = 2; enc[1] = 2; enc[2] = uint8_t(width >> 8); @@ -569,7 +569,7 @@ namespace } 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) { auto pixelLoc = scanLine + channel; - for(size_t pixelCount = 0; pixelCount < mdata.width;) + for (size_t pixelCount = 0; pixelCount < mdata.width;) { if (pixelLen < 2) { @@ -1163,7 +1163,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce return hr; // Write blob -#ifdef WIN32 + #ifdef WIN32 auto const bytesToWrite = static_cast(blob.GetBufferSize()); DWORD bytesWritten; 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; } -#else + #else outFile.write(reinterpret_cast(blob.GetBufferPointer()), static_cast(blob.GetBufferSize())); if (!outFile) return E_FAIL; -#endif + #endif } else { @@ -1196,7 +1196,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce char header[256] = {}; sprintf_s(header, g_Header, image.height, image.width); -#ifdef WIN32 + #ifdef WIN32 auto const headerLen = static_cast(strlen(header)); DWORD bytesWritten; @@ -1207,21 +1207,21 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce if (bytesWritten != headerLen) return E_FAIL; -#else + #else outFile.write(reinterpret_cast(header), static_cast(strlen(header))); if (!outFile) return E_FAIL; -#endif + #endif -#ifdef DISABLE_COMPRESS - // Uncompressed write + #ifdef DISABLE_COMPRESS + // Uncompressed write auto sPtr = reinterpret_cast(image.pixels); for (size_t scan = 0; scan < image.height; ++scan) { FloatToRGBE(rgbe, reinterpret_cast(sPtr), image.width, fpp); sPtr += image.rowPitch; - #ifdef WIN32 + #ifdef WIN32 if (!WriteFile(hFile.get(), rgbe, static_cast(rowPitch), &bytesWritten, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); @@ -1229,20 +1229,20 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce if (bytesWritten != rowPitch) return E_FAIL; - #else + #else outFile.write(reinterpret_cast(rgbe), static_cast(rowPitch)); if (!outFile) return E_FAIL; - #endif + #endif } -#else + #else auto enc = temp.get() + rowPitch; const uint8_t* sPtr = image.pixels; 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(sPtr), image.width, fpp); } @@ -1258,7 +1258,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce if (encSize > UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; -#ifdef WIN32 + #ifdef WIN32 if (!WriteFile(hFile.get(), enc, static_cast(encSize), &bytesWritten, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); @@ -1266,15 +1266,15 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce if (bytesWritten != encSize) return E_FAIL; -#else + #else outFile.write(reinterpret_cast(enc), static_cast(encSize)); if (!outFile) return E_FAIL; -#endif + #endif } else { -#ifdef WIN32 + #ifdef WIN32 if (!WriteFile(hFile.get(), rgbe, static_cast(rowPitch), &bytesWritten, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); @@ -1282,14 +1282,14 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce if (bytesWritten != rowPitch) return E_FAIL; -#else + #else outFile.write(reinterpret_cast(rgbe), static_cast(rowPitch)); if (!outFile) return E_FAIL; -#endif + #endif } } -#endif + #endif } #ifdef WIN32 diff --git a/DirectXTex/DirectXTexImage.cpp b/DirectXTex/DirectXTexImage.cpp index c03ebab..497b282 100644 --- a/DirectXTex/DirectXTexImage.cpp +++ b/DirectXTex/DirectXTexImage.cpp @@ -23,7 +23,7 @@ namespace return std::aligned_alloc(alignment, size); } - #define _aligned_free free +#define _aligned_free free } #endif @@ -75,37 +75,37 @@ bool DirectX::Internal::DetermineImageArray( break; 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; - if (FAILED(ComputePitch(metadata.format, w, h, rowPitch, slicePitch, cpFlags))) + size_t w = metadata.width; + size_t h = metadata.height; + size_t d = metadata.depth; + + for (size_t level = 0; level < metadata.mipLevels; ++level) { - nImages = pixelSize = 0; - return false; + size_t rowPitch, slicePitch; + 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: nImages = pixelSize = 0; @@ -202,57 +202,57 @@ bool DirectX::Internal::SetupImageArray( return true; case TEX_DIMENSION_TEXTURE3D: - { - if (metadata.mipLevels == 0 || metadata.depth == 0) { - return false; - } - - 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 (metadata.mipLevels == 0 || metadata.depth == 0) { - 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; - } + return false; } - if (h > 1) - h >>= 1; + size_t w = metadata.width; + size_t h = metadata.height; + size_t d = metadata.depth; - if (w > 1) - w >>= 1; + 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; - if (d > 1) - d >>= 1; + for (size_t slice = 0; slice < d; ++slice) + { + 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: return false; @@ -801,7 +801,7 @@ bool ScratchImage::IsAlphaAllOpaque() const noexcept for (size_t index = 0; index < m_nimages; ++index) { -#pragma warning( suppress : 6011 ) + #pragma warning( suppress : 6011 ) const Image& img = m_image[index]; const uint8_t *pPixels = img.pixels; diff --git a/DirectXTex/DirectXTexMipmaps.cpp b/DirectXTex/DirectXTexMipmaps.cpp index 28245ed..1a401ce 100644 --- a/DirectXTex/DirectXTexMipmaps.cpp +++ b/DirectXTex/DirectXTexMipmaps.cpp @@ -305,10 +305,10 @@ namespace HRESULT EstimateAlphaScaleForCoverage( - const Image& srcImage, - float alphaReference, - float targetCoverage, - float& alphaScale) noexcept + const Image& srcImage, + float alphaReference, + float targetCoverage, + float& alphaScale) noexcept { float minAlphaScale = 0.0f; float maxAlphaScale = 4.0f; @@ -454,16 +454,16 @@ HRESULT DirectX::Internal::ResizeSeparateColorAndAlpha( } else { -#if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) + #if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) if (iswic2) { colorBytesInPixel = colorBytesPerPixel = 12; colorPixelFormat = GUID_WICPixelFormat96bppRGBFloat; } else -#else + #else UNREFERENCED_PARAMETER(iswic2); -#endif + #endif { colorBytesInPixel = 12; colorBytesPerPixel = 16; @@ -593,7 +593,7 @@ HRESULT DirectX::Internal::ResizeSeparateColorAndAlpha( } 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); } } @@ -642,14 +642,14 @@ namespace 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 || format == DXGI_FORMAT_R16_FLOAT) { // Use non-WIC code paths as these conversions are not supported by Xbox version of WIC return false; } -#endif + #endif 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 for (size_t level = 1; level < levels; ++level) { -#ifdef _DEBUG + #ifdef _DEBUG memset(row, 0xCD, sizeof(XMVECTOR)*width); -#endif + #endif // 2D point filter const Image* src = mipChain.GetImage(level - 1, item, 0); @@ -1129,10 +1129,10 @@ namespace const size_t nheight = (height > 1) ? (height >> 1) : 1; CreateLinearFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, lfY); -#ifdef _DEBUG + #ifdef _DEBUG memset(row0, 0xCD, sizeof(XMVECTOR)*width); memset(row1, 0xDD, sizeof(XMVECTOR)*width); -#endif + #endif size_t u0 = size_t(-1); size_t u1 = size_t(-1); @@ -1190,6 +1190,10 @@ namespace } //--- 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 { using namespace DirectX::Filters; @@ -1244,12 +1248,12 @@ namespace 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); -#ifdef _DEBUG + #ifdef _DEBUG memset(row0, 0xCD, sizeof(XMVECTOR)*width); memset(row1, 0xDD, sizeof(XMVECTOR)*width); memset(row2, 0xED, sizeof(XMVECTOR)*width); memset(row3, 0xFD, sizeof(XMVECTOR)*width); -#endif + #endif size_t u0 = size_t(-1); size_t u1 = size_t(-1); @@ -1353,12 +1357,12 @@ namespace XMVECTOR C0, C1, C2, C3; - 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(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(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(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(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)) @@ -1433,9 +1437,9 @@ namespace if (FAILED(hr)) return hr; -#ifdef _DEBUG + #ifdef _DEBUG memset(row, 0xCD, sizeof(XMVECTOR)*width); -#endif + #endif auto xFromEnd = reinterpret_cast(reinterpret_cast(tfX.get()) + tfX->sizeInBytes); auto yFromEnd = reinterpret_cast(reinterpret_cast(tfY.get()) + tfY->sizeInBytes); @@ -1550,18 +1554,18 @@ namespace { case DXGI_FORMAT_R10G10B10A2_UNORM: 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: break; @@ -1673,9 +1677,9 @@ namespace // Resize base image to each target mip level for (size_t level = 1; level < levels; ++level) { -#ifdef _DEBUG + #ifdef _DEBUG memset(row, 0xCD, sizeof(XMVECTOR)*width); -#endif + #endif if (depth > 1) { @@ -2012,12 +2016,12 @@ namespace const size_t nheight = (height > 1) ? (height >> 1) : 1; CreateLinearFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, lfY); -#ifdef _DEBUG + #ifdef _DEBUG memset(urow0, 0xCD, sizeof(XMVECTOR)*width); memset(urow1, 0xDD, sizeof(XMVECTOR)*width); memset(vrow0, 0xED, sizeof(XMVECTOR)*width); memset(vrow1, 0xFD, sizeof(XMVECTOR)*width); -#endif + #endif if (depth > 1) { @@ -2216,7 +2220,7 @@ namespace 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); -#ifdef _DEBUG + #ifdef _DEBUG for (size_t j = 0; j < 4; ++j) { memset(urow[j], 0xCD, sizeof(XMVECTOR)*width); @@ -2224,7 +2228,7 @@ namespace memset(srow[j], 0xED, sizeof(XMVECTOR)*width); memset(trow[j], 0xFD, sizeof(XMVECTOR)*width); } -#endif + #endif if (depth > 1) { @@ -2384,15 +2388,15 @@ namespace for (size_t j = 0; j < 4; ++j) { 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(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(C3, toX.x, trow[j][toX.u0], trow[j][toX.u1], trow[j][toX.u2], trow[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(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(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)) @@ -2516,12 +2520,12 @@ namespace auto const& toX = cfX[x]; 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(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(C3, toX.x, trow[0][toX.u0], trow[0][toX.u1], trow[0][toX.u2], trow[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(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(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)) @@ -2592,9 +2596,9 @@ namespace if (FAILED(hr)) return hr; -#ifdef _DEBUG + #ifdef _DEBUG memset(row, 0xCD, sizeof(XMVECTOR)*width); -#endif + #endif auto xFromEnd = reinterpret_cast(reinterpret_cast(tfX.get()) + tfX->sizeInBytes); auto yFromEnd = reinterpret_cast(reinterpret_cast(tfY.get()) + tfY->sizeInBytes); @@ -2739,18 +2743,18 @@ namespace { case DXGI_FORMAT_R10G10B10A2_UNORM: 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: break; @@ -2854,56 +2858,56 @@ HRESULT DirectX::GenerateMipMaps( case TEX_FILTER_FANT: // Equivalent to Box filter case TEX_FILTER_LINEAR: 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 - 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; + static_assert(TEX_FILTER_FANT == TEX_FILTER_BOX, "TEX_FILTER_ flag alias mismatch"); - 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: return HRESULT_E_NOT_SUPPORTED; } } else -#endif // WIN32 + #endif // WIN32 { //--- Use custom filters to generate mipmaps ---------------------------------- TexMetadata mdata = {}; @@ -3069,69 +3073,69 @@ HRESULT DirectX::GenerateMipMaps( case TEX_FILTER_FANT: // Equivalent to Box filter case TEX_FILTER_LINEAR: 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 - TexMetadata mdata2 = metadata; - mdata2.mipLevels = levels; - hr = mipChain.Initialize(mdata2); - if (FAILED(hr)) - return hr; + static_assert(TEX_FILTER_FANT == TEX_FILTER_BOX, "TEX_FILTER_ flag alias mismatch"); - 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)) + return hr; + + for (size_t item = 0; item < metadata.arraySize; ++item) { - mipChain.Release(); - return hr; + hr = GenerateMipMapsUsingWIC(baseImages[item], filter, levels, pfGUID, mipChain, item); + if (FAILED(hr)) + { + mipChain.Release(); + return hr; + } } + + return S_OK; } - - 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) + else { - ScratchImage temp; - hr = ConvertToR32G32B32A32(baseImages[item], temp); + // 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; - const Image *timg = temp.GetImage(0, 0, 0); - if (!timg) - return E_POINTER; + for (size_t item = 0; item < metadata.arraySize; ++item) + { + ScratchImage temp; + hr = ConvertToR32G32B32A32(baseImages[item], temp); + if (FAILED(hr)) + return hr; - hr = GenerateMipMapsUsingWIC(*timg, filter, levels, GUID_WICPixelFormat128bppRGBAFloat, tMipChain, item); - if (FAILED(hr)) - return hr; + const Image *timg = temp.GetImage(0, 0, 0); + if (!timg) + 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: return HRESULT_E_NOT_SUPPORTED; } } else -#endif // WIN32 + #endif // WIN32 { //--- Use custom filters to generate mipmaps ---------------------------------- TexMetadata mdata2 = metadata; diff --git a/DirectXTex/DirectXTexMisc.cpp b/DirectXTex/DirectXTexMisc.cpp index 053ad96..1f3b9be 100644 --- a/DirectXTex/DirectXTexMisc.cpp +++ b/DirectXTex/DirectXTexMisc.cpp @@ -246,9 +246,9 @@ namespace if (!LoadScanline(sScanline, width, pSrc, spitch, srcImage.format)) return E_FAIL; -#ifdef _DEBUG + #ifdef _DEBUG memset(dScanline, 0xCD, sizeof(XMVECTOR)*width); -#endif + #endif pixelFunc(dScanline, sScanline, width, h); @@ -563,33 +563,33 @@ HRESULT DirectX::EvaluateImage( break; 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) - return E_FAIL; + for (size_t slice = 0; slice < d; ++slice, ++index) + { + if (index >= nimages) + return E_FAIL; - const Image& img = images[index]; - if (img.format != format) - return E_FAIL; + const Image& img = images[index]; + if (img.format != format) + return E_FAIL; - if ((img.width > UINT32_MAX) || (img.height > UINT32_MAX)) - return E_FAIL; + if ((img.width > UINT32_MAX) || (img.height > UINT32_MAX)) + return E_FAIL; - HRESULT hr = EvaluateImage_(img, pixelFunc); - if (FAILED(hr)) - return hr; + HRESULT hr = EvaluateImage_(img, pixelFunc); + if (FAILED(hr)) + return hr; + } + + if (d > 1) + d >>= 1; } - - if (d > 1) - d >>= 1; } - } - break; + break; default: return E_FAIL; @@ -710,53 +710,53 @@ HRESULT DirectX::TransformImage( break; 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(); - return E_FAIL; + if (index >= nimages) + { + 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 (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; - } + if (d > 1) + d >>= 1; } - - if (d > 1) - d >>= 1; } - } - break; + break; default: result.Release(); diff --git a/DirectXTex/DirectXTexNormalMaps.cpp b/DirectXTex/DirectXTexNormalMaps.cpp index 48bf826..0a35900 100644 --- a/DirectXTex/DirectXTexNormalMaps.cpp +++ b/DirectXTex/DirectXTexNormalMaps.cpp @@ -34,11 +34,11 @@ namespace case CNMAP_CHANNEL_ALPHA: return XMVectorGetW(val); case CNMAP_CHANNEL_LUMINANCE: - { - const XMVECTOR v = XMVectorMultiply(val, lScale); - XMStoreFloat4A(&f, v); - return f.x + f.y + f.z; - } + { + const XMVECTOR v = XMVectorMultiply(val, lScale); + XMStoreFloat4A(&f, v); + return f.x + f.y + f.z; + } default: assert(false); diff --git a/DirectXTex/DirectXTexP.h b/DirectXTex/DirectXTexP.h index f3757cf..928190f 100644 --- a/DirectXTex/DirectXTexP.h +++ b/DirectXTex/DirectXTexP.h @@ -210,7 +210,7 @@ namespace DirectX { //----------------------------------------------------------------------------- // WIC helper functions -#ifdef WIN32 + #ifdef WIN32 DXGI_FORMAT __cdecl WICToDXGI(_In_ const GUID& guid) noexcept; bool __cdecl DXGIToWIC(_In_ DXGI_FORMAT format, _Out_ GUID& guid, _In_ bool ignoreRGBvsBGR = false) noexcept; @@ -295,7 +295,7 @@ namespace DirectX return WICBitmapInterpolationModeFant; } } -#endif // WIN32 + #endif // WIN32 //--------------------------------------------------------------------------------- // Image helper functions @@ -313,32 +313,36 @@ namespace DirectX enum TEXP_SCANLINE_FLAGS : uint32_t { - 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_NONE = 0, + + 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 { - CONVF_FLOAT = 0x1, - CONVF_UNORM = 0x2, - CONVF_UINT = 0x4, - CONVF_SNORM = 0x8, - CONVF_SINT = 0x10, - CONVF_DEPTH = 0x20, - CONVF_STENCIL = 0x40, + CONVF_FLOAT = 0x1, + CONVF_UNORM = 0x2, + CONVF_UINT = 0x4, + CONVF_SNORM = 0x8, + CONVF_SINT = 0x10, + CONVF_DEPTH = 0x20, + CONVF_STENCIL = 0x40, CONVF_SHAREDEXP = 0x80, - CONVF_BGR = 0x100, - CONVF_XR = 0x200, - CONVF_PACKED = 0x400, - CONVF_BC = 0x800, - CONVF_YUV = 0x1000, - CONVF_POS_ONLY = 0x2000, - CONVF_R = 0x10000, - CONVF_G = 0x20000, - CONVF_B = 0x40000, - CONVF_A = 0x80000, - CONVF_RGB_MASK = 0x70000, + CONVF_BGR = 0x100, + CONVF_XR = 0x200, + CONVF_PACKED = 0x400, + CONVF_BC = 0x800, + CONVF_YUV = 0x1000, + CONVF_POS_ONLY = 0x2000, + CONVF_R = 0x10000, + CONVF_G = 0x20000, + CONVF_B = 0x40000, + CONVF_A = 0x80000, + CONVF_RGB_MASK = 0x70000, 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, _Inout_ size_t& mipLevels) noexcept; -#ifdef WIN32 + #ifdef WIN32 HRESULT __cdecl ResizeSeparateColorAndAlpha(_In_ IWICImagingFactory* pWIC, _In_ bool iswic2, _In_ IWICBitmap* original, _In_ size_t newWidth, _In_ size_t newHeight, _In_ TEX_FILTER_FLAGS filter, _Inout_ const Image* img) noexcept; -#endif + #endif } // namespace Internal } // namespace DirectX diff --git a/DirectXTex/DirectXTexResize.cpp b/DirectXTex/DirectXTexResize.cpp index 23b21f4..a44eedb 100644 --- a/DirectXTex/DirectXTexResize.cpp +++ b/DirectXTex/DirectXTexResize.cpp @@ -189,14 +189,14 @@ namespace 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 || format == DXGI_FORMAT_R16_FLOAT) { // Use non-WIC code paths as these conversions are not supported by Xbox version of WIC return false; } -#endif + #endif 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; -#ifdef _DEBUG + #ifdef _DEBUG memset(row, 0xCD, sizeof(XMVECTOR)*srcImage.width); -#endif + #endif const uint8_t* pSrc = srcImage.pixels; uint8_t* pDest = destImage.pixels; @@ -321,10 +321,10 @@ namespace XMVECTOR* urow0 = target + destImage.width; XMVECTOR* urow1 = urow0 + srcImage.width; -#ifdef _DEBUG + #ifdef _DEBUG memset(urow0, 0xCD, sizeof(XMVECTOR)*srcImage.width); memset(urow1, 0xDD, sizeof(XMVECTOR)*srcImage.width); -#endif + #endif const XMVECTOR* urow2 = urow0 + 1; const XMVECTOR* urow3 = urow1 + 1; @@ -391,10 +391,10 @@ namespace XMVECTOR* row0 = target + destImage.width; XMVECTOR* row1 = row0 + srcImage.width; -#ifdef _DEBUG + #ifdef _DEBUG memset(row0, 0xCD, sizeof(XMVECTOR)*srcImage.width); memset(row1, 0xDD, sizeof(XMVECTOR)*srcImage.width); -#endif + #endif const uint8_t* pSrc = srcImage.pixels; uint8_t* pDest = destImage.pixels; @@ -451,6 +451,10 @@ namespace //--- 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 { using namespace DirectX::Filters; @@ -480,12 +484,12 @@ namespace XMVECTOR* row2 = row0 + srcImage.width * 2; XMVECTOR* row3 = row0 + srcImage.width * 3; -#ifdef _DEBUG + #ifdef _DEBUG memset(row0, 0xCD, sizeof(XMVECTOR)*srcImage.width); memset(row1, 0xDD, sizeof(XMVECTOR)*srcImage.width); memset(row2, 0xED, sizeof(XMVECTOR)*srcImage.width); memset(row3, 0xFD, sizeof(XMVECTOR)*srcImage.width); -#endif + #endif const uint8_t* pSrc = srcImage.pixels; uint8_t* pDest = destImage.pixels; @@ -594,12 +598,12 @@ namespace XMVECTOR C0, C1, C2, C3; - 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(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(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(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(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)) @@ -642,9 +646,9 @@ namespace XMVECTOR* row = scanline.get(); -#ifdef _DEBUG + #ifdef _DEBUG memset(row, 0xCD, sizeof(XMVECTOR)*srcImage.width); -#endif + #endif auto xFromEnd = reinterpret_cast(reinterpret_cast(tfX.get()) + tfX->sizeInBytes); auto yFromEnd = reinterpret_cast(reinterpret_cast(tfY.get()) + tfY->sizeInBytes); @@ -757,18 +761,18 @@ namespace { case DXGI_FORMAT_R10G10B10A2_UNORM: 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: break; @@ -908,7 +912,7 @@ HRESULT DirectX::Resize( } } else -#endif + #endif { // Case 3: not using WIC resizing hr = PerformResizeUsingCustomFilters(srcImage, filter, *rimage); @@ -1007,7 +1011,7 @@ HRESULT DirectX::Resize( return E_FAIL; } -#ifdef WIN32 + #ifdef WIN32 if (usewic) { if (wicpf) @@ -1022,7 +1026,7 @@ HRESULT DirectX::Resize( } } else -#endif + #endif { // Case 3: not using WIC resizing hr = PerformResizeUsingCustomFilters(*srcimg, filter, *destimg); @@ -1068,7 +1072,7 @@ HRESULT DirectX::Resize( return E_FAIL; } -#ifdef WIN32 + #ifdef WIN32 if (usewic) { if (wicpf) @@ -1083,7 +1087,7 @@ HRESULT DirectX::Resize( } } else -#endif + #endif { // Case 3: not using WIC resizing hr = PerformResizeUsingCustomFilters(*srcimg, filter, *destimg); diff --git a/DirectXTex/DirectXTexTGA.cpp b/DirectXTex/DirectXTexTGA.cpp index 07b20b9..029d109 100644 --- a/DirectXTex/DirectXTexTGA.cpp +++ b/DirectXTex/DirectXTexTGA.cpp @@ -120,14 +120,14 @@ namespace enum CONVERSION_FLAGS { - CONV_FLAGS_NONE = 0x0, - CONV_FLAGS_EXPAND = 0x1, // Conversion requires expanded pixel size - CONV_FLAGS_INVERTX = 0x2, // If set, scanlines are right-to-left - CONV_FLAGS_INVERTY = 0x4, // If set, scanlines are top-to-bottom - CONV_FLAGS_RLE = 0x8, // Source data is RLE compressed + CONV_FLAGS_NONE = 0x0, + CONV_FLAGS_EXPAND = 0x1, // Conversion requires expanded pixel size + CONV_FLAGS_INVERTX = 0x2, // If set, scanlines are right-to-left + CONV_FLAGS_INVERTY = 0x4, // If set, scanlines are top-to-bottom + CONV_FLAGS_RLE = 0x8, // Source data is RLE compressed - CONV_FLAGS_SWIZZLE = 0x10000, // Swizzle BGR<->RGB data - CONV_FLAGS_888 = 0x20000, // 24bpp format + CONV_FLAGS_SWIZZLE = 0x10000, // Swizzle BGR<->RGB data + CONV_FLAGS_888 = 0x20000, // 24bpp format }; @@ -374,66 +374,31 @@ namespace //-------------------------------------------------------------------------- 16-bit case DXGI_FORMAT_B5G5R5A1_UNORM: - { - uint32_t minalpha = 255; - uint32_t maxalpha = 0; - - for (size_t y = 0; y < image->height; ++y) { - size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); - assert(offset * 2 < rowPitch); + uint32_t minalpha = 255; + uint32_t maxalpha = 0; - auto dPtr = reinterpret_cast(image->pixels - + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) - + offset; - - for (size_t x = 0; x < image->width; ) + for (size_t y = 0; y < image->height; ++y) { - if (sPtr >= endPtr) - return E_FAIL; + size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); + assert(offset * 2 < rowPitch); - if (*sPtr & 0x80) + auto dPtr = reinterpret_cast(image->pixels + + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) + + offset; + + for (size_t x = 0; x < image->width; ) { - // Repeat - size_t j = size_t(*sPtr & 0x7F) + 1; - ++sPtr; - - if (sPtr + 1 >= endPtr) + if (sPtr >= endPtr) return E_FAIL; - auto t = static_cast(uint32_t(*sPtr) | uint32_t(*(sPtr + 1u) << 8)); - - const uint32_t alpha = (t & 0x8000) ? 255 : 0; - minalpha = std::min(minalpha, alpha); - maxalpha = std::max(maxalpha, alpha); - - sPtr += 2; - - for (; j > 0; --j, ++x) + if (*sPtr & 0x80) { - if (x >= image->width) - return E_FAIL; + // Repeat + size_t j = size_t(*sPtr & 0x7F) + 1; + ++sPtr; - *dPtr = t; - - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; - } - } - else - { - // Literal - size_t j = size_t(*sPtr & 0x7F) + 1; - ++sPtr; - - if (sPtr + (j * 2) > endPtr) - return E_FAIL; - - for (; j > 0; --j, ++x) - { - if (x >= image->width) + if (sPtr + 1 >= endPtr) return E_FAIL; auto t = static_cast(uint32_t(*sPtr) | uint32_t(*(sPtr + 1u) << 8)); @@ -443,123 +408,93 @@ namespace maxalpha = std::max(maxalpha, alpha); sPtr += 2; - *dPtr = t; - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; + for (; j > 0; --j, ++x) + { + if (x >= image->width) + return E_FAIL; + + *dPtr = t; + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } + } + else + { + // Literal + size_t j = size_t(*sPtr & 0x7F) + 1; + ++sPtr; + + if (sPtr + (j * 2) > endPtr) + return E_FAIL; + + for (; j > 0; --j, ++x) + { + if (x >= image->width) + return E_FAIL; + + auto t = static_cast(uint32_t(*sPtr) | uint32_t(*(sPtr + 1u) << 8)); + + const uint32_t alpha = (t & 0x8000) ? 255 : 0; + minalpha = std::min(minalpha, alpha); + maxalpha = std::max(maxalpha, alpha); + + sPtr += 2; + *dPtr = t; + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } } } } - } - // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque - if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) - { - opaquealpha = true; - hr = SetAlphaChannelToOpaque(image); - if (FAILED(hr)) - return hr; - } - else if (minalpha == 255) - { - opaquealpha = true; - } - } - break; - - //------------------------------------------------------ 24/32-bit (with swizzling) - case DXGI_FORMAT_R8G8B8A8_UNORM: - { - uint32_t minalpha = 255; - uint32_t maxalpha = 0; - - for (size_t y = 0; y < image->height; ++y) - { - size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); - - auto dPtr = reinterpret_cast(image->pixels - + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) - + offset; - - for (size_t x = 0; x < image->width; ) + // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque + if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) { - if (sPtr >= endPtr) - return E_FAIL; + opaquealpha = true; + hr = SetAlphaChannelToOpaque(image); + if (FAILED(hr)) + return hr; + } + else if (minalpha == 255) + { + opaquealpha = true; + } + } + break; - if (*sPtr & 0x80) + //------------------------------------------------------ 24/32-bit (with swizzling) + case DXGI_FORMAT_R8G8B8A8_UNORM: + { + uint32_t minalpha = 255; + uint32_t maxalpha = 0; + + for (size_t y = 0; y < image->height; ++y) + { + size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); + + auto dPtr = reinterpret_cast(image->pixels + + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) + + offset; + + for (size_t x = 0; x < image->width; ) { - // Repeat - size_t j = size_t(*sPtr & 0x7F) + 1; - ++sPtr; + if (sPtr >= endPtr) + return E_FAIL; - uint32_t t; - if (convFlags & CONV_FLAGS_EXPAND) + if (*sPtr & 0x80) { - assert(offset * 3 < rowPitch); - - if (sPtr + 2 >= endPtr) - return E_FAIL; - - // BGR -> RGBA - t = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | 0xFF000000; - sPtr += 3; - - minalpha = maxalpha = 255; - } - else - { - assert(offset * 4 < rowPitch); - - if (sPtr + 3 >= endPtr) - return E_FAIL; - - // BGRA -> RGBA - const uint32_t alpha = *(sPtr + 3); - t = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24); - - minalpha = std::min(minalpha, alpha); - maxalpha = std::max(maxalpha, alpha); - - sPtr += 4; - } - - for (; j > 0; --j, ++x) - { - if (x >= image->width) - return E_FAIL; - - *dPtr = t; - - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; - } - } - else - { - // Literal - size_t j = size_t(*sPtr & 0x7F) + 1; - ++sPtr; - - if (convFlags & CONV_FLAGS_EXPAND) - { - if (sPtr + (j * 3) > endPtr) - return E_FAIL; - } - else - { - if (sPtr + (j * 4) > endPtr) - return E_FAIL; - } - - for (; j > 0; --j, ++x) - { - if (x >= image->width) - return E_FAIL; + // Repeat + size_t j = size_t(*sPtr & 0x7F) + 1; + ++sPtr; + uint32_t t; if (convFlags & CONV_FLAGS_EXPAND) { assert(offset * 3 < rowPitch); @@ -568,7 +503,7 @@ namespace return E_FAIL; // BGR -> RGBA - *dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | 0xFF000000; + t = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | 0xFF000000; sPtr += 3; minalpha = maxalpha = 255; @@ -581,8 +516,8 @@ namespace return E_FAIL; // BGRA -> RGBA - uint32_t alpha = *(sPtr + 3); - *dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24); + const uint32_t alpha = *(sPtr + 3); + t = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24); minalpha = std::min(minalpha, alpha); maxalpha = std::max(maxalpha, alpha); @@ -590,97 +525,121 @@ namespace sPtr += 4; } - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; + for (; j > 0; --j, ++x) + { + if (x >= image->width) + return E_FAIL; + + *dPtr = t; + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } + } + else + { + // Literal + size_t j = size_t(*sPtr & 0x7F) + 1; + ++sPtr; + + if (convFlags & CONV_FLAGS_EXPAND) + { + if (sPtr + (j * 3) > endPtr) + return E_FAIL; + } else - ++dPtr; + { + if (sPtr + (j * 4) > endPtr) + return E_FAIL; + } + + for (; j > 0; --j, ++x) + { + if (x >= image->width) + return E_FAIL; + + if (convFlags & CONV_FLAGS_EXPAND) + { + assert(offset * 3 < rowPitch); + + if (sPtr + 2 >= endPtr) + return E_FAIL; + + // BGR -> RGBA + *dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | 0xFF000000; + sPtr += 3; + + minalpha = maxalpha = 255; + } + else + { + assert(offset * 4 < rowPitch); + + if (sPtr + 3 >= endPtr) + return E_FAIL; + + // BGRA -> RGBA + uint32_t alpha = *(sPtr + 3); + *dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24); + + minalpha = std::min(minalpha, alpha); + maxalpha = std::max(maxalpha, alpha); + + sPtr += 4; + } + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } } } } - } - // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque - if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) - { - opaquealpha = true; - hr = SetAlphaChannelToOpaque(image); - if (FAILED(hr)) - return hr; - } - else if (minalpha == 255) - { - opaquealpha = true; - } - } - break; - - //-------------------------------------------------------------------- 32-bit (BGR) - case DXGI_FORMAT_B8G8R8A8_UNORM: - { - assert((convFlags & CONV_FLAGS_EXPAND) == 0); - - uint32_t minalpha = 255; - uint32_t maxalpha = 0; - - for (size_t y = 0; y < image->height; ++y) - { - size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); - - auto dPtr = reinterpret_cast(image->pixels - + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) - + offset; - - for (size_t x = 0; x < image->width; ) + // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque + if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) { - if (sPtr >= endPtr) - return E_FAIL; + opaquealpha = true; + hr = SetAlphaChannelToOpaque(image); + if (FAILED(hr)) + return hr; + } + else if (minalpha == 255) + { + opaquealpha = true; + } + } + break; - if (*sPtr & 0x80) + //-------------------------------------------------------------------- 32-bit (BGR) + case DXGI_FORMAT_B8G8R8A8_UNORM: + { + assert((convFlags & CONV_FLAGS_EXPAND) == 0); + + uint32_t minalpha = 255; + uint32_t maxalpha = 0; + + for (size_t y = 0; y < image->height; ++y) + { + size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); + + auto dPtr = reinterpret_cast(image->pixels + + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) + + offset; + + for (size_t x = 0; x < image->width; ) { - // Repeat - size_t j = size_t(*sPtr & 0x7F) + 1; - ++sPtr; - - assert(offset * 4 < rowPitch); - - if (sPtr + 3 >= endPtr) + if (sPtr >= endPtr) return E_FAIL; - const uint32_t alpha = *(sPtr + 3); - - auto t = *reinterpret_cast(sPtr); - - minalpha = std::min(minalpha, alpha); - maxalpha = std::max(maxalpha, alpha); - - sPtr += 4; - - for (; j > 0; --j, ++x) + if (*sPtr & 0x80) { - if (x >= image->width) - return E_FAIL; - - *dPtr = t; - - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; - } - } - else - { - // Literal - size_t j = size_t(*sPtr & 0x7F) + 1; - ++sPtr; - - if (sPtr + (j * 4) > endPtr) - return E_FAIL; - - for (; j > 0; --j, ++x) - { - if (x >= image->width) - return E_FAIL; + // Repeat + size_t j = size_t(*sPtr & 0x7F) + 1; + ++sPtr; assert(offset * 4 < rowPitch); @@ -688,116 +647,157 @@ namespace return E_FAIL; const uint32_t alpha = *(sPtr + 3); - *dPtr = *reinterpret_cast(sPtr); + + auto t = *reinterpret_cast(sPtr); minalpha = std::min(minalpha, alpha); maxalpha = std::max(maxalpha, alpha); sPtr += 4; - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; + for (; j > 0; --j, ++x) + { + if (x >= image->width) + return E_FAIL; + + *dPtr = t; + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } + } + else + { + // Literal + size_t j = size_t(*sPtr & 0x7F) + 1; + ++sPtr; + + if (sPtr + (j * 4) > endPtr) + return E_FAIL; + + for (; j > 0; --j, ++x) + { + if (x >= image->width) + return E_FAIL; + + assert(offset * 4 < rowPitch); + + if (sPtr + 3 >= endPtr) + return E_FAIL; + + const uint32_t alpha = *(sPtr + 3); + *dPtr = *reinterpret_cast(sPtr); + + minalpha = std::min(minalpha, alpha); + maxalpha = std::max(maxalpha, alpha); + + sPtr += 4; + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } } } } - } - // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque - if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) - { - opaquealpha = true; - hr = SetAlphaChannelToOpaque(image); - if (FAILED(hr)) - return hr; - } - else if (minalpha == 255) - { - opaquealpha = true; - } - } - break; - - //-------------------------------------------------------------------- 24-bit (BGR) - case DXGI_FORMAT_B8G8R8X8_UNORM: - { - assert((convFlags & CONV_FLAGS_EXPAND) != 0); - - for (size_t y = 0; y < image->height; ++y) - { - size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); - - auto dPtr = reinterpret_cast(image->pixels - + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) - + offset; - - for (size_t x = 0; x < image->width; ) + // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque + if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) { - if (sPtr >= endPtr) - return E_FAIL; + opaquealpha = true; + hr = SetAlphaChannelToOpaque(image); + if (FAILED(hr)) + return hr; + } + else if (minalpha == 255) + { + opaquealpha = true; + } + } + break; - if (*sPtr & 0x80) + //-------------------------------------------------------------------- 24-bit (BGR) + case DXGI_FORMAT_B8G8R8X8_UNORM: + { + assert((convFlags & CONV_FLAGS_EXPAND) != 0); + + for (size_t y = 0; y < image->height; ++y) + { + size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); + + auto dPtr = reinterpret_cast(image->pixels + + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) + + offset; + + for (size_t x = 0; x < image->width; ) { - // Repeat - size_t j = size_t(*sPtr & 0x7F) + 1; - ++sPtr; - - assert(offset * 3 < rowPitch); - - if (sPtr + 2 >= endPtr) + if (sPtr >= endPtr) return E_FAIL; - uint32_t t = uint32_t(*sPtr) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2) << 16); - sPtr += 3; - - for (; j > 0; --j, ++x) + if (*sPtr & 0x80) { - if (x >= image->width) - return E_FAIL; - - *dPtr = t; - - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; - } - } - else - { - // Literal - size_t j = size_t(*sPtr & 0x7F) + 1; - ++sPtr; - - if (sPtr + (j * 3) > endPtr) - return E_FAIL; - - for (; j > 0; --j, ++x) - { - if (x >= image->width) - return E_FAIL; + // Repeat + size_t j = size_t(*sPtr & 0x7F) + 1; + ++sPtr; assert(offset * 3 < rowPitch); if (sPtr + 2 >= endPtr) return E_FAIL; - *dPtr = uint32_t(*sPtr) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2) << 16); + uint32_t t = uint32_t(*sPtr) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2) << 16); sPtr += 3; - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; + for (; j > 0; --j, ++x) + { + if (x >= image->width) + return E_FAIL; + + *dPtr = t; + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } + } + else + { + // Literal + size_t j = size_t(*sPtr & 0x7F) + 1; + ++sPtr; + + if (sPtr + (j * 3) > endPtr) + return E_FAIL; + + for (; j > 0; --j, ++x) + { + if (x >= image->width) + return E_FAIL; + + assert(offset * 3 < rowPitch); + + if (sPtr + 2 >= endPtr) + return E_FAIL; + + *dPtr = uint32_t(*sPtr) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2) << 16); + sPtr += 3; + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } } } } } - } - break; + break; - //--------------------------------------------------------------------------------- + //--------------------------------------------------------------------------------- default: return E_FAIL; } @@ -863,208 +863,208 @@ namespace //-------------------------------------------------------------------------- 16-bit case DXGI_FORMAT_B5G5R5A1_UNORM: - { - uint32_t minalpha = 255; - uint32_t maxalpha = 0; - - for (size_t y = 0; y < image->height; ++y) { - size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); - assert(offset * 2 < rowPitch); + uint32_t minalpha = 255; + uint32_t maxalpha = 0; - auto dPtr = reinterpret_cast(image->pixels - + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) - + offset; - - for (size_t x = 0; x < image->width; ++x) + for (size_t y = 0; y < image->height; ++y) { - if (sPtr + 1 >= endPtr) - return E_FAIL; + size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); + assert(offset * 2 < rowPitch); - auto t = static_cast(uint32_t(*sPtr) | uint32_t(*(sPtr + 1u) << 8)); - sPtr += 2; - *dPtr = t; + auto dPtr = reinterpret_cast(image->pixels + + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) + + offset; - const uint32_t alpha = (t & 0x8000) ? 255 : 0; - minalpha = std::min(minalpha, alpha); - maxalpha = std::max(maxalpha, alpha); - - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; - } - } - - // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque - if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) - { - opaquealpha = true; - hr = SetAlphaChannelToOpaque(image); - if (FAILED(hr)) - return hr; - } - else if (minalpha == 255) - { - opaquealpha = true; - } - } - break; - - //------------------------------------------------------ 24/32-bit (with swizzling) - case DXGI_FORMAT_R8G8B8A8_UNORM: - { - uint32_t minalpha = 255; - uint32_t maxalpha = 0; - - for (size_t y = 0; y < image->height; ++y) - { - size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); - - auto dPtr = reinterpret_cast(image->pixels - + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) - + offset; - - for (size_t x = 0; x < image->width; ++x) - { - if (convFlags & CONV_FLAGS_EXPAND) + for (size_t x = 0; x < image->width; ++x) { - assert(offset * 3 < rowPitch); - - if (sPtr + 2 >= endPtr) + if (sPtr + 1 >= endPtr) return E_FAIL; - // BGR -> RGBA - *dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | 0xFF000000; - sPtr += 3; + auto t = static_cast(uint32_t(*sPtr) | uint32_t(*(sPtr + 1u) << 8)); + sPtr += 2; + *dPtr = t; - minalpha = maxalpha = 255; + const uint32_t alpha = (t & 0x8000) ? 255 : 0; + minalpha = std::min(minalpha, alpha); + maxalpha = std::max(maxalpha, alpha); + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; } - else + } + + // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque + if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) + { + opaquealpha = true; + hr = SetAlphaChannelToOpaque(image); + if (FAILED(hr)) + return hr; + } + else if (minalpha == 255) + { + opaquealpha = true; + } + } + break; + + //------------------------------------------------------ 24/32-bit (with swizzling) + case DXGI_FORMAT_R8G8B8A8_UNORM: + { + uint32_t minalpha = 255; + uint32_t maxalpha = 0; + + for (size_t y = 0; y < image->height; ++y) + { + size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); + + auto dPtr = reinterpret_cast(image->pixels + + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) + + offset; + + for (size_t x = 0; x < image->width; ++x) + { + if (convFlags & CONV_FLAGS_EXPAND) + { + assert(offset * 3 < rowPitch); + + if (sPtr + 2 >= endPtr) + return E_FAIL; + + // BGR -> RGBA + *dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | 0xFF000000; + sPtr += 3; + + minalpha = maxalpha = 255; + } + else + { + assert(offset * 4 < rowPitch); + + if (sPtr + 3 >= endPtr) + return E_FAIL; + + // BGRA -> RGBA + uint32_t alpha = *(sPtr + 3); + *dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24); + + minalpha = std::min(minalpha, alpha); + maxalpha = std::max(maxalpha, alpha); + + sPtr += 4; + } + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } + } + + // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque + if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) + { + opaquealpha = true; + hr = SetAlphaChannelToOpaque(image); + if (FAILED(hr)) + return hr; + } + else if (minalpha == 255) + { + opaquealpha = true; + } + } + break; + + //-------------------------------------------------------------------- 32-bit (BGR) + case DXGI_FORMAT_B8G8R8A8_UNORM: + { + assert((convFlags & CONV_FLAGS_EXPAND) == 0); + + uint32_t minalpha = 255; + uint32_t maxalpha = 0; + + for (size_t y = 0; y < image->height; ++y) + { + size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); + + auto dPtr = reinterpret_cast(image->pixels + + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) + + offset; + + for (size_t x = 0; x < image->width; ++x) { assert(offset * 4 < rowPitch); if (sPtr + 3 >= endPtr) return E_FAIL; - // BGRA -> RGBA - uint32_t alpha = *(sPtr + 3); - *dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24); + const uint32_t alpha = *(sPtr + 3); + *dPtr = *reinterpret_cast(sPtr); minalpha = std::min(minalpha, alpha); maxalpha = std::max(maxalpha, alpha); sPtr += 4; + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; } - - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; } - } - // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque - if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) - { - opaquealpha = true; - hr = SetAlphaChannelToOpaque(image); - if (FAILED(hr)) - return hr; - } - else if (minalpha == 255) - { - opaquealpha = true; - } - } - break; - - //-------------------------------------------------------------------- 32-bit (BGR) - case DXGI_FORMAT_B8G8R8A8_UNORM: - { - assert((convFlags & CONV_FLAGS_EXPAND) == 0); - - uint32_t minalpha = 255; - uint32_t maxalpha = 0; - - for (size_t y = 0; y < image->height; ++y) - { - size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); - - auto dPtr = reinterpret_cast(image->pixels - + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) - + offset; - - for (size_t x = 0; x < image->width; ++x) + // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque + if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) { - assert(offset * 4 < rowPitch); - - if (sPtr + 3 >= endPtr) - return E_FAIL; - - const uint32_t alpha = *(sPtr + 3); - *dPtr = *reinterpret_cast(sPtr); - - minalpha = std::min(minalpha, alpha); - maxalpha = std::max(maxalpha, alpha); - - sPtr += 4; - - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; + opaquealpha = true; + hr = SetAlphaChannelToOpaque(image); + if (FAILED(hr)) + return hr; + } + else if (minalpha == 255) + { + opaquealpha = true; } } + break; - // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque - if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) - { - opaquealpha = true; - hr = SetAlphaChannelToOpaque(image); - if (FAILED(hr)) - return hr; - } - else if (minalpha == 255) - { - opaquealpha = true; - } - } - break; - - //-------------------------------------------------------------------- 24-bit (BGR) + //-------------------------------------------------------------------- 24-bit (BGR) case DXGI_FORMAT_B8G8R8X8_UNORM: - { - assert((convFlags & CONV_FLAGS_EXPAND) != 0); - - for (size_t y = 0; y < image->height; ++y) { - size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); + assert((convFlags & CONV_FLAGS_EXPAND) != 0); - auto dPtr = reinterpret_cast(image->pixels - + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) - + offset; - - for (size_t x = 0; x < image->width; ++x) + for (size_t y = 0; y < image->height; ++y) { - assert(offset * 3 < rowPitch); + size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0); - if (sPtr + 2 >= endPtr) - return E_FAIL; + auto dPtr = reinterpret_cast(image->pixels + + (image->rowPitch * ((convFlags & CONV_FLAGS_INVERTY) ? y : (image->height - y - 1)))) + + offset; - *dPtr = uint32_t(*sPtr) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2) << 16); - sPtr += 3; + for (size_t x = 0; x < image->width; ++x) + { + assert(offset * 3 < rowPitch); - if (convFlags & CONV_FLAGS_INVERTX) - --dPtr; - else - ++dPtr; + if (sPtr + 2 >= endPtr) + return E_FAIL; + + *dPtr = uint32_t(*sPtr) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2) << 16); + sPtr += 3; + + if (convFlags & CONV_FLAGS_INVERTX) + --dPtr; + else + ++dPtr; + } } } - } - break; + break; - //--------------------------------------------------------------------------------- + //--------------------------------------------------------------------------------- default: return E_FAIL; } @@ -1224,14 +1224,14 @@ namespace time_t now = {}; time(&now); -#ifdef WIN32 + #ifdef WIN32 tm info; auto pinfo = &info; if (!gmtime_s(pinfo, &now)) -#else + #else const tm* pinfo = gmtime(&now); if (pinfo) -#endif + #endif { ext->wStampMonth = static_cast(pinfo->tm_mon + 1); ext->wStampDay = static_cast(pinfo->tm_mday); @@ -1424,7 +1424,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags, { TGA_FOOTER footer = {}; -#ifdef WIN32 + #ifdef WIN32 if (SetFilePointer(hFile.get(), -static_cast(sizeof(TGA_FOOTER)), nullptr, FILE_END) != INVALID_SET_FILE_POINTER) { if (!ReadFile(hFile.get(), &footer, sizeof(TGA_FOOTER), &bytesRead, nullptr)) @@ -1437,7 +1437,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags, return E_FAIL; } } -#else + #else inFile.seekg(-static_cast(sizeof(TGA_FOOTER)), std::ios::end); if (inFile) { @@ -1445,14 +1445,14 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags, if (!inFile) return E_FAIL; } -#endif + #endif if (memcmp(footer.Signature, g_Signature, sizeof(g_Signature)) == 0) { if (footer.dwExtensionOffset != 0 && ((footer.dwExtensionOffset + sizeof(TGA_EXTENSION)) <= len)) { -#ifdef WIN32 + #ifdef WIN32 const LARGE_INTEGER filePos = { { static_cast(footer.dwExtensionOffset), 0 } }; if (SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { @@ -1463,7 +1463,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags, metadata.SetAlphaMode(GetAlphaModeFromExtension(ext)); } } -#else // !WIN32 + #else // !WIN32 inFile.seekg(static_cast(footer.dwExtensionOffset), std::ios::beg); if (inFile) { @@ -1474,7 +1474,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags, metadata.SetAlphaMode(GetAlphaModeFromExtension(ext)); } } -#endif + #endif } } } @@ -1659,7 +1659,7 @@ HRESULT DirectX::LoadFromTGAFile( if (!inFile) return E_FAIL; - size_t headerLen = sizeof(TGA_HEADER); + size_t headerLen = sizeof(TGA_HEADER); #endif size_t offset; @@ -1676,18 +1676,18 @@ HRESULT DirectX::LoadFromTGAFile( if (offset > sizeof(TGA_HEADER)) { -#ifdef WIN32 - // Skip past the id string + #ifdef WIN32 + // Skip past the id string const LARGE_INTEGER filePos = { { static_cast(offset), 0 } }; if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { return HRESULT_FROM_WIN32(GetLastError()); } -#else + #else inFile.seekg(offset, std::ios::beg); if (!inFile) return E_FAIL; -#endif + #endif } hr = image.Initialize2D(mdata.format, mdata.width, mdata.height, 1, 1); @@ -1713,7 +1713,7 @@ HRESULT DirectX::LoadFromTGAFile( return HRESULT_E_ARITHMETIC_OVERFLOW; } -#ifdef WIN32 + #ifdef WIN32 if (!ReadFile(hFile.get(), image.GetPixels(), static_cast(image.GetPixelsSize()), &bytesRead, nullptr)) { image.Release(); @@ -1725,195 +1725,195 @@ HRESULT DirectX::LoadFromTGAFile( image.Release(); return E_FAIL; } -#else + #else inFile.read(reinterpret_cast(image.GetPixels()), image.GetPixelsSize()); if (!inFile) { image.Release(); return E_FAIL; } -#endif + #endif switch (mdata.format) { case DXGI_FORMAT_R8G8B8A8_UNORM: - { - // TGA stores 32-bit data in BGRA form, need to swizzle to RGBA - assert(image.GetImageCount() == 1); - const Image* img = image.GetImage(0, 0, 0); - if (!img) { - image.Release(); - return E_POINTER; - } - - uint8_t *pPixels = img->pixels; - if (!pPixels) - { - image.Release(); - return E_POINTER; - } - - size_t rowPitch = img->rowPitch; - - // Scan for non-zero alpha channel - uint32_t minalpha = 255; - uint32_t maxalpha = 0; - - for (size_t h = 0; h < img->height; ++h) - { - auto sPtr = reinterpret_cast(pPixels); - - for (size_t x = 0; x < img->width; ++x) + // TGA stores 32-bit data in BGRA form, need to swizzle to RGBA + assert(image.GetImageCount() == 1); + const Image* img = image.GetImage(0, 0, 0); + if (!img) { - const uint32_t alpha = ((*sPtr & 0xFF000000) >> 24); - - minalpha = std::min(minalpha, alpha); - maxalpha = std::max(maxalpha, alpha); - - ++sPtr; + image.Release(); + return E_POINTER; } - pPixels += rowPitch; - } + uint8_t *pPixels = img->pixels; + if (!pPixels) + { + image.Release(); + return E_POINTER; + } - uint32_t tflags = TEXP_SCANLINE_NONE; - if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) - { - opaquealpha = true; - tflags = TEXP_SCANLINE_SETALPHA; - } - else if (minalpha == 255) - { - opaquealpha = true; - } + size_t rowPitch = img->rowPitch; - // Swizzle scanlines - pPixels = img->pixels; + // Scan for non-zero alpha channel + uint32_t minalpha = 255; + uint32_t maxalpha = 0; - for (size_t h = 0; h < img->height; ++h) - { - SwizzleScanline(pPixels, rowPitch, pPixels, rowPitch, mdata.format, tflags); - pPixels += rowPitch; + for (size_t h = 0; h < img->height; ++h) + { + auto sPtr = reinterpret_cast(pPixels); + + for (size_t x = 0; x < img->width; ++x) + { + const uint32_t alpha = ((*sPtr & 0xFF000000) >> 24); + + minalpha = std::min(minalpha, alpha); + maxalpha = std::max(maxalpha, alpha); + + ++sPtr; + } + + pPixels += rowPitch; + } + + uint32_t tflags = TEXP_SCANLINE_NONE; + if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) + { + opaquealpha = true; + tflags = TEXP_SCANLINE_SETALPHA; + } + else if (minalpha == 255) + { + opaquealpha = true; + } + + // Swizzle scanlines + pPixels = img->pixels; + + for (size_t h = 0; h < img->height; ++h) + { + SwizzleScanline(pPixels, rowPitch, pPixels, rowPitch, mdata.format, tflags); + pPixels += rowPitch; + } } - } - break; + break; case DXGI_FORMAT_B8G8R8A8_UNORM: - { - assert(image.GetImageCount() == 1); - const Image* img = image.GetImage(0, 0, 0); - if (!img) { - image.Release(); - return E_POINTER; - } - - // Scan for non-zero alpha channel - uint32_t minalpha = 255; - uint32_t maxalpha = 0; - - const uint8_t *pPixels = img->pixels; - if (!pPixels) - { - image.Release(); - return E_POINTER; - } - - const size_t rowPitch = img->rowPitch; - - for (size_t h = 0; h < img->height; ++h) - { - auto sPtr = reinterpret_cast(pPixels); - - for (size_t x = 0; x < img->width; ++x) - { - const uint32_t alpha = ((*sPtr & 0xFF000000) >> 24); - - minalpha = std::min(minalpha, alpha); - maxalpha = std::max(maxalpha, alpha); - - ++sPtr; - } - - pPixels += rowPitch; - } - - // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque - if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) - { - opaquealpha = true; - hr = SetAlphaChannelToOpaque(img); - if (FAILED(hr)) + assert(image.GetImageCount() == 1); + const Image* img = image.GetImage(0, 0, 0); + if (!img) { image.Release(); - return hr; + return E_POINTER; + } + + // Scan for non-zero alpha channel + uint32_t minalpha = 255; + uint32_t maxalpha = 0; + + const uint8_t *pPixels = img->pixels; + if (!pPixels) + { + image.Release(); + return E_POINTER; + } + + const size_t rowPitch = img->rowPitch; + + for (size_t h = 0; h < img->height; ++h) + { + auto sPtr = reinterpret_cast(pPixels); + + for (size_t x = 0; x < img->width; ++x) + { + const uint32_t alpha = ((*sPtr & 0xFF000000) >> 24); + + minalpha = std::min(minalpha, alpha); + maxalpha = std::max(maxalpha, alpha); + + ++sPtr; + } + + pPixels += rowPitch; + } + + // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque + if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) + { + opaquealpha = true; + hr = SetAlphaChannelToOpaque(img); + if (FAILED(hr)) + { + image.Release(); + return hr; + } + } + else if (minalpha == 255) + { + opaquealpha = true; } } - else if (minalpha == 255) - { - opaquealpha = true; - } - } - break; + break; case DXGI_FORMAT_B5G5R5A1_UNORM: - { - assert(image.GetImageCount() == 1); - const Image* img = image.GetImage(0, 0, 0); - if (!img) { - image.Release(); - return E_POINTER; - } - - // Scan for non-zero alpha channel - uint32_t minalpha = 255; - uint32_t maxalpha = 0; - - const uint8_t *pPixels = img->pixels; - if (!pPixels) - { - image.Release(); - return E_POINTER; - } - - const size_t rowPitch = img->rowPitch; - - for (size_t h = 0; h < img->height; ++h) - { - auto sPtr = reinterpret_cast(pPixels); - - for (size_t x = 0; x < img->width; ++x) - { - const uint32_t alpha = (*sPtr & 0x8000) ? 255 : 0; - - minalpha = std::min(minalpha, alpha); - maxalpha = std::max(maxalpha, alpha); - - ++sPtr; - } - - pPixels += rowPitch; - } - - // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque - if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) - { - opaquealpha = true; - hr = SetAlphaChannelToOpaque(img); - if (FAILED(hr)) + assert(image.GetImageCount() == 1); + const Image* img = image.GetImage(0, 0, 0); + if (!img) { image.Release(); - return hr; + return E_POINTER; + } + + // Scan for non-zero alpha channel + uint32_t minalpha = 255; + uint32_t maxalpha = 0; + + const uint8_t *pPixels = img->pixels; + if (!pPixels) + { + image.Release(); + return E_POINTER; + } + + const size_t rowPitch = img->rowPitch; + + for (size_t h = 0; h < img->height; ++h) + { + auto sPtr = reinterpret_cast(pPixels); + + for (size_t x = 0; x < img->width; ++x) + { + const uint32_t alpha = (*sPtr & 0x8000) ? 255 : 0; + + minalpha = std::min(minalpha, alpha); + maxalpha = std::max(maxalpha, alpha); + + ++sPtr; + } + + pPixels += rowPitch; + } + + // If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque + if (maxalpha == 0 && !(flags & TGA_FLAGS_ALLOW_ALL_ZERO_ALPHA)) + { + opaquealpha = true; + hr = SetAlphaChannelToOpaque(img); + if (FAILED(hr)) + { + image.Release(); + return hr; + } + } + else if (minalpha == 255) + { + opaquealpha = true; } } - else if (minalpha == 255) - { - opaquealpha = true; - } - } - break; + break; case DXGI_FORMAT_B8G8R8X8_UNORM: // Should never be trying to direct-read 24bpp @@ -1932,7 +1932,7 @@ HRESULT DirectX::LoadFromTGAFile( return E_OUTOFMEMORY; } -#ifdef WIN32 + #ifdef WIN32 if (!ReadFile(hFile.get(), temp.get(), static_cast(remaining), &bytesRead, nullptr)) { image.Release(); @@ -1944,14 +1944,14 @@ HRESULT DirectX::LoadFromTGAFile( image.Release(); return E_FAIL; } -#else + #else inFile.read(reinterpret_cast(temp.get()), remaining); if (!inFile) { image.Release(); return E_FAIL; } -#endif + #endif if (convFlags & CONV_FLAGS_RLE) { @@ -1978,7 +1978,7 @@ HRESULT DirectX::LoadFromTGAFile( { TGA_FOOTER footer = {}; -#ifdef WIN32 + #ifdef WIN32 if (SetFilePointer(hFile.get(), -static_cast(sizeof(TGA_FOOTER)), nullptr, FILE_END) != INVALID_SET_FILE_POINTER) { if (!ReadFile(hFile.get(), &footer, sizeof(TGA_FOOTER), &bytesRead, nullptr)) @@ -1993,7 +1993,7 @@ HRESULT DirectX::LoadFromTGAFile( return E_FAIL; } } -#else // !WIN32 + #else // !WIN32 inFile.seekg(-static_cast(sizeof(TGA_FOOTER)), std::ios::end); if (inFile) { @@ -2004,14 +2004,14 @@ HRESULT DirectX::LoadFromTGAFile( return E_FAIL; } } -#endif + #endif if (memcmp(footer.Signature, g_Signature, sizeof(g_Signature)) == 0) { if (footer.dwExtensionOffset != 0 && ((footer.dwExtensionOffset + sizeof(TGA_EXTENSION)) <= len)) { -#ifdef WIN32 + #ifdef WIN32 const LARGE_INTEGER filePos = { { static_cast(footer.dwExtensionOffset), 0 } }; if (SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { @@ -2021,7 +2021,7 @@ HRESULT DirectX::LoadFromTGAFile( ext = &extData; } } -#else // !WIN32 + #else // !WIN32 inFile.seekg(static_cast(footer.dwExtensionOffset), std::ios::beg); if (inFile) { @@ -2031,7 +2031,7 @@ HRESULT DirectX::LoadFromTGAFile( ext = &extData; } } -#endif + #endif } } } @@ -2211,7 +2211,7 @@ HRESULT DirectX::SaveToTGAFile( return hr; // Write blob -#ifdef WIN32 + #ifdef WIN32 const DWORD bytesToWrite = static_cast(blob.GetBufferSize()); DWORD bytesWritten; if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr)) @@ -2223,13 +2223,13 @@ HRESULT DirectX::SaveToTGAFile( { return E_FAIL; } -#else + #else outFile.write(reinterpret_cast(blob.GetBufferPointer()), static_cast(blob.GetBufferSize())); if (!outFile) return E_FAIL; -#endif + #endif } else { @@ -2239,7 +2239,7 @@ HRESULT DirectX::SaveToTGAFile( return E_OUTOFMEMORY; // Write header -#ifdef WIN32 + #ifdef WIN32 DWORD bytesWritten; if (!WriteFile(hFile.get(), &tga_header, sizeof(TGA_HEADER), &bytesWritten, nullptr)) { @@ -2248,11 +2248,11 @@ HRESULT DirectX::SaveToTGAFile( if (bytesWritten != sizeof(TGA_HEADER)) return E_FAIL; -#else + #else outFile.write(reinterpret_cast(&tga_header), sizeof(TGA_HEADER)); if (!outFile) return E_FAIL; -#endif + #endif if (rowPitch > UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; @@ -2278,7 +2278,7 @@ HRESULT DirectX::SaveToTGAFile( pPixels += image.rowPitch; -#ifdef WIN32 + #ifdef WIN32 if (!WriteFile(hFile.get(), temp.get(), static_cast(rowPitch), &bytesWritten, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); @@ -2286,11 +2286,11 @@ HRESULT DirectX::SaveToTGAFile( if (bytesWritten != rowPitch) return E_FAIL; -#else + #else outFile.write(reinterpret_cast(temp.get()), rowPitch); if (!outFile) return E_FAIL; -#endif + #endif } uint32_t extOffset = 0; @@ -2300,7 +2300,7 @@ HRESULT DirectX::SaveToTGAFile( TGA_EXTENSION ext = {}; SetExtension(&ext, flags, *metadata); -#ifdef WIN32 + #ifdef WIN32 extOffset = SetFilePointer(hFile.get(), 0, nullptr, FILE_CURRENT); if (extOffset == INVALID_SET_FILE_POINTER) { @@ -2314,7 +2314,7 @@ HRESULT DirectX::SaveToTGAFile( if (bytesWritten != sizeof(TGA_EXTENSION)) return E_FAIL; -#else + #else extOffset = static_cast(outFile.tellp()); if (!outFile) return E_FAIL; @@ -2322,7 +2322,7 @@ HRESULT DirectX::SaveToTGAFile( outFile.write(reinterpret_cast(&ext), sizeof(TGA_EXTENSION)); if (!outFile) return E_FAIL; -#endif + #endif } // Write TGA 2.0 footer @@ -2330,7 +2330,7 @@ HRESULT DirectX::SaveToTGAFile( footer.dwExtensionOffset = extOffset; memcpy(footer.Signature, g_Signature, sizeof(g_Signature)); -#ifdef WIN32 + #ifdef WIN32 if (!WriteFile(hFile.get(), &footer, sizeof(TGA_FOOTER), &bytesWritten, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); @@ -2338,11 +2338,11 @@ HRESULT DirectX::SaveToTGAFile( if (bytesWritten != sizeof(footer)) return E_FAIL; -#else + #else outFile.write(reinterpret_cast(&footer), sizeof(TGA_FOOTER)); if (!outFile) return E_FAIL; -#endif + #endif } #ifdef WIN32 diff --git a/DirectXTex/DirectXTexUtil.cpp b/DirectXTex/DirectXTexUtil.cpp index ed312c1..af66c6a 100644 --- a/DirectXTex/DirectXTexUtil.cpp +++ b/DirectXTex/DirectXTexUtil.cpp @@ -122,7 +122,7 @@ namespace return std::aligned_alloc(alignment, size); } - #define _aligned_free free +#define _aligned_free free #endif } @@ -157,56 +157,56 @@ bool DirectX::Internal::DXGIToWIC(DXGI_FORMAT format, GUID& guid, bool ignoreRGB { switch (format) { - case DXGI_FORMAT_R8G8B8A8_UNORM: - case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: - if (ignoreRGBvsBGR) - { - // 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 - 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: + case DXGI_FORMAT_R8G8B8A8_UNORM: + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + if (ignoreRGBvsBGR) + { + // 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 memcpy(&guid, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID)); - return true; + } + else + { + memcpy(&guid, &GUID_WICPixelFormat32bppRGBA, sizeof(GUID)); + } + return true; - case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: - memcpy(&guid, &GUID_WICPixelFormat32bppBGR, sizeof(GUID)); - return true; + case DXGI_FORMAT_D32_FLOAT: + memcpy(&guid, &GUID_WICPixelFormat32bppGrayFloat, sizeof(GUID)); + return true; - #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) - case DXGI_FORMAT_R32G32B32_FLOAT: - if (g_WIC2) + 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)); + 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; } - break; - #endif - - 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; + } + break; } memset(&guid, 0, sizeof(GUID)); @@ -317,14 +317,14 @@ void DirectX::SetWICFactory(_In_opt_ IWICImagingFactory* pWIC) noexcept bool iswic2 = false; if (pWIC) { -#if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) + #if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) ComPtr wic2; HRESULT hr = pWIC->QueryInterface(IID_PPV_ARGS(wic2.GetAddressOf())); if (SUCCEEDED(hr)) { iswic2 = true; } -#endif + #endif pWIC->AddRef(); } diff --git a/DirectXTex/DirectXTexWIC.cpp b/DirectXTex/DirectXTexWIC.cpp index 16c22e7..fc1ebac 100644 --- a/DirectXTex/DirectXTexWIC.cpp +++ b/DirectXTex/DirectXTexWIC.cpp @@ -106,7 +106,7 @@ namespace { 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 (pConvert) @@ -114,9 +114,9 @@ namespace format = DXGI_FORMAT_R32G32B32_FLOAT; } else -#else + #else UNREFERENCED_PARAMETER(iswic2); -#endif + #endif { if (pConvert) memcpy_s(pConvert, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat128bppRGBAFloat, sizeof(GUID)); @@ -600,7 +600,7 @@ namespace 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) { 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; } } -#else + #else else if (SUCCEEDED(metareader->GetMetadataByName(L"System.Image.ColorSpace", &value)) && value.vt == VT_UI2) { sRGB = (value.uiVal == 1); @@ -632,7 +632,7 @@ namespace { sRGB = (flags & WIC_FLAGS_DEFAULT_SRGB) != 0; } -#endif + #endif std::ignore = PropVariantClear(&value); @@ -913,7 +913,7 @@ namespace 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) { // Set Software name @@ -940,7 +940,7 @@ namespace std::ignore = metawriter->SetMetadataByName(L"/ifd/exif/{ushort=40961}", &value); } } -#else + #else else { // Set Software name @@ -954,7 +954,7 @@ namespace std::ignore = metawriter->SetMetadataByName(L"System.Image.ColorSpace", &value); } } -#endif + #endif } else if (hr == WINCODEC_ERR_UNSUPPORTEDOPERATION) { diff --git a/DirectXTex/Shaders/BC6HEncode.hlsl b/DirectXTex/Shaders/BC6HEncode.hlsl index 2fc025a..7daea76 100644 --- a/DirectXTex/Shaders/BC6HEncode.hlsl +++ b/DirectXTex/Shaders/BC6HEncode.hlsl @@ -18,7 +18,7 @@ #define MAX_INT asint(0x7FFFFFFF) #define MIN_INT asint(0x80000000) -cbuffer cbCS : register( b0 ) +cbuffer cbCS : register(b0) { uint g_tex_width; uint g_num_block_x; @@ -36,7 +36,7 @@ static const uint4 candidateModePrec[14] = { uint4(10,5,5,5), uint4(7,6,6,6), uint4(8,6,5,5), uint4(8,5,6,5), uint4(8,5,5,6), uint4(6,6,6,6), uint4(10,10,10,10), uint4(11,9,9,9), uint4(12,8,8,8), uint4(16,4,4,4) }; -/*static const uint4x4 candidateSection[32] = +/*static const uint4x4 candidateSection[32] = { {0,0,1,1, 0,0,1,1, 0,0,1,1, 0,0,1,1}, {0,0,0,1, 0,0,0,1, 0,0,0,1, 0,0,0,1}, {0,1,1,1, 0,1,1,1, 0,1,1,1, 0,1,1,1}, {0,0,0,1, 0,0,1,1, 0,0,1,1, 0,1,1,1}, {0,0,0,0, 0,0,0,1, 0,0,0,1, 0,0,1,1}, {0,0,1,1, 0,1,1,1, 0,1,1,1, 1,1,1,1}, {0,0,0,1, 0,0,1,1, 0,1,1,1, 1,1,1,1}, {0,0,0,0, 0,0,0,1, 0,0,1,1, 0,1,1,1}, @@ -48,7 +48,7 @@ static const uint4 candidateModePrec[14] = { uint4(10,5,5,5), uint4(7,6,6,6), {0,0,0,1, 0,1,1,1, 1,1,1,0, 1,0,0,0}, {0,0,0,0, 1,1,1,1, 1,1,1,1, 0,0,0,0}, {0,1,1,1, 0,0,0,1, 1,0,0,0, 1,1,1,0}, {0,0,1,1, 1,0,0,1, 1,0,0,1, 1,1,0,0} };*/ -static const uint candidateSectionBit[32] = +static const uint candidateSectionBit[32] = { 0xCCCC, 0x8888, 0xEEEE, 0xECC8, 0xC880, 0xFEEC, 0xFEC8, 0xEC80, @@ -60,7 +60,7 @@ static const uint candidateSectionBit[32] = 0x17E8, 0x0FF0, 0x718E, 0x399C }; -static const uint candidateFixUpIndex1D[32] = +static const uint candidateFixUpIndex1D[32] = { 15,15,15,15, 15,15,15,15, @@ -73,15 +73,15 @@ static const uint candidateFixUpIndex1D[32] = }; //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, 2,2,2,2,2,2,2,3, 3,3,3,3,3,3,3,3, 3,4,4,4,4,4,4,4, 4,4,5,5,5,5,5,5, 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 static const uint aStep2[64] = { 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, @@ -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, 9,10,10,10,10,10,11,11, 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); @@ -101,23 +101,23 @@ static const float3 RGB2LUM = float3(0.2126f, 0.7152f, 0.0722f); //Forward declaration -uint3 float2half( float3 pixel_f ); -int3 start_quantize( uint3 pixel_h ); -void quantize( inout int2x3 endPoint, uint prec ); -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( out bool bBadQuantize, inout int2x3 endPoint, uint4 prec, bool transformed ); +uint3 float2half(float3 pixel_f); +int3 start_quantize(uint3 pixel_h); +void quantize(inout int2x3 endPoint, uint prec); +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(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, uint4 prec, bool transformed ); -void unquantize( inout int2x3 color, uint prec ); -uint3 finish_unquantize( int3 color ); -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 ); -float3 half2float(uint3 color_h ); +void start_unquantize(inout int2x3 endPoint[2], uint4 prec, bool transformed); +void start_unquantize(inout int2x3 endPoint, uint4 prec, bool transformed); +void unquantize(inout int2x3 color, uint prec); +uint3 finish_unquantize(int3 color); +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); +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, uint mode_type ); +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 swap(inout int3 lhs, inout int3 rhs) { @@ -126,10 +126,10 @@ void swap(inout int3 lhs, inout int3 rhs) rhs = tmp; } -Texture2D g_Input : register( t0 ); -StructuredBuffer g_InBuff : register( t1 ); +Texture2D g_Input : register(t0); +StructuredBuffer g_InBuff : register(t1); -RWStructuredBuffer g_OutBuff : register( u0 ); +RWStructuredBuffer g_OutBuff : register(u0); struct SharedData { @@ -148,8 +148,8 @@ struct SharedData groupshared SharedData shared_temp[THREAD_GROUP_SIZE]; -[numthreads( THREAD_GROUP_SIZE, 1, 1 )] -void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) +[numthreads(THREAD_GROUP_SIZE, 1, 1)] +void TryModeG10CS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) { const uint MAX_USED_THREAD = 16; uint BLOCK_IN_GROUP = THREAD_GROUP_SIZE / MAX_USED_THREAD; @@ -164,20 +164,20 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) return; } #endif - + uint block_y = blockID / g_num_block_x; uint block_x = blockID - block_y * g_num_block_x; uint base_x = block_x * BLOCK_SIZE_X; uint base_y = block_y * BLOCK_SIZE_Y; - + if (threadInBlock < 16) { - 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 ); + 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); shared_temp[GI].pixel_hr = half2float(pixel_h); 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_high = shared_temp[GI].pixel_ph; shared_temp[GI].endPoint_lum_low = shared_temp[GI].pixel_lum; @@ -186,7 +186,7 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) #ifdef REF_DEVICE GroupMemoryBarrierWithGroupSync(); #endif - + if (threadInBlock < 8) { if (shared_temp[GI].endPoint_lum_low > shared_temp[GI + 8].endPoint_lum_low) @@ -253,18 +253,18 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) #endif //ergod mode_type 11:14 - if ( threadInBlock == 0 ) + if (threadInBlock == 0) { int2x3 endPoint; // find_axis endPoint[0] = shared_temp[threadBase + 0].endPoint_low; endPoint[1] = shared_temp[threadBase + 0].endPoint_high; - + //compute_index 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 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 ) + 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 + if (span_norm_sqr > 0 && dotProduct >= 0 && uint(dotProduct * 63.49999 / span_norm_sqr) > 32) { swap(endPoint[0], endPoint[1]); @@ -281,41 +281,41 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) int2x3 endPoint; endPoint[0] = shared_temp[threadBase + 0].endPoint_low; endPoint[1] = shared_temp[threadBase + 0].endPoint_high; - + 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]; int2x3 endPoint_q = endPoint; - quantize( endPoint_q, prec.x ); + quantize(endPoint_q, prec.x); bool transformed = candidateModeTransformed[threadInBlock + 10]; if (transformed) { endPoint_q[1] -= endPoint_q[0]; } - + bool bBadQuantize; - finish_quantize( bBadQuantize, endPoint_q, prec, transformed ); - - start_unquantize( endPoint_q, prec, transformed ); - - unquantize( endPoint_q, prec.x ); - + finish_quantize(bBadQuantize, endPoint_q, prec, transformed); + + start_unquantize(endPoint_q, prec, transformed); + + unquantize(endPoint_q, prec.x); + 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 - uint index = ( span_norm_sqr <= 0 || dotProduct <= 0 ) ? 0 - : ( ( dotProduct < span_norm_sqr ) ? aStep2[ uint( dotProduct * 63.49999 / span_norm_sqr ) ] : aStep2[63] ); - + 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 + : ((dotProduct < span_norm_sqr) ? aStep2[uint(dotProduct * 63.49999 / span_norm_sqr)] : aStep2[63]); + uint3 pixel_rh; - generate_palette_unquantized16( pixel_rh, endPoint_q[0], endPoint_q[1], index ); - float3 pixel_r = half2float( pixel_rh ); + generate_palette_unquantized16(pixel_rh, endPoint_q[0], endPoint_q[1], index); + float3 pixel_r = half2float(pixel_rh); pixel_r -= shared_temp[threadBase + j].pixel_hr; error += dot(pixel_r, pixel_r); } - if ( bBadQuantize ) + if (bBadQuantize) error = 1e20f; shared_temp[GI].error = error; @@ -324,10 +324,10 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) #ifdef REF_DEVICE GroupMemoryBarrierWithGroupSync(); #endif - + 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].best_mode = shared_temp[GI + 2].best_mode; @@ -338,18 +338,18 @@ void TryModeG10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) #endif 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].best_mode = shared_temp[GI + 1].best_mode; } - + g_OutBuff[blockID] = uint4(asuint(shared_temp[GI].error), shared_temp[GI].best_mode, 0, 0); } } -[numthreads( THREAD_GROUP_SIZE, 1, 1 )] -void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) +[numthreads(THREAD_GROUP_SIZE, 1, 1)] +void TryModeLE10CS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) { const uint MAX_USED_THREAD = 32; uint BLOCK_IN_GROUP = THREAD_GROUP_SIZE / MAX_USED_THREAD; @@ -370,24 +370,24 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) return; } #endif - + uint block_y = blockID / g_num_block_x; uint block_x = blockID - block_y * g_num_block_x; uint base_x = block_x * BLOCK_SIZE_X; uint base_y = block_y * BLOCK_SIZE_Y; - + if (threadInBlock < 16) { - 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 ); + 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); shared_temp[GI].pixel_hr = half2float(pixel_h); 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 GroupMemoryBarrierWithGroupSync(); #endif - + //ergod mode_type 1:10 if (threadInBlock < 32) { @@ -397,7 +397,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) endPoint[0][1] = MIN_INT; endPoint[1][0] = MAX_INT; endPoint[1][1] = MIN_INT; - + float2 endPoint_lum[2]; endPoint_lum[0][0] = MAX_FLOAT; endPoint_lum[0][1] = MIN_FLOAT; @@ -405,11 +405,11 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) endPoint_lum[1][1] = MIN_FLOAT; 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; 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) { @@ -436,18 +436,18 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) } } } - + //compute_index float3 span[2];// fixed a bug in v0.2 float span_norm_sqr[2];// fixed a bug in v0.2 [unroll] - for (uint p = 0; p < 2; ++ p) + for (uint p = 0; p < 2; ++p) { 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 - if ( span_norm_sqr[p] > 0 && dotProduct >= 0 && uint( dotProduct * 63.49999 / span_norm_sqr[p] ) > 32 ) + 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) { span[p] = -span[p]; 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]; int2x3 endPoint_q[2] = endPoint; - quantize( endPoint_q[0], prec.x ); - quantize( endPoint_q[1], prec.x ); + quantize(endPoint_q[0], prec.x); + quantize(endPoint_q[1], prec.x); bool transformed = candidateModeTransformed[g_mode_id]; if (transformed) @@ -468,38 +468,38 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) } int bBadQuantize = 0; - finish_quantize_0( bBadQuantize, endPoint_q[0], prec, transformed ); - finish_quantize_1( bBadQuantize, endPoint_q[1], prec, transformed ); - - start_unquantize( endPoint_q, prec, transformed ); - - unquantize( endPoint_q[0], prec.x ); - unquantize( endPoint_q[1], prec.x ); - + finish_quantize_0(bBadQuantize, endPoint_q[0], prec, transformed); + finish_quantize_1(bBadQuantize, endPoint_q[1], prec, transformed); + + start_unquantize(endPoint_q, prec, transformed); + + unquantize(endPoint_q[0], prec.x); + unquantize(endPoint_q[1], prec.x); + float error = 0; - for ( uint j = 0; j < 16; j ++ ) + for (uint j = 0; j < 16; j++) { uint3 pixel_rh; if ((bit >> j) & 1) { - 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 - : ( ( 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 ); + 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 + : ((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); } else { - 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 - : ( ( 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 ); + 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 + : ((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); } - float3 pixel_r = half2float( pixel_rh ); + float3 pixel_r = half2float(pixel_rh); pixel_r -= shared_temp[threadBase + j].pixel_hr; error += dot(pixel_r, pixel_r); } - if ( bBadQuantize ) + if (bBadQuantize) error = 1e20f; shared_temp[GI].error = error; @@ -509,10 +509,10 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) #ifdef REF_DEVICE GroupMemoryBarrierWithGroupSync(); #endif - + 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].best_mode = shared_temp[GI + 16].best_mode; @@ -524,7 +524,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) #endif 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].best_mode = shared_temp[GI + 8].best_mode; @@ -536,7 +536,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) #endif 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].best_mode = shared_temp[GI + 4].best_mode; @@ -548,7 +548,7 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) #endif 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].best_mode = shared_temp[GI + 2].best_mode; @@ -560,13 +560,13 @@ void TryModeLE10CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) #endif 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].best_mode = shared_temp[GI + 1].best_mode; shared_temp[GI].best_partition = shared_temp[GI + 1].best_partition; } - + if (asfloat(g_InBuff[blockID].x) > shared_temp[GI].error) { g_OutBuff[blockID] = uint4(asuint(shared_temp[GI].error), shared_temp[GI].best_mode, shared_temp[GI].best_partition, 0); @@ -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) { const uint MAX_USED_THREAD = 32; @@ -599,21 +599,21 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) uint block_x = blockID - block_y * g_num_block_x; uint base_x = block_x * BLOCK_SIZE_X; uint base_y = block_y * BLOCK_SIZE_Y; - + 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); - uint3 pixel_h = float2half( shared_temp[GI].pixel ); - shared_temp[GI].pixel_ph = start_quantize( pixel_h ); + uint3 pixel_h = float2half(shared_temp[GI].pixel); + shared_temp[GI].pixel_ph = start_quantize(pixel_h); } #ifdef REF_DEVICE GroupMemoryBarrierWithGroupSync(); #endif - + uint best_mode = g_InBuff[blockID].y; uint best_partition = g_InBuff[blockID].z; - + uint4 block = 0; if (threadInBlock < 32) @@ -625,7 +625,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) float2 endPoint_lum; endPoint_lum[0] = MAX_FLOAT; endPoint_lum[1] = MIN_FLOAT; - + int2 endPoint_lum_index; endPoint_lum_index[0] = -1; endPoint_lum_index[1] = -1; @@ -664,7 +664,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) shared_temp[GI].endPoint_low = endPoint[0]; shared_temp[GI].endPoint_high = endPoint[1]; - + shared_temp[GI].endPoint_lum_low = endPoint_lum[0]; shared_temp[GI].endPoint_lum_high = endPoint_lum[1]; } @@ -748,11 +748,11 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) { fixup = candidateFixUpIndex1D[best_partition]; } - + float3 span = endPoint[1] - endPoint[0]; - float span_norm_sqr = dot( span, span ); - 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 ) + float span_norm_sqr = dot(span, span); + 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) { swap(endPoint[0], endPoint[1]); } @@ -763,7 +763,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) #ifdef REF_DEVICE GroupMemoryBarrierWithGroupSync(); #endif - + if (threadInBlock < 16) { uint bits; @@ -781,19 +781,19 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) if ((bits >> threadInBlock) & 1) { 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 { 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) { - uint index = ( span_norm_sqr <= 0 || dotProduct <= 0 ) ? 0 - : ( ( dotProduct < span_norm_sqr ) ? aStep2[ uint( dotProduct * 63.49999 / span_norm_sqr ) ] : aStep2[63] ); + uint index = (span_norm_sqr <= 0 || dotProduct <= 0) ? 0 + : ((dotProduct < span_norm_sqr) ? aStep2[uint(dotProduct * 63.49999 / span_norm_sqr)] : aStep2[63]); if (threadInBlock == 0) { block.z |= index << 1; @@ -809,8 +809,8 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) } else { - uint index = ( span_norm_sqr <= 0 || dotProduct <= 0 ) ? 0 - : ( ( dotProduct < span_norm_sqr ) ? aStep1[ uint( dotProduct * 63.49999 / span_norm_sqr ) ] : aStep1[63] ); + uint index = (span_norm_sqr <= 0 || dotProduct <= 0) ? 0 + : ((dotProduct < span_norm_sqr) ? aStep1[uint(dotProduct * 63.49999 / span_norm_sqr)] : aStep1[63]); uint fixup = candidateFixUpIndex1D[best_partition]; int2 offset = int2((fixup != 2), (fixup == 15)); @@ -844,7 +844,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) block.w |= index << (11 + (threadInBlock - 9) * 3 + offset.y); } } - + shared_temp[GI].pixel_hr.xy = asfloat(block.zw); } #ifdef REF_DEVICE @@ -874,7 +874,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) if (threadInBlock < 1) { shared_temp[GI].pixel_hr.xy = asfloat(asuint(shared_temp[GI].pixel_hr.xy) | asuint(shared_temp[GI + 1].pixel_hr.xy)); - + block.zw = asuint(shared_temp[GI].pixel_hr.xy); } #ifdef REF_DEVICE @@ -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[1] = shared_temp[threadBase + 0].endPoint_high; - quantize( endPoint_q, prec.x ); + quantize(endPoint_q, prec.x); if (transformed) { endPoint_q[1] -= endPoint_q[0]; @@ -910,7 +910,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) if (best_mode <= 10) { - quantize( endPoint_q, prec.x ); + quantize(endPoint_q, prec.x); if (transformed) { endPoint_q[0] -= ep0; @@ -936,18 +936,18 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) { if (best_mode > 10) { - finish_quantize( bBadQuantize, endPoint_q, prec, transformed ); + finish_quantize(bBadQuantize, endPoint_q, prec, transformed); } else { - finish_quantize_0( bBadQuantize, endPoint_q, prec, transformed ); + finish_quantize_0(bBadQuantize, endPoint_q, prec, transformed); } } else // if (threadInBlock == 1) { if (best_mode <= 10) { - finish_quantize_1( bBadQuantize, endPoint_q, prec, transformed ); + finish_quantize_1(bBadQuantize, endPoint_q, prec, transformed); } } @@ -957,8 +957,8 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) #ifdef REF_DEVICE GroupMemoryBarrierWithGroupSync(); #endif - - if ( threadInBlock == 0 ) + + if (threadInBlock == 0) { int2x3 endPoint_q[2]; endPoint_q[0][0] = shared_temp[threadBase + 0].endPoint_low; @@ -966,27 +966,27 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) endPoint_q[1][0] = shared_temp[threadBase + 1].endPoint_low; 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 { - block_package( block, endPoint_q, best_mode, best_partition ); + block_package(block, endPoint_q, best_mode, best_partition); } - + g_OutBuff[blockID] = block; } } -uint float2half1( float f ) +uint float2half1(float f) { uint Result; uint IValue = asuint(f); uint Sign = (IValue & 0x80000000U) >> 16U; IValue = IValue & 0x7FFFFFFFU; - + if (IValue > 0x47FFEFFFU) { // The number is too large to be represented as a half. Saturate to infinity. @@ -1007,12 +1007,12 @@ uint float2half1( float f ) IValue += 0xC8000000U; } - Result = ((IValue + 0x0FFFU + ((IValue >> 13U) & 1U)) >> 13U)&0x7FFFU; + Result = ((IValue + 0x0FFFU + ((IValue >> 13U) & 1U)) >> 13U)&0x7FFFU; } return (Result|Sign); } -uint3 float2half( float3 endPoint_f ) +uint3 float2half(float3 endPoint_f) { //uint3 sign = asuint(endPoint_f) & 0x80000000; //uint3 expo = asuint(endPoint_f) & 0x7F800000; @@ -1027,140 +1027,140 @@ uint3 float2half( float3 endPoint_f ) // : ( ( 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 { - 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 + 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 } } -void quantize( inout int2x3 endPoint, uint prec ) +void quantize(inout int2x3 endPoint, uint prec) { - int iprec = asint( prec ); - if ( g_format == UNSIGNED_F16 ) + int iprec = asint(prec); + if (g_format == UNSIGNED_F16) { - endPoint = ( ( iprec >= 15 ) | ( endPoint == 0 ) ) ? endPoint - : ( ( endPoint == asint(0xFFFF) ) ? ( ( 1 << iprec ) - 1 ) - : ( ( ( endPoint << iprec ) + asint(0x0000) ) >> 16 ) ); + endPoint = ((iprec >= 15) | (endPoint == 0)) ? endPoint + : ((endPoint == asint(0xFFFF)) ? ((1 << iprec) - 1) + : (((endPoint << iprec) + asint(0x0000)) >> 16)); } else { - endPoint = ( ( iprec >= 16 ) | ( endPoint == 0 ) ) ? endPoint - : ( ( 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 = ((iprec >= 16) | (endPoint == 0)) ? endPoint + : ((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))); } } -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 ) ) ) - : ( -endPoint[1] > ( 1 << ( prec.yzw - 1 ) ) ); + bool3 bBadComponent = (endPoint[1] >= 0) ? (endPoint[1] >= (1 << (prec.yzw - 1))) + : (-endPoint[1] > (1 << (prec.yzw - 1))); bBadQuantize |= any(bBadComponent); - 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] > ( 1 << ( prec.yzw - 1 ) ) ) ? ( 1 << ( prec.yzw - 1 ) ) : ( endPoint[1] & ( ( 1 << prec.yzw ) - 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] > (1 << (prec.yzw - 1))) ? (1 << (prec.yzw - 1)) : (endPoint[1] & ((1 << prec.yzw) - 1))); } 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; - bBadComponent[0] = ( endPoint[0] >= 0 ) ? ( endPoint[0] >= ( 1 << ( prec.yzw - 1 ) ) ) - : ( -endPoint[0] > ( 1 << ( prec.yzw - 1 ) ) ); - bBadComponent[1] = ( endPoint[1] >= 0 ) ? ( endPoint[1] >= ( 1 << ( prec.yzw - 1 ) ) ) - : ( -endPoint[1] > ( 1 << ( prec.yzw - 1 ) ) ); + bBadComponent[0] = (endPoint[0] >= 0) ? (endPoint[0] >= (1 << (prec.yzw - 1))) + : (-endPoint[0] > (1 << (prec.yzw - 1))); + bBadComponent[1] = (endPoint[1] >= 0) ? (endPoint[1] >= (1 << (prec.yzw - 1))) + : (-endPoint[1] > (1 << (prec.yzw - 1))); bBadQuantize |= any(bBadComponent); - 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[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[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[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))); } 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; - bBadComponent = ( endPoint[1] >= 0 ) ? ( endPoint[1] >= ( 1 << ( prec.yzw - 1 ) ) ) - : ( -endPoint[1] > ( 1 << ( prec.yzw - 1 ) ) ); - bBadQuantize = any( bBadComponent ); + bBadComponent = (endPoint[1] >= 0) ? (endPoint[1] >= (1 << (prec.yzw - 1))) + : (-endPoint[1] > (1 << (prec.yzw - 1))); + bBadQuantize = any(bBadComponent); - 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] > ( 1 << ( prec.yzw - 1 ) ) ) ? ( 1 << ( prec.yzw - 1 ) ) : ( endPoint[1] & ( ( 1 << prec.yzw ) - 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] > (1 << (prec.yzw - 1))) ? (1 << (prec.yzw - 1)) : (endPoint[1] & ((1 << prec.yzw) - 1))); } else { - endPoint &= ( ( 1 << prec.x ) - 1 ); - + endPoint &= ((1 << prec.x) - 1); + bBadQuantize = 0; } } -void SIGN_EXTEND( uint3 prec, inout int3 color ) +void SIGN_EXTEND(uint3 prec, inout int3 color) { uint3 p = 1 << (prec - 1); 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 ) - SIGN_EXTEND( prec.x, endPoint[0] ); - if ( g_format == SIGNED_F16 || transformed ) - SIGN_EXTEND( prec.yzw, endPoint[1] ); + if (g_format == SIGNED_F16) + SIGN_EXTEND(prec.x, endPoint[0]); + if (g_format == SIGNED_F16 || transformed) + 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 ) - SIGN_EXTEND( prec.x, endPoint[0][0] ); - if ( g_format == SIGNED_F16 || transformed ) + if (g_format == SIGNED_F16) + SIGN_EXTEND(prec.x, endPoint[0][0]); + if (g_format == SIGNED_F16 || transformed) { - SIGN_EXTEND( prec.yzw, endPoint[0][1] ); - SIGN_EXTEND( prec.yzw, endPoint[1][0] ); - SIGN_EXTEND( prec.yzw, endPoint[1][1] ); + SIGN_EXTEND(prec.yzw, endPoint[0][1]); + SIGN_EXTEND(prec.yzw, endPoint[1][0]); + 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 ); - if ( transformed ) + sign_extend(transformed, prec, endPoint); + if (transformed) { endPoint[0][1] += endPoint[0][0]; endPoint[1][0] += 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 ); - if ( transformed ) + sign_extend(transformed, prec, endPoint); + if (transformed) endPoint[1] += endPoint[0]; } -void unquantize( inout int2x3 color, uint prec ) +void unquantize(inout int2x3 color, uint prec) { - int iprec = asint( prec ); - if (g_format == UNSIGNED_F16 ) + int iprec = asint(prec); + if (g_format == UNSIGNED_F16) { 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 ) - color = ( color * 31 ) >> 6; + if (g_format == UNSIGNED_F16) + color = (color * 31) >> 6; else { - color = ( color < 0 ) ? -( ( -color * 31 ) >> 5 ) : ( color * 31 ) >> 5; - color = ( color < 0 ) ? ( ( -color ) | 0x8000 ) : color; + color = (color < 0) ? -((-color * 31) >> 5) : (color * 31) >> 5; + color = (color < 0) ? ((-color) | 0x8000) : 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}; - - int3 tmp = ( low * ( 64 - aWeight3[i] ) + high * aWeight3[i] + 32 ) >> 6; - palette = finish_unquantize( tmp ); + static const int aWeight3[] = { 0, 9, 18, 27, 37, 46, 55, 64 }; + + int3 tmp = (low * (64 - aWeight3[i]) + high * aWeight3[i] + 32) >> 6; + 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}; - - int3 tmp = ( low * ( 64 - aWeight4[i] ) + high * aWeight4[i] + 32 ) >> 6; - palette = finish_unquantize( tmp ); + 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; + palette = finish_unquantize(tmp); } -float half2float1( uint Value ) +float half2float1(uint Value) { uint Mantissa = (uint)(Value & 0x03FF); @@ -1232,13 +1232,13 @@ float half2float1( uint Value ) } uint Result = ((Value & 0x8000) << 16) | // Sign - ((Exponent + 112) << 23) | // Exponent - (Mantissa << 13); // Mantissa + ((Exponent + 112) << 23) | // Exponent + (Mantissa << 13); // Mantissa return asfloat(Result); } -float3 half2float(uint3 color_h ) +float3 half2float(uint3 color_h) { //uint3 sign = color_h & 0x8000; //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 // : 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.z &= 0xFFFC0000; - + //block.z |= (partition_index & 0x1f) << 13; - - if ( mode_type == candidateModeFlag[0]) + + if (mode_type == candidateModeFlag[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 ); @@ -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 >> 4) & 1) << 17; } - else if ( mode_type == candidateModeFlag[1]) + else if (mode_type == candidateModeFlag[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 ); @@ -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 >> 4) & 1) << 17; } - else if ( mode_type == candidateModeFlag[2]) + else if (mode_type == candidateModeFlag[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 ); @@ -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 >> 4) & 1) << 17; } - else if ( mode_type == candidateModeFlag[3]) + else if (mode_type == candidateModeFlag[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 ); @@ -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 >> 4) & 1) << 17; } - else if ( mode_type == candidateModeFlag[4]) + else if (mode_type == candidateModeFlag[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 ); @@ -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 >> 4) & 1) << 17; } - else if ( mode_type == candidateModeFlag[5]) + else if (mode_type == candidateModeFlag[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); @@ -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 >> 4) & 1) << 17; } - else if ( mode_type == candidateModeFlag[6]) + else if (mode_type == candidateModeFlag[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 ); @@ -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 >> 4) & 1) << 17; } - else if ( mode_type == candidateModeFlag[7]) + else if (mode_type == candidateModeFlag[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 ); @@ -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 >> 4) & 1) << 17; } - else if ( mode_type == candidateModeFlag[8]) + else if (mode_type == candidateModeFlag[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 ); @@ -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 >> 4) & 1) << 17; } - else if ( mode_type == candidateModeFlag[9]) + else if (mode_type == candidateModeFlag[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 ); @@ -2246,7 +2246,7 @@ void block_package( inout uint4 block, int2x3 endPoint[2], uint mode_type, uint 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.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; - if ( mode_type == candidateModeFlag[10]) + if (mode_type == candidateModeFlag[10]) { - /* block.x |= candidateModeMemory[10]; - 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.x |= candidateModeMemory[10]; + 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.x |= ((candidateModeMemory[10] >> 0) & 1) << 0; block.x |= ((candidateModeMemory[10] >> 1) & 1) << 1; @@ -2495,7 +2495,7 @@ void block_package( inout uint4 block, int2x3 endPoint, uint mode_type ) // for block.y |= ( ( endPoint[0].b << 16 ) & 0x20000000 ); block.y |= ( ( endPoint[0].b << 18 ) & 0x40000000 ); block.y |= ( ( endPoint[0].b << 20 ) & 0x80000000 ); - block.y |= ( ( endPoint[1].r << 3 ) & 0x00000078 ) | ( ( endPoint[1].g << 13 ) & 0x0001E000 ) | ( ( endPoint[1].b << 23 ) & 0x07800000 ); + block.y |= ( ( endPoint[1].r << 3 ) & 0x00000078 ) | ( ( endPoint[1].g << 13 ) & 0x0001E000 ) | ( ( endPoint[1].b << 23 ) & 0x07800000 ); block.z |= ( endPoint[0].b >> 10 ) & 0x00000001;*/ block.x |= ((candidateModeMemory[13] >> 0) & 1) << 0; diff --git a/DirectXTex/Shaders/BC7Encode.hlsl b/DirectXTex/Shaders/BC7Encode.hlsl index 9552a6f..eed5578 100644 --- a/DirectXTex/Shaders/BC7Encode.hlsl +++ b/DirectXTex/Shaders/BC7Encode.hlsl @@ -25,14 +25,14 @@ static const uint candidateSectionBit[64] = //Associated to partition 0-63 0x008C, 0x7310, 0x3100, 0x8CCE, 0x088C, 0x3110, 0x6666, 0x366C, 0x17E8, 0x0FF0, 0x718E, 0x399C, - 0xaaaa, 0xf0f0, 0x5a5a, 0x33cc, - 0x3c3c, 0x55aa, 0x9696, 0xa55a, - 0x73ce, 0x13c8, 0x324c, 0x3bdc, - 0x6996, 0xc33c, 0x9966, 0x660, - 0x272, 0x4e4, 0x4e40, 0x2720, - 0xc936, 0x936c, 0x39c6, 0x639c, - 0x9336, 0x9cc6, 0x817e, 0xe718, - 0xccf0, 0xfcc, 0x7744, 0xee22, + 0xaaaa, 0xf0f0, 0x5a5a, 0x33cc, + 0x3c3c, 0x55aa, 0x9696, 0xa55a, + 0x73ce, 0x13c8, 0x324c, 0x3bdc, + 0x6996, 0xc33c, 0x9966, 0x660, + 0x272, 0x4e4, 0x4e40, 0x2720, + 0xc936, 0x936c, 0x39c6, 0x639c, + 0x9336, 0x9cc6, 0x817e, 0xe718, + 0xccf0, 0xfcc, 0x7744, 0xee22, }; static const uint candidateSectionBit2[64] = //Associated to partition 64-127 { @@ -53,7 +53,7 @@ static const uint candidateSectionBit2[64] = //Associated to partition 64-127 0xaaaa1414, 0xa05050a0, 0xa0a5a5a0, 0x96000000, 0x40804080, 0xa9a8a9a8, 0xaaaaaa44, 0x2a4a5254, }; -static const uint2 candidateFixUpIndex1D[128] = +static const uint2 candidateFixUpIndex1D[128] = { {15, 0},{15, 0},{15, 0},{15, 0}, {15, 0},{15, 0},{15, 0},{15, 0}, @@ -63,7 +63,7 @@ static const uint2 candidateFixUpIndex1D[128] = { 2, 0},{ 8, 0},{ 8, 0},{15, 0}, { 2, 0},{ 8, 0},{ 2, 0},{ 2, 0}, { 8, 0},{ 8, 0},{ 2, 0},{ 2, 0}, - + {15, 0},{15, 0},{ 6, 0},{ 8, 0}, { 2, 0},{ 8, 0},{15, 0},{15, 0}, { 2, 0},{ 8, 0},{ 2, 0},{ 2, 0}, @@ -73,7 +73,7 @@ static const uint2 candidateFixUpIndex1D[128] = {15, 0},{15, 0},{15, 0},{15, 0}, {15, 0},{ 2, 0},{ 2, 0},{15, 0}, //candidateFixUpIndex1D[i][1], i < 64 should not be used - + { 3,15},{ 3, 8},{15, 8},{15, 3}, { 8,15},{ 3,15},{15, 3},{15, 8}, { 8,15},{ 8,15},{ 6,15},{ 6,15}, @@ -82,7 +82,7 @@ static const uint2 candidateFixUpIndex1D[128] = { 3,15},{ 3, 8},{ 6,15},{10, 8}, { 5, 3},{ 8,15},{ 8, 6},{ 6,10}, { 8,15},{ 5,15},{15,10},{15, 8}, - + { 8,15},{15, 3},{ 3,15},{ 5,10}, { 6,10},{10, 8},{ 8, 9},{15,10}, {15, 6},{ 3,15},{15, 8},{ 5,15}, @@ -102,7 +102,7 @@ static const uint2 candidateFixUpIndex1DOrdered[128] = //Same with candidateFixU { 2, 0},{ 8, 0},{ 8, 0},{15, 0}, { 2, 0},{ 8, 0},{ 2, 0},{ 2, 0}, { 8, 0},{ 8, 0},{ 2, 0},{ 2, 0}, - + {15, 0},{15, 0},{ 6, 0},{ 8, 0}, { 2, 0},{ 8, 0},{15, 0},{15, 0}, { 2, 0},{ 8, 0},{ 2, 0},{ 2, 0}, @@ -112,7 +112,7 @@ static const uint2 candidateFixUpIndex1DOrdered[128] = //Same with candidateFixU {15, 0},{15, 0},{15, 0},{15, 0}, {15, 0},{ 2, 0},{ 2, 0},{15, 0}, //candidateFixUpIndex1DOrdered[i][1], i < 64 should not be used - + { 3,15},{ 3, 8},{ 8,15},{ 3,15}, { 8,15},{ 3,15},{ 3,15},{ 8,15}, { 8,15},{ 8,15},{ 6,15},{ 6,15}, @@ -121,7 +121,7 @@ static const uint2 candidateFixUpIndex1DOrdered[128] = //Same with candidateFixU { 3,15},{ 3, 8},{ 6,15},{ 8,10}, { 3, 5},{ 8,15},{ 6, 8},{ 6,10}, { 8,15},{ 5,15},{10,15},{ 8,15}, - + { 8,15},{ 3,15},{ 3,15},{ 5,10}, { 6,10},{ 8,10},{ 8, 9},{10,15}, { 6,15},{ 3,15},{ 8,15},{ 5,15}, @@ -146,8 +146,8 @@ static const uint aWeight[3][16] = { {0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, {0, 9, 18, 27, 37, 46, 55, 64, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 21, 43, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; - //4 bit index: 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64 -static const uint aStep[3][64] = { { 0, 0, 0, 1, 1, 1, 1, 2, +//4 bit index: 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64 +static const uint aStep[3][64] = { { 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, @@ -155,26 +155,26 @@ static const uint aStep[3][64] = { { 0, 0, 0, 1, 1, 1, 1, 2, 9,10,10,10,10,10,11,11, 11,11,12,12,12,12,13,13, 13,13,14,14,14,14,15,15 }, - //3 bit index: 0, 9, 18, 27, 37, 46, 55, 64 - { 0,0,0,0,0,1,1,1, - 1,1,1,1,1,1,2,2, - 2,2,2,2,2,2,2,3, - 3,3,3,3,3,3,3,3, - 3,4,4,4,4,4,4,4, - 4,4,5,5,5,5,5,5, - 5,5,5,6,6,6,6,6, - 6,6,6,6,7,7,7,7 }, - //2 bit index: 0, 21, 43, 64 - { 0,0,0,0,0,0,0,0, - 0,0,0,1,1,1,1,1, - 1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1, - 1,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,3,3, - 3,3,3,3,3,3,3,3 } }; + //3 bit index: 0, 9, 18, 27, 37, 46, 55, 64 + { 0,0,0,0,0,1,1,1, + 1,1,1,1,1,1,2,2, + 2,2,2,2,2,2,2,3, + 3,3,3,3,3,3,3,3, + 3,4,4,4,4,4,4,4, + 4,4,5,5,5,5,5,5, + 5,5,5,6,6,6,6,6, + 6,6,6,6,7,7,7,7 }, + //2 bit index: 0, 21, 43, 64 + { 0,0,0,0,0,0,0,0, + 0,0,0,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,2,2,2,2,2,2,2, + 2,2,2,2,2,2,2,2, + 2,2,2,2,2,2,3,3, + 3,3,3,3,3,3,3,3 } }; -cbuffer cbCS : register( b0 ) +cbuffer cbCS : register(b0) { uint g_tex_width; uint g_num_block_x; @@ -186,23 +186,23 @@ cbuffer cbCS : register( b0 ) }; //Forward declaration -uint2x4 compress_endpoints0( inout uint2x4 endPoint, uint2 P ); //Mode = 0 -uint2x4 compress_endpoints1( inout uint2x4 endPoint, uint2 P ); //Mode = 1 -uint2x4 compress_endpoints2( inout uint2x4 endPoint ); //Mode = 2 -uint2x4 compress_endpoints3( inout uint2x4 endPoint, uint2 P ); //Mode = 3 -uint2x4 compress_endpoints7( inout uint2x4 endPoint, uint2 P ); //Mode = 7 -uint2x4 compress_endpoints6( inout uint2x4 endPoint, uint2 P ); //Mode = 6 -uint2x4 compress_endpoints4( inout uint2x4 endPoint ); //Mode = 4 -uint2x4 compress_endpoints5( inout uint2x4 endPoint ); //Mode = 5 +uint2x4 compress_endpoints0(inout uint2x4 endPoint, uint2 P); //Mode = 0 +uint2x4 compress_endpoints1(inout uint2x4 endPoint, uint2 P); //Mode = 1 +uint2x4 compress_endpoints2(inout uint2x4 endPoint); //Mode = 2 +uint2x4 compress_endpoints3(inout uint2x4 endPoint, uint2 P); //Mode = 3 +uint2x4 compress_endpoints7(inout uint2x4 endPoint, uint2 P); //Mode = 7 +uint2x4 compress_endpoints6(inout uint2x4 endPoint, uint2 P); //Mode = 6 +uint2x4 compress_endpoints4(inout uint2x4 endPoint); //Mode = 4 +uint2x4 compress_endpoints5(inout uint2x4 endPoint); //Mode = 5 -void block_package0( out uint4 block, uint partition, uint threadBase ); //Mode0 -void block_package1( out uint4 block, uint partition, uint threadBase ); //Mode1 -void block_package2( out uint4 block, uint partition, uint threadBase ); //Mode2 -void block_package3( out uint4 block, uint partition, uint threadBase ); //Mode3 -void block_package4( out uint4 block, uint rotation, uint index_selector, uint threadBase ); //Mode4 -void block_package5( out uint4 block, uint rotation, uint threadBase ); //Mode5 -void block_package6( out uint4 block, uint threadBase ); //Mode6 -void block_package7( out uint4 block, uint partition, uint threadBase ); //Mode7 +void block_package0(out uint4 block, uint partition, uint threadBase); //Mode0 +void block_package1(out uint4 block, uint partition, uint threadBase); //Mode1 +void block_package2(out uint4 block, uint partition, uint threadBase); //Mode2 +void block_package3(out uint4 block, uint partition, uint threadBase); //Mode3 +void block_package4(out uint4 block, uint rotation, uint index_selector, uint threadBase); //Mode4 +void block_package5(out uint4 block, uint rotation, uint threadBase); //Mode5 +void block_package6(out uint4 block, uint threadBase); //Mode6 +void block_package7(out uint4 block, uint partition, uint threadBase); //Mode7 void swap(inout uint4 lhs, inout uint4 rhs) @@ -225,27 +225,27 @@ void swap(inout uint lhs, inout uint rhs) } uint ComputeError(in uint4 a, in uint4 b) -{ - return dot(a.rgb, b.rgb) + g_alpha_weight * a.a*b.a; -} - -void Ensure_A_Is_Larger( inout uint4 a, inout uint4 b ) { - if ( a.x < b.x ) - swap( a.x, b.x ); - if ( a.y < b.y ) - swap( a.y, b.y ); - if ( a.z < b.z ) - swap( a.z, b.z ); - if ( a.w < b.w ) - swap( a.w, b.w ); + return dot(a.rgb, b.rgb) + g_alpha_weight * a.a*b.a; +} + +void Ensure_A_Is_Larger(inout uint4 a, inout uint4 b) +{ + if (a.x < b.x) + swap(a.x, b.x); + if (a.y < b.y) + swap(a.y, b.y); + if (a.z < b.z) + swap(a.z, b.z); + if (a.w < b.w) + swap(a.w, b.w); } -Texture2D g_Input : register( t0 ); -StructuredBuffer g_InBuff : register( t1 ); +Texture2D g_Input : register(t0); +StructuredBuffer g_InBuff : register(t1); -RWStructuredBuffer g_OutBuff : register( u0 ); +RWStructuredBuffer g_OutBuff : register(u0); #define THREAD_GROUP_SIZE 64 #define BLOCK_SIZE_Y 4 @@ -267,8 +267,8 @@ struct BufferShared }; groupshared BufferShared shared_temp[THREAD_GROUP_SIZE]; -[numthreads( THREAD_GROUP_SIZE, 1, 1 )] -void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode 4 5 6 all have 1 subset per block, and fix-up index is always index 0 +[numthreads(THREAD_GROUP_SIZE, 1, 1)] +void TryMode456CS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) // mode 4 5 6 all have 1 subset per block, and fix-up index is always index 0 { // we process 4 BC blocks per thread group const uint MAX_USED_THREAD = 16; // pixels in a BC (block compressed) block @@ -289,10 +289,10 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode uint block_x = blockID - block_y * g_num_block_x; uint base_x = block_x * BLOCK_SIZE_X; uint base_y = block_y * BLOCK_SIZE_Y; - + if (threadInBlock < 16) { - shared_temp[GI].pixel = clamp(uint4(g_Input.Load( uint3( base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0 ) ) * 255), 0, 255); + shared_temp[GI].pixel = clamp(uint4(g_Input.Load(uint3(base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0)) * 255), 0, 255); shared_temp[GI].endPoint_low = shared_temp[GI].pixel; shared_temp[GI].endPoint_high = shared_temp[GI].pixel; @@ -350,19 +350,19 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode { //2 represents 2bit index precision; 1 represents 3bit index precision index_selector = 0; - indexPrec = uint2( 2, 1 ); + indexPrec = uint2(2, 1); } else // thread 1, 3, 5, 7 { //2 represents 2bit index precision; 1 represents 3bit index precision index_selector = 1; - indexPrec = uint2( 1, 2 ); + indexPrec = uint2(1, 2); } } else { - //2 represents 2bit index precision - indexPrec = uint2( 2, 2 ); + //2 represents 2bit index precision + indexPrec = uint2(2, 2); } uint4 pixel_r; @@ -408,7 +408,7 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode // Index selector 0 1 0 1 0 1 0 1 mode = 4; - compress_endpoints4( endPoint ); + compress_endpoints4(endPoint); } else // try mode 5 in threads 8..11 { @@ -417,7 +417,7 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode // Rotation 0 1 2 3 mode = 5; - compress_endpoints5( endPoint ); + compress_endpoints5(endPoint); } uint4 pixel = shared_temp[threadBase + 0].pixel; @@ -435,8 +435,8 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode } span = endPoint[1] - endPoint[0]; - span_norm_sqr = uint2( dot( span.rgb, span.rgb ), span.a * span.a ); - + span_norm_sqr = uint2(dot(span.rgb, span.rgb), span.a * span.a); + // in mode 4 5 6, end point 0 must be closer to pixel 0 than end point 1, because of the fix-up index is always index 0 // TODO: this shouldn't be necessary here in error calculation /* @@ -452,23 +452,23 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode swap(endPoint[0].a, endPoint[1].a); } */ - + // should be the same as above - dotProduct = int2( dot( pixel.rgb - endPoint[0].rgb, pixel.rgb - endPoint[0].rgb ), dot( pixel.rgb - endPoint[1].rgb, pixel.rgb - endPoint[1].rgb ) ); - if ( dotProduct.x > dotProduct.y ) + dotProduct = int2(dot(pixel.rgb - endPoint[0].rgb, pixel.rgb - endPoint[0].rgb), dot(pixel.rgb - endPoint[1].rgb, pixel.rgb - endPoint[1].rgb)); + if (dotProduct.x > dotProduct.y) { span.rgb = -span.rgb; swap(endPoint[0].rgb, endPoint[1].rgb); } - dotProduct = int2( dot( pixel.a - endPoint[0].a, pixel.a - endPoint[0].a ), dot( pixel.a - endPoint[1].a, pixel.a - endPoint[1].a ) ); - if ( dotProduct.x > dotProduct.y ) + dotProduct = int2(dot(pixel.a - endPoint[0].a, pixel.a - endPoint[0].a), dot(pixel.a - endPoint[1].a, pixel.a - endPoint[1].a)); + if (dotProduct.x > dotProduct.y) { span.a = -span.a; swap(endPoint[0].a, endPoint[1].a); } error = 0; - for ( uint i = 0; i < 16; i ++ ) + for (uint i = 0; i < 16; i++) { pixel = shared_temp[threadBase + i].pixel; if (1 == rotation) @@ -484,12 +484,12 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode pixel.ba = pixel.ab; } - dotProduct.x = dot( span.rgb, pixel.rgb - endPoint[0].rgb ); - color_index = ( span_norm_sqr.x <= 0 /*endPoint[0] == endPoint[1]*/ || dotProduct.x <= 0 /*pixel == endPoint[0]*/ ) ? 0 - : ( ( dotProduct.x < span_norm_sqr.x ) ? aStep[indexPrec.x][ uint( dotProduct.x * 63.49999 / span_norm_sqr.x ) ] : aStep[indexPrec.x][63] ); - dotProduct.y = dot( span.a, pixel.a - endPoint[0].a ); - alpha_index = ( span_norm_sqr.y <= 0 || dotProduct.y <= 0 ) ? 0 - : ( ( dotProduct.y < span_norm_sqr.y ) ? aStep[indexPrec.y][ uint( dotProduct.y * 63.49999 / span_norm_sqr.y ) ] : aStep[indexPrec.y][63] ); + dotProduct.x = dot(span.rgb, pixel.rgb - endPoint[0].rgb); + color_index = (span_norm_sqr.x <= 0 /*endPoint[0] == endPoint[1]*/ || dotProduct.x <= 0 /*pixel == endPoint[0]*/) ? 0 + : ((dotProduct.x < span_norm_sqr.x) ? aStep[indexPrec.x][uint(dotProduct.x * 63.49999 / span_norm_sqr.x)] : aStep[indexPrec.x][63]); + dotProduct.y = dot(span.a, pixel.a - endPoint[0].a); + alpha_index = (span_norm_sqr.y <= 0 || dotProduct.y <= 0) ? 0 + : ((dotProduct.y < span_norm_sqr.y) ? aStep[indexPrec.y][uint(dotProduct.y * 63.49999 / span_norm_sqr.y)] : aStep[indexPrec.y][63]); // the same color_index and alpha_index should be used for reconstruction, so this should be left commented out /*if (index_selector) @@ -497,14 +497,14 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode swap(color_index, alpha_index); }*/ - pixel_r.rgb = ( ( 64 - aWeight[indexPrec.x][color_index] ) * endPoint[0].rgb + - aWeight[indexPrec.x][color_index] * endPoint[1].rgb + - 32 ) >> 6; - pixel_r.a = ( ( 64 - aWeight[indexPrec.y][alpha_index] ) * endPoint[0].a + - aWeight[indexPrec.y][alpha_index] * endPoint[1].a + - 32 ) >> 6; + pixel_r.rgb = ((64 - aWeight[indexPrec.x][color_index]) * endPoint[0].rgb + + aWeight[indexPrec.x][color_index] * endPoint[1].rgb + + 32) >> 6; + pixel_r.a = ((64 - aWeight[indexPrec.y][alpha_index]) * endPoint[0].a + + aWeight[indexPrec.y][alpha_index] * endPoint[1].a + + 32) >> 6; - Ensure_A_Is_Larger( pixel_r, pixel ); + Ensure_A_Is_Larger(pixel_r, pixel); pixel_r -= pixel; if (1 == rotation) { @@ -525,32 +525,32 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode { uint p = threadInBlock - 12; - compress_endpoints6( endPoint, uint2(p >> 0, p >> 1) & 1 ); + compress_endpoints6(endPoint, uint2(p >> 0, p >> 1) & 1); uint4 pixel = shared_temp[threadBase + 0].pixel; span = endPoint[1] - endPoint[0]; - span_norm_sqr = dot( span, span ); - dotProduct = dot( span, pixel - endPoint[0] ); - if ( span_norm_sqr.x > 0 && dotProduct.x >= 0 && uint( dotProduct.x * 63.49999 ) > uint( 32 * span_norm_sqr.x ) ) + span_norm_sqr = dot(span, span); + dotProduct = dot(span, pixel - endPoint[0]); + if (span_norm_sqr.x > 0 && dotProduct.x >= 0 && uint(dotProduct.x * 63.49999) > uint(32 * span_norm_sqr.x)) { span = -span; swap(endPoint[0], endPoint[1]); } - + error = 0; - for ( uint i = 0; i < 16; i ++ ) + for (uint i = 0; i < 16; i++) { pixel = shared_temp[threadBase + i].pixel; - - dotProduct.x = dot( span, pixel - endPoint[0] ); - color_index = ( span_norm_sqr.x <= 0 || dotProduct.x <= 0 ) ? 0 - : ( ( dotProduct.x < span_norm_sqr.x ) ? aStep[0][ uint( dotProduct.x * 63.49999 / span_norm_sqr.x ) ] : aStep[0][63] ); - - pixel_r = ( ( 64 - aWeight[0][color_index] ) * endPoint[0] - + aWeight[0][color_index] * endPoint[1] + 32 ) >> 6; - - Ensure_A_Is_Larger( pixel_r, pixel ); + + dotProduct.x = dot(span, pixel - endPoint[0]); + color_index = (span_norm_sqr.x <= 0 || dotProduct.x <= 0) ? 0 + : ((dotProduct.x < span_norm_sqr.x) ? aStep[0][uint(dotProduct.x * 63.49999 / span_norm_sqr.x)] : aStep[0][63]); + + pixel_r = ((64 - aWeight[0][color_index]) * endPoint[0] + + aWeight[0][color_index] * endPoint[1] + 32) >> 6; + + Ensure_A_Is_Larger(pixel_r, pixel); pixel_r -= pixel; error += ComputeError(pixel_r, pixel_r); } @@ -570,7 +570,7 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode 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].mode = shared_temp[GI + 8].mode; @@ -583,7 +583,7 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode #endif 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].mode = shared_temp[GI + 4].mode; @@ -596,7 +596,7 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode #endif 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].mode = shared_temp[GI + 2].mode; @@ -609,7 +609,7 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode #endif 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].mode = shared_temp[GI + 1].mode; @@ -622,8 +622,8 @@ void TryMode456CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode } } -[numthreads( THREAD_GROUP_SIZE, 1, 1 )] -void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode 1 3 7 all have 2 subsets per block +[numthreads(THREAD_GROUP_SIZE, 1, 1)] +void TryMode137CS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) // mode 1 3 7 all have 2 subsets per block { const uint MAX_USED_THREAD = 64; uint BLOCK_IN_GROUP = THREAD_GROUP_SIZE / MAX_USED_THREAD; @@ -636,10 +636,10 @@ void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode uint block_x = blockID - block_y * g_num_block_x; uint base_x = block_x * BLOCK_SIZE_X; uint base_y = block_y * BLOCK_SIZE_Y; - + if (threadInBlock < 16) { - shared_temp[GI].pixel = clamp(uint4(g_Input.Load( uint3( base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0 ) ) * 255), 0, 255); + shared_temp[GI].pixel = clamp(uint4(g_Input.Load(uint3(base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0)) * 255), 0, 255); } GroupMemoryBarrierWithGroupSync(); @@ -658,18 +658,18 @@ void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode endPoint[1][0] = MAX_UINT; endPoint[1][1] = MIN_UINT; uint bits = candidateSectionBit[partition]; - for ( uint i = 0; i < 16; i ++ ) + for (uint i = 0; i < 16; i++) { uint4 pixel = shared_temp[threadBase + i].pixel; - if ( (( bits >> i ) & 0x01) == 1 ) + if (((bits >> i) & 0x01) == 1) { - endPoint[1][0] = min( endPoint[1][0], pixel ); - endPoint[1][1] = max( endPoint[1][1], pixel ); + endPoint[1][0] = min(endPoint[1][0], pixel); + endPoint[1][1] = max(endPoint[1][1], pixel); } else { - endPoint[0][0] = min( endPoint[0][0], pixel ); - endPoint[0][1] = max( endPoint[0][1], pixel ); + endPoint[0][0] = min(endPoint[0][0], pixel); + endPoint[0][1] = max(endPoint[0][1], pixel); } } @@ -690,24 +690,24 @@ void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode uint final_p[2] = { 0, 0 }; uint error[2] = { MAX_UINT, MAX_UINT }; - for ( uint p = 0; p < max_p; p ++ ) + for (uint p = 0; p < max_p; p++) { endPoint[0] = endPointBackup[0]; endPoint[1] = endPointBackup[1]; - for ( i = 0; i < 2; i ++ ) // loop through 2 subsets + for (i = 0; i < 2; i++) // loop through 2 subsets { if (g_mode_id == 1) { - compress_endpoints1( endPoint[i], p ); + compress_endpoints1(endPoint[i], p); } else if (g_mode_id == 3) { - compress_endpoints3( endPoint[i], uint2(p, p >> 1) & 1 ); + compress_endpoints3(endPoint[i], uint2(p, p >> 1) & 1); } else if (g_mode_id == 7) { - compress_endpoints7( endPoint[i], uint2(p, p >> 1) & 1 ); + compress_endpoints7(endPoint[i], uint2(p, p >> 1) & 1); } } @@ -721,18 +721,18 @@ void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode } int span_norm_sqr[2]; - span_norm_sqr[0] = dot( span[0], span[0] ); - span_norm_sqr[1] = dot( span[1], span[1] ); + span_norm_sqr[0] = dot(span[0], span[0]); + span_norm_sqr[1] = dot(span[1], span[1]); // TODO: again, this shouldn't be necessary here in error calculation - int dotProduct = dot( span[0], shared_temp[threadBase + 0].pixel - endPoint[0][0] ); - if ( span_norm_sqr[0] > 0 && dotProduct > 0 && uint( dotProduct * 63.49999 ) > uint( 32 * span_norm_sqr[0] ) ) + int dotProduct = dot(span[0], shared_temp[threadBase + 0].pixel - endPoint[0][0]); + if (span_norm_sqr[0] > 0 && dotProduct > 0 && uint(dotProduct * 63.49999) > uint(32 * span_norm_sqr[0])) { span[0] = -span[0]; swap(endPoint[0][0], endPoint[0][1]); } - dotProduct = dot( span[1], shared_temp[threadBase + candidateFixUpIndex1D[partition].x].pixel - endPoint[1][0] ); - if ( span_norm_sqr[1] > 0 && dotProduct > 0 && uint( dotProduct * 63.49999 ) > uint( 32 * span_norm_sqr[1] ) ) + dotProduct = dot(span[1], shared_temp[threadBase + candidateFixUpIndex1D[partition].x].pixel - endPoint[1][0]); + if (span_norm_sqr[1] > 0 && dotProduct > 0 && uint(dotProduct * 63.49999) > uint(32 * span_norm_sqr[1])) { span[1] = -span[1]; swap(endPoint[1][0], endPoint[1][1]); @@ -749,19 +749,19 @@ void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode } uint p_error[2] = { 0, 0 }; - for ( i = 0; i < 16; i ++ ) + for (i = 0; i < 16; i++) { uint subset_index = (bits >> i) & 0x01; if (subset_index == 1) { - dotProduct = dot( span[1], shared_temp[threadBase + i].pixel - endPoint[1][0] ); + dotProduct = dot(span[1], shared_temp[threadBase + i].pixel - endPoint[1][0]); color_index = (span_norm_sqr[1] <= 0 || dotProduct <= 0) ? 0 : ((dotProduct < span_norm_sqr[1]) ? aStep[step_selector][uint(dotProduct * 63.49999 / span_norm_sqr[1])] : aStep[step_selector][63]); } else { - dotProduct = dot( span[0], shared_temp[threadBase + i].pixel - endPoint[0][0] ); + dotProduct = dot(span[0], shared_temp[threadBase + i].pixel - endPoint[0][0]); color_index = (span_norm_sqr[0] <= 0 || dotProduct <= 0) ? 0 : ((dotProduct < span_norm_sqr[0]) ? aStep[step_selector][uint(dotProduct * 63.49999 / span_norm_sqr[0])] : aStep[step_selector][63]); } @@ -774,16 +774,16 @@ void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode } uint4 pixel = shared_temp[threadBase + i].pixel; - Ensure_A_Is_Larger( pixel_r, pixel ); + Ensure_A_Is_Larger(pixel_r, pixel); pixel_r -= pixel; uint pixel_error = ComputeError(pixel_r, pixel_r); - if ( subset_index == 1 ) + if (subset_index == 1) p_error[1] += pixel_error; else p_error[0] += pixel_error; } - for ( i = 0; i < 2; i++ ) + for (i = 0; i < 2; i++) { if (p_error[i] < error[i]) { @@ -798,7 +798,7 @@ void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode shared_temp[GI].partition = partition; // mode 1 3 7 don't have rotation, we use rotation for p bits - if ( g_mode_id == 1 ) + if (g_mode_id == 1) shared_temp[GI].rotation = (final_p[1] << 1) | final_p[0]; else shared_temp[GI].rotation = (final_p[1] << 2) | final_p[0]; @@ -807,7 +807,7 @@ void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode if (threadInBlock < 32) { - if ( shared_temp[GI].error > shared_temp[GI + 32].error ) + if (shared_temp[GI].error > shared_temp[GI + 32].error) { shared_temp[GI].error = shared_temp[GI + 32].error; shared_temp[GI].mode = shared_temp[GI + 32].mode; @@ -818,9 +818,9 @@ void TryMode137CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode #ifdef REF_DEVICE GroupMemoryBarrierWithGroupSync(); #endif -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].mode = shared_temp[GI + 16].mode; @@ -833,7 +833,7 @@ if (threadInBlock < 16) #endif 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].mode = shared_temp[GI + 8].mode; @@ -846,7 +846,7 @@ if (threadInBlock < 16) #endif 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].mode = shared_temp[GI + 4].mode; @@ -859,7 +859,7 @@ if (threadInBlock < 16) #endif 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].mode = shared_temp[GI + 2].mode; @@ -872,7 +872,7 @@ if (threadInBlock < 16) #endif 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].mode = shared_temp[GI + 1].mode; @@ -891,8 +891,8 @@ if (threadInBlock < 16) } } -[numthreads( THREAD_GROUP_SIZE, 1, 1 )] -void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode 0 2 have 3 subsets per block +[numthreads(THREAD_GROUP_SIZE, 1, 1)] +void TryMode02CS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) // mode 0 2 have 3 subsets per block { const uint MAX_USED_THREAD = 64; uint BLOCK_IN_GROUP = THREAD_GROUP_SIZE / MAX_USED_THREAD; @@ -905,10 +905,10 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode uint block_x = blockID - block_y * g_num_block_x; uint base_x = block_x * BLOCK_SIZE_X; uint base_y = block_y * BLOCK_SIZE_Y; - + if (threadInBlock < 16) { - shared_temp[GI].pixel = clamp(uint4(g_Input.Load( uint3( base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0 ) ) * 255), 0, 255); + shared_temp[GI].pixel = clamp(uint4(g_Input.Load(uint3(base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0)) * 255), 0, 255); } GroupMemoryBarrierWithGroupSync(); @@ -939,24 +939,24 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode endPoint[2][0] = MAX_UINT; endPoint[2][1] = MIN_UINT; uint bits2 = candidateSectionBit2[partition - 64]; - for ( uint i = 0; i < 16; i ++ ) + for (uint i = 0; i < 16; i++) { uint4 pixel = shared_temp[threadBase + i].pixel; - uint subset_index = ( bits2 >> ( i * 2 ) ) & 0x03; - if ( subset_index == 2 ) + uint subset_index = (bits2 >> (i * 2)) & 0x03; + if (subset_index == 2) { - endPoint[2][0] = min( endPoint[2][0], pixel ); - endPoint[2][1] = max( endPoint[2][1], pixel ); + endPoint[2][0] = min(endPoint[2][0], pixel); + endPoint[2][1] = max(endPoint[2][1], pixel); } - else if ( subset_index == 1 ) + else if (subset_index == 1) { - endPoint[1][0] = min( endPoint[1][0], pixel ); - endPoint[1][1] = max( endPoint[1][1], pixel ); + endPoint[1][0] = min(endPoint[1][0], pixel); + endPoint[1][1] = max(endPoint[1][1], pixel); } else { - endPoint[0][0] = min( endPoint[0][0], pixel ); - endPoint[0][1] = max( endPoint[0][1], pixel ); + endPoint[0][0] = min(endPoint[0][0], pixel); + endPoint[0][1] = max(endPoint[0][1], pixel); } } @@ -976,21 +976,21 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode uint final_p[3] = { 0, 0, 0 }; uint error[3] = { MAX_UINT, MAX_UINT, MAX_UINT }; - for ( uint p = 0; p < max_p; p ++ ) + for (uint p = 0; p < max_p; p++) { endPoint[0] = endPointBackup[0]; endPoint[1] = endPointBackup[1]; endPoint[2] = endPointBackup[2]; - for ( i = 0; i < 3; i ++ ) + for (i = 0; i < 3; i++) { if (0 == g_mode_id) { - compress_endpoints0( endPoint[i], uint2(p, p >> 1) & 1 ); + compress_endpoints0(endPoint[i], uint2(p, p >> 1) & 1); } else { - compress_endpoints2( endPoint[i] ); + compress_endpoints2(endPoint[i]); } } @@ -1002,16 +1002,16 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode span[2] = endPoint[2][1] - endPoint[2][0]; span[0].w = span[1].w = span[2].w = 0; int span_norm_sqr[3]; - span_norm_sqr[0] = dot( span[0], span[0] ); - span_norm_sqr[1] = dot( span[1], span[1] ); - span_norm_sqr[2] = dot( span[2], span[2] ); + span_norm_sqr[0] = dot(span[0], span[0]); + span_norm_sqr[1] = dot(span[1], span[1]); + span_norm_sqr[2] = dot(span[2], span[2]); // TODO: again, this shouldn't be necessary here in error calculation uint ci[3] = { 0, candidateFixUpIndex1D[partition].x, candidateFixUpIndex1D[partition].y }; - for (i = 0; i < 3; i ++) + for (i = 0; i < 3; i++) { - int dotProduct = dot( span[i], shared_temp[threadBase + ci[i]].pixel - endPoint[i][0] ); - if ( span_norm_sqr[i] > 0 && dotProduct > 0 && uint( dotProduct * 63.49999 ) > uint( 32 * span_norm_sqr[i] ) ) + int dotProduct = dot(span[i], shared_temp[threadBase + ci[i]].pixel - endPoint[i][0]); + if (span_norm_sqr[i] > 0 && dotProduct > 0 && uint(dotProduct * 63.49999) > uint(32 * span_norm_sqr[i])) { span[i] = -span[i]; swap(endPoint[i][0], endPoint[i][1]); @@ -1019,47 +1019,47 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode } uint p_error[3] = { 0, 0, 0 }; - for ( i = 0; i < 16; i ++ ) + for (i = 0; i < 16; i++) { - uint subset_index = ( bits2 >> ( i * 2 ) ) & 0x03; - if ( subset_index == 2 ) + uint subset_index = (bits2 >> (i * 2)) & 0x03; + if (subset_index == 2) { - int dotProduct = dot( span[2], shared_temp[threadBase + i].pixel - endPoint[2][0] ); - color_index[i] = ( span_norm_sqr[2] <= 0 || dotProduct <= 0 ) ? 0 - : ( ( dotProduct < span_norm_sqr[2] ) ? aStep[step_selector][ uint( dotProduct * 63.49999 / span_norm_sqr[2] ) ] : aStep[step_selector][63] ); + int dotProduct = dot(span[2], shared_temp[threadBase + i].pixel - endPoint[2][0]); + color_index[i] = (span_norm_sqr[2] <= 0 || dotProduct <= 0) ? 0 + : ((dotProduct < span_norm_sqr[2]) ? aStep[step_selector][uint(dotProduct * 63.49999 / span_norm_sqr[2])] : aStep[step_selector][63]); } - else if ( subset_index == 1 ) + else if (subset_index == 1) { - int dotProduct = dot( span[1], shared_temp[threadBase + i].pixel - endPoint[1][0] ); - color_index[i] = ( span_norm_sqr[1] <= 0 || dotProduct <= 0 ) ? 0 - : ( ( dotProduct < span_norm_sqr[1] ) ? aStep[step_selector][ uint( dotProduct * 63.49999 / span_norm_sqr[1] ) ] : aStep[step_selector][63] ); + int dotProduct = dot(span[1], shared_temp[threadBase + i].pixel - endPoint[1][0]); + color_index[i] = (span_norm_sqr[1] <= 0 || dotProduct <= 0) ? 0 + : ((dotProduct < span_norm_sqr[1]) ? aStep[step_selector][uint(dotProduct * 63.49999 / span_norm_sqr[1])] : aStep[step_selector][63]); } else { - int dotProduct = dot( span[0], shared_temp[threadBase + i].pixel - endPoint[0][0] ); - color_index[i] = ( span_norm_sqr[0] <= 0 || dotProduct <= 0 ) ? 0 - : ( ( dotProduct < span_norm_sqr[0] ) ? aStep[step_selector][ uint( dotProduct * 63.49999 / span_norm_sqr[0] ) ] : aStep[step_selector][63] ); + int dotProduct = dot(span[0], shared_temp[threadBase + i].pixel - endPoint[0][0]); + color_index[i] = (span_norm_sqr[0] <= 0 || dotProduct <= 0) ? 0 + : ((dotProduct < span_norm_sqr[0]) ? aStep[step_selector][uint(dotProduct * 63.49999 / span_norm_sqr[0])] : aStep[step_selector][63]); } - pixel_r = ( ( 64 - aWeight[step_selector][color_index[i]] ) * endPoint[subset_index][0] - + aWeight[step_selector][color_index[i]] * endPoint[subset_index][1] + 32 ) >> 6; + pixel_r = ((64 - aWeight[step_selector][color_index[i]]) * endPoint[subset_index][0] + + aWeight[step_selector][color_index[i]] * endPoint[subset_index][1] + 32) >> 6; pixel_r.a = 255; - uint4 pixel = shared_temp[threadBase + i].pixel; - Ensure_A_Is_Larger( pixel_r, pixel ); + uint4 pixel = shared_temp[threadBase + i].pixel; + Ensure_A_Is_Larger(pixel_r, pixel); pixel_r -= pixel; uint pixel_error = ComputeError(pixel_r, pixel_r); - if ( subset_index == 2 ) + if (subset_index == 2) p_error[2] += pixel_error; - else if ( subset_index == 1 ) + else if (subset_index == 1) p_error[1] += pixel_error; else p_error[0] += pixel_error; } - for ( i = 0; i < 3; i++ ) + for (i = 0; i < 3; i++) { if (p_error[i] < error[i]) { @@ -1077,7 +1077,7 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode if (threadInBlock < 32) { - if ( shared_temp[GI].error > shared_temp[GI + 32].error ) + if (shared_temp[GI].error > shared_temp[GI + 32].error) { shared_temp[GI].error = shared_temp[GI + 32].error; shared_temp[GI].partition = shared_temp[GI + 32].partition; @@ -1089,7 +1089,7 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode #endif 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].partition = shared_temp[GI + 16].partition; @@ -1101,7 +1101,7 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode #endif 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].partition = shared_temp[GI + 8].partition; @@ -1113,7 +1113,7 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode #endif 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].partition = shared_temp[GI + 4].partition; @@ -1125,7 +1125,7 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode #endif 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].partition = shared_temp[GI + 2].partition; @@ -1137,7 +1137,7 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode #endif 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].partition = shared_temp[GI + 1].partition; @@ -1155,7 +1155,7 @@ void TryMode02CS( uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID ) // mode } } -[numthreads( THREAD_GROUP_SIZE, 1, 1 )] +[numthreads(THREAD_GROUP_SIZE, 1, 1)] void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) { const uint MAX_USED_THREAD = 16; @@ -1184,7 +1184,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) if (threadInBlock < 16) { - uint4 pixel = clamp(uint4(g_Input.Load( uint3( base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0 ) ) * 255), 0, 255); + uint4 pixel = clamp(uint4(g_Input.Load(uint3(base_x + threadInBlock % 4, base_y + threadInBlock / 4, 0)) * 255), 0, 255); if ((4 == mode) || (5 == mode)) { @@ -1216,7 +1216,7 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) ep[1] = MIN_UINT; uint2x4 ep_quantized; [unroll] - for (int ii = 2; ii >= 0; -- ii) + for (int ii = 2; ii >= 0; --ii) { if (threadInBlock < 16) { @@ -1226,8 +1226,8 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) uint4 pixel = shared_temp[GI].pixel; - uint subset_index = ( bits >> threadInBlock ) & 0x01; - uint subset_index2 = ( bits2 >> ( threadInBlock * 2 ) ) & 0x03; + uint subset_index = (bits >> threadInBlock) & 0x01; + uint subset_index2 = (bits2 >> (threadInBlock * 2)) & 0x03; if (0 == ii) { if ((0 == mode) || (2 == mode)) @@ -1338,35 +1338,35 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) if (0 == mode) { - ep_quantized = compress_endpoints0( ep, P ); + ep_quantized = compress_endpoints0(ep, P); } else if (1 == mode) { - ep_quantized = compress_endpoints1( ep, P ); + ep_quantized = compress_endpoints1(ep, P); } else if (2 == mode) { - ep_quantized = compress_endpoints2( ep ); + ep_quantized = compress_endpoints2(ep); } else if (3 == mode) { - ep_quantized = compress_endpoints3( ep, P ); + ep_quantized = compress_endpoints3(ep, P); } else if (4 == mode) { - ep_quantized = compress_endpoints4( ep ); + ep_quantized = compress_endpoints4(ep); } else if (5 == mode) { - ep_quantized = compress_endpoints5( ep ); + ep_quantized = compress_endpoints5(ep); } else if (6 == mode) { - ep_quantized = compress_endpoints6( ep, P ); + ep_quantized = compress_endpoints6(ep, P); } else //if (7 == mode) { - ep_quantized = compress_endpoints7( ep, P ); + ep_quantized = compress_endpoints7(ep, P); } int4 span = ep[1] - ep[0]; @@ -1379,17 +1379,17 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) { if (0 == threadInBlock) { - int2 span_norm_sqr = uint2( dot( span.rgb, span.rgb ), span.a * span.a ); - int2 dotProduct = int2( dot( span.rgb, shared_temp[threadBase + 0].pixel.rgb - ep[0].rgb ), span.a * ( shared_temp[threadBase + 0].pixel.a - ep[0].a ) ); - if ( span_norm_sqr.x > 0 && dotProduct.x > 0 && uint( dotProduct.x * 63.49999 ) > uint( 32 * span_norm_sqr.x ) ) + int2 span_norm_sqr = uint2(dot(span.rgb, span.rgb), span.a * span.a); + int2 dotProduct = int2(dot(span.rgb, shared_temp[threadBase + 0].pixel.rgb - ep[0].rgb), span.a * (shared_temp[threadBase + 0].pixel.a - ep[0].a)); + if (span_norm_sqr.x > 0 && dotProduct.x > 0 && uint(dotProduct.x * 63.49999) > uint(32 * span_norm_sqr.x)) { swap(ep[0].rgb, ep[1].rgb); swap(ep_quantized[0].rgb, ep_quantized[1].rgb); } - if ( span_norm_sqr.y > 0 && dotProduct.y > 0 && uint( dotProduct.y * 63.49999 ) > uint( 32 * span_norm_sqr.y ) ) + if (span_norm_sqr.y > 0 && dotProduct.y > 0 && uint(dotProduct.y * 63.49999) > uint(32 * span_norm_sqr.y)) { swap(ep[0].a, ep[1].a); - swap(ep_quantized[0].a, ep_quantized[1].a); + swap(ep_quantized[0].a, ep_quantized[1].a); } } } @@ -1409,12 +1409,12 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) p = candidateFixUpIndex1D[partition].y; } - int span_norm_sqr = dot( span, span ); - int dotProduct = dot( span, shared_temp[threadBase + p].pixel - ep[0] ); - if ( span_norm_sqr > 0 && dotProduct > 0 && uint( dotProduct * 63.49999 ) > uint( 32 * span_norm_sqr ) ) + int span_norm_sqr = dot(span, span); + int dotProduct = dot(span, shared_temp[threadBase + p].pixel - ep[0]); + if (span_norm_sqr > 0 && dotProduct > 0 && uint(dotProduct * 63.49999) > uint(32 * span_norm_sqr)) { swap(ep[0], ep[1]); - swap(ep_quantized[0], ep_quantized[1]); + swap(ep_quantized[0], ep_quantized[1]); } } @@ -1485,15 +1485,15 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) if ((4 == mode) || (5 == mode)) { int2 span_norm_sqr; - span_norm_sqr.x = dot( span.rgb, span.rgb ); + span_norm_sqr.x = dot(span.rgb, span.rgb); span_norm_sqr.y = span.a * span.a; - - int dotProduct = dot( span.rgb, shared_temp[threadBase + threadInBlock].pixel.rgb - ep[0].rgb ); - color_index = ( span_norm_sqr.x <= 0 || dotProduct <= 0 ) ? 0 - : ( ( dotProduct < span_norm_sqr.x ) ? aStep[indexPrec.x][ uint( dotProduct * 63.49999 / span_norm_sqr.x ) ] : aStep[indexPrec.x][63] ); - dotProduct = dot( span.a, shared_temp[threadBase + threadInBlock].pixel.a - ep[0].a ); - alpha_index = ( span_norm_sqr.y <= 0 || dotProduct <= 0 ) ? 0 - : ( ( dotProduct < span_norm_sqr.y ) ? aStep[indexPrec.y][ uint( dotProduct * 63.49999 / span_norm_sqr.y ) ] : aStep[indexPrec.y][63] ); + + int dotProduct = dot(span.rgb, shared_temp[threadBase + threadInBlock].pixel.rgb - ep[0].rgb); + color_index = (span_norm_sqr.x <= 0 || dotProduct <= 0) ? 0 + : ((dotProduct < span_norm_sqr.x) ? aStep[indexPrec.x][uint(dotProduct * 63.49999 / span_norm_sqr.x)] : aStep[indexPrec.x][63]); + dotProduct = dot(span.a, shared_temp[threadBase + threadInBlock].pixel.a - ep[0].a); + alpha_index = (span_norm_sqr.y <= 0 || dotProduct <= 0) ? 0 + : ((dotProduct < span_norm_sqr.y) ? aStep[indexPrec.y][uint(dotProduct * 63.49999 / span_norm_sqr.y)] : aStep[indexPrec.y][63]); if (index_selector) { @@ -1502,11 +1502,11 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) } else { - int span_norm_sqr = dot( span, span ); + int span_norm_sqr = dot(span, span); - int dotProduct = dot( span, shared_temp[threadBase + threadInBlock].pixel - ep[0] ); - color_index = ( span_norm_sqr <= 0 || dotProduct <= 0 ) ? 0 - : ( ( dotProduct < span_norm_sqr ) ? aStep[indexPrec.x][ uint( dotProduct * 63.49999 / span_norm_sqr ) ] : aStep[indexPrec.x][63] ); + int dotProduct = dot(span, shared_temp[threadBase + threadInBlock].pixel - ep[0]); + color_index = (span_norm_sqr <= 0 || dotProduct <= 0) ? 0 + : ((dotProduct < span_norm_sqr) ? aStep[indexPrec.x][uint(dotProduct * 63.49999 / span_norm_sqr)] : aStep[indexPrec.x][63]); } shared_temp[GI].error = color_index; @@ -1521,35 +1521,35 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) uint4 block; if (0 == mode) { - block_package0( block, partition, threadBase ); + block_package0(block, partition, threadBase); } else if (1 == mode) { - block_package1( block, partition, threadBase ); + block_package1(block, partition, threadBase); } else if (2 == mode) { - block_package2( block, partition, threadBase ); + block_package2(block, partition, threadBase); } else if (3 == mode) { - block_package3( block, partition, threadBase ); + block_package3(block, partition, threadBase); } else if (4 == mode) { - block_package4( block, rotation, index_selector, threadBase ); + block_package4(block, rotation, index_selector, threadBase); } else if (5 == mode) { - block_package5( block, rotation, threadBase ); + block_package5(block, rotation, threadBase); } else if (6 == mode) { - block_package6( block, threadBase ); + block_package6(block, threadBase); } else //if (7 == mode) { - block_package7( block, partition, threadBase ); + block_package7(block, partition, threadBase); } g_OutBuff[blockID] = block; @@ -1583,24 +1583,24 @@ void EncodeBlockCS(uint GI : SV_GroupIndex, uint3 groupID : SV_GroupID) // } //} -uint4 quantize( uint4 color, uint uPrec ) +uint4 quantize(uint4 color, uint uPrec) { - return (((color << 8) + color) * ((1 << uPrec) - 1) + 32768) >> 16; + return (((color << 8) + color) * ((1 << uPrec) - 1) + 32768) >> 16; } -uint4 unquantize( uint4 color, uint uPrec ) +uint4 unquantize(uint4 color, uint uPrec) { color = color << (8 - uPrec); return color | (color >> uPrec); } -uint2x4 compress_endpoints0( inout uint2x4 endPoint, uint2 P ) +uint2x4 compress_endpoints0(inout uint2x4 endPoint, uint2 P) { uint2x4 quantized; - [unroll] for ( uint j = 0; j < 2; j ++ ) + [unroll] for (uint j = 0; j < 2; j++) { quantized[j].rgb = quantize(endPoint[j].rgbb, 5).rgb & 0xFFFFFFFE; - quantized[j].rgb |= P[j]; + quantized[j].rgb |= P[j]; quantized[j].a = 0xFF; endPoint[j].rgb = unquantize(quantized[j].rgbb, 5).rgb; @@ -1610,71 +1610,71 @@ uint2x4 compress_endpoints0( inout uint2x4 endPoint, uint2 P ) } return quantized; } -uint2x4 compress_endpoints1( inout uint2x4 endPoint, uint2 P ) +uint2x4 compress_endpoints1(inout uint2x4 endPoint, uint2 P) { uint2x4 quantized; - [unroll] for ( uint j = 0; j < 2; j ++ ) + [unroll] for (uint j = 0; j < 2; j++) { quantized[j].rgb = quantize(endPoint[j].rgbb, 7).rgb & 0xFFFFFFFE; - quantized[j].rgb |= P[j]; + quantized[j].rgb |= P[j]; quantized[j].a = 0xFF; endPoint[j].rgb = unquantize(quantized[j].rgbb, 7).rgb; - endPoint[j].a = 0xFF; + endPoint[j].a = 0xFF; quantized[j] <<= 1; } return quantized; } -uint2x4 compress_endpoints2( inout uint2x4 endPoint ) +uint2x4 compress_endpoints2(inout uint2x4 endPoint) { uint2x4 quantized; - [unroll] for ( uint j = 0; j < 2; j ++ ) + [unroll] for (uint j = 0; j < 2; j++) { quantized[j].rgb = quantize(endPoint[j].rgbb, 5).rgb; quantized[j].a = 0xFF; endPoint[j].rgb = unquantize(quantized[j].rgbb, 5).rgb; - endPoint[j].a = 0xFF; + endPoint[j].a = 0xFF; quantized[j] <<= 3; } return quantized; } -uint2x4 compress_endpoints3( inout uint2x4 endPoint, uint2 P ) +uint2x4 compress_endpoints3(inout uint2x4 endPoint, uint2 P) { uint2x4 quantized; - for ( uint j = 0; j < 2; j ++ ) + for (uint j = 0; j < 2; j++) { quantized[j].rgb = endPoint[j].rgb & 0xFFFFFFFE; - quantized[j].rgb |= P[j]; + quantized[j].rgb |= P[j]; quantized[j].a = 0xFF; - + endPoint[j].rgb = quantized[j].rgb; endPoint[j].a = 0xFF; } return quantized; } -uint2x4 compress_endpoints4( inout uint2x4 endPoint ) +uint2x4 compress_endpoints4(inout uint2x4 endPoint) { uint2x4 quantized; - [unroll] for ( uint j = 0; j < 2; j ++ ) + [unroll] for (uint j = 0; j < 2; j++) { quantized[j].rgb = quantize(endPoint[j].rgbb, 5).rgb; quantized[j].a = quantize(endPoint[j].a, 6).r; - - endPoint[j].rgb = unquantize(quantized[j].rgbb, 5).rgb; + + endPoint[j].rgb = unquantize(quantized[j].rgbb, 5).rgb; endPoint[j].a = unquantize(quantized[j].a, 6).r; quantized[j].rgb <<= 3; quantized[j].a <<= 2; - } + } return quantized; } -uint2x4 compress_endpoints5( inout uint2x4 endPoint ) +uint2x4 compress_endpoints5(inout uint2x4 endPoint) { uint2x4 quantized; - [unroll] for ( uint j = 0; j < 2; j ++ ) + [unroll] for (uint j = 0; j < 2; j++) { quantized[j].rgb = quantize(endPoint[j].rgbb, 7).rgb; quantized[j].a = endPoint[j].a; @@ -1683,28 +1683,28 @@ uint2x4 compress_endpoints5( inout uint2x4 endPoint ) // endPoint[j].a Alpha is full precision quantized[j].rgb <<= 1; - } + } return quantized; } -uint2x4 compress_endpoints6( inout uint2x4 endPoint, uint2 P ) +uint2x4 compress_endpoints6(inout uint2x4 endPoint, uint2 P) { uint2x4 quantized; - for ( uint j = 0; j < 2; j ++ ) + for (uint j = 0; j < 2; j++) { quantized[j] = endPoint[j] & 0xFFFFFFFE; - quantized[j] |= P[j]; - + quantized[j] |= P[j]; + endPoint[j] = quantized[j]; } return quantized; } -uint2x4 compress_endpoints7( inout uint2x4 endPoint, uint2 P ) +uint2x4 compress_endpoints7(inout uint2x4 endPoint, uint2 P) { uint2x4 quantized; - [unroll] for ( uint j = 0; j < 2; j ++ ) + [unroll] for (uint j = 0; j < 2; j++) { quantized[j] = quantize(endPoint[j], 6) & 0xFFFFFFFE; - quantized[j] |= P[j]; + quantized[j] |= P[j]; endPoint[j] = unquantize(quantized[j], 6); } @@ -1716,75 +1716,75 @@ uint2x4 compress_endpoints7( inout uint2x4 endPoint, uint2 P ) #define get_color_index(index) shared_temp[threadBase + index].error #define get_alpha_index(index) shared_temp[threadBase + index].mode -void block_package0( out uint4 block, uint partition, uint threadBase ) +void block_package0(out uint4 block, uint partition, uint threadBase) { - block.x = 0x01 | ( (partition - 64) << 1 ) - | ( ( get_end_point_l(0).r & 0xF0 ) << 1 ) | ( ( get_end_point_h(0).r & 0xF0 ) << 5 ) - | ( ( get_end_point_l(1).r & 0xF0 ) << 9 ) | ( ( get_end_point_h(1).r & 0xF0 ) << 13 ) - | ( ( get_end_point_l(2).r & 0xF0 ) << 17 ) | ( ( get_end_point_h(2).r & 0xF0 ) << 21 ) - | ( ( get_end_point_l(0).g & 0xF0 ) << 25 ); - block.y = ( ( get_end_point_l(0).g & 0xF0 ) >> 7 ) | ( ( get_end_point_h(0).g & 0xF0 ) >> 3 ) - | ( ( get_end_point_l(1).g & 0xF0 ) << 1 ) | ( ( get_end_point_h(1).g & 0xF0 ) << 5 ) - | ( ( get_end_point_l(2).g & 0xF0 ) << 9 ) | ( ( get_end_point_h(2).g & 0xF0 ) << 13 ) - | ( ( get_end_point_l(0).b & 0xF0 ) << 17 ) | ( ( get_end_point_h(0).b & 0xF0 ) << 21 ) - | ( ( get_end_point_l(1).b & 0xF0 ) << 25 ); - block.z = ( ( get_end_point_l(1).b & 0xF0 ) >> 7 ) | ( ( get_end_point_h(1).b & 0xF0 ) >> 3 ) - | ( ( get_end_point_l(2).b & 0xF0 ) << 1 ) | ( ( get_end_point_h(2).b & 0xF0 ) << 5 ) - | ( ( get_end_point_l(0).r & 0x08 ) << 10 ) | ( ( get_end_point_h(0).r & 0x08 ) << 11 ) - | ( ( get_end_point_l(1).r & 0x08 ) << 12 ) | ( ( get_end_point_h(1).r & 0x08 ) << 13 ) - | ( ( get_end_point_l(2).r & 0x08 ) << 14 ) | ( ( get_end_point_h(2).r & 0x08 ) << 15 ) - | ( get_color_index(0) << 19 ); + block.x = 0x01 | ((partition - 64) << 1) + | ((get_end_point_l(0).r & 0xF0) << 1) | ((get_end_point_h(0).r & 0xF0) << 5) + | ((get_end_point_l(1).r & 0xF0) << 9) | ((get_end_point_h(1).r & 0xF0) << 13) + | ((get_end_point_l(2).r & 0xF0) << 17) | ((get_end_point_h(2).r & 0xF0) << 21) + | ((get_end_point_l(0).g & 0xF0) << 25); + block.y = ((get_end_point_l(0).g & 0xF0) >> 7) | ((get_end_point_h(0).g & 0xF0) >> 3) + | ((get_end_point_l(1).g & 0xF0) << 1) | ((get_end_point_h(1).g & 0xF0) << 5) + | ((get_end_point_l(2).g & 0xF0) << 9) | ((get_end_point_h(2).g & 0xF0) << 13) + | ((get_end_point_l(0).b & 0xF0) << 17) | ((get_end_point_h(0).b & 0xF0) << 21) + | ((get_end_point_l(1).b & 0xF0) << 25); + block.z = ((get_end_point_l(1).b & 0xF0) >> 7) | ((get_end_point_h(1).b & 0xF0) >> 3) + | ((get_end_point_l(2).b & 0xF0) << 1) | ((get_end_point_h(2).b & 0xF0) << 5) + | ((get_end_point_l(0).r & 0x08) << 10) | ((get_end_point_h(0).r & 0x08) << 11) + | ((get_end_point_l(1).r & 0x08) << 12) | ((get_end_point_h(1).r & 0x08) << 13) + | ((get_end_point_l(2).r & 0x08) << 14) | ((get_end_point_h(2).r & 0x08) << 15) + | (get_color_index(0) << 19); block.w = 0; uint i = 1; - for ( ; i <= min( candidateFixUpIndex1DOrdered[partition][0], 4 ); i ++ ) + for (; i <= min(candidateFixUpIndex1DOrdered[partition][0], 4); i++) { - block.z |= get_color_index(i) << ( i * 3 + 18 ); + block.z |= get_color_index(i) << (i * 3 + 18); } - if ( candidateFixUpIndex1DOrdered[partition][0] < 4 ) //i = 4 + if (candidateFixUpIndex1DOrdered[partition][0] < 4) //i = 4 { block.z |= get_color_index(4) << 29; i += 1; } else //i = 5 { - block.w |= ( get_color_index(4) & 0x04 ) >> 2; - for ( ; i <= candidateFixUpIndex1DOrdered[partition][0]; i ++ ) - block.w |= get_color_index(i) << ( i * 3 - 14 ); + block.w |= (get_color_index(4) & 0x04) >> 2; + for (; i <= candidateFixUpIndex1DOrdered[partition][0]; i++) + block.w |= get_color_index(i) << (i * 3 - 14); } - for ( ; i <= candidateFixUpIndex1DOrdered[partition][1]; i ++ ) + for (; i <= candidateFixUpIndex1DOrdered[partition][1]; i++) { - block.w |= get_color_index(i) << ( i * 3 - 15 ); + block.w |= get_color_index(i) << (i * 3 - 15); } - for ( ; i < 16; i ++ ) + for (; i < 16; i++) { - block.w |= get_color_index(i) << ( i * 3 - 16 ); + block.w |= get_color_index(i) << (i * 3 - 16); } } -void block_package1( out uint4 block, uint partition, uint threadBase ) +void block_package1(out uint4 block, uint partition, uint threadBase) { - block.x = 0x02 | ( partition << 2 ) - | ( ( get_end_point_l(0).r & 0xFC ) << 6 ) | ( ( get_end_point_h(0).r & 0xFC ) << 12 ) - | ( ( get_end_point_l(1).r & 0xFC ) << 18 ) | ( ( get_end_point_h(1).r & 0xFC ) << 24 ); - block.y = ( ( get_end_point_l(0).g & 0xFC ) >> 2 ) | ( ( get_end_point_h(0).g & 0xFC ) << 4 ) - | ( ( get_end_point_l(1).g & 0xFC ) << 10 ) | ( ( get_end_point_h(1).g & 0xFC ) << 16 ) - | ( ( get_end_point_l(0).b & 0xFC ) << 22 ) | ( ( get_end_point_h(0).b & 0xFC ) << 28 ); - block.z = ( ( get_end_point_h(0).b & 0xFC ) >> 4 ) | ( ( get_end_point_l(1).b & 0xFC ) << 2 ) - | ( ( get_end_point_h(1).b & 0xFC ) << 8 ) - | ( ( get_end_point_l(0).r & 0x02 ) << 15 ) | ( ( get_end_point_l(1).r & 0x02 ) << 16 ) - | ( get_color_index(0) << 18 ); - if ( candidateFixUpIndex1DOrdered[partition][0] == 15 ) + block.x = 0x02 | (partition << 2) + | ((get_end_point_l(0).r & 0xFC) << 6) | ((get_end_point_h(0).r & 0xFC) << 12) + | ((get_end_point_l(1).r & 0xFC) << 18) | ((get_end_point_h(1).r & 0xFC) << 24); + block.y = ((get_end_point_l(0).g & 0xFC) >> 2) | ((get_end_point_h(0).g & 0xFC) << 4) + | ((get_end_point_l(1).g & 0xFC) << 10) | ((get_end_point_h(1).g & 0xFC) << 16) + | ((get_end_point_l(0).b & 0xFC) << 22) | ((get_end_point_h(0).b & 0xFC) << 28); + block.z = ((get_end_point_h(0).b & 0xFC) >> 4) | ((get_end_point_l(1).b & 0xFC) << 2) + | ((get_end_point_h(1).b & 0xFC) << 8) + | ((get_end_point_l(0).r & 0x02) << 15) | ((get_end_point_l(1).r & 0x02) << 16) + | (get_color_index(0) << 18); + if (candidateFixUpIndex1DOrdered[partition][0] == 15) { block.w = (get_color_index(15) << 30) | (get_color_index(14) << 27) | (get_color_index(13) << 24) | (get_color_index(12) << 21) | (get_color_index(11) << 18) | (get_color_index(10) << 15) | (get_color_index(9) << 12) | (get_color_index(8) << 9) | (get_color_index(7) << 6) | (get_color_index(6) << 3) | get_color_index(5); block.z |= (get_color_index(4) << 29) | (get_color_index(3) << 26) | (get_color_index(2) << 23) | (get_color_index(1) << 20) | (get_color_index(0) << 18); } - else if ( candidateFixUpIndex1DOrdered[partition][0] == 2 ) + else if (candidateFixUpIndex1DOrdered[partition][0] == 2) { block.w = (get_color_index(15) << 29) | (get_color_index(14) << 26) | (get_color_index(13) << 23) | (get_color_index(12) << 20) | (get_color_index(11) << 17) | (get_color_index(10) << 14) | (get_color_index(9) << 11) | (get_color_index(8) << 8) | (get_color_index(7) << 5) | (get_color_index(6) << 2) | (get_color_index(5) >> 1); block.z |= (get_color_index(5) << 31) | (get_color_index(4) << 28) | (get_color_index(3) << 25) | (get_color_index(2) << 23) | (get_color_index(1) << 20) | (get_color_index(0) << 18); } - else if ( candidateFixUpIndex1DOrdered[partition][0] == 8 ) + else if (candidateFixUpIndex1DOrdered[partition][0] == 8) { block.w = (get_color_index(15) << 29) | (get_color_index(14) << 26) | (get_color_index(13) << 23) | (get_color_index(12) << 20) | (get_color_index(11) << 17) | (get_color_index(10) << 14) | (get_color_index(9) << 11) | (get_color_index(8) << 9) | (get_color_index(7) << 6) | (get_color_index(6) << 3) | get_color_index(5); @@ -1797,136 +1797,136 @@ void block_package1( out uint4 block, uint partition, uint threadBase ) block.z |= (get_color_index(4) << 29) | (get_color_index(3) << 26) | (get_color_index(2) << 23) | (get_color_index(1) << 20) | (get_color_index(0) << 18); } } -void block_package2( out uint4 block, uint partition, uint threadBase ) +void block_package2(out uint4 block, uint partition, uint threadBase) { - block.x = 0x04 | ( (partition - 64) << 3 ) - | ( ( get_end_point_l(0).r & 0xF8 ) << 6 ) | ( ( get_end_point_h(0).r & 0xF8 ) << 11 ) - | ( ( get_end_point_l(1).r & 0xF8 ) << 16 ) | ( ( get_end_point_h(1).r & 0xF8 ) << 21 ) - | ( ( get_end_point_l(2).r & 0xF8 ) << 26 ); - block.y = ( ( get_end_point_l(2).r & 0xF8 ) >> 6 ) | ( ( get_end_point_h(2).r & 0xF8 ) >> 1 ) - | ( ( get_end_point_l(0).g & 0xF8 ) << 4 ) | ( ( get_end_point_h(0).g & 0xF8 ) << 9 ) - | ( ( get_end_point_l(1).g & 0xF8 ) << 14 ) | ( ( get_end_point_h(1).g & 0xF8 ) << 19 ) - | ( ( get_end_point_l(2).g & 0xF8 ) << 24 ); - block.z = ( ( get_end_point_h(2).g & 0xF8 ) >> 3 ) | ( ( get_end_point_l(0).b & 0xF8 ) << 2 ) - | ( ( get_end_point_h(0).b & 0xF8 ) << 7 ) | ( ( get_end_point_l(1).b & 0xF8 ) << 12 ) - | ( ( get_end_point_h(1).b & 0xF8 ) << 17 ) | ( ( get_end_point_l(2).b & 0xF8 ) << 22 ) - | ( ( get_end_point_h(2).b & 0xF8 ) << 27 ); - block.w = ( ( get_end_point_h(2).b & 0xF8 ) >> 5 ) - | ( get_color_index(0) << 3 ); + block.x = 0x04 | ((partition - 64) << 3) + | ((get_end_point_l(0).r & 0xF8) << 6) | ((get_end_point_h(0).r & 0xF8) << 11) + | ((get_end_point_l(1).r & 0xF8) << 16) | ((get_end_point_h(1).r & 0xF8) << 21) + | ((get_end_point_l(2).r & 0xF8) << 26); + block.y = ((get_end_point_l(2).r & 0xF8) >> 6) | ((get_end_point_h(2).r & 0xF8) >> 1) + | ((get_end_point_l(0).g & 0xF8) << 4) | ((get_end_point_h(0).g & 0xF8) << 9) + | ((get_end_point_l(1).g & 0xF8) << 14) | ((get_end_point_h(1).g & 0xF8) << 19) + | ((get_end_point_l(2).g & 0xF8) << 24); + block.z = ((get_end_point_h(2).g & 0xF8) >> 3) | ((get_end_point_l(0).b & 0xF8) << 2) + | ((get_end_point_h(0).b & 0xF8) << 7) | ((get_end_point_l(1).b & 0xF8) << 12) + | ((get_end_point_h(1).b & 0xF8) << 17) | ((get_end_point_l(2).b & 0xF8) << 22) + | ((get_end_point_h(2).b & 0xF8) << 27); + block.w = ((get_end_point_h(2).b & 0xF8) >> 5) + | (get_color_index(0) << 3); uint i = 1; - for ( ; i <= candidateFixUpIndex1DOrdered[partition][0]; i ++ ) + for (; i <= candidateFixUpIndex1DOrdered[partition][0]; i++) { - block.w |= get_color_index(i) << ( i * 2 + 2 ); + block.w |= get_color_index(i) << (i * 2 + 2); } - for ( ; i <= candidateFixUpIndex1DOrdered[partition][1]; i ++ ) + for (; i <= candidateFixUpIndex1DOrdered[partition][1]; i++) { - block.w |= get_color_index(i) << ( i * 2 + 1 ); + block.w |= get_color_index(i) << (i * 2 + 1); } - for ( ; i < 16; i ++ ) + for (; i < 16; i++) { - block.w |= get_color_index(i) << ( i * 2 ); + block.w |= get_color_index(i) << (i * 2); } } -void block_package3( out uint4 block, uint partition, uint threadBase ) +void block_package3(out uint4 block, uint partition, uint threadBase) { - block.x = 0x08 | ( partition << 4 ) - | ( ( get_end_point_l(0).r & 0xFE ) << 9 ) | ( ( get_end_point_h(0).r & 0xFE ) << 16 ) - | ( ( get_end_point_l(1).r & 0xFE ) << 23 ) | ( ( get_end_point_h(1).r & 0xFE ) << 30 ); - block.y = ( ( get_end_point_h(1).r & 0xFE ) >> 2 ) | ( ( get_end_point_l(0).g & 0xFE ) << 5 ) - | ( ( get_end_point_h(0).g & 0xFE ) << 12 ) | ( ( get_end_point_l(1).g & 0xFE ) << 19 ) - | ( ( get_end_point_h(1).g & 0xFE ) << 26 ); - block.z = ( ( get_end_point_h(1).g & 0xFE ) >> 6 ) | ( ( get_end_point_l(0).b & 0xFE ) << 1 ) - | ( ( get_end_point_h(0).b & 0xFE ) << 8 ) | ( ( get_end_point_l(1).b & 0xFE ) << 15 ) - | ( ( get_end_point_h(1).b & 0xFE ) << 22 ) - | ( ( get_end_point_l(0).r & 0x01 ) << 30 ) | ( ( get_end_point_h(0).r & 0x01 ) << 31 ); - block.w = ( ( get_end_point_l(1).r & 0x01 ) << 0 ) | ( ( get_end_point_h(1).r & 0x01 ) << 1 ) - | ( get_color_index(0) << 2 ); + block.x = 0x08 | (partition << 4) + | ((get_end_point_l(0).r & 0xFE) << 9) | ((get_end_point_h(0).r & 0xFE) << 16) + | ((get_end_point_l(1).r & 0xFE) << 23) | ((get_end_point_h(1).r & 0xFE) << 30); + block.y = ((get_end_point_h(1).r & 0xFE) >> 2) | ((get_end_point_l(0).g & 0xFE) << 5) + | ((get_end_point_h(0).g & 0xFE) << 12) | ((get_end_point_l(1).g & 0xFE) << 19) + | ((get_end_point_h(1).g & 0xFE) << 26); + block.z = ((get_end_point_h(1).g & 0xFE) >> 6) | ((get_end_point_l(0).b & 0xFE) << 1) + | ((get_end_point_h(0).b & 0xFE) << 8) | ((get_end_point_l(1).b & 0xFE) << 15) + | ((get_end_point_h(1).b & 0xFE) << 22) + | ((get_end_point_l(0).r & 0x01) << 30) | ((get_end_point_h(0).r & 0x01) << 31); + block.w = ((get_end_point_l(1).r & 0x01) << 0) | ((get_end_point_h(1).r & 0x01) << 1) + | (get_color_index(0) << 2); uint i = 1; - for ( ; i <= candidateFixUpIndex1DOrdered[partition][0]; i ++ ) + for (; i <= candidateFixUpIndex1DOrdered[partition][0]; i++) { - block.w |= get_color_index(i) << ( i * 2 + 1 ); + block.w |= get_color_index(i) << (i * 2 + 1); } - for ( ; i < 16; i ++ ) + for (; i < 16; i++) { - block.w |= get_color_index(i) << ( i * 2 ); + block.w |= get_color_index(i) << (i * 2); } } -void block_package4( out uint4 block, uint rotation, uint index_selector, uint threadBase ) +void block_package4(out uint4 block, uint rotation, uint index_selector, uint threadBase) { - block.x = 0x10 | ( (rotation & 3) << 5 ) | ( (index_selector & 1) << 7 ) - | ( ( get_end_point_l(0).r & 0xF8 ) << 5 ) | ( ( get_end_point_h(0).r & 0xF8 ) << 10 ) - | ( ( get_end_point_l(0).g & 0xF8 ) << 15 ) | ( ( get_end_point_h(0).g & 0xF8 ) << 20 ) - | ( ( get_end_point_l(0).b & 0xF8 ) << 25 ); + block.x = 0x10 | ((rotation & 3) << 5) | ((index_selector & 1) << 7) + | ((get_end_point_l(0).r & 0xF8) << 5) | ((get_end_point_h(0).r & 0xF8) << 10) + | ((get_end_point_l(0).g & 0xF8) << 15) | ((get_end_point_h(0).g & 0xF8) << 20) + | ((get_end_point_l(0).b & 0xF8) << 25); - block.y = ( ( get_end_point_l(0).b & 0xF8 ) >> 7 ) | ( ( get_end_point_h(0).b & 0xF8 ) >> 2 ) - | ( ( get_end_point_l(0).a & 0xFC ) << 4 ) | ( ( get_end_point_h(0).a & 0xFC ) << 10 ) - | ( (get_color_index(0) & 1) << 18 ) | ( get_color_index(1) << 19 ) | ( get_color_index(2) << 21 ) | ( get_color_index(3) << 23 ) - | ( get_color_index(4) << 25 ) | ( get_color_index(5) << 27 ) | ( get_color_index(6) << 29 ) | ( get_color_index(7) << 31 ); + block.y = ((get_end_point_l(0).b & 0xF8) >> 7) | ((get_end_point_h(0).b & 0xF8) >> 2) + | ((get_end_point_l(0).a & 0xFC) << 4) | ((get_end_point_h(0).a & 0xFC) << 10) + | ((get_color_index(0) & 1) << 18) | (get_color_index(1) << 19) | (get_color_index(2) << 21) | (get_color_index(3) << 23) + | (get_color_index(4) << 25) | (get_color_index(5) << 27) | (get_color_index(6) << 29) | (get_color_index(7) << 31); - block.z = ( get_color_index(7) >> 1 ) | ( get_color_index(8) << 1 ) | ( get_color_index(9) << 3 ) | ( get_color_index(10)<< 5 ) - | ( get_color_index(11)<< 7 ) | ( get_color_index(12)<< 9 ) | ( get_color_index(13)<< 11 ) | ( get_color_index(14)<< 13 ) - | ( get_color_index(15)<< 15 ) | ( (get_alpha_index(0) & 3) << 17 ) | ( get_alpha_index(1) << 19 ) | ( get_alpha_index(2) << 22 ) - | ( get_alpha_index(3) << 25 ) | ( get_alpha_index(4) << 28 ) | ( get_alpha_index(5) << 31 ); + block.z = (get_color_index(7) >> 1) | (get_color_index(8) << 1) | (get_color_index(9) << 3) | (get_color_index(10)<< 5) + | (get_color_index(11)<< 7) | (get_color_index(12)<< 9) | (get_color_index(13)<< 11) | (get_color_index(14)<< 13) + | (get_color_index(15)<< 15) | ((get_alpha_index(0) & 3) << 17) | (get_alpha_index(1) << 19) | (get_alpha_index(2) << 22) + | (get_alpha_index(3) << 25) | (get_alpha_index(4) << 28) | (get_alpha_index(5) << 31); - block.w = ( get_alpha_index(5) >> 1 ) | ( get_alpha_index(6) << 2 ) | ( get_alpha_index(7) << 5 ) | ( get_alpha_index(8) << 8 ) - | ( get_alpha_index(9) << 11 ) | ( get_alpha_index(10)<< 14 ) | ( get_alpha_index(11)<< 17 ) | ( get_alpha_index(12)<< 20 ) - | ( get_alpha_index(13)<< 23 ) | ( get_alpha_index(14)<< 26 ) | ( get_alpha_index(15)<< 29 ); + block.w = (get_alpha_index(5) >> 1) | (get_alpha_index(6) << 2) | (get_alpha_index(7) << 5) | (get_alpha_index(8) << 8) + | (get_alpha_index(9) << 11) | (get_alpha_index(10)<< 14) | (get_alpha_index(11)<< 17) | (get_alpha_index(12)<< 20) + | (get_alpha_index(13)<< 23) | (get_alpha_index(14)<< 26) | (get_alpha_index(15)<< 29); } -void block_package5( out uint4 block, uint rotation, uint threadBase ) +void block_package5(out uint4 block, uint rotation, uint threadBase) { - block.x = 0x20 | ( rotation << 6 ) - | ( ( get_end_point_l(0).r & 0xFE ) << 7 ) | ( ( get_end_point_h(0).r & 0xFE ) << 14 ) - | ( ( get_end_point_l(0).g & 0xFE ) << 21 ) | ( ( get_end_point_h(0).g & 0xFE ) << 28 ); - block.y = ( ( get_end_point_h(0).g & 0xFE ) >> 4 ) | ( ( get_end_point_l(0).b & 0xFE ) << 3 ) - | ( ( get_end_point_h(0).b & 0xFE ) << 10 ) | ( get_end_point_l(0).a << 18 ) | ( get_end_point_h(0).a << 26 ); - block.z = ( get_end_point_h(0).a >> 6 ) - | ( get_color_index(0) << 2 ) | ( get_color_index(1) << 3 ) | ( get_color_index(2) << 5 ) | ( get_color_index(3) << 7 ) - | ( get_color_index(4) << 9 ) | ( get_color_index(5) << 11 ) | ( get_color_index(6) << 13 ) | ( get_color_index(7) << 15 ) - | ( get_color_index(8) << 17 ) | ( get_color_index(9) << 19 ) | ( get_color_index(10)<< 21 ) | ( get_color_index(11)<< 23 ) - | ( get_color_index(12)<< 25 ) | ( get_color_index(13)<< 27 ) | ( get_color_index(14)<< 29 ) | ( get_color_index(15)<< 31 ); - block.w = ( get_color_index(15)>> 1 ) | ( get_alpha_index(0) << 1 ) | ( get_alpha_index(1) << 2 ) | ( get_alpha_index(2) << 4 ) - | ( get_alpha_index(3) << 6 ) | ( get_alpha_index(4) << 8 ) | ( get_alpha_index(5) << 10 ) | ( get_alpha_index(6) << 12 ) - | ( get_alpha_index(7) << 14 ) | ( get_alpha_index(8) << 16 ) | ( get_alpha_index(9) << 18 ) | ( get_alpha_index(10)<< 20 ) - | ( get_alpha_index(11)<< 22 ) | ( get_alpha_index(12)<< 24 ) | ( get_alpha_index(13)<< 26 ) | ( get_alpha_index(14)<< 28 ) - | ( get_alpha_index(15)<< 30 ); + block.x = 0x20 | (rotation << 6) + | ((get_end_point_l(0).r & 0xFE) << 7) | ((get_end_point_h(0).r & 0xFE) << 14) + | ((get_end_point_l(0).g & 0xFE) << 21) | ((get_end_point_h(0).g & 0xFE) << 28); + block.y = ((get_end_point_h(0).g & 0xFE) >> 4) | ((get_end_point_l(0).b & 0xFE) << 3) + | ((get_end_point_h(0).b & 0xFE) << 10) | (get_end_point_l(0).a << 18) | (get_end_point_h(0).a << 26); + block.z = (get_end_point_h(0).a >> 6) + | (get_color_index(0) << 2) | (get_color_index(1) << 3) | (get_color_index(2) << 5) | (get_color_index(3) << 7) + | (get_color_index(4) << 9) | (get_color_index(5) << 11) | (get_color_index(6) << 13) | (get_color_index(7) << 15) + | (get_color_index(8) << 17) | (get_color_index(9) << 19) | (get_color_index(10)<< 21) | (get_color_index(11)<< 23) + | (get_color_index(12)<< 25) | (get_color_index(13)<< 27) | (get_color_index(14)<< 29) | (get_color_index(15)<< 31); + block.w = (get_color_index(15)>> 1) | (get_alpha_index(0) << 1) | (get_alpha_index(1) << 2) | (get_alpha_index(2) << 4) + | (get_alpha_index(3) << 6) | (get_alpha_index(4) << 8) | (get_alpha_index(5) << 10) | (get_alpha_index(6) << 12) + | (get_alpha_index(7) << 14) | (get_alpha_index(8) << 16) | (get_alpha_index(9) << 18) | (get_alpha_index(10)<< 20) + | (get_alpha_index(11)<< 22) | (get_alpha_index(12)<< 24) | (get_alpha_index(13)<< 26) | (get_alpha_index(14)<< 28) + | (get_alpha_index(15)<< 30); } -void block_package6( out uint4 block, uint threadBase ) +void block_package6(out uint4 block, uint threadBase) { block.x = 0x40 - | ( ( get_end_point_l(0).r & 0xFE ) << 6 ) | ( ( get_end_point_h(0).r & 0xFE ) << 13 ) - | ( ( get_end_point_l(0).g & 0xFE ) << 20 ) | ( ( get_end_point_h(0).g & 0xFE ) << 27 ); - block.y = ( ( get_end_point_h(0).g & 0xFE ) >> 5 ) | ( ( get_end_point_l(0).b & 0xFE ) << 2 ) - | ( ( get_end_point_h(0).b & 0xFE ) << 9 ) | ( ( get_end_point_l(0).a & 0xFE ) << 16 ) - | ( ( get_end_point_h(0).a & 0xFE ) << 23 ) - | ( get_end_point_l(0).r & 0x01 ) << 31; - block.z = ( get_end_point_h(0).r & 0x01 ) - | ( get_color_index(0) << 1 ) | ( get_color_index(1) << 4 ) | ( get_color_index(2) << 8 ) | ( get_color_index(3) << 12 ) - | ( get_color_index(4) << 16 ) | ( get_color_index(5) << 20 ) | ( get_color_index(6) << 24 ) | ( get_color_index(7) << 28 ); - block.w = ( get_color_index(8) << 0 ) | ( get_color_index(9) << 4 ) | ( get_color_index(10)<< 8 ) | ( get_color_index(11)<< 12 ) - | ( get_color_index(12)<< 16 ) | ( get_color_index(13)<< 20 ) | ( get_color_index(14)<< 24 ) | ( get_color_index(15)<< 28 ); + | ((get_end_point_l(0).r & 0xFE) << 6) | ((get_end_point_h(0).r & 0xFE) << 13) + | ((get_end_point_l(0).g & 0xFE) << 20) | ((get_end_point_h(0).g & 0xFE) << 27); + block.y = ((get_end_point_h(0).g & 0xFE) >> 5) | ((get_end_point_l(0).b & 0xFE) << 2) + | ((get_end_point_h(0).b & 0xFE) << 9) | ((get_end_point_l(0).a & 0xFE) << 16) + | ((get_end_point_h(0).a & 0xFE) << 23) + | (get_end_point_l(0).r & 0x01) << 31; + block.z = (get_end_point_h(0).r & 0x01) + | (get_color_index(0) << 1) | (get_color_index(1) << 4) | (get_color_index(2) << 8) | (get_color_index(3) << 12) + | (get_color_index(4) << 16) | (get_color_index(5) << 20) | (get_color_index(6) << 24) | (get_color_index(7) << 28); + block.w = (get_color_index(8) << 0) | (get_color_index(9) << 4) | (get_color_index(10)<< 8) | (get_color_index(11)<< 12) + | (get_color_index(12)<< 16) | (get_color_index(13)<< 20) | (get_color_index(14)<< 24) | (get_color_index(15)<< 28); } -void block_package7( out uint4 block, uint partition, uint threadBase ) +void block_package7(out uint4 block, uint partition, uint threadBase) { - block.x = 0x80 | ( partition << 8 ) - | ( ( get_end_point_l(0).r & 0xF8 ) << 11 ) | ( ( get_end_point_h(0).r & 0xF8 ) << 16 ) - | ( ( get_end_point_l(1).r & 0xF8 ) << 21 ) | ( ( get_end_point_h(1).r & 0xF8 ) << 26 ); - block.y = ( ( get_end_point_h(1).r & 0xF8 ) >> 6 ) | ( ( get_end_point_l(0).g & 0xF8 ) >> 1 ) - | ( ( get_end_point_h(0).g & 0xF8 ) << 4 ) | ( ( get_end_point_l(1).g & 0xF8 ) << 9 ) - | ( ( get_end_point_h(1).g & 0xF8 ) << 14 ) | ( ( get_end_point_l(0).b & 0xF8 ) << 19 ) - | ( ( get_end_point_h(0).b & 0xF8 ) << 24 ); - block.z = ( ( get_end_point_l(1).b & 0xF8 ) >> 3 ) | ( ( get_end_point_h(1).b & 0xF8 ) << 2 ) - | ( ( get_end_point_l(0).a & 0xF8 ) << 7 ) | ( ( get_end_point_h(0).a & 0xF8 ) << 12 ) - | ( ( get_end_point_l(1).a & 0xF8 ) << 17 ) | ( ( get_end_point_h(1).a & 0xF8 ) << 22 ) - | ( ( get_end_point_l(0).r & 0x04 ) << 28 ) | ( ( get_end_point_h(0).r & 0x04 ) << 29 ); - block.w = ( ( get_end_point_l(1).r & 0x04 ) >> 2 ) | ( ( get_end_point_h(1).r & 0x04 ) >> 1 ) - | ( get_color_index(0) << 2 ); + block.x = 0x80 | (partition << 8) + | ((get_end_point_l(0).r & 0xF8) << 11) | ((get_end_point_h(0).r & 0xF8) << 16) + | ((get_end_point_l(1).r & 0xF8) << 21) | ((get_end_point_h(1).r & 0xF8) << 26); + block.y = ((get_end_point_h(1).r & 0xF8) >> 6) | ((get_end_point_l(0).g & 0xF8) >> 1) + | ((get_end_point_h(0).g & 0xF8) << 4) | ((get_end_point_l(1).g & 0xF8) << 9) + | ((get_end_point_h(1).g & 0xF8) << 14) | ((get_end_point_l(0).b & 0xF8) << 19) + | ((get_end_point_h(0).b & 0xF8) << 24); + block.z = ((get_end_point_l(1).b & 0xF8) >> 3) | ((get_end_point_h(1).b & 0xF8) << 2) + | ((get_end_point_l(0).a & 0xF8) << 7) | ((get_end_point_h(0).a & 0xF8) << 12) + | ((get_end_point_l(1).a & 0xF8) << 17) | ((get_end_point_h(1).a & 0xF8) << 22) + | ((get_end_point_l(0).r & 0x04) << 28) | ((get_end_point_h(0).r & 0x04) << 29); + block.w = ((get_end_point_l(1).r & 0x04) >> 2) | ((get_end_point_h(1).r & 0x04) >> 1) + | (get_color_index(0) << 2); uint i = 1; - for ( ; i <= candidateFixUpIndex1DOrdered[partition][0]; i ++ ) + for (; i <= candidateFixUpIndex1DOrdered[partition][0]; i++) { - block.w |= get_color_index(i) << ( i * 2 + 1 ); + block.w |= get_color_index(i) << (i * 2 + 1); } - for ( ; i < 16; i ++ ) + for (; i < 16; i++) { - block.w |= get_color_index(i) << ( i * 2 ); + block.w |= get_color_index(i) << (i * 2); } -} \ No newline at end of file +} diff --git a/DirectXTex/filters.h b/DirectXTex/filters.h index 71b3b64..fb8a63f 100644 --- a/DirectXTex/filters.h +++ b/DirectXTex/filters.h @@ -28,7 +28,7 @@ namespace DirectX XMGLOBALCONST XMVECTORF32 g_boxScale = { { { 0.25f, 0.25f, 0.25f, 0.25f } } }; 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)); \ v = XMVectorAdd(v, (p2)); \ @@ -36,7 +36,7 @@ namespace DirectX 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)); \ 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), \ 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 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 d0 = XMVectorSubtract(p0, a0); \ diff --git a/DirectXTex/scoped.h b/DirectXTex/scoped.h index f49a6bf..1114e2c 100644 --- a/DirectXTex/scoped.h +++ b/DirectXTex/scoped.h @@ -29,7 +29,7 @@ inline ScopedAlignedArrayFloat make_AlignedArrayFloat(uint64_t count) if (size > static_cast(UINT32_MAX)) return nullptr; - auto ptr = aligned_alloc(16, static_cast(size) ); + auto ptr = aligned_alloc(16, static_cast(size)); return ScopedAlignedArrayFloat(static_cast(ptr)); } diff --git a/ScreenGrab/ScreenGrab11.cpp b/ScreenGrab/ScreenGrab11.cpp index 1273ef3..75645a3 100644 --- a/ScreenGrab/ScreenGrab11.cpp +++ b/ScreenGrab/ScreenGrab11.cpp @@ -57,7 +57,7 @@ using Microsoft::WRL::ComPtr; // Macros //-------------------------------------------------------------------------------------- #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)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 )) #endif /* defined(MAKEFOURCC) */ @@ -69,9 +69,9 @@ using Microsoft::WRL::ComPtr; //-------------------------------------------------------------------------------------- namespace { - #pragma pack(push,1) +#pragma pack(push,1) - #define DDS_MAGIC 0x20534444 // "DDS " +#define DDS_MAGIC 0x20534444 // "DDS " struct DDS_PIXELFORMAT { @@ -85,20 +85,20 @@ namespace uint32_t ABitMask; }; - #define DDS_FOURCC 0x00000004 // DDPF_FOURCC - #define DDS_RGB 0x00000040 // DDPF_RGB - #define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS - #define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE - #define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS - #define DDS_ALPHA 0x00000002 // DDPF_ALPHA - #define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV +#define DDS_FOURCC 0x00000004 // DDPF_FOURCC +#define DDS_RGB 0x00000040 // DDPF_RGB +#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS +#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE +#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS +#define DDS_ALPHA 0x00000002 // DDPF_ALPHA +#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV - #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_PITCH 0x00000008 // DDSD_PITCH - #define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE +#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_PITCH 0x00000008 // DDSD_PITCH +#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 { @@ -127,7 +127,7 @@ namespace uint32_t reserved; }; - #pragma pack(pop) +#pragma pack(pop) const DDS_PIXELFORMAT DDSPF_DXT1 = { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }; @@ -574,13 +574,13 @@ namespace 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!"); if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX) return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); -#else + #else static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!"); -#endif + #endif if (outNumBytes) { @@ -732,7 +732,7 @@ namespace 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( CLSID_WICImagingFactory2, nullptr, @@ -758,14 +758,14 @@ namespace ); return SUCCEEDED(hr) ? TRUE : FALSE; } -#else + #else return SUCCEEDED(CoCreateInstance( CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWICImagingFactory), ifactory)) ? TRUE : FALSE; -#endif + #endif } IWICImagingFactory* GetWIC() noexcept @@ -1092,7 +1092,7 @@ HRESULT DirectX::SaveWICTextureToFile( // Screenshots don't typically include the alpha channel of the render target 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_R16G16B16A16_FLOAT: if (g_WIC2) @@ -1104,7 +1104,7 @@ HRESULT DirectX::SaveWICTextureToFile( targetGuid = GUID_WICPixelFormat24bppBGR; } break; -#endif + #endif case DXGI_FORMAT_R16G16B16A16_UNORM: targetGuid = GUID_WICPixelFormat48bppBGR; break; case DXGI_FORMAT_B5G5R5A1_UNORM: targetGuid = GUID_WICPixelFormat16bppBGR555; break; diff --git a/ScreenGrab/ScreenGrab12.cpp b/ScreenGrab/ScreenGrab12.cpp index 385e244..f68bc77 100644 --- a/ScreenGrab/ScreenGrab12.cpp +++ b/ScreenGrab/ScreenGrab12.cpp @@ -91,9 +91,9 @@ using Microsoft::WRL::ComPtr; //-------------------------------------------------------------------------------------- namespace { - #pragma pack(push,1) +#pragma pack(push,1) - #define DDS_MAGIC 0x20534444 // "DDS " +#define DDS_MAGIC 0x20534444 // "DDS " struct DDS_PIXELFORMAT { @@ -107,20 +107,20 @@ namespace uint32_t ABitMask; }; - #define DDS_FOURCC 0x00000004 // DDPF_FOURCC - #define DDS_RGB 0x00000040 // DDPF_RGB - #define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS - #define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE - #define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS - #define DDS_ALPHA 0x00000002 // DDPF_ALPHA - #define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV +#define DDS_FOURCC 0x00000004 // DDPF_FOURCC +#define DDS_RGB 0x00000040 // DDPF_RGB +#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS +#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE +#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS +#define DDS_ALPHA 0x00000002 // DDPF_ALPHA +#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV - #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_PITCH 0x00000008 // DDSD_PITCH - #define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE +#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_PITCH 0x00000008 // DDSD_PITCH +#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 { @@ -149,7 +149,7 @@ namespace uint32_t reserved; }; - #pragma pack(pop) +#pragma pack(pop) const DDS_PIXELFORMAT DDSPF_DXT1 = { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 }; @@ -602,13 +602,13 @@ namespace 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!"); if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; -#else + #else static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!"); -#endif + #endif if (outNumBytes) { @@ -842,11 +842,11 @@ namespace // Block until the copy is complete while (fence->GetCompletedValue() < 1) { -#ifdef WIN32 + #ifdef WIN32 SwitchToThread(); -#else + #else std::this_thread::yield(); -#endif + #endif } return S_OK; diff --git a/ScreenGrab/ScreenGrab9.cpp b/ScreenGrab/ScreenGrab9.cpp index c75c971..43077c1 100644 --- a/ScreenGrab/ScreenGrab9.cpp +++ b/ScreenGrab/ScreenGrab9.cpp @@ -51,7 +51,7 @@ using Microsoft::WRL::ComPtr; // Macros //-------------------------------------------------------------------------------------- #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)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 )) #endif /* defined(MAKEFOURCC) */ @@ -63,9 +63,9 @@ using Microsoft::WRL::ComPtr; //-------------------------------------------------------------------------------------- namespace { - #pragma pack(push,1) +#pragma pack(push,1) - #define DDS_MAGIC 0x20534444 // "DDS " +#define DDS_MAGIC 0x20534444 // "DDS " struct DDS_PIXELFORMAT { @@ -79,21 +79,21 @@ namespace uint32_t ABitMask; }; - #define DDS_FOURCC 0x00000004 // DDPF_FOURCC - #define DDS_RGB 0x00000040 // DDPF_RGB - #define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS - #define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE - #define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS - #define DDS_ALPHA 0x00000002 // DDPF_ALPHA - #define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV - #define DDS_BUMPLUMINANCE 0x00040000 // DDPF_BUMPLUMINANCE +#define DDS_FOURCC 0x00000004 // DDPF_FOURCC +#define DDS_RGB 0x00000040 // DDPF_RGB +#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS +#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE +#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS +#define DDS_ALPHA 0x00000002 // DDPF_ALPHA +#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV +#define DDS_BUMPLUMINANCE 0x00040000 // DDPF_BUMPLUMINANCE - #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_PITCH 0x00000008 // DDSD_PITCH - #define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE +#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_PITCH 0x00000008 // DDSD_PITCH +#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 { @@ -113,7 +113,7 @@ namespace uint32_t reserved2; }; - #pragma pack(pop) +#pragma pack(pop) const DDS_PIXELFORMAT DDSPF_DXT1 = { 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_G16R16F: case D3DFMT_R32F: -#if !defined(D3D_DISABLE_9EX) + #if !defined(D3D_DISABLE_9EX) case D3DFMT_D32_LOCKABLE: -#endif + #endif return 32; case D3DFMT_R8G8B8: @@ -354,9 +354,9 @@ namespace case D3DFMT_P8: case D3DFMT_L8: case D3DFMT_A4L4: -#if !defined(D3D_DISABLE_9EX) + #if !defined(D3D_DISABLE_9EX) case D3DFMT_S8_LOCKABLE: -#endif + #endif return 8; case D3DFMT_DXT1: @@ -374,10 +374,10 @@ namespace case MAKEFOURCC('Y', 'V', '1', '2'): return 12; -#if !defined(D3D_DISABLE_9EX) + #if !defined(D3D_DISABLE_9EX) case D3DFMT_A1: return 1; -#endif + #endif default: return 0; @@ -483,13 +483,13 @@ namespace 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!"); if (numBytes > UINT32_MAX || rowBytes > UINT32_MAX || numRows > UINT32_MAX) return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); -#else + #else static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!"); -#endif + #endif if (outNumBytes) { @@ -513,7 +513,7 @@ namespace 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( CLSID_WICImagingFactory2, nullptr, @@ -539,14 +539,14 @@ namespace ); return SUCCEEDED(hr) ? TRUE : FALSE; } -#else + #else return SUCCEEDED(CoCreateInstance( CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWICImagingFactory), ifactory)) ? TRUE : FALSE; -#endif + #endif } IWICImagingFactory* GetWIC() @@ -795,14 +795,14 @@ HRESULT DirectX::SaveWICTextureToFile( case D3DFMT_R32F: pfGuid = GUID_WICPixelFormat32bppGrayFloat; 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: if (g_WIC2) pfGuid = GUID_WICPixelFormat32bppRGB; else HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); break; -#endif + #endif default: 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 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_A16B16G16R16F: if (g_WIC2) @@ -886,7 +886,7 @@ HRESULT DirectX::SaveWICTextureToFile( targetGuid = GUID_WICPixelFormat24bppBGR; } break; -#endif + #endif case D3DFMT_A16B16G16R16: targetGuid = GUID_WICPixelFormat48bppBGR; break; case D3DFMT_R5G6B5: targetGuid = GUID_WICPixelFormat16bppBGR565; break; diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index c74a104..0d3dfcb 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -686,9 +686,9 @@ namespace wprintf(L"Microsoft (R) DirectX Texture Assembler [DirectXTex] Version %ls\n", version); wprintf(L"Copyright (C) Microsoft Corp.\n"); -#ifdef _DEBUG + #ifdef _DEBUG wprintf(L"*** Debug build ***\n"); -#endif + #endif wprintf(L"\n"); } @@ -785,20 +785,20 @@ namespace case CODEC_HDR: return SaveToHDRFile(img, szOutputFile); -#ifdef USE_OPENEXR + #ifdef USE_OPENEXR case CODEC_EXR: return SaveToEXRFile(img, szOutputFile); -#endif + #endif default: - { - HRESULT hr = SaveToWICFile(img, WIC_FLAGS_NONE, GetWICCodec(static_cast(fileType)), szOutputFile); - if ((hr == static_cast(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(fileType)), szOutputFile); + if ((hr == static_cast(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; 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: - case CMD_V_CROSS: - case CMD_H_STRIP: - case CMD_V_STRIP: - case CMD_MERGE: - case CMD_ARRAY_STRIP: - break; + wcscpy_s(szOutputFile, MAX_PATH, pValue); - default: - if (fileType != CODEC_DDS) + wchar_t ext[_MAX_EXT] = {}; + _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"); - return 1; + case CMD_H_CROSS: + 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: if (dwFilterOpts & TEX_FILTER_MIRROR) @@ -1162,19 +1162,19 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case OPT_FILELIST: - { - std::wifstream inFile(pValue); - if (!inFile) { - wprintf(L"Error opening -flist file %ls\n", pValue); - return 1; + std::wifstream inFile(pValue); + if (!inFile) + { + wprintf(L"Error opening -flist file %ls\n", pValue); + return 1; + } + + inFile.imbue(std::locale::classic()); + + ProcessFileList(inFile, conversion); } - - inFile.imbue(std::locale::classic()); - - ProcessFileList(inFile, conversion); - } - break; + break; case OPT_FEATURE_LEVEL: maxSize = LookupByName(pValue, g_pFeatureLevels); @@ -1458,7 +1458,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 1; } } -#ifdef USE_OPENEXR + #ifdef USE_OPENEXR else if (_wcsicmp(ext, L".exr") == 0) { 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; } } -#endif + #endif else { // 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; } -#ifndef NDEBUG + #ifndef NDEBUG auto& tinfo = timage->GetMetadata(); -#endif + #endif assert(info.width == tinfo.width); 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_H_STRIP: case CMD_V_STRIP: - { - size_t twidth = 0; - size_t theight = 0; - - switch (dwCommand) { - case CMD_H_CROSS: - // posy - // 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(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; + size_t twidth = 0; + size_t theight = 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; + twidth = width * 4; + theight = height * 3; 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; + twidth = width * 3; + theight = height * 4; break; - } case CMD_H_STRIP: - // posx, negx, posy, negy, posz, negz - offsetx = index * width; + twidth = width * 6; + theight = height; break; case CMD_V_STRIP: - // posx, negx, posy, negy, posz, negz - offsety = index * height; + twidth = width; + theight = height * 6; break; default: break; } - hr = CopyRectangle(*img, rect, *dest, dwFilter | dwFilterOpts, offsetx, offsety); + ScratchImage result; + hr = result.Initialize2D(format, twidth, theight, 1, 1); if (FAILED(hr)) { - wprintf(L"FAILED building result image (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); + wprintf(L"FAILED setting up result image (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); return 1; } - } - // Write cross/strip - wprintf(L"\nWriting %ls ", szOutputFile); - PrintInfo(result.GetMetadata()); - wprintf(L"\n"); - fflush(stdout); + memset(result.GetPixels(), 0, result.GetPixelsSize()); - if (dwOptions & (1 << OPT_TOLOWER)) - { - std::ignore = _wcslwr_s(szOutputFile); - } + auto src = loadedImages.cbegin(); + auto dest = result.GetImage(0, 0, 0); - if (~dwOptions & (1 << OPT_OVERWRITE)) - { - if (GetFileAttributesW(szOutputFile) != INVALID_FILE_ATTRIBUTES) + for (size_t index = 0; index < 6; ++index) { - 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(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(hr), GetErrorDesc(hr)); return 1; } + break; } - hr = SaveImageFile(*dest, fileType, szOutputFile); - if (FAILED(hr)) - { - wprintf(L" FAILED (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); - return 1; - } - break; - } - 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(hr), GetErrorDesc(hr)); - return 1; - } - - const Image& img = *tempImage.GetImage(0, 0, 0); - - // 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) + // 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)) { - const XMVECTOR *inPixels2 = reinterpret_cast(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(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"); + wprintf(L" FAILED [convert second input] (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); return 1; } - } - hr = SaveImageFile(*result.GetImage(0, 0, 0), fileType, szOutputFile); - if (FAILED(hr)) - { - wprintf(L" FAILED (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); - return 1; + const Image& img = *tempImage.GetImage(0, 0, 0); + + // 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(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(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(hr), GetErrorDesc(hr)); + return 1; + } + break; } - break; - } 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(hr), GetErrorDesc(hr)); - return 1; - } + const size_t twidth = width; + const size_t theight = height * images; - memset(result.GetPixels(), 0, result.GetPixelsSize()); - - auto src = loadedImages.cbegin(); - auto dest = result.GetImage(0, 0, 0); - - for (size_t index = 0; index < images; ++index) - { - auto img = (*src)->GetImage(0, index, 0); - if (!img) + ScratchImage result; + hr = result.Initialize2D(format, twidth, theight, 1, 1); + if (FAILED(hr)) { - wprintf(L"FAILED: Unexpected error\n"); + wprintf(L"FAILED setting up result image (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); return 1; } - const Rect rect(0, 0, width, height); + memset(result.GetPixels(), 0, result.GetPixelsSize()); - constexpr size_t offsetx = 0; - size_t offsety = 0; + auto src = loadedImages.cbegin(); + 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(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(hr), GetErrorDesc(hr)); + return 1; + } + break; + } + default: + { + std::vector 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)) { wprintf(L"FAILED building result image (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); return 1; } - } - // Write array strip - wprintf(L"\nWriting %ls ", szOutputFile); - PrintInfo(result.GetMetadata()); - wprintf(L"\n"); - fflush(stdout); + // 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) + if (dwOptions & (1 << OPT_TOLOWER)) { - 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(hr), GetErrorDesc(hr)); return 1; } - } - - hr = SaveImageFile(*dest, fileType, szOutputFile); - if (FAILED(hr)) - { - wprintf(L" FAILED (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); - return 1; - } - break; - } - default: - { - std::vector 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; - } - - if (FAILED(hr)) - { - wprintf(L"FAILED building result image (%08X%ls)\n", static_cast(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(hr), GetErrorDesc(hr)); - return 1; - } - break; - } } return 0; diff --git a/Texconv/ExtendedBMP.cpp b/Texconv/ExtendedBMP.cpp index f821cb4..d60f189 100644 --- a/Texconv/ExtendedBMP.cpp +++ b/Texconv/ExtendedBMP.cpp @@ -45,12 +45,12 @@ namespace { 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))); -#else + #else ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr))); -#endif + #endif if (!hFile) { return HRESULT_FROM_WIN32(GetLastError()); diff --git a/Texconv/PortablePixMap.cpp b/Texconv/PortablePixMap.cpp index 578ea08..7e2a221 100644 --- a/Texconv/PortablePixMap.cpp +++ b/Texconv/PortablePixMap.cpp @@ -82,12 +82,12 @@ namespace { 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))); -#else + #else ScopedHandle hFile(safe_handle(CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr))); -#endif + #endif if (!hFile) { return HRESULT_FROM_WIN32(GetLastError()); @@ -257,30 +257,30 @@ HRESULT __cdecl LoadFromPortablePixMap( break; case PPM_HEIGHT: - { - if (u == 0) - return E_FAIL; - - if (metadata) { - *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; + if (u == 0) + return E_FAIL; + + if (metadata) + { + *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(img->pixels); + pixelEnd = pixels + width * u; } - - 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(img->pixels); - pixelEnd = pixels + width * u; - } - break; + break; case PPM_MAX: if (u == 0) @@ -680,7 +680,7 @@ HRESULT __cdecl SaveToPortablePixMapHDR( if (!WriteFile(hFile.get(), flipImage.GetPixels(), static_cast(flipImage.GetPixelsSize()), &bytesWritten, nullptr)) return HRESULT_FROM_WIN32(GetLastError()); - + delonfail.clear(); return S_OK; diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 47e4c4a..471ea16 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -839,9 +839,9 @@ namespace wprintf(L"Microsoft (R) DirectX Texture Converter [DirectXTex] Version %ls\n", version); wprintf(L"Copyright (C) Microsoft Corp.\n"); -#ifdef _DEBUG + #ifdef _DEBUG wprintf(L"*** Debug build ***\n"); -#endif + #endif wprintf(L"\n"); } @@ -928,9 +928,9 @@ namespace wprintf(L" -wicmulti When writing images with WIC encode multiframe images\n"); wprintf(L"\n -nologo suppress copyright message\n"); wprintf(L" -timing Display elapsed processing time\n\n"); -#ifdef _OPENMP + #ifdef _OPENMP wprintf(L" -singleproc Do not use multi-threaded compression\n"); -#endif + #endif wprintf(L" -gpu Select GPU for DirectCompute-based codecs (0 is default)\n"); wprintf(L" -nogpu Do not use DirectCompute-based codecs\n"); wprintf( @@ -1043,9 +1043,9 @@ namespace }; UINT createDeviceFlags = 0; -#ifdef _DEBUG + #ifdef _DEBUG createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; -#endif + #endif ComPtr pAdapter; if (adapter >= 0) @@ -1614,62 +1614,62 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case OPT_NORMAL_MAP: - { - dwNormalMap = CNMAP_DEFAULT; + { + dwNormalMap = CNMAP_DEFAULT; - 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')) + if (wcschr(pValue, L'l')) { - 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; } } - - if (wcschr(pValue, L'i')) - { - dwNormalMap |= CNMAP_INVERT_SIGN; - } - - if (wcschr(pValue, L'o')) - { - dwNormalMap |= CNMAP_COMPUTE_OCCLUSION; - } - } - break; + break; case OPT_NORMAL_MAP_AMPLITUDE: if (!dwNormalMap) @@ -1750,48 +1750,48 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case OPT_BC_COMPRESS: - { - dwCompress = TEX_COMPRESS_DEFAULT; - - bool found = false; - if (wcschr(pValue, L'u')) { - dwCompress |= TEX_COMPRESS_UNIFORM; - found = true; - } + dwCompress = TEX_COMPRESS_DEFAULT; - if (wcschr(pValue, L'd')) - { - dwCompress |= TEX_COMPRESS_DITHER; - found = true; - } + bool found = false; + if (wcschr(pValue, L'u')) + { + dwCompress |= TEX_COMPRESS_UNIFORM; + found = true; + } - if (wcschr(pValue, L'q')) - { - dwCompress |= TEX_COMPRESS_BC7_QUICK; - found = true; - } + if (wcschr(pValue, L'd')) + { + dwCompress |= TEX_COMPRESS_DITHER; + found = true; + } - if (wcschr(pValue, L'x')) - { - dwCompress |= TEX_COMPRESS_BC7_USE_3SUBSETS; - found = true; - } + if (wcschr(pValue, L'q')) + { + dwCompress |= TEX_COMPRESS_BC7_QUICK; + found = true; + } - if ((dwCompress & (TEX_COMPRESS_BC7_QUICK | TEX_COMPRESS_BC7_USE_3SUBSETS)) == (TEX_COMPRESS_BC7_QUICK | TEX_COMPRESS_BC7_USE_3SUBSETS)) - { - wprintf(L"Can't use -bc x (max) and -bc q (quick) at same time\n\n"); - PrintUsage(); - return 1; - } + if (wcschr(pValue, L'x')) + { + dwCompress |= TEX_COMPRESS_BC7_USE_3SUBSETS; + found = true; + } - if (!found) - { - wprintf(L"Invalid value specified for -bc (%ls), missing d, u, q, or x\n\n", pValue); - return 1; + if ((dwCompress & (TEX_COMPRESS_BC7_QUICK | TEX_COMPRESS_BC7_USE_3SUBSETS)) == (TEX_COMPRESS_BC7_QUICK | TEX_COMPRESS_BC7_USE_3SUBSETS)) + { + wprintf(L"Can't use -bc x (max) and -bc q (quick) at same time\n\n"); + 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: 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; case OPT_FILELIST: - { - std::wifstream inFile(pValue); - if (!inFile) { - wprintf(L"Error opening -flist file %ls\n", pValue); - return 1; + std::wifstream inFile(pValue); + if (!inFile) + { + wprintf(L"Error opening -flist file %ls\n", pValue); + return 1; + } + + inFile.imbue(std::locale::classic()); + + ProcessFileList(inFile, conversion); } - - inFile.imbue(std::locale::classic()); - - ProcessFileList(inFile, conversion); - } - break; + break; case OPT_PAPER_WHITE_NITS: 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; } } -#ifdef USE_OPENEXR + #ifdef USE_OPENEXR else if (_wcsicmp(ext, L".exr") == 0) { hr = LoadFromEXRFile(pConv->szSrc, &info, *image); @@ -2099,7 +2099,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) continue; } } -#endif + #endif else { // 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; } -#ifndef NDEBUG + #ifndef NDEBUG auto& tinfo = timage->GetMetadata(); -#endif + #endif assert(info.width == tinfo.width); assert(info.height == tinfo.height); @@ -2526,9 +2526,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 1; } -#ifndef NDEBUG + #ifndef NDEBUG auto& tinfo = timage->GetMetadata(); -#endif + #endif assert(tinfo.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; } -#ifndef NDEBUG + #ifndef NDEBUG auto& tinfo = timage->GetMetadata(); -#endif + #endif assert(info.width == tinfo.width); assert(info.height == tinfo.height); @@ -2839,9 +2839,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 1; } -#ifndef NDEBUG + #ifndef NDEBUG auto& tinfo = timage->GetMetadata(); -#endif + #endif assert(info.width == tinfo.width); assert(info.height == tinfo.height); @@ -2986,9 +2986,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 1; } -#ifndef NDEBUG + #ifndef NDEBUG auto& tinfo = timage->GetMetadata(); -#endif + #endif assert(info.width == tinfo.width); assert(info.height == tinfo.height); @@ -3035,9 +3035,9 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) return 1; } -#ifndef NDEBUG + #ifndef NDEBUG auto& tinfo = timage->GetMetadata(); -#endif + #endif assert(info.width == tinfo.width); 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(), [&](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; - 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))); - } + UNREFERENCED_PARAMETER(y); - outPixels[j] = XMVectorSelect(value, z, s_selectz); - } - }, *timage); + for (size_t j = 0; j < w; ++j) + { + 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)) { wprintf(L" FAILED [reconstructz] (%08X%ls)\n", static_cast(hr), GetErrorDesc(hr)); return 1; } -#ifndef NDEBUG + #ifndef NDEBUG auto& tinfo = timage->GetMetadata(); -#endif + #endif assert(info.width == tinfo.width); 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(); -#endif + #endif assert(info.width == tinfo.width); 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; -#ifdef _OPENMP + #ifdef _OPENMP if (!(dwOptions & (uint64_t(1) << OPT_FORCE_SINGLEPROC))) { cflags |= TEX_COMPRESS_PARALLEL; } -#endif + #endif 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) { 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; - } - else if (dwOptions & (uint64_t(1) << OPT_USE_DX9)) - { - ddsFlags |= DDS_FLAGS_FORCE_DX9_LEGACY; - } + 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; + } + else if (dwOptions & (uint64_t(1) << OPT_USE_DX9)) + { + ddsFlags |= DDS_FLAGS_FORCE_DX9_LEGACY; + } - hr = SaveToDDSFile(img, nimg, info, ddsFlags, szDest); - break; - } + hr = SaveToDDSFile(img, nimg, info, ddsFlags, szDest); + break; + } case CODEC_TGA: 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); break; -#ifdef USE_OPENEXR + #ifdef USE_OPENEXR case CODEC_EXR: hr = SaveToEXRFile(img[0], szDest); break; -#endif + #endif default: - { - const WICCodecs codec = (FileType == CODEC_HDP || FileType == CODEC_JXR) ? WIC_CODEC_WMP : static_cast(FileType); - const size_t nimages = (dwOptions & (uint64_t(1) << OPT_WIC_MULTIFRAME)) ? nimg : 1; - hr = SaveToWICFile(img, nimages, WIC_FLAGS_NONE, GetWICCodec(codec), szDest, nullptr, - [&](IPropertyBag2* props) - { - const bool wicLossless = (dwOptions & (uint64_t(1) << OPT_WIC_LOSSLESS)) != 0; - - switch (FileType) + { + const WICCodecs codec = (FileType == CODEC_HDP || FileType == CODEC_JXR) ? WIC_CODEC_WMP : static_cast(FileType); + const size_t nimages = (dwOptions & (uint64_t(1) << OPT_WIC_MULTIFRAME)) ? nimg : 1; + hr = SaveToWICFile(img, nimages, WIC_FLAGS_NONE, GetWICCodec(codec), szDest, nullptr, + [&](IPropertyBag2* props) { - case WIC_CODEC_JPEG: - if (wicLossless || wicQuality >= 0.f) - { - PROPBAG2 options = {}; - VARIANT varValues = {}; - options.pstrName = const_cast(L"ImageQuality"); - varValues.vt = VT_R4; - varValues.fltVal = (wicLossless) ? 1.f : wicQuality; - std::ignore = props->Write(1, &options, &varValues); - } - break; + const bool wicLossless = (dwOptions & (uint64_t(1) << OPT_WIC_LOSSLESS)) != 0; - case WIC_CODEC_TIFF: - { - PROPBAG2 options = {}; - VARIANT varValues = {}; - if (wicLossless) + switch (FileType) { - options.pstrName = const_cast(L"TiffCompressionMethod"); - varValues.vt = VT_UI1; - varValues.bVal = WICTiffCompressionNone; - } - else if (wicQuality >= 0.f) - { - options.pstrName = const_cast(L"CompressionQuality"); - varValues.vt = VT_R4; - varValues.fltVal = wicQuality; - } - std::ignore = props->Write(1, &options, &varValues); - } - break; + case WIC_CODEC_JPEG: + if (wicLossless || wicQuality >= 0.f) + { + PROPBAG2 options = {}; + VARIANT varValues = {}; + options.pstrName = const_cast(L"ImageQuality"); + varValues.vt = VT_R4; + varValues.fltVal = (wicLossless) ? 1.f : 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(L"Lossless"); - varValues.vt = VT_BOOL; - varValues.bVal = TRUE; + case WIC_CODEC_TIFF: + { + PROPBAG2 options = {}; + VARIANT varValues = {}; + if (wicLossless) + { + options.pstrName = const_cast(L"TiffCompressionMethod"); + varValues.vt = VT_UI1; + varValues.bVal = WICTiffCompressionNone; + } + else if (wicQuality >= 0.f) + { + options.pstrName = const_cast(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(L"Lossless"); + varValues.vt = VT_BOOL; + varValues.bVal = TRUE; + } + else if (wicQuality >= 0.f) + { + options.pstrName = const_cast(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(L"ImageQuality"); - varValues.vt = VT_R4; - varValues.fltVal = wicQuality; - } - std::ignore = props->Write(1, &options, &varValues); - } - break; - } - }); - } - break; + }); + } + break; } if (FAILED(hr)) diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index 13d073d..d948579 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -644,9 +644,9 @@ namespace wprintf(L"Microsoft (R) DirectX Texture Diagnostic Tool [DirectXTex] Version %ls\n", version); wprintf(L"Copyright (C) Microsoft Corp.\n"); -#ifdef _DEBUG + #ifdef _DEBUG wprintf(L"*** Debug build ***\n"); -#endif + #endif wprintf(L"\n"); } @@ -782,12 +782,12 @@ namespace { return LoadFromHDRFile(fileName, &info, *image); } -#ifdef USE_OPENEXR + #ifdef USE_OPENEXR else if (_wcsicmp(ext, L".exr") == 0) { return LoadFromEXRFile(fileName, &info, *image); } -#endif + #endif else { // WIC shares the same filter values for mode and dither @@ -827,10 +827,10 @@ namespace case CODEC_HDR: return SaveToHDRFile(*image, fileName); -#ifdef USE_OPENEXR + #ifdef USE_OPENEXR case CODEC_EXR: return SaveToEXRFile(*image, fileName); -#endif + #endif default: return SaveToWICFile(*image, WIC_FLAGS_NONE, GetWICCodec(static_cast(codec)), fileName); @@ -1120,131 +1120,131 @@ namespace { case DXGI_FORMAT_BC1_UNORM: case DXGI_FORMAT_BC1_UNORM_SRGB: - { - auto block = reinterpret_cast(sptr); - - if (block->rgb[0] <= block->rgb[1]) { - // Transparent block - ++result.blockHist[1]; - } - else - { - // Opaque block - ++result.blockHist[0]; - } - } - break; + auto block = reinterpret_cast(sptr); - // BC2 only has a single 'type' of block + if (block->rgb[0] <= block->rgb[1]) + { + // Transparent block + ++result.blockHist[1]; + } + else + { + // Opaque block + ++result.blockHist[0]; + } + } + break; + + // BC2 only has a single 'type' of block case DXGI_FORMAT_BC3_UNORM: case DXGI_FORMAT_BC3_UNORM_SRGB: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - if (block->alpha[0] > block->alpha[1]) - { - // 8 alpha block - ++result.blockHist[0]; + if (block->alpha[0] > block->alpha[1]) + { + // 8 alpha block + ++result.blockHist[0]; + } + else + { + // 6 alpha block + ++result.blockHist[1]; + } } - else - { - // 6 alpha block - ++result.blockHist[1]; - } - } - break; + break; case DXGI_FORMAT_BC4_UNORM: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - if (block->red_0 > block->red_1) - { - // 8 red block - ++result.blockHist[0]; + if (block->red_0 > block->red_1) + { + // 8 red block + ++result.blockHist[0]; + } + else + { + // 6 red block + ++result.blockHist[1]; + } } - else - { - // 6 red block - ++result.blockHist[1]; - } - } - break; + break; case DXGI_FORMAT_BC4_SNORM: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - if (block->red_0 > block->red_1) - { - // 8 red block - ++result.blockHist[0]; + if (block->red_0 > block->red_1) + { + // 8 red block + ++result.blockHist[0]; + } + else + { + // 6 red block + ++result.blockHist[1]; + } } - else - { - // 6 red block - ++result.blockHist[1]; - } - } - break; + break; case DXGI_FORMAT_BC5_UNORM: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - if (block->u.red_0 > block->u.red_1) - { - // 8 red block - ++result.blockHist[0]; - } - else - { - // 6 red block - ++result.blockHist[1]; - } + if (block->u.red_0 > block->u.red_1) + { + // 8 red block + ++result.blockHist[0]; + } + else + { + // 6 red block + ++result.blockHist[1]; + } - if (block->v.red_0 > block->v.red_1) - { - // 8 green block - ++result.blockHist[2]; + if (block->v.red_0 > block->v.red_1) + { + // 8 green block + ++result.blockHist[2]; + } + else + { + // 6 green block + ++result.blockHist[3]; + } } - else - { - // 6 green block - ++result.blockHist[3]; - } - } - break; + break; case DXGI_FORMAT_BC5_SNORM: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - if (block->u.red_0 > block->u.red_1) - { - // 8 red block - ++result.blockHist[0]; - } - else - { - // 6 red block - ++result.blockHist[1]; - } + if (block->u.red_0 > block->u.red_1) + { + // 8 red block + ++result.blockHist[0]; + } + else + { + // 6 red block + ++result.blockHist[1]; + } - if (block->v.red_0 > block->v.red_1) - { - // 8 green block - ++result.blockHist[2]; + if (block->v.red_0 > block->v.red_1) + { + // 8 green block + ++result.blockHist[2]; + } + else + { + // 6 green block + ++result.blockHist[3]; + } } - else - { - // 6 green block - ++result.blockHist[3]; - } - } - break; + break; case DXGI_FORMAT_BC6H_UF16: case DXGI_FORMAT_BC6H_SF16: @@ -1492,6 +1492,7 @@ namespace return Convert(diffImage.GetImages(), diffImage.GetImageCount(), diffImage.GetMetadata(), format, dwFilter, TEX_THRESHOLD_DEFAULT, result); } +#pragma region DumpBC //-------------------------------------------------------------------------------------- // Partition, Shape, Fixup const uint8_t g_aFixUp[3][64][3] = @@ -1730,155 +1731,155 @@ namespace { case DXGI_FORMAT_BC1_UNORM: case DXGI_FORMAT_BC1_UNORM_SRGB: - { - auto block = reinterpret_cast(sptr); - - if (block->rgb[0] <= block->rgb[1]) { - // Transparent block - wprintf(L"\tTransparent - E0: "); - } - else - { - // Opaque block - wprintf(L"\t Opaque - E0: "); - } + auto block = reinterpret_cast(sptr); - Print565(block->rgb[0]); - wprintf(L"\n\t E1: "); - Print565(block->rgb[1]); - wprintf(L"\n\t Index: "); - PrintIndex2bpp(block->bitmap); - wprintf(L"\n"); - } - break; + if (block->rgb[0] <= block->rgb[1]) + { + // Transparent block + wprintf(L"\tTransparent - E0: "); + } + else + { + // Opaque block + wprintf(L"\t Opaque - E0: "); + } + + Print565(block->rgb[0]); + wprintf(L"\n\t E1: "); + Print565(block->rgb[1]); + wprintf(L"\n\t Index: "); + PrintIndex2bpp(block->bitmap); + wprintf(L"\n"); + } + break; case DXGI_FORMAT_BC2_UNORM: case DXGI_FORMAT_BC2_UNORM_SRGB: - { - auto block = reinterpret_cast(sptr); - - wprintf(L"\tColor - E0: "); - Print565(block->bc1.rgb[0]); - wprintf(L"\n\t E1: "); - Print565(block->bc1.rgb[1]); - wprintf(L"\n\t Index: "); - PrintIndex2bpp(block->bc1.bitmap); - wprintf(L"\n"); - - wprintf(L"\tAlpha - "); - - size_t j = 0; - uint32_t bitmap = block->bitmap[0]; - for (; j < (NUM_PIXELS_PER_BLOCK / 2); ++j, bitmap >>= 4) { - wprintf(L"%X%ls", bitmap & 0xF, ((j % 4) == 3) ? L" | " : L" "); - } + auto block = reinterpret_cast(sptr); - bitmap = block->bitmap[1]; - for (; j < NUM_PIXELS_PER_BLOCK; ++j, bitmap >>= 4) - { - wprintf(L"%X%ls", bitmap & 0xF, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" "); - } + wprintf(L"\tColor - E0: "); + Print565(block->bc1.rgb[0]); + wprintf(L"\n\t E1: "); + Print565(block->bc1.rgb[1]); + wprintf(L"\n\t Index: "); + PrintIndex2bpp(block->bc1.bitmap); + wprintf(L"\n"); - wprintf(L"\n"); - } - break; + wprintf(L"\tAlpha - "); + + size_t j = 0; + uint32_t bitmap = block->bitmap[0]; + for (; j < (NUM_PIXELS_PER_BLOCK / 2); ++j, bitmap >>= 4) + { + wprintf(L"%X%ls", bitmap & 0xF, ((j % 4) == 3) ? L" | " : L" "); + } + + bitmap = block->bitmap[1]; + for (; j < NUM_PIXELS_PER_BLOCK; ++j, bitmap >>= 4) + { + wprintf(L"%X%ls", bitmap & 0xF, ((j < (NUM_PIXELS_PER_BLOCK - 1)) && ((j % 4) == 3)) ? L" | " : L" "); + } + + wprintf(L"\n"); + } + break; case DXGI_FORMAT_BC3_UNORM: case DXGI_FORMAT_BC3_UNORM_SRGB: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - wprintf(L"\tColor - E0: "); - Print565(block->bc1.rgb[0]); - wprintf(L"\n\t E1: "); - Print565(block->bc1.rgb[1]); - wprintf(L"\n\t Index: "); - PrintIndex2bpp(block->bc1.bitmap); - wprintf(L"\n"); + wprintf(L"\tColor - E0: "); + Print565(block->bc1.rgb[0]); + wprintf(L"\n\t E1: "); + Print565(block->bc1.rgb[1]); + wprintf(L"\n\t Index: "); + PrintIndex2bpp(block->bc1.bitmap); + wprintf(L"\n"); - wprintf(L"\tAlpha - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", - (float(block->alpha[0]) / 255.f), - (float(block->alpha[1]) / 255.f), (block->alpha[0] > block->alpha[1]) ? 8u : 6u); + wprintf(L"\tAlpha - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", + (float(block->alpha[0]) / 255.f), + (float(block->alpha[1]) / 255.f), (block->alpha[0] > block->alpha[1]) ? 8u : 6u); - PrintIndex3bpp(block->bitmap); + PrintIndex3bpp(block->bitmap); - wprintf(L"\n"); - } - break; + wprintf(L"\n"); + } + break; case DXGI_FORMAT_BC4_UNORM: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - wprintf(L"\t E0: %0.3f E1: %0.3f (%u)\n\tIndex: ", - (float(block->red_0) / 255.f), - (float(block->red_1) / 255.f), (block->red_0 > block->red_1) ? 8u : 6u); + wprintf(L"\t E0: %0.3f E1: %0.3f (%u)\n\tIndex: ", + (float(block->red_0) / 255.f), + (float(block->red_1) / 255.f), (block->red_0 > block->red_1) ? 8u : 6u); - PrintIndex3bpp(block->indices); + PrintIndex3bpp(block->indices); - wprintf(L"\n"); - } - break; + wprintf(L"\n"); + } + break; case DXGI_FORMAT_BC4_SNORM: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - wprintf(L"\t E0: %0.3f E1: %0.3f (%u)\n\tIndex: ", - (float(block->red_0) / 127.f), - (float(block->red_1) / 127.f), (block->red_0 > block->red_1) ? 8u : 6u); + wprintf(L"\t E0: %0.3f E1: %0.3f (%u)\n\tIndex: ", + (float(block->red_0) / 127.f), + (float(block->red_1) / 127.f), (block->red_0 > block->red_1) ? 8u : 6u); - PrintIndex3bpp(block->indices); + PrintIndex3bpp(block->indices); - wprintf(L"\n"); - } - break; + wprintf(L"\n"); + } + break; case DXGI_FORMAT_BC5_UNORM: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - wprintf(L"\tU - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", - (float(block->u.red_0) / 255.f), - (float(block->u.red_1) / 255.f), (block->u.red_0 > block->u.red_1) ? 8u : 6u); + wprintf(L"\tU - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", + (float(block->u.red_0) / 255.f), + (float(block->u.red_1) / 255.f), (block->u.red_0 > block->u.red_1) ? 8u : 6u); - PrintIndex3bpp(block->u.indices); + PrintIndex3bpp(block->u.indices); - wprintf(L"\n"); + wprintf(L"\n"); - wprintf(L"\tV - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", - (float(block->v.red_0) / 255.f), - (float(block->v.red_1) / 255.f), (block->v.red_0 > block->v.red_1) ? 8u : 6u); + wprintf(L"\tV - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", + (float(block->v.red_0) / 255.f), + (float(block->v.red_1) / 255.f), (block->v.red_0 > block->v.red_1) ? 8u : 6u); - PrintIndex3bpp(block->v.indices); + PrintIndex3bpp(block->v.indices); - wprintf(L"\n"); - } - break; + wprintf(L"\n"); + } + break; case DXGI_FORMAT_BC5_SNORM: - { - auto block = reinterpret_cast(sptr); + { + auto block = reinterpret_cast(sptr); - wprintf(L"\tU - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", - (float(block->u.red_0) / 127.f), - (float(block->u.red_1) / 127.f), (block->u.red_0 > block->u.red_1) ? 8u : 6u); + wprintf(L"\tU - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", + (float(block->u.red_0) / 127.f), + (float(block->u.red_1) / 127.f), (block->u.red_0 > block->u.red_1) ? 8u : 6u); - PrintIndex3bpp(block->u.indices); + PrintIndex3bpp(block->u.indices); - wprintf(L"\n"); + wprintf(L"\n"); - wprintf(L"\tV - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", - (float(block->v.red_0) / 127.f), - (float(block->v.red_1) / 127.f), (block->v.red_0 > block->v.red_1) ? 8u : 6u); + wprintf(L"\tV - E0: %0.3f E1: %0.3f (%u)\n\t Index: ", + (float(block->v.red_0) / 127.f), + (float(block->v.red_1) / 127.f), (block->v.red_0 > block->v.red_1) ? 8u : 6u); - PrintIndex3bpp(block->v.indices); + PrintIndex3bpp(block->v.indices); - wprintf(L"\n"); - } - break; + wprintf(L"\n"); + } + break; case DXGI_FORMAT_BC6H_UF16: case DXGI_FORMAT_BC6H_SF16: @@ -1888,550 +1889,21 @@ namespace { case 0x00: // Mode 1 (2 bits, 00) - { - struct bc6h_mode1 { - uint64_t mode : 2; // { M, 0}, { M, 1} - uint64_t gy4 : 1; // {GY, 4} - uint64_t by4 : 1; // {BY, 4} - uint64_t bz4 : 1; // {BZ, 4} - uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} - uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} - uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} - uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4} - uint64_t gz4 : 1; // {GZ, 4} - uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} - uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4} - uint64_t bz0 : 1; // {BZ, 0}, - uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} - uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4} - uint64_t bz1 : 1; // {BZ, 1} - uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} - uint64_t by3 : 1; // {BY, 3} - uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4} - uint64_t bz2 : 1; // {BZ, 2} - uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4} - uint64_t bz3 : 1; // {BZ, 3} - uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} - uint64_t indices : 46; - }; - static_assert(sizeof(bc6h_mode1) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - XMINT3 e1_A(int(m->ry), - int(m->gy | (m->gy4 << 4)), - int(m->by | (m->by3 << 3) | (m->by4 << 4))); - XMINT3 e1_B(int(m->rz), - int(m->gz | (m->gz4 << 4)), - int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 10); - e0_A.y = SIGN_EXTEND(e0_A.y, 10); - e0_A.z = SIGN_EXTEND(e0_A.z, 10); - - e0_B.x = SIGN_EXTEND(e0_B.x, 5); - e0_B.y = SIGN_EXTEND(e0_B.y, 5); - e0_B.z = SIGN_EXTEND(e0_B.z, 5); - - e1_A.x = SIGN_EXTEND(e1_A.x, 5); - e1_A.y = SIGN_EXTEND(e1_A.y, 5); - e1_A.z = SIGN_EXTEND(e1_A.z, 5); - - e1_B.x = SIGN_EXTEND(e1_B.x, 5); - e1_B.y = SIGN_EXTEND(e1_B.y, 5); - e1_B.z = SIGN_EXTEND(e1_B.z, 5); - } - - wprintf(L"\tMode 1 - [10 5 5 5] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - case 0x01: - // Mode 2 (2 bits, 01) - { - struct bc6h_mode2 - { - uint64_t mode : 2; // { M, 0}, { M, 1} - uint64_t gy5 : 1; // {GY, 5} - uint64_t gz45 : 2; // {GZ, 4}, {GZ, 5} - uint64_t rw : 7; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6} - uint64_t bz : 2; // {BZ, 0}, {BZ, 1} - uint64_t by4 : 1; // {BY, 4}, - uint64_t gw : 7; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6} - uint64_t by5 : 1; // {BY, 5} - uint64_t bz2 : 1; // {BZ, 2} - uint64_t gy4 : 1; // {GY, 4} - uint64_t bw : 7; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6} - uint64_t bz3 : 1; // {BZ, 3} - uint64_t bz5 : 1; // {BZ, 5} - uint64_t bz4 : 1; // {BZ, 4} - uint64_t rx : 6; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5} - uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} - uint64_t gx : 6; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5} - uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} - uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5} - uint64_t by : 4; // {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3} - uint64_t ry : 6; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, {RY, 5} - uint64_t rz : 6; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5}, - uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} - uint64_t indices : 46; - - }; - static_assert(sizeof(bc6h_mode2) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - XMINT3 e1_A(int(m->ry), - int(m->gy | (m->gy4 << 4) | (m->gy5 << 5)), - int(m->by | (m->by4 << 4) | (m->by5 << 5))); - XMINT3 e1_B(int(m->rz), - int(m->gz | (m->gz45 << 4)), - int(m->bz | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4) | (m->bz5 << 5))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 7); - e0_A.y = SIGN_EXTEND(e0_A.y, 7); - e0_A.z = SIGN_EXTEND(e0_A.z, 7); - - e0_B.x = SIGN_EXTEND(e0_B.x, 6); - e0_B.y = SIGN_EXTEND(e0_B.y, 6); - e0_B.z = SIGN_EXTEND(e0_B.z, 6); - - e1_A.x = SIGN_EXTEND(e1_A.x, 6); - e1_A.y = SIGN_EXTEND(e1_A.y, 6); - e1_A.z = SIGN_EXTEND(e1_A.z, 6); - - e1_B.x = SIGN_EXTEND(e1_B.x, 6); - e1_B.y = SIGN_EXTEND(e1_B.y, 6); - e1_B.z = SIGN_EXTEND(e1_B.z, 6); - } - - wprintf(L"\tMode 2 - [7 6 6 6] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - default: - switch (*sptr & 0x1F) - { - case 0x02: - // Mode 3 (5 bits, 00010) - { - struct bc6h_mode3 + struct bc6h_mode1 { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t mode : 2; // { M, 0}, { M, 1} + uint64_t gy4 : 1; // {GY, 4} + uint64_t by4 : 1; // {BY, 4} + uint64_t bz4 : 1; // {BZ, 4} uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4} - uint64_t rw10 : 1; // {RW,10} - uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} - uint64_t gx : 4; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3} - uint64_t gw10 : 1; // {GW,10} - uint64_t bz0 : 1; // {BZ, 0} - uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} - uint64_t bx : 4; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3} - uint64_t bw10 : 1; // {BW,10} - uint64_t bz1 : 1; // {BZ, 1} - uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} - uint64_t by3 : 1; // {BY, 3} - uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4} - uint64_t bz2 : 1; // {BZ, 2} - uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4} - uint64_t bz3 : 1; // {BZ, 3} - uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} - uint64_t indices : 46; - - }; - static_assert(sizeof(bc6h_mode3) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw | (m->rw10 << 10)), - int(m->gw | (m->gw10 << 10)), - int(m->bw | (m->bw10 << 10))); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - XMINT3 e1_A(int(m->ry), int(m->gy), - int(m->by | (m->by3 << 3))); - XMINT3 e1_B(int(m->rz), - int(m->gz), - int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 11); - e0_A.y = SIGN_EXTEND(e0_A.y, 11); - e0_A.z = SIGN_EXTEND(e0_A.z, 11); - - e0_B.x = SIGN_EXTEND(e0_B.x, 5); - e0_B.y = SIGN_EXTEND(e0_B.y, 4); - e0_B.z = SIGN_EXTEND(e0_B.z, 4); - - e1_A.x = SIGN_EXTEND(e1_A.x, 5); - e1_A.y = SIGN_EXTEND(e1_A.y, 4); - e1_A.z = SIGN_EXTEND(e1_A.z, 4); - - e1_B.x = SIGN_EXTEND(e1_B.x, 5); - e1_B.y = SIGN_EXTEND(e1_B.y, 4); - e1_B.z = SIGN_EXTEND(e1_B.z, 4); - } - - wprintf(L"\tMode 3 - [11 5 4 4] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - case 0x06: - // Mode 4 (5 bits, 00110) - { - struct bc6h_mode4 - { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} - uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} - uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} - uint64_t rx : 4; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3} - uint64_t rw10 : 1; // {RW,10} uint64_t gz4 : 1; // {GZ, 4} uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4} - uint64_t gw10 : 1; // {GW,10} - uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} - uint64_t bx : 4; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3} - uint64_t bw10 : 1; // {BW,10} - uint64_t bz1 : 1; // {BZ, 1} - uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} - uint64_t by3 : 1; // {BY, 3} - uint64_t ry : 4; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3} - uint64_t bz0 : 1; // {BZ, 0} - uint64_t bz2 : 1; // {BZ, 2} - uint64_t rz : 4; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3} - uint64_t gy4 : 1; // {GY, 4} - uint64_t bz3 : 1; // {BZ, 3} - uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} - uint64_t indices : 46; - - }; - static_assert(sizeof(bc6h_mode4) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw | (m->rw10 << 10)), - int(m->gw | (m->gw10 << 10)), - int(m->bw | (m->bw10 << 10))); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - XMINT3 e1_A(int(m->ry), - int(m->gy | (m->gy4 << 4)), - int(m->by | (m->by3 << 3))); - XMINT3 e1_B(int(m->rz), - int(m->gz | (m->gz4 << 4)), - int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 11); - e0_A.y = SIGN_EXTEND(e0_A.y, 11); - e0_A.z = SIGN_EXTEND(e0_A.z, 11); - - e0_B.x = SIGN_EXTEND(e0_B.x, 4); - e0_B.y = SIGN_EXTEND(e0_B.y, 5); - e0_B.z = SIGN_EXTEND(e0_B.z, 4); - - e1_A.x = SIGN_EXTEND(e1_A.x, 4); - e1_A.y = SIGN_EXTEND(e1_A.y, 5); - e1_A.z = SIGN_EXTEND(e1_A.z, 4); - - e1_B.x = SIGN_EXTEND(e1_B.x, 4); - e1_B.y = SIGN_EXTEND(e1_B.y, 5); - e1_B.z = SIGN_EXTEND(e1_B.z, 4); - } - - wprintf(L"\tMode 4 - [11 4 5 4] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - case 0x0A: - // Mode 5 (5 bits, 01010) - { - struct bc6h_mode5 - { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} - uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} - uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} - uint64_t rx : 4; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3} - uint64_t rw10 : 1; // {RW,10} - uint64_t by4 : 1; // {BY, 4} - uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} - uint64_t gx : 4; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3} - uint64_t gw10 : 1; // {GW,10} - uint64_t bz0 : 1; // {BZ, 0} - uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} - uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4} - uint64_t bw10 : 1; // {BW,10} - uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} - uint64_t by3 : 1; // {BY, 3} - uint64_t ry : 4; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3} - uint64_t bz12 : 2; // {BZ, 1}, {BZ, 2} - uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {BZ, 4} - uint64_t bz3 : 1; // {BZ, 3} - uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} - uint64_t indices : 46; - }; - static_assert(sizeof(bc6h_mode5) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw | (m->rw10 << 10)), - int(m->gw | (m->gw10 << 10)), - int(m->bw | (m->bw10 << 10))); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - XMINT3 e1_A(int(m->ry), int(m->gy), - int(m->by | (m->by3 << 3) | (m->by4 << 4))); - XMINT3 e1_B(int(m->rz), int(m->gz), - int(m->bz0 | (m->bz12 << 1) | (m->bz3 << 3))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 11); - e0_A.y = SIGN_EXTEND(e0_A.y, 11); - e0_A.z = SIGN_EXTEND(e0_A.z, 11); - - e0_B.x = SIGN_EXTEND(e0_B.x, 4); - e0_B.y = SIGN_EXTEND(e0_B.y, 4); - e0_B.z = SIGN_EXTEND(e0_B.z, 5); - - e1_A.x = SIGN_EXTEND(e1_A.x, 4); - e1_A.y = SIGN_EXTEND(e1_A.y, 4); - e1_A.z = SIGN_EXTEND(e1_A.z, 5); - - e1_B.x = SIGN_EXTEND(e1_B.x, 4); - e1_B.y = SIGN_EXTEND(e1_B.y, 4); - e1_B.z = SIGN_EXTEND(e1_B.z, 5); - } - - wprintf(L"\tMode 5 - [11 4 4 5] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - case 0x0E: - // Mode 6 (5 bits, 01110) - { - struct bc6h_mode6 - { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 9; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8} - uint64_t by4 : 1; // {BY, 4} - uint64_t gw : 9; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8} - uint64_t gy4 : 1; // {GY, 4} - uint64_t bw : 9; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8} - uint64_t bz4 : 1; // {BZ, 4} - uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4} - uint64_t gz4 : 1; // {GZ, 4} - uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} - uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4} - uint64_t bz0 : 1; // {BZ, 0} - uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} - uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4} - uint64_t bz1 : 1; // {BZ, 1} - uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} - uint64_t by3 : 1; // {BY, 3} - uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, - uint64_t bz2 : 1; // {BZ, 2} - uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {BZ, 4} - uint64_t bz3 : 1; // {BZ, 3} - uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} - uint64_t indices : 46; - }; - static_assert(sizeof(bc6h_mode6) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - XMINT3 e1_A(int(m->ry), - int(m->gy | (m->gy4 << 4)), - int(m->by | (m->by3 << 3) | (m->by4 << 4))); - XMINT3 e1_B(int(m->rz), - int(m->gz | (m->gz4 << 4)), - int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 9); - e0_A.y = SIGN_EXTEND(e0_A.y, 9); - e0_A.z = SIGN_EXTEND(e0_A.z, 9); - - e0_B.x = SIGN_EXTEND(e0_B.x, 5); - e0_B.y = SIGN_EXTEND(e0_B.y, 5); - e0_B.z = SIGN_EXTEND(e0_B.z, 5); - - e1_A.x = SIGN_EXTEND(e1_A.x, 5); - e1_A.y = SIGN_EXTEND(e1_A.y, 5); - e1_A.z = SIGN_EXTEND(e1_A.z, 5); - - e1_B.x = SIGN_EXTEND(e1_B.x, 5); - e1_B.y = SIGN_EXTEND(e1_B.y, 5); - e1_B.z = SIGN_EXTEND(e1_B.z, 5); - } - - wprintf(L"\tMode 6 - [9 5 5 5] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - case 0x12: - // Mode 7 (5 bits, 10010) - { - struct bc6h_mode7 - { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 8; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7} - uint64_t gz4 : 1; // {GZ, 4} - uint64_t by4 : 1; // {BY, 4} - uint64_t gw : 8; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7} - uint64_t bz2 : 1; // {BZ, 2} - uint64_t gy4 : 1; // {GY, 4} - uint64_t bw : 8; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7} - uint64_t bz3 : 1; // {BZ, 3} - uint64_t bz4 : 1; // {BZ, 4} - uint64_t rx : 6; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5} - uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} - uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4} - uint64_t bz0 : 1; // {BZ, 0} - uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} - uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4} - uint64_t bz1 : 1; // {BZ, 1} - uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} - uint64_t by3 : 1; // {BY, 3} - uint64_t ry : 6; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, {RY, 5} - uint64_t rz : 6; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5} - uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} - uint64_t indices : 46; - }; - static_assert(sizeof(bc6h_mode7) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - XMINT3 e1_A(int(m->ry), - int(m->gy | (m->gy4 << 4)), - int(m->by | (m->by3 << 3) | (m->by4 << 4))); - XMINT3 e1_B(int(m->rz), - int(m->gz | (m->gz4 << 4)), - int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 8); - e0_A.y = SIGN_EXTEND(e0_A.y, 8); - e0_A.z = SIGN_EXTEND(e0_A.z, 8); - - e0_B.x = SIGN_EXTEND(e0_B.x, 6); - e0_B.y = SIGN_EXTEND(e0_B.y, 5); - e0_B.z = SIGN_EXTEND(e0_B.z, 5); - - e1_A.x = SIGN_EXTEND(e1_A.x, 6); - e1_A.y = SIGN_EXTEND(e1_A.y, 5); - e1_A.z = SIGN_EXTEND(e1_A.z, 5); - - e1_B.x = SIGN_EXTEND(e1_B.x, 6); - e1_B.y = SIGN_EXTEND(e1_B.y, 5); - e1_B.z = SIGN_EXTEND(e1_B.z, 5); - } - - wprintf(L"\tMode 7 - [8 6 5 5] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - case 0x16: - // Mode 8 (5 bits, 10110) - { - struct bc6h_mode8 - { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 8; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7} - uint64_t bz0 : 1; // {BZ, 0} - uint64_t by4 : 1; // {BY, 4} - uint64_t gw : 8; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7} - uint64_t gy5 : 1; // {GY, 5} - uint64_t gy4 : 1; // {GY, 4} - uint64_t bw : 8; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7} - uint64_t gz5 : 1; // {GZ, 5} - uint64_t bz4 : 1; // {BZ, 4} - uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4} - uint64_t gz4 : 1; // {GZ, 4} - uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} - uint64_t gx : 6; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5} + uint64_t bz0 : 1; // {BZ, 0}, uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4} uint64_t bz1 : 1; // {BZ, 1} @@ -2444,227 +1916,20 @@ namespace uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} uint64_t indices : 46; }; - static_assert(sizeof(bc6h_mode8) == 16, "Block size must be 16 bytes"); + static_assert(sizeof(bc6h_mode1) == 16, "Block size must be 16 bytes"); const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - XMINT3 e1_A(int(m->ry), - int(m->gy | (m->gy4 << 4) | (m->gy5 << 5)), - int(m->by | (m->by3 << 3) | (m->by4 << 4))); - XMINT3 e1_B(int(m->rz), - int(m->gz | (m->gz4 << 4) | (m->gz5 << 5)), - int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 8); - e0_A.y = SIGN_EXTEND(e0_A.y, 8); - e0_A.z = SIGN_EXTEND(e0_A.z, 8); - - e0_B.x = SIGN_EXTEND(e0_B.x, 5); - e0_B.y = SIGN_EXTEND(e0_B.y, 6); - e0_B.z = SIGN_EXTEND(e0_B.z, 5); - - e1_A.x = SIGN_EXTEND(e1_A.x, 5); - e1_A.y = SIGN_EXTEND(e1_A.y, 6); - e1_A.z = SIGN_EXTEND(e1_A.z, 5); - - e1_B.x = SIGN_EXTEND(e1_B.x, 5); - e1_B.y = SIGN_EXTEND(e1_B.y, 6); - e1_B.z = SIGN_EXTEND(e1_B.z, 5); - } - - wprintf(L"\tMode 8 - [8 5 6 5] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - case 0x1A: - // Mode 9 (5 bits, 11010) - { - struct bc6h_mode9 - { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 8; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7} - uint64_t bz1 : 1; // {BZ, 1} - uint64_t by4 : 1; // {BY, 4} - uint64_t gw : 8; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7} - uint64_t by5 : 1; // {BY, 5} - uint64_t gy4 : 1; // {GY, 4} - uint64_t bw : 8; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7} - uint64_t bz5 : 1; // {BZ, 5} - uint64_t bz4 : 1; // {BZ, 4} - uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4} - uint64_t gz4 : 1; // {GZ, 4} - uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} - uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4} - uint64_t bz0 : 1; // {BZ, 0} - uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} - uint64_t bx : 6; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5} - uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} - uint64_t by3 : 1; // {BY, 3} - uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4} - uint64_t bz2 : 1; // {BZ, 2} - uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4} - uint64_t bz3 : 1; // {BZ, 3} - uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} - uint64_t indices : 46; - }; - static_assert(sizeof(bc6h_mode9) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); + auto m = reinterpret_cast(sptr); XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); XMINT3 e1_A(int(m->ry), int(m->gy | (m->gy4 << 4)), - int(m->by | (m->by3 << 3) | (m->by4 << 4) | (m->by5 << 5))); + int(m->by | (m->by3 << 3) | (m->by4 << 4))); XMINT3 e1_B(int(m->rz), int(m->gz | (m->gz4 << 4)), - int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4) | (m->bz5 << 5))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 8); - e0_A.y = SIGN_EXTEND(e0_A.y, 8); - e0_A.z = SIGN_EXTEND(e0_A.z, 8); - - e0_B.x = SIGN_EXTEND(e0_B.x, 5); - e0_B.y = SIGN_EXTEND(e0_B.y, 5); - e0_B.z = SIGN_EXTEND(e0_B.z, 6); - - e1_A.x = SIGN_EXTEND(e1_A.x, 5); - e1_A.y = SIGN_EXTEND(e1_A.y, 5); - e1_A.z = SIGN_EXTEND(e1_A.z, 6); - - e1_B.x = SIGN_EXTEND(e1_B.x, 5); - e1_B.y = SIGN_EXTEND(e1_B.y, 5); - e1_B.z = SIGN_EXTEND(e1_B.z, 6); - } - - wprintf(L"\tMode 9 - [8 5 5 6] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - case 0x1E: - // Mode 10 (5 bits, 11110) - { - struct bc6h_mode10 - { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 6; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5} - uint64_t gz4 : 1; // {GZ, 4} - uint64_t bz : 2; // {BZ, 0}, {BZ, 1} - uint64_t by4 : 1; // {BY, 4} - uint64_t gw : 6; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5} - uint64_t gy5 : 1; // {GY, 5} - uint64_t by5 : 1; // {BY, 5} - uint64_t bz2 : 1; // {BZ, 2} - uint64_t gy4 : 1; // {GY, 4} - uint64_t bw : 6; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {GZ, 5} - uint64_t bz3 : 1; // {BZ, 3} - uint64_t bz5 : 1; // {BZ, 5} - uint64_t bz4 : 1; // {BZ, 4} - uint64_t rx : 6; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5} - uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} - uint64_t gx : 6; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5} - uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} - uint64_t bx : 6; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5} - uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} - uint64_t by3 : 1; // {BY, 3} - uint64_t ry : 6; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, {RY, 5} - uint64_t rz : 6; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5} - uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} - uint64_t indices : 46; - }; - static_assert(sizeof(bc6h_mode10) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - XMINT3 e1_A(int(m->ry), - int(m->gy | (m->gy4 << 4) | (m->gy5 << 5)), - int(m->by | (m->by3 << 3) | (m->by4 << 4) | (m->by5 << 5))); - XMINT3 e1_B(int(m->rz), - int(m->gz | (m->gz4 << 4)), - int(m->bz | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4) | (m->bz5 << 5))); - - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 6); - e0_A.y = SIGN_EXTEND(e0_A.y, 6); - e0_A.z = SIGN_EXTEND(e0_A.z, 6); - - e0_B.x = SIGN_EXTEND(e0_B.x, 6); - e0_B.y = SIGN_EXTEND(e0_B.y, 6); - e0_B.z = SIGN_EXTEND(e0_B.z, 6); - - e1_A.x = SIGN_EXTEND(e1_A.x, 6); - e1_A.y = SIGN_EXTEND(e1_A.y, 6); - e1_A.z = SIGN_EXTEND(e1_A.z, 6); - - e1_B.x = SIGN_EXTEND(e1_B.x, 6); - e1_B.y = SIGN_EXTEND(e1_B.y, 6); - e1_B.z = SIGN_EXTEND(e1_B.z, 6); - } - - wprintf(L"\tMode 10 - [6 6 6 6] shape %llu\n", m->d); - wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); - wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex3bpp(m->indices, 1, m->d); - wprintf(L"\n"); - } - break; - - case 0x03: - // Mode 11 (5 bits, 00011) - { - struct bc6h_mode11 - { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} - uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} - uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} - uint64_t rx : 10; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}, {RX, 6}, {RX, 7}, {RX, 8}, {RX, 9} - uint64_t gx : 10; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}, {GX, 6}, {GX, 7}, {GX, 8}, {GX, 9} - uint64_t bx : 9; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}, {BX, 6}, {BX, 7}, {BX, 8} - uint64_t bx9 : 1; // {BX, 9} - uint64_t indices : 63; - }; - static_assert(sizeof(bc6h_mode11) == 16, "Block size must be 16 bytes"); - - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - - auto m = reinterpret_cast(sptr); - - XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); - XMINT3 e0_B(int(m->rx), int(m->gx), - int(m->bx | (m->bx9 << 9))); + int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4))); if (bSigned) { @@ -2672,181 +1937,917 @@ namespace e0_A.y = SIGN_EXTEND(e0_A.y, 10); e0_A.z = SIGN_EXTEND(e0_A.z, 10); - e0_B.x = SIGN_EXTEND(e0_B.x, 10); - e0_B.y = SIGN_EXTEND(e0_B.y, 10); - e0_B.z = SIGN_EXTEND(e0_B.z, 10); + e0_B.x = SIGN_EXTEND(e0_B.x, 5); + e0_B.y = SIGN_EXTEND(e0_B.y, 5); + e0_B.z = SIGN_EXTEND(e0_B.z, 5); + + e1_A.x = SIGN_EXTEND(e1_A.x, 5); + e1_A.y = SIGN_EXTEND(e1_A.y, 5); + e1_A.z = SIGN_EXTEND(e1_A.z, 5); + + e1_B.x = SIGN_EXTEND(e1_B.x, 5); + e1_B.y = SIGN_EXTEND(e1_B.y, 5); + e1_B.z = SIGN_EXTEND(e1_B.z, 5); } - wprintf(L"\tMode 11 - [10 10]\n"); - wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\tMode 1 - [10 5 5 5] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); wprintf(L"\t Index: "); - PrintIndex4bpp(m->indices, 0, 0); + PrintIndex3bpp(m->indices, 1, m->d); wprintf(L"\n"); } break; + case 0x01: + // Mode 2 (2 bits, 01) + { + struct bc6h_mode2 + { + uint64_t mode : 2; // { M, 0}, { M, 1} + uint64_t gy5 : 1; // {GY, 5} + uint64_t gz45 : 2; // {GZ, 4}, {GZ, 5} + uint64_t rw : 7; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6} + uint64_t bz : 2; // {BZ, 0}, {BZ, 1} + uint64_t by4 : 1; // {BY, 4}, + uint64_t gw : 7; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6} + uint64_t by5 : 1; // {BY, 5} + uint64_t bz2 : 1; // {BZ, 2} + uint64_t gy4 : 1; // {GY, 4} + uint64_t bw : 7; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6} + uint64_t bz3 : 1; // {BZ, 3} + uint64_t bz5 : 1; // {BZ, 5} + uint64_t bz4 : 1; // {BZ, 4} + uint64_t rx : 6; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5} + uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} + uint64_t gx : 6; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5} + uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} + uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5} + uint64_t by : 4; // {BY, 0}, {BY, 1}, {BY, 2}, {BY, 3} + uint64_t ry : 6; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, {RY, 5} + uint64_t rz : 6; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5}, + uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} + uint64_t indices : 46; + + }; + static_assert(sizeof(bc6h_mode2) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e1_A(int(m->ry), + int(m->gy | (m->gy4 << 4) | (m->gy5 << 5)), + int(m->by | (m->by4 << 4) | (m->by5 << 5))); + XMINT3 e1_B(int(m->rz), + int(m->gz | (m->gz45 << 4)), + int(m->bz | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4) | (m->bz5 << 5))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 7); + e0_A.y = SIGN_EXTEND(e0_A.y, 7); + e0_A.z = SIGN_EXTEND(e0_A.z, 7); + + e0_B.x = SIGN_EXTEND(e0_B.x, 6); + e0_B.y = SIGN_EXTEND(e0_B.y, 6); + e0_B.z = SIGN_EXTEND(e0_B.z, 6); + + e1_A.x = SIGN_EXTEND(e1_A.x, 6); + e1_A.y = SIGN_EXTEND(e1_A.y, 6); + e1_A.z = SIGN_EXTEND(e1_A.z, 6); + + e1_B.x = SIGN_EXTEND(e1_B.x, 6); + e1_B.y = SIGN_EXTEND(e1_B.y, 6); + e1_B.z = SIGN_EXTEND(e1_B.z, 6); + } + + wprintf(L"\tMode 2 - [7 6 6 6] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex3bpp(m->indices, 1, m->d); + wprintf(L"\n"); + } + break; + + default: + switch (*sptr & 0x1F) + { + case 0x02: + // Mode 3 (5 bits, 00010) + { + struct bc6h_mode3 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} + uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} + uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} + uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4} + uint64_t rw10 : 1; // {RW,10} + uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} + uint64_t gx : 4; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3} + uint64_t gw10 : 1; // {GW,10} + uint64_t bz0 : 1; // {BZ, 0} + uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} + uint64_t bx : 4; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3} + uint64_t bw10 : 1; // {BW,10} + uint64_t bz1 : 1; // {BZ, 1} + uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} + uint64_t by3 : 1; // {BY, 3} + uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4} + uint64_t bz2 : 1; // {BZ, 2} + uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4} + uint64_t bz3 : 1; // {BZ, 3} + uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} + uint64_t indices : 46; + + }; + static_assert(sizeof(bc6h_mode3) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw | (m->rw10 << 10)), + int(m->gw | (m->gw10 << 10)), + int(m->bw | (m->bw10 << 10))); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e1_A(int(m->ry), int(m->gy), + int(m->by | (m->by3 << 3))); + XMINT3 e1_B(int(m->rz), + int(m->gz), + int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 11); + e0_A.y = SIGN_EXTEND(e0_A.y, 11); + e0_A.z = SIGN_EXTEND(e0_A.z, 11); + + e0_B.x = SIGN_EXTEND(e0_B.x, 5); + e0_B.y = SIGN_EXTEND(e0_B.y, 4); + e0_B.z = SIGN_EXTEND(e0_B.z, 4); + + e1_A.x = SIGN_EXTEND(e1_A.x, 5); + e1_A.y = SIGN_EXTEND(e1_A.y, 4); + e1_A.z = SIGN_EXTEND(e1_A.z, 4); + + e1_B.x = SIGN_EXTEND(e1_B.x, 5); + e1_B.y = SIGN_EXTEND(e1_B.y, 4); + e1_B.z = SIGN_EXTEND(e1_B.z, 4); + } + + wprintf(L"\tMode 3 - [11 5 4 4] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex3bpp(m->indices, 1, m->d); + wprintf(L"\n"); + } + break; + + case 0x06: + // Mode 4 (5 bits, 00110) + { + struct bc6h_mode4 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} + uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} + uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} + uint64_t rx : 4; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3} + uint64_t rw10 : 1; // {RW,10} + uint64_t gz4 : 1; // {GZ, 4} + uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} + uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4} + uint64_t gw10 : 1; // {GW,10} + uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} + uint64_t bx : 4; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3} + uint64_t bw10 : 1; // {BW,10} + uint64_t bz1 : 1; // {BZ, 1} + uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} + uint64_t by3 : 1; // {BY, 3} + uint64_t ry : 4; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3} + uint64_t bz0 : 1; // {BZ, 0} + uint64_t bz2 : 1; // {BZ, 2} + uint64_t rz : 4; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3} + uint64_t gy4 : 1; // {GY, 4} + uint64_t bz3 : 1; // {BZ, 3} + uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} + uint64_t indices : 46; + + }; + static_assert(sizeof(bc6h_mode4) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw | (m->rw10 << 10)), + int(m->gw | (m->gw10 << 10)), + int(m->bw | (m->bw10 << 10))); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e1_A(int(m->ry), + int(m->gy | (m->gy4 << 4)), + int(m->by | (m->by3 << 3))); + XMINT3 e1_B(int(m->rz), + int(m->gz | (m->gz4 << 4)), + int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 11); + e0_A.y = SIGN_EXTEND(e0_A.y, 11); + e0_A.z = SIGN_EXTEND(e0_A.z, 11); + + e0_B.x = SIGN_EXTEND(e0_B.x, 4); + e0_B.y = SIGN_EXTEND(e0_B.y, 5); + e0_B.z = SIGN_EXTEND(e0_B.z, 4); + + e1_A.x = SIGN_EXTEND(e1_A.x, 4); + e1_A.y = SIGN_EXTEND(e1_A.y, 5); + e1_A.z = SIGN_EXTEND(e1_A.z, 4); + + e1_B.x = SIGN_EXTEND(e1_B.x, 4); + e1_B.y = SIGN_EXTEND(e1_B.y, 5); + e1_B.z = SIGN_EXTEND(e1_B.z, 4); + } + + wprintf(L"\tMode 4 - [11 4 5 4] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex3bpp(m->indices, 1, m->d); + wprintf(L"\n"); + } + break; + + case 0x0A: + // Mode 5 (5 bits, 01010) + { + struct bc6h_mode5 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} + uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} + uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} + uint64_t rx : 4; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3} + uint64_t rw10 : 1; // {RW,10} + uint64_t by4 : 1; // {BY, 4} + uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} + uint64_t gx : 4; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3} + uint64_t gw10 : 1; // {GW,10} + uint64_t bz0 : 1; // {BZ, 0} + uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} + uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4} + uint64_t bw10 : 1; // {BW,10} + uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} + uint64_t by3 : 1; // {BY, 3} + uint64_t ry : 4; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3} + uint64_t bz12 : 2; // {BZ, 1}, {BZ, 2} + uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {BZ, 4} + uint64_t bz3 : 1; // {BZ, 3} + uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} + uint64_t indices : 46; + }; + static_assert(sizeof(bc6h_mode5) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw | (m->rw10 << 10)), + int(m->gw | (m->gw10 << 10)), + int(m->bw | (m->bw10 << 10))); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e1_A(int(m->ry), int(m->gy), + int(m->by | (m->by3 << 3) | (m->by4 << 4))); + XMINT3 e1_B(int(m->rz), int(m->gz), + int(m->bz0 | (m->bz12 << 1) | (m->bz3 << 3))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 11); + e0_A.y = SIGN_EXTEND(e0_A.y, 11); + e0_A.z = SIGN_EXTEND(e0_A.z, 11); + + e0_B.x = SIGN_EXTEND(e0_B.x, 4); + e0_B.y = SIGN_EXTEND(e0_B.y, 4); + e0_B.z = SIGN_EXTEND(e0_B.z, 5); + + e1_A.x = SIGN_EXTEND(e1_A.x, 4); + e1_A.y = SIGN_EXTEND(e1_A.y, 4); + e1_A.z = SIGN_EXTEND(e1_A.z, 5); + + e1_B.x = SIGN_EXTEND(e1_B.x, 4); + e1_B.y = SIGN_EXTEND(e1_B.y, 4); + e1_B.z = SIGN_EXTEND(e1_B.z, 5); + } + + wprintf(L"\tMode 5 - [11 4 4 5] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex3bpp(m->indices, 1, m->d); + wprintf(L"\n"); + } + break; + + case 0x0E: + // Mode 6 (5 bits, 01110) + { + struct bc6h_mode6 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 9; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8} + uint64_t by4 : 1; // {BY, 4} + uint64_t gw : 9; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8} + uint64_t gy4 : 1; // {GY, 4} + uint64_t bw : 9; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8} + uint64_t bz4 : 1; // {BZ, 4} + uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4} + uint64_t gz4 : 1; // {GZ, 4} + uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} + uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4} + uint64_t bz0 : 1; // {BZ, 0} + uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} + uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4} + uint64_t bz1 : 1; // {BZ, 1} + uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} + uint64_t by3 : 1; // {BY, 3} + uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, + uint64_t bz2 : 1; // {BZ, 2} + uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {BZ, 4} + uint64_t bz3 : 1; // {BZ, 3} + uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} + uint64_t indices : 46; + }; + static_assert(sizeof(bc6h_mode6) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e1_A(int(m->ry), + int(m->gy | (m->gy4 << 4)), + int(m->by | (m->by3 << 3) | (m->by4 << 4))); + XMINT3 e1_B(int(m->rz), + int(m->gz | (m->gz4 << 4)), + int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 9); + e0_A.y = SIGN_EXTEND(e0_A.y, 9); + e0_A.z = SIGN_EXTEND(e0_A.z, 9); + + e0_B.x = SIGN_EXTEND(e0_B.x, 5); + e0_B.y = SIGN_EXTEND(e0_B.y, 5); + e0_B.z = SIGN_EXTEND(e0_B.z, 5); + + e1_A.x = SIGN_EXTEND(e1_A.x, 5); + e1_A.y = SIGN_EXTEND(e1_A.y, 5); + e1_A.z = SIGN_EXTEND(e1_A.z, 5); + + e1_B.x = SIGN_EXTEND(e1_B.x, 5); + e1_B.y = SIGN_EXTEND(e1_B.y, 5); + e1_B.z = SIGN_EXTEND(e1_B.z, 5); + } + + wprintf(L"\tMode 6 - [9 5 5 5] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex3bpp(m->indices, 1, m->d); + wprintf(L"\n"); + } + break; + + case 0x12: + // Mode 7 (5 bits, 10010) + { + struct bc6h_mode7 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 8; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7} + uint64_t gz4 : 1; // {GZ, 4} + uint64_t by4 : 1; // {BY, 4} + uint64_t gw : 8; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7} + uint64_t bz2 : 1; // {BZ, 2} + uint64_t gy4 : 1; // {GY, 4} + uint64_t bw : 8; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7} + uint64_t bz3 : 1; // {BZ, 3} + uint64_t bz4 : 1; // {BZ, 4} + uint64_t rx : 6; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5} + uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} + uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4} + uint64_t bz0 : 1; // {BZ, 0} + uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} + uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4} + uint64_t bz1 : 1; // {BZ, 1} + uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} + uint64_t by3 : 1; // {BY, 3} + uint64_t ry : 6; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, {RY, 5} + uint64_t rz : 6; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5} + uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} + uint64_t indices : 46; + }; + static_assert(sizeof(bc6h_mode7) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e1_A(int(m->ry), + int(m->gy | (m->gy4 << 4)), + int(m->by | (m->by3 << 3) | (m->by4 << 4))); + XMINT3 e1_B(int(m->rz), + int(m->gz | (m->gz4 << 4)), + int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 8); + e0_A.y = SIGN_EXTEND(e0_A.y, 8); + e0_A.z = SIGN_EXTEND(e0_A.z, 8); + + e0_B.x = SIGN_EXTEND(e0_B.x, 6); + e0_B.y = SIGN_EXTEND(e0_B.y, 5); + e0_B.z = SIGN_EXTEND(e0_B.z, 5); + + e1_A.x = SIGN_EXTEND(e1_A.x, 6); + e1_A.y = SIGN_EXTEND(e1_A.y, 5); + e1_A.z = SIGN_EXTEND(e1_A.z, 5); + + e1_B.x = SIGN_EXTEND(e1_B.x, 6); + e1_B.y = SIGN_EXTEND(e1_B.y, 5); + e1_B.z = SIGN_EXTEND(e1_B.z, 5); + } + + wprintf(L"\tMode 7 - [8 6 5 5] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex3bpp(m->indices, 1, m->d); + wprintf(L"\n"); + } + break; + + case 0x16: + // Mode 8 (5 bits, 10110) + { + struct bc6h_mode8 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 8; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7} + uint64_t bz0 : 1; // {BZ, 0} + uint64_t by4 : 1; // {BY, 4} + uint64_t gw : 8; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7} + uint64_t gy5 : 1; // {GY, 5} + uint64_t gy4 : 1; // {GY, 4} + uint64_t bw : 8; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7} + uint64_t gz5 : 1; // {GZ, 5} + uint64_t bz4 : 1; // {BZ, 4} + uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4} + uint64_t gz4 : 1; // {GZ, 4} + uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} + uint64_t gx : 6; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5} + uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} + uint64_t bx : 5; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4} + uint64_t bz1 : 1; // {BZ, 1} + uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} + uint64_t by3 : 1; // {BY, 3} + uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4} + uint64_t bz2 : 1; // {BZ, 2} + uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4} + uint64_t bz3 : 1; // {BZ, 3} + uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} + uint64_t indices : 46; + }; + static_assert(sizeof(bc6h_mode8) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e1_A(int(m->ry), + int(m->gy | (m->gy4 << 4) | (m->gy5 << 5)), + int(m->by | (m->by3 << 3) | (m->by4 << 4))); + XMINT3 e1_B(int(m->rz), + int(m->gz | (m->gz4 << 4) | (m->gz5 << 5)), + int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 8); + e0_A.y = SIGN_EXTEND(e0_A.y, 8); + e0_A.z = SIGN_EXTEND(e0_A.z, 8); + + e0_B.x = SIGN_EXTEND(e0_B.x, 5); + e0_B.y = SIGN_EXTEND(e0_B.y, 6); + e0_B.z = SIGN_EXTEND(e0_B.z, 5); + + e1_A.x = SIGN_EXTEND(e1_A.x, 5); + e1_A.y = SIGN_EXTEND(e1_A.y, 6); + e1_A.z = SIGN_EXTEND(e1_A.z, 5); + + e1_B.x = SIGN_EXTEND(e1_B.x, 5); + e1_B.y = SIGN_EXTEND(e1_B.y, 6); + e1_B.z = SIGN_EXTEND(e1_B.z, 5); + } + + wprintf(L"\tMode 8 - [8 5 6 5] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex3bpp(m->indices, 1, m->d); + wprintf(L"\n"); + } + break; + + case 0x1A: + // Mode 9 (5 bits, 11010) + { + struct bc6h_mode9 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 8; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7} + uint64_t bz1 : 1; // {BZ, 1} + uint64_t by4 : 1; // {BY, 4} + uint64_t gw : 8; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7} + uint64_t by5 : 1; // {BY, 5} + uint64_t gy4 : 1; // {GY, 4} + uint64_t bw : 8; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7} + uint64_t bz5 : 1; // {BZ, 5} + uint64_t bz4 : 1; // {BZ, 4} + uint64_t rx : 5; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4} + uint64_t gz4 : 1; // {GZ, 4} + uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} + uint64_t gx : 5; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4} + uint64_t bz0 : 1; // {BZ, 0} + uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} + uint64_t bx : 6; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5} + uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} + uint64_t by3 : 1; // {BY, 3} + uint64_t ry : 5; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4} + uint64_t bz2 : 1; // {BZ, 2} + uint64_t rz : 5; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4} + uint64_t bz3 : 1; // {BZ, 3} + uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} + uint64_t indices : 46; + }; + static_assert(sizeof(bc6h_mode9) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e1_A(int(m->ry), + int(m->gy | (m->gy4 << 4)), + int(m->by | (m->by3 << 3) | (m->by4 << 4) | (m->by5 << 5))); + XMINT3 e1_B(int(m->rz), + int(m->gz | (m->gz4 << 4)), + int(m->bz0 | (m->bz1 << 1) | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4) | (m->bz5 << 5))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 8); + e0_A.y = SIGN_EXTEND(e0_A.y, 8); + e0_A.z = SIGN_EXTEND(e0_A.z, 8); + + e0_B.x = SIGN_EXTEND(e0_B.x, 5); + e0_B.y = SIGN_EXTEND(e0_B.y, 5); + e0_B.z = SIGN_EXTEND(e0_B.z, 6); + + e1_A.x = SIGN_EXTEND(e1_A.x, 5); + e1_A.y = SIGN_EXTEND(e1_A.y, 5); + e1_A.z = SIGN_EXTEND(e1_A.z, 6); + + e1_B.x = SIGN_EXTEND(e1_B.x, 5); + e1_B.y = SIGN_EXTEND(e1_B.y, 5); + e1_B.z = SIGN_EXTEND(e1_B.z, 6); + } + + wprintf(L"\tMode 9 - [8 5 5 6] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex3bpp(m->indices, 1, m->d); + wprintf(L"\n"); + } + break; + + case 0x1E: + // Mode 10 (5 bits, 11110) + { + struct bc6h_mode10 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 6; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5} + uint64_t gz4 : 1; // {GZ, 4} + uint64_t bz : 2; // {BZ, 0}, {BZ, 1} + uint64_t by4 : 1; // {BY, 4} + uint64_t gw : 6; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5} + uint64_t gy5 : 1; // {GY, 5} + uint64_t by5 : 1; // {BY, 5} + uint64_t bz2 : 1; // {BZ, 2} + uint64_t gy4 : 1; // {GY, 4} + uint64_t bw : 6; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {GZ, 5} + uint64_t bz3 : 1; // {BZ, 3} + uint64_t bz5 : 1; // {BZ, 5} + uint64_t bz4 : 1; // {BZ, 4} + uint64_t rx : 6; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5} + uint64_t gy : 4; // {GY, 0}, {GY, 1}, {GY, 2}, {GY, 3} + uint64_t gx : 6; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5} + uint64_t gz : 4; // {GZ, 0}, {GZ, 1}, {GZ, 2}, {GZ, 3} + uint64_t bx : 6; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5} + uint64_t by : 3; // {BY, 0}, {BY, 1}, {BY, 2} + uint64_t by3 : 1; // {BY, 3} + uint64_t ry : 6; // {RY, 0}, {RY, 1}, {RY, 2}, {RY, 3}, {RY, 4}, {RY, 5} + uint64_t rz : 6; // {RZ, 0}, {RZ, 1}, {RZ, 2}, {RZ, 3}, {RZ, 4}, {RZ, 5} + uint64_t d : 5; // { D, 0}, { D, 1}, { D, 2}, { D, 3}, { D, 4} + uint64_t indices : 46; + }; + static_assert(sizeof(bc6h_mode10) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e1_A(int(m->ry), + int(m->gy | (m->gy4 << 4) | (m->gy5 << 5)), + int(m->by | (m->by3 << 3) | (m->by4 << 4) | (m->by5 << 5))); + XMINT3 e1_B(int(m->rz), + int(m->gz | (m->gz4 << 4)), + int(m->bz | (m->bz2 << 2) | (m->bz3 << 3) | (m->bz4 << 4) | (m->bz5 << 5))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 6); + e0_A.y = SIGN_EXTEND(e0_A.y, 6); + e0_A.z = SIGN_EXTEND(e0_A.z, 6); + + e0_B.x = SIGN_EXTEND(e0_B.x, 6); + e0_B.y = SIGN_EXTEND(e0_B.y, 6); + e0_B.z = SIGN_EXTEND(e0_B.z, 6); + + e1_A.x = SIGN_EXTEND(e1_A.x, 6); + e1_A.y = SIGN_EXTEND(e1_A.y, 6); + e1_A.z = SIGN_EXTEND(e1_A.z, 6); + + e1_B.x = SIGN_EXTEND(e1_B.x, 6); + e1_B.y = SIGN_EXTEND(e1_B.y, 6); + e1_B.z = SIGN_EXTEND(e1_B.z, 6); + } + + wprintf(L"\tMode 10 - [6 6 6 6] shape %llu\n", m->d); + wprintf(L"\t E0(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E0(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t E1(A): (%04X, %04X, %04X)\n", e1_A.x & 0xFFFF, e1_A.y & 0xFFFF, e1_A.z & 0xFFFF); + wprintf(L"\t E1(B): (%04X, %04X, %04X)\n", e1_B.x & 0xFFFF, e1_B.y & 0xFFFF, e1_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex3bpp(m->indices, 1, m->d); + wprintf(L"\n"); + } + break; + + case 0x03: + // Mode 11 (5 bits, 00011) + { + struct bc6h_mode11 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} + uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} + uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} + uint64_t rx : 10; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}, {RX, 6}, {RX, 7}, {RX, 8}, {RX, 9} + uint64_t gx : 10; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}, {GX, 6}, {GX, 7}, {GX, 8}, {GX, 9} + uint64_t bx : 9; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}, {BX, 6}, {BX, 7}, {BX, 8} + uint64_t bx9 : 1; // {BX, 9} + uint64_t indices : 63; + }; + static_assert(sizeof(bc6h_mode11) == 16, "Block size must be 16 bytes"); + + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + + auto m = reinterpret_cast(sptr); + + XMINT3 e0_A(int(m->rw), int(m->gw), int(m->bw)); + XMINT3 e0_B(int(m->rx), int(m->gx), + int(m->bx | (m->bx9 << 9))); + + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 10); + e0_A.y = SIGN_EXTEND(e0_A.y, 10); + e0_A.z = SIGN_EXTEND(e0_A.z, 10); + + e0_B.x = SIGN_EXTEND(e0_B.x, 10); + e0_B.y = SIGN_EXTEND(e0_B.y, 10); + e0_B.z = SIGN_EXTEND(e0_B.z, 10); + } + + wprintf(L"\tMode 11 - [10 10]\n"); + wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex4bpp(m->indices, 0, 0); + wprintf(L"\n"); + } + break; + case 0x07: // Mode 12 (5 bits, 00111) - { - struct bc6h_mode12 { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} - uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} - uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} - uint64_t rx : 9; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}, {RX, 6}, {RX, 7}, {RX, 8} - uint64_t rw10 : 1; // {RW,10} - uint64_t gx : 9; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}, {GX, 6}, {GX, 7}, {GX, 8} - uint64_t gw10 : 1; // {GW,10} - uint64_t bx : 9; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}, {BX, 6}, {BX, 7}, {BX, 8} - uint64_t bw10 : 1; // {BW,10} - uint64_t indices : 63; - }; - static_assert(sizeof(bc6h_mode12) == 16, "Block size must be 16 bytes"); + struct bc6h_mode12 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} + uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} + uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} + uint64_t rx : 9; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}, {RX, 6}, {RX, 7}, {RX, 8} + uint64_t rw10 : 1; // {RW,10} + uint64_t gx : 9; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}, {GX, 6}, {GX, 7}, {GX, 8} + uint64_t gw10 : 1; // {GW,10} + uint64_t bx : 9; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}, {BX, 6}, {BX, 7}, {BX, 8} + uint64_t bw10 : 1; // {BW,10} + uint64_t indices : 63; + }; + static_assert(sizeof(bc6h_mode12) == 16, "Block size must be 16 bytes"); - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - auto m = reinterpret_cast(sptr); + auto m = reinterpret_cast(sptr); - XMINT3 e0_A(int(m->rw | (m->rw10 << 10)), - int(m->gw | (m->gw10 << 10)), - int(m->bw | (m->bw10 << 10))); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e0_A(int(m->rw | (m->rw10 << 10)), + int(m->gw | (m->gw10 << 10)), + int(m->bw | (m->bw10 << 10))); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 11); - e0_A.y = SIGN_EXTEND(e0_A.y, 11); - e0_A.z = SIGN_EXTEND(e0_A.z, 11); + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 11); + e0_A.y = SIGN_EXTEND(e0_A.y, 11); + e0_A.z = SIGN_EXTEND(e0_A.z, 11); - e0_B.x = SIGN_EXTEND(e0_B.x, 9); - e0_B.y = SIGN_EXTEND(e0_B.y, 9); - e0_B.z = SIGN_EXTEND(e0_B.z, 9); + e0_B.x = SIGN_EXTEND(e0_B.x, 9); + e0_B.y = SIGN_EXTEND(e0_B.y, 9); + e0_B.z = SIGN_EXTEND(e0_B.z, 9); + } + + wprintf(L"\tMode 12 - [11 9]\n"); + wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex4bpp(m->indices, 0, 0); + wprintf(L"\n"); } - - wprintf(L"\tMode 12 - [11 9]\n"); - wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex4bpp(m->indices, 0, 0); - wprintf(L"\n"); - } - break; + break; case 0x0B: // Mode 13 (5 bits, 01011) - { - struct bc6h_mode13 { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} - uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} - uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} - uint64_t rx : 8; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}, {RX, 6}, {RX, 7} - uint64_t rw11 : 1; // {RW,11} - uint64_t rw10 : 1; // {RW,10} - uint64_t gx : 8; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}, {GX, 6}, {GX, 7} - uint64_t gw11 : 1; // {GW,11} - uint64_t gw10 : 1; // {GW,10} - uint64_t bx : 8; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}, {BX, 6}, {BX, 7} - uint64_t bw11 : 1; // {BW,11} - uint64_t bw10 : 1; // {BW,10} - uint64_t indices : 63; - }; - static_assert(sizeof(bc6h_mode13) == 16, "Block size must be 16 bytes"); + struct bc6h_mode13 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} + uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} + uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} + uint64_t rx : 8; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3}, {RX, 4}, {RX, 5}, {RX, 6}, {RX, 7} + uint64_t rw11 : 1; // {RW,11} + uint64_t rw10 : 1; // {RW,10} + uint64_t gx : 8; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3}, {GX, 4}, {GX, 5}, {GX, 6}, {GX, 7} + uint64_t gw11 : 1; // {GW,11} + uint64_t gw10 : 1; // {GW,10} + uint64_t bx : 8; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3}, {BX, 4}, {BX, 5}, {BX, 6}, {BX, 7} + uint64_t bw11 : 1; // {BW,11} + uint64_t bw10 : 1; // {BW,10} + uint64_t indices : 63; + }; + static_assert(sizeof(bc6h_mode13) == 16, "Block size must be 16 bytes"); - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - auto m = reinterpret_cast(sptr); + auto m = reinterpret_cast(sptr); - XMINT3 e0_A(int(m->rw | (m->rw10 << 10) | (m->rw11 << 11)), - int(m->gw | (m->gw10 << 10) | (m->gw11 << 11)), - int(m->bw | (m->bw10 << 10) | (m->bw11 << 11))); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e0_A(int(m->rw | (m->rw10 << 10) | (m->rw11 << 11)), + int(m->gw | (m->gw10 << 10) | (m->gw11 << 11)), + int(m->bw | (m->bw10 << 10) | (m->bw11 << 11))); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 12); - e0_A.y = SIGN_EXTEND(e0_A.y, 12); - e0_A.z = SIGN_EXTEND(e0_A.z, 12); + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 12); + e0_A.y = SIGN_EXTEND(e0_A.y, 12); + e0_A.z = SIGN_EXTEND(e0_A.z, 12); - e0_B.x = SIGN_EXTEND(e0_B.x, 8); - e0_B.y = SIGN_EXTEND(e0_B.y, 8); - e0_B.z = SIGN_EXTEND(e0_B.z, 8); + e0_B.x = SIGN_EXTEND(e0_B.x, 8); + e0_B.y = SIGN_EXTEND(e0_B.y, 8); + e0_B.z = SIGN_EXTEND(e0_B.z, 8); + } + + wprintf(L"\tMode 13 - [12 8]\n"); + wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex4bpp(m->indices, 0, 0); + wprintf(L"\n"); } - - wprintf(L"\tMode 13 - [12 8]\n"); - wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex4bpp(m->indices, 0, 0); - wprintf(L"\n"); - } - break; + break; case 0x0F: // Mode 14 (5 bits, 01111) - { - struct bc6h_mode14 { - uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} - uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} - uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} - uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} - uint64_t rx : 4; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3} - uint64_t rw15 : 1; // {RW,15} - uint64_t rw14 : 1; // {RW,14} - uint64_t rw13 : 1; // {RW,13} - uint64_t rw12 : 1; // {RW,12} - uint64_t rw11 : 1; // {RW,11} - uint64_t rw10 : 1; // {RW,10} - uint64_t gx : 4; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3} - uint64_t gw15 : 1; // {GW,15} - uint64_t gw14 : 1; // {GW,14} - uint64_t gw13 : 1; // {GW,13} - uint64_t gw12 : 1; // {GW,12} - uint64_t gw11 : 1; // {GW,11} - uint64_t gw10 : 1; // {GW,10} - uint64_t bx : 4; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3} - uint64_t bw15 : 1; // {BW,15} - uint64_t bw14 : 1; // {BW,14} - uint64_t bw13 : 1; // {BW,13} - uint64_t bw12 : 1; // {BW,12} - uint64_t bw11 : 1; // {BW,11} - uint64_t bw10 : 1; // {BW,10} - uint64_t indices : 63; - }; - static_assert(sizeof(bc6h_mode14) == 16, "Block size must be 16 bytes"); + struct bc6h_mode14 + { + uint64_t mode : 5; // { M, 0}, { M, 1}, { M, 2}, { M, 3}, { M, 4} + uint64_t rw : 10; // {RW, 0}, {RW, 1}, {RW, 2}, {RW, 3}, {RW, 4}, {RW, 5}, {RW, 6}, {RW, 7}, {RW, 8}, {RW, 9} + uint64_t gw : 10; // {GW, 0}, {GW, 1}, {GW, 2}, {GW, 3}, {GW, 4}, {GW, 5}, {GW, 6}, {GW, 7}, {GW, 8}, {GW, 9} + uint64_t bw : 10; // {BW, 0}, {BW, 1}, {BW, 2}, {BW, 3}, {BW, 4}, {BW, 5}, {BW, 6}, {BW, 7}, {BW, 8}, {BW, 9} + uint64_t rx : 4; // {RX, 0}, {RX, 1}, {RX, 2}, {RX, 3} + uint64_t rw15 : 1; // {RW,15} + uint64_t rw14 : 1; // {RW,14} + uint64_t rw13 : 1; // {RW,13} + uint64_t rw12 : 1; // {RW,12} + uint64_t rw11 : 1; // {RW,11} + uint64_t rw10 : 1; // {RW,10} + uint64_t gx : 4; // {GX, 0}, {GX, 1}, {GX, 2}, {GX, 3} + uint64_t gw15 : 1; // {GW,15} + uint64_t gw14 : 1; // {GW,14} + uint64_t gw13 : 1; // {GW,13} + uint64_t gw12 : 1; // {GW,12} + uint64_t gw11 : 1; // {GW,11} + uint64_t gw10 : 1; // {GW,10} + uint64_t bx : 4; // {BX, 0}, {BX, 1}, {BX, 2}, {BX, 3} + uint64_t bw15 : 1; // {BW,15} + uint64_t bw14 : 1; // {BW,14} + uint64_t bw13 : 1; // {BW,13} + uint64_t bw12 : 1; // {BW,12} + uint64_t bw11 : 1; // {BW,11} + uint64_t bw10 : 1; // {BW,10} + uint64_t indices : 63; + }; + static_assert(sizeof(bc6h_mode14) == 16, "Block size must be 16 bytes"); - const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; + const bool bSigned = (image.format == DXGI_FORMAT_BC6H_SF16) ? true : false; - auto m = reinterpret_cast(sptr); + auto m = reinterpret_cast(sptr); - XMINT3 e0_A(int(m->rw | (m->rw10 << 10) | (m->rw11 << 11) | (m->rw12 << 12) | (m->rw13 << 13) | (m->rw14 << 14) | (m->rw15 << 15)), - int(m->gw | (m->gw10 << 10) | (m->gw11 << 11) | (m->gw12 << 12) | (m->gw13 << 13) | (m->gw14 << 14) | (m->gw15 << 15)), - int(m->bw | (m->bw10 << 10) | (m->bw11 << 11) | (m->bw12 << 12) | (m->bw13 << 13) | (m->bw14 << 14) | (m->bw15 << 15))); - XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); + XMINT3 e0_A(int(m->rw | (m->rw10 << 10) | (m->rw11 << 11) | (m->rw12 << 12) | (m->rw13 << 13) | (m->rw14 << 14) | (m->rw15 << 15)), + int(m->gw | (m->gw10 << 10) | (m->gw11 << 11) | (m->gw12 << 12) | (m->gw13 << 13) | (m->gw14 << 14) | (m->gw15 << 15)), + int(m->bw | (m->bw10 << 10) | (m->bw11 << 11) | (m->bw12 << 12) | (m->bw13 << 13) | (m->bw14 << 14) | (m->bw15 << 15))); + XMINT3 e0_B(int(m->rx), int(m->gx), int(m->bx)); - if (bSigned) - { - e0_A.x = SIGN_EXTEND(e0_A.x, 16); - e0_A.y = SIGN_EXTEND(e0_A.y, 16); - e0_A.z = SIGN_EXTEND(e0_A.z, 16); + if (bSigned) + { + e0_A.x = SIGN_EXTEND(e0_A.x, 16); + e0_A.y = SIGN_EXTEND(e0_A.y, 16); + e0_A.z = SIGN_EXTEND(e0_A.z, 16); - e0_B.x = SIGN_EXTEND(e0_B.x, 4); - e0_B.y = SIGN_EXTEND(e0_B.y, 4); - e0_B.z = SIGN_EXTEND(e0_B.z, 4); + e0_B.x = SIGN_EXTEND(e0_B.x, 4); + e0_B.y = SIGN_EXTEND(e0_B.y, 4); + e0_B.z = SIGN_EXTEND(e0_B.z, 4); + } + + wprintf(L"\tMode 14 - [16 4]\n"); + wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); + wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); + wprintf(L"\t Index: "); + PrintIndex4bpp(m->indices, 0, 0); + wprintf(L"\n"); } - - wprintf(L"\tMode 14 - [16 4]\n"); - wprintf(L"\t E(A): (%04X, %04X, %04X)\n", e0_A.x & 0xFFFF, e0_A.y & 0xFFFF, e0_A.z & 0xFFFF); - wprintf(L"\t E(B): (%04X, %04X, %04X)\n", e0_B.x & 0xFFFF, e0_B.y & 0xFFFF, e0_B.z & 0xFFFF); - wprintf(L"\t Index: "); - PrintIndex4bpp(m->indices, 0, 0); - wprintf(L"\n"); - } - break; + break; case 0x13: // Reserved mode (5 bits, 10011) wprintf(L"\tERROR - Reserved mode 10011\n"); @@ -3209,6 +3210,7 @@ namespace return S_OK; } +#pragma endregion } @@ -3437,19 +3439,19 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[]) break; case OPT_FILELIST: - { - std::wifstream inFile(pValue); - if (!inFile) { - wprintf(L"Error opening -flist file %ls\n", pValue); - return 1; + std::wifstream inFile(pValue); + if (!inFile) + { + wprintf(L"Error opening -flist file %ls\n", pValue); + return 1; + } + + inFile.imbue(std::locale::classic()); + + ProcessFileList(inFile, conversion); } - - inFile.imbue(std::locale::classic()); - - ProcessFileList(inFile, conversion); - } - break; + break; default: break; diff --git a/WICTextureLoader/WICTextureLoader11.cpp b/WICTextureLoader/WICTextureLoader11.cpp index b72a07f..5f9b0fc 100644 --- a/WICTextureLoader/WICTextureLoader11.cpp +++ b/WICTextureLoader/WICTextureLoader11.cpp @@ -65,12 +65,12 @@ namespace template 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); -#else + #else UNREFERENCED_PARAMETER(resource); UNREFERENCED_PARAMETER(name); -#endif + #endif } //------------------------------------------------------------------------------------- @@ -116,7 +116,7 @@ namespace 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). @@ -180,7 +180,7 @@ namespace 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( CLSID_WICImagingFactory2, nullptr, @@ -206,14 +206,14 @@ namespace ); return SUCCEEDED(hr) ? TRUE : FALSE; } -#else + #else return SUCCEEDED(CoCreateInstance( CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWICImagingFactory), ifactory)) ? TRUE : FALSE; -#endif + #endif } IWICImagingFactory* GetWIC() noexcept @@ -242,13 +242,13 @@ namespace 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 (memcmp(&GUID_WICPixelFormat96bppRGBFloat, &guid, sizeof(GUID)) == 0) return DXGI_FORMAT_R32G32B32_FLOAT; } -#endif + #endif return DXGI_FORMAT_UNKNOWN; } @@ -454,7 +454,7 @@ namespace { 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) { memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat96bppRGBFloat, sizeof(GUID)); @@ -462,7 +462,7 @@ namespace bpp = 96; } else -#endif + #endif { memcpy_s(&convertGUID, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat128bppRGBAFloat, sizeof(GUID)); format = DXGI_FORMAT_R32G32B32A32_FLOAT; @@ -493,7 +493,7 @@ namespace 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) { // Special case test for optional device support for autogen mipchains for R32G32B32_FLOAT @@ -507,7 +507,7 @@ namespace bpp = 128; } } -#endif + #endif if (loadFlags & WIC_LOADER_FORCE_RGBA32) { @@ -773,7 +773,7 @@ namespace _In_opt_ ID3D11Resource** texture, _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) { CHAR strFileA[MAX_PATH]; @@ -815,11 +815,11 @@ namespace } } } -#else + #else UNREFERENCED_PARAMETER(fileName); UNREFERENCED_PARAMETER(texture); UNREFERENCED_PARAMETER(textureView); -#endif + #endif } } // anonymous namespace diff --git a/WICTextureLoader/WICTextureLoader11.h b/WICTextureLoader/WICTextureLoader11.h index 54876ee..151da38 100644 --- a/WICTextureLoader/WICTextureLoader11.h +++ b/WICTextureLoader/WICTextureLoader11.h @@ -37,12 +37,12 @@ namespace DirectX #define WIC_LOADER_FLAGS_DEFINED enum WIC_LOADER_FLAGS : uint32_t { - WIC_LOADER_DEFAULT = 0, - WIC_LOADER_FORCE_SRGB = 0x1, - WIC_LOADER_IGNORE_SRGB = 0x2, + WIC_LOADER_DEFAULT = 0, + WIC_LOADER_FORCE_SRGB = 0x1, + WIC_LOADER_IGNORE_SRGB = 0x2, WIC_LOADER_SRGB_DEFAULT = 0x4, - WIC_LOADER_FIT_POW2 = 0x20, - WIC_LOADER_MAKE_SQUARE = 0x40, + WIC_LOADER_FIT_POW2 = 0x20, + WIC_LOADER_MAKE_SQUARE = 0x40, WIC_LOADER_FORCE_RGBA32 = 0x80, }; diff --git a/WICTextureLoader/WICTextureLoader12.cpp b/WICTextureLoader/WICTextureLoader12.cpp index 4246a91..f36cb0e 100644 --- a/WICTextureLoader/WICTextureLoader12.cpp +++ b/WICTextureLoader/WICTextureLoader12.cpp @@ -107,7 +107,7 @@ namespace 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). @@ -198,12 +198,12 @@ namespace template inline void SetDebugObjectName(_In_ ID3D12DeviceChild* resource, _In_z_ const wchar_t(&name)[TNameLength]) noexcept { - #if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) - resource->SetName(name); - #else - UNREFERENCED_PARAMETER(resource); - UNREFERENCED_PARAMETER(name); - #endif + #if !defined(NO_D3D12_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) + resource->SetName(name); + #else + UNREFERENCED_PARAMETER(resource); + UNREFERENCED_PARAMETER(name); + #endif } inline uint32_t CountMips(uint32_t width, uint32_t height) noexcept @@ -634,7 +634,7 @@ namespace _In_z_ const wchar_t* fileName, _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) { const wchar_t* pstrName = wcsrchr(fileName, '\\'); @@ -649,10 +649,10 @@ namespace (*texture)->SetName(pstrName); } -#else + #else UNREFERENCED_PARAMETER(fileName); UNREFERENCED_PARAMETER(texture); -#endif + #endif } } // anonymous namespace diff --git a/WICTextureLoader/WICTextureLoader12.h b/WICTextureLoader/WICTextureLoader12.h index 17ac216..6960edd 100644 --- a/WICTextureLoader/WICTextureLoader12.h +++ b/WICTextureLoader/WICTextureLoader12.h @@ -36,14 +36,14 @@ namespace DirectX #define WIC_LOADER_FLAGS_DEFINED enum WIC_LOADER_FLAGS : uint32_t { - WIC_LOADER_DEFAULT = 0, - WIC_LOADER_FORCE_SRGB = 0x1, - WIC_LOADER_IGNORE_SRGB = 0x2, + WIC_LOADER_DEFAULT = 0, + WIC_LOADER_FORCE_SRGB = 0x1, + WIC_LOADER_IGNORE_SRGB = 0x2, WIC_LOADER_SRGB_DEFAULT = 0x4, - WIC_LOADER_MIP_AUTOGEN = 0x8, - WIC_LOADER_MIP_RESERVE = 0x10, - WIC_LOADER_FIT_POW2 = 0x20, - WIC_LOADER_MAKE_SQUARE = 0x40, + WIC_LOADER_MIP_AUTOGEN = 0x8, + WIC_LOADER_MIP_RESERVE = 0x10, + WIC_LOADER_FIT_POW2 = 0x20, + WIC_LOADER_MAKE_SQUARE = 0x40, WIC_LOADER_FORCE_RGBA32 = 0x80, }; diff --git a/WICTextureLoader/WICTextureLoader9.cpp b/WICTextureLoader/WICTextureLoader9.cpp index b53a767..e7b2a62 100644 --- a/WICTextureLoader/WICTextureLoader9.cpp +++ b/WICTextureLoader/WICTextureLoader9.cpp @@ -95,7 +95,7 @@ namespace 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). @@ -161,7 +161,7 @@ namespace //-------------------------------------------------------------------------------------- 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( CLSID_WICImagingFactory2, nullptr, @@ -187,14 +187,14 @@ namespace ); return SUCCEEDED(hr) ? TRUE : FALSE; } -#else + #else return SUCCEEDED(CoCreateInstance( CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWICImagingFactory), ifactory)) ? TRUE : FALSE; -#endif + #endif } IWICImagingFactory* GetWIC() noexcept diff --git a/WICTextureLoader/WICTextureLoader9.h b/WICTextureLoader/WICTextureLoader9.h index 465d8a5..cee2ef6 100644 --- a/WICTextureLoader/WICTextureLoader9.h +++ b/WICTextureLoader/WICTextureLoader9.h @@ -35,10 +35,10 @@ namespace DirectX #define WIC_LOADER_FLAGS_DEFINED enum WIC_LOADER_FLAGS : uint32_t { - WIC_LOADER_DEFAULT = 0, - WIC_LOADER_MIP_AUTOGEN = 0x8, - WIC_LOADER_FIT_POW2 = 0x20, - WIC_LOADER_MAKE_SQUARE = 0x40, + WIC_LOADER_DEFAULT = 0, + WIC_LOADER_MIP_AUTOGEN = 0x8, + WIC_LOADER_FIT_POW2 = 0x20, + WIC_LOADER_MAKE_SQUARE = 0x40, WIC_LOADER_FORCE_RGBA32 = 0x80, };