From 8d15f7583ca000bc06568c79175835a7eed3cd3d Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 28 Jan 2015 18:52:33 +0100 Subject: [PATCH] vo_opengl: remove is_linear_rgb and clean up code This opportunity for refactoring was enabled by f3c84a3. --- video/csputils.h | 3 ++- video/out/gl_video.c | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/video/csputils.h b/video/csputils.h index f973117751..abf319cdcb 100644 --- a/video/csputils.h +++ b/video/csputils.h @@ -70,7 +70,8 @@ enum mp_csp_prim { enum mp_csp_trc { MP_CSP_TRC_NONE, MP_CSP_TRC_BT_1886, - MP_CSP_TRC_SRGB + MP_CSP_TRC_SRGB, + MP_CSP_TRC_LINEAR }; // Any enum mp_csp_prim value is a valid index (except MP_CSP_PRIM_COUNT) diff --git a/video/out/gl_video.c b/video/out/gl_video.c index f31c63b571..805df58de6 100644 --- a/video/out/gl_video.c +++ b/video/out/gl_video.c @@ -1106,19 +1106,16 @@ static void compile_shaders(struct gl_video *p) float input_gamma = 1.0; float conv_gamma = 1.0; - bool is_linear_rgb = false; - if (p->image_desc.flags & MP_IMGFLAG_XYZ) { + bool is_xyz = p->image_desc.flags & MP_IMGFLAG_XYZ; + if (is_xyz) { input_gamma *= 2.6; // If we're using cms, we can treat it as proper linear input, // otherwise we just scale back to 2.40 to match typical displays, // as a reasonable approximation. - if (use_cms) { - is_linear_rgb = true; - } else { + if (!use_cms) conv_gamma *= 1.0 / 2.40; - } } p->input_gamma = input_gamma; @@ -1133,11 +1130,14 @@ static void compile_shaders(struct gl_video *p) // Linear light scaling is only enabled when either color correction // option (3dlut or srgb) is enabled, otherwise scaling is done in the // source space. - if (!is_linear_rgb && use_cms) { - // We just use the color level range to distinguish between PC + if (use_cms) { + // We use the color level range to distinguish between PC // content like images, which are most likely sRGB, and TV content - // like movies, which are most likely BT.1886 - if (p->image_params.colorlevels == MP_CSP_LEVELS_PC && !p->hwdec_active) { + // like movies, which are most likely BT.1886. XYZ input is always + // treated as linear. + if (is_xyz) { + gamma_fun = MP_CSP_TRC_LINEAR; + } else if (p->image_params.colorlevels == MP_CSP_LEVELS_PC && !p->hwdec_active) { // FIXME: I don't know if hwdec sets the color levels to PC or not, // but let's avoid the bug just in case. gamma_fun = MP_CSP_TRC_SRGB; @@ -1146,7 +1146,7 @@ static void compile_shaders(struct gl_video *p) } } - bool use_linear_light = gamma_fun != MP_CSP_TRC_NONE || is_linear_rgb; + bool use_linear_light = gamma_fun != MP_CSP_TRC_NONE; // Optionally transform to sigmoidal color space if requested, but only // when upscaling in linear light