Skip to content

Compensate for incorrect camera orientation on affected iOS and Android devices#7326

Open
kaustuvpokharel wants to merge 4 commits into
masterfrom
cameraUtilOrientation
Open

Compensate for incorrect camera orientation on affected iOS and Android devices#7326
kaustuvpokharel wants to merge 4 commits into
masterfrom
cameraUtilOrientation

Conversation

@kaustuvpokharel
Copy link
Copy Markdown
Collaborator

@kaustuvpokharel kaustuvpokharel commented Apr 18, 2026

On some iOS and Android devices, Qt Multimedia's produces wrong orientation when the device is held in landscape.

This PR introduces a CameraOrientationNormalizer object that lives inside the camera's capture loader and handles two things-

Preview correction: Computes a previewRotation value bound to VideoOutput.orientation. On iOS (where correctionAngle() returns 0, consistent with Qt's documentation noting the correction angle is non-zero mostly on Android), it applies 180° in landscape to compensate for the AVFoundation inversion

Captured image normalization: At shutter press, the current screen orientation is recorded. When the JPEG is saved, normalizeImageOrientation() compares the pixel dimensions against the recorded orientation, if the user captured in landscape but the pixels are portrait (or vice versa), it rotates them. Any non-identity EXIF tag is stripped by re-saving with EXIF reset to identity. If everything already matches, the file is not touched. The corrected image is then shown as the photo preview, so the user sees the right orientation before accepting.

On devices where the backend already produces correct output, previewRotation is 0 in portrait (no change) and the image normalization returns false without modifying the file, should not regression.

Video capture orientation is not addressed. The MediaRecorder receives frames directly from the capture session's internal pipeline, not from the VideoOutput, so the orientation property does not affect recorded video.

THIS NEEDS TESTING ON FEW DEVICES

@qfield-fairy
Copy link
Copy Markdown
Collaborator

qfield-fairy commented Apr 18, 2026

🍎 MacOS DMG universal builds

Download a MacOS DMG universal build of this PR for testing.
(Built from commit 61481e1)

📱 Android builds

Download an Android arm64 build of this PR for testing.
(Built from commit 61481e1)

Other Android architectures

🪟 Windows builds

Download a Windows build of this PR for testing and for arm64.

(Built from commit 61481e1)

🐧 Linux AppImage builds

Download a Linux AppImage build of this PR for testing.
(Built from commit 61481e1)

@kaustuvpokharel kaustuvpokharel marked this pull request as ready for review April 18, 2026 07:40
Comment thread src/qml/QFieldCamera.qml
Comment thread src/core/cameraorientationnormalizer.cpp
@nirvn
Copy link
Copy Markdown
Member

nirvn commented May 8, 2026

@kaustuvpokharel , as per our discussion, can we narrow the code down to only apply to iOS and Windows OSes? I'll then send the iOS build to a local tester here to increase nb of devices tested.

@kaustuvpokharel kaustuvpokharel requested a review from nirvn May 9, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants