summaryrefslogtreecommitdiffstats
path: root/video/out/gl_lcms.c
diff options
context:
space:
mode:
authorNiklas Haas <git@nand.wakku.to>2014-03-05 03:56:30 +0100
committerwm4 <wm4@nowhere>2014-03-10 22:56:25 +0100
commit6a833797dbafaf11bd37ba9827f828ff07e4577d (patch)
tree53e3a4a393e9f35509f088b857b16ffa383171cc /video/out/gl_lcms.c
parent76554ca62a27d2f3dfdff38dc8675fd43bc6ea49 (diff)
downloadmpv-6a833797dbafaf11bd37ba9827f828ff07e4577d.tar.bz2
mpv-6a833797dbafaf11bd37ba9827f828ff07e4577d.tar.xz
vo_opengl: Simplify and clarify color correction code
This commit: - Changes some of the #define and variable names for clarification and adds comments where appropriate. - Unifies :srgb and :icc-profile, making them fit into the same step of the decoding process and removing the weird interactions between both of them. - Makes :icc-profile take precedence over :srgb (to significantly reduce the number of confusing and useless special cases) - Moves BT709 decompanding (approximate or actual) to the shader in all cases, making it happen before upscaling (instead of the old 0.45 gamma function). This is the simpler and more proper way to do it. - Enables the approx gamma function to work with :srgb as well due to this (since they now share the gamma expansion code). - Renames :icc-approx-gamma to :approx-gamma since it is no longer tied to the ICC options or LittleCMS. - Uses gamma 2.4 as input space for the actual 3DLUT, this is now a pretty arbitrary factor but I picked 2.4 mainly because a higher pure power value here seems to produce visually better results with wide gamut profiles, rather then the previous 1.95 or BT.709. - Adds the input gamma space to the 3dlut cache header in case we change it more in the future, or even make it user customizable (though I don't see why the latter would really be necessary). - Fixes the OSD's gamma when using :srgb, which was previously still using the old (0.45) approximation in all cases. - Updates documentation on :srgb, it was still mentioning the old behavior from circa a year ago. This commit should serve to both open up and make the CMS/shader code much more accessible and less confusing/error-prone and simultaneously also improve the performance of 3DLUTs with wide gamut color spaces. I would liked to have made it more modular but almost all of these changes are interdependent, save for the documentation updates. Note: Right now, the "3DLUT takes precedence over SRGB" logic is just coded into gl_lcms.c's compile_shaders function. Ideally, this should be done earlier, when parsing the options (by overriding the actual opts.srgb flag) and output a warning to the user. Note: I'm not sure how well this works together with real-world subtitles that may need to be color corrected as well. I'm not sure whether :approx-gamma needs to apply to subtitles as well. I'll need to test this on proper files later. Note: As of now, linear light scaling is still intrinsically tied to either :srgb or :icc-profile. It would be thinkable to have this as an extra option, :linear-scaling or similar, that could be used with or without the two color management options.
Diffstat (limited to 'video/out/gl_lcms.c')
-rw-r--r--video/out/gl_lcms.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/video/out/gl_lcms.c b/video/out/gl_lcms.c
index 8c30ce3719..08f89b81d9 100644
--- a/video/out/gl_lcms.c
+++ b/video/out/gl_lcms.c
@@ -73,7 +73,6 @@ 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}
},
@@ -130,8 +129,11 @@ struct lut3d *mp_load_icc(struct mp_icc_opts *opts, struct mp_log *log,
goto error_exit;
char *cache_info =
- talloc_asprintf(tmp, "intent=%d, size=%dx%dx%d, approx=%d\n",
- opts->intent, s_r, s_g, s_b, opts->approx);
+ // Gamma is included in the header to help uniquely identify it,
+ // because we may change the parameter in the future or make it
+ // customizable.
+ talloc_asprintf(tmp, "intent=%d, size=%dx%dx%d, gamma=2.4",
+ opts->intent, s_r, s_g, s_b);
// check cache
if (opts->cache) {
@@ -166,22 +168,9 @@ struct lut3d *mp_load_icc(struct mp_icc_opts *opts, struct mp_log *log,
.Blue = {0.15, 0.06, 1.0},
};
- 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});
- }
-
+ // 2.4 is arbitrarily used as a gamma compression factor for the 3DLUT,
+ // reducing artifacts due to rounding errors on wide gamut profiles
+ cmsToneCurve *tonecurve = cmsBuildGamma(NULL, 2.4);
cmsHPROFILE vid_profile = cmsCreateRGBProfile(&d65, &bt709prim,
(cmsToneCurve*[3]){tonecurve, tonecurve, tonecurve});
cmsFreeToneCurve(tonecurve);