From 60607544e16eda72d0896f4699e492486b9c7a86 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Fri, 8 Feb 2013 17:38:25 +0100 Subject: [PATCH] Blackberry: Fix orientation of taken photos Ensure that the taken photos are always upright. As long as the QCamera API does not provide information about the native orientation of the camera, we have to do the rotation inside the BBCamera plugin. Change-Id: Iebb04a5417274c2baee5e944dadf10fc706484d9 Reviewed-by: Bernd Weimer Reviewed-by: Giuseppe D'Angelo --- .../blackberry/camera/bbcamerasession.cpp | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/plugins/blackberry/camera/bbcamerasession.cpp b/src/plugins/blackberry/camera/bbcamerasession.cpp index be352b19..0ab3ab7d 100644 --- a/src/plugins/blackberry/camera/bbcamerasession.cpp +++ b/src/plugins/blackberry/camera/bbcamerasession.cpp @@ -807,7 +807,7 @@ void BbCameraSession::handleVideoViewFinderData(camera_buffer_t *buffer) { QTransform transform; - transform.rotate(360 - m_nativeCameraOrientation); + transform.rotate(m_nativeCameraOrientation); const QImage frame = convertFrameToImage(buffer).transformed(transform); @@ -829,8 +829,21 @@ void BbCameraSession::updateReadyForCapture() emit readyForCaptureChanged(isReadyForCapture()); } -void BbCameraSession::imageCaptured(int requestId, const QImage &image, const QString &fileName) +void BbCameraSession::imageCaptured(int requestId, const QImage &rawImage, const QString &fileName) { + QTransform transform; + + // subtract out the native rotation + transform.rotate(m_nativeCameraOrientation); + + // subtract out the current device orientation + if (m_device == cameraIdentifierRear()) + transform.rotate(360 - m_orientationHandler->orientation()); + else + transform.rotate(m_orientationHandler->orientation()); + + const QImage image = rawImage.transformed(transform); + // Generate snap preview as downscaled image { QSize previewSize = image.size(); @@ -1139,7 +1152,7 @@ void BbCameraSession::applyConfiguration() CAMERA_IMGPROP_WIDTH, viewfinderResolution.width(), CAMERA_IMGPROP_HEIGHT, viewfinderResolution.height(), CAMERA_IMGPROP_FORMAT, CAMERA_FRAMETYPE_NV12, - CAMERA_IMGPROP_ROTATION, m_nativeCameraOrientation); + CAMERA_IMGPROP_ROTATION, 360 - m_nativeCameraOrientation); if (result != CAMERA_EOK) { qWarning() << "Unable to apply photo viewfinder settings:" << result; @@ -1171,7 +1184,7 @@ void BbCameraSession::applyConfiguration() CAMERA_IMGPROP_WIDTH, photoResolution.width(), CAMERA_IMGPROP_HEIGHT, photoResolution.height(), CAMERA_IMGPROP_JPEGQFACTOR, jpegQuality, - CAMERA_IMGPROP_ROTATION, m_nativeCameraOrientation); + CAMERA_IMGPROP_ROTATION, 360 - m_nativeCameraOrientation); if (result != CAMERA_EOK) { qWarning() << "Unable to apply photo settings:" << result; @@ -1204,7 +1217,7 @@ void BbCameraSession::applyConfiguration() const camera_error_t result = camera_set_videovf_property(m_handle, CAMERA_IMGPROP_WIDTH, viewfinderResolution.width(), CAMERA_IMGPROP_HEIGHT, viewfinderResolution.height(), - CAMERA_IMGPROP_ROTATION, m_nativeCameraOrientation); + CAMERA_IMGPROP_ROTATION, 360 - m_nativeCameraOrientation); if (result != CAMERA_EOK) { qWarning() << "Unable to apply video viewfinder settings:" << result;