So I got a bit to review @jeff’s utility code with fresh eyes, now that I’ve played with WLED/FastLED (shortened to WLED, hereafter) palettes and IQ’s palettes. And it’s interesting because Jeff’s approach is more PB centric (0…1, including rollover), but isn’t really compatible with many WLED palettes (which use an explicit palette map, with up to 255 positions, so you can specify a color at position 0, and then say position 128, and it’s a smooth transition between them, but then the next step might be 150, with a smooth transition to there. I think Jeff’s approach is 8 steps, but it’s also HSV compliant, while the WLED and IQ methods are mostly RGB, by default (I believe they could work with HSV, in many cases).
The IQ method of cosine gradients is very much a ‘quick and dirty’ method, but its not really suited to specific custom palettes, but more of a mathematical offering of many palettes. This works from a PB perspective in that it’s using 0…1, it’ll wrap since it’s using cosine math, and it’s relatively light in terms of definition. A mere 12-16 values should be enough. So an IQ palette is absolutely a winner in terms of “I don’t want a rainbow, what else do you have?” type palettes, where you want to replace a color ‘flow’ with something else.
WLED palettes, being focused on 8bit, are essentially tables of position+RGB, with a minimal size of 2 (0[start] and 255[end]) with as many midpoints as you’d like to add (between 1-254). It would be easy enough to modify all of those values to 0…1, so you’d have something akin to Jeff’s palettes, but more flexible, and more ‘standardized’ ie lots of WLED/FastLed users, but also sites like cpt-city use the usual RGB 0-255 ranges but can also use 0…1 for position.
For an example, you compare different formats for sd | Blue-Gloss 0
you’ll notice that the .pg and .c3g versions (among others) are using 0…1 for positioning.
The negative to all of these is that most of them don’t cycle/loop between 0 and 1, so you end up with a ‘hard edge’ if you try to wrap it. This isn’t always an issue, depends greatly on usage. But it does mean it’s not always a clean replacement for just wrapping ala hsv()
As for which (if any) is better, it’ll depend greatly on how (and who) wants to implement palette support in whatever patterns. For example, if you’re porting WLED patterns, you’ll almost certainly want to support palettes as it expects, if you want it to look ‘like the real thing’. But if you are modifying existing patterns that are ok with wrapping, thanks to the use of hsv(), then a wrapping palette method makes more sense.
Moving forward, I think a lot will depend on how cleanly the implementation is, and how ‘featureful’ it is. If we end up with some form of ‘library’ include, then it might not matter, but in the short term, if you need to include all of the “palette code” into your pattern, then a minimal amount of code is going to win the day in most cases. I wouldn’t want a short pattern to require twice as much code for palettes as the new code itself. If Ben decides to include some form of palette support in the firmware at some point, this might change, but… until we demonstrate what’s really useful and would benefit from firmware including, I’m not sure it’s clear what would be worth stashing into firmware.
Including the existing WLED palettes into a port of WLED patterns/effects makes huge sense. I’ll discuss the WLED porting effort elsewhere (there is a thread for it).
If it’s possible to define lots of ‘wrapping’ palettes via IQ’s method, and even make random palettes viable, or have a robust selection in a quick/small bit of code, is that ‘better’ than having some discreet non-linear palettes that require something akin to the WLED/cpt-city style ‘positioning’ method? I don’t know the answer, and there may not be a definitive answer, it probably depends on usage and preference… but we’ll see. My hope is we flesh out “both” methods and see what get used and how. And to that end, I’d like to see @Jeff’s utility code tweaked to support more of the WLED method, along with code above, so we have a solid ‘positional’ palette library. and the IQ method (which is definitely shader friendly) will also get a solid ‘library’ approach, and we can just see what is more useful.