-
Notifications
You must be signed in to change notification settings - Fork 1.7k
generic color palettes #1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
generic color palettes #1036
Conversation
… for generic TColorPalette constr (rm synonym fill_gradient_HSV)
…e not inherited via 'using'
…nd of i for operator==
808fac5
to
f89188a
Compare
…ven if default is intended (-Wextra)
f89188a
to
1c738c1
Compare
…BPalette32 cosntructor for CRGBPalette32
Hello @5chmidti ! Thank you for your contribution to FastLED -- we really appreciate all the thought and hard work that goes into a change like this one. A few questions for you: First, can you check on the speed on compilation? Sometimes template-izing part of the code makes compile time slower. Ideally, if you can compare compile times on a relatively slow computer, that would tell us a lot. Second, can you look at the resulting code size? I would not expect this number to be different, but you never know until you look. Finally, while we certainly appreciate the value of code cleanup (and making the interfaces more uniform), what do you see as the big advantages of this approach over, say, adding the missing functionality to the existing code? Thank you! |
Hi, here some measurements. Compile time (measured compile time three times each) (RPi 3B, platformio cli, esp32 arduino framework):
Binary size:
If we were add the functionality where it is missing, we have to check where it is missing, and we have to check if it is correct in every implementation. Doing it like this reduces this checking for completeness and correctness of palettes's member functions and puts it into one single common base class (for the member functions that allow it). Example: lets create a 64 entry CRGB palette
and all that is missing is for this to work is the |
accidentally deleted the branch in the fork... restored it and reopened |
6fdf45c
to
f18be6e
Compare
The regression in compile times to not bother that much. However, the binary size increase means this is dead on arrival. I am super strict about this and our automated testing is set up to fail with the slightest increase in binary size on the avr platforms. You might want to rebase from master and update this PR. If you do this, then there is a binary size profile that will run now so we can see where the size increase is coming from. |
fcf8a90
to
4796b69
Compare
Alright this one is a bit bigger, maybe too big :) so I know it will take time to go through the changes. I've been sitting on this since april and rebased the commits recently so here we go.
@kriegsman looking at the commits this is your code.
This started as an idea that the palettes are very similar/the same in their implementation and that it would be better to make them have a base class to avoid code duplication and slight differences between them. The CRGBPalettes have the CRGBPalette to inherit from, so they inherit the things from TColorPalette as well as constructors for CHSV colors and palettes.
Do note that there are no virtual functions/operators/constructors. The inheritance makes it look look like we call multiple constructors when we use the ones from TColorPalette. That is true when compiling with -O0 (i.e. no optimization), but even -Os optimizes this away (should be default for embedded ide's).
proof of concept for no hit in speed (orange means warnings, this is because -std=c++11 or -std=gnu++11 is not set (all green if set), default in Arduino IDE since 1.6.6 and it was also default for me in platformio, so should be default for all relatively up to date environments) (note: only use x86 compilers, as I've used std::time in this example to make sure the constructors wont get optimized too far). You can inspect the generated code on the right, if you specify any optimization level other than -O0 there are no calls to constructors from base classes.
Basics:
Color palettes inherit from a common template class base, to make the color palette implementations more consistent and avoid code duplication. Examples of differences between palettes in the current implementation:
Changes:
Things to discuss:
Moving forward
Definition of the CHSVPalette16 as an example
This could also proof useful for the future when CRGBW get's introduced (I know you guys are currently working on it), as the amount of things to define is greatly reduced. The above example (maybe without the progmem part) could be quite similar to a CRGBWPalette16. The only things left to do after defining the palette like above would be declaring the upscaling functions (way of declaration and if needed depends on discussion) and defining fill_gradient functions, as well as the ColorFromPalette functions of course (no change here).
Test
code used to test the implementation (note does not compile on current master bc of the mentioned missing constructors)
I've tested a lot of parts in compiler explorer using gcc 4.8.1. I've also compared compiled assembly (esp32) (regex to remove all code addresses, bc those would change), of an example (only tested one palette, but only got like 4 changes or so in multiple of tens of thousands of lines).
Note: the diff in github is quite messy, I suggest opening up the branch in another window and comparing with master side by side as well as the diff.
...
Too far? ;D