Simplify clamp_component

Surprise surprise: the compiler generates shorter, branch-free code
if we don't try to be clever with signed/unsigned casting tricks.

Change-Id: I93d2020b6127e7d43feee394b06a52aaeddf3b79
This commit is contained in:
Aidan MacDonald 2021-07-28 11:18:51 +01:00 committed by William Wilgus
parent 429a7e2c0a
commit 03a6eb63f1

View file

@ -83,8 +83,8 @@ union uint8_rgbyuv {
static inline int clamp_component(int x)
{
if ((unsigned)x > 255)
x = x < 0 ? 0 : 255;
if(x > 255) return 255;
if(x < 0) return 0;
return x;
}
#include <debug.h>