X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=ycbcr_conversion_effect.frag;h=ef289df8fa34dc35ddf74858d8a351227b96de12;hp=6bc29b1be63782bcd950f3dd451256a2caedb8f0;hb=90ac46cdc5845432df13385f946c63b5496c685e;hpb=80fc4a6e806e5638ae050c3020962137ca5fd76b diff --git a/ycbcr_conversion_effect.frag b/ycbcr_conversion_effect.frag index 6bc29b1..ef289df 100644 --- a/ycbcr_conversion_effect.frag +++ b/ycbcr_conversion_effect.frag @@ -1,24 +1,38 @@ +// See footer.frag for details about this if statement. +#ifndef YCBCR_ALSO_OUTPUT_RGBA +#define YCBCR_ALSO_OUTPUT_RGBA 0 +#endif + uniform sampler2D PREFIX(tex_y); uniform sampler2D PREFIX(tex_cb); uniform sampler2D PREFIX(tex_cr); +#if YCBCR_ALSO_OUTPUT_RGBA +vec4[2] FUNCNAME(vec2 tc) { +#else vec4 FUNCNAME(vec2 tc) { +#endif vec4 rgba = INPUT(tc); vec4 ycbcr_a; ycbcr_a.rgb = PREFIX(ycbcr_matrix) * rgba.rgb + PREFIX(offset); -#if YCBCR_CLAMP_RANGE - // If we use limited-range Y'CbCr, the card's usual 0–255 clamping - // won't be enough, so we need to clamp ourselves here. - // - // We clamp before dither, which is a bit unfortunate, since - // it means dither can take us out of the clamped range again. - // However, since DitherEffect never adds enough dither to change - // the quantized levels, we will be fine in practice. - ycbcr_a.rgb = clamp(ycbcr_a.rgb, PREFIX(ycbcr_min), PREFIX(ycbcr_max)); -#endif + if (PREFIX(clamp_range)) { + // If we use limited-range Y'CbCr, the card's usual 0–255 clamping + // won't be enough, so we need to clamp ourselves here. + // + // We clamp before dither, which is a bit unfortunate, since + // it means dither can take us out of the clamped range again. + // However, since DitherEffect never adds enough dither to change + // the quantized levels, we will be fine in practice. + ycbcr_a.rgb = clamp(ycbcr_a.rgb, PREFIX(ycbcr_min), PREFIX(ycbcr_max)); + } ycbcr_a.a = rgba.a; + +#if YCBCR_ALSO_OUTPUT_RGBA + return vec4[2](ycbcr_a, rgba); +#else return ycbcr_a; +#endif }