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 | |
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.
-rw-r--r-- | DOCS/man/options.rst | 7 | ||||
-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 |
4 files changed, 21 insertions, 0 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 209b857850..e5e43bfb7f 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -6167,6 +6167,13 @@ The following video options are currently all specific to ``--vo=gpu`` and well with ICC profiles, since the 3DLUTs are always generated against the source color space and have chromatically-accurate clipping built in. +``--gamut-clipping`` + If enabled (default: yes), mpv will colorimetrically clip out-of-gamut + colors by desaturating them (preserving luma), rather than hard-clipping + each component individually. This should make playback of wide gamut + content on typical (standard gamut) monitors look much more aesthetically + pleasing and less blown-out. + ``--use-embedded-icc-profile`` Load the embedded ICC profile contained in media files such as PNG images. (Default: yes). Note that this option only works when also using a display 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) |