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

◆ ColorFromPalette() [4/8]

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

Definition at line 300 of file colorutils.cpp.

301 {
302 if (blendType == LINEARBLEND_NOWRAP) {
303 index = map8(index, 0, 239); // Blend range is affected by lo4 blend of
304 // values, remap to avoid wrapping
305 }
306
307 // hi4 = index >> 4;
308 fl::u8 hi4 = lsrX4(index);
309 fl::u8 lo4 = index & 0x0F;
310
311 // const CRGB* entry = &(pal[0]) + hi4;
312 // since hi4 is always 0..15, hi4 * sizeof(CRGB) can be a single-byte value,
313 // instead of the two byte 'int' that avr-gcc defaults to.
314 // So, we multiply hi4 X sizeof(CRGB), giving hi4XsizeofCRGB;
315 fl::u8 hi4XsizeofCRGB = hi4 * sizeof(CRGB);
316 // We then add that to a base array pointer.
317 const CRGB *entry = (CRGB *)((fl::u8 *)(&(pal[0])) + hi4XsizeofCRGB);
318
319 fl::u8 blend = lo4 && (blendType != NOBLEND);
320
321 fl::u8 red1 = entry->red;
322 fl::u8 green1 = entry->green;
323 fl::u8 blue1 = entry->blue;
324
325 if (blend) {
326
327 if (hi4 == 15) {
328 entry = &(pal[0]);
329 } else {
330 ++entry;
331 }
332
333 fl::u8 f2 = lo4 << 4;
334 fl::u8 f1 = 255 - f2;
335
336 // rgb1.nscale8(f1);
337 fl::u8 red2 = entry->red;
338 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
339 red2 = scale8_LEAVING_R1_DIRTY(red2, f2);
340 red1 += red2;
341
342 fl::u8 green2 = entry->green;
343 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
344 green2 = scale8_LEAVING_R1_DIRTY(green2, f2);
345 green1 += green2;
346
347 fl::u8 blue2 = entry->blue;
348 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
349 blue2 = scale8_LEAVING_R1_DIRTY(blue2, f2);
350 blue1 += blue2;
351
352 cleanup_R1();
353 }
354
355 if (brightness != 255) {
356 if (brightness) {
357 ++brightness; // adjust for rounding
358 // Now, since brightness is nonzero, we don't need the full
359 // scale8_video logic; we can just to scale8 and then add one
360 // (unless scale8 fixed) to all nonzero inputs.
361 if (red1) {
363#if !(FASTLED_SCALE8_FIXED == 1)
364 ++red1;
365#endif
366 }
367 if (green1) {
368 green1 = scale8_LEAVING_R1_DIRTY(green1, brightness);
369#if !(FASTLED_SCALE8_FIXED == 1)
370 ++green1;
371#endif
372 }
373 if (blue1) {
374 blue1 = scale8_LEAVING_R1_DIRTY(blue1, brightness);
375#if !(FASTLED_SCALE8_FIXED == 1)
376 ++blue1;
377#endif
378 }
379 cleanup_R1();
380 } else {
381 red1 = 0;
382 green1 = 0;
383 blue1 = 0;
384 }
385 }
386
387 return CRGB(red1, green1, blue1);
388}
UISlider brightness("Brightness", 128, 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:397
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:343
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:180
unsigned char u8
Definition int.h:17
fl::u8 lsrX4(fl::u8 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:86

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

Referenced by fl::DemoReel100::bpm(), computeOneTwinkle(), fl::TwinkleFox::computeOneTwinkle(), fl::Fire2012::draw(), fillFrameBufferFire(), fillFrameBufferNoise(), 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: