qv4l2: Fixed cropping bug
authorOve Brynestad <ovebryne@cisco.com>
Thu, 7 Aug 2014 10:58:39 +0000 (12:58 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Fri, 8 Aug 2014 09:13:03 +0000 (11:13 +0200)
Pillar/letterboxing was assumed given by m_cropMethod, but is also depending on
pixelAspectRatio and frame aspect ratio

Signed-off-by: Ove Brynestad <ovebryne@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/qv4l2/capture-win.cpp

index 82431cd..66bfa24 100644 (file)
@@ -128,28 +128,36 @@ QSize CaptureWin::cropSize(QSize size)
        QSize croppedSize = size;
        double realWidth = size.width() * m_pixelAspectRatio;
        double realHeight = size.height() / m_pixelAspectRatio;
+       double aspectRatio = 1;
 
        switch (m_cropMethod) {
        case QV4L2_CROP_P43:
-               croppedSize.setWidth(realHeight * 4.0 / 3.0);
+               aspectRatio = 4.0 / 3.0;
                break;
        case QV4L2_CROP_W149:
-               croppedSize.setHeight(realWidth / (14.0 / 9.0));
+               aspectRatio = 14.0 / 9.0;
                break;
        case QV4L2_CROP_W169:
-               croppedSize.setHeight(realWidth / (16.0 / 9.0));
+               aspectRatio = 16.0 / 9.0;
                break;
        case QV4L2_CROP_C185:
-               croppedSize.setHeight(realWidth / 1.85);
+               aspectRatio = 1.85;
                break;
        case QV4L2_CROP_C239:
-               croppedSize.setHeight(realWidth / 2.39);
+               aspectRatio = 2.39;
                break;
        case QV4L2_CROP_TB:
                croppedSize.setHeight(size.height() - 2);
                break;
        default:
-               ;  // No cropping
+               break;  // No cropping
+       }
+
+       if ((m_cropMethod != QV4L2_CROP_TB) && (m_cropMethod != QV4L2_CROP_NONE)) {
+               if (realWidth / size.height() < aspectRatio)
+                       croppedSize.setHeight(realWidth / aspectRatio);
+               else
+                       croppedSize.setWidth(realHeight * aspectRatio);
        }
 
        if (croppedSize.width() < MIN_WIN_SIZE_WIDTH || croppedSize.width() >= size.width())