summaryrefslogtreecommitdiffstats
path: root/video/csputils.c
diff options
context:
space:
mode:
authorNiklas Haas <git@nand.wakku.to>2015-04-29 22:04:11 +0200
committerNiklas Haas <git@nand.wakku.to>2015-04-29 22:09:09 +0200
commit99439f11ea6add0996adc6f5fb04bb7d27da265e (patch)
tree415f3939b8d45e91815c7b8939b6f56c441244ab /video/csputils.c
parent0600d378f9afb20d92e75d26c0df7d255e1df554 (diff)
downloadmpv-99439f11ea6add0996adc6f5fb04bb7d27da265e.tar.bz2
mpv-99439f11ea6add0996adc6f5fb04bb7d27da265e.tar.xz
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.
Diffstat (limited to 'video/csputils.c')
-rw-r--r--video/csputils.c14
1 files 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);