qv4l2: Add option to enable linear scaling filter
authorOve Brynestad <ovebryne@cisco.com>
Fri, 8 Aug 2014 06:22:48 +0000 (08:22 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Fri, 8 Aug 2014 10:17:28 +0000 (12:17 +0200)
New menu option to enable linear scaling filter when using OpenGL. Default is to
use nearest neighbour

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-gl.h
utils/qv4l2/capture-win-qt.h
utils/qv4l2/capture-win.cpp
utils/qv4l2/capture-win.h
utils/qv4l2/qv4l2.cpp
utils/qv4l2/qv4l2.h

index 6132e3b..9a4ceff 100644 (file)
@@ -119,6 +119,13 @@ void CaptureWinGL::setBlending(bool enable)
 #endif
 }
 
+void CaptureWinGL::setLinearFilter(bool enable)
+{
+#ifdef HAVE_QTGL
+       m_videoSurface.setLinearFilter(enable);
+#endif
+}
+
 #ifdef HAVE_QTGL
 CaptureWinGLEngine::CaptureWinGLEngine() :
        m_frameWidth(0),
@@ -132,7 +139,9 @@ CaptureWinGLEngine::CaptureWinGLEngine() :
        m_formatChange(false),
        m_frameFormat(0),
        m_frameData(NULL),
-       m_blending(false)
+       m_blending(false),
+       m_mag_filter(GL_NEAREST),
+       m_min_filter(GL_NEAREST)
 {
        m_glfunction.initializeGLFunctions(context());
 }
@@ -204,6 +213,19 @@ void CaptureWinGLEngine::setField(unsigned field)
        m_formatChange = true;
 }
 
+void CaptureWinGLEngine::setLinearFilter(bool enable)
+{
+       if (enable) {
+               m_mag_filter = GL_LINEAR;
+               m_min_filter = GL_LINEAR;
+       }
+       else {
+               m_mag_filter = GL_NEAREST;
+               m_min_filter = GL_NEAREST;
+       }
+       m_formatChange = true;
+}
+
 void CaptureWinGLEngine::clearShader()
 {
        glDeleteTextures(m_screenTextureCount, m_screenTexture);
@@ -459,8 +481,8 @@ void CaptureWinGLEngine::paintGL()
 void CaptureWinGLEngine::configureTexture(size_t idx)
 {
        glBindTexture(GL_TEXTURE_2D, m_screenTexture[idx]);
-       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_min_filter);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_mag_filter);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 }
index bd7d6d6..a20e626 100644 (file)
@@ -50,6 +50,7 @@ public:
        void setDisplayColorspace(unsigned colorspace);
        void setField(unsigned field);
        void setBlending(bool enable) { m_blending = enable; }
+       void setLinearFilter(bool enable);
 
 protected:
        void paintGL();
@@ -99,6 +100,8 @@ private:
        QGLShaderProgram m_shaderProgram;
        bool m_haveFramebufferSRGB;
        bool m_blending;
+       GLint m_mag_filter;
+       GLint m_min_filter;
 };
 
 #endif
@@ -116,6 +119,7 @@ public:
        void setField(unsigned field);
        void setDisplayColorspace(unsigned colorspace);
        void setBlending(bool enable);
+       void setLinearFilter(bool enable);
 
 protected:
        void resizeEvent(QResizeEvent *event);
index 0c92ce0..cb477dd 100644 (file)
@@ -40,6 +40,7 @@ public:
        void setField(unsigned field) {}
        void setDisplayColorspace(unsigned colorspace) {}
        void setBlending(bool enable) {}
+       void setLinearFilter(bool enable) {}
 
 protected:
        void resizeEvent(QResizeEvent *event);
index 66bfa24..fb7867b 100644 (file)
@@ -345,6 +345,7 @@ void CaptureWin::customMenuRequested(QPoint pos)
        
        menu->addAction(m_appWin->m_resetScalingAct);
        menu->addAction(m_appWin->m_useBlendingAct);
+       menu->addAction(m_appWin->m_useLinearAct);
        menu->addAction(m_appWin->m_snapshotAct);
        menu->addAction(m_appWin->m_showFramesAct);
        
index fb048c5..df28b33 100644 (file)
@@ -73,6 +73,7 @@ public:
        virtual void setField(unsigned field) = 0;
        virtual void setDisplayColorspace(unsigned colorspace) = 0;
        virtual void setBlending(bool enable) = 0;
+       virtual void setLinearFilter(bool enable) = 0;
        void setCropMethod(CropMethod crop);
        void makeFullScreen(bool);
        QAction *m_exitFullScreen;
index 0e168e8..fafdf88 100644 (file)
@@ -184,6 +184,14 @@ ApplicationWindow::ApplicationWindow() :
                m_useBlendingAct->setChecked(false);
                connect(m_useBlendingAct, SIGNAL(toggled(bool)), this, SLOT(setBlending(bool)));
                captureMenu->addAction(m_useBlendingAct);
+
+               m_useLinearAct = new QAction("Enable &Linear filter", this);
+               m_useLinearAct->setStatusTip("Enable linear scaling filter");
+               m_useLinearAct->setCheckable(true);
+               m_useLinearAct->setChecked(false);
+               connect(m_useLinearAct, SIGNAL(toggled(bool)), this, SLOT(setLinearFilter(bool)));
+               captureMenu->addAction(m_useLinearAct);
+
        } else {
                m_renderMethod = QV4L2_RENDER_QT;
        }
@@ -343,6 +351,12 @@ void ApplicationWindow::setBlending(bool checked)
                m_capture->setBlending(checked);
 }
 
+void ApplicationWindow::setLinearFilter(bool checked)
+{
+       if (m_capture)
+               m_capture->setLinearFilter(checked);
+}
+
 void ApplicationWindow::setAudioBufferSize()
 {
        bool ok;
index fd64868..d948cd4 100644 (file)
@@ -140,6 +140,7 @@ private slots:
        void saveRaw(bool);
        void setRenderMethod(bool);
        void setBlending(bool);
+       void setLinearFilter(bool);
        void traceIoctls(bool);
        void changeAudioDevice();
 
@@ -186,6 +187,7 @@ public:
        void updateLimRGBRange();
        QAction *m_resetScalingAct;
        QAction *m_useBlendingAct;
+       QAction *m_useLinearAct;
        QAction *m_snapshotAct;
        QAction *m_showFramesAct;