qv4l2: moved crop calculation out of GL renderer
authorOve Brynestad <ovebryne@cisco.com>
Mon, 7 Jul 2014 14:32:41 +0000 (16:32 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Fri, 11 Jul 2014 13:31:58 +0000 (15:31 +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-gl.h

index 49ebc9c..7644094 100644 (file)
@@ -58,6 +58,12 @@ void CaptureWinGL::resizeEvent(QResizeEvent *event)
 
 void CaptureWinGL::setRenderFrame()
 {
+       // Force a recalculation by setting this to 0.
+       m_cropInfo.bytes = 0;
+       m_curWinWidth  = m_videoSurface.width();
+       m_curWinHeight = m_videoSurface.height();
+       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,
@@ -116,10 +122,10 @@ void CaptureWinGL::setBlending(bool enable)
 
 #ifdef HAVE_QTGL
 CaptureWinGLEngine::CaptureWinGLEngine() :
-       m_frameHeight(0),
        m_frameWidth(0),
-       m_cropHeight(0),
-       m_cropWidth(0),
+       m_frameHeight(0),
+       m_WCrop(0),
+       m_HCrop(0),
        m_colorspace(V4L2_COLORSPACE_REC709),
        m_displayColorspace(V4L2_COLORSPACE_SRGB),
        m_screenTextureCount(0),
@@ -247,16 +253,16 @@ void CaptureWinGLEngine::resizeGL(int width, int height)
        glViewport(0, 0, width, height);
 }
 
-void CaptureWinGLEngine::setFrame(int width, int height, int cropWidth, int cropHeight,
+void CaptureWinGLEngine::setFrame(int width, int height, int WCrop, int HCrop,
                                  __u32 format, unsigned char *data, unsigned char *data2)
 {
        if (format != m_frameFormat || width != m_frameWidth || height != m_frameHeight
-           || cropWidth != m_cropWidth || cropHeight != m_cropHeight) {
+           || WCrop != m_WCrop || HCrop != m_HCrop) {
                m_formatChange = true;
                m_frameWidth = width;
                m_frameHeight = height;
-               m_cropWidth = cropWidth;
-               m_cropHeight = cropHeight;
+               m_WCrop = WCrop;
+               m_HCrop = HCrop;
                m_frameFormat = format;
        }
 
@@ -348,14 +354,14 @@ void CaptureWinGLEngine::changeShader()
 
 void CaptureWinGLEngine::paintFrame()
 {
-       float cropH = (float)CaptureWin::cropHeight(m_frameWidth, m_frameHeight) / m_frameHeight;
-       float cropW = (float)CaptureWin::cropWidth(m_frameWidth, m_frameHeight) / m_frameWidth;
+       float HCrop_f = (float)m_HCrop / m_frameHeight;
+       float WCrop_f = (float)m_WCrop / m_frameWidth;
 
        glBegin(GL_QUADS);
-       glTexCoord2f(cropW, cropH);               glVertex2f(0, 0);
-       glTexCoord2f(1.0f - cropW, cropH);        glVertex2f(m_frameWidth, 0);
-       glTexCoord2f(1.0f - cropW, 1.0f - cropH); glVertex2f(m_frameWidth, m_frameHeight);
-       glTexCoord2f(cropW, 1.0f - cropH);        glVertex2f(0, m_frameHeight);
+       glTexCoord2f(WCrop_f, HCrop_f);               glVertex2f(0, 0);
+       glTexCoord2f(1.0f - WCrop_f, HCrop_f);        glVertex2f(m_frameWidth, 0);
+       glTexCoord2f(1.0f - WCrop_f, 1.0f - HCrop_f); glVertex2f(m_frameWidth, m_frameHeight);
+       glTexCoord2f(WCrop_f, 1.0f - HCrop_f);        glVertex2f(0, m_frameHeight);
        glEnd();
 }
 
index c149b6b..043620c 100644 (file)
@@ -82,10 +82,10 @@ private:
        void configureTexture(size_t idx);
        void checkError(const char *msg);
 
-       int m_frameHeight;
        int m_frameWidth;
-       int m_cropHeight;
-       int m_cropWidth;
+       int m_frameHeight;
+       int m_WCrop;
+       int m_HCrop;
        unsigned m_colorspace;
        unsigned m_field;
        unsigned m_displayColorspace;