comparison 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
comparison
equal deleted inserted replaced
692:10910827f235 693:9a474e90e832
262 const DicomFrameConverter& converter) const 262 const DicomFrameConverter& converter) const
263 { 263 {
264 if (hasRange_) 264 if (hasRange_)
265 { 265 {
266 style.windowing_ = ImageWindowing_Custom; 266 style.windowing_ = ImageWindowing_Custom;
267 style.customWindowCenter_ = converter.Apply((minValue_ + maxValue_) / 2.0); 267
268 style.customWindowWidth_ = converter.Apply(maxValue_ - minValue_); 268 // casting the narrower type to wider before calling the + operator
269 // will prevent overflowing (this is why the cast to double is only
270 // done on the first operand)
271 style.customWindowCenter_ = static_cast<float>(
272 converter.Apply((static_cast<double>(minValue_) + maxValue_) / 2.0));
273
274 style.customWindowWidth_ = static_cast<float>(
275 converter.Apply(static_cast<double>(maxValue_) - minValue_));
269 276
270 if (style.customWindowWidth_ > 1) 277 if (style.customWindowWidth_ > 1)
271 { 278 {
272 return true; 279 return true;
273 } 280 }