summaryrefslogtreecommitdiffstats
path: root/src/qtmultimediaquicktools/qsgvideonode_yuv.cpp
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@edeltech.ch>2016-04-29 15:47:52 +0200
committerYoann Lopes <yoann.lopes@qt.io>2016-04-29 13:51:02 +0000
commitbc8e257718240f92db70b229980fc97e8317997d (patch)
treef9e053ae29416152494504a6eb938c52c41df10c /src/qtmultimediaquicktools/qsgvideonode_yuv.cpp
parent0a73b2e63a5cec80edc89cfefd7d86064d393c46 (diff)
Implement YUV 4:2:2 8bit support for QtQuick
This patch implements support for rendering of UYVY and YUYV sources when using QtQuick for preview. [ChangeLog][QtQuick][Rendering] Support for YUV 4:2:2 8bit has been implemented for the QtQuick viewfinder. Change-Id: I4d98f3c44240ee53f7708bc6bd84e7fb83aac069 Reviewed-by: Yoann Lopes <yoann.lopes@qt.io>
Diffstat (limited to 'src/qtmultimediaquicktools/qsgvideonode_yuv.cpp')
-rw-r--r--src/qtmultimediaquicktools/qsgvideonode_yuv.cpp99
1 files changed, 95 insertions, 4 deletions
diff --git a/src/qtmultimediaquicktools/qsgvideonode_yuv.cpp b/src/qtmultimediaquicktools/qsgvideonode_yuv.cpp
index 314a26264..68e6b456b 100644
--- a/src/qtmultimediaquicktools/qsgvideonode_yuv.cpp
+++ b/src/qtmultimediaquicktools/qsgvideonode_yuv.cpp
@@ -53,7 +53,8 @@ QList<QVideoFrame::PixelFormat> QSGVideoNodeFactory_YUV::supportedPixelFormats(
if (handleType == QAbstractVideoBuffer::NoHandle) {
formats << QVideoFrame::Format_YUV420P << QVideoFrame::Format_YV12
- << QVideoFrame::Format_NV12 << QVideoFrame::Format_NV21;
+ << QVideoFrame::Format_NV12 << QVideoFrame::Format_NV21
+ << QVideoFrame::Format_UYVY << QVideoFrame::Format_YUYV;
}
return formats;
@@ -109,6 +110,55 @@ protected:
int m_id_opacity;
};
+class QSGVideoMaterialShader_UYVY : public QSGMaterialShader
+{
+public:
+ QSGVideoMaterialShader_UYVY()
+ : QSGMaterialShader()
+ {
+ setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qtmultimediaquicktools/shaders/monoplanarvideo.vert"));
+ setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qtmultimediaquicktools/shaders/uyvyvideo.frag"));
+ }
+
+ void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) Q_DECL_OVERRIDE;
+
+ char const *const *attributeNames() const Q_DECL_OVERRIDE {
+ static const char *names[] = {
+ "qt_VertexPosition",
+ "qt_VertexTexCoord",
+ 0
+ };
+ return names;
+ }
+
+protected:
+ void initialize() Q_DECL_OVERRIDE {
+ m_id_matrix = program()->uniformLocation("qt_Matrix");
+ m_id_yuvtexture = program()->uniformLocation("yuvTexture");
+ m_id_imageWidth = program()->uniformLocation("imageWidth");
+ m_id_colorMatrix = program()->uniformLocation("colorMatrix");
+ m_id_opacity = program()->uniformLocation("opacity");
+ QSGMaterialShader::initialize();
+ }
+
+ int m_id_matrix;
+ int m_id_yuvtexture;
+ int m_id_imageWidth;
+ int m_id_colorMatrix;
+ int m_id_opacity;
+};
+
+
+class QSGVideoMaterialShader_YUYV : public QSGVideoMaterialShader_UYVY
+{
+public:
+ QSGVideoMaterialShader_YUYV()
+ : QSGVideoMaterialShader_UYVY()
+ {
+ setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qtmultimediaquicktools/shaders/yuyvvideo.frag"));
+ }
+};
+
class QSGVideoMaterialShader_YUV_BiPlanar_swizzle : public QSGVideoMaterialShader_YUV_BiPlanar
{
@@ -152,13 +202,17 @@ public:
~QSGVideoMaterial_YUV();
virtual QSGMaterialType *type() const {
- static QSGMaterialType biPlanarType, biPlanarSwizzleType, triPlanarType;
+ static QSGMaterialType biPlanarType, biPlanarSwizzleType, triPlanarType, uyvyType, yuyvType;
switch (m_format.pixelFormat()) {
case QVideoFrame::Format_NV12:
return &biPlanarType;
case QVideoFrame::Format_NV21:
return &biPlanarSwizzleType;
+ case QVideoFrame::Format_UYVY:
+ return &uyvyType;
+ case QVideoFrame::Format_YUYV:
+ return &yuyvType;
default: // Currently: YUV420P and YV12
return &triPlanarType;
}
@@ -170,6 +224,10 @@ public:
return new QSGVideoMaterialShader_YUV_BiPlanar;
case QVideoFrame::Format_NV21:
return new QSGVideoMaterialShader_YUV_BiPlanar_swizzle;
+ case QVideoFrame::Format_UYVY:
+ return new QSGVideoMaterialShader_UYVY;
+ case QVideoFrame::Format_YUYV:
+ return new QSGVideoMaterialShader_YUYV;
default: // Currently: YUV420P and YV12
return new QSGVideoMaterialShader_YUV_TriPlanar;
}
@@ -230,6 +288,8 @@ QSGVideoMaterial_YUV::QSGVideoMaterial_YUV(const QVideoSurfaceFormat &format) :
case QVideoFrame::Format_YV12:
m_planeCount = 3;
break;
+ case QVideoFrame::Format_UYVY:
+ case QVideoFrame::Format_YUYV:
default:
m_planeCount = 1;
break;
@@ -293,7 +353,15 @@ void QSGVideoMaterial_YUV::bind()
functions->glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousAlignment);
functions->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- if (m_format.pixelFormat() == QVideoFrame::Format_NV12
+ if (m_format.pixelFormat() == QVideoFrame::Format_UYVY
+ || m_format.pixelFormat() == QVideoFrame::Format_YUYV) {
+ int fw = m_frame.width() / 2;
+ m_planeWidth[0] = fw;
+
+ functions->glActiveTexture(GL_TEXTURE0);
+ bindTexture(m_textureIds[0], fw, m_frame.height(), m_frame.bits(), GL_RGBA);
+
+ } else if (m_format.pixelFormat() == QVideoFrame::Format_NV12
|| m_format.pixelFormat() == QVideoFrame::Format_NV21) {
const int y = 0;
const int uv = 1;
@@ -338,7 +406,6 @@ void QSGVideoMaterial_YUV::bind()
void QSGVideoMaterial_YUV::bindTexture(int id, int w, int h, const uchar *bits, GLenum format)
{
QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
-
functions->glBindTexture(GL_TEXTURE_2D, id);
functions->glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, format, GL_UNSIGNED_BYTE, bits);
functions->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -399,4 +466,28 @@ void QSGVideoMaterialShader_YUV_TriPlanar::updateState(const RenderState &state,
program()->setUniformValue(m_id_plane3Width, mat->m_planeWidth[2]);
}
+void QSGVideoMaterialShader_UYVY::updateState(const RenderState &state,
+ QSGMaterial *newMaterial,
+ QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(oldMaterial);
+
+ QSGVideoMaterial_YUV *mat = static_cast<QSGVideoMaterial_YUV *>(newMaterial);
+
+ program()->setUniformValue(m_id_yuvtexture, 0);
+
+ mat->bind();
+
+ program()->setUniformValue(m_id_colorMatrix, mat->m_colorMatrix);
+ program()->setUniformValue(m_id_imageWidth, mat->m_frame.width());
+
+ if (state.isOpacityDirty()) {
+ mat->m_opacity = state.opacity();
+ program()->setUniformValue(m_id_opacity, GLfloat(mat->m_opacity));
+ }
+
+ if (state.isMatrixDirty())
+ program()->setUniformValue(m_id_matrix, state.combinedMatrix());
+}
+
QT_END_NAMESPACE