diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-22 02:33:11 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-10-22 02:33:30 +0200 |
commit | d7d733131d62777481c9a72fee9005dd58cf0c74 (patch) | |
tree | 4bb353829d02eb1da09cc35c857bf4cf063d446c /FTNoIR_Tracker_PT/pt_video_widget.cpp | |
parent | 5bf0964212f2210e9a454e1bcf24b1f96b479922 (diff) |
Optimize widget redraw
Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
Diffstat (limited to 'FTNoIR_Tracker_PT/pt_video_widget.cpp')
-rw-r--r-- | FTNoIR_Tracker_PT/pt_video_widget.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/FTNoIR_Tracker_PT/pt_video_widget.cpp b/FTNoIR_Tracker_PT/pt_video_widget.cpp index 03c42fc7..35a2c42b 100644 --- a/FTNoIR_Tracker_PT/pt_video_widget.cpp +++ b/FTNoIR_Tracker_PT/pt_video_widget.cpp @@ -18,19 +18,7 @@ using namespace std; void PTVideoWidget::update_image(const cv::Mat& frame)
{
QMutexLocker foo(&mtx);
- QImage qframe = QImage(frame.cols, frame.rows, QImage::Format_RGB888);
- uchar* data = qframe.bits();
- const int pitch = qframe.bytesPerLine();
- for (int y = 0; y < frame.rows; y++)
- for (int x = 0; x < frame.cols; x++)
- {
- const int pos = 3 * (y*frame.cols + x);
- data[y * pitch + x * 3 + 0] = frame.data[pos + 2];
- data[y * pitch + x * 3 + 1] = frame.data[pos + 1];
- data[y * pitch + x * 3 + 2] = frame.data[pos + 0];
- }
- qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
- pixmap = QPixmap::fromImage(qframe);
+ _frame = frame;
}
// ----------------------------------------------------------------------------
@@ -50,3 +38,24 @@ VideoWidgetDialog::VideoWidgetDialog(QWidget *parent, FrameProvider* provider) setLayout(layout);
resize(VIDEO_FRAME_WIDTH, VIDEO_FRAME_HEIGHT);
}
+
+void PTVideoWidget::update_and_repaint()
+{
+ QMutexLocker foo(&mtx);
+ if (_frame.empty())
+ return;
+ QImage qframe = QImage(_frame.cols, _frame.rows, QImage::Format_RGB888);
+ uchar* data = qframe.bits();
+ const int pitch = qframe.bytesPerLine();
+ for (int y = 0; y < _frame.rows; y++)
+ for (int x = 0; x < _frame.cols; x++)
+ {
+ const int pos = 3 * (y*_frame.cols + x);
+ data[y * pitch + x * 3 + 0] = _frame.data[pos + 2];
+ data[y * pitch + x * 3 + 1] = _frame.data[pos + 1];
+ data[y * pitch + x * 3 + 2] = _frame.data[pos + 0];
+ }
+ qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
+ pixmap = QPixmap::fromImage(qframe);
+ update();
+}
|