From 860dcbf888ee3c9a34b734190bf99201459f0148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Mon, 18 Mar 2024 21:17:56 +0100 Subject: [PATCH] colorspace: use pl_color_space_is_black_scaled also in linearize --- src/colorspace.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/colorspace.c b/src/colorspace.c index df9db743..5e8f8585 100644 --- a/src/colorspace.c +++ b/src/colorspace.c @@ -596,7 +596,7 @@ void pl_color_linearize(const struct pl_color_space *csp, float color[3]) MAP3(powf(X, 1 / PQ_M2)); MAP3(fmaxf(X - PQ_C1, 0) / (PQ_C2 - PQ_C3 * X)); MAP3(10000 / PL_COLOR_SDR_WHITE * powf(X, 1 / PQ_M1)); - return; + goto scale_out; case PL_COLOR_TRC_HLG: { const float y = fmaxf(1.2f + 0.42f * log10f(csp_max / HLG_REF), 1); const float b = sqrtf(3 * powf(csp_min / csp_max, 1 / y)); @@ -611,19 +611,19 @@ void pl_color_linearize(const struct pl_color_space *csp, float color[3]) float luma = coef[0] * color[0] + coef[1] * color[1] + coef[2] * color[2]; luma = powf(fmaxf(luma / 12, 0), y - 1); MAP3(luma * X / 12); - return; + goto scale_out; } case PL_COLOR_TRC_V_LOG: MAP3(X >= 0.181f ? powf(10, (X - VLOG_D) / VLOG_C) - VLOG_B : (X - 0.125f) / 5.6f); - return; + goto scale_out; case PL_COLOR_TRC_S_LOG1: MAP3(powf(10, (X - SLOG_C) / SLOG_A) - SLOG_B); - return; + goto scale_out; case PL_COLOR_TRC_S_LOG2: MAP3(X >= SLOG_Q ? (powf(10, (X - SLOG_C) / SLOG_A) - SLOG_B) / SLOG_K2 : (X - SLOG_Q) / SLOG_P); - return; + goto scale_out; case PL_COLOR_TRC_LINEAR: case PL_COLOR_TRC_COUNT: break; @@ -632,7 +632,8 @@ void pl_color_linearize(const struct pl_color_space *csp, float color[3]) pl_unreachable(); scale_out: - MAP3((csp_max - csp_min) * X + csp_min); + if (pl_color_space_is_black_scaled(csp) && csp->transfer != PL_COLOR_TRC_HLG) + MAP3((csp_max - csp_min) * X + csp_min); } void pl_color_delinearize(const struct pl_color_space *csp, float color[3])