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
| 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 |
| 11 | static 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 | |
| 19 | static HSV16 RGBtoHSV16(const CRGB &rgb) { |
| 20 | // Work with 8-bit values directly |