jfjoch_viewer: Improve in displaying overlay numbers
This commit is contained in:
@@ -680,6 +680,10 @@ void JFJochImage::writePixelLabels() {
|
||||
const int visH = std::max(0, endY - startY);
|
||||
int maxLabels = 1000;
|
||||
|
||||
// Choose thresholds that fit your UI width
|
||||
constexpr float kMinFixed = 1e-3;
|
||||
constexpr float kMaxFixed = 1e5;
|
||||
|
||||
if (visW * visH <= maxLabels) {
|
||||
QString numBuf; // reused buffer
|
||||
|
||||
@@ -688,14 +692,27 @@ void JFJochImage::writePixelLabels() {
|
||||
const int idx = y * W + x;
|
||||
const float val = image_fp[idx];
|
||||
|
||||
const auto absVal = std::abs(val);
|
||||
const auto nearest = std::nearbyint(val);
|
||||
|
||||
const QString* pText = nullptr;
|
||||
if (std::isnan(val)) {
|
||||
pText = &kGap;
|
||||
} else if (std::isinf(val)) {
|
||||
pText = std::signbit(val) ? &kErr : &kSat;
|
||||
} else if (val == 0.0f) {
|
||||
numBuf = QStringLiteral("0");
|
||||
pText = &numBuf;
|
||||
} else if (absVal >= kMinFixed && absVal < kMaxFixed) {
|
||||
if (std::abs(val - nearest) < 1e-6)
|
||||
numBuf = QString::number(static_cast<qint64>(val));
|
||||
else if (absVal < 1e4)
|
||||
numBuf = QString::number(val, 'f', 3);
|
||||
else
|
||||
numBuf = QString::number(val, 'f', 2);
|
||||
pText = &numBuf;
|
||||
} else {
|
||||
// Fixed format reduces overhead and string length variability
|
||||
numBuf = QString::number(val, 'g', 4);
|
||||
numBuf = QString::number(val, 'e', 1);
|
||||
pText = &numBuf;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user