diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2019-03-19 14:12:07 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2019-03-28 07:05:30 +0000 |
commit | 80411380fbf614d833cd42dee80d01510326ccd3 (patch) | |
tree | 76d4498daff13cd229ecf629393178a96c75105e /src/plugins/winrt | |
parent | c296df781d9fa445bb4b1fcbb6f340e0d1db0c3a (diff) | |
download | qtmultimedia-80411380fbf614d833cd42dee80d01510326ccd3.tar.gz |
winrt: Use highest supported resolution for camera preview/image capture
Using the lowest supported resolution yields ugly results and has weird
side effects (green bars). If no resolution is explicitly given, we
should use the maximum supported solution for preview as well as
capture.
Task-number: QTBUG-72874
Change-Id: Ie0fae65180e66156c6de468f2cabb9122fe665ba
Reviewed-by: VaL Doroshchuk <valentyn.doroshchuk@qt.io>
Diffstat (limited to 'src/plugins/winrt')
-rw-r--r-- | src/plugins/winrt/qwinrtcameracontrol.cpp | 16 | ||||
-rw-r--r-- | src/plugins/winrt/qwinrtimageencodercontrol.cpp | 9 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/plugins/winrt/qwinrtcameracontrol.cpp b/src/plugins/winrt/qwinrtcameracontrol.cpp index c00f65624..ede3f6b04 100644 --- a/src/plugins/winrt/qwinrtcameracontrol.cpp +++ b/src/plugins/winrt/qwinrtcameracontrol.cpp @@ -1398,6 +1398,10 @@ HRESULT QWinRTCameraControl::onInitializationCompleted(IAsyncAction *, AsyncStat &captureResolutions); RETURN_HR_IF_FAILED("Failed to find a suitable video format"); + std::sort(captureResolutions.begin(), captureResolutions.end(), [](QSize size1, QSize size2) { + return size1.width() * size1.height() < size2.width() * size2.height(); + }); + // Set capture resolutions. d->imageEncoderControl->setSupportedResolutionsList(captureResolutions.toList()); const QSize captureResolution = d->imageEncoderControl->imageSettings().resolution(); @@ -1412,17 +1416,17 @@ HRESULT QWinRTCameraControl::onInitializationCompleted(IAsyncAction *, AsyncStat Q_ASSERT_SUCCEEDED(hr); // Set preview resolution. - QVector<QSize> filtered; + QSize maxSize; const float captureAspectRatio = float(captureResolution.width()) / captureResolution.height(); for (const QSize &resolution : qAsConst(previewResolutions)) { const float aspectRatio = float(resolution.width()) / resolution.height(); - if (qAbs(aspectRatio - captureAspectRatio) <= ASPECTRATIO_EPSILON) - filtered.append(resolution); + if ((qAbs(aspectRatio - captureAspectRatio) <= ASPECTRATIO_EPSILON) + && (maxSize.width() * maxSize.height() < resolution.width() * resolution.height())) { + maxSize = resolution; + } } - std::sort(filtered.begin(), filtered.end(), - [](QSize size1, QSize size2) { return size1.width() * size1.height() < size2.width() * size2.height(); }); - const QSize &viewfinderResolution = filtered.first(); + const QSize &viewfinderResolution = maxSize; const quint32 viewfinderResolutionIndex = quint32(previewResolutions.indexOf(viewfinderResolution)); hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Media_MediaProperties_MediaEncodingProfile).Get(), &d->encodingProfile); diff --git a/src/plugins/winrt/qwinrtimageencodercontrol.cpp b/src/plugins/winrt/qwinrtimageencodercontrol.cpp index 7ea851b77..2aed5f8a6 100644 --- a/src/plugins/winrt/qwinrtimageencodercontrol.cpp +++ b/src/plugins/winrt/qwinrtimageencodercontrol.cpp @@ -105,8 +105,15 @@ void QWinRTImageEncoderControl::applySettings() if (d->imageEncoderSetting.codec().isEmpty()) d->imageEncoderSetting.setCodec(QStringLiteral("jpeg")); + if (d->supportedResolutions.isEmpty()) + return; + QSize requestResolution = d->imageEncoderSetting.resolution(); - if (d->supportedResolutions.isEmpty() || d->supportedResolutions.contains(requestResolution)) + if (!requestResolution.isValid()) { + d->imageEncoderSetting.setResolution(d->supportedResolutions.last()); + return; + } + if (d->supportedResolutions.contains(requestResolution)) return; // Find closest resolution from the list |