diff --git a/inspectrum.pro b/inspectrum.pro index fd4aff8..9d012b4 100644 --- a/inspectrum.pro +++ b/inspectrum.pro @@ -4,4 +4,5 @@ TARGET = inspectrum TEMPLATE = app LIBS += -lfftw3f -SOURCES += main.cpp inputsource.cpp +HEADERS += mainwindow.h inputsource.h spectrogram.h +SOURCES += main.cpp mainwindow.cpp inputsource.cpp spectrogram.cpp diff --git a/main.cpp b/main.cpp index 4e74b01..e67d24f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,34 +1,12 @@ #include -#include -#include -#include -#include -#include -#include "inputsource.h" +#include "mainwindow.h" int main(int argc, char *argv[]) { - const int width = 1024; - const int height = 256; - QApplication a(argc, argv); - InputSource *input = new InputSource(argv[1], width); - QImage image(width, height, QImage::Format_RGB32); - float *data = (float*)malloc(width * height * sizeof(float)); - input->GetViewport(data, 0, 0, width, height, 0); - - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - *(image.scanLine(y) + x) = (int)data[y * width + x] * -4; - } - } - - QLabel lbl; - lbl.setPixmap(QPixmap::fromImage(image)); - lbl.show(); - - + a.setApplicationName("inspectrum"); + MainWindow mainWin; + mainWin.show(); return a.exec(); - } \ No newline at end of file diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..409eb39 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,10 @@ +#include + +#include "mainwindow.h" + +MainWindow::MainWindow() +{ + setWindowTitle(tr("inspectrum")); + scrollArea.setWidget(&spectrogram); + setCentralWidget(&scrollArea); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..bc7628f --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include +#include "spectrogram.h" + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private: + QScrollArea scrollArea; + Spectrogram spectrogram; +}; \ No newline at end of file diff --git a/spectrogram.cpp b/spectrogram.cpp new file mode 100644 index 0000000..0581e0c --- /dev/null +++ b/spectrogram.cpp @@ -0,0 +1,45 @@ +#include "spectrogram.h" + +#include +#include +#include + +Spectrogram::Spectrogram() +{ + inputSource = new InputSource("/home/mike/Downloads/hubsan-chopped.cfile", 1024); + resize(inputSource->GetWidth(), inputSource->GetHeight()); +} + +Spectrogram::~Spectrogram() +{ + delete inputSource; +} + +void Spectrogram::paintEvent(QPaintEvent *event) +{ + QRect rect = event->rect(); + QPainter painter(this); + painter.fillRect(rect, Qt::black); + + if (inputSource != nullptr) { + int width = inputSource->GetWidth(); + int height = rect.height(); + + float *data = (float*)malloc(width * height * sizeof(float)); + + inputSource->GetViewport(data, 0, rect.y(), width, height, 0); + + QImage image(width, height, QImage::Format_RGB32); + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + uint8_t pixel = data[y*width + x] * -3; + image.setPixel(x, y, qRgb(0, 0, pixel)); + } + } + + QPixmap pixmap = QPixmap::fromImage(image); + painter.drawPixmap(QRect(0, rect.y(), width, height), pixmap); + + free(data); + } +} \ No newline at end of file diff --git a/spectrogram.h b/spectrogram.h new file mode 100644 index 0000000..165d11b --- /dev/null +++ b/spectrogram.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include "inputsource.h" + +class Spectrogram : public QWidget { +public: + Spectrogram(); + ~Spectrogram(); + +protected: + void paintEvent(QPaintEvent *event); + +private: + InputSource *inputSource; +}; \ No newline at end of file