summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnatoly Stolbov <a.stolbov@netris.ru>2016-07-27 11:01:51 +0300
committerYoann Lopes <yoann.lopes@qt.io>2016-07-27 13:15:53 +0000
commitd7d31d63db5f0029a4a5e24d998601baee8bade0 (patch)
tree6d2f243606b8d15b6c1f382dee339f67ca77fbd5
parent7788feea5d55418ab61681e122c1d2d29f7bddce (diff)
Android camera: use closest viewfinder resolution
For some cameras difference between preview aspect rate and capture aspect rate is more than 0.01. Therefore it is better to use preview size with closest aspect rate. Task-number: QTBUG-50813 Change-Id: I1284c8ec2be1aa160a656e396a52960fa06aaa56 Reviewed-by: Yoann Lopes <yoann.lopes@qt.io>
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerasession.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
index 7b065c8c..df9f0367 100644
--- a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
+++ b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
@@ -261,17 +261,28 @@ void QAndroidCameraSession::adjustViewfinderSize(const QSize &captureSize, bool
// search for viewfinder resolution with the same aspect ratio
const qreal aspectRatio = qreal(captureSize.width()) / qreal(captureSize.height());
QList<QSize> previewSizes = m_camera->getSupportedPreviewSizes();
+ qreal minAspectDiff = 1;
+ QSize closestResolution;
for (int i = previewSizes.count() - 1; i >= 0; --i) {
const QSize &size = previewSizes.at(i);
- if (qAbs(aspectRatio - (qreal(size.width()) / size.height())) < 0.01) {
+ const qreal sizeAspect = qreal(size.width()) / size.height();
+ if (qFuzzyCompare(aspectRatio, sizeAspect)) {
adjustedViewfinderResolution = size;
break;
+ } else if (minAspectDiff > qAbs(sizeAspect - aspectRatio)) {
+ closestResolution = size;
+ minAspectDiff = qAbs(sizeAspect - aspectRatio);
}
}
if (!adjustedViewfinderResolution.isValid()) {
qWarning("Cannot find a viewfinder resolution matching the capture aspect ratio.");
- return;
+ if (closestResolution.isValid()) {
+ adjustedViewfinderResolution = closestResolution;
+ qWarning("Using closest viewfinder resolution.");
+ } else {
+ return;
+ }
}
}