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-18 10:53:57 +0300
committerDaniel Garcia <danielgarcia@gmail.com>2014-11-18 10:53:57 +0300
commitc7766f85f070f8dfab8727d105c78bb42db77f49 (patch)
tree1dcde4d004e4bb0105e17581d53a1c64b566e524 /colorutils.cpp
parent5b8c97da6f5629c5ee2b234744555e1eec4eeb8b (diff)
Re-arranging code layout, pulling off platform specific headers into their own directories.
Diffstat (limited to 'colorutils.cpp')
-rw-r--r--colorutils.cpp115
1 files changed, 57 insertions, 58 deletions
diff --git a/colorutils.cpp b/colorutils.cpp
index 995db69e..9bb64b7e 100644
--- a/colorutils.cpp
+++ b/colorutils.cpp
@@ -2,8 +2,7 @@
#include <stdint.h>
-#include "hsv2rgb.h"
-#include "colorutils.h"
+#include "FastLED.h"
@@ -73,22 +72,22 @@ void fill_gradient_RGB( CRGB* leds,
endcolor = startcolor;
endpos = startpos;
}
-
+
saccum87 rdistance87;
saccum87 gdistance87;
saccum87 bdistance87;
-
+
rdistance87 = (endcolor.r - startcolor.r) << 7;
gdistance87 = (endcolor.g - startcolor.g) << 7;
bdistance87 = (endcolor.b - startcolor.b) << 7;
-
+
uint16_t pixeldistance = endpos - startpos;
int16_t divisor = pixeldistance ? pixeldistance : 1;
saccum87 rdelta87 = rdistance87 / divisor;
saccum87 gdelta87 = gdistance87 / divisor;
saccum87 bdelta87 = bdistance87 / divisor;
-
+
rdelta87 *= 2;
gdelta87 *= 2;
bdelta87 *= 2;
@@ -213,23 +212,23 @@ CRGB& nblend( CRGB& existing, const CRGB& overlay, fract8 amountOfOverlay )
if( amountOfOverlay == 0) {
return existing;
}
-
+
if( amountOfOverlay == 255) {
existing = overlay;
return existing;
}
-
+
fract8 amountOfKeep = 256 - amountOfOverlay;
-
+
existing.red = scale8_LEAVING_R1_DIRTY( existing.red, amountOfKeep)
+ scale8_LEAVING_R1_DIRTY( overlay.red, amountOfOverlay);
existing.green = scale8_LEAVING_R1_DIRTY( existing.green, amountOfKeep)
+ scale8_LEAVING_R1_DIRTY( overlay.green, amountOfOverlay);
existing.blue = scale8_LEAVING_R1_DIRTY( existing.blue, amountOfKeep)
+ scale8_LEAVING_R1_DIRTY( overlay.blue, amountOfOverlay);
-
+
cleanup_R1();
-
+
return existing;
}
@@ -266,30 +265,30 @@ CHSV& nblend( CHSV& existing, const CHSV& overlay, fract8 amountOfOverlay, TGrad
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);
}
@@ -298,14 +297,14 @@ CHSV& nblend( CHSV& existing, const CHSV& overlay, fract8 amountOfOverlay, TGrad
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;
}
@@ -351,37 +350,37 @@ CHSV* blend( const CHSV* src1, const CHSV* src2, CHSV* dest, uint16_t count, fra
CRGB HeatColor( uint8_t temperature)
{
CRGB heatcolor;
-
+
// Scale 'heat' down from 0-255 to 0-191,
// which can then be easily divided into three
// equal 'thirds' of 64 units each.
uint8_t t192 = scale8_video( temperature, 192);
-
+
// calculate a value that ramps up from
// zero to 255 in each 'third' of the scale.
uint8_t heatramp = t192 & 0x3F; // 0..63
heatramp <<= 2; // scale up to 0..252
-
+
// now figure out which third of the spectrum we're in:
if( t192 & 0x80) {
// we're in the hottest third
heatcolor.r = 255; // full red
heatcolor.g = 255; // full green
heatcolor.b = heatramp; // ramp up blue
-
+
} else if( t192 & 0x40 ) {
// we're in the middle third
heatcolor.r = 255; // full red
heatcolor.g = heatramp; // ramp up green
heatcolor.b = 0; // no blue
-
+
} else {
// we're in the coolest third
heatcolor.r = heatramp; // ramp up red
heatcolor.g = 0; // no green
heatcolor.b = 0; // no blue
}
-
+
return heatcolor;
}
@@ -391,33 +390,33 @@ CRGB ColorFromPalette( const CRGBPalette16& pal, uint8_t index, uint8_t brightne
{
uint8_t hi4 = index >> 4;
uint8_t lo4 = index & 0x0F;
-
+
// CRGB rgb1 = pal[ hi4];
const CRGB* entry = &(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 = &(pal[0]);
} else {
entry++;
}
-
+
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;
@@ -426,21 +425,21 @@ CRGB ColorFromPalette( const CRGBPalette16& pal, uint8_t index, uint8_t brightne
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);
+
+ return CRGB( red1, green1, blue1);
}
@@ -451,11 +450,11 @@ CRGB ColorFromPalette( const CRGBPalette256& pal, uint8_t index, uint8_t brightn
uint8_t red = entry->red;
uint8_t green = entry->green;
uint8_t blue = entry->blue;
-
+
if( brightness != 255) {
nscale8x3_video( red, green, blue, brightness);
}
-
+
return CRGB( red, green, blue);
}
@@ -464,27 +463,27 @@ CHSV ColorFromPalette( const struct CHSVPalette16& pal, uint8_t index, uint8_t b
{
uint8_t hi4 = index >> 4;
uint8_t lo4 = index & 0x0F;
-
+
// CRGB rgb1 = pal[ hi4];
const CHSV* entry = &(pal[0]) + hi4;
uint8_t hue1 = entry->hue;
uint8_t sat1 = entry->sat;
uint8_t val1 = entry->val;
-
+
uint8_t blend = lo4 && (blendType != NOBLEND);
-
+
if( blend ) {
-
+
if( hi4 == 15 ) {
entry = &(pal[0]);
} else {
entry++;
}
-
+
uint8_t f2 = lo4 << 4;
uint8_t f1 = 256 - f2;
-
+
uint8_t hue2 = entry->hue;
uint8_t sat2 = entry->sat;
uint8_t val2 = entry->val;
@@ -497,26 +496,26 @@ CHSV ColorFromPalette( const struct CHSVPalette16& pal, uint8_t index, uint8_t b
// of the other color, so that you get the expected
// brightness or saturation ramp, with hue staying
// constant:
-
+
// If we are starting from white (sat=0)
// or black (val=0), adopt the target hue.
if( sat1 == 0 || val1 == 0) {
hue1 = hue2;
}
-
+
// If we are ending at white (sat=0)
// or black (val=0), adopt the starting hue.
if( sat2 == 0 || val2 == 0) {
hue2 = hue1;
}
-
-
+
+
sat1 = scale8_LEAVING_R1_DIRTY( sat1, f1);
val1 = scale8_LEAVING_R1_DIRTY( val1, f1);
-
+
sat2 = scale8_LEAVING_R1_DIRTY( sat2, f2);
val2 = scale8_LEAVING_R1_DIRTY( val2, f2);
-
+
// cleanup_R1();
// These sums can't overflow, so no qadd8 needed.
@@ -531,15 +530,15 @@ CHSV ColorFromPalette( const struct CHSVPalette16& pal, uint8_t index, uint8_t b
// go forwards
hue1 += scale8( deltaHue, f2);
}
-
+
cleanup_R1();
}
-
+
if( brightness != 255) {
val1 = scale8_video( val1, brightness);
}
-
- return CHSV( hue1, sat1, val1);
+
+ return CHSV( hue1, sat1, val1);
}
@@ -550,7 +549,7 @@ CHSV ColorFromPalette( const struct CHSVPalette256& pal, uint8_t index, uint8_t
if( brightness != 255) {
hsv.value = scale8_video( hsv.value, brightness);
}
-
+
return hsv;
}