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>2016-01-22 03:56:32 +0300
committerMark Kriegsman <kriegsman@tr.org>2016-01-22 03:56:32 +0300
commitce4bfbc878d5be4cf5aecd9268bd2a4520a41363 (patch)
tree90ddc014f57ac4d950c6306285b628bc5d7b7200
parentf3623dc59a716d766380b2bc9b8ff798d830a280 (diff)
Speedup in basic HSV to RGB conversion. On AVR this takes us from from about 68,000 conversions/second to about 105,000 conversions/second.
-rw-r--r--hsv2rgb.cpp72
1 files changed, 44 insertions, 28 deletions
diff --git a/hsv2rgb.cpp b/hsv2rgb.cpp
index 8ba642d4..49056d51 100644
--- a/hsv2rgb.cpp
+++ b/hsv2rgb.cpp
@@ -286,22 +286,22 @@ void hsv2rgb_rainbow( const CHSV& hsv, CRGB& rgb)
// Level Y2 is a strong boost.
const uint8_t Y1 = 1;
const uint8_t Y2 = 0;
-
+
// G2: Whether to divide all greens by two.
// Depends GREATLY on your particular LEDs
const uint8_t G2 = 0;
-
+
// Gscale: what to scale green down by.
// Depends GREATLY on your particular LEDs
const uint8_t Gscale = 0;
-
-
+
+
uint8_t hue = hsv.hue;
uint8_t sat = hsv.sat;
uint8_t val = hsv.val;
-
+
uint8_t offset = hue & 0x1F; // 0..31
-
+
// offset8 = offset * 8
uint8_t offset8 = offset;
{
@@ -319,11 +319,11 @@ void hsv2rgb_rainbow( const CHSV& hsv, CRGB& rgb)
offset8 <<= 3;
#endif
}
-
+
uint8_t third = scale8( offset8, (256 / 3));
-
+
uint8_t r, g, b;
-
+
if( ! (hue & 0x80) ) {
// 0XX
if( ! (hue & 0x40) ) {
@@ -397,7 +397,7 @@ void hsv2rgb_rainbow( const CHSV& hsv, CRGB& rgb)
uint8_t twothirds = scale8( offset8, ((256 * 2) / 3));
g = K171 - twothirds;
b = K85 + twothirds;
-
+
} else {
// 101
//case 5: // B -> P
@@ -405,7 +405,7 @@ void hsv2rgb_rainbow( const CHSV& hsv, CRGB& rgb)
g = 0;
FORCE_REFERENCE(g);
b = K255 - third;
-
+
}
} else {
if( ! (hue & 0x20) ) {
@@ -415,7 +415,7 @@ void hsv2rgb_rainbow( const CHSV& hsv, CRGB& rgb)
g = 0;
FORCE_REFERENCE(g);
b = K171 - third;
-
+
} else {
// 111
//case 7: // K -> R
@@ -423,37 +423,53 @@ void hsv2rgb_rainbow( const CHSV& hsv, CRGB& rgb)
g = 0;
FORCE_REFERENCE(g);
b = K85 - third;
-
+
}
}
}
-
+
// This is one of the good places to scale the green down,
// although the client can scale green down as well.
if( G2 ) g = g >> 1;
if( Gscale ) g = scale8_video_LEAVING_R1_DIRTY( g, Gscale);
-
+
// Scale down colors if we're desaturated at all
// and add the brightness_floor to r, g, and b.
if( sat != 255 ) {
-
- nscale8x3_video( r, g, b, sat);
-
- uint8_t desat = 255 - sat;
- desat = scale8( desat, desat);
-
- uint8_t brightness_floor = desat;
- r += brightness_floor;
- g += brightness_floor;
- b += brightness_floor;
+ if( sat == 0) {
+ r = 255; b = 255; g = 255;
+ } else {
+ //nscale8x3_video( r, g, b, sat);
+ if( r ) r = scale8_LEAVING_R1_DIRTY( r, sat) + 1;
+ if( g ) g = scale8_LEAVING_R1_DIRTY( g, sat) + 1;
+ if( b ) b = scale8_LEAVING_R1_DIRTY( b, sat) + 1;
+ cleanup_R1();
+
+ uint8_t desat = 255 - sat;
+ desat = scale8( desat, desat);
+
+ uint8_t brightness_floor = desat;
+ r += brightness_floor;
+ g += brightness_floor;
+ b += brightness_floor;
+ }
}
-
+
// Now scale everything down if we're at value < 255.
if( val != 255 ) {
+
val = scale8_video_LEAVING_R1_DIRTY( val, val);
- nscale8x3_video( r, g, b, val);
+ if( val == 0 ) {
+ r=0; g=0; b=0;
+ } else {
+ // nscale8x3_video( r, g, b, val);
+ if( r ) r = scale8_LEAVING_R1_DIRTY( r, val) + 1;
+ if( g ) g = scale8_LEAVING_R1_DIRTY( g, val) + 1;
+ if( b ) b = scale8_LEAVING_R1_DIRTY( b, val) + 1;
+ cleanup_R1();
+ }
}
-
+
// Here we have the old AVR "missing std X+n" problem again
// It turns out that fixing it winds up costing more than
// not fixing it.