summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <git@nand.wakku.to>2015-04-29 22:04:11 +0200
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-05-07 10:40:44 +0900
commit99389eb174a7c5b489a7f044c9765e668ccff6f9 (patch)
tree8caaf2b37eac7841228455a34ae1b5cd396f2e4f
parentaf930e2a2e3f33aa11a0fea3d6c3e3c7344b21fb (diff)
downloadmpv-99389eb174a7c5b489a7f044c9765e668ccff6f9.tar.bz2
mpv-99389eb174a7c5b489a7f044c9765e668ccff6f9.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. (cherry picked from commit 99439f11ea6add0996adc6f5fb04bb7d27da265e)
-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);