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