mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-03 23:14:16 +01:00
Flesh out Qt port a bit more
This commit is contained in:
45
spectrogram.cpp
Normal file
45
spectrogram.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "spectrogram.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QRect>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user