Nonoptimal image drawing function (Bug #2356)
Description
I've found a bug in highgui module with Qt support.
To draw image the data is firstly scaled to the current window size.
Then it is drawing with "painter->drawImage" function which also scales image according to the zoom level.
If the cvWindow is created with CV_WINDOW_NORMAL flag, zoom level > 1 and the image size is greater then window size, that leads to loss of data.
Current code in "window_QT.cpp":
void DefaultViewPort::draw2D(QPainter *painter) { image2Draw_qt = QImage(image2Draw_mat->data.ptr, image2Draw_mat->cols, image2Draw_mat->rows,image2Draw_mat->step,QImage::Format_RGB888); image2Draw_qt_resized = image2Draw_qt.scaled(viewport()->width(),viewport()->height(),Qt::IgnoreAspectRatio,Qt::FastTransformation);//Qt::SmoothTransformation); painter->drawImage(0,0,image2Draw_qt_resized); }
Proposed code:
void DefaultViewPort::draw2D(QPainter *painter) { image2Draw_qt = QImage(image2Draw_mat->data.ptr, image2Draw_mat->cols, image2Draw_mat->rows,image2Draw_mat->step,QImage::Format_RGB888); painter->drawImage(QRect(0,0,viewport()->width(),viewport()->height()), image2Draw_qt, QRect(0,0, image2Draw_qt.width(), image2Draw_qt.height()) ); }
Associated revisions
improved image rendering performance in Qt backend for highgui UI (bug #2356)
Merge pull request #2356 from SpecLad:merge-2.4
History
Updated by Vadim Pisarevsky over 12 years ago
thanks! your patch was applied in d9e801
- Status changed from Open to Done