Skip to content
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

Merged
merged 1 commit into from
Dec 17, 2019
Merged

Fix wrong fromRGBO alpha value calculation #13777

merged 1 commit into from
Dec 17, 2019

Conversation

KNawm
Copy link
Contributor

@KNawm KNawm commented Nov 11, 2019

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

but 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));

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.

@KNawm KNawm changed the title Fix wrong fromRGBO alpha value calculation [WIP] Fix wrong fromRGBO alpha value calculation Nov 11, 2019
@chinmaygarde chinmaygarde added the Work in progress (WIP) Not ready (yet) for review! label Nov 14, 2019
@KNawm KNawm changed the title [WIP] Fix wrong fromRGBO alpha value calculation Fix wrong fromRGBO alpha value calculation Nov 17, 2019
@KNawm
Copy link
Contributor Author

KNawm commented Nov 18, 2019

@Hixie

((r & 0xff) << 16) |
((g & 0xff) << 8) |
((b & 0xff) << 0)) & 0xFFFFFFFF;
value = (((((opacity * 0xff + 0.5) ~/ 1) & 0xff) << 24) | // Round the alpha value for accuracy
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, makes sense.

Copy link
Contributor

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

@cbracken
Copy link
Member

cbracken commented Dec 9, 2019

Please add a test.

@KNawm KNawm requested a review from Hixie December 10, 2019 08:11
@cbracken cbracken removed the Work in progress (WIP) Not ready (yet) for review! label Dec 16, 2019
Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM stamp from a Japanese personal seal

@cbracken
Copy link
Member

Thanks for adding the test. I've re-triggered the failed build_and_test_linux_unopt_debug test above, which failed due to an infra flake while downloading dependencies.

@cbracken
Copy link
Member

I've rebased this against head of master and will land when the tree is green.

@cbracken cbracken merged commit 9f2daad into flutter:master Dec 17, 2019
@KNawm KNawm deleted the patch-1 branch December 18, 2019 04:18
chingjun added a commit to chingjun/flutter_svg that referenced this pull request Dec 18, 2019
flutter/engine#13777 changed the rendering,
update the goldens to fix the tests
chingjun added a commit that referenced this pull request Dec 18, 2019
chingjun added a commit that referenced this pull request Dec 18, 2019
filmil pushed a commit to filmil/engine that referenced this pull request Mar 13, 2020
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.
filmil pushed a commit to filmil/engine that referenced this pull request Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants