From 3851b2fb91fc6867f01149b4c5bb824324ba3d69 Mon Sep 17 00:00:00 2001 From: Ove Brynestad Date: Mon, 4 Aug 2014 15:31:29 +0200 Subject: [PATCH] qv4l2: refactored cropSize to deliver cropped size cropFrameSize returned the delta between the full frame and the cropped frame instead of just returning the cropped frame. This made the code hard to read, so switch to returning the cropped frame. Signed-off-by: Ove Brynestad Signed-off-by: Hans Verkuil --- utils/qv4l2/capture-win.cpp | 54 ++++++++++++++++++--------------------------- utils/qv4l2/capture-win.h | 14 +++++------- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/utils/qv4l2/capture-win.cpp b/utils/qv4l2/capture-win.cpp index d388b03..82431cd 100644 --- a/utils/qv4l2/capture-win.cpp +++ b/utils/qv4l2/capture-win.cpp @@ -123,51 +123,41 @@ void CaptureWin::resetSize() setWindowSize(resetFrameSize); } -QSize CaptureWin::cropFrameSize(QSize size) +QSize CaptureWin::cropSize(QSize size) { - // Crop width - int validWidth; - - if (m_cropMethod == QV4L2_CROP_P43) - validWidth = (size.height() * 4.0 / 3.0) / m_pixelAspectRatio; - else - validWidth = size.width(); // no width crop - - if (validWidth < MIN_WIN_SIZE_WIDTH || validWidth >= size.width()) - validWidth = size.width(); // no width crop - - int deltaWidth = (size.width() - validWidth) / 2; - - // Crop height + QSize croppedSize = size; double realWidth = size.width() * m_pixelAspectRatio; - int validHeight; + double realHeight = size.height() / m_pixelAspectRatio; switch (m_cropMethod) { + case QV4L2_CROP_P43: + croppedSize.setWidth(realHeight * 4.0 / 3.0); + break; case QV4L2_CROP_W149: - validHeight = realWidth / (14.0 / 9.0); + croppedSize.setHeight(realWidth / (14.0 / 9.0)); break; case QV4L2_CROP_W169: - validHeight = realWidth / (16.0 / 9.0); + croppedSize.setHeight(realWidth / (16.0 / 9.0)); break; case QV4L2_CROP_C185: - validHeight = realWidth / 1.85; + croppedSize.setHeight(realWidth / 1.85); break; case QV4L2_CROP_C239: - validHeight = realWidth / 2.39; + croppedSize.setHeight(realWidth / 2.39); break; case QV4L2_CROP_TB: - validHeight = size.height() - 2; + croppedSize.setHeight(size.height() - 2); break; default: - validHeight = size.height(); // No height crop + ; // No cropping } - if (validHeight < MIN_WIN_SIZE_HEIGHT || validHeight >= size.height()) - validHeight = size.height(); // No height crop - - int deltaHeight = (size.height() - validHeight) / 2; + if (croppedSize.width() < MIN_WIN_SIZE_WIDTH || croppedSize.width() >= size.width()) + croppedSize.setWidth(size.width()); + if (croppedSize.height() < MIN_WIN_SIZE_HEIGHT || croppedSize.height() >= size.height()) + croppedSize.setHeight(size.height()); - return QSize(deltaWidth, deltaHeight); + return croppedSize; } void CaptureWin::updateSize() @@ -175,8 +165,8 @@ void CaptureWin::updateSize() m_crop.updated = false; if (m_frame.updated) { m_scaledSize = scaleFrameSize(m_windowSize, m_frame.size); - m_crop.delta = cropFrameSize(m_frame.size); - m_crop.size = m_frame.size - 2 * m_crop.delta; + m_crop.size = cropSize(m_frame.size); + m_crop.delta = (m_frame.size - m_crop.size) / 2; m_crop.updated = true; } } @@ -234,8 +224,7 @@ void CaptureWin::setWindowSize(QSize frameSize) QDesktopWidget *screen = QApplication::desktop(); QRect resolution = screen->screenGeometry(); - QSize windowSize = margins + pixelAspectFrameSize(frameSize) - - 2 * cropFrameSize(frameSize); + QSize windowSize = pixelAspectFrameSize(cropSize(frameSize)) + margins; if (windowSize.width() > resolution.width()) windowSize.setWidth(resolution.width()); @@ -256,8 +245,7 @@ void CaptureWin::setWindowSize(QSize frameSize) QSize CaptureWin::scaleFrameSize(QSize window, QSize frame) { - QSize croppedSize = frame - 2 * cropFrameSize(frame); - QSize actualSize = pixelAspectFrameSize(croppedSize); + QSize actualSize = pixelAspectFrameSize(cropSize(frame)); if (!m_enableScaling) { window.setWidth(actualSize.width()); diff --git a/utils/qv4l2/capture-win.h b/utils/qv4l2/capture-win.h index 7330efe..fb048c5 100644 --- a/utils/qv4l2/capture-win.h +++ b/utils/qv4l2/capture-win.h @@ -129,19 +129,15 @@ public: static QSize scaleFrameSize(QSize window, QSize frame); /** - * @brief Get the number of pixels to crop. + * @brief Crop size * - * When cropping is applied this gives the number of pixels to - * remove from top and bottom. To get total multiply the return - * value by 2. + * Reduces size width or height according to m_cropMethod * - * @param size Frame size - * @return The size (no of height & width pixels) to remove when cropping + * @param size Input size + * @return Cropped size * - * @note The width and height must be original frame size - * to ensure that the cropping is done correctly. */ - static QSize cropFrameSize(QSize size); + static QSize cropSize(QSize size); /** * @brief Get the frame size when aspect ratio is applied and increases size. -- 2.7.4