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