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:
authorDaniel Garcia <danielgarcia@gmail.com>2014-11-30 09:02:43 +0300
committerDaniel Garcia <danielgarcia@gmail.com>2014-11-30 09:02:43 +0300
commit50d5433b4de6d1d60c11ba339edca29653e0c772 (patch)
treeadcd6a8f4c6bb76d7c8395f23b57a413a4fca54d
parent3630190d99ac23efaa69c3015271e86eb5c7e991 (diff)
parent29327e44b76f83e53c5e7dfbc8ed04fc82396acb (diff)
Merge branch 'FastLED3.1' of https://github.com/FastLED/FastLED into FastLED3.1
-rw-r--r--colorutils.cpp12
-rw-r--r--lib8tion.h46
2 files changed, 35 insertions, 23 deletions
diff --git a/colorutils.cpp b/colorutils.cpp
index 4a4d53a4..16433f45 100644
--- a/colorutils.cpp
+++ b/colorutils.cpp
@@ -38,9 +38,9 @@ void fill_rainbow( struct CRGB * pFirstLED, int numToFill,
CHSV hsv;
hsv.hue = initialhue;
hsv.val = 255;
- hsv.sat = 255;
+ hsv.sat = 240;
for( int i = 0; i < numToFill; i++) {
- hsv2rgb_rainbow( hsv, pFirstLED[i]);
+ pFirstLED[i] = hsv;
hsv.hue += deltahue;
}
}
@@ -52,7 +52,7 @@ void fill_rainbow( struct CHSV * targetArray, int numToFill,
CHSV hsv;
hsv.hue = initialhue;
hsv.val = 255;
- hsv.sat = 255;
+ hsv.sat = 240;
for( int i = 0; i < numToFill; i++) {
targetArray[i] = hsv;
hsv.hue += deltahue;
@@ -267,7 +267,7 @@ CRGB blend( const CRGB& p1, const CRGB& p2, fract8 amountOfP2 )
CRGB* blend( const CRGB* src1, const CRGB* src2, CRGB* dest, uint16_t count, fract8 amountOfsrc2 )
{
- for( uint16_t i = count; i; i--) {
+ for( uint16_t i = 0; i < count; i++) {
dest[i] = blend(src1[i], src2[i], amountOfsrc2);
}
return dest;
@@ -343,7 +343,7 @@ CHSV blend( const CHSV& p1, const CHSV& p2, fract8 amountOfP2, TGradientDirectio
CHSV* blend( const CHSV* src1, const CHSV* src2, CHSV* dest, uint16_t count, fract8 amountOfsrc2, TGradientDirectionCode directionCode )
{
- for( uint16_t i = count; i; i--) {
+ for( uint16_t i = 0; i < count; i++) {
dest[i] = blend(src1[i], src2[i], amountOfsrc2, directionCode);
}
return dest;
@@ -353,7 +353,7 @@ CHSV* blend( const CHSV* src1, const CHSV* src2, CHSV* dest, uint16_t count, fra
// Forward declaration of the function "XY" which must be provided by
// the application for use in two-dimensional filter functions.
-uint16_t XY( uint8_t, uint8_t);
+uint16_t XY( uint8_t, uint8_t);// __attribute__ ((weak));
// blur1d: one-dimensional blur filter. Spreads light to 2 line neighbors.
diff --git a/lib8tion.h b/lib8tion.h
index eb3f5c8a..3b913ecd 100644
--- a/lib8tion.h
+++ b/lib8tion.h
@@ -1419,13 +1419,29 @@ void * memset8 ( void * ptr, uint8_t value, uint16_t num ) __attribute__ ((noinl
// linear interpolation, such as could be used for Perlin noise, etc.
//
+// A note on the structure of the lerp functions:
+// The cases for b>a and b<=a are handled separately for
+// speed: without knowing the relative order of a and b,
+// the value (a-b) might be overflow the width of a or b,
+// and have to be promoted to a wider, slower type.
+// To avoid that, we separate the two cases, and are able
+// to do all the math in the same width as the arguments,
+// which is much faster and smaller on AVR.
+
// linear interpolation between two unsigned 8-bit values,
// with 8-bit fraction
LIB8STATIC uint8_t lerp8by8( uint8_t a, uint8_t b, fract8 frac)
{
- uint8_t delta = b - a;
- uint8_t scaled = scale8( delta, frac);
- uint8_t result = a + scaled;
+ uint8_t result;
+ if( b > a) {
+ uint8_t delta = b - a;
+ uint8_t scaled = scale8( delta, frac);
+ result = a + scaled;
+ } else {
+ uint8_t delta = a - b;
+ uint8_t scaled = scale8( delta, frac);
+ result = a - scaled;
+ }
return result;
}
@@ -1433,23 +1449,19 @@ LIB8STATIC uint8_t lerp8by8( uint8_t a, uint8_t b, fract8 frac)
// with 16-bit fraction
LIB8STATIC uint16_t lerp16by16( uint16_t a, uint16_t b, fract16 frac)
{
- uint16_t delta = b - a;
- uint32_t prod = (uint32_t)delta * (uint32_t)frac;
- uint16_t scaled = prod >> 16;
- uint16_t result = a + scaled;
+ uint16_t result;
+ if( b > a ) {
+ uint16_t delta = b - a;
+ uint32_t scaled = scale16(delta, frac);
+ result = a + scaled;
+ } else {
+ uint16_t delta = a - b;
+ uint16_t scaled = scale16( delta, frac);
+ result = a - scaled;
+ }
return result;
}
-
-// A note on the structure of lerp16by8 (and lerp15by8) :
-// The cases for b>a and b<=a are handled separately for
-// speed: without knowing the relative order of a and b,
-// the value (a-b) might be a signed 17-bit value, which
-// would have to be stored in a 32-bit signed int and
-// processed as such. To avoid that, we separate the
-// two cases, and are able to do all the math with 16-bit
-// unsigned values, which is much faster and smaller on AVR.
-
// linear interpolation between two unsigned 16-bit values,
// with 8-bit fraction
LIB8STATIC uint16_t lerp16by8( uint16_t a, uint16_t b, fract8 frac)