summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-04-04 17:49:48 +0200
committerLars Knoll <lars.knoll@qt.io>2021-04-08 12:19:11 +0000
commitebb4b2cd47dde5b343c1e53104e8cd5aa426a09c (patch)
treeb93d12ae3a009868d3eb985392301849ad94a1b9 /src/multimedia
parenteef8a2079639e5c35dc74fafe656b0d0ef504f9a (diff)
Add a colorMatrix to the rgb shaders
This unifies the uniform layout for all pixel formats, and has the advantage that we can now use the color matrix to do brightness adjustments if required by the sink. Fix the rgb pixel shaders and add a missing one for ABGR. Change-Id: I545b4e0f0c067501903ee5f7af1f0f1f80b2b0bb Reviewed-by: Doris Verria <doris.verria@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/CMakeLists.txt7
-rw-r--r--src/multimedia/shaders/abgr.frag17
-rw-r--r--src/multimedia/shaders/argb.frag (renamed from src/multimedia/shaders/rgba.frag)3
-rw-r--r--src/multimedia/shaders/bgra.frag3
-rw-r--r--src/multimedia/shaders/rgb.vert (renamed from src/multimedia/shaders/rgba.vert)1
-rw-r--r--src/multimedia/video/qvideotexturehelper.cpp20
6 files changed, 35 insertions, 16 deletions
diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt
index ff924771b..6cf4a6e6d 100644
--- a/src/multimedia/CMakeLists.txt
+++ b/src/multimedia/CMakeLists.txt
@@ -476,13 +476,14 @@ qt_internal_add_shaders(Multimedia "shaders"
PREFIX
"/qt-project.org/multimedia/shaders"
FILES
+ "shaders/rgb.vert"
+ "shaders/abgr.frag"
+ "shaders/argb.frag"
"shaders/bgra.frag"
+ "shaders/yuv.vert"
"shaders/nv12.frag"
"shaders/nv21.frag"
- "shaders/rgba.frag"
- "shaders/rgba.vert"
"shaders/uyvy.frag"
- "shaders/yuv.vert"
"shaders/yuv_yv.frag"
"shaders/yuyv.frag"
"shaders/ayuv.frag"
diff --git a/src/multimedia/shaders/abgr.frag b/src/multimedia/shaders/abgr.frag
new file mode 100644
index 000000000..207993584
--- /dev/null
+++ b/src/multimedia/shaders/abgr.frag
@@ -0,0 +1,17 @@
+#version 440
+
+layout(location = 0) in vec2 qt_TexCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ mat4 colorMatrix;
+ float opacity;
+} ubuf;
+
+layout(binding = 1) uniform sampler2D rgbTexture;
+
+void main()
+{
+ fragColor = texture(rgbTexture, qt_TexCoord).bgra * ubuf.colorMatrix * ubuf.opacity;
+}
diff --git a/src/multimedia/shaders/rgba.frag b/src/multimedia/shaders/argb.frag
index 1623c2cc7..1fd7d1bdf 100644
--- a/src/multimedia/shaders/rgba.frag
+++ b/src/multimedia/shaders/argb.frag
@@ -5,6 +5,7 @@ layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform buf {
mat4 matrix;
+ mat4 colorMatrix;
float opacity;
} ubuf;
@@ -12,5 +13,5 @@ layout(binding = 1) uniform sampler2D rgbTexture;
void main()
{
- fragColor = texture(rgbTexture, qt_TexCoord) * ubuf.opacity;
+ fragColor = texture(rgbTexture, qt_TexCoord) * ubuf.colorMatrix * ubuf.opacity;
}
diff --git a/src/multimedia/shaders/bgra.frag b/src/multimedia/shaders/bgra.frag
index f04e3e721..c63908c42 100644
--- a/src/multimedia/shaders/bgra.frag
+++ b/src/multimedia/shaders/bgra.frag
@@ -5,6 +5,7 @@ layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform buf {
mat4 matrix;
+ mat4 colorMatrix;
float opacity;
} ubuf;
@@ -12,5 +13,5 @@ layout(binding = 1) uniform sampler2D rgbTexture;
void main()
{
- fragColor = texture(rgbTexture, qt_TexCoord).bgra * ubuf.opacity;
+ fragColor = texture(rgbTexture, qt_TexCoord).grab * ubuf.colorMatrix * ubuf.opacity;
}
diff --git a/src/multimedia/shaders/rgba.vert b/src/multimedia/shaders/rgb.vert
index ebc53a65f..db88cb0b8 100644
--- a/src/multimedia/shaders/rgba.vert
+++ b/src/multimedia/shaders/rgb.vert
@@ -7,6 +7,7 @@ layout(location = 0) out vec2 qt_TexCoord;
layout(std140, binding = 0) uniform buf {
mat4 matrix;
+ mat4 colorMatrix;
float opacity;
} ubuf;
diff --git a/src/multimedia/video/qvideotexturehelper.cpp b/src/multimedia/video/qvideotexturehelper.cpp
index e57e2f615..b9db64c5f 100644
--- a/src/multimedia/video/qvideotexturehelper.cpp
+++ b/src/multimedia/video/qvideotexturehelper.cpp
@@ -234,7 +234,7 @@ QString vertexShaderFileName(QVideoSurfaceFormat::PixelFormat format)
case QVideoSurfaceFormat::Format_BGRA32_Premultiplied:
case QVideoSurfaceFormat::Format_ABGR32:
case QVideoSurfaceFormat::Format_BGR32:
- return QStringLiteral(":/qt-project.org/multimedia/shaders/rgba.vert.qsb");
+ return QStringLiteral(":/qt-project.org/multimedia/shaders/rgb.vert.qsb");
case QVideoSurfaceFormat::Format_YUV420P:
case QVideoSurfaceFormat::Format_YUV422P:
case QVideoSurfaceFormat::Format_YV12:
@@ -273,11 +273,13 @@ QString fragmentShaderFileName(QVideoSurfaceFormat::PixelFormat format)
case QVideoSurfaceFormat::Format_ARGB32:
case QVideoSurfaceFormat::Format_ARGB32_Premultiplied:
case QVideoSurfaceFormat::Format_RGB32:
+ return QStringLiteral(":/qt-project.org/multimedia/shaders/argb.frag.qsb");
case QVideoSurfaceFormat::Format_BGRA32:
case QVideoSurfaceFormat::Format_BGRA32_Premultiplied:
+ return QStringLiteral(":/qt-project.org/multimedia/shaders/bgra.frag.qsb");
case QVideoSurfaceFormat::Format_ABGR32:
case QVideoSurfaceFormat::Format_BGR32:
- return QStringLiteral(":/qt-project.org/multimedia/shaders/rgba.frag.qsb");
+ return QStringLiteral(":/qt-project.org/multimedia/shaders/abgr.frag.qsb");
case QVideoSurfaceFormat::Format_YUV420P:
case QVideoSurfaceFormat::Format_YUV422P:
case QVideoSurfaceFormat::Format_YV12:
@@ -324,6 +326,7 @@ static QMatrix4x4 colorMatrix(QVideoSurfaceFormat::YCbCrColorSpace colorSpace)
QByteArray uniformData(const QVideoSurfaceFormat &format, const QMatrix4x4 &transform, float opacity)
{
+ QMatrix4x4 cmat;
switch (format.pixelFormat()) {
case QVideoSurfaceFormat::Format_Invalid:
case QVideoSurfaceFormat::Format_Jpeg:
@@ -347,14 +350,8 @@ QByteArray uniformData(const QVideoSurfaceFormat &format, const QMatrix4x4 &tran
case QVideoSurfaceFormat::Format_BGRA32:
case QVideoSurfaceFormat::Format_BGRA32_Premultiplied:
case QVideoSurfaceFormat::Format_ABGR32:
- case QVideoSurfaceFormat::Format_BGR32: {
- // { matrix4x4, opacity }
- QByteArray buf(16*4 + 4, Qt::Uninitialized);
- char *data = buf.data();
- memcpy(data, transform.constData(), 64);
- memcpy(data + 64, &opacity, 4);
- return buf;
- }
+ case QVideoSurfaceFormat::Format_BGR32:
+ break;
case QVideoSurfaceFormat::Format_AYUV444:
case QVideoSurfaceFormat::Format_AYUV444_Premultiplied:
case QVideoSurfaceFormat::Format_YUV420P:
@@ -366,13 +363,14 @@ QByteArray uniformData(const QVideoSurfaceFormat &format, const QMatrix4x4 &tran
case QVideoSurfaceFormat::Format_NV21:
case QVideoSurfaceFormat::Format_P010:
case QVideoSurfaceFormat::Format_P016:
+ cmat = colorMatrix(format.yCbCrColorSpace());
break;
}
// { matrix4x4, colorMatrix, opacity, planeWidth[3] }
QByteArray buf(64*2 + 4, Qt::Uninitialized);
char *data = buf.data();
memcpy(data, transform.constData(), 64);
- memcpy(data + 64, colorMatrix(format.yCbCrColorSpace()).constData(), 64);
+ memcpy(data + 64, cmat.constData(), 64);
memcpy(data + 64 + 64, &opacity, 4);
return buf;
}