qv4l2: moved scaling calculations from setRenderFrame
authorOve Brynestad <ovebryne@cisco.com>
Tue, 8 Jul 2014 13:39:24 +0000 (15:39 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Fri, 11 Jul 2014 13:32:00 +0000 (15:32 +0200)
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 <ovebryne@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/qv4l2/capture-win-gl.cpp
utils/qv4l2/capture-win-qt.cpp
utils/qv4l2/capture-win.cpp
utils/qv4l2/capture-win.h

index ed9d87f..013e21d 100644 (file)
@@ -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)
index eb1a0c4..54de552 100644 (file)
@@ -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) {
index ad769bc..be9a3d2 100644 (file)
@@ -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);
index d6b4b16..1edeae7 100644 (file)
@@ -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