Repository navigation
fix: round Color components to the nearest byte in toNumber and toHex - #12400
Open
SwastikTripathi wants to merge 1 commit into
Open
SwastikTripathi wants to merge 1 commit into
SwastikTripathi wants to merge 1 commit into
Conversation
SwastikTripathi
requested review from
GoodBoyDigital,
Zyie and
bigtimebuddy
as code owners
November 14, 2026 03:09
commit: |
bigtimebuddy
approved these changes
Nov 14, 2026
This branch has not been deployed
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 of change
Colorconverts a component to a byte two different ways.toUint8RgbArray(),toRgbaString()andtoBgrNumber()round, but the cached integer behindtoNumber(),toHex(),toHexa(),toLittleEndianNumber()andtoPremultiplied()truncates ((r * 255) << 16). Any component that isn't an exact multiple of 1/255 gives two different colors:This shows up in rendering. A container tint goes through
toBgrNumber()(rounded), while aGraphicsfill goes throughtoNumber()and the canvas renderer throughtoHex()(both truncated). So the same color is one step darker on a filled shape than on a tinted sprite, and differs between the WebGL/WebGPU and canvas renderers. ThetoHex()docs also say "Values are rounded to nearest hex value"._refreshInt()now usesMath.round, liketoUint8RgbArray(). Exact byte values (numbers, hex strings, CSS colors) are unchanged, sincev / 255 * 255already lands onv. I checked all 256 values with the components stored as aFloat32Array.The multiply test expected
0x3f3f3ffor0.25. 0.25 * 255 = 63.75, which rounds to0x40, so it now expects0x404040. The new test checks that every output agrees for components between two bytes. Both fail before the change.Pre-Merge Checklist
npm run lint)npm run test)I ran
src/colorwith Jest in a plain Node environment, since the Electron runner isn't set up on my machine, plus eslint andtsc -p .configs/tsconfig.build.json. CI will run the full suite.