Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented Nov 1, 2021

This PR fixes 2 bugs of how an image is encoded into a BMP:

  1. The alpha channel used to be discarded. This occurred because previous implementation assumed that since BITMAPINFOHEADER uses 32 bits per pixel, it takes the last byte as alpha, while in fact, it discards the byte. The encoder needs to use BITMAPV4HEADER and specify the bitfields to apply the alpha channel.
  2. The image used to be upside-down. This occurred because BMP scans from bottom to top, while the raw pixels are sent from top to bottom.

Some test for the BMP encoder are also added (for the first time).

The test for transparent images is janky (despite being fine for opaque images). When the image is encoded and decoded back, the resulting pixels are slightly off from the original ones (up to 10 out of 255), and the deviation is dependent on the browser. I think it's because of the decoding process, which draws on a canvas to get its pixels and introduced rounding errors converting to and from premultiplied values. I switched to drawing on a blue background first then the transparent image, and managed to narrow the deviation down to 1. I've filed the issue at flutter/flutter#92958.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flutter-dashboard flutter-dashboard bot added platform-web Code specifically for the web engine needs tests labels Nov 1, 2021
@google-cla google-cla bot added the cla: yes label Nov 1, 2021
@dkwingsmt dkwingsmt changed the title Fix BMP [Web] Fix BMP encoder Nov 3, 2021
@dkwingsmt dkwingsmt requested review from dnfield and yjbanov November 3, 2021 21:35
Comment on lines 63 to 64
width: 2,
height: 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do the opacity tests get any better if you just do a 1x1 pixel image that's fully transparent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test is fine if all pixels of the image is either fully opaque or fully transparent. The problem occurs if it contains any pixel between 1 and 254. So 1x1 fully transparent should work fine (and has been tested in the opaque image one.)

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM with question about how we might be able to improve the test/make it more stable.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 7, 2021
dkwingsmt added a commit that referenced this pull request Nov 7, 2021
dkwingsmt added a commit that referenced this pull request Nov 7, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 7, 2021
zanderso pushed a commit to flutter/flutter that referenced this pull request Nov 8, 2021
* 422b15a Roll Skia from d9d9e21b311c to a8d38078a4f3 (1 revision) (flutter/engine#29521)

* afe1c98 Roll Fuchsia Mac SDK from SfdmlzXiU... to nkHhPcy3q... (flutter/engine#29522)

* b7f4651 Roll Fuchsia Linux SDK from 5-RB9TzQH... to m90mMA37b... (flutter/engine#29523)

* 15d5a23 [Web] Fix BMP encoder (flutter/engine#29448)

* 3f55aec Fix FlutterPresentInfo struct_size doc string (flutter/engine#29524)

* b991af9 Roll Skia from a8d38078a4f3 to 7368c6d00b7c (5 revisions) (flutter/engine#29525)

* 93666e2 Fix isolate_configuration typo (flutter/engine#29318)

* 91033b9 Roll Skia from 7368c6d00b7c to a5030e9090e8 (3 revisions) (flutter/engine#29527)

* c2090c2 [iOS] Make sure spawnee's isGpuDisabled is set correctly when FlutterEngine spawn (flutter/engine#29361)

* e071f1d Roll Skia from a5030e9090e8 to 37afdbc22e89 (4 revisions) (flutter/engine#29528)

* ca1710a Roll Skia from 37afdbc22e89 to a05d3029ac65 (4 revisions) (flutter/engine#29532)

* 3364409 Reland Display Features support (Foldable and Cutout) (flutter/engine#29447)

* 4684d23 [fuchsia] Add more logging for error cases. (flutter/engine#29397)

* 5cf7c39 Remove D3D9 fallback path (flutter/engine#29533)

* 98d31de [raster_cache] Increment access_count on Touch (flutter/engine#29529)

* cc6fc4a Re-enable A11yTreeIsConsistent with higher timeout (flutter/engine#29367)

* fb20916 Roll Skia from a05d3029ac65 to 37da672b14b7 (1 revision) (flutter/engine#29534)

* d229ec8 use SkMatrix.invert() instead of MatrixDecomposition to validate cache matrices (flutter/engine#29530)

* a92aebb Roll Clang Linux from 5N9a1nYj5... to UtjvZhwws... (flutter/engine#29535)

* 47dab8a Roll Dart SDK from 3b11f88c96a5 to f38618d5d0c0 (7 revisions) (flutter/engine#29537)

* 83ccad7 FragmentProgram constructed asynchronously (flutter/engine#29513)

* 2078baf Roll Fuchsia Linux SDK from m90mMA37b... to Ci-Vji1rx... (flutter/engine#29546)

* 6bf8093 Roll Fuchsia Mac SDK from nkHhPcy3q... to emi7COLIo... (flutter/engine#29547)

* 290d179 Roll Skia from 37da672b14b7 to cf8daf79e710 (9 revisions) (flutter/engine#29548)

* 197ca59 [iOS] Fixes press key message leaks (flutter/engine#29354)

* 986b8d8 Roll Skia from cf8daf79e710 to ae67f07a58a2 (1 revision) (flutter/engine#29549)

* 11010f0 Roll Skia from ae67f07a58a2 to 17616469ddf8 (1 revision) (flutter/engine#29551)

* dadc7b2 Roll Skia from 17616469ddf8 to 4322c7fec7e4 (3 revisions) (flutter/engine#29552)

* ed66091 don't build flutter SDK artifacts for armv7 (flutter/engine#28016)

* 484cc5c Roll Dart SDK from f38618d5d0c0 to 05febe0a7860 (5 revisions) (flutter/engine#29539)

* 387563a Roll Skia from 4322c7fec7e4 to 1800d410df16 (1 revision) (flutter/engine#29553)

* 05ceba2 Roll Skia from 1800d410df16 to 725705f6630b (1 revision) (flutter/engine#29555)

* 2b142ef Roll Dart SDK from 05febe0a7860 to 38e7078fa2b7 (5 revisions) (flutter/engine#29556)

* 29da91f Roll Fuchsia Linux SDK from Ci-Vji1rx... to kHXT3xnTG... (flutter/engine#29557)

* da02a4b Roll Fuchsia Mac SDK from emi7COLIo... to 6BYh8qaYo... (flutter/engine#29558)

* 71fb575 Roll Skia from 725705f6630b to deb9386be146 (3 revisions) (flutter/engine#29559)

* c5f572a [Linux keyboard] Fix logical keys of up events are not regularized (flutter/engine#29550)

* 988ea43 Roll Dart SDK from 38e7078fa2b7 to d464cd3f2dc8 (5 revisions) (flutter/engine#29561)

* fdee74d Trace calls to Canvas::saveLayer (flutter/engine#29444)

* 953f718 ios test script checks for `ios_test_flutter` artifacts (flutter/engine#29554)

* 145d890 Roll Skia from deb9386be146 to 37bef2d300e4 (6 revisions) (flutter/engine#29563)

* cc9b174 Fix race condition introduced by background platform channels (flutter/engine#29377)

* 79b5e3c Roll Dart SDK from d464cd3f2dc8 to 996ef242a2c9 (1 revision) (flutter/engine#29564)

* 3eb6e15 fuchsia: Enable integration tests (flutter/engine#29565)

* ffa8b25 Roll Skia from 37bef2d300e4 to 2417872a9993 (1 revision) (flutter/engine#29567)

* 9af2de9 Roll Dart SDK from 996ef242a2c9 to 5ccf755b37a4 (1 revision) (flutter/engine#29568)

* 16d6d18 Roll Fuchsia Linux SDK from kHXT3xnTG... to uP2kJIngK... (flutter/engine#29569)

* 321bc56 Roll Fuchsia Mac SDK from 6BYh8qaYo... to W9UXc2Fwx... (flutter/engine#29570)

* f0a8d4e Roll Dart SDK from 5ccf755b37a4 to f6a43e5eb71d (1 revision) (flutter/engine#29571)

* 0be0303 Hide a11y elements when resigning active (flutter/engine#29566)

* 9a3195a Roll Fuchsia Linux SDK from uP2kJIngK... to aD3d4Kqmy... (flutter/engine#29572)

* b3cbee5 Roll Fuchsia Mac SDK from W9UXc2Fwx... to rIpW1050J... (flutter/engine#29573)

* df686d2 Revert "Reland Display Features support (Foldable and Cutout) (#29447)" (flutter/engine#29574)

* e812731 Revert dart to 38e7078fa2b7 (flutter/engine#29575)

* 049074e Roll Skia from 2417872a9993 to cd7220e7686c (2 revisions) (flutter/engine#29577)

* e6a51a4 Roll Fuchsia Mac SDK from rIpW1050J... to TOmxgL3av... (flutter/engine#29578)

* 8f272d9 Roll Fuchsia Linux SDK from aD3d4Kqmy... to ZniYyCw7U... (flutter/engine#29579)

* 469d6f1 Revert "[Web] Fix BMP encoder (#29448)" (flutter/engine#29580)
dkwingsmt added a commit to dkwingsmt/engine that referenced this pull request Nov 8, 2021
@dkwingsmt dkwingsmt mentioned this pull request Nov 8, 2021
8 tasks
dkwingsmt added a commit that referenced this pull request Nov 10, 2021
This PR fixes 2 bugs of how an image is encoded into a BMP.
WizzXu pushed a commit to WizzXu/flutter that referenced this pull request Nov 19, 2021
* 422b15a Roll Skia from d9d9e21b311c to a8d38078a4f3 (1 revision) (flutter/engine#29521)

* afe1c98 Roll Fuchsia Mac SDK from SfdmlzXiU... to nkHhPcy3q... (flutter/engine#29522)

* b7f4651 Roll Fuchsia Linux SDK from 5-RB9TzQH... to m90mMA37b... (flutter/engine#29523)

* 15d5a23 [Web] Fix BMP encoder (flutter/engine#29448)

* 3f55aec Fix FlutterPresentInfo struct_size doc string (flutter/engine#29524)

* b991af9 Roll Skia from a8d38078a4f3 to 7368c6d00b7c (5 revisions) (flutter/engine#29525)

* 93666e2 Fix isolate_configuration typo (flutter/engine#29318)

* 91033b9 Roll Skia from 7368c6d00b7c to a5030e9090e8 (3 revisions) (flutter/engine#29527)

* c2090c2 [iOS] Make sure spawnee's isGpuDisabled is set correctly when FlutterEngine spawn (flutter/engine#29361)

* e071f1d Roll Skia from a5030e9090e8 to 37afdbc22e89 (4 revisions) (flutter/engine#29528)

* ca1710a Roll Skia from 37afdbc22e89 to a05d3029ac65 (4 revisions) (flutter/engine#29532)

* 3364409 Reland Display Features support (Foldable and Cutout) (flutter/engine#29447)

* 4684d23 [fuchsia] Add more logging for error cases. (flutter/engine#29397)

* 5cf7c39 Remove D3D9 fallback path (flutter/engine#29533)

* 98d31de [raster_cache] Increment access_count on Touch (flutter/engine#29529)

* cc6fc4a Re-enable A11yTreeIsConsistent with higher timeout (flutter/engine#29367)

* fb20916 Roll Skia from a05d3029ac65 to 37da672b14b7 (1 revision) (flutter/engine#29534)

* d229ec8 use SkMatrix.invert() instead of MatrixDecomposition to validate cache matrices (flutter/engine#29530)

* a92aebb Roll Clang Linux from 5N9a1nYj5... to UtjvZhwws... (flutter/engine#29535)

* 47dab8a Roll Dart SDK from 3b11f88c96a5 to f38618d5d0c0 (7 revisions) (flutter/engine#29537)

* 83ccad7 FragmentProgram constructed asynchronously (flutter/engine#29513)

* 2078baf Roll Fuchsia Linux SDK from m90mMA37b... to Ci-Vji1rx... (flutter/engine#29546)

* 6bf8093 Roll Fuchsia Mac SDK from nkHhPcy3q... to emi7COLIo... (flutter/engine#29547)

* 290d179 Roll Skia from 37da672b14b7 to cf8daf79e710 (9 revisions) (flutter/engine#29548)

* 197ca59 [iOS] Fixes press key message leaks (flutter/engine#29354)

* 986b8d8 Roll Skia from cf8daf79e710 to ae67f07a58a2 (1 revision) (flutter/engine#29549)

* 11010f0 Roll Skia from ae67f07a58a2 to 17616469ddf8 (1 revision) (flutter/engine#29551)

* dadc7b2 Roll Skia from 17616469ddf8 to 4322c7fec7e4 (3 revisions) (flutter/engine#29552)

* ed66091 don't build flutter SDK artifacts for armv7 (flutter/engine#28016)

* 484cc5c Roll Dart SDK from f38618d5d0c0 to 05febe0a7860 (5 revisions) (flutter/engine#29539)

* 387563a Roll Skia from 4322c7fec7e4 to 1800d410df16 (1 revision) (flutter/engine#29553)

* 05ceba2 Roll Skia from 1800d410df16 to 725705f6630b (1 revision) (flutter/engine#29555)

* 2b142ef Roll Dart SDK from 05febe0a7860 to 38e7078fa2b7 (5 revisions) (flutter/engine#29556)

* 29da91f Roll Fuchsia Linux SDK from Ci-Vji1rx... to kHXT3xnTG... (flutter/engine#29557)

* da02a4b Roll Fuchsia Mac SDK from emi7COLIo... to 6BYh8qaYo... (flutter/engine#29558)

* 71fb575 Roll Skia from 725705f6630b to deb9386be146 (3 revisions) (flutter/engine#29559)

* c5f572a [Linux keyboard] Fix logical keys of up events are not regularized (flutter/engine#29550)

* 988ea43 Roll Dart SDK from 38e7078fa2b7 to d464cd3f2dc8 (5 revisions) (flutter/engine#29561)

* fdee74d Trace calls to Canvas::saveLayer (flutter/engine#29444)

* 953f718 ios test script checks for `ios_test_flutter` artifacts (flutter/engine#29554)

* 145d890 Roll Skia from deb9386be146 to 37bef2d300e4 (6 revisions) (flutter/engine#29563)

* cc9b174 Fix race condition introduced by background platform channels (flutter/engine#29377)

* 79b5e3c Roll Dart SDK from d464cd3f2dc8 to 996ef242a2c9 (1 revision) (flutter/engine#29564)

* 3eb6e15 fuchsia: Enable integration tests (flutter/engine#29565)

* ffa8b25 Roll Skia from 37bef2d300e4 to 2417872a9993 (1 revision) (flutter/engine#29567)

* 9af2de9 Roll Dart SDK from 996ef242a2c9 to 5ccf755b37a4 (1 revision) (flutter/engine#29568)

* 16d6d18 Roll Fuchsia Linux SDK from kHXT3xnTG... to uP2kJIngK... (flutter/engine#29569)

* 321bc56 Roll Fuchsia Mac SDK from 6BYh8qaYo... to W9UXc2Fwx... (flutter/engine#29570)

* f0a8d4e Roll Dart SDK from 5ccf755b37a4 to f6a43e5eb71d (1 revision) (flutter/engine#29571)

* 0be0303 Hide a11y elements when resigning active (flutter/engine#29566)

* 9a3195a Roll Fuchsia Linux SDK from uP2kJIngK... to aD3d4Kqmy... (flutter/engine#29572)

* b3cbee5 Roll Fuchsia Mac SDK from W9UXc2Fwx... to rIpW1050J... (flutter/engine#29573)

* df686d2 Revert "Reland Display Features support (Foldable and Cutout) (flutter#29447)" (flutter/engine#29574)

* e812731 Revert dart to 38e7078fa2b7 (flutter/engine#29575)

* 049074e Roll Skia from 2417872a9993 to cd7220e7686c (2 revisions) (flutter/engine#29577)

* e6a51a4 Roll Fuchsia Mac SDK from rIpW1050J... to TOmxgL3av... (flutter/engine#29578)

* 8f272d9 Roll Fuchsia Linux SDK from aD3d4Kqmy... to ZniYyCw7U... (flutter/engine#29579)

* 469d6f1 Revert "[Web] Fix BMP encoder (flutter#29448)" (flutter/engine#29580)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes needs tests platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants