Last active
August 29, 2015 14:06
-
-
Save kasperkamperman/a28c2b002df684fffe39 to your computer and use it in GitHub Desktop.
FastLed 2.1 - added saturation to ColorFromPalette (colorutils.cpp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* use this code in Arduino | |
for (int i=0; i <NUM_LEDS; i++) | |
{ leds[i] = ColorFromPalette( currentPalette, map(i, 0, NUM_LEDS, 0, 255), brightness, map(i, 0, NUM_LEDS, 0, 255)); | |
} | |
*/ | |
// blend doesn't seem to be implemented/necessary in CRGBPalette, so I left it out | |
// Probably this can be optimized? See questions in comments. | |
CRGB ColorFromPalette( const CRGBPalette256& pal, uint8_t index, uint8_t brightness, uint8_t saturation) | |
{ | |
const CRGB* entry = &(pal[0]) + index; | |
uint8_t red = entry->red; | |
uint8_t green = entry->green; | |
uint8_t blue = entry->blue; | |
// added manipulation of saturation | |
// variables need to become externally accessible | |
// just for testing | |
uint8_t maxSaturation = 255; | |
uint8_t minSaturation = 0; | |
// scale saturation in the right range. | |
// and inverse the value (255-saturation) | |
saturation = lerp8by8(255 - maxSaturation, 255 - minSaturation, 255 - saturation); | |
// make saturation appear linear | |
// I picked now raw, since we we won't have issues like with dimming brightness: | |
// https://plus.google.com/112889495015752015404/posts/UGXWJtFvz61 | |
saturation = dim8_raw(saturation); | |
// apply saturation | |
// qadd8 works faster? Because we just add saturation | |
red = lerp8by8(red , 255, saturation); | |
green = lerp8by8(green, 255, saturation); | |
blue = lerp8by8(blue , 255, saturation); | |
if( brightness != 255) { | |
nscale8x3_video( red, green, blue, brightness); | |
} | |
return CRGB( red, green, blue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment