From faf91854a857900f0f92710bd90522aa23d59723 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Fri, 20 Apr 2012 11:22:16 +0200 Subject: [PATCH] compositor: add YUV shaders. Add shaders for NV12 (2 planes), YUV (3 planes) and YUYV (sampled as 2 planes) Signed-off-by: Gwenole Beauchesne --- src/compositor.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/compositor.h | 3 +++ 2 files changed, 64 insertions(+) diff --git a/src/compositor.c b/src/compositor.c index 4284c67..dcff709 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -2778,6 +2778,12 @@ static const char vertex_shader[] = " gl_FragColor.a = 1.0;\n" \ " gl_FragColor = alpha * gl_FragColor;\n" +#define FRAGMENT_CONVERT_YUV \ + " gl_FragColor.r = y + 1.59602678 * v;\n" \ + " gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n" \ + " gl_FragColor.b = y + 2.01723214 * u;\n" \ + " gl_FragColor.a = 1.0;\n" + static const char texture_fragment_shader_rgba[] = "precision mediump float;\n" "varying vec2 v_texcoord;\n" @@ -2790,6 +2796,52 @@ static const char texture_fragment_shader_rgba[] = FRAGMENT_SHADER_EXIT "}\n"; +static const char texture_fragment_shader_y_uv[] = + "precision mediump float;\n" + "uniform sampler2D tex;\n" + "uniform sampler2D tex1;\n" + "varying vec2 v_texcoord;\n" + FRAGMENT_SHADER_UNIFORMS + "void main() {\n" + FRAGMENT_SHADER_INIT + " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n" + " float u = texture2D(tex1, v_texcoord).r - 0.5;\n" + " float v = texture2D(tex1, v_texcoord).g - 0.5;\n" + FRAGMENT_CONVERT_YUV + FRAGMENT_SHADER_EXIT + "}\n"; + +static const char texture_fragment_shader_y_u_v[] = + "precision mediump float;\n" + "uniform sampler2D tex;\n" + "uniform sampler2D tex1;\n" + "uniform sampler2D tex2;\n" + "varying vec2 v_texcoord;\n" + FRAGMENT_SHADER_UNIFORMS + "void main() {\n" + FRAGMENT_SHADER_INIT + " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n" + " float u = texture2D(tex1, v_texcoord).x - 0.5;\n" + " float v = texture2D(tex2, v_texcoord).x - 0.5;\n" + FRAGMENT_CONVERT_YUV + FRAGMENT_SHADER_EXIT + "}\n"; + +static const char texture_fragment_shader_y_xuxv[] = + "precision mediump float;\n" + "uniform sampler2D tex;\n" + "uniform sampler2D tex1;\n" + "varying vec2 v_texcoord;\n" + FRAGMENT_SHADER_UNIFORMS + "void main() {\n" + FRAGMENT_SHADER_INIT + " float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n" + " float u = texture2D(tex1, v_texcoord).g - 0.5;\n" + " float v = texture2D(tex1, v_texcoord).a - 0.5;\n" + FRAGMENT_CONVERT_YUV + FRAGMENT_SHADER_EXIT + "}\n"; + static const char solid_fragment_shader[] = "precision mediump float;\n" "uniform vec4 color;\n" @@ -3149,6 +3201,15 @@ weston_compositor_init_gl(struct weston_compositor *ec) if (weston_shader_init(&ec->texture_shader_rgba, vertex_shader, texture_fragment_shader_rgba) < 0) return -1; + if (weston_shader_init(&ec->texture_shader_y_uv, + vertex_shader, texture_fragment_shader_y_uv) < 0) + return -1; + if (weston_shader_init(&ec->texture_shader_y_u_v, + vertex_shader, texture_fragment_shader_y_u_v) < 0) + return -1; + if (weston_shader_init(&ec->texture_shader_y_xuxv, + vertex_shader, texture_fragment_shader_y_xuxv) < 0) + return -1; if (weston_shader_init(&ec->solid_shader, vertex_shader, solid_fragment_shader) < 0) return -1; diff --git a/src/compositor.h b/src/compositor.h index 533de3f..d1fa58e 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -271,6 +271,9 @@ struct weston_compositor { EGLConfig egl_config; GLuint fbo; struct weston_shader texture_shader_rgba; + struct weston_shader texture_shader_y_uv; + struct weston_shader texture_shader_y_u_v; + struct weston_shader texture_shader_y_xuxv; struct weston_shader solid_shader; struct weston_shader *current_shader; struct wl_display *wl_display; -- 2.7.4