Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kriegsman <kriegsman@tr.org>2014-12-11 03:16:06 +0300
committerMark Kriegsman <kriegsman@tr.org>2014-12-11 03:16:06 +0300
commit061d4373c484b3f462a6cadd2c0f87f3b222e557 (patch)
tree1da5e5f4c05cfc7ab7bf7b62056323363cbe1bb6
parentdf69cb80b375b5bd4fef510b4da575b280ff0d04 (diff)
Added support for ColorFromPalette directly from a progmem RGB palette16
-rw-r--r--colorutils.cpp58
-rw-r--r--colorutils.h5
2 files changed, 63 insertions, 0 deletions
diff --git a/colorutils.cpp b/colorutils.cpp
index 16433f45..3667855f 100644
--- a/colorutils.cpp
+++ b/colorutils.cpp
@@ -530,6 +530,64 @@ CRGB ColorFromPalette( const CRGBPalette16& pal, uint8_t index, uint8_t brightne
return CRGB( red1, green1, blue1);
}
+CRGB ColorFromPalette( const TProgmemRGBPalette16& pal, uint8_t index, uint8_t brightness, TBlendType blendType)
+{
+ uint8_t hi4 = index >> 4;
+ uint8_t lo4 = index & 0x0F;
+
+ // CRGB rgb1 = pal[ hi4];
+ CRGB entry = pgm_read_dword_near( &(pal[0]) + hi4 );
+
+ uint8_t red1 = entry.red;
+ uint8_t green1 = entry.green;
+ uint8_t blue1 = entry.blue;
+
+ uint8_t blend = lo4 && (blendType != NOBLEND);
+
+ if( blend ) {
+
+ if( hi4 == 15 ) {
+ entry = pgm_read_dword_near( &(pal[0]) );
+ } else {
+ entry = pgm_read_dword_near( &(pal[1]) + hi4 );
+ }
+
+ uint8_t f2 = lo4 << 4;
+ uint8_t f1 = 256 - f2;
+
+ // rgb1.nscale8(f1);
+ red1 = scale8_LEAVING_R1_DIRTY( red1, f1);
+ green1 = scale8_LEAVING_R1_DIRTY( green1, f1);
+ blue1 = scale8_LEAVING_R1_DIRTY( blue1, f1);
+
+ // cleanup_R1();
+
+ // CRGB rgb2 = pal[ hi4];
+ // rgb2.nscale8(f2);
+ uint8_t red2 = entry.red;
+ uint8_t green2 = entry.green;
+ uint8_t blue2 = entry.blue;
+ red2 = scale8_LEAVING_R1_DIRTY( red2, f2);
+ green2 = scale8_LEAVING_R1_DIRTY( green2, f2);
+ blue2 = scale8_LEAVING_R1_DIRTY( blue2, f2);
+
+ cleanup_R1();
+
+ // These sums can't overflow, so no qadd8 needed.
+ red1 += red2;
+ green1 += green2;
+ blue1 += blue2;
+
+ }
+
+ if( brightness != 255) {
+ nscale8x3_video( red1, green1, blue1, brightness);
+ }
+
+ return CRGB( red1, green1, blue1);
+}
+
+
CRGB ColorFromPalette( const CRGBPalette256& pal, uint8_t index, uint8_t brightness, TBlendType)
{
diff --git a/colorutils.h b/colorutils.h
index 76542acf..120b685f 100644
--- a/colorutils.h
+++ b/colorutils.h
@@ -781,6 +781,11 @@ public:
typedef enum { NOBLEND=0, BLEND=1 } TBlendType;
CRGB ColorFromPalette( const CRGBPalette16& pal,
+ uint8_t index,
+ uint8_t brightness=255,
+ TBlendType blendType=BLEND);
+
+CRGB ColorFromPalette( const TProgmemRGBPalette16& pal,
uint8_t index,
uint8_t brightness=255,
TBlendType blendType=BLEND);