Skip to content

Conversation

@mboetger
Copy link
Contributor

@mboetger mboetger commented Oct 10, 2025

Fixing two HEIF decoding issues on Android:

API 36: ImageDecoder has a known issue decoding HEIF images with certain gain maps. Image won't load. The workaround is to use BitmapFactory instead.

Pre-36: HEIF Flipping did not work. Image is upside.

Before After
Api 36 Screenshot_20251010_151132 Screenshot_20251010_150551
Pre Api 36 Screenshot_20251010_150752 Screenshot_20251010_150703

Fixes: #176407

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], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added platform-android Android applications specifically engine flutter/engine related. See also e: labels. team-android Owned by Android platform team labels Oct 10, 2025
@mboetger mboetger force-pushed the heic-176407 branch 4 times, most recently from 5b80e98 to fc3d7b3 Compare October 10, 2025 21:05
@mboetger mboetger marked this pull request as ready for review October 13, 2025 17:52
@mboetger mboetger requested a review from a team as a code owner October 13, 2025 17:52
@mboetger mboetger requested a review from gmackall October 13, 2025 17:53
@mboetger
Copy link
Contributor Author

@gmackall - I tried to get the flipping metadata a couple of different ways, but the Exif was the only one that worked. I think that's fine as we have verification that flipping does not work pre-36. And since we are applying it ourselves in 36, it's still fine.

I've been told a fix is in the works, so I'm hoping things will work in 37.

Copy link
Contributor

@reidbaker reidbaker left a comment

Choose a reason for hiding this comment

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

Have not reviewed tests yet

Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

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

My main question is: do we know that the image flipping issue affects all HEIF images on api 36? Or is it only a subset? My concern would be that if this only affects a certain case of HEIF images that we might regress rotation of the unaffected set by double-rotating them (because it is based on EXIF). But if rotation is broken for all HEIF images than I think this approach makes sense.

@mboetger
Copy link
Contributor Author

@gmackall

My main question is: do we know that the image flipping issue affects all HEIF images on api 36?

Flipping is only an issue pre 36.

The flipping is not an issue on 36 - it will throw an exception trying parse the data. The workaround for that (as advised by the codec team) is to just use BitmapFactory and handle the rotation/flipping ourselves. It won't be double applied because BitmapFactory is not doing that - ImageDecoder would, but it throws an exception.

It technically is a subset of images that will throw the exception - so we could try and then only fallback once an exception has been thrown. It's only if the underlying codec cannot handle the incoming gainmap. However, it's impossible with the tools at hand to know: 1.) if the codec can handle it and 2.) if the HEIC has the type of gainmap.

We could take a dependency on an HEIC parsing library - and that would allow us to check for gainmaps - but we would still not know #1. But if we do add that dependency then we could use the HEIC info and not the EXIF.

@mboetger
Copy link
Contributor Author

set? My concern would be that if this only affects a certain case of HEIF images that we might regress rotation of the unaffected

@gmackall - per offline convo I updated to only fallback if the default ImageDecoder call fails.

@mboetger mboetger requested a review from gmackall October 14, 2025 20:08
Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

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

lgtm

@mboetger
Copy link
Contributor Author

@reidbaker - per our offline convo, removed the dep on androidx.exifinterface to try to get this in. Filed #177071 and #177066 as follow-ups.

@reidbaker
Copy link
Contributor

@mboetger you will still need to ignore the lint that warns you to use androidx

@mboetger mboetger added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 18, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Oct 18, 2025
Merged via the queue into flutter:master with commit 8b7310e Oct 18, 2025
184 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 18, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 19, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 19, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 19, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 19, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 20, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Oct 20, 2025
flutter/flutter@891d7d5...2d34167

2025-10-20 [email protected] Cleanup create_updated_flutter_deps.py a bit (flutter/flutter#177162)
2025-10-20 [email protected] Fixed hot reload/restart crashes after closing browser tab on web-server device (flutter/flutter#177026)
2025-10-20 [email protected] Roll Skia from 0a3ace6fde82 to ed4294faecde (2 revisions) (flutter/flutter#177249)
2025-10-20 [email protected] Add DropdownMenu.decorationBuilder (flutter/flutter#176264)
2025-10-20 [email protected] Roll Skia from 05e2f42f533d to 0a3ace6fde82 (1 revision) (flutter/flutter#177242)
2025-10-20 [email protected] Roll Skia from 89abc5393317 to 05e2f42f533d (1 revision) (flutter/flutter#177238)
2025-10-20 [email protected] [ios][engine] Fix autofill context cleanup and view lifecycle management (flutter/flutter#173598)
2025-10-20 [email protected] Fix Image.network not using cache when headers are specified (flutter/flutter#176831)
2025-10-19 [email protected] Roll Dart SDK from a66f334fee2a to 2cd2106f2cef (4 revisions) (flutter/flutter#177190)
2025-10-19 [email protected] Roll Skia from 2d424175a481 to 89abc5393317 (1 revision) (flutter/flutter#177235)
2025-10-19 [email protected] Make sure that a ListTile doesn't crash in 0x0 environment (flutter/flutter#176176)
2025-10-19 [email protected] Make sure that a DropdownButton doesn't crash in 0x0 environment (flutter/flutter#174880)
2025-10-19 [email protected] Roll Skia from 899155871d29 to 2d424175a481 (1 revision) (flutter/flutter#177229)
2025-10-19 [email protected] Roll Skia from b864c56efb66 to 899155871d29 (1 revision) (flutter/flutter#177227)
2025-10-19 [email protected] Roll Fuchsia Linux SDK from M8WT2GMY46e_0fFho... to tKrvmvTOQITL81oOC... (flutter/flutter#177223)
2025-10-19 [email protected] Roll Skia from 0992b560454f to b864c56efb66 (1 revision) (flutter/flutter#177222)
2025-10-18 [email protected] Fix HEIF decoding (flutter/flutter#176860)
2025-10-18 [email protected] Roll Skia from 74df18176924 to 0992b560454f (1 revision) (flutter/flutter#177217)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
Fixing two HEIF decoding issues on Android:

API 36: ImageDecoder has a known issue decoding HEIF images with certain
gain maps. Image won't load. The workaround is to use BitmapFactory
instead.

Pre-36: HEIF Flipping did not work.  Image is upside.

|  |Before | After |
|---|---|---|
| Api 36 | <img width="320" height="714"
alt="Screenshot_20251010_151132"
src="https://github.com/user-attachments/assets/c1f48e0e-def8-4d8e-9847-c2ca9dac16e4"
/> | <img width="320" height="714" alt="Screenshot_20251010_150551"
src="https://github.com/user-attachments/assets/f0df1d19-3a5d-4751-b529-1e062a0af48c"
/> |
| Pre Api 36 | <img width="320" height="714"
alt="Screenshot_20251010_150752"
src="https://github.com/user-attachments/assets/9291d76b-d383-49d5-b9d7-add8bbf33e59"
/> | <img width="320" height="714" alt="Screenshot_20251010_150703"
src="https://github.com/user-attachments/assets/814454dc-d97a-4baf-9a8c-d9b5fe6ac51e"
/> |

Fixes: flutter#176407

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.

---------

Co-authored-by: Gray Mackall <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HEIC image with vertical flip displays incorrectly via the Image widget (on Android 15 or lower) or outright fails (on Android 16)

4 participants