diff options
Diffstat (limited to 'pixeltypes.h')
-rw-r--r-- | pixeltypes.h | 133 |
1 files changed, 101 insertions, 32 deletions
diff --git a/pixeltypes.h b/pixeltypes.h index 6d3f67f2..e112636b 100644 --- a/pixeltypes.h +++ b/pixeltypes.h @@ -3,6 +3,7 @@ #include <stdint.h> #include "lib8tion.h" +#include "color.h" struct CRGB; struct CHSV; @@ -66,6 +67,16 @@ struct CHSV { } }; +typedef enum { + HUE_RED = 0, + HUE_ORANGE = 32, + HUE_YELLOW = 64, + HUE_GREEN = 96, + HUE_AQUA = 128, + HUE_BLUE = 160, + HUE_PURPLE = 192, + HUE_PINK = 224 +} HSVHue; struct CRGB { union { @@ -100,19 +111,31 @@ struct CRGB { inline CRGB() __attribute__((always_inline)) { } - + // allow construction from R, G, B inline CRGB( uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline)) : r(ir), g(ig), b(ib) { } - + // allow construction from 32-bit (really 24-bit) bit 0xRRGGBB color code inline CRGB( uint32_t colorcode) __attribute__((always_inline)) : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF) { } - + + inline CRGB( LEDColorCorrection colorcode) __attribute__((always_inline)) + : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF) + { + + } + + inline CRGB( ColorTemperature colorcode) __attribute__((always_inline)) + : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF) + { + + } + // allow copy construction inline CRGB(const CRGB& rhs) __attribute__((always_inline)) { @@ -120,7 +143,7 @@ struct CRGB { g = rhs.g; b = rhs.b; } - + // allow construction from HSV color inline CRGB(const CHSV& rhs) __attribute__((always_inline)) { @@ -134,7 +157,7 @@ struct CRGB { g = rhs.g; b = rhs.b; return *this; - } + } // allow assignment from 32-bit (really 24-bit) 0xRRGGBB color code inline CRGB& operator= (const uint32_t colorcode) __attribute__((always_inline)) @@ -144,7 +167,7 @@ struct CRGB { b = (colorcode >> 0) & 0xFF; return *this; } - + // allow assignment from R, G, and B inline CRGB& setRGB (uint8_t nr, uint8_t ng, uint8_t nb) __attribute__((always_inline)) { @@ -153,28 +176,28 @@ struct CRGB { b = nb; return *this; } - + // allow assignment from H, S, and V inline CRGB& setHSV (uint8_t hue, uint8_t sat, uint8_t val) __attribute__((always_inline)) { hsv2rgb_rainbow( CHSV(hue, sat, val), *this); return *this; } - + // allow assignment from just a Hue, saturation and value automatically at max. inline CRGB& setHue (uint8_t hue) __attribute__((always_inline)) { hsv2rgb_rainbow( CHSV(hue, 255, 255), *this); return *this; } - + // allow assignment from HSV color inline CRGB& operator= (const CHSV& rhs) __attribute__((always_inline)) { hsv2rgb_rainbow( rhs, *this); return *this; } - + // allow assignment from 32-bit (really 24-bit) 0xRRGGBB color code inline CRGB& setColorCode (uint32_t colorcode) __attribute__((always_inline)) { @@ -183,7 +206,7 @@ struct CRGB { b = (colorcode >> 0) & 0xFF; return *this; } - + // add one RGB to another, saturating at 0xFF for each channel inline CRGB& operator+= (const CRGB& rhs ) @@ -193,7 +216,7 @@ struct CRGB { b = qadd8( b, rhs.b); return *this; } - + // add a contstant to each channel, saturating at 0xFF // this is NOT an operator+= overload because the compiler // can't usefully decide when it's being passed a 32-bit @@ -205,7 +228,7 @@ struct CRGB { b = qadd8( b, d); return *this; } - + // subtract one RGB from another, saturating at 0x00 for each channel inline CRGB& operator-= (const CRGB& rhs ) { @@ -214,7 +237,7 @@ struct CRGB { b = qsub8( b, rhs.b); return *this; } - + // subtract a constant from each channel, saturating at 0x00 // this is NOT an operator+= overload because the compiler // can't usefully decide when it's being passed a 32-bit @@ -226,14 +249,14 @@ struct CRGB { b = qsub8( b, d); return *this; } - + // subtract a constant of '1' from each channel, saturating at 0x00 inline CRGB& operator-- () __attribute__((always_inline)) { subtractFromRGB(1); return *this; } - + // subtract a constant of '1' from each channel, saturating at 0x00 inline CRGB operator-- (int DUMMY_ARG) __attribute__((always_inline)) { @@ -248,7 +271,7 @@ struct CRGB { addToRGB(1); return *this; } - + // add a constant of '1' from each channel, saturating at 0xFF inline CRGB operator++ (int DUMMY_ARG) __attribute__((always_inline)) { @@ -265,7 +288,16 @@ struct CRGB { b /= d; return *this; } - + + // right shift each of the channels by a constant + inline CRGB& operator>>= (uint8_t d) + { + r >>= d; + g >>= d; + b >>= d; + return *this; + } + // multiply each of the channels by a constant, // saturating each channel at 0xFF inline CRGB& operator*= (uint8_t d ) @@ -286,7 +318,7 @@ struct CRGB { nscale8x3_video( r, g, b, scaledown); return *this; } - + // %= is a synonym for nscale8_video. Think of it is scaling down // by "a percentage" inline CRGB& operator%= (uint8_t scaledown ) @@ -301,7 +333,7 @@ struct CRGB { nscale8x3_video( r, g, b, 255 - fadefactor); return *this; } - + // scale down a RGB to N 256ths of it's current brightness, using // 'plain math' dimming rules, which means that if the low light levels // may dim all the way to 100% black. @@ -317,7 +349,7 @@ struct CRGB { nscale8x3( r, g, b, 255 - fadefactor); return *this; } - + // "or" operator brings each channel up to the higher of the two values inline CRGB& operator|= (const CRGB& rhs ) { @@ -333,7 +365,7 @@ struct CRGB { if( d > b) b = d; return *this; } - + // "and" operator brings each channel down to the lower of the two values inline CRGB& operator&= (const CRGB& rhs ) { @@ -349,13 +381,13 @@ struct CRGB { if( d < b) b = d; return *this; } - + // this allows testing a CRGB for zero-ness inline operator bool() const __attribute__((always_inline)) { return r || g || b; } - + // invert each channel inline CRGB operator- () { @@ -365,19 +397,28 @@ struct CRGB { retval.b = 255 - b; return retval; } - - + +#ifdef SmartMatrix_h + operator rgb24() const { + rgb24 ret; + ret.red = r; + ret.green = g; + ret.blue = b; + return ret; + } +#endif + inline uint8_t getLuma ( ) { //Y' = 0.2126 R' + 0.7152 G' + 0.0722 B' // 54 183 18 (!) - + uint8_t luma = scale8_LEAVING_R1_DIRTY( r, 54) + \ scale8_LEAVING_R1_DIRTY( g, 183) + \ scale8_LEAVING_R1_DIRTY( b, 18); cleanup_R1(); return luma; } - + inline uint8_t getAverageLight( ) { const uint8_t eightysix = 86; uint8_t avg = scale8_LEAVING_R1_DIRTY( r, eightysix) + \ @@ -396,7 +437,29 @@ struct CRGB { green = (green * factor) / 256; blue = (blue * factor) / 256; } - + + inline CRGB lerp8( CRGB & other, fract8 frac) + { + CRGB ret; + + ret.r = lerp8by8(r,other.r,frac); + ret.g = lerp8by8(g,other.g,frac); + ret.b = lerp8by8(b,other.b,frac); + + return ret; + } + + inline CRGB lerp16( CRGB & other, fract16 frac) + { + CRGB ret; + + ret.r = lerp16by16(r<<8,other.r<<8,frac)>>8; + ret.g = lerp16by16(g<<8,other.g<<8,frac)>>8; + ret.b = lerp16by16(b<<8,other.b<<8,frac)>>8; + + return ret; + } + typedef enum { AliceBlue=0xF0F8FF, Amethyst=0x9966CC, @@ -424,6 +487,7 @@ struct CRGB { DarkCyan=0x008B8B, DarkGoldenrod=0xB8860B, DarkGray=0xA9A9A9, + DarkGrey=0xA9A9A9, DarkGreen=0x006400, DarkKhaki=0xBDB76B, DarkMagenta=0x8B008B, @@ -435,11 +499,13 @@ struct CRGB { DarkSeaGreen=0x8FBC8F, DarkSlateBlue=0x483D8B, DarkSlateGray=0x2F4F4F, + DarkSlateGrey=0x2F4F4F, DarkTurquoise=0x00CED1, DarkViolet=0x9400D3, DeepPink=0xFF1493, DeepSkyBlue=0x00BFFF, DimGray=0x696969, + DimGrey=0x696969, DodgerBlue=0x1E90FF, FireBrick=0xB22222, FloralWhite=0xFFFAF0, @@ -450,6 +516,7 @@ struct CRGB { Gold=0xFFD700, Goldenrod=0xDAA520, Gray=0x808080, + Grey=0x808080, Green=0x008000, GreenYellow=0xADFF2F, Honeydew=0xF0FFF0, @@ -473,6 +540,7 @@ struct CRGB { LightSeaGreen=0x20B2AA, LightSkyBlue=0x87CEFA, LightSlateGray=0x778899, + LightSlateGrey=0x778899, LightSteelBlue=0xB0C4DE, LightYellow=0xFFFFE0, Lime=0x00FF00, @@ -526,6 +594,7 @@ struct CRGB { SkyBlue=0x87CEEB, SlateBlue=0x6A5ACD, SlateGray=0x708090, + SlateGrey=0x708090, Snow=0xFFFAFA, SpringGreen=0x00FF7F, SteelBlue=0x4682B4, @@ -541,7 +610,7 @@ struct CRGB { Yellow=0xFFFF00, YellowGreen=0x9ACD32 } HTMLColorCode; - static uint32_t Squant; + // static uint32_t Squant; }; @@ -618,7 +687,7 @@ inline CRGB operator/( const CRGB& p1, uint8_t d) return CRGB( p1.r/d, p1.g/d, p1.b/d); } - + __attribute__((always_inline)) inline CRGB operator&( const CRGB& p1, const CRGB& p2) { @@ -626,7 +695,7 @@ inline CRGB operator&( const CRGB& p1, const CRGB& p2) p1.g < p2.g ? p1.g : p2.g, p1.b < p2.b ? p1.b : p2.b); } - + __attribute__((always_inline)) inline CRGB operator|( const CRGB& p1, const CRGB& p2) { |