Flesh out Qt port a bit more

This commit is contained in:
Mike Walters
2015-07-01 21:12:52 +01:00
parent 628db604c3
commit 9619ba2a5f
6 changed files with 94 additions and 27 deletions

45
spectrogram.cpp Normal file
View 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);
}
}