From 74b8483457b51727dba38aa05a5be9bc773d8a28 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 4 Jun 2015 19:51:33 +0200 Subject: octopus, pt, aruco: optimize image copying Perform less operations in inner loop where pixels are accessed. --- ftnoir_tracker_ht/ht_video_widget.cpp | 49 ++++++++++++++++++++++------------- ftnoir_tracker_ht/ht_video_widget.h | 5 ++-- 2 files changed, 34 insertions(+), 20 deletions(-) (limited to 'ftnoir_tracker_ht') diff --git a/ftnoir_tracker_ht/ht_video_widget.cpp b/ftnoir_tracker_ht/ht_video_widget.cpp index c6d59b34..1c5f565c 100644 --- a/ftnoir_tracker_ht/ht_video_widget.cpp +++ b/ftnoir_tracker_ht/ht_video_widget.cpp @@ -14,31 +14,44 @@ 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; + if (!fresh) + { + memcpy(fb, frame, width * height * 3); + this->width = width; + this->height = height; + fresh = true; + } } 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++) + QImage qframe; { - const int part = y*width; - for (int x = 0; x < width; x++) + QMutexLocker foo(&mtx); + if (width*height <= 0 || !fresh) + return; + fresh = false; + 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 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]; + const int part = y*width; + for (int x = 0; x < width; x++) + { + const int pos = 3 * (part + x); + const int x_ = x * 3; + data[x_ + 0] = fb[pos + 2]; + data[x_ + 1] = fb[pos + 1]; + data[x_ + 2] = fb[pos + 0]; + } + data += pitch; } } - auto qframe2 = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); - texture = qframe2; + qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); + { + QMutexLocker foo(&mtx); + texture = qframe; + } update(); } diff --git a/ftnoir_tracker_ht/ht_video_widget.h b/ftnoir_tracker_ht/ht_video_widget.h index cbfe6ddc..be4aee44 100644 --- a/ftnoir_tracker_ht/ht_video_widget.h +++ b/ftnoir_tracker_ht/ht_video_widget.h @@ -23,7 +23,7 @@ class HTVideoWidget : public QWidget Q_OBJECT public: - HTVideoWidget(QWidget *parent) : QWidget(parent), fb(), width(0), height(0) { + HTVideoWidget(QWidget *parent) : QWidget(parent), fb(), width(0), height(0), fresh(false) { connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint())); timer.start(60); } @@ -40,8 +40,9 @@ private: QMutex mtx; QImage texture; QTimer timer; - char fb[2048*2048*3]; + unsigned char fb[2048*2048*3]; int width,height; + bool fresh; }; #endif // VIDEOWIDGET_H -- cgit v1.2.3