Make GetColor32 return an unsigned integer (fixes #7305) - #7346
Open
TheOnlyJason wants to merge 1 commit into
Open
Make GetColor32 return an unsigned integer (fixes #7305)#7346TheOnlyJason wants to merge 1 commit into
TheOnlyJason wants to merge 1 commit into
Conversation
GetColor32 packed ARGB using signed 32-bit shifts, so any alpha of 128 or above produced a negative number. IntegerToRGB and ColorToRGBA gate their alpha handling on color > 16777215, which negative values never pass, so the alpha component was silently dropped on round-trips. Coerce the packed value with an unsigned right shift so GetColor32 always returns an unsigned 32-bit integer. Also updates the GetColor32 tests, which previously asserted the signed (negative) values, and adds round-trip regression tests through IntegerToRGB and ColorToRGBA for alpha >= 128. Fixes phaserjs#7305
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Phaser.Display.Color.GetColor32packed ARGB using signed 32-bit shifts, so any alpha >= 128 produced a negative number.IntegerToRGBandColorToRGBAgate their alpha handling oncolor > 16777215, which negative values never pass — so alpha was silently dropped on round-trips (see #7305 for a repro).This PR coerces the packed value with an unsigned right shift (
>>> 0) soGetColor32always returns an unsigned 32-bit integer, makingGetColor32 -> IntegerToRGB/ColorToRGBAround-trips lossless for all alpha values.Changes
src/display/color/GetColor32.js: return(alpha << 24 | red << 16 | green << 8 | blue) >>> 0; JSDoc updated.tests/display/color/GetColor32.test.js: updated expectations that previously asserted the signed (negative) values, and added regression tests: a full 0-255 alpha sweep asserting non-negative output, and round-trips throughIntegerToRGBandColorToRGBAfor alpha >= 128.Testing
npx vitest run tests/display/color/— 398/398 pass.BaseTweenfailures also present on cleanmaster.I audited internal consumers of
GetColor32(Color#_color32, WebGL camera background/flash fill) — none depend on signed values.Fixes #7305