qv4l2: crop: take pixel aspect ratio into account.
authorHans Verkuil <hans.verkuil@cisco.com>
Fri, 4 Oct 2013 08:43:27 +0000 (10:43 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Fri, 4 Oct 2013 08:43:27 +0000 (10:43 +0200)
When cropping to a desired letterboxed/pillarboxed picture ratio you
need to take the pixel aspect ratio into account as well.

Also use 4.0/3.0 instead of 1.33 due to rounding errors (ditto for 1.57
and 1.78).

Finally the pillarbox ratio was calculated the wrong way around.

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

index 49cb3be..74581e4 100644 (file)
@@ -80,20 +80,21 @@ void CaptureWin::resetSize()
 
 int CaptureWin::cropHeight(int width, int height)
 {
+       double realWidth = width * m_pixelAspectRatio;
        int validHeight;
 
        switch (m_cropMethod) {
        case QV4L2_CROP_W149:
-               validHeight = (int)(width / 1.57);
+               validHeight = realWidth / (14.0 / 9.0);
                break;
        case QV4L2_CROP_W169:
-               validHeight = (int)(width / 1.78);
+               validHeight = realWidth / (16.0 / 9.0);
                break;
        case QV4L2_CROP_C185:
-               validHeight = (int)(width / 1.85);
+               validHeight = realWidth / 1.85;
                break;
        case QV4L2_CROP_C239:
-               validHeight = (int)(width / 2.39);
+               validHeight = realWidth / 2.39;
                break;
        case QV4L2_CROP_TB:
                validHeight = height - 2;
@@ -113,7 +114,7 @@ int CaptureWin::cropWidth(int width, int height)
        if (m_cropMethod != QV4L2_CROP_P43)
                return 0;
 
-       int validWidth = (int)(height / 1.33);
+       int validWidth = (height * 4.0 / 3.0) / m_pixelAspectRatio;
 
        if (validWidth < MIN_WIN_SIZE_WIDTH || validWidth >= width)
                return 0;
index be33463..a0bc75f 100644 (file)
@@ -152,11 +152,11 @@ GeneralTab::GeneralTab(const QString &device, v4l2 &fd, int n, QWidget *parent)
                m_crop = new QComboBox(parent);
                m_crop->addItem("None");
                m_crop->addItem("Top and Bottom Line");
-               m_crop->addItem("Widescreen 14:9");
-               m_crop->addItem("Widescreen 16:9");
-               m_crop->addItem("Cinema 1.85:1");
-               m_crop->addItem("Cinema 2.39:1");
-               m_crop->addItem("Traditional 4:3");
+               m_crop->addItem("Widescreen 14:9 (Letterbox)");
+               m_crop->addItem("Widescreen 16:9 (Letterbox)");
+               m_crop->addItem("Cinema 1.85:1 (Letterbox)");
+               m_crop->addItem("Cinema 2.39:1 (Letterbox)");
+               m_crop->addItem("Traditional 4:3 (Pillarbox)");
 
                addLabel("Cropping");
                addWidget(m_crop);