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>
This commit is contained in:
Anatoly Stolbov
2016-07-27 11:01:51 +03:00
committed by Yoann Lopes
parent 7788feea5d
commit d7d31d63db

View File

@@ -261,19 +261,30 @@ 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.");
if (closestResolution.isValid()) {
adjustedViewfinderResolution = closestResolution;
qWarning("Using closest viewfinder resolution.");
} else {
return;
}
}
}
if (currentViewfinderResolution != adjustedViewfinderResolution) {
if (m_videoOutput)