From 546a5ccdba66dd8d8c19ce6d8486f46c84637cf2 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Sat, 7 Dec 2024 13:58:46 -0700 Subject: Add way to toggle the default pattern and a way to switch the pattern. --- include/byte_math.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include/byte_math.h') diff --git a/include/byte_math.h b/include/byte_math.h index 79f93b8..9be4b67 100644 --- a/include/byte_math.h +++ b/include/byte_math.h @@ -13,3 +13,24 @@ static inline uint8_t byte_sin(uint8_t n) } uint8_t calc_w(uint8_t n); + +static inline uint8_t byte_scale(uint8_t v, uint8_t scale) +{ + uint16_t acc = v; + return (acc * scale) >> 8; +} + +static inline uint8_t clip(int x) +{ + if (x > 240) { + return 240; + } + + if (x < 0) { + return 0; + } + + return (uint8_t)x; +} + +#define AS_BYTE(n) ((n) * 256) -- cgit