Source:
Palette.h
palette¶
Sixteen evenly-spaced entries a wheel index reads by interpolating between the two that bracket it.
Classes¶
| Name | Description |
|---|---|
Palettes |
The global active palette effects read: the [AudioService::latestFrame()] static-seam pattern. |
Palette |
|
LivePalettes |
How many SCRIPTED palettes the picker offers, and their names. |
Functions¶
| Return | Name | Description |
|---|---|---|
RGB |
colorFromPalette inline |
The per-light lookup: index is a 0..255 wheel position (wraps), mapped across the 16 entries;. |
RGB |
blend inline |
Cross-fade two colors: amt/255 of the way from a to b (amt 0 = a, 255 = b). |
void |
fadeToBlackBy inline |
Dim a color toward black by amt/255: the per-frame fade that gives effects a decaying trail. |
void |
paletteOptions inline |
|
void |
paletteNames inline |
Emit the built-in palette names as a bare JSON string array, the element list WLED's /json. |
uint8_t |
paletteCount inline |
How many entries paletteNames() writes. |
colorFromPalette¶
inline
The per-light lookup: index is a 0..255 wheel position (wraps), mapped across the 16 entries;.
blend¶
inline
Cross-fade two colors: amt/255 of the way from a to b (amt 0 = a, 255 = b).
fadeToBlackBy¶
inline
Dim a color toward black by amt/255: the per-frame fade that gives effects a decaying trail.
paletteOptions¶
inline
paletteNames¶
inline
Emit the built-in palette names as a bare JSON string array, the element list WLED's /json.
paletteCount¶
inline
How many entries paletteNames() writes.
Palettes¶
src/light/util/Palette.h:214The global active palette effects read: the [AudioService::latestFrame()] static-seam pattern.
Public Static Methods¶
static inline const Palette * active()
: The palette effects read, which the drivers module sets.
static inline void setActiveDirect(const Palette & p)
: Restore a previously captured palette verbatim. For tests that must hand back the global they disturbed.
static inline void setActive(uint8_t index)
: Expand built-in index into the active palette, off the hot path, on selection.
static inline Palette fromBuiltin(uint8_t index)
: Build the 16-entry palette for built-in index (rainbow generated via hsvToRgb, the rest expanded from their gradient stops).
static inline uint16_t representativeHue(uint8_t index)
: Representative hue (0..359) of built-in index.
static inline RGB representativeRgb(uint8_t index)
: Representative [RGB] color of built-in index: the palette's identity color, for any external.
static inline uint8_t nearestForRgb(uint8_t r, uint8_t g, uint8_t b)
: [RGB] to the nearest palette: the one call every RGB-input consumer should reach for rather.
static inline uint8_t nearestForHue(uint16_t hue, uint8_t sat)
: The palette whose representative (hue, sat) is closest to the target, by 2D distance in (circular-hue, saturation) space.
static inline void representativeHueSat(uint8_t index, uint16_t & hueOut, uint16_t & satOut)
: Compute a palette's representative hue (0..359) + saturation (0..255) from the average of its expanded [RGB] entries.
Palette¶
src/light/util/Palette.h:27Public Attributes¶
RGB entry = {}
Public Methods¶
inline void fromGradient(const uint8_t * stops, size_t count)
: Build the 16 entries from a gradient-stop list.
Public Static Attributes¶
constexpr uint8_t kEntries = 16
: Entries a palette holds, evenly spaced across the wheel.
Public Static Methods¶
static inline RGB lerpRGB(const RGB & a, const RGB & b, uint8_t frac)
: Linear blend a→b by frac (0 = a, 255 = b).
LivePalettes¶
src/light/util/Palette.h:325How many SCRIPTED palettes the picker offers, and their names.
Set by [Drivers] from the catalog plus whatever .mlp files the device carries, because [Palette.h] knows nothing about the filesystem and must not learn. This is the same one-pointer seam Palettes::active() is.
They sort FIRST in the picker, ahead of the sixty built-ins. A scripted palette is one the user wrote or downloaded, so it is what they are looking for. A built-in is always there.
Public Static Attributes¶
constexpr uint8_t kMax = 16
: The most scripted palettes a device carries, which keeps the picker readable.
Public Static Methods¶
static inline uint8_t count()
: How many scripted palettes the picker offers.
static inline const char * nameAt(uint8_t i)
: One scripted palette's name, or empty when the index names none.
static inline const char * tagsAt(uint8_t i)
: What the script declared about itself, for the picker's emoji filter. Empty when the device carries a .mlp the catalog does not know, which is a script the user wrote.
static inline void set(const char const * names, const char const * tags, uint8_t n)
: REFERENCES the caller's arrays; it does not copy them.
static inline void clear(const char *const * names = nullptr)
: Detach, for a publisher whose storage is about to go away.
static inline bool isLive(uint8_t pickerIndex)
: Scripted palettes sort LAST, after the built-ins, and the position is the whole point.
static inline uint8_t sourceIndex(uint8_t pickerIndex)
: The index into the underlying array (scripted or built-in) behind a picker index.
static inline int cmpName(const char * a, const char * b)
: Case-insensitive name order, for sorting the scripted names among themselves.
Builtin¶
src/light/util/Palette.h:169A built-in palette: its name, its gradient, and the tags the picker filters on.
tags describes what the palette LOOKS LIKE, which is the question someone scrolling sixty entries is asking. Warm or cold, one hue or many, calm or loud. It is not a category system to be completed, and an untagged palette stays findable by name and swatch.
Public Attributes¶
const char * name
const uint8_t * stops
size_t len
bool rainbow
const char * tags = ""
More info¶
Gradients expand once¶
A gradient is a stop list in flash that expands into the sixteen entries on selection, off the hot path. The per-light lookup is then a single blend.
Prior art¶
FastLED's gradient palettes, the convention WLED and MoonLight share, so the recognizable names and model are carried. The implementation is our own; the gradient data is a public palette set, reformatted.