FastLED 3.9.3
Loading...
Searching...
No Matches
colorutils.cpp File Reference

Detailed Description

Utility functions for color fill, palettes, blending, and more.

Definition in file colorutils.cpp.

#include <stdint.h>
#include <math.h>
#include "FastLED.h"
#include "xymap.h"

Go to the source code of this file.

Functions

void fill_solid (struct CRGB *targetArray, int numToFill, const struct CRGB &color)
 Fill a range of LEDs with a solid color.
 
void fill_solid (struct CHSV *targetArray, int numToFill, const struct CHSV &color)
 Fill a range of LEDs with a solid color.
 
void fill_rainbow (struct CRGB *targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue)
 Fill a range of LEDs with a rainbow of colors.
 
void fill_rainbow (struct CHSV *targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue)
 Fill a range of LEDs with a rainbow of colors.
 
void fill_rainbow_circular (struct CRGB *targetArray, int numToFill, uint8_t initialhue, bool reversed)
 Fill a range of LEDs with a rainbow of colors, so that the hues are continuous between the end of the strip and the beginning.
 
void fill_rainbow_circular (struct CHSV *targetArray, int numToFill, uint8_t initialhue, bool reversed)
 Fill a range of LEDs with a rainbow of colors, so that the hues are continuous between the end of the strip and the beginning.
 
void fill_gradient_RGB (CRGB *leds, uint16_t startpos, CRGB startcolor, uint16_t endpos, CRGB endcolor)
 Fill a range of LEDs with a smooth RGB gradient between two RGB colors.
 
void fill_gradient_RGB (CRGB *leds, uint16_t numLeds, const CRGB &c1, const CRGB &c2)
 Fill a range of LEDs with a smooth RGB gradient between two RGB colors.
 
void fill_gradient_RGB (CRGB *leds, uint16_t numLeds, const CRGB &c1, const CRGB &c2, const CRGB &c3)
 Fill a range of LEDs with a smooth RGB gradient between three RGB colors.
 
void fill_gradient_RGB (CRGB *leds, uint16_t numLeds, const CRGB &c1, const CRGB &c2, const CRGB &c3, const CRGB &c4)
 Fill a range of LEDs with a smooth RGB gradient between four RGB colors.
 
void nscale8_video (CRGB *leds, uint16_t num_leds, uint8_t scale)
 Scale the brightness of an array of pixels all at once.
 
void fade_video (CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
 Reduce the brightness of an array of pixels all at once.
 
void fadeLightBy (CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
 Reduce the brightness of an array of pixels all at once.
 
void fadeToBlackBy (CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
 Reduce the brightness of an array of pixels all at once.
 
void fade_raw (CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
 Reduce the brightness of an array of pixels all at once.
 
void nscale8_raw (CRGB *leds, uint16_t num_leds, uint8_t scale)
 Unused alias of nscale8(CRGB*, uint16_t, uint8_t)
 
void nscale8 (CRGB *leds, uint16_t num_leds, uint8_t scale)
 Scale the brightness of an array of pixels all at once.
 
void fadeUsingColor (CRGB *leds, uint16_t numLeds, const CRGB &colormask)
 Reduce the brightness of an array of pixels as thought it were seen through a transparent filter with the specified color.
 
CRGBnblend (CRGB &existing, const CRGB &overlay, fract8 amountOfOverlay)
 Destructively modifies one color, blending in a given fraction of an overlay color.
 
void nblend (CRGB *existing, CRGB *overlay, uint16_t count, fract8 amountOfOverlay)
 Destructively blends a given fraction of a color array into an existing color array.
 
CRGB blend (const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
 Computes a new color blended some fraction of the way between two other colors.
 
CRGBblend (const CRGB *src1, const CRGB *src2, CRGB *dest, uint16_t count, fract8 amountOfsrc2)
 Computes a new blended array of colors, each some fraction of the way between corresponding elements of two source arrays of colors.
 
CHSVnblend (CHSV &existing, const CHSV &overlay, fract8 amountOfOverlay, TGradientDirectionCode directionCode)
 Destructively modifies one color, blending in a given fraction of an overlay color.
 
void nblend (CHSV *existing, CHSV *overlay, uint16_t count, fract8 amountOfOverlay, TGradientDirectionCode directionCode)
 Destructively blends a given fraction of a color array into an existing color array.
 
CHSV blend (const CHSV &p1, const CHSV &p2, fract8 amountOfP2, TGradientDirectionCode directionCode)
 Computes a new color blended some fraction of the way between two other colors.
 
CHSVblend (const CHSV *src1, const CHSV *src2, CHSV *dest, uint16_t count, fract8 amountOfsrc2, TGradientDirectionCode directionCode)
 Computes a new blended array of colors, each some fraction of the way between corresponding elements of two source arrays of colors.
 
void blur1d (CRGB *leds, uint16_t numLeds, fract8 blur_amount)
 One-dimensional blur filter.
 
void blur2d (CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount, const XYMap &xymap)
 Two-dimensional blur filter.
 
void blurRows (CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount, const XYMap &xyMap)
 Perform a blur1d() on every row of a rectangular matrix.
 
void blurColumns (CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount, const XYMap &xyMap)
 Perform a blur1d() on every column of a rectangular matrix.
 
CRGB HeatColor (uint8_t temperature)
 Approximates a "black body radiation" spectrum for a given "heat" level.
 
uint8_t lsrX4 (uint8_t dividend)
 Helper function to divide a number by 16, aka four logical shift right (LSR)'s.
 
CRGB ColorFromPaletteExtended (const CRGBPalette32 &pal, uint16_t index, uint8_t brightness, TBlendType blendType)
 
CRGB ColorFromPalette (const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
 Get a color from a palette.
 
CRGB ColorFromPaletteExtended (const CRGBPalette16 &pal, uint16_t index, uint8_t brightness, TBlendType blendType)
 
CRGB ColorFromPalette (const TProgmemRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
 Get a color from a palette.
 
CRGB ColorFromPalette (const CRGBPalette32 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
 Get a color from a palette.
 
CRGB ColorFromPalette (const TProgmemRGBPalette32 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
 Get a color from a palette.
 
CRGB ColorFromPalette (const CRGBPalette256 &pal, uint8_t index, uint8_t brightness, TBlendType)
 Get a color from a palette.
 
CRGB ColorFromPaletteExtended (const CRGBPalette256 &pal, uint16_t index, uint8_t brightness, TBlendType blendType)
 
CHSV ColorFromPalette (const CHSVPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
 Get a color from a palette.
 
CHSV ColorFromPalette (const CHSVPalette32 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
 Get a color from a palette.
 
CHSV ColorFromPalette (const CHSVPalette256 &pal, uint8_t index, uint8_t brightness, TBlendType)
 Get a color from a palette.
 
void UpscalePalette (const class CRGBPalette16 &srcpal16, class CRGBPalette256 &destpal256)
 Convert a 16-entry palette to a 256-entry palette.
 
void UpscalePalette (const class CHSVPalette16 &srcpal16, class CHSVPalette256 &destpal256)
 
void UpscalePalette (const class CRGBPalette16 &srcpal16, class CRGBPalette32 &destpal32)
 Convert a 16-entry palette to a 32-entry palette.
 
void UpscalePalette (const class CHSVPalette16 &srcpal16, class CHSVPalette32 &destpal32)
 
void UpscalePalette (const class CRGBPalette32 &srcpal32, class CRGBPalette256 &destpal256)
 Convert a 32-entry palette to a 256-entry palette.
 
void UpscalePalette (const class CHSVPalette32 &srcpal32, class CHSVPalette256 &destpal256)
 
void nblendPaletteTowardPalette (CRGBPalette16 &current, CRGBPalette16 &target, uint8_t maxChanges)
 Alter one palette by making it slightly more like a "target palette".
 
uint8_t applyGamma_video (uint8_t brightness, float gamma)
 Applies a gamma adjustment to a color channel.
 
CRGB applyGamma_video (const CRGB &orig, float gamma)
 Applies a gamma adjustment to a color.
 
CRGB applyGamma_video (const CRGB &orig, float gammaR, float gammaG, float gammaB)
 Applies a gamma adjustment to a color.
 
CRGBnapplyGamma_video (CRGB &rgb, float gamma)
 Destructively applies a gamma adjustment to a color.
 
CRGBnapplyGamma_video (CRGB &rgb, float gammaR, float gammaG, float gammaB)
 Destructively applies a gamma adjustment to a color.
 
void napplyGamma_video (CRGB *rgbarray, uint16_t count, float gamma)
 Destructively applies a gamma adjustment to a color array.
 
void napplyGamma_video (CRGB *rgbarray, uint16_t count, float gammaR, float gammaG, float gammaB)
 Destructively applies a gamma adjustment to a color array.
 

Macro Definition Documentation

◆ __PROG_TYPES_COMPAT__

#define __PROG_TYPES_COMPAT__

Definition at line 2 of file colorutils.cpp.

◆ FASTLED_INTERNAL

#define FASTLED_INTERNAL

Definition at line 1 of file colorutils.cpp.

Function Documentation

◆ lsrX4()

uint8_t lsrX4 ( uint8_t dividend)
inline

Helper function to divide a number by 16, aka four logical shift right (LSR)'s.

On avr-gcc, "u8 >> 4" generates a loop, which is big, and slow. merely forcing it to be four /=2's causes avr-gcc to emit a SWAP instruction followed by an AND 0x0F, which is faster, and smaller.

Definition at line 552 of file colorutils.cpp.

◆ nscale8_raw()

void nscale8_raw ( CRGB * leds,
uint16_t num_leds,
uint8_t scale )

Unused alias of nscale8(CRGB*, uint16_t, uint8_t)

Todo
Remove this or add a declaration? This is not listed in the colorutils.h header.

Definition at line 248 of file colorutils.cpp.