diff --git a/src/imageformats/exr.cpp b/src/imageformats/exr.cpp index 9de2459..3a667a0 100644 --- a/src/imageformats/exr.cpp +++ b/src/imageformats/exr.cpp @@ -368,7 +368,8 @@ static void readMetadata(const Imf::Header &header, QImage &image) // shot metadata if (auto isoSpeed = header.findTypedAttribute("isoSpeed")) { - image.setText(QStringLiteral(META_KEY_ISOSPEEDRATINGS), QLocale::c().toString(qRound(isoSpeed->value()))); + if (auto v = qRoundOrZero(isoSpeed->value())) + image.setText(QStringLiteral(META_KEY_ISOSPEEDRATINGS), QLocale::c().toString(v)); } if (auto expTime = header.findTypedAttribute("expTime")) { image.setText(QStringLiteral(META_KEY_EXPOSURETIME), QLocale::c().toString(expTime->value())); diff --git a/src/imageformats/util_p.h b/src/imageformats/util_p.h index c7e79ec..091e123 100644 --- a/src/imageformats/util_p.h +++ b/src/imageformats/util_p.h @@ -165,20 +165,27 @@ inline bool checkImageSize(const QSize& size, qint32 bytesPerPixel) return checkImageSize(size.width(), size.height(), bytesPerPixel); } +/*! + * \brief qRoundOrZero_T + * In images, many float values ​​can only be positive (e.g., resolution). This function calculates + * the roundness of the passed value, returning 0 if the value is negative or invalid. + * \return 0 when \a d is negative, NaN, Inf or std::numeric_limits::max(). Otherwise the qRound of \a d. + */ template // SF = source FP, TI = target INT TI qRoundOrZero_T(SF d, bool *ok = nullptr) { + bool tmp = false; + if (ok == nullptr) { + ok = &tmp; + } + // checks for undefined behavior - if (qIsNaN(d) || qIsInf(d) || d < SF() || d > SF(std::numeric_limits::max())) { - if (ok) { - *ok = false; - } - return 0; + if (qIsNaN(d) || qIsInf(d) || d < SF()) { + *ok = false; + } else { + *ok = d < SF(std::numeric_limits::max()); } - if (ok) { - *ok = true; - } - return qRound(d); + return *ok ? qRound(d) : 0; } inline qint32 qRoundOrZero(double d, bool *ok = nullptr)