diff options
author | Tomasz Olszak <olszak.tomasz@gmail.com> | 2017-06-13 11:24:47 +0200 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2018-01-15 08:39:28 +0000 |
commit | d58b6b908ea130e9422b08b5b3b460b48da7d337 (patch) | |
tree | 3c0edf6f46ea880a451dd975125649527ee8d288 /src/qtmultimediaquicktools/shaders | |
parent | b9440a3047cfca9ae253e850db31b8e9b08538e7 (diff) | |
download | qtmultimedia-d58b6b908ea130e9422b08b5b3b460b48da7d337.tar.gz |
Improve quality of YUVY and UYVY rendering
Idea is to upload YUYV/UYVY data as 2 textures and use GL_LINEAR like
in biplanar formats. Having proper interpolation of only one texture
(using e.g. mix function) resulted in vertical and horizontal 1 pixel
stripes depending on scale. The reason was float precision and
unexpected value of fract function. Additionally branching in shader
is expensive so this solution should be more performant.
Task-number: QTBUG-62155
Change-Id: I7ceeb09b4a54eecd16640a626b499d638b52c127
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'src/qtmultimediaquicktools/shaders')
-rw-r--r-- | src/qtmultimediaquicktools/shaders/uyvyvideo.frag | 18 | ||||
-rw-r--r-- | src/qtmultimediaquicktools/shaders/yuyvvideo.frag | 18 |
2 files changed, 8 insertions, 28 deletions
diff --git a/src/qtmultimediaquicktools/shaders/uyvyvideo.frag b/src/qtmultimediaquicktools/shaders/uyvyvideo.frag index 905035703..5c62441c2 100644 --- a/src/qtmultimediaquicktools/shaders/uyvyvideo.frag +++ b/src/qtmultimediaquicktools/shaders/uyvyvideo.frag @@ -1,22 +1,12 @@ -uniform sampler2D yuvTexture; // UYVY macropixel texture passed as RGBA format -uniform mediump float imageWidth; // The UYVY texture appears to the shader with 1/2 the image width since we use the RGBA format to pass UYVY +uniform sampler2D yTexture; // Y component passed as GL_LUMINANCE_ALPHA, in uyvy Y = a +uniform sampler2D uvTexture; // UV component passed as RGBA macropixel, in uyvy U = r, V = b uniform mediump mat4 colorMatrix; uniform lowp float opacity; - varying highp vec2 qt_TexCoord; void main() { - // For U0 Y0 V0 Y1 macropixel, lookup Y0 or Y1 based on whether - // the original texture x coord is even or odd. - mediump float Y; - if (fract(floor(qt_TexCoord.x * imageWidth + 0.5) / 2.0) > 0.0) - Y = texture2D(yuvTexture, qt_TexCoord).a; // odd so choose Y1 - else - Y = texture2D(yuvTexture, qt_TexCoord).g; // even so choose Y0 - mediump float Cb = texture2D(yuvTexture, qt_TexCoord).r; - mediump float Cr = texture2D(yuvTexture, qt_TexCoord).b; + mediump vec3 YUV = vec3(texture2D(yTexture, qt_TexCoord).a, texture2D(uvTexture, qt_TexCoord).rb); - mediump vec4 color = vec4(Y, Cb, Cr, 1.0); - gl_FragColor = colorMatrix * color * opacity; + gl_FragColor = colorMatrix * vec4(YUV, 1.0) * opacity; } diff --git a/src/qtmultimediaquicktools/shaders/yuyvvideo.frag b/src/qtmultimediaquicktools/shaders/yuyvvideo.frag index 72732cd66..5ce8b7366 100644 --- a/src/qtmultimediaquicktools/shaders/yuyvvideo.frag +++ b/src/qtmultimediaquicktools/shaders/yuyvvideo.frag @@ -1,22 +1,12 @@ -uniform sampler2D yuvTexture; // YUYV macropixel texture passed as RGBA format -uniform mediump float imageWidth; // The YUYV texture appears to the shader with 1/2 the image width since we use the RGBA format to pass YUYV +uniform sampler2D yTexture; // Y component passed as GL_LUMINANCE_ALPHA, in yuyv Y = r +uniform sampler2D uvTexture; // UV component passed as RGBA macropixel, in uyvy U = g, V = a uniform mediump mat4 colorMatrix; uniform lowp float opacity; - varying highp vec2 qt_TexCoord; void main() { - // For Y0 U0 Y1 V0 macropixel, lookup Y0 or Y1 based on whether - // the original texture x coord is even or odd. - mediump float Y; - if (fract(floor(qt_TexCoord.x * imageWidth + 0.5) / 2.0) > 0.0) - Y = texture2D(yuvTexture, qt_TexCoord).b; // odd so choose Y1 - else - Y = texture2D(yuvTexture, qt_TexCoord).r; // even so choose Y0 - mediump float Cb = texture2D(yuvTexture, qt_TexCoord).g; - mediump float Cr = texture2D(yuvTexture, qt_TexCoord).a; + mediump vec3 YUV = vec3(texture2D(yTexture, qt_TexCoord).r, texture2D(uvTexture, qt_TexCoord).ga); - mediump vec4 color = vec4(Y, Cb, Cr, 1.0); - gl_FragColor = colorMatrix * color * opacity; + gl_FragColor = colorMatrix * vec4(YUV, 1.0) * opacity; } |