diff --git a/include/mitsuba/render/mipmap.h b/include/mitsuba/render/mipmap.h index e43bb90f..62849a31 100644 --- a/include/mitsuba/render/mipmap.h +++ b/include/mitsuba/render/mipmap.h @@ -614,8 +614,8 @@ public: const Value p11 = evalTexel(level, xPos+1, yPos+1); Value tmp = p01 + p10 - p11; - gradient[0] = (p10 + p00*(dy-1) - tmp*dy) * size.x; - gradient[1] = (p01 + p00*(dx-1) - tmp*dx) * size.y; + gradient[0] = (p10 + p00*(dy-1) - tmp*dy) * static_cast (size.x); + gradient[1] = (p01 + p00*(dx-1) - tmp*dx) * static_cast (size.y); } /// \brief Perform a filtered texture lookup using the configured method diff --git a/src/libcore/bitmap.cpp b/src/libcore/bitmap.cpp index 657fee46..bf928c37 100644 --- a/src/libcore/bitmap.cpp +++ b/src/libcore/bitmap.cpp @@ -67,6 +67,17 @@ extern "C" { MTS_NAMESPACE_BEGIN +namespace +{ +// Safely convert between scalar types avoiding downcasting warning +template inline T safe_cast(S a) { + return static_cast(a); +} +template <> inline half safe_cast(double a) { + return static_cast(static_cast(a)); +} +} + #if defined(MTS_HAS_OPENEXR) /* ========================== * * EXR helper classes * @@ -869,7 +880,7 @@ void Bitmap::convolve(const Bitmap *_kernel) { * (double) input[(xs+ys*width)*m_channelCount+ch]; } } - output[(x+y*width)*m_channelCount+ch] = (half) result; + output[(x+y*width)*m_channelCount+ch] = safe_cast(result); } } } @@ -982,7 +993,7 @@ void Bitmap::scale(Float value) { half *data = (half *) m_data; for (size_t i=0; i (*data * value); ++data; } ++data; } @@ -1046,7 +1057,7 @@ void Bitmap::scale(Float value) { case EFloat16: { half *data = (half *) m_data; for (size_t i=0; i (data[i] * value); } break; @@ -1504,9 +1515,9 @@ template void tonemapReinhard(T *data, size_t pixels, Bitmap::EPixe Z = ratio * ((Float) 1.0f - x - y); /* Convert from XYZ tristimulus values to ITU-R Rec. BT.709 linear RGB */ - data[0] = (T)( 3.240479f * X + -1.537150f * Y + -0.498535f * Z); - data[1] = (T)( -0.969256f * X + 1.875991f * Y + 0.041556f * Z); - data[2] = (T)( 0.055648f * X + -0.204043f * Y + 1.057311f * Z); + data[0] = safe_cast( 3.240479f * X + -1.537150f * Y + -0.498535f * Z); + data[1] = safe_cast( -0.969256f * X + 1.875991f * Y + 0.041556f * Z); + data[2] = safe_cast( 0.055648f * X + -0.204043f * Y + 1.057311f * Z); data += channels; } @@ -1531,9 +1542,9 @@ template void tonemapReinhard(T *data, size_t pixels, Bitmap::EPixe X = ratio * x; Z = ratio * ((Float) 1.0f - x - y); - data[0] = (T) X; - data[1] = (T) Y; - data[2] = (T) Z; + data[0] = safe_cast(X); + data[1] = safe_cast(Y); + data[2] = safe_cast(Z); data += channels; } @@ -1544,7 +1555,7 @@ template void tonemapReinhard(T *data, size_t pixels, Bitmap::EPixe Float Lp = (Float) *data * scale; /* Apply the tonemapping transformation */ - *data = (T) (Lp * (1.0f + Lp*invWp2) / (1.0f + Lp)); + *data = safe_cast (Lp * (1.0f + Lp*invWp2) / (1.0f + Lp)); data += channels; } @@ -1795,7 +1806,7 @@ template static void resample(ref + y * target->getWidth() * channels; r.resampleAndClamp(srcPtr, 1, trgPtr, 1, channels, - (Scalar) minValue, (Scalar) maxValue); + safe_cast(minValue), safe_cast(maxValue)); } /* Now, read from the temporary bitmap */ @@ -1814,7 +1825,7 @@ template static void resample(ref Scalar *trgPtr = (Scalar *) target->getUInt8Data() + x * channels; r.resampleAndClamp(srcPtr, source->getWidth(), trgPtr, target->getWidth(), - channels, (Scalar) minValue, (Scalar) maxValue); + channels, safe_cast(minValue), safe_cast(maxValue)); } } } @@ -3228,7 +3239,7 @@ void Bitmap::readPFM(Stream *stream) { } stream->setByteOrder(backup); - Float scale = std::abs(scaleAndOrder); + const float scale = std::abs(scaleAndOrder); if (scale != 1) { for (size_t i=0; i inline T safe_cast(size_t a) { + template inline T safe_cast(S a) { return static_cast(a); } - template <> inline half safe_cast(size_t a) { - float tmp = static_cast(a); - return static_cast(tmp); + return static_cast(static_cast(a)); + } + template <> inline half safe_cast(double a) { + return static_cast(static_cast(a)); } } @@ -1140,10 +1141,10 @@ private: value = applyGamma(value, invDestGamma); if (format_traits::is_float) - return (DestFmt) value; + return detail::safe_cast (value); else /* Round to nearest value and clamp to representable range */ - return (DestFmt) std::min(static_cast(std::numeric_limits::max()), - std::max((Float) 0, value * (Float) std::numeric_limits::max() + (Float) 0.5f)); + return detail::safe_cast (std::min(static_cast(std::numeric_limits::max()), + std::max((Float) 0, value * (Float) std::numeric_limits::max() + (Float) 0.5f))); } }; diff --git a/src/sensors/perspective_rdist.cpp b/src/sensors/perspective_rdist.cpp index 52214850..1bc7929e 100644 --- a/src/sensors/perspective_rdist.cpp +++ b/src/sensors/perspective_rdist.cpp @@ -115,8 +115,8 @@ public: m_distortion = false; } else if (kc_tokens.size() == 2) { char *end_ptr0, *end_ptr1; - m_kc[0] = std::strtod(kc_tokens[0].c_str(), &end_ptr0); - m_kc[1] = std::strtod(kc_tokens[1].c_str(), &end_ptr1); + m_kc[0] = (Float) std::strtod(kc_tokens[0].c_str(), &end_ptr0); + m_kc[1] = (Float) std::strtod(kc_tokens[1].c_str(), &end_ptr1); if (*end_ptr0 != '\0' || *end_ptr1 != 0) Log(EError, "Invalid input to the 'kc' parameter!"); m_distortion = m_kc[0] != 0 || m_kc[1] != 0; diff --git a/src/volume/gridvolume.cpp b/src/volume/gridvolume.cpp index 9519cb82..23d2ccf6 100644 --- a/src/volume/gridvolume.cpp +++ b/src/volume/gridvolume.cpp @@ -299,6 +299,10 @@ public: value[0] = a; value[1] = b; value[2] = c; } + inline explicit float3(double a, double b, double c) { + value[0] = (float) a; value[1] = (float) b; value[2] = (float) c; + } + inline float3 operator*(Float v) const { return float3((float) (value[0]*v), (float) (value[1]*v), (float) (value[2]*v)); }