diff options
author | Yoann Lopes <yoann.lopes@digia.com> | 2013-09-27 18:20:15 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-01 17:26:31 +0200 |
commit | 28df116570a1359585a314df17223a7b0e6b04c0 (patch) | |
tree | b59c62b7ef35d6a7219210cda0e94871b75a04da /src/plugins/android/src/common | |
parent | be7a6241e77f67e4a19c63ac5683dd7fa566e9d2 (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/common')
5 files changed, 27 insertions, 10 deletions
diff --git a/src/plugins/android/src/common/qandroidmultimediautils.cpp b/src/plugins/android/src/common/qandroidmultimediautils.cpp index 7ae40358f..9bf38a869 100644 --- a/src/plugins/android/src/common/qandroidmultimediautils.cpp +++ b/src/plugins/android/src/common/qandroidmultimediautils.cpp @@ -76,4 +76,29 @@ bool qt_sizeLessThan(const QSize &s1, const QSize &s2) return s1.width() * s1.height() < s2.width() * s2.height(); } +void qt_convert_NV21_to_ARGB32(const uchar *yuv, quint32 *rgb, int width, int height) +{ + const int frameSize = width * height; + + int a = 0; + for (int i = 0, ci = 0; i < height; ++i, ci += 1) { + for (int j = 0, cj = 0; j < width; ++j, cj += 1) { + int y = (0xff & ((int) yuv[ci * width + cj])); + int v = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 0])); + int u = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 1])); + y = y < 16 ? 16 : y; + + int r = (int) (1.164f * (y - 16) + 1.596f * (v - 128)); + int g = (int) (1.164f * (y - 16) - 0.813f * (v - 128) - 0.391f * (u - 128)); + int b = (int) (1.164f * (y - 16) + 2.018f * (u - 128)); + + r = qBound(0, r, 255); + g = qBound(0, g, 255); + b = qBound(0, b, 255); + + rgb[a++] = 0xff000000 | (r << 16) | (g << 8) | b; + } + } +} + QT_END_NAMESPACE diff --git a/src/plugins/android/src/common/qandroidmultimediautils.h b/src/plugins/android/src/common/qandroidmultimediautils.h index 1996209b0..792ab06db 100644 --- a/src/plugins/android/src/common/qandroidmultimediautils.h +++ b/src/plugins/android/src/common/qandroidmultimediautils.h @@ -53,6 +53,8 @@ int qt_findClosestValue(const QList<int> &list, int value); bool qt_sizeLessThan(const QSize &s1, const QSize &s2); +void qt_convert_NV21_to_ARGB32(const uchar *yuv, quint32 *rgb, int width, int height); + QT_END_NAMESPACE #endif // QANDROIDMULTIMEDIAUTILS_H diff --git a/src/plugins/android/src/common/qandroidvideooutput.h b/src/plugins/android/src/common/qandroidvideooutput.h index 1ad64a4b4..6e4a32e3f 100644 --- a/src/plugins/android/src/common/qandroidvideooutput.h +++ b/src/plugins/android/src/common/qandroidvideooutput.h @@ -61,8 +61,6 @@ public: virtual void setVideoSize(const QSize &) { } virtual void stop() { } - virtual QImage toImage() = 0; - // signals: // void readyChanged(bool); }; diff --git a/src/plugins/android/src/common/qandroidvideorendercontrol.cpp b/src/plugins/android/src/common/qandroidvideorendercontrol.cpp index b9aac6434..5306fe918 100644 --- a/src/plugins/android/src/common/qandroidvideorendercontrol.cpp +++ b/src/plugins/android/src/common/qandroidvideorendercontrol.cpp @@ -223,13 +223,6 @@ void QAndroidVideoRendererControl::stop() m_nativeSize = QSize(); } -QImage QAndroidVideoRendererControl::toImage() -{ - // FIXME!!! Since we are not using a FBO anymore, we can't grab the pixels. And glGetTexImage - // doesn't work on GL_TEXTURE_EXTERNAL_OES - return QImage(); -} - void QAndroidVideoRendererControl::onFrameAvailable() { if (!m_nativeSize.isValid() || !m_surface) diff --git a/src/plugins/android/src/common/qandroidvideorendercontrol.h b/src/plugins/android/src/common/qandroidvideorendercontrol.h index e98495ede..5d9130c07 100644 --- a/src/plugins/android/src/common/qandroidvideorendercontrol.h +++ b/src/plugins/android/src/common/qandroidvideorendercontrol.h @@ -77,7 +77,6 @@ public: bool isReady() Q_DECL_OVERRIDE; void setVideoSize(const QSize &size) Q_DECL_OVERRIDE; void stop() Q_DECL_OVERRIDE; - QImage toImage() Q_DECL_OVERRIDE; void customEvent(QEvent *) Q_DECL_OVERRIDE; |