From 701c8c8254c22b2def38515a1d09dcdd94fea3d3 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Mon, 24 Feb 2014 13:39:39 +0100 Subject: vo_opengl: Add :icc-approx-gamma suboption to approximate BT.709 gamma This uses the value of 1.95 as an approximation for the exact gamma curve, which replicates the behavior of popular video software including anything in the Apple ecosystem, as per issue #534. --- DOCS/man/en/vo.rst | 8 ++++++++ video/out/gl_lcms.c | 22 ++++++++++++++++------ video/out/gl_lcms.h | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/DOCS/man/en/vo.rst b/DOCS/man/en/vo.rst index 8c3f1ba030..9e74cc9f3d 100644 --- a/DOCS/man/en/vo.rst +++ b/DOCS/man/en/vo.rst @@ -462,6 +462,14 @@ Available video output drivers are: 3 absolute colorimetric (default) + ``icc-approx-gamma`` + Approximate the actual BT.709 gamma function as a pure power curve of + 1.95. This is not quite correct, but it was historically used as a + faster version of the actual function, and seems to still be used by + many video editing programs and perhaps even studios. If you find your + videos displaying ever so slightly slightly brighter than you'd expect + them to, try enabling this option. + ``3dlut-size=xx`` Size of the 3D LUT generated from the ICC profile in each dimension. Default is 128x256x64. diff --git a/video/out/gl_lcms.c b/video/out/gl_lcms.c index a6f30e0126..6fd86d9874 100644 --- a/video/out/gl_lcms.c +++ b/video/out/gl_lcms.c @@ -73,6 +73,7 @@ const struct m_sub_options mp_icc_conf = { OPT_STRING("icc-profile", profile, 0), OPT_STRING("icc-cache", cache, 0), OPT_INT("icc-intent", intent, 0), + OPT_FLAG("icc-approx-gamma", approx, 0), OPT_STRING_VALIDATE("3dlut-size", size_str, 0, validate_3dlut_size_opt), {0} }, @@ -164,13 +165,22 @@ struct lut3d *mp_load_icc(struct mp_icc_opts *opts, struct mp_log *log, .Blue = {0.15, 0.06, 1.0}, }; - /* Rec BT.709 defines the tone curve as: - V = 1.099 * L^0.45 - 0.099 for L >= 0.018 - V = 4.500 * L for L < 0.018 - - The 0.081 parameter comes from inserting 0.018 into the function */ - cmsToneCurve *tonecurve = cmsBuildParametricToneCurve(NULL, 4, + cmsToneCurve *tonecurve; + if (opts->approx) { + /* Apple's CMS, among other programs that rely on it, uses 1.95 as a + faster approximation of this curve. It's not quite correct, but the + option is provided for compatibility with such incorrect clips. */ + tonecurve = cmsBuildGamma(NULL, 1.95); + } else { + /* Rec BT.709 defines the tone curve as: + V = 1.099 * L^0.45 - 0.099 for L >= 0.018 + V = 4.500 * L for L < 0.018 + + The 0.081 parameter comes from inserting 0.018 into the function */ + tonecurve = cmsBuildParametricToneCurve(NULL, 4, (cmsFloat64Number[5]){1/0.45, 1/1.099, 0.099/1.099, 1/4.5, 0.081}); + } + cmsHPROFILE vid_profile = cmsCreateRGBProfile(&d65, &bt709prim, (cmsToneCurve*[3]){tonecurve, tonecurve, tonecurve}); cmsFreeToneCurve(tonecurve); diff --git a/video/out/gl_lcms.h b/video/out/gl_lcms.h index a579b78f43..4a8e0cfb6a 100644 --- a/video/out/gl_lcms.h +++ b/video/out/gl_lcms.h @@ -8,6 +8,7 @@ struct mp_icc_opts { char *cache; char *size_str; int intent; + int approx; }; struct lut3d; -- cgit v1.2.3