summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-04-20 11:22:16 +0200
committerKristian Høgsberg <krh@bitplanet.net>2012-07-10 15:54:17 -0400
commitfaf91854a857900f0f92710bd90522aa23d59723 (patch)
tree9d6c093099c29a1a28d6386d55b1e52b18ec8a92
parent6d0304904c4c174fe91aca20ea01ea1287534d9e (diff)
compositor: add YUV shaders.
Add shaders for NV12 (2 planes), YUV (3 planes) and YUYV (sampled as 2 planes) Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
-rw-r--r--src/compositor.c61
-rw-r--r--src/compositor.h3
2 files changed, 64 insertions, 0 deletions
diff --git a/src/compositor.c b/src/compositor.c
index 4284c678..dcff7097 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 533de3fa..d1fa58e7 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;