]> git.sesse.net Git - movit/blob - ycbcr_conversion_effect.frag
Merge branch '1.3.x-release'
[movit] / ycbcr_conversion_effect.frag
1 // See footer.frag for details about this if statement.
2 #ifndef YCBCR_ALSO_OUTPUT_RGBA
3 #define YCBCR_ALSO_OUTPUT_RGBA 0
4 #endif
5
6 uniform sampler2D PREFIX(tex_y);
7 uniform sampler2D PREFIX(tex_cb);
8 uniform sampler2D PREFIX(tex_cr);
9
10 #if YCBCR_ALSO_OUTPUT_RGBA
11 vec4[2] FUNCNAME(vec2 tc) {
12 #else
13 vec4 FUNCNAME(vec2 tc) {
14 #endif
15         vec4 rgba = INPUT(tc);
16         vec4 ycbcr_a;
17
18         ycbcr_a.rgb = PREFIX(ycbcr_matrix) * rgba.rgb + PREFIX(offset);
19
20 #if YCBCR_CLAMP_RANGE
21         // If we use limited-range Y'CbCr, the card's usual 0–255 clamping
22         // won't be enough, so we need to clamp ourselves here.
23         //
24         // We clamp before dither, which is a bit unfortunate, since
25         // it means dither can take us out of the clamped range again.
26         // However, since DitherEffect never adds enough dither to change
27         // the quantized levels, we will be fine in practice.
28         ycbcr_a.rgb = clamp(ycbcr_a.rgb, PREFIX(ycbcr_min), PREFIX(ycbcr_max));
29 #endif
30
31         ycbcr_a.a = rgba.a;
32
33 #if YCBCR_ALSO_OUTPUT_RGBA
34         return vec4[2](ycbcr_a, rgba);
35 #else
36         return ycbcr_a;
37 #endif
38 }