Mercurial > hg > orthanc-stone
diff Framework/Volumes/ImageBuffer3D.cpp @ 693:9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 17 May 2019 08:49:55 +0200 |
parents | 7719eb852dd5 |
children | d2c0e347ddc2 |
line wrap: on
line diff
--- a/Framework/Volumes/ImageBuffer3D.cpp Thu May 16 20:39:30 2019 +0200 +++ b/Framework/Volumes/ImageBuffer3D.cpp Fri May 17 08:49:55 2019 +0200 @@ -264,8 +264,15 @@ if (hasRange_) { style.windowing_ = ImageWindowing_Custom; - style.customWindowCenter_ = converter.Apply((minValue_ + maxValue_) / 2.0); - style.customWindowWidth_ = converter.Apply(maxValue_ - minValue_); + + // casting the narrower type to wider before calling the + operator + // will prevent overflowing (this is why the cast to double is only + // done on the first operand) + style.customWindowCenter_ = static_cast<float>( + converter.Apply((static_cast<double>(minValue_) + maxValue_) / 2.0)); + + style.customWindowWidth_ = static_cast<float>( + converter.Apply(static_cast<double>(maxValue_) - minValue_)); if (style.customWindowWidth_ > 1) {