mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2026-09-14 05:07:00 -04:00
qRoundOrZero_T: fix possible assert in qRound
also: - qRoundOrZero_T: added documentation - EXR: I don't set the ISO Speed if it's zero. BUG: 524678
This commit is contained in:
committed by
Albert Astals Cid
parent
47ea774621
commit
a6027264d4
@@ -368,7 +368,8 @@ static void readMetadata(const Imf::Header &header, QImage &image)
|
||||
|
||||
// shot metadata
|
||||
if (auto isoSpeed = header.findTypedAttribute<Imf::FloatAttribute>("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<Imf::FloatAttribute>("expTime")) {
|
||||
image.setText(QStringLiteral(META_KEY_EXPOSURETIME), QLocale::c().toString(expTime->value()));
|
||||
|
||||
@@ -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<TI>::max(). Otherwise the qRound of \a d.
|
||||
*/
|
||||
template<class TI, class SF> // 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<TI>::max())) {
|
||||
if (ok) {
|
||||
*ok = false;
|
||||
}
|
||||
return 0;
|
||||
if (qIsNaN(d) || qIsInf(d) || d < SF()) {
|
||||
*ok = false;
|
||||
} else {
|
||||
*ok = d < SF(std::numeric_limits<TI>::max());
|
||||
}
|
||||
if (ok) {
|
||||
*ok = true;
|
||||
}
|
||||
return qRound(d);
|
||||
return *ok ? qRound(d) : 0;
|
||||
}
|
||||
|
||||
inline qint32 qRoundOrZero(double d, bool *ok = nullptr)
|
||||
|
||||
Reference in New Issue
Block a user