Fix legacy 0-255 Bodymovin colours and clamp colour narrowing - #601
Open
gindemit wants to merge 1 commit into
Open
Fix legacy 0-255 Bodymovin colours and clamp colour narrowing#601gindemit wants to merge 1 commit into
gindemit wants to merge 1 commit into
Conversation
gindemit
force-pushed
the
fix/legacy-colors-and-shape-budget
branch
from
August 16, 2026 05:19
2ced270 to
133ff15
Compare
Bodymovin exporters older than 4.1.9 emit colours in the 0-255 range instead of the normalized 0-1 range the Lottie schema mandates. The parser stored those raw values, and Color::toColor() then evaluated uint8_t(255 * r) on them - an out-of-range float->integer conversion, which is undefined behaviour. The two toolchains materialized that UB differently, so the same file rendered different colours per platform: the Android NDK build truncated mod 256 (giving an inverted palette, since v*255 mod 256 == 256-v), while the Apple clang build optimized the narrowing away and let each channel's high byte bleed into the next. Neither matched the intended artwork. Detect the legacy encoding in getValue(model::Color) and normalize it, matching what lottie-web and lottie-android do. Additionally clamp in toColor() so any remaining out-of-range value degrades identically and deterministically on every target instead of diverging by compiler. Verified against the bundled body_movin.json (Bodymovin 4.0.0): the banner now renders RGB(88,214,112) with RGB(255,219,67) lettering, matching lottie-web 5.12.2 exactly; before the fix it was (168,42,144) on Android and (168,127,213) on macOS. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
gindemit
force-pushed
the
fix/legacy-colors-and-shape-budget
branch
from
August 16, 2026 11:21
133ff15 to
9474225
Compare
gindemit
marked this pull request as ready for review
August 16, 2026 16:57
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.
Test file
body_movin.json
Legacy 0-255 Bodymovin colours
Bodymovin exporters older than 4.1.9 emit colour components in the 0-255 range instead of the normalized 0-1 range the schema mandates.
LottieParserImpl::getValue(model::Color&)stored those values raw, andColor::toColor()then narrowed values such as255 * 88.0ftouint8_t. That out-of-range float-to-integer conversion is undefined behaviour and renders differently across toolchains.The bundled
body_movin.jsonsample demonstrates the problem: its banner fill is[88, 214, 112, 255]. Before this fix it renders magenta on Android and purple on Apple platforms instead of the intended green.This change:
1.0;uint8_t, including deterministic handling of NaN and out-of-range values.Verified against
body_movin.json: the banner renders RGB(88, 214, 112) with RGB(255, 219, 67) lettering, matching lottie-web 5.12.2.Gradient stops are not covered by this change because no tested sample combines legacy 0-255 colours with gradients.
The shape-content-budget fix previously included in this draft has been moved into a separate pull request so the two independent changes can be reviewed independently.