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/Image.cpp | 9 ++++---- TextureLoader/src/TextureLoader.cpp | 44 +++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 23 deletions(-) (limited to 'TextureLoader/src') diff --git a/TextureLoader/src/Image.cpp b/TextureLoader/src/Image.cpp index b2c7ab9..fc3cd85 100644 --- a/TextureLoader/src/Image.cpp +++ b/TextureLoader/src/Image.cpp @@ -154,7 +154,7 @@ namespace Diligent auto ScanlineSize = TIFFScanlineSize(TiffFile); m_Desc.RowStride = Align(static_cast( ScanlineSize ), 4u); - m_pData->Resize(m_Desc.Height * m_Desc.RowStride ); + m_pData->Resize(size_t{m_Desc.Height} * size_t{m_Desc.RowStride}); auto *pDataPtr = reinterpret_cast( m_pData->GetDataPtr() ); for (Uint32 row = 0; row < m_Desc.Height; row++, pDataPtr += m_Desc.RowStride) { @@ -266,7 +266,7 @@ namespace Diligent //Alocate a buffer with enough space. Align stride to 4 bytes m_Desc.RowStride = Align(m_Desc.Width * bit_depth * m_Desc.NumComponents / 8, 4u); - m_pData->Resize( m_Desc.Height * m_Desc.RowStride ); + m_pData->Resize( size_t{m_Desc.Height} * size_t{m_Desc.RowStride} ); for( size_t i = 0; i < m_Desc.Height; i++ ) rowPtrs[i] = reinterpret_cast(m_pData->GetDataPtr()) + i * m_Desc.RowStride; @@ -281,6 +281,7 @@ namespace Diligent struct my_jpeg_error_mgr { jpeg_error_mgr pub; + char padding[8]; jmp_buf setjmp_buffer;// for return to caller }; @@ -362,7 +363,7 @@ namespace Diligent m_Desc.RowStride = Align(m_Desc.Width * m_Desc.NumComponents, 4u); m_Desc.BitsPerPixel = 8 * m_Desc.NumComponents; - m_pData->Resize(m_Desc.RowStride * m_Desc.Height); + m_pData->Resize(size_t{m_Desc.RowStride} * size_t{m_Desc.Height}); // Step 6: while (scan lines remain to be read) // jpeg_read_scanlines(...); @@ -374,7 +375,7 @@ namespace Diligent // more than one scanline at a time if that's more convenient. - auto *pDstScanline = reinterpret_cast( m_pData->GetDataPtr() ) + cinfo.output_scanline * m_Desc.RowStride; + auto *pDstScanline = reinterpret_cast( m_pData->GetDataPtr() ) + size_t{cinfo.output_scanline} * size_t{m_Desc.RowStride}; JSAMPROW RowPtrs[] = { reinterpret_cast(pDstScanline) }; jpeg_read_scanlines( &cinfo, RowPtrs, 1 ); } 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