Skip to content

Commit

Permalink
gl: add yuv to rgb shader
Browse files Browse the repository at this point in the history
result color is wrong, shader seems right. may be some mistakes in c++
code
  • Loading branch information
wang-bin committed Feb 16, 2014
1 parent 8a857a8 commit 5efd5b5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/libQtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ PROJECTROOT = $$PWD/..
preparePaths($$OUT_PWD/../out)


RESOURCES += ../i18n/QtAV.qrc
RESOURCES += ../i18n/QtAV.qrc \
shaders/shaders.qrc

win32 {
RC_FILE = $${PROJECTROOT}/res/QtAV.rc
Expand Down Expand Up @@ -111,6 +112,7 @@ config_gl {
SOURCES += GLWidgetRenderer.cpp
HEADERS += QtAV/private/GLWidgetRenderer_p.h
SDK_HEADERS += QtAV/GLWidgetRenderer.h
OTHER_FILES += shaders/yuv_rgb.f.glsl
}
config_dxva {
DEFINES *= QTAV_HAVE_DXVA=1
Expand Down
5 changes: 5 additions & 0 deletions src/shaders/shaders.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/shaders">
<file>yuv_rgb.f.glsl</file>
</qresource>
</RCC>
36 changes: 36 additions & 0 deletions src/shaders/yuv_rgb.f.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifdef GL_ES
// Set default precision to medium
precision mediump int;
precision mediump float;
#else
#define highp
#define mediump
#define lowp
#endif

// u_TextureN: yuv. use array?
uniform sampler2D u_Texture0;
uniform sampler2D u_Texture1;
uniform sampler2D u_Texture2;
varying lowp vec2 v_TexCoords;

//http://en.wikipedia.org/wiki/YUV calculation used
//http://www.fourcc.org/fccyvrgb.php
//GLSL: col first
// use bt601
const mat4 colorMatrix = mat4(1, 1, 1, 0,
0, -0.344, 1.773, 0,
1.403, -0.714, 0, 0,
0, 0, 0, 1)
* mat4(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, -0.5, -0.5, 1);
void main()
{
gl_FragColor = clamp(colorMatrix* vec4(texture2D(u_Texture0, v_TexCoords).r,
texture2D(u_Texture1, v_TexCoords).r,
texture2D(u_Texture2, v_TexCoords).r,
1)
, 0.0, 1.0);
}

0 comments on commit 5efd5b5

Please sign in to comment.