From 061d4373c484b3f462a6cadd2c0f87f3b222e557 Mon Sep 17 00:00:00 2001 From: Mark Kriegsman Date: Wed, 10 Dec 2014 19:16:06 -0500 Subject: Added support for ColorFromPalette directly from a progmem RGB palette16 --- colorutils.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ colorutils.h | 5 +++++ 2 files changed, 63 insertions(+) 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); -- cgit v1.2.3