From b440ddfbf8353d829502f276e5c44f367e1b5436 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 16 Dec 2018 11:48:54 -0800 Subject: Fixed msvc warning plus few minor issues revealed by code analysis --- TextureLoader/src/TextureLoader.cpp | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'TextureLoader/src/TextureLoader.cpp') diff --git a/TextureLoader/src/TextureLoader.cpp b/TextureLoader/src/TextureLoader.cpp index 7fc9a40..cd40c54 100644 --- a/TextureLoader/src/TextureLoader.cpp +++ b/TextureLoader/src/TextureLoader.cpp @@ -57,7 +57,7 @@ namespace Diligent template ChannelType SRGBAverage(ChannelType c0, ChannelType c1, ChannelType c2, ChannelType c3) { - const float NormVal = static_cast(std::numeric_limits::max()); + constexpr float NormVal = static_cast(std::numeric_limits::max()); float fc0 = static_cast(c0) / NormVal; float fc1 = static_cast(c1) / NormVal; float fc2 = static_cast(c2) / NormVal; @@ -73,15 +73,18 @@ namespace Diligent template < typename ChannelType > void ComputeCoarseMip(Uint32 NumChannels, bool IsSRGB, - const void *pFineMip, Uint32 FineMipStride, - void *pCoarseMip, Uint32 CoarseMipStride, - Uint32 CoarseMipWidth, Uint32 CoarseMipHeight) + const void* pFineMip, + Uint32 FineMipStride, + void* pCoarseMip, + Uint32 CoarseMipStride, + Uint32 CoarseMipWidth, + Uint32 CoarseMipHeight) { - for( Uint32 row = 0; row < CoarseMipHeight; ++row ) - for( Uint32 col = 0; col < CoarseMipWidth; ++col ) + for( size_t row = 0; row < size_t{CoarseMipHeight}; ++row ) + for( size_t col = 0; col < size_t{CoarseMipWidth}; ++col ) { - auto FineRow0 = reinterpret_cast( reinterpret_cast(pFineMip) + row * 2 * FineMipStride ); - auto FineRow1 = reinterpret_cast( reinterpret_cast(pFineMip) + (row * 2 + 1 ) * FineMipStride ); + auto FineRow0 = reinterpret_cast( reinterpret_cast(pFineMip) + row * 2 * size_t{FineMipStride} ); + auto FineRow1 = reinterpret_cast( reinterpret_cast(pFineMip) + (row * 2 + 1 ) * size_t{FineMipStride} ); for( Uint32 c = 0; c < NumChannels; ++c ) { @@ -89,7 +92,7 @@ namespace Diligent auto Col01 = FineRow0[ (col*2+1) * NumChannels + c ]; auto Col10 = FineRow1[ col*2 * NumChannels + c ]; auto Col11 = FineRow1[ (col*2+1) * NumChannels + c ]; - auto &DstCol = reinterpret_cast(reinterpret_cast(pCoarseMip) + row * CoarseMipStride)[col * NumChannels + c]; + auto &DstCol = reinterpret_cast(reinterpret_cast(pCoarseMip) + row * size_t{CoarseMipStride})[col * NumChannels + c]; if( IsSRGB ) DstCol = SRGBAverage( Col00, Col01, Col10, Col11 ); else @@ -99,19 +102,22 @@ namespace Diligent } template < typename ChannelType > - void RGBToRGBA(const void *pRGBData, Uint32 RGBStride, - void *pRGBAData, Uint32 RGBAStride, - Uint32 Width, Uint32 Height) + void RGBToRGBA(const void* pRGBData, + Uint32 RGBStride, + void* pRGBAData, + Uint32 RGBAStride, + Uint32 Width, + Uint32 Height) { - for( Uint32 row = 0; row < Height; ++row ) - for( Uint32 col = 0; col < Width; ++col ) + for( size_t row = 0; row < size_t{Height}; ++row ) + for( size_t col = 0; col < size_t{Width}; ++col ) { for( int c = 0; c < 3; ++c ) { - reinterpret_cast( (reinterpret_cast(pRGBAData) + RGBAStride * row) ) [col *4 + c] = - reinterpret_cast( (reinterpret_cast(pRGBData) + RGBStride * row))[col*3 + c]; + reinterpret_cast( (reinterpret_cast(pRGBAData) + size_t{RGBAStride} * row) ) [col *4 + c] = + reinterpret_cast( (reinterpret_cast(pRGBData) + size_t{RGBStride} * row))[col*3 + c]; } - reinterpret_cast( (reinterpret_cast(pRGBAData) + RGBAStride * row) ) [col *4 + 3] = std::numeric_limits::max(); + reinterpret_cast( (reinterpret_cast(pRGBAData) + size_t{RGBAStride} * row) ) [col *4 + 3] = std::numeric_limits::max(); } } @@ -180,7 +186,7 @@ namespace Diligent VERIFY_EXPR( NumComponents == 4 ); auto RGBAStride = ImgDesc.Width * NumComponents * ChannelDepth / 8; RGBAStride = (RGBAStride + 3) & (-4); - Mips[0].resize(RGBAStride * ImgDesc.Height); + Mips[0].resize(size_t{RGBAStride} * size_t{ImgDesc.Height}); pSubResources[0].pData = Mips[0].data(); pSubResources[0].Stride = RGBAStride; if( ChannelDepth == 8 ) @@ -206,7 +212,7 @@ namespace Diligent auto CoarseMipHeight = std::max(MipHeight/2u, 1u); auto CoarseMipStride = CoarseMipWidth * NumComponents * ChannelDepth / 8; CoarseMipStride = (CoarseMipStride + 3) & (-4); - Mips[m].resize(CoarseMipStride * CoarseMipHeight); + Mips[m].resize(size_t{CoarseMipStride} * size_t{CoarseMipHeight}); if (TexLoadInfo.GenerateMips) { -- cgit v1.2.3