Merge pull request #4435 from TripleWhy/TripleWhy/issue4425

palette effect overflow fix
This commit is contained in:
netmindz 2025-01-09 11:03:44 +00:00 committed by GitHub
commit 709aeff9ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2032,7 +2032,7 @@ uint16_t mode_palette() {
const mathType sourceX = xtSinTheta + ytCosTheta + centerX; 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 // 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. // 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);
// inputSize determines by how much we want to scale the palette: // inputSize determines by how much we want to scale the palette:
// values < 128 display a fraction of a palette, // values < 128 display a fraction of a palette,
// values > 128 display multiple palettes. // values > 128 display multiple palettes.