From ae1dee94de5f4a496e74be67681320aab9abd020 Mon Sep 17 00:00:00 2001 From: Ove Brynestad Date: Thu, 7 Aug 2014 12:58:39 +0200 Subject: [PATCH] qv4l2: Fixed cropping bug Pillar/letterboxing was assumed given by m_cropMethod, but is also depending on pixelAspectRatio and frame aspect ratio Signed-off-by: Ove Brynestad Signed-off-by: Hans Verkuil --- utils/qv4l2/capture-win.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/utils/qv4l2/capture-win.cpp b/utils/qv4l2/capture-win.cpp index 82431cd..66bfa24 100644 --- a/utils/qv4l2/capture-win.cpp +++ b/utils/qv4l2/capture-win.cpp @@ -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()) -- 2.7.4