From 03a6eb63f1ad6c94aa693bf7d5c766b25072c5ef Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Wed, 28 Jul 2021 11:18:51 +0100 Subject: [PATCH] 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 --- apps/recorder/jpeg_common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/recorder/jpeg_common.h b/apps/recorder/jpeg_common.h index c2abce8f49..de998f1ddd 100644 --- a/apps/recorder/jpeg_common.h +++ b/apps/recorder/jpeg_common.h @@ -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