-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix wrong fromRGBO alpha value calculation #13777
Conversation
lib/ui/painting.dart
Outdated
((r & 0xff) << 16) | | ||
((g & 0xff) << 8) | | ||
((b & 0xff) << 0)) & 0xFFFFFFFF; | ||
value = (((((opacity * 0xff + 0.5) ~/ 1) & 0xff) << 24) | // Round the alpha value for accuracy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just ((opacity * 0xff).round() & 0xff) < 24
? Seems like that would be more idiomatic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a constant which is why I think it was that way originally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah, makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment explaining that? thanks
Please add a test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the test. I've re-triggered the failed |
I've rebased this against head of |
flutter/engine#13777 changed the rendering, update the goldens to fix the tests
Constructing colors using `fromRGBO` should return the same values as the CSS `rgba()` notation. rgba(0, 0, 255, 0.5) is the same as `#0000ff80` However `fromRGBO` sometimes creates a color with an off-by-one alpha value: expect(Color.fromRGBO(0, 0, 255, 0.5), Color(0x800000ff)); Expected: Color:<Color(0x800000ff)> Actual: Color:<Color(0x7f0000ff)> If we use `withOpacity` to create the same color, it returns the correct color: expect(Color.fromRGBO(0, 0, 255, 1).withOpacity(0.5), Color(0x800000ff)); This should also be changed in lib/web_ui/lib/src/ui/painting.dart in a followup change.
…" (flutter#14548) This reverts commit 9f2daad.
Constructing colors using
fromRGBO
should return the same values as the CSSrgba()
notation.rgba(0, 0, 255, 0.5)
is the same as#0000ff80
but
fromRGBO
sometimes creates a color with an off by one alpha valueif we use
withOpacity
to create the same color it returns the correct color:it should be changed in lib/web_ui/lib/src/ui/painting.dart too and I think it would break golden tests so I don't know where to go from here.