From 9158da20e0b51ed690b5e9825ea8ddd9fe8bd036 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 17 Oct 2018 15:28:53 +0200 Subject: [PATCH] Spectrum: reviewed histogram capping to phosphor palette and stroke value limits --- sdrgui/gui/glspectrum.cpp | 23 ++++++++++++++--------- sdrgui/gui/glspectrumgui.cpp | 10 ++-------- sdrgui/gui/glspectrumgui.ui | 4 ++-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/sdrgui/gui/glspectrum.cpp b/sdrgui/gui/glspectrum.cpp index eaf6e8b62..8c8bedc8f 100644 --- a/sdrgui/gui/glspectrum.cpp +++ b/sdrgui/gui/glspectrum.cpp @@ -107,7 +107,7 @@ GLSpectrum::GLSpectrum(QWidget* parent) : m_histogramHoldoffBase = 4; // was 2 m_histogramHoldoffCount = m_histogramHoldoffBase; m_histogramLateHoldoff = 20; // was 1 - m_histogramStroke = 40; // was 4 + m_histogramStroke = 4; m_timeScale.setFont(font()); m_timeScale.setOrientation(Qt::Vertical); @@ -175,12 +175,12 @@ void GLSpectrum::setDecay(int decay) void GLSpectrum::setHistoHoldoffBase(int holdoffBase) { - m_histogramHoldoffBase = holdoffBase < 0 ? 0 : holdoffBase > 20 ? 20 : holdoffBase; + m_histogramHoldoffBase = holdoffBase < 0 ? 0 : holdoffBase > 240 ? 240 : holdoffBase; } void GLSpectrum::setHistoStroke(int stroke) { - m_histogramStroke = stroke < 4 ? 4 : stroke > 240 ? 240 : stroke; + m_histogramStroke = stroke < 1 ? 1 : stroke > 40 ? 40 : stroke; } void GLSpectrum::setSampleRate(qint32 sampleRate) @@ -373,7 +373,7 @@ void GLSpectrum::updateHistogram(const std::vector& spectrum) { for (int i = 0; i < fftMulSize; i++) { - if (*b > 16) // was 20 + if (*b > 20) // must be more than max value of m_decay { *b = *b - sub; } @@ -470,15 +470,20 @@ void GLSpectrum::updateHistogram(const std::vector& spectrum) } } #else - for(int i = 0; i < m_fftSize; i++) { + for (int i = 0; i < m_fftSize; i++) + { int v = (int)((spectrum[i] - m_referenceLevel) * 100.0 / m_powerRange + 100.0); - if ((v >= 0) && (v <= 99)) { + if ((v >= 0) && (v <= 99)) + { b = m_histogram + i * 100 + v; - if(*b < 220) + + // capping to 239 as palette values are [0..239] + if (*b + m_histogramStroke <= 239) { *b += m_histogramStroke; // was 4 - else if(*b < 239) - *b += 1; + } else { + *b = 239; + } } } #endif diff --git a/sdrgui/gui/glspectrumgui.cpp b/sdrgui/gui/glspectrumgui.cpp index b131664f7..1c65233d6 100644 --- a/sdrgui/gui/glspectrumgui.cpp +++ b/sdrgui/gui/glspectrumgui.cpp @@ -68,7 +68,7 @@ void GLSpectrumGUI::resetToDefaults() m_powerRange = 100; m_decay = 0; m_histogramHoldoffBase = 0; - m_histogramStroke = 40; + m_histogramStroke = 4; m_displayGridIntensity = 5, m_displayWaterfall = true; m_invertedWaterfall = false; @@ -135,7 +135,7 @@ bool GLSpectrumGUI::deserialize(const QByteArray& data) d.readBool(12, &m_invert, true); d.readS32(13, &m_displayGridIntensity, 5); d.readS32(14, &m_histogramHoldoffBase, 0); - d.readS32(15, &m_histogramStroke, 40); + d.readS32(15, &m_histogramStroke, 4); d.readBool(16, &m_displayCurrent, false); d.readS32(17, &m_displayTraceIntensity, 50); Real waterfallShare; @@ -369,9 +369,6 @@ void GLSpectrumGUI::on_decay_valueChanged(int index) void GLSpectrumGUI::on_holdoff_valueChanged(int index) { - if (index < 0) { - return; - } m_histogramHoldoffBase = index; //ui->holdoff->setToolTip(QString("Holdoff: %1").arg(m_histogramHoldoffBase)); if(m_glSpectrum != 0) { @@ -381,9 +378,6 @@ void GLSpectrumGUI::on_holdoff_valueChanged(int index) void GLSpectrumGUI::on_stroke_valueChanged(int index) { - if (index < 4) { - return; - } m_histogramStroke = index; //ui->stroke->setToolTip(QString("Stroke: %1").arg(m_histogramStroke)); if(m_glSpectrum != 0) { diff --git a/sdrgui/gui/glspectrumgui.ui b/sdrgui/gui/glspectrumgui.ui index bf898392f..7dbcb01aa 100644 --- a/sdrgui/gui/glspectrumgui.ui +++ b/sdrgui/gui/glspectrumgui.ui @@ -93,10 +93,10 @@ Stroke: - 4 + 1 - 240 + 40 1