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

◆ ColorFromPaletteExtended()

CRGB fl::ColorFromPaletteExtended ( const CRGBPalette32 & pal,
uint16_t index,
uint8_t brightness,
TBlendType blendType )

Definition at line 252 of file colorutils.cpp.

253 {
254 // Extract the five most significant bits of the index as a palette index.
255 uint8_t index_5bit = (index >> 11);
256 // Calculate the 8-bit offset from the palette index.
257 uint8_t offset = (uint8_t)(index >> 3);
258 // Get the palette entry from the 5-bit index
259 const CRGB *entry = &(pal[0]) + index_5bit;
260 uint8_t red1 = entry->red;
261 uint8_t green1 = entry->green;
262 uint8_t blue1 = entry->blue;
263
264 uint8_t blend = offset && (blendType != NOBLEND);
265 if (blend) {
266 if (index_5bit == 31) {
267 entry = &(pal[0]);
268 } else {
269 entry++;
270 }
271
272 // Calculate the scaling factor and scaled values for the lower palette
273 // value.
274 uint8_t f1 = 255 - offset;
275 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
276 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
277 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
278
279 // Calculate the scaled values for the neighbouring palette value.
280 uint8_t red2 = entry->red;
281 uint8_t green2 = entry->green;
282 uint8_t blue2 = entry->blue;
283 red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
284 green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
285 blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
286 cleanup_R1();
287
288 // These sums can't overflow, so no qadd8 needed.
289 red1 += red2;
290 green1 += green2;
291 blue1 += blue2;
292 }
293 if (brightness != 255) {
294 nscale8x3_video(red1, green1, blue1, brightness);
295 }
296 return CRGB(red1, green1, blue1);
297}
UISlider brightness("Brightness", 255, 0, 255, 1)
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
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
LIB8STATIC void nscale8x3_video(uint8_t &r, uint8_t &g, uint8_t &b, fract8 scale)
Scale three one-byte values by a fourth one, which is treated as the numerator of a fraction whose de...
Definition scale8.h:397
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55

Referenced by fl::anonymous_namespace{gradient.cpp}::Visitor::accept(), and fl::anonymous_namespace{gradient.cpp}::VisitorFill::accept().

+ Here is the caller graph for this function: