summaryrefslogtreecommitdiffstats
path: root/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@digia.com>2013-09-27 18:20:15 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-01 17:26:31 +0200
commit28df116570a1359585a314df17223a7b0e6b04c0 (patch)
treeb59c62b7ef35d6a7219210cda0e94871b75a04da /src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
parentbe7a6241e77f67e4a19c63ac5683dd7fa566e9d2 (diff)
Android: fixed image capture preview.
We used to generate the capture preview from the video output, grabbing the pixels of the last frame (in a FBO). This is not possible anymore, we instead query the camera for a preview frame, which is in the NV21 format and needs to be converted to RGB. Change-Id: I1c728b3a708a6f052a83aebf9f15f511eab7a02f Reviewed-by: Christian Stromme <christian.stromme@digia.com>
Diffstat (limited to 'src/plugins/android/src/mediacapture/qandroidcamerasession.cpp')
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerasession.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
index ec86322a4..3ee700bf4 100644
--- a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
+++ b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
@@ -147,8 +147,11 @@ bool QAndroidCameraSession::open()
if (m_camera) {
connect(m_camera, SIGNAL(pictureExposed()), this, SLOT(onCameraPictureExposed()));
connect(m_camera, SIGNAL(pictureCaptured(QByteArray)), this, SLOT(onCameraPictureCaptured(QByteArray)));
+ connect(m_camera, SIGNAL(previewFrameAvailable(QByteArray)), this, SLOT(onCameraPreviewFrameAvailable(QByteArray)));
m_nativeOrientation = m_camera->getNativeOrientation();
m_status = QCamera::LoadedStatus;
+ if (m_camera->getPreviewFormat() != JCamera::NV21)
+ m_camera->setPreviewFormat(JCamera::NV21);
emit opened();
} else {
m_status = QCamera::UnavailableStatus;
@@ -422,6 +425,7 @@ int QAndroidCameraSession::capture(const QString &fileName)
// adjust picture rotation depending on the device orientation
m_camera->setRotation(currentCameraRotation());
+ m_camera->requestPreviewFrame();
m_camera->takePicture();
} else {
emit imageCaptureError(m_lastImageCaptureId, QCameraImageCapture::NotSupportedFeatureError,
@@ -450,10 +454,6 @@ void QAndroidCameraSession::onCameraPictureExposed()
void QAndroidCameraSession::onCameraPictureCaptured(const QByteArray &data)
{
if (!m_captureCanceled) {
- // generate a preview from the viewport
- if (m_videoOutput)
- emit imageCaptured(m_currentImageCaptureId, m_videoOutput->toImage());
-
// Loading and saving the captured image can be slow, do it in a separate thread
QtConcurrent::run(this, &QAndroidCameraSession::processCapturedImage,
m_currentImageCaptureId,
@@ -517,6 +517,34 @@ void QAndroidCameraSession::processCapturedImage(int id,
}
}
+void QAndroidCameraSession::onCameraPreviewFrameAvailable(const QByteArray &data)
+{
+ if (m_captureCanceled || m_readyForCapture)
+ return;
+
+ QtConcurrent::run(this, &QAndroidCameraSession::processPreviewImage,
+ m_currentImageCaptureId,
+ data);
+}
+
+void QAndroidCameraSession::processPreviewImage(int id, const QByteArray &data)
+{
+ QSize frameSize = m_camera->previewSize();
+ QImage preview(frameSize, QImage::Format_ARGB32);
+ qt_convert_NV21_to_ARGB32((const uchar *)data.constData(),
+ (quint32 *)preview.bits(),
+ frameSize.width(),
+ frameSize.height());
+
+ // Preview display of front-facing cameras is flipped horizontally, but the frame data
+ // we get here is not. Flip it ourselves if the camera is front-facing to match what the user
+ // sees on the viewfinder.
+ if (m_camera->getFacing() == JCamera::CameraFacingFront)
+ preview = preview.transformed(QTransform().scale(-1, 1));
+
+ emit imageCaptured(id, preview);
+}
+
void QAndroidCameraSession::onVideoOutputReady(bool ready)
{
if (m_camera && m_videoOutput && ready)