Mercurial > hg > orthanc
diff OrthancFramework/Sources/Images/ImageAccessor.cpp @ 4278:9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 03 Nov 2020 20:05:55 +0100 |
parents | 0034f855c023 |
children | b30a8de92ad9 |
line wrap: on
line diff
--- a/OrthancFramework/Sources/Images/ImageAccessor.cpp Tue Nov 03 18:45:32 2020 +0100 +++ b/OrthancFramework/Sources/Images/ImageAccessor.cpp Tue Nov 03 20:05:55 2020 +0100 @@ -41,7 +41,10 @@ { target.AddChunk("double([ "); - for (unsigned int y = 0; y < source.GetHeight(); y++) + const unsigned int width = source.GetWidth(); + const unsigned int height = source.GetHeight(); + + for (unsigned int y = 0; y < height; y++) { const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); @@ -51,9 +54,9 @@ s = "; "; } - s.reserve(source.GetWidth() * 8); + s.reserve(width * 8); - for (unsigned int x = 0; x < source.GetWidth(); x++, p++) + for (unsigned int x = 0; x < width; x++, p++) { s += boost::lexical_cast<std::string>(static_cast<double>(*p)) + " "; } @@ -72,14 +75,17 @@ target.AddChunk("double(permute(reshape([ "); - for (unsigned int y = 0; y < source.GetHeight(); y++) + const unsigned int width = source.GetWidth(); + const unsigned int height = source.GetHeight(); + + for (unsigned int y = 0; y < height; y++) { const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); std::string s; - s.reserve(source.GetWidth() * 3 * 8); + s.reserve(width * 3 * 8); - for (unsigned int x = 0; x < 3 * source.GetWidth(); x++, p++) + for (unsigned int x = 0; x < 3 * width; x++, p++) { s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " "; } @@ -87,8 +93,8 @@ target.AddChunk(s); } - target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(source.GetHeight()) + - " " + boost::lexical_cast<std::string>(source.GetWidth()) + " ]), [ 3 2 1 ]))"); + target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(height) + + " " + boost::lexical_cast<std::string>(width) + " ]), [ 3 2 1 ]))"); }