From 99389eb174a7c5b489a7f044c9765e668ccff6f9 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 29 Apr 2015 22:04:11 +0200 Subject: [PATCH] csputils: improve contrast semantics for limited range output The previous version of this logic resulted in black crush and incorrect brightness scaling when combined with limited range (TV) output. (cherry picked from commit 99439f11ea6add0996adc6f5fb04bb7d27da265e) --- video/csputils.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/video/csputils.c b/video/csputils.c index f42cfb398b..238c4daf4e 100644 --- a/video/csputils.c +++ b/video/csputils.c @@ -671,18 +671,22 @@ void mp_get_yuv2rgb_coeffs(struct mp_csp_params *params, struct mp_cmat *m) abort(); } - rgblev.min = (rgblev.min + params->brightness) * params->contrast; - rgblev.max = (rgblev.max + params->brightness) * params->contrast; - double ymul = (rgblev.max - rgblev.min) / (yuvlev.ymax - yuvlev.ymin); double cmul = (rgblev.max - rgblev.min) / (yuvlev.cmid - yuvlev.cmin) / 2; + + // Contrast scales the output value range (gain) + ymul *= params->contrast; + cmul *= params->contrast; + for (int i = 0; i < 3; i++) { m->m[i][0] *= ymul; m->m[i][1] *= cmul; m->m[i][2] *= cmul; - // Set c so that Y=umin,UV=cmid maps to RGB=min (black to black) + // Set c so that Y=umin,UV=cmid maps to RGB=min (black to black), + // also add brightness offset (black lift) m->c[i] = rgblev.min - m->m[i][0] * yuvlev.ymin - -(m->m[i][1] + m->m[i][2]) * yuvlev.cmid; + - (m->m[i][1] + m->m[i][2]) * yuvlev.cmid + + params->brightness; } int in_bits = FFMAX(params->int_bits_in, 1);