diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-22 02:40:02 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-22 02:40:02 +0200 |
commit | 8503f538d18f8df0f18ee4973e96f3889a11419a (patch) | |
tree | cc7c65a8911ed7f897070d9c9898506c9a414a74 | |
parent | d7d733131d62777481c9a72fee9005dd58cf0c74 (diff) |
optimize HT widget refresh
Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
-rw-r--r-- | ftnoir_tracker_ht/ftnoir_tracker_ht.cpp | 9 | ||||
-rw-r--r-- | ftnoir_tracker_ht/ftnoir_tracker_ht.h | 4 | ||||
-rw-r--r-- | ftnoir_tracker_ht/ht_video_widget.cpp | 26 | ||||
-rw-r--r-- | ftnoir_tracker_ht/ht_video_widget.h | 14 |
4 files changed, 31 insertions, 22 deletions
diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp index 62606395..d14fa5e0 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp @@ -184,15 +184,6 @@ void Tracker::StartTracker(QFrame* videoframe) #else subprocess.start(QCoreApplication::applicationDirPath() + "/tracker-ht/headtracker-ftnoir"); #endif - connect(&timer, SIGNAL(timeout()), this, SLOT(paint_widget())); - timer.start(40); -} - -void Tracker::paint_widget() { - if (fresh) { - fresh = false; - videoWidget->update(); - } } bool Tracker::GiveHeadPoseData(double *data) diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.h b/ftnoir_tracker_ht/ftnoir_tracker_ht.h index bde4ca67..e1810232 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.h +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.h @@ -15,7 +15,6 @@ #include "ht_video_widget.h" #include "compat/compat.h" #include <QObject> -#include <QTimer> class Tracker : public QObject, public ITracker { @@ -28,14 +27,11 @@ public: bool enableTX, enableTY, enableTZ, enableRX, enableRY, enableRZ; ht_shm_t* shm; private: - QTimer timer; PortableLockedShm lck_shm; QProcess subprocess; HTVideoWidget* videoWidget; QHBoxLayout* layout; volatile bool fresh; -private slots: - void paint_widget(); }; // Widget that has controls for FTNoIR protocol client-settings. diff --git a/ftnoir_tracker_ht/ht_video_widget.cpp b/ftnoir_tracker_ht/ht_video_widget.cpp index 4d7d66a2..8ccec997 100644 --- a/ftnoir_tracker_ht/ht_video_widget.cpp +++ b/ftnoir_tracker_ht/ht_video_widget.cpp @@ -14,17 +14,31 @@ using namespace std; void HTVideoWidget::update_image(unsigned char *frame, int width, int height) { QMutexLocker foo(&mtx); + memcpy(fb, frame, width * height * 3); + this->width = width; + this->height = height; +} + +void HTVideoWidget::update_and_repaint() +{ + QMutexLocker foo(&mtx); + if (width*height <= 0) + return; QImage qframe = QImage(width, height, QImage::Format_RGB888); uchar* data = qframe.bits(); const int pitch = qframe.bytesPerLine(); for (int y = 0; y < height; y++) + { + const int part = y*width; for (int x = 0; x < width; x++) { - const int pos = 3 * (y*width + x); - data[y * pitch + x * 3 + 0] = frame[pos + 2]; - data[y * pitch + x * 3 + 1] = frame[pos + 1]; - data[y * pitch + x * 3 + 2] = frame[pos + 0]; + const int pos = 3 * (part + x); + data[y * pitch + x * 3 + 0] = fb[pos + 2]; + data[y * pitch + x * 3 + 1] = fb[pos + 1]; + data[y * pitch + x * 3 + 2] = fb[pos + 0]; } - qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); - pixmap = QPixmap::fromImage(qframe); + } + auto qframe2 = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); + pixmap = QPixmap::fromImage(qframe2); + update(); } diff --git a/ftnoir_tracker_ht/ht_video_widget.h b/ftnoir_tracker_ht/ht_video_widget.h index b1182d8b..78000afa 100644 --- a/ftnoir_tracker_ht/ht_video_widget.h +++ b/ftnoir_tracker_ht/ht_video_widget.h @@ -15,15 +15,18 @@ #include <QLabel> #include <QPainter> #include <QPaintEvent> +#include <QTimer> // ---------------------------------------------------------------------------- class HTVideoWidget : public QWidget { - Q_OBJECT + Q_OBJECT public: - HTVideoWidget(QWidget *parent) : QWidget(parent), mtx() { - } + HTVideoWidget(QWidget *parent) : QWidget(parent), width(0), height(0), fb{0} { + connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint())); + timer.start(60); + } void update_image(unsigned char* frame, int width, int height); protected slots: void paintEvent( QPaintEvent* e ) { @@ -31,9 +34,14 @@ protected slots: QPainter painter(this); painter.drawPixmap(e->rect(), pixmap, e->rect()); } + void update_and_repaint(); + private: QMutex mtx; QPixmap pixmap; + QTimer timer; + char fb[2048*2048*3]; + int width,height; }; #endif // VIDEOWIDGET_H |