qv4l2: add video scaling for CaptureWin
authorBård Eirik Winther <bwinther@cisco.com>
Mon, 5 Aug 2013 07:56:55 +0000 (07:56 +0000)
committerHans Verkuil <hans.verkuil@cisco.com>
Thu, 8 Aug 2013 07:49:15 +0000 (09:49 +0200)
Signed-off-by: Bård Eirik Winther <bwinther@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/qv4l2/qv4l2.cpp

index 68fcf45..fd52788 100644 (file)
@@ -137,9 +137,20 @@ ApplicationWindow::ApplicationWindow() :
        toolBar->addSeparator();
        toolBar->addAction(quitAct);
 
+       m_scalingAct = new QAction("Enable Video Scaling", this);
+       m_scalingAct->setStatusTip("Scale video frames to match window size if set");
+       m_scalingAct->setCheckable(true);
+       m_scalingAct->setChecked(true);
+       connect(m_scalingAct, SIGNAL(toggled(bool)), this, SLOT(enableScaling(bool)));
+       m_resetScalingAct = new QAction("Resize to Frame Size", this);
+       m_resetScalingAct->setStatusTip("Resizes the capture window to match frame size");
+
        QMenu *captureMenu = menuBar()->addMenu("&Capture");
        captureMenu->addAction(m_capStartAct);
        captureMenu->addAction(m_showFramesAct);
+       captureMenu->addAction(m_scalingAct);
+       captureMenu->addAction(m_resetScalingAct);
+
 
        if (CaptureWinGL::isSupported()) {
                m_renderMethod = QV4L2_RENDER_GL;
@@ -351,7 +362,9 @@ void ApplicationWindow::newCaptureWin()
                break;
        }
 
-       connect(m_capture, SIGNAL(close()), this, SLOT(closeCaptureWin()));
+       m_capture->enableScaling(m_scalingAct->isChecked());
+        connect(m_capture, SIGNAL(close()), this, SLOT(closeCaptureWin()));
+       connect(m_resetScalingAct, SIGNAL(triggered()), m_capture, SLOT(resetSize()));
 }
 
 void ApplicationWindow::capVbiFrame()
@@ -791,6 +804,12 @@ void ApplicationWindow::stopOutput()
 {
 }
 
+void ApplicationWindow::enableScaling(bool enable)
+{
+       if (m_capture != NULL)
+               m_capture->enableScaling(enable);
+}
+
 void ApplicationWindow::startAudio()
 {
 #ifdef HAVE_ALSA
@@ -901,7 +920,7 @@ void ApplicationWindow::capStart(bool start)
                        m_vbiHeight = fmt.fmt.vbi.count[0] + fmt.fmt.vbi.count[1];
                m_vbiSize = m_vbiWidth * m_vbiHeight;
                m_frameData = new unsigned char[m_vbiSize];
-               m_capture->setMinimumSize(m_vbiWidth, m_vbiHeight);
+               m_capture->resize(m_vbiWidth, m_vbiHeight);
                m_capImage = new QImage(m_vbiWidth, m_vbiHeight, dstFmt);
                m_capImage->fill(0);
                m_capture->setFrame(m_capImage->width(), m_capImage->height(),
@@ -931,8 +950,8 @@ void ApplicationWindow::capStart(bool start)
                m_mustConvert = false;
        } else {
                m_mustConvert = true;
+               
                v4l2_format copy = m_capSrcFormat;
-
                v4lconvert_try_format(m_convertData, &m_capDestFormat, &m_capSrcFormat);
                // v4lconvert_try_format sometimes modifies the source format if it thinks
                // that there is a better format available. Restore our selected source
@@ -940,7 +959,7 @@ void ApplicationWindow::capStart(bool start)
                m_capSrcFormat = copy;
        }
 
-       m_capture->setMinimumSize(dstPix.width, dstPix.height);
+       m_capture->resize(dstPix.width, dstPix.height);
        // Ensure that the initial image is large enough for native 32 bit per pixel formats
        if (dstPix.pixelformat == V4L2_PIX_FMT_RGB32 || dstPix.pixelformat == V4L2_PIX_FMT_BGR32)
                dstFmt = QImage::Format_ARGB32;