From 9cc964b09e2b6076ad759485022dfdc48a22d9e1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 27 Apr 2013 16:54:54 +0200 Subject: Avoid crashes in video frame --- ftnoir_tracker_ht/video_widget.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'ftnoir_tracker_ht/video_widget.cpp') diff --git a/ftnoir_tracker_ht/video_widget.cpp b/ftnoir_tracker_ht/video_widget.cpp index 1504822d..2fa272bd 100644 --- a/ftnoir_tracker_ht/video_widget.cpp +++ b/ftnoir_tracker_ht/video_widget.cpp @@ -14,9 +14,20 @@ using namespace std; void VideoWidget::update_image(unsigned char *frame, int width, int height) { QMutexLocker((QMutex*)&mtx); - QImage qframe = QImage(frame, width, height, 3 * width, QImage::Format_RGB888).rgbSwapped(); - if (qframe.size() == size() || (qframe.width() <= this->width() && qframe.height() <= this->height())) - qframe = qframe; + QImage qframe = QImage(width, height, QImage::Format_RGB888); + uchar* data = qframe.bits(); + const int pitch = qframe.bytesPerLine(); + const int cn = 3; + for (int y = 0; y < height; y++) + 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]; + } + if (qframe.size() == size() || (qframe.width() <= this->width() && qframe.height() <= this->height())) { + } else qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); pixmap = QPixmap::fromImage(qframe); -- cgit v1.2.3