From 14554b877756ca429de205cf11eb5bc7e1563f51 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 8 Oct 2024 15:18:23 +0200 Subject: [PATCH] moved internal macros from color.h to .c --- src/color.c | 30 ++++++++++++++++++++++++++++++ src/color.h | 28 ---------------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/color.c b/src/color.c index 16f2d1873..e10fdc677 100644 --- a/src/color.c +++ b/src/color.c @@ -43,9 +43,27 @@ #include "host.h" // for ADD_TO_PARAM #include "types.h" // for depth +#define KG(kr,kb) (1.-(kr)-(kb)) #define D(kr, kb) (2. * ((kr) + KG(kr, kb))) #define E(kr) (2. * (1. - (kr))) +#ifdef YCBCR_FULL +#define C_EPS 0 // prevent under/overflows when there is no clip +#define Y_LIMIT(out_depth) 1.0 +#define CBCR_LIMIT(out_depth) 1.0 +#else +#define C_EPS 0.5 +#define Y_LIMIT(out_depth) \ + (219. * (1 << ((out_depth) - 8)) / ((1 << (out_depth)) - 1)) +#define CBCR_LIMIT(out_depth) \ + (224. * (1 << ((out_depth) - 8)) / ((1 << (out_depth)) - 1)) +#endif // !defined YCBCR_FULL + +#define Y_LIMIT_INV(in_depth) (1./Y_LIMIT(in_depth)) +#define Y_SCALE(in_depth) \ + SCALED(Y_LIMIT_INV(in_depth)) // precomputed value, Y multiplier is same + // for all channels + #define Y_R(out_depth, kr, kb) \ ((comp_type_t) (((kr * Y_LIMIT(out_depth)) * (1 << COMP_BASE)) + C_EPS)) #define Y_G(out_depth, kr, kb) \ @@ -80,6 +98,18 @@ (1 << COMP_BASE)) + \ C_EPS)) +#define C_SIGN(x) ((x) > 0 ? 1. : -1.) +#define SCALED(x) ((comp_type_t) (((x) * (1<= COMP_BASE + 18, "comp_type_t not wide enough (we are computing in up to 16 bits!)"); -#ifdef YCBCR_FULL -#define C_EPS 0 // prevent under/overflows when there is no clip -#define Y_LIMIT(out_depth) 1.0 -#define CBCR_LIMIT(out_depth) 1.0 -#else -#define C_EPS 0.5 -#define Y_LIMIT(out_depth) \ - (219. * (1 << ((out_depth) - 8)) / ((1 << (out_depth)) - 1)) -#define CBCR_LIMIT(out_depth) \ - (224. * (1 << ((out_depth) - 8)) / ((1 << (out_depth)) - 1)) -#endif // !defined YCBCR_FULL - #define KR_601 .299 #define KB_601 .114 #define KR_709 .212639 @@ -91,7 +79,6 @@ static_assert(sizeof(comp_type_t) * 8 >= COMP_BASE + 18, "comp_type_t not wide e #define KB_2020 .059302 #define KR_P3 .228975 #define KB_P3 .079287 -#define KG(kr,kb) (1.-kr-kb) #ifdef YCBCR_FULL #define LIMIT_LO(depth) 0 @@ -106,21 +93,6 @@ static_assert(sizeof(comp_type_t) * 8 >= COMP_BASE + 18, "comp_type_t not wide e #define CLAMP_LIMITED_Y(val, depth) (val) #define CLAMP_LIMITED_CBCR(val, depth) (val) -#define C_SIGN(x) ((x) > 0 ? 1. : -1.) -#define SCALED(x) ((comp_type_t) (((x) * (1<