From 3c3a80b2408d5a98521746c26502cd7addf3b365 Mon Sep 17 00:00:00 2001 From: notaz Date: Tue, 22 Oct 2024 23:53:38 +0300 Subject: [PATCH] mdec: compiler-friendlier clamp that whole thing begs to be rewritten but ohwell --- libpcsxcore/mdec.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/libpcsxcore/mdec.c b/libpcsxcore/mdec.c index 38b03e1b..d02a419a 100644 --- a/libpcsxcore/mdec.c +++ b/libpcsxcore/mdec.c @@ -323,11 +323,22 @@ static const unsigned short *rl2blk(int *blk, const unsigned short *mdec_rl) { #define SCALE8(c) SCALER(c, 20) #define SCALE5(c) SCALER(c, 23) -#define CLAMP5(c) ( ((c) < -16) ? 0 : (((c) > (31 - 16)) ? 31 : ((c) + 16)) ) -#define CLAMP8(c) ( ((c) < -128) ? 0 : (((c) > (255 - 128)) ? 255 : ((c) + 128)) ) +static inline int clamp5(int v) +{ + v += 16; + v = v < 0 ? 0 : (v > 31 ? 31 : v); + return v; +} + +static inline int clamp8(int v) +{ + v += 128; + v = v < 0 ? 0 : (v > 255 ? 255 : v); + return v; +} -#define CLAMP_SCALE8(a) (CLAMP8(SCALE8(a))) -#define CLAMP_SCALE5(a) (CLAMP5(SCALE5(a))) +#define CLAMP_SCALE8(a) (clamp8(SCALE8(a))) +#define CLAMP_SCALE5(a) (clamp5(SCALE5(a))) static inline void putlinebw15(u16 *image, int *Yblk) { int i; @@ -336,7 +347,7 @@ static inline void putlinebw15(u16 *image, int *Yblk) { for (i = 0; i < 8; i++, Yblk++) { int Y = *Yblk; // missing rounding - image[i] = SWAP16((CLAMP5(Y >> 3) * 0x421) | A); + image[i] = SWAP16((clamp5(Y >> 3) * 0x421) | A); } } @@ -385,7 +396,7 @@ static inline void putlinebw24(u8 * image, int *Yblk) { int i; unsigned char Y; for (i = 0; i < 8 * 3; i += 3, Yblk++) { - Y = CLAMP8(*Yblk); + Y = clamp8(*Yblk); image[i + 0] = Y; image[i + 1] = Y; image[i + 2] = Y; -- 2.39.5