From 8adbd3d8026d106ac01ce264f62c651316a51ee5 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Tue, 10 May 2022 11:34:57 +0300 Subject: [PATCH] tests/color_util: streamline sRGB_linearize/delinearize Re-use color_float_apply_curve() instead of open-coding it. Maybe makes reading the code a little easier. Signed-off-by: Pekka Paalanen --- tests/color_util.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/tests/color_util.c b/tests/color_util.c index 44d1e034..f00a2400 100644 --- a/tests/color_util.c +++ b/tests/color_util.c @@ -161,15 +161,6 @@ Power2_4_EOTF_inv(float o) return pow(o, 1./2.4); } -void -sRGB_linearize(struct color_float *cf) -{ - int i; - - for (i = 0; i < COLOR_CHAN_NUM; i++) - cf->rgb[i] = sRGB_EOTF(cf->rgb[i]); -} - static float apply_tone_curve(enum transfer_fn fn, float r) { @@ -199,15 +190,6 @@ apply_tone_curve(enum transfer_fn fn, float r) return ret; } -void -sRGB_delinearize(struct color_float *cf) -{ - int i; - - for (i = 0; i < COLOR_CHAN_NUM; i++) - cf->rgb[i] = sRGB_EOTF_inv(cf->rgb[i]); -} - struct color_float a8r8g8b8_to_float(uint32_t v) { @@ -232,6 +214,18 @@ color_float_apply_curve(enum transfer_fn fn, struct color_float c) return c; } +void +sRGB_linearize(struct color_float *cf) +{ + *cf = color_float_apply_curve(TRANSFER_FN_SRGB_EOTF, *cf); +} + +void +sRGB_delinearize(struct color_float *cf) +{ + *cf = color_float_apply_curve(TRANSFER_FN_SRGB_EOTF_INVERSE, *cf); +} + /* * Returns the result of the matrix-vector multiplication mat * c. */