Skip to content
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

palette effect overflow fix #4435

Merged
merged 1 commit into from
Jan 9, 2025
Merged

Conversation

TripleWhy
Copy link
Contributor

I belive this fixes #4425

@TripleWhy
Copy link
Contributor Author

Note: this does replace some more 32 bit multiplications with slightly more expensive 64 bit multiplications.

@blazoncek
Copy link
Collaborator

Tested and works.

@netmindz netmindz requested a review from DedeHai December 28, 2024 11:02
@@ -2032,7 +2032,7 @@ uint16_t mode_palette() {
const mathType sourceX = xtSinTheta + ytCosTheta + centerX;
// The computation was scaled just right so that the result should always be in range [0, maxXOut], but enforce this anyway
// to account for imprecision. Then scale it so that the range is [0, 255], which we can use with the palette.
int colorIndex = (std::min(std::max(sourceX, mathType(0)), maxXOut * sInt16Scale) * 255) / (sInt16Scale * maxXOut);
int colorIndex = (std::min(std::max(sourceX, mathType(0)), maxXOut * sInt16Scale) * wideMathType(255)) / (sInt16Scale * maxXOut);
Copy link
Collaborator

@softhack007 softhack007 Dec 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does wideMathType() do?

Essentially this PR changes "255" to "wideMathType(255)", I'm wondering is this the same as writing "255.0f" or maybe "255L" ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

255ULL for ESP8266 and 255.0f otherwise

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like someone tried to avoid fixed point math?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way it is implemented is quite an elegant way to support float AND fixed point math.

Copy link
Collaborator

@DedeHai DedeHai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simple fix, approved.

@DedeHai DedeHai added this to the 0.15.1 candidate milestone Dec 29, 2024
@netmindz netmindz merged commit 709aeff into Aircoookie:main Jan 9, 2025
19 checks passed
@netmindz netmindz added the bug label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Palette effect will not spread palette colors across entire strip
5 participants