diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-07-28 11:18:51 +0100 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2021-08-05 10:26:50 +0000 |
commit | 03a6eb63f1ad6c94aa693bf7d5c766b25072c5ef (patch) | |
tree | 7f0affdf9ef081d4723703ed03c218b6da3c4267 | |
parent | 429a7e2c0a83f70b0dc15c5287547fafcac80a9c (diff) | |
download | rockbox-03a6eb63f1ad6c94aa693bf7d5c766b25072c5ef.tar.gz rockbox-03a6eb63f1ad6c94aa693bf7d5c766b25072c5ef.zip |
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
-rw-r--r-- | apps/recorder/jpeg_common.h | 4 |
1 files 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 { | |||
83 | 83 | ||
84 | static inline int clamp_component(int x) | 84 | static inline int clamp_component(int x) |
85 | { | 85 | { |
86 | if ((unsigned)x > 255) | 86 | if(x > 255) return 255; |
87 | x = x < 0 ? 0 : 255; | 87 | if(x < 0) return 0; |
88 | return x; | 88 | return x; |
89 | } | 89 | } |
90 | #include <debug.h> | 90 | #include <debug.h> |