|
11 | 11 | */ |
12 | 12 | #include "wled.h" |
13 | 13 | #include "FXparticleSystem.h" // TODO: better define the required function (mem service) in FX.h? |
14 | | -#include "palettes.h" |
15 | 14 |
|
16 | 15 | /* |
17 | 16 | Custom per-LED mapping has moved! |
@@ -226,8 +225,12 @@ void Segment::resetIfRequired() { |
226 | 225 | } |
227 | 226 |
|
228 | 227 | CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) { |
229 | | - if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0; |
230 | | - if (pal > 245 && (customPalettes.size() == 0 || 255U-pal > customPalettes.size()-1)) pal = 0; |
| 228 | + // there is one randomy generated palette (1) followed by 4 palettes created from segment colors (2-5) |
| 229 | + // those are followed by 7 fastled palettes (6-12) and 59 gradient palettes (13-71) |
| 230 | + // then come the custom palettes (255,254,...) growing downwards from 255 (255 being 1st custom palette) |
| 231 | + // palette 0 is a varying palette depending on effect and may be replaced by segment's color if so |
| 232 | + // instructed in color_from_palette() |
| 233 | + if (pal > FIXED_PALETTE_COUNT && pal <= 255-customPalettes.size()) pal = 0; // out of bounds palette |
231 | 234 | //default palette. Differs depending on effect |
232 | 235 | if (pal == 0) pal = _default_palette; // _default_palette is set in setMode() |
233 | 236 | switch (pal) { |
@@ -263,13 +266,13 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) { |
263 | 266 | } |
264 | 267 | break;} |
265 | 268 | default: //progmem palettes |
266 | | - if (pal>245) { |
| 269 | + if (pal > 255 - customPalettes.size()) { |
267 | 270 | targetPalette = customPalettes[255-pal]; // we checked bounds above |
268 | | - } else if (pal < 13) { // palette 6 - 12, fastled palettes |
269 | | - targetPalette = *fastledPalettes[pal-6]; |
| 271 | + } else if (pal < DYNAMIC_PALETTE_COUNT+FASTLED_PALETTE_COUNT+1) { // palette 6 - 12, fastled palettes |
| 272 | + targetPalette = *fastledPalettes[pal-DYNAMIC_PALETTE_COUNT-1]; |
270 | 273 | } else { |
271 | 274 | byte tcp[72]; |
272 | | - memcpy_P(tcp, (byte*)pgm_read_dword(&(gGradientPalettes[pal-13])), 72); |
| 275 | + memcpy_P(tcp, (byte*)pgm_read_dword(&(gGradientPalettes[pal-(DYNAMIC_PALETTE_COUNT+FASTLED_PALETTE_COUNT)-1])), 72); |
273 | 276 | targetPalette.loadDynamicGradientPalette(tcp); |
274 | 277 | } |
275 | 278 | break; |
@@ -573,8 +576,7 @@ Segment &Segment::setMode(uint8_t fx, bool loadDefaults) { |
573 | 576 | } |
574 | 577 |
|
575 | 578 | Segment &Segment::setPalette(uint8_t pal) { |
576 | | - if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0; // built in palettes |
577 | | - if (pal > 245 && (customPalettes.size() == 0 || 255U-pal > customPalettes.size()-1)) pal = 0; // custom palettes |
| 579 | + if (pal <= 255-customPalettes.size() && pal > FIXED_PALETTE_COUNT) pal = 0; // not built in palette or custom palette |
578 | 580 | if (pal != palette) { |
579 | 581 | //DEBUG_PRINTF_P(PSTR("- Starting palette transition: %d\n"), pal); |
580 | 582 | startTransition(strip.getTransition(), blendingStyle != BLEND_STYLE_FADE); // start transition prior to change (no need to copy segment) |
|
0 commit comments