@@ -15,7 +15,7 @@ CRGBA& CRGBA::nscale8(uint8_t scale) {
1515 return *this ;
1616}
1717
18- CRGBA& CRGBA::nadd (CRGBA c, bool preserveCR) {
18+ CRGBA& __attribute__ ((optimize( " O2 " ))) CRGBA::nadd(CRGBA c, bool preserveCR) {
1919 uint32_t c2 = c.color32 & 0x00FFFFFF ; // ignore alpha/white of color2
2020 if (c.a < 255 ) fast_color_scale (c2, c.a ); // scale color2 by its alpha
2121 uint32_t c1 = color32 & 0x00FFFFFF ; // ignore alpha/white of color1
@@ -48,7 +48,7 @@ CRGBA& CRGBA::nadd(CRGBA c, bool preserveCR) {
4848 * color blend function, based on FastLED blend function
4949 * the calculation for each color is: result = (A*(amountOfA) + A + B*(amountOfB) + B) / 256 with amountOfA = 255 - amountOfB
5050 */
51- uint32_t color_blend (uint32_t color1, uint32_t color2, uint8_t blend) {
51+ uint32_t __attribute__ ((optimize( " O2 " ))) color_blend(uint32_t color1, uint32_t color2, uint8_t blend) {
5252 // min / max blend checking is omitted: calls with 0 or 255 are rare, checking lowers overall performance
5353 uint32_t rb1 = color1 & TWO_CHANNEL_MASK; // extract R & B channels from color1
5454 uint32_t wg1 = (color1 >> 8 ) & TWO_CHANNEL_MASK; // extract W & G channels from color1 (shifted for multiplication later)
@@ -64,7 +64,7 @@ uint32_t color_blend(uint32_t color1, uint32_t color2, uint8_t blend) {
6464 * original idea: https://github.com/wled/WLED/pull/2465 by https://github.com/Proto-molecule
6565 * speed optimisations by @dedehai
6666 */
67- uint32_t color_add (uint32_t c1, uint32_t c2, bool preserveCR) {
67+ uint32_t __attribute__ ((optimize( " O2 " ))) color_add(uint32_t c1, uint32_t c2, bool preserveCR) {
6868 if (preserveCR) { fast_color_add (c1, c2); return c1; }
6969 if (c1 == BLACK) return c2;
7070 if (c2 == BLACK) return c1;
@@ -78,15 +78,15 @@ uint32_t color_add(uint32_t c1, uint32_t c2, bool preserveCR) {
7878}
7979
8080// fast color scale function (scales c1 as c1 * scale / 256)
81- void fast_color_scale (uint32_t &c1, uint8_t scale) {
81+ void __attribute__ ((optimize( " O2 " ))) fast_color_scale(uint32_t &c1, uint8_t scale) {
8282 uint32_t s = scale + 1 ;
8383 uint32_t rb = ((( c1 & TWO_CHANNEL_MASK) * s) >> 8 ) & TWO_CHANNEL_MASK;
8484 uint32_t wg = (((c1>>8 ) & TWO_CHANNEL_MASK) * s) & ~TWO_CHANNEL_MASK;
8585 c1 = rb | wg;
8686}
8787
8888// fast color add function that preserves ratio
89- void fast_color_add (uint32_t &c1, uint32_t c2, uint8_t scale) {
89+ void __attribute__ ((optimize( " O2 " ))) fast_color_add(uint32_t &c1, uint32_t c2, uint8_t scale) {
9090 if (c2 == BLACK) return ; // adding black does nothing
9191 if (scale < 255 ) fast_color_scale (c2, scale); // scale added color
9292 if (c1 == BLACK) { c1 = c2; return ; } // source is black, just assign c2
@@ -108,7 +108,7 @@ void fast_color_add(uint32_t &c1, uint32_t c2, uint8_t scale) {
108108 * fades color toward black
109109 * if using "video" method the resulting color will never become black unless it is already black
110110 */
111- uint32_t color_fade (uint32_t c1, uint8_t amount, bool video) {
111+ uint32_t __attribute__ ((optimize( " O2 " ))) color_fade(uint32_t c1, uint8_t amount, bool video) {
112112 if (amount == 255 ) return c1; // no fading
113113 uint32_t addRemains = 0 ;
114114 if (video && amount) { // video scaling: make sure colors do not dim to zero if they started non-zero
@@ -126,7 +126,7 @@ uint32_t color_fade(uint32_t c1, uint8_t amount, bool video) {
126126// Blending also occurs between the 16th and 1st elements when blendType is LINEARBLEND, producing wrap-around palette.
127127// If you do not want wrap-around, use LINEARBLEND_NOWRAP which effectively reduces color entris count to 240.
128128// If you do not want any blending at all, use NOBLEND which effectively reduces color entries count to 16.
129- CRGBA ColorFromPaletteWLED (const CRGBPalette16& pal, uint8_t index, uint8_t brightness, TBlendType blendType) {
129+ CRGBA __attribute__ ((optimize( " O2 " ))) ColorFromPaletteWLED(const CRGBPalette16& pal, uint8_t index, uint8_t brightness, TBlendType blendType) {
130130 if (blendType == LINEARBLEND_NOWRAP) {
131131 index = (index*241 ) >> 8 ; // Blend range is affected by lo4 blend of values, remap to avoid wrapping
132132 }
0 commit comments