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-09-24 05:43:03 +0400
committerMark Kriegsman <kriegsman@tr.org>2014-09-24 05:43:03 +0400
commit3103724f81abeb3d1f000960ad642e2d859b9b25 (patch)
tree10de16eb6fc286ad2a27cceeafe289c712d47341
parentd975f96a875650a3b7850a0bcf3a51ef336af48c (diff)
Added HSV blend functions
-rw-r--r--colorutils.cpp75
-rw-r--r--colorutils.h25
2 files changed, 94 insertions, 6 deletions
diff --git a/colorutils.cpp b/colorutils.cpp
index ccaa646f..0f8d3832 100644
--- a/colorutils.cpp
+++ b/colorutils.cpp
@@ -319,6 +319,81 @@ CRGB* blend( const CRGB* src1, const CRGB* src2, CRGB* dest, uint16_t count, fra
+CHSV& nblend( CHSV& existing, const CHSV& overlay, fract8 amountOfOverlay, TGradientDirectionCode directionCode)
+{
+ if( amountOfOverlay == 0) {
+ return existing;
+ }
+
+ if( amountOfOverlay == 255) {
+ existing = overlay;
+ return existing;
+ }
+
+ fract8 amountOfKeep = 256 - amountOfOverlay;
+
+ uint8_t huedelta8 = overlay.hue - existing.hue;
+
+ if( directionCode == SHORTEST_HUES ) {
+ directionCode = FORWARD_HUES;
+ if( huedelta8 > 127) {
+ directionCode = BACKWARD_HUES;
+ }
+ }
+
+ if( directionCode == LONGEST_HUES ) {
+ directionCode = FORWARD_HUES;
+ if( huedelta8 < 128) {
+ directionCode = BACKWARD_HUES;
+ }
+ }
+
+ if( directionCode == FORWARD_HUES) {
+ existing.hue = existing.hue + scale8( huedelta8, amountOfOverlay);
+ }
+ else /* directionCode == BACKWARD_HUES */
+ {
+ huedelta8 = -huedelta8;
+ existing.hue = existing.hue - scale8( huedelta8, amountOfOverlay);
+ }
+
+ existing.sat = scale8_LEAVING_R1_DIRTY( existing.sat, amountOfKeep)
+ + scale8_LEAVING_R1_DIRTY( overlay.sat, amountOfOverlay);
+ existing.val = scale8_LEAVING_R1_DIRTY( existing.val, amountOfKeep)
+ + scale8_LEAVING_R1_DIRTY( overlay.val, amountOfOverlay);
+
+ cleanup_R1();
+
+ return existing;
+}
+
+
+
+void nblend( CHSV* existing, CHSV* overlay, uint16_t count, fract8 amountOfOverlay, TGradientDirectionCode directionCode )
+{
+ for( uint16_t i = count; i; i--) {
+ nblend( *existing, *overlay, amountOfOverlay, directionCode);
+ existing++;
+ overlay++;
+ }
+}
+
+CHSV blend( const CHSV& p1, const CHSV& p2, fract8 amountOfP2, TGradientDirectionCode directionCode )
+{
+ CHSV nu(p1);
+ nblend( nu, p2, amountOfP2, directionCode);
+ return nu;
+}
+
+CHSV* blend( const CHSV* src1, const CHSV* src2, CHSV* dest, uint16_t count, fract8 amountOfsrc2, TGradientDirectionCode directionCode )
+{
+ for( uint16_t i = count; i; i--) {
+ dest[i] = blend(src1[i], src2[i], amountOfsrc2, directionCode);
+ }
+ return dest;
+}
+
+
// CRGB HeatColor( uint8_t temperature)
//
diff --git a/colorutils.h b/colorutils.h
index c986838b..181970e7 100644
--- a/colorutils.h
+++ b/colorutils.h
@@ -96,25 +96,38 @@ void nscale8( CRGB* leds, uint16_t num_leds, uint8_t scale);
// Pixel blending
//
-// blend - computes an RGB-blended some fraction of the way
-// between two other RGB colors.
+// blend - computes a new color blended some fraction of the way
+// between two other colors.
CRGB blend( const CRGB& p1, const CRGB& p2, fract8 amountOfP2 );
-// blend - computes an RGB-blended array of colors, each
+CHSV blend( const CHSV& p1, const CHSV& p2, fract8 amountOfP2,
+ TGradientDirectionCode directionCode = SHORTEST_HUES );
+
+// blend - computes a new color blended array of colors, each
// a given fraction of the way between corresponding
// elements of two source arrays of colors.
// Useful for blending palettes.
CRGB* blend( const CRGB* src1, const CRGB* src2, CRGB* dest,
uint16_t count, fract8 amountOfsrc2 );
-// nblend - destructively modifies one RGB color, blending
-// in a given fraction of an overlay RGB color
+CHSV* blend( const CHSV* src1, const CHSV* src2, CHSV* dest,
+ uint16_t count, fract8 amountOfsrc2,
+ TGradientDirectionCode directionCode = SHORTEST_HUES );
+
+// nblend - destructively modifies one color, blending
+// in a given fraction of an overlay color
CRGB& nblend( CRGB& existing, const CRGB& overlay, fract8 amountOfOverlay );
+CHSV& nblend( CHSV& existing, const CHSV& overlay, fract8 amountOfOverlay,
+ TGradientDirectionCode directionCode = SHORTEST_HUES );
+
// nblend - destructively blends a given fraction of
-// a new RGB array into an existing RGB array
+// a new color array into an existing color array
void nblend( CRGB* existing, CRGB* overlay, uint16_t count, fract8 amountOfOverlay);
+void nblend( CHSV* existing, CHSV* overlay, uint16_t count, fract8 amountOfOverlay,
+ TGradientDirectionCode directionCode = SHORTEST_HUES);
+
// CRGB HeatColor( uint8_t temperature)