Use std::lround instead of qRound

qRound will assert if the resulting integer is out of range, by using
lround we can ask if the rounding range failed
This commit is contained in:
Albert Astals Cid
2025-09-11 11:57:19 +02:00
parent 95f0d15e14
commit c36b4e2350
2 changed files with 34 additions and 7 deletions

View File

@ -32,6 +32,7 @@
#include <QTemporaryDir>
#include <JXRGlue.h>
#include <cfenv>
#include <cstring>
Q_DECLARE_LOGGING_CATEGORY(LOG_JXRPLUGIN)
@ -977,8 +978,15 @@ bool JXRHandler::read(QImage *outImage)
if (auto err = d->pDecoder->GetResolution(d->pDecoder, &hres, &vres)) {
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() error while reading resolution:" << err;
} else {
img.setDotsPerMeterX(qRound(hres * 1000 / 25.4));
img.setDotsPerMeterY(qRound(vres * 1000 / 25.4));
std::feclearexcept(FE_ALL_EXCEPT);
const int hdpm = std::lround(hres * 1000 / 25.4);
const int vdpm = std::lround(vres * 1000 / 25.4);
if (std::fetestexcept(FE_INVALID)) {
qCWarning(LOG_JXRPLUGIN) << "JXRHandler::read() resolution is out of range:" << hres << vres;
} else {
img.setDotsPerMeterX(hdpm);
img.setDotsPerMeterY(vdpm);
}
}
// alpha copy mode