diff options
author | Niklas Haas <git@haasn.xyz> | 2020-06-19 08:03:46 +0200 |
---|---|---|
committer | Niklas Haas <git@haasn.xyz> | 2020-06-19 08:09:19 +0200 |
commit | dc24a437fb9ba2485bc8c5866542bd36254410d4 (patch) | |
tree | 35a8090178cc19bc4e302389a46b006c8cf75845 /video/out/gpu | |
parent | ae5ac7e90a96c02f66b3eb5b63ed960bfffa3fdb (diff) | |
download | mpv-dc24a437fb9ba2485bc8c5866542bd36254410d4.tar.bz2 mpv-dc24a437fb9ba2485bc8c5866542bd36254410d4.tar.xz |
vo_gpu: add better gamut clipping option
See https://code.videolan.org/videolan/libplacebo/-/commit/d63eeb1ecc204
Enabled by default because I think it looks better. YMMV.
Diffstat (limited to 'video/out/gpu')
-rw-r--r-- | video/out/gpu/video.c | 2 | ||||
-rw-r--r-- | video/out/gpu/video.h | 1 | ||||
-rw-r--r-- | video/out/gpu/video_shaders.c | 11 |
3 files changed, 14 insertions, 0 deletions
diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c index f135d0ff94..851289e281 100644 --- a/video/out/gpu/video.c +++ b/video/out/gpu/video.c @@ -330,6 +330,7 @@ static const struct gl_video_opts gl_video_opts_def = { .scene_threshold_high = 10.0, .desat = 0.75, .desat_exp = 1.5, + .gamut_clipping = 1, }, .early_flush = -1, .hwdec_interop = "auto", @@ -401,6 +402,7 @@ const struct m_sub_options gl_video_conf = { {"tone-mapping-desaturate-exponent", OPT_FLOAT(tone_map.desat_exp), M_RANGE(0.0, 20.0)}, {"gamut-warning", OPT_FLAG(tone_map.gamut_warning)}, + {"gamut-clipping", OPT_FLAG(tone_map.gamut_clipping)}, {"opengl-pbo", OPT_FLAG(pbo)}, SCALER_OPTS("scale", SCALER_SCALE), SCALER_OPTS("dscale", SCALER_DSCALE), diff --git a/video/out/gpu/video.h b/video/out/gpu/video.h index 4e442a5e6d..dd16744778 100644 --- a/video/out/gpu/video.h +++ b/video/out/gpu/video.h @@ -108,6 +108,7 @@ struct gl_tone_map_opts { float desat; float desat_exp; int gamut_warning; // bool + int gamut_clipping; // bool }; struct gl_video_opts { diff --git a/video/out/gpu/video_shaders.c b/video/out/gpu/video_shaders.c index 5bc32dcd3b..19b002170d 100644 --- a/video/out/gpu/video_shaders.c +++ b/video/out/gpu/video_shaders.c @@ -870,6 +870,17 @@ void pass_color_map(struct gl_shader_cache *sc, bool is_linear, mp_get_cms_matrix(csp_src, csp_dst, MP_INTENT_RELATIVE_COLORIMETRIC, m); gl_sc_uniform_mat3(sc, "cms_matrix", true, &m[0][0]); GLSL(color.rgb = cms_matrix * color.rgb;) + + if (opts->gamut_clipping) { + GLSL(float cmin = min(min(color.r, color.g), color.b);) + GLSL(if (cmin < 0.0) { + float luma = dot(dst_luma, color.rgb); + float coeff = cmin / (cmin - luma); + color.rgb = mix(color.rgb, vec3(luma), coeff); + }) + GLSL(float cmax = max(max(color.r, color.g), color.b);) + GLSL(if (cmax > 1.0) color.rgb /= cmax;) + } } if (need_ootf) |