-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Conversation
Note: this does replace some more 32 bit multiplications with slightly more expensive 64 bit multiplications. |
Tested and works. |
@@ -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); |
There was a problem hiding this comment.
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" ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simple fix, approved.
I belive this fixes #4425