Random red pixel fix by MisterGoodDeal · Pull Request #943 · FastLED/FastLED
Hi there, I'm looking at this again and would like to get this old PR fix in. Overall it looks good and I have absolutely noticed bad color with the hue algorithm in many tests.
What I'm noticing here is that you missed a few places. Wanted to give you a chance to review before I proceed.
In src/colorutils.cpp I notice that there are four rainbow functions that each set the set hsv.sat = 240
Here is what I currently see with ripgrep:
1
void fill_rainbow( struct CRGB * targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue ) { CHSV hsv; hsv.hue = initialhue; hsv.val = 255; hsv.sat = 240; for( int i = 0; i < numToFill; ++i) { targetArray[i] = hsv; hsv.hue += deltahue; } }
2
void fill_rainbow( struct CHSV * targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue ) { CHSV hsv; hsv.hue = initialhue; hsv.val = 255; hsv.sat = 240; for( int i = 0; i < numToFill; ++i) { targetArray[i] = hsv; hsv.hue += deltahue; } }
3
void fill_rainbow_circular(struct CRGB* targetArray, int numToFill, uint8_t initialhue, bool reversed) { if (numToFill == 0) return; // avoiding div/0 CHSV hsv; hsv.hue = initialhue; hsv.val = 255; hsv.sat = 240; const uint16_t hueChange = 65535 / (uint16_t)numToFill; // hue change for each LED, * 256 for precision (256 * 256 - 1) uint16_t hueOffset = 0; // offset for hue value, with precision (*256) for (int i = 0; i < numToFill; ++i) { targetArray[i] = hsv; if (reversed) hueOffset -= hueChange; else hueOffset += hueChange; hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit) } }
4
void fill_rainbow_circular(struct CHSV* targetArray, int numToFill, uint8_t initialhue, bool reversed) { if (numToFill == 0) return; // avoiding div/0 CHSV hsv; hsv.hue = initialhue; hsv.val = 255; hsv.sat = 240; const uint16_t hueChange = 65535 / (uint16_t) numToFill; // hue change for each LED, * 256 for precision (256 * 256 - 1) uint16_t hueOffset = 0; // offset for hue value, with precision (*256) for (int i = 0; i < numToFill; ++i) { targetArray[i] = hsv; if (reversed) hueOffset -= hueChange; else hueOffset += hueChange; hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit) } }
