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:
committed by
Yoann Lopes
parent
7788feea5d
commit
d7d31d63db
@@ -261,19 +261,30 @@ void QAndroidCameraSession::adjustViewfinderSize(const QSize &captureSize, bool
|
|||||||
// search for viewfinder resolution with the same aspect ratio
|
// search for viewfinder resolution with the same aspect ratio
|
||||||
const qreal aspectRatio = qreal(captureSize.width()) / qreal(captureSize.height());
|
const qreal aspectRatio = qreal(captureSize.width()) / qreal(captureSize.height());
|
||||||
QList<QSize> previewSizes = m_camera->getSupportedPreviewSizes();
|
QList<QSize> previewSizes = m_camera->getSupportedPreviewSizes();
|
||||||
|
qreal minAspectDiff = 1;
|
||||||
|
QSize closestResolution;
|
||||||
for (int i = previewSizes.count() - 1; i >= 0; --i) {
|
for (int i = previewSizes.count() - 1; i >= 0; --i) {
|
||||||
const QSize &size = previewSizes.at(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;
|
adjustedViewfinderResolution = size;
|
||||||
break;
|
break;
|
||||||
|
} else if (minAspectDiff > qAbs(sizeAspect - aspectRatio)) {
|
||||||
|
closestResolution = size;
|
||||||
|
minAspectDiff = qAbs(sizeAspect - aspectRatio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!adjustedViewfinderResolution.isValid()) {
|
if (!adjustedViewfinderResolution.isValid()) {
|
||||||
qWarning("Cannot find a viewfinder resolution matching the capture aspect ratio.");
|
qWarning("Cannot find a viewfinder resolution matching the capture aspect ratio.");
|
||||||
|
if (closestResolution.isValid()) {
|
||||||
|
adjustedViewfinderResolution = closestResolution;
|
||||||
|
qWarning("Using closest viewfinder resolution.");
|
||||||
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (currentViewfinderResolution != adjustedViewfinderResolution) {
|
if (currentViewfinderResolution != adjustedViewfinderResolution) {
|
||||||
if (m_videoOutput)
|
if (m_videoOutput)
|
||||||
|
|||||||
Reference in New Issue
Block a user