Skip to content

Make GetColor32 return an unsigned integer (fixes #7305) - #7346

Open
TheOnlyJason wants to merge 1 commit into
phaserjs:masterfrom
TheOnlyJason:fix/get-color32-unsigned
Open

Make GetColor32 return an unsigned integer (fixes #7305)#7346
TheOnlyJason wants to merge 1 commit into
phaserjs:masterfrom
TheOnlyJason:fix/get-color32-unsigned

Conversation

@TheOnlyJason

Copy link
Copy Markdown

Description

Phaser.Display.Color.GetColor32 packed ARGB using signed 32-bit shifts, so any alpha >= 128 produced a negative number. IntegerToRGB and ColorToRGBA gate their alpha handling on color > 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) so GetColor32 always returns an unsigned 32-bit integer, making GetColor32 -> IntegerToRGB/ColorToRGBA round-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 through IntegerToRGB and ColorToRGBA for alpha >= 128.

Testing

  • npx vitest run tests/display/color/ — 398/398 pass.
  • Full suite: 23,323 pass; the only failures are 4 pre-existing BaseTween failures also present on clean master.

I audited internal consumers of GetColor32 (Color#_color32, WebGL camera background/flash fill) — none depend on signed values.

Fixes #7305

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetColor32() shouldn't output negative values

1 participant