FastLED 3.9.15
Loading...
Searching...
No Matches

◆ ColorFromPalette() [4/8]

CRGB fl::ColorFromPalette ( const CRGBPalette16 & pal,
uint8_t index,
uint8_t brightness,
TBlendType blendType )

Definition at line 299 of file colorutils.cpp.

300 {
301 if (blendType == LINEARBLEND_NOWRAP) {
302 index = map8(index, 0, 239); // Blend range is affected by lo4 blend of
303 // values, remap to avoid wrapping
304 }
305
306 // hi4 = index >> 4;
307 uint8_t hi4 = lsrX4(index);
308 uint8_t lo4 = index & 0x0F;
309
310 // const CRGB* entry = &(pal[0]) + hi4;
311 // since hi4 is always 0..15, hi4 * sizeof(CRGB) can be a single-byte value,
312 // instead of the two byte 'int' that avr-gcc defaults to.
313 // So, we multiply hi4 X sizeof(CRGB), giving hi4XsizeofCRGB;
314 uint8_t hi4XsizeofCRGB = hi4 * sizeof(CRGB);
315 // We then add that to a base array pointer.
316 const CRGB *entry = (CRGB *)((uint8_t *)(&(pal[0])) + hi4XsizeofCRGB);
317
318 uint8_t blend = lo4 && (blendType != NOBLEND);
319
320 uint8_t red1 = entry->red;
321 uint8_t green1 = entry->green;
322 uint8_t blue1 = entry->blue;
323
324 if (blend) {
325
326 if (hi4 == 15) {
327 entry = &(pal[0]);
328 } else {
329 ++entry;
330 }
331
332 uint8_t f2 = lo4 << 4;
333 uint8_t f1 = 255 - f2;
334
335 // rgb1.nscale8(f1);
336 uint8_t red2 = entry->red;
337 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
338 red2 = scale8_LEAVING_R1_DIRTY(red2, f2);
339 red1 += red2;
340
341 uint8_t green2 = entry->green;
342 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
343 green2 = scale8_LEAVING_R1_DIRTY(green2, f2);
344 green1 += green2;
345
346 uint8_t blue2 = entry->blue;
347 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
348 blue2 = scale8_LEAVING_R1_DIRTY(blue2, f2);
349 blue1 += blue2;
350
351 cleanup_R1();
352 }
353
354 if (brightness != 255) {
355 if (brightness) {
356 ++brightness; // adjust for rounding
357 // Now, since brightness is nonzero, we don't need the full
358 // scale8_video logic; we can just to scale8 and then add one
359 // (unless scale8 fixed) to all nonzero inputs.
360 if (red1) {
362#if !(FASTLED_SCALE8_FIXED == 1)
363 ++red1;
364#endif
365 }
366 if (green1) {
367 green1 = scale8_LEAVING_R1_DIRTY(green1, brightness);
368#if !(FASTLED_SCALE8_FIXED == 1)
369 ++green1;
370#endif
371 }
372 if (blue1) {
373 blue1 = scale8_LEAVING_R1_DIRTY(blue1, brightness);
374#if !(FASTLED_SCALE8_FIXED == 1)
375 ++blue1;
376#endif
377 }
378 cleanup_R1();
379 } else {
380 red1 = 0;
381 green1 = 0;
382 blue1 = 0;
383 }
384 }
385
386 return CRGB(red1, green1, blue1);
387}
UISlider brightness("Brightness", 255, 0, 255, 1)
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
LIB8STATIC uint8_t map8(uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
Map from one full-range 8-bit value into a narrower range of 8-bit values, possibly a range of hues.
Definition lib8tion.h:541
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:339
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8() does not clean up the R1 register on AVR.
Definition scale8.h:176
uint8_t lsrX4(uint8_t dividend)
Helper function to divide a number by 16, aka four logical shift right (LSR)'s.
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55

References blend(), brightness, cleanup_R1(), lsrX4(), map8(), and scale8_LEAVING_R1_DIRTY().

Referenced by fl::DemoReel100::bpm(), fl::TwinkleFox::computeOneTwinkle(), fl::Fire2012::draw(), Fire2023(), loop(), fl::NoisePalette::mapNoiseToLEDsUsingPalette(), fl::Pacifica::pacifica_one_layer(), UpscalePalette(), UpscalePalette(), UpscalePalette(), and UpscalePalette().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: