FastLED 3.9.15
Loading...
Searching...
No Matches
pixel.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/int.h"
4namespace fl {
5
6// Color formats for decoded output
7enum class PixelFormat {
8 RGB565, // 16-bit RGB: RRRRR GGGGGG BBBBB
9 RGB888, // 24-bit RGB: RRRRRRRR GGGGGGGG BBBBBBBB
10 RGBA8888, // 32-bit RGBA: RRRRRRRR GGGGGGGG BBBBBBBB AAAAAAAA
11 YUV420 // YUV 4:2:0 format (mainly for internal use)
12};
13
14// Calculate bytes per pixel for given format
16 switch (format) {
17 case PixelFormat::RGB565: return 2;
18 case PixelFormat::RGB888: return 3;
19 case PixelFormat::RGBA8888: return 4;
20 case PixelFormat::YUV420: return 1; // Simplified for luminance component
21 default: return 3;
22 }
23}
24
25// Convert RGB565 to RGB888 with proper scaling to full 8-bit range using lookup tables
26void rgb565ToRgb888(fl::u16 rgb565, fl::u8& r, fl::u8& g, fl::u8& b);
27
28// Convert RGB888 to RGB565
29inline fl::u16 rgb888ToRgb565(fl::u8 r, fl::u8 g, fl::u8 b) {
30 return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
31}
32
33} // namespace fl
unsigned char u8
Definition s16x16x4.h:132
unsigned char u8
Definition stdint.h:131
fl::u16 rgb888ToRgb565(fl::u8 r, fl::u8 g, fl::u8 b)
Definition pixel.h:29
void rgb565ToRgb888(fl::u16 rgb565, fl::u8 &r, fl::u8 &g, fl::u8 &b)
Definition pixel.cpp.hpp:23
fl::u8 getBytesPerPixel(PixelFormat format)
Definition pixel.h:15
fl::string format(const char *fmt)
Format with no arguments.
Definition format.h:439
PixelFormat
Definition pixel.h:7
Base definition for an LED controller.
Definition crgb.hpp:179