FastLED 3.9.3
Loading...
Searching...
No Matches
intmap.h
1
2#pragma once
3
4#include "namespace.h"
5#include "lib8static.h"
6#include <stdint.h>
7
8FASTLED_NAMESPACE_BEGIN
9
10LIB8STATIC_ALWAYS_INLINE uint16_t map8_to_16(uint8_t x) {
11 return uint16_t(x) * 0x101;
12}
13
14// map16_to_8: map 16-bit values to 8-bit values
15// This function maps 16-bit values to 8-bit values.
16LIB8STATIC_ALWAYS_INLINE uint8_t map16_to_8(uint16_t x) {
17 // Tested to be nearly identical to double precision floating point
18 // doing this operation.
19 if (x == 0) {
20 return 0;
21 }
22 if (x >= 0xff00) {
23 return 0xff;
24 }
25 return uint8_t((x + 128) >> 8);
26}
27
28LIB8STATIC_ALWAYS_INLINE uint32_t map8_to_32(uint8_t x) {
29 return uint32_t(x) * 0x1010101;
30}
31
32FASTLED_NAMESPACE_END