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-12-09 07:59:14 +0300
committerMark Kriegsman <kriegsman@tr.org>2014-12-09 07:59:14 +0300
commit4d9c0c60d09e5e9256f8a16bbb62ed5bea295a85 (patch)
tree922418c003121c23bb3e998f3a55121cdbaac5d2
parentff4ba590f1d957796a5358a8477a52c579350a13 (diff)
Added CRGB::getParity, CRGB::setParity, and fairy light color apporximations: CRGB::FairyLight and CRGB::FairyLightNCC (for use with No Color Correction).
-rw-r--r--pixeltypes.h91
1 files changed, 89 insertions, 2 deletions
diff --git a/pixeltypes.h b/pixeltypes.h
index e112636b..3c583a42 100644
--- a/pixeltypes.h
+++ b/pixeltypes.h
@@ -460,6 +460,85 @@ struct CRGB {
return ret;
}
+ // getParity returns 0 or 1, depending on the
+ // lowest bit of the sum of the color components.
+ inline uint8_t getParity()
+ {
+ uint8_t sum = r + g + b;
+ return (sum & 0x01);
+ }
+
+ // setParity adjusts the color in the smallest
+ // way possible so that the parity of the color
+ // is now the desired value. This allows you to
+ // 'hide' one bit of information in the color.
+ //
+ // Ideally, we find one color channel which already
+ // has data in it, and modify just that channel by one.
+ // We don't want to light up a channel that's black
+ // if we can avoid it, and if the pixel is 'grayscale',
+ // (meaning that R==G==B), we modify all three channels
+ // at once, to preserve the neutral hue.
+ //
+ // There's no such thing as a free lunch; in many cases
+ // this 'hidden bit' may actually be visible, but this
+ // code makes reasonable efforts to hide it as much
+ // as is reasonably possible.
+ //
+ // Also, an effort is made to have make it such that
+ // repeatedly setting the parity to different values
+ // will not cause the color to 'drift'. Toggling
+ // the parity twice should generally result in the
+ // original color again.
+ //
+ inline void setParity( uint8_t parity)
+ {
+ uint8_t curparity = getParity();
+
+ if( parity == curparity) return;
+
+ if( parity ) {
+ // going 'up'
+ if( (b > 0) && (b < 255)) {
+ if( r == g && g == b) {
+ r++;
+ g++;
+ }
+ b++;
+ } else if( (r > 0) && (r < 255)) {
+ r++;
+ } else if( (g > 0) && (g < 255)) {
+ g++;
+ } else {
+ if( r == g && g == b) {
+ r ^= 0x01;
+ g ^= 0x01;
+ }
+ b ^= 0x01;
+ }
+ } else {
+ // going 'down'
+ if( b > 1) {
+ if( r == g && g == b) {
+ r--;
+ g--;
+ }
+ b--;
+ } else if( g > 1) {
+ g--;
+ } else if( r > 1) {
+ r--;
+ } else {
+ if( r == g && g == b) {
+ r ^= 0x01;
+ g ^= 0x01;
+ }
+ b ^= 0x01;
+ }
+ }
+ }
+
+
typedef enum {
AliceBlue=0xF0F8FF,
Amethyst=0x9966CC,
@@ -608,9 +687,17 @@ struct CRGB {
White=0xFFFFFF,
WhiteSmoke=0xF5F5F5,
Yellow=0xFFFF00,
- YellowGreen=0x9ACD32
+ YellowGreen=0x9ACD32,
+
+ // LED RGB color that roughly approximates
+ // the color of incandescent fairy lights,
+ // assuming that you're using FastLED
+ // color correction on your LEDs (recommended).
+ FairyLight=0xFFE42D,
+ // If you are using no color correction, use this
+ FairyLightNCC=0xFF9D2A
+
} HTMLColorCode;
- // static uint32_t Squant;
};