From b9e7478760a34827ae5e4f202713509ee553dd9a Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 14 Feb 2018 14:14:48 +0100 Subject: vo_gpu: simplify and correct color scale handling The primary need for this change is the fact that the OOTF was incorrectly scaled, due to the fact that the application of the OOTF can itself change the required normalization peak. (Plus, an oversight in pass_inverse_ootf meant we forgot to normalize at the end of it) The linearize/delinearize functions still normalize the scale since it's used in a number of places throughout gpu/video.c, but the color management function now converts to absolute scale right away, instead of in an awkward way inside the tone mapping branch. The OOTF functions now work in absolute scale only. In addition, minor changes have been made to the way normalization is handled for tone mapping - we now divide out the dst_peak *after* peak detection, in order to make the scale of the peak detection buffer consistent even if the dst_peak were to (hypothetically) change mid-stream. In theory, we could also do this for desaturation, but doing the desaturation before tone mapping has the advantage of preserving much more brightness than the other way around - and even mid-stream changes are not that drastic here. Finally, some preparation work has been done for allowing the user to customize the `dst.sig_peak` in the future. --- video/out/gpu/video.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'video/out/gpu/video.c') diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c index 2d4e711210..fdefc0044f 100644 --- a/video/out/gpu/video.c +++ b/video/out/gpu/video.c @@ -2411,6 +2411,7 @@ static void pass_colormanage(struct gl_video *p, struct mp_colorspace src, bool if (gl_video_get_lut3d(p, prim_orig, trc_orig)) { dst.primaries = prim_orig; dst.gamma = trc_orig; + assert(dst.primaries && dst.gamma); } } @@ -2445,6 +2446,11 @@ static void pass_colormanage(struct gl_video *p, struct mp_colorspace src, bool dst.gamma = MP_CSP_TRC_GAMMA22; } + // For now, just infer the dst sig peak from the gamma function always. + // In theory, we could allow users to configure this or detect it from the + // ICC profile, but avoid the complexity for now. + dst.sig_peak = mp_trc_nom_peak(dst.gamma); + bool detect_peak = p->opts.compute_hdr_peak >= 0 && mp_trc_is_hdr(src.gamma); if (detect_peak && !p->hdr_peak_ssbo) { struct { -- cgit v1.2.3