aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOve Brynestad <ovebryne@cisco.com>2014-08-04 15:31:29 +0200
committerHans Verkuil <hans.verkuil@cisco.com>2014-08-08 11:12:59 +0200
commit3851b2fb91fc6867f01149b4c5bb824324ba3d69 (patch)
treeaedb71eb8dec57baddf4132a8873ee459c38dd90
parent48c8f3b4371afc02b57c525e1691cd4090f91261 (diff)
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 <ovebryne@cisco.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
-rw-r--r--utils/qv4l2/capture-win.cpp54
-rw-r--r--utils/qv4l2/capture-win.h14
2 files changed, 26 insertions, 42 deletions
diff --git a/utils/qv4l2/capture-win.cpp b/utils/qv4l2/capture-win.cpp
index d388b03f..82431cd1 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 7330efe6..fb048c5c 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.

Privacy Policy