-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix HEIF decoding #176860
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 HEIF decoding #176860
Conversation
5b80e98 to
fc3d7b3
Compare
|
@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. |
reidbaker
left a comment
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.
Have not reviewed tests yet
...src/flutter/shell/platform/android/io/flutter/embedding/engine/image/ExifMetadataReader.java
Outdated
Show resolved
Hide resolved
...rc/flutter/shell/platform/android/io/flutter/embedding/engine/image/FlutterImageDecoder.java
Outdated
Show resolved
Hide resolved
...tter/shell/platform/android/io/flutter/embedding/engine/image/ImageDecoderHeifApi36Impl.java
Show resolved
Hide resolved
...ell/platform/android/io/flutter/embedding/engine/image/FlutterImageDecoderImplHeifPre36.java
Outdated
Show resolved
Hide resolved
engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/image/Utils.java
Outdated
Show resolved
Hide resolved
engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/image/ImageUtils.java
Show resolved
Hide resolved
...rc/flutter/shell/platform/android/io/flutter/embedding/engine/image/FlutterImageDecoder.java
Show resolved
Hide resolved
...lutter/shell/platform/android/io/flutter/embedding/engine/image/ImageDecoderDefaultImpl.java
Show resolved
Hide resolved
...src/flutter/shell/platform/android/io/flutter/embedding/engine/image/ExifMetadataReader.java
Show resolved
Hide resolved
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.
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.
...rc/flutter/shell/platform/android/io/flutter/embedding/engine/image/FlutterImageDecoder.java
Outdated
Show resolved
Hide resolved
...ell/platform/android/io/flutter/embedding/engine/image/FlutterImageDecoderImplHeifPre36.java
Outdated
Show resolved
Hide resolved
...rc/flutter/shell/platform/android/io/flutter/embedding/engine/image/FlutterImageDecoder.java
Outdated
Show resolved
Hide resolved
engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/image/Utils.java
Outdated
Show resolved
Hide resolved
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. |
@gmackall - per offline convo I updated to only fallback if the default ImageDecoder call fails. |
gmackall
left a comment
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.
lgtm
...shell/platform/android/io/flutter/embedding/engine/image/FlutterImageDecoderImplDefault.java
Outdated
Show resolved
Hide resolved
...tter/shell/platform/android/io/flutter/embedding/engine/image/ImageDecoderHeifApi36Impl.java
Show resolved
Hide resolved
...tter/shell/platform/android/io/flutter/embedding/engine/image/ImageDecoderHeifPre36Impl.java
Show resolved
Hide resolved
|
@reidbaker - per our offline convo, removed the dep on androidx.exifinterface to try to get this in. Filed #177071 and #177066 as follow-ups. |
|
@mboetger you will still need to ignore the lint that warns you to use androidx |
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
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]>
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.
Fixes: #176407
Pre-launch Checklist
///).