From cb9ba6cb26a2b5649c7b9ea997ed5b25ede5360c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 24 Jan 2023 07:54:01 +0100 Subject: [PATCH] csputils: add MP_CSP_TRC_ST428 as defined in ST 428-1 --- video/csputils.c | 3 +++ video/csputils.h | 1 + video/out/gpu/video_shaders.c | 6 ++++++ video/out/placebo/utils.c | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/video/csputils.c b/video/csputils.c index be5295c380..a0db6c8cd4 100644 --- a/video/csputils.c +++ b/video/csputils.c @@ -87,6 +87,7 @@ const struct m_opt_choice_alternatives mp_csp_trc_names[] = { {"v-log", MP_CSP_TRC_V_LOG}, {"s-log1", MP_CSP_TRC_S_LOG1}, {"s-log2", MP_CSP_TRC_S_LOG2}, + {"st428", MP_CSP_TRC_ST428}, {0} }; @@ -208,6 +209,7 @@ enum mp_csp_trc avcol_trc_to_mp_csp_trc(int avtrc) case AVCOL_TRC_GAMMA28: return MP_CSP_TRC_GAMMA28; case AVCOL_TRC_SMPTEST2084: return MP_CSP_TRC_PQ; case AVCOL_TRC_ARIB_STD_B67: return MP_CSP_TRC_HLG; + case AVCOL_TRC_SMPTE428: return MP_CSP_TRC_ST428; default: return MP_CSP_TRC_AUTO; } } @@ -260,6 +262,7 @@ int mp_csp_trc_to_avcol_trc(enum mp_csp_trc trc) case MP_CSP_TRC_GAMMA28: return AVCOL_TRC_GAMMA28; case MP_CSP_TRC_PQ: return AVCOL_TRC_SMPTEST2084; case MP_CSP_TRC_HLG: return AVCOL_TRC_ARIB_STD_B67; + case MP_CSP_TRC_ST428: return AVCOL_TRC_SMPTE428; default: return AVCOL_TRC_UNSPECIFIED; } } diff --git a/video/csputils.h b/video/csputils.h index cbf7df96e6..69928b29f2 100644 --- a/video/csputils.h +++ b/video/csputils.h @@ -89,6 +89,7 @@ enum mp_csp_trc { MP_CSP_TRC_V_LOG, MP_CSP_TRC_S_LOG1, MP_CSP_TRC_S_LOG2, + MP_CSP_TRC_ST428, MP_CSP_TRC_COUNT }; diff --git a/video/out/gpu/video_shaders.c b/video/out/gpu/video_shaders.c index d9393faa48..049151bd24 100644 --- a/video/out/gpu/video_shaders.c +++ b/video/out/gpu/video_shaders.c @@ -422,6 +422,9 @@ void pass_linearize(struct gl_shader_cache *sc, enum mp_csp_trc trc) " %s(lessThanEqual(vec3(%f), color.rgb))); \n", SLOG_Q, SLOG_P, SLOG_C, SLOG_A, SLOG_B, SLOG_K2, gl_sc_bvec(sc, 3), SLOG_Q); break; + case MP_CSP_TRC_ST428: + GLSL(color.rgb = vec3(52.37/48.0) * pow(color.rgb, vec3(2.6));); + break; default: abort(); } @@ -512,6 +515,9 @@ void pass_delinearize(struct gl_shader_cache *sc, enum mp_csp_trc trc) " %s(lessThanEqual(vec3(0.0), color.rgb))); \n", SLOG_P, SLOG_Q, SLOG_A / M_LN10, SLOG_K2, SLOG_B, SLOG_C, gl_sc_bvec(sc, 3)); break; + case MP_CSP_TRC_ST428: + GLSL(color.rgb = pow(color.rgb * vec3(48.0/52.37), vec3(1.0/2.6));); + break; default: abort(); } diff --git a/video/out/placebo/utils.c b/video/out/placebo/utils.c index 76fac9234d..03a2fdd005 100644 --- a/video/out/placebo/utils.c +++ b/video/out/placebo/utils.c @@ -110,6 +110,11 @@ enum pl_color_transfer mp_trc_to_pl(enum mp_csp_trc trc) case MP_CSP_TRC_V_LOG: return PL_COLOR_TRC_V_LOG; case MP_CSP_TRC_S_LOG1: return PL_COLOR_TRC_S_LOG1; case MP_CSP_TRC_S_LOG2: return PL_COLOR_TRC_S_LOG2; +#if PL_API_VER >= 240 + case MP_CSP_TRC_ST428: return PL_COLOR_TRC_ST428; +#else + case MP_CSP_TRC_ST428: return PL_COLOR_TRC_UNKNOWN; +#endif case MP_CSP_TRC_COUNT: return PL_COLOR_TRC_COUNT; }