Skip to content

Add ColorFromPaletteExtended function for higher precision - #1687

Merged
zackees merged 1 commit into
masterfrom
color-from-palette
Aug 31, 2024
Merged

zackees merged 1 commit into
masterfrom
color-from-palette

Conversation

@zackees

@zackees zackees commented Aug 30, 2024 •

Copy link
Copy Markdown
Member

@zackees

zackees commented Aug 30, 2024

Copy link
Copy Markdown
Member Author

https://github.com/sutaburosu please feel free to pull these changes and re-submit as your own pr

@zackees

zackees commented Aug 31, 2024

Copy link
Copy Markdown
Member Author

Fixes:

#202

@zackees
zackees merged commit fb51c57 into master Aug 31, 2024
@sutaburosu

Copy link
Copy Markdown
Contributor

It's not me who should be credited for this. It was @generalelectrix who originally suggested this improvement and provided the implementation for CRGBPalette16. I just added the code for 32-colour palettes. I guess, for completeness, a version should also be added for 256-colour palettes.

I'm no expert in C++, but is it not possible to keep the same function name for the Extended version and have the compiler select which version to use based on the types? The original function takes a uint8_t index into the palette, and the extended version takes uint16_t.

@generalelectrix

Copy link
Copy Markdown

@sutaburosu our 9-year collaboration has come to fruition 🤣

@zackees

zackees commented Aug 31, 2024

Copy link
Copy Markdown
Member Author

I don't like selecting templates that auto parameterize on coercable types.

You don't know what you are going to get.

If anything there should be a define that eliminates the older version for non avr chipsets.

Are you that comfortable with this gradient that I can do this?

@sutaburosu

Copy link
Copy Markdown
Contributor

I don't like selecting templates that auto parameterize on coercable types.

I don't think templates are being used here. This should be plain old function overloading. My understanding is that if an exact match of types exists, the relevant function will be chosen. If this fails to match any functions, chars and shorts would be promoted to int, which will then fail to match any function signatures. Perhaps I am wrong in this?

If anything there should be a define that eliminates the older version for non avr chipsets.

I don't understand your reasoning here. If sketches aren't using the 8-bit indexing version, it will be absent from the binary. Why does AVR need different behaviour than other platforms?

Let users choose whether they want 8-bit or 16-bit indexing based on the type of the index parameter. This keeps backwards compatibility with existing sketches, and permits the variant to be chosen on a case-by-case basis.

Are you that comfortable with this gradient that I can do this?

I've used the 16-colour palette variant extensively on AVR for 4 years. I've never noticed a problem with it. I have very rarely used the 32-colour palette version, so I have far less confidence in it.

@sutaburosu

Copy link
Copy Markdown
Contributor

@zackees this sketch has the missing variant for 256-colour RGB palettes. I've tested all three (16, 32 and 256 colour palette variants) in multiple sketches today, and they all seem to perform flawlessly.

See the comments at the top of that sketch for benchmark results. In short, on AVR the 16-bit versions are 35%, 23% and 136% (for good reasons) slower. On platforms that can do arbitrary bit-shifts, rather than only 1-bit at a time like AVR, I would expect the performance penalty to be far lower.

That same sketch uses the function overloading idea that I suggested. Feel free to change it as you see fit. If you feel the need for the FastLED API to be different on AVR, I'll just keep including my preferred version in my sketches as I have for several years now.

As I reminder, I would prefer if you credit @generalelectrix for this work. It was their observation, and their implementation before I became obsessive over the details of it.

I hope this information is useful to you. It would be great if some form of these suggestions could make it into tomorrow's release, rather than the 32-colour palette only version that currently stands in the root branch of the repo.

All the best. 🍷

@zackees

zackees commented Sep 3, 2024

Copy link
Copy Markdown
Member Author

That same sketch uses the function overloading idea that I suggested. Feel free to change it as you see fit. If you feel the need for the FastLED API to be different on AVR, I'll just keep including my preferred version in my sketches as I have for several years now.

If someone uses a 16 bit index on avr then they automatically get the new Palette function. I'm not a big fan of that as it's non obvious.

Are you really using AVR that much?

@sutaburosu

Copy link
Copy Markdown
Contributor

Are you really using AVR that much?

My projects are almost exclusively AVR. I use Teensy 4.x when I need something bigger and faster, but easily >95% of my projects use USD$0.80 Nano clones. Apart from the price, I very much enjoy the challenge of getting pleasing results at high frame rates with such limited specifications.

I notice the recent release of FastLED is missing the 16-colour palette variant of ColorFromPaletteExtended. There is well tested code in that sketch I linked previously.

zackees added a commit that referenced this pull request Sep 7, 2024
@zackees

zackees commented Sep 7, 2024

Copy link
Copy Markdown
Member Author

16-colour palette extended added.

@zackees

zackees commented Sep 14, 2024 •

Copy link
Copy Markdown
Member Author

Okay I didn't realize you were an AVR expert. I'm willing to revisit this and move *Extended to the normal function calls... IF and only if it doesn't break my compiled size tests for AVR.

Can you confirm the performance is reasonable in comparison to bit banging the let's out?

@sutaburosu

@zackees
zackees deleted the color-from-palette branch September 28, 2024 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants