summaryrefslogtreecommitdiffstats
path: root/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@theqtcompany.com>2015-02-09 17:37:10 +0100
committerYoann Lopes <yoann.lopes@theqtcompany.com>2015-02-11 14:11:23 +0000
commit06259f1dfbd9cb2ebd58bba59381a42dc8a758df (patch)
tree6070b71086233ebdcb1b5912b7f0f47d67e1f934 /src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
parent4ce9d89d7a315100393aeae9998a8f9e838650ca (diff)
Android: fix adjusting camera viewfinder resolution.
The viewfinder resolution must be in the same aspect ratio as the image capture resolution. When adjusting the viewfinder resolution to comply with that restriction, we assumed that the ratios had to be exactly equal. Though, in practice, there can be a small difference. For example for resolutions 2592x1952 (ratio=1.3278) and resolution 640x480 (ratio=1.3333). Task-number: QTBUG-37525 Change-Id: Ia5a6dd3a4a6d901b24bf74f8aa4e34bffe61f89b Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
Diffstat (limited to 'src/plugins/android/src/mediacapture/qandroidcamerasession.cpp')
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerasession.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
index 5a645bdf5..1ad28e1c8 100644
--- a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
+++ b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
@@ -276,33 +276,38 @@ void QAndroidCameraSession::adjustViewfinderSize(const QSize &captureSize, bool
if (!m_camera)
return;
- QSize viewfinderResolution = m_camera->previewSize();
+ QSize currentViewfinderResolution = m_camera->previewSize();
const qreal aspectRatio = qreal(captureSize.width()) / qreal(captureSize.height());
- if (viewfinderResolution.isValid() &&
- qFuzzyCompare(aspectRatio,
- qreal(viewfinderResolution.width()) / viewfinderResolution.height())) {
+ if (currentViewfinderResolution.isValid() &&
+ qAbs(aspectRatio - (qreal(currentViewfinderResolution.width()) / currentViewfinderResolution.height())) < 0.01) {
return;
}
+ QSize adjustedViewfinderResolution;
QList<QSize> previewSizes = m_camera->getSupportedPreviewSizes();
for (int i = previewSizes.count() - 1; i >= 0; --i) {
const QSize &size = previewSizes.at(i);
// search for viewfinder resolution with the same aspect ratio
- if (qFuzzyCompare(aspectRatio, (static_cast<qreal>(size.width())/static_cast<qreal>(size.height())))) {
- viewfinderResolution = size;
+ if (qAbs(aspectRatio - (qreal(size.width()) / size.height())) < 0.01) {
+ adjustedViewfinderResolution = size;
break;
}
}
- if (m_camera->previewSize() != viewfinderResolution) {
+ if (!adjustedViewfinderResolution.isValid()) {
+ qWarning("Cannot find a viewfinder resolution matching the capture aspect ratio.");
+ return;
+ }
+
+ if (currentViewfinderResolution != adjustedViewfinderResolution) {
if (m_videoOutput)
- m_videoOutput->setVideoSize(viewfinderResolution);
+ m_videoOutput->setVideoSize(adjustedViewfinderResolution);
// if preview is started, we have to stop it first before changing its size
if (m_previewStarted && restartPreview)
m_camera->stopPreview();
- m_camera->setPreviewSize(viewfinderResolution);
+ m_camera->setPreviewSize(adjustedViewfinderResolution);
// restart preview
if (m_previewStarted && restartPreview)