diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2017-09-07 17:26:53 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2018-05-02 04:42:03 +0000 |
commit | 82789905f291033504427a1406da430d744fe843 (patch) | |
tree | e1c46489378560ffef70dfdcfa9746395437132b | |
parent | 0ac74678fd584a1db089b90ab8892c0a39b0376b (diff) |
winrt: Fix rotation of camera image
Task-number: QTBUG-63014
Change-Id: I6afacdb31f13a9e95784afaab90029a77f9fabfc
Reviewed-by: VaL Doroshchuk <valentyn.doroshchuk@qt.io>
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
(cherry picked from commit c47553562264ea4d157772a8ff38a8832b93407a)
-rw-r--r-- | src/plugins/winrt/qwinrtcameracontrol.cpp | 3 | ||||
-rw-r--r-- | src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp | 53 |
2 files changed, 32 insertions, 24 deletions
diff --git a/src/plugins/winrt/qwinrtcameracontrol.cpp b/src/plugins/winrt/qwinrtcameracontrol.cpp index 527dd6e8f..e50c09021 100644 --- a/src/plugins/winrt/qwinrtcameracontrol.cpp +++ b/src/plugins/winrt/qwinrtcameracontrol.cpp @@ -950,8 +950,7 @@ HRESULT QWinRTCameraControl::initialize() } const QCamera::Position position = d->videoDeviceSelector->cameraPosition(deviceName); - d->videoRenderer->setScanLineDirection(position == QCamera::BackFace ? QVideoSurfaceFormat::TopToBottom - : QVideoSurfaceFormat::BottomToTop); + d->videoRenderer->setScanLineDirection(QVideoSurfaceFormat::TopToBottom); ComPtr<IMediaCaptureInitializationSettings> settings; hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Media_Capture_MediaCaptureInitializationSettings).Get(), &settings); diff --git a/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp b/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp index abe10f9a4..909d7e65b 100644 --- a/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp +++ b/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp @@ -251,6 +251,22 @@ private: }; Q_GLOBAL_STATIC(QWinRTVideoDeviceSelectorControlGlobal, g) +static ComPtr<IEnclosureLocation> enclosureLocation(const QString &deviceName) +{ + ComPtr<IEnclosureLocation> enclosureLocation; + int deviceIndex = g->deviceIndex.value(deviceName); + IDeviceInformation *deviceInfo = g->devices.value(deviceIndex).Get(); + if (!deviceInfo) + return enclosureLocation; + + HRESULT hr; + hr = deviceInfo->get_EnclosureLocation(&enclosureLocation); + if (FAILED(hr)) + qErrnoWarning(hr, "Failed to get camera enclosure location"); + + return enclosureLocation; +} + class QWinRTVideoDeviceSelectorControlPrivate { public: @@ -307,20 +323,13 @@ int QWinRTVideoDeviceSelectorControl::selectedDevice() const QCamera::Position QWinRTVideoDeviceSelectorControl::cameraPosition(const QString &deviceName) { - int deviceIndex = g->deviceIndex.value(deviceName); - IDeviceInformation *deviceInfo = g->devices.value(deviceIndex).Get(); - if (!deviceInfo) + ComPtr<IEnclosureLocation> enclosure = enclosureLocation(deviceName); + if (!enclosure) return QCamera::UnspecifiedPosition; - ComPtr<IEnclosureLocation> enclosureLocation; HRESULT hr; - hr = deviceInfo->get_EnclosureLocation(&enclosureLocation); - RETURN_IF_FAILED("Failed to get camera enclosure location", return QCamera::UnspecifiedPosition); - if (!enclosureLocation) - return QCamera::UnspecifiedPosition; - Panel panel; - hr = enclosureLocation->get_Panel(&panel); + hr = enclosure->get_Panel(&panel); RETURN_IF_FAILED("Failed to get camera panel location", return QCamera::UnspecifiedPosition); switch (panel) { @@ -336,18 +345,18 @@ QCamera::Position QWinRTVideoDeviceSelectorControl::cameraPosition(const QString int QWinRTVideoDeviceSelectorControl::cameraOrientation(const QString &deviceName) { -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) - switch (cameraPosition(deviceName)) { - case QCamera::FrontFace: - case QCamera::BackFace: - return 270; - default: - break; - } -#else - Q_UNUSED(deviceName); -#endif - return 0; + ComPtr<IEnclosureLocation> enclosure = enclosureLocation(deviceName); + if (!enclosure) + return 0; + + HRESULT hr; + ComPtr<IEnclosureLocation2> enclosure2; + hr = enclosure.As(&enclosure2); + RETURN_IF_FAILED("Failed to cast camera enclosure location", return 0); + quint32 rotation; + hr = enclosure2->get_RotationAngleInDegreesClockwise(&rotation); + RETURN_IF_FAILED("Failed to get camera rotation angle", return 0); + return rotation; } QList<QByteArray> QWinRTVideoDeviceSelectorControl::deviceNames() |