From a87f5897723cd0e5338b8952227b0b64e2727944 Mon Sep 17 00:00:00 2001 From: Ove Brynestad Date: Tue, 8 Jul 2014 15:39:24 +0200 Subject: [PATCH] qv4l2: moved scaling calculations from setRenderFrame Ongoing work to move aspect/crop/scale calculations from individual render classes to the common capture-win class. Currently different renderers use slightly different code to calculate the various cropping/scaling/etc. data. This makes it hard to maintain. Signed-off-by: Ove Brynestad Signed-off-by: Hans Verkuil --- utils/qv4l2/capture-win-gl.cpp | 11 +++-------- utils/qv4l2/capture-win-qt.cpp | 33 +++++++++++++-------------------- utils/qv4l2/capture-win.cpp | 34 ++++++++++++++++++++-------------- utils/qv4l2/capture-win.h | 7 ++++--- 4 files changed, 40 insertions(+), 45 deletions(-) diff --git a/utils/qv4l2/capture-win-gl.cpp b/utils/qv4l2/capture-win-gl.cpp index ed9d87f..013e21d 100644 --- a/utils/qv4l2/capture-win-gl.cpp +++ b/utils/qv4l2/capture-win-gl.cpp @@ -52,6 +52,7 @@ void CaptureWinGL::resizeEvent(QResizeEvent *event) m_curWinWidth = width() - margins.width(); m_curWinHeight = height() - margins.height(); // Re-calculate + m_frameInfo.updated = true; CaptureWin::resizeScaleCrop(); // Lock viewport size to follow calculated size m_videoSurface.lockSize(m_scaledSize); @@ -62,20 +63,14 @@ void CaptureWinGL::resizeEvent(QResizeEvent *event) void CaptureWinGL::setRenderFrame() { #ifdef HAVE_QTGL - m_curWinWidth = m_videoSurface.width(); - m_curWinHeight = m_videoSurface.height(); -#endif - // No recalculation is performed if all parameters are unchanged - CaptureWin::resizeScaleCrop(); - - // Get/copy (TODO: remove CaptureWinGLEngine and use direct or use pointer) -#ifdef HAVE_QTGL m_videoSurface.setFrame(m_frameInfo.frameWidth, m_frameInfo.frameHeight, m_cropInfo.cropW, m_cropInfo.cropH, m_frameInfo.format, m_frameInfo.planeData[0], m_frameInfo.planeData[1]); #endif + m_frameInfo.updated = false; + m_cropInfo.updated = false; } bool CaptureWinGL::hasNativeFormat(__u32 format) diff --git a/utils/qv4l2/capture-win-qt.cpp b/utils/qv4l2/capture-win-qt.cpp index eb1a0c4..54de552 100644 --- a/utils/qv4l2/capture-win-qt.cpp +++ b/utils/qv4l2/capture-win-qt.cpp @@ -25,10 +25,7 @@ CaptureWinQt::CaptureWinQt() : m_supportedFormat(false), m_filled(false) { - CaptureWin::buildWindow(&m_videoSurface); - m_scaledSize.setWidth(0); - m_scaledSize.setHeight(0); } CaptureWinQt::~CaptureWinQt() @@ -40,8 +37,10 @@ void CaptureWinQt::resizeEvent(QResizeEvent *event) { m_curWinWidth = m_videoSurface.width(); m_curWinHeight = m_videoSurface.height(); + m_frameInfo.updated = true; CaptureWin::resizeScaleCrop(); paintFrame(); + event->accept(); } void CaptureWinQt::setRenderFrame() @@ -54,33 +53,27 @@ void CaptureWinQt::setRenderFrame() if (!m_supportedFormat) dstFmt = QImage::Format_RGB888; - if (m_frame->width() != m_frameInfo.frameWidth - || m_frame->height() != m_frameInfo.frameHeight - || m_frame->format() != dstFmt) { + if (m_frameInfo.updated || m_frame->format() != dstFmt) { delete m_frame; m_frame = new QImage(m_frameInfo.frameWidth, m_frameInfo.frameHeight, dstFmt); - // Force a recalculation by setting this to 0. - m_cropInfo.bytes = 0; - - m_curWinWidth = m_videoSurface.width(); - m_curWinHeight = m_videoSurface.height(); - CaptureWin::resizeScaleCrop(); } + m_frameInfo.updated = false; + paintFrame(); } void CaptureWinQt::paintFrame() { if (m_cropInfo.updated) { - m_cropInfo.offset = m_cropInfo.cropH * (m_frame->depth() / 8) - * m_frameInfo.frameWidth + m_cropInfo.cropW * (m_frame->depth() / 8); - - // Even though the values above can be valid, it might be that there is no - // data at all. This makes sure that it is. - m_cropInfo.bytes = m_cropInfo.height * m_cropInfo.width - * (m_frame->depth() / 8); - m_cropInfo.updated = 0; + m_cropInfo.offset = m_cropInfo.cropH * (m_frame->depth() / 8) + * m_frameInfo.frameWidth + m_cropInfo.cropW * (m_frame->depth() / 8); + + // Even though the values above can be valid, it might be that there is no + // data at all. This makes sure that it is. + m_cropInfo.bytes = m_cropInfo.height * m_cropInfo.width + * (m_frame->depth() / 8); + m_cropInfo.updated = false; } if (!m_supportedFormat || !m_cropInfo.bytes) { diff --git a/utils/qv4l2/capture-win.cpp b/utils/qv4l2/capture-win.cpp index ad769bc..be9a3d2 100644 --- a/utils/qv4l2/capture-win.cpp +++ b/utils/qv4l2/capture-win.cpp @@ -49,6 +49,8 @@ CaptureWin::CaptureWin() : m_frameInfo.frameWidth = 0; m_frameInfo.planeData[0] = NULL; m_frameInfo.planeData[1] = NULL; + m_scaledSize.setWidth(0); + m_scaledSize.setHeight(0); m_cropInfo.cropH = 0; m_cropInfo.cropW = 0; m_cropInfo.height = 0; @@ -70,15 +72,21 @@ CaptureWin::~CaptureWin() } void CaptureWin::setFrame(int width, int height, __u32 format, - unsigned char *data, unsigned char *data2, const QString &info) + unsigned char *data, unsigned char *data2, const QString &info) { - m_frameInfo.frameHeight = height; - m_frameInfo.frameWidth = width; - m_frameInfo.format = format; - m_frameInfo.planeData[0] = data; - m_frameInfo.planeData[1] = data2; - m_frameInfo.info = info; - + m_frameInfo.planeData[0] = data; + m_frameInfo.planeData[1] = data2; + m_frameInfo.info = info; + + m_frameInfo.updated = false; + if (width != m_frameInfo.frameWidth || height != m_frameInfo.frameHeight + || format != m_frameInfo.format) { + m_frameInfo.frameHeight = height; + m_frameInfo.frameWidth = width; + m_frameInfo.format = format; + m_frameInfo.updated = true; + resizeScaleCrop(); + } m_information.setText(m_frameInfo.info); setRenderFrame(); @@ -154,12 +162,10 @@ int CaptureWin::cropWidth(int width, int height) void CaptureWin::resizeScaleCrop() { - m_scaledSize = scaleFrameSize(QSize(m_curWinWidth, m_curWinHeight), - QSize(m_frameInfo.frameWidth, m_frameInfo.frameHeight)); - m_cropInfo.updated = 0; - if (!m_cropInfo.bytes - || m_cropInfo.cropH != cropHeight(m_frameInfo.frameWidth, m_frameInfo.frameHeight) - || m_cropInfo.cropW != cropWidth(m_frameInfo.frameWidth, m_frameInfo.frameHeight)) { + m_cropInfo.updated = 0; + if (m_frameInfo.updated) { + m_scaledSize = scaleFrameSize(QSize(m_curWinWidth, m_curWinHeight), + QSize(m_frameInfo.frameWidth, m_frameInfo.frameHeight)); m_cropInfo.cropH = cropHeight(m_frameInfo.frameWidth, m_frameInfo.frameHeight); m_cropInfo.cropW = cropWidth(m_frameInfo.frameWidth, m_frameInfo.frameHeight); m_cropInfo.height = m_frameInfo.frameHeight - (m_cropInfo.cropH * 2); diff --git a/utils/qv4l2/capture-win.h b/utils/qv4l2/capture-win.h index d6b4b16..1edeae7 100644 --- a/utils/qv4l2/capture-win.h +++ b/utils/qv4l2/capture-win.h @@ -50,11 +50,12 @@ struct cropInfo { }; struct frameInfo { - __u32 format; + __u32 format; int frameHeight; int frameWidth; - unsigned char *planeData[2]; - QString info; + unsigned char *planeData[2]; + QString info; + bool updated; }; class CaptureWin : public QWidget -- 2.7.4