MCPcopy Create free account
hub / github.com/FastLED/FastLED / scale8_to_16_accurate

Function scale8_to_16_accurate

src/fl/gfx/hsv16.cpp.hpp:11–17  ·  view source on GitHub ↗

Improved 8-bit to 16-bit scaling using the same technique as map8_to_16 but with proper rounding for the 0-255 to 0-65535 conversion

Source from the content-addressed store, hash-verified

9// Improved 8-bit to 16-bit scaling using the same technique as map8_to_16
10// but with proper rounding for the 0-255 to 0-65535 conversion
11static inline u16 scale8_to_16_accurate(u8 x) {
12 if (x == 0) return 0;
13 if (x == 255) return 65535;
14 // Use 32-bit arithmetic with rounding: (x * 65535 + 127) / 255
15 // This is equivalent to: (x * 65535 + 255/2) / 255
16 return (u16)(((u32)x * 65535 + 127) / 255);
17}
18
19static HSV16 RGBtoHSV16(const CRGB &rgb) {
20 // Work with 8-bit values directly

Callers 1

RGBtoHSV16Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected