]> git.sesse.net Git - movit/blob - ycbcr_input.frag
Hard-assert on something that has bitten me too many times now.
[movit] / ycbcr_input.frag
1 // Implicit uniforms:
2 // uniform sampler2D PREFIX(tex_y);
3 // uniform sampler2D PREFIX(tex_cbcr);  // If CB_CR_SAME_TEXTURE.
4 // uniform sampler2D PREFIX(tex_cb);    // If not CB_CR_SAME_TEXTURE.
5 // uniform sampler2D PREFIX(tex_cr);    // If not CB_CR_SAME_TEXTURE.
6
7 vec4 FUNCNAME(vec2 tc) {
8         // OpenGL's origin is bottom-left, but most graphics software assumes
9         // a top-left origin. Thus, for inputs that come from the user,
10         // we flip the y coordinate.
11         tc.y = 1.0 - tc.y;
12
13         vec3 ycbcr;
14         ycbcr.x = tex2D(PREFIX(tex_y), tc).x;
15 #if CB_CR_SAME_TEXTURE
16 #if CB_CR_OFFSETS_EQUAL
17         ycbcr.yz = tex2D(PREFIX(tex_cbcr), tc + PREFIX(cb_offset)).xy;
18 #else
19         ycbcr.y = tex2D(PREFIX(tex_cbcr), tc + PREFIX(cb_offset)).x;
20         ycbcr.z = tex2D(PREFIX(tex_cbcr), tc + PREFIX(cr_offset)).x;
21 #endif
22 #else
23         ycbcr.y = tex2D(PREFIX(tex_cb), tc + PREFIX(cb_offset)).x;
24         ycbcr.z = tex2D(PREFIX(tex_cr), tc + PREFIX(cr_offset)).x;
25 #endif
26
27         ycbcr -= PREFIX(offset);
28
29         vec4 rgba;
30         rgba.rgb = PREFIX(inv_ycbcr_matrix) * ycbcr;
31         rgba.a = 1.0;
32         return rgba;
33 }