diff --git a/src/gui/waterfallview.cc b/src/gui/waterfallview.cc index e36b62b..afcfe6b 100644 --- a/src/gui/waterfallview.cc +++ b/src/gui/waterfallview.cc @@ -41,7 +41,37 @@ GrayScaleColorMap::map(const double &value) { /* ****************************************************************************************** * - * Implementation of GrayScaleColorMap + * Implementation of LinearColorMap + * ****************************************************************************************** */ +LinearColorMap::LinearColorMap(const QVector &colors, double min, double max) + : ColorMap(min, max), _colors(colors) +{ + // pass... +} + +LinearColorMap::~LinearColorMap() { + // pass... +} + +QColor +LinearColorMap::map(const double &value) { + // Calc indices + double upper = ceil(value*(_colors.size()-1)); + double lower = floor(value*(_colors.size()-1)); + int idx = int(lower); + if (lower == upper) { return _colors[idx]; } + double dv = upper-(value*(_colors.size()-1)); + double dr = dv * (_colors[idx].red() - _colors[idx+1].red()); + double dg = dv * (_colors[idx].green() - _colors[idx+1].green()); + double db = dv * (_colors[idx].blue() - _colors[idx+1].blue()); + return QColor(int(_colors[idx+1].red()+dr), + int(_colors[idx+1].green()+dg), + int(_colors[idx+1].blue()+db)); +} + + +/* ****************************************************************************************** * + * Implementation of WaterFallView * ****************************************************************************************** */ WaterFallView::WaterFallView(Spectrum *spectrum, size_t height, QWidget *parent) : QWidget(parent), _spectrum(spectrum), _N(_spectrum->fftSize()), _M(height), _waterfall(_N,_M) @@ -49,7 +79,10 @@ WaterFallView::WaterFallView(Spectrum *spectrum, size_t height, QWidget *parent) // Fill waterfall pixmap _waterfall.fill(Qt::black); // Create color map - _colorMap = new GrayScaleColorMap(-120, 0); + //_colorMap = new GrayScaleColorMap(-120, 0); + QVector colors; colors.reserve(4); + colors << Qt::black << Qt::red << Qt::yellow << Qt::white; + _colorMap = new LinearColorMap(colors, -60, 0); // Get notified once a new spectrum is available: QObject::connect(_spectrum, SIGNAL(spectrumUpdated()), this, SLOT(_onSpectrumUpdated())); diff --git a/src/gui/waterfallview.hh b/src/gui/waterfallview.hh index cc58f81..b6af394 100644 --- a/src/gui/waterfallview.hh +++ b/src/gui/waterfallview.hh @@ -52,6 +52,18 @@ public: virtual QColor map(const double &value); }; +/** A linear interpolating color map. */ +class LinearColorMap: public ColorMap { +public: + LinearColorMap(const QVector &colors, double min, double max); + /** Destructor. */ + virtual ~LinearColorMap(); + virtual QColor map(const double &value); + +protected: + QVector _colors; +}; + /** A simple waterfall display of the spectrogram. */ class WaterFallView : public QWidget diff --git a/src/rtlsource.cc b/src/rtlsource.cc index 9d9ab5b..72495b2 100644 --- a/src/rtlsource.cc +++ b/src/rtlsource.cc @@ -109,6 +109,16 @@ RTLSource::stop() { pthread_join(_thread, &p); } +size_t +RTLSource::numDevices() { + return rtlsdr_get_device_count(); +} + +std::string +RTLSource::deviceName(size_t idx) { + return rtlsdr_get_device_name(idx); +} + void * RTLSource::__rtl_srd_parallel_main(void *ctx) { diff --git a/src/rtlsource.hh b/src/rtlsource.hh index 3b7db01..bd5da5a 100644 --- a/src/rtlsource.hh +++ b/src/rtlsource.hh @@ -55,6 +55,8 @@ public: /** Stops the reception. */ void stop(); + static size_t numDevices(); + static std::string deviceName(size_t idx); protected: /** Prallel routine to receive some data from the device. */