Skip to content

[Impeller] Keep the aspect ratio when shrinking images to the max texture size - #194010

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
santoshakil:fix-impeller-image-aspect-ratio
Oct 13, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:masterfrom
santoshakil:fix-impeller-image-aspect-ratio

Conversation

@santoshakil

@santoshakil santoshakil commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Impeller clamps each side of a decoded image to the max texture size on its own, so an image bigger than the limit on one side gets squished. A 1000x50000 image on a device with a 16384 limit comes out 1000x16384. This shrinks both sides by the same factor instead, so it comes out 328x16384 and keeps its shape. The image attached to #177239 (6984x32975) comes out 6984x16384 today and 3470x16384 with this change.

We hit this in immich when the original of a long image loads (immich-app/immich#11987, immich-app/immich#31690). For now we cap the decode size in the app (immich-app/immich#29367), but every app that shows big images needs the same workaround.

The existing VerifySimpleDecoding case expected the squish (a 60x20 target with a 10x10 limit came back 10x10), so it now expects 10x3, and a tall case (20x60, expects 3x10) is added.

Before and after on a Pixel 7 (Vulkan, 32768 limit) with a 1000x50000 image of circles:

case1-A-vs-B

Fixes #177239

Pre-launch Checklist

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

@github-actions github-actions Bot added the engine flutter/engine related. See also e: labels. label Oct 8, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the image decoding logic in Impeller to preserve the aspect ratio when scaling down images that exceed the maximum texture size, and adds corresponding unit tests. The review feedback points out a potential narrowing conversion from long to int when using std::lround and 1L with SkISize::Make, suggesting an explicit cast to int and using 1 to prevent compiler warnings.

@gaaclarke
gaaclarke requested a review from b-luk October 12, 2026 21:45
@gaaclarke gaaclarke added the CICD Run CI/CD label Oct 12, 2026

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm! thanks for the contribution

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 12, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 13, 2026
@auto-submit

auto-submit Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/194010, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@santoshakil

Copy link
Copy Markdown
Contributor Author

@gaaclarke thanks for the review! google testing failed even after the rerun and autosubmit got removed. i cant see the internal results, can you please check if its this change or a flake?

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 13, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Oct 13, 2026
Merged via the queue into flutter:master with commit 264ca2c Oct 13, 2026
38 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 13, 2026
@santoshakil
santoshakil deleted the fix-impeller-image-aspect-ratio branch October 14, 2026 12:14
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Oct 14, 2026
Roll Flutter from 4249ccbc18a3 to 426be968b5eb (44 revisions)

flutter/flutter@4249ccb...426be96

2026-10-14 [email protected] Allow color delta tolerance in in-memory fuzzy image comparator (flutter/flutter#193937)
2026-10-14 [email protected] [web] Drop stale composing range after text is replaced mid-composition (flutter/flutter#194096)
2026-10-14 [email protected] Roll Skia from 2a2bbea66844 to acde3755d2e2 (1 revision) (flutter/flutter#194376)
2026-10-14 [email protected] Roll Skia from 128c983b12de to 2a2bbea66844 (1 revision) (flutter/flutter#194371)
2026-10-14 [email protected] Roll Skia from 48a294ed4955 to 128c983b12de (3 revisions) (flutter/flutter#194353)
2026-10-14 [email protected] feat(flutter_tools): extract WebDebugConfig from DebuggingOptions (flutter/flutter#194312)
2026-10-14 [email protected] Roll Skia from ea6781c5b6d1 to 48a294ed4955 (2 revisions) (flutter/flutter#194349)
2026-10-14 [email protected] Include <vector> in Android proc_table.h. (flutter/flutter#194325)
2026-10-14 [email protected] Roll Dart SDK from 5933cb486b4a to 6b50116630d0 (28 revisions) (flutter/flutter#194341)
2026-10-14 [email protected] Move GLES3 instancing API entry points to FOR_EACH_IMPELLER_GLES3_PROC (flutter/flutter#194319)
2026-10-14 [email protected] feat(flutter_tools): extract AndroidGradleConfig and move toGradleConfig to AndroidBuildInfo (flutter/flutter#194016)
2026-10-14 [email protected] Roll Skia from ae297bec6012 to ea6781c5b6d1 (8 revisions) (flutter/flutter#194331)
2026-10-14 [email protected] [flutter_tools] Migrate gradle_errors and deferred_components_prebuild_validator away from globals (flutter/flutter#193649)
2026-10-14 [email protected] [Impeller] Cache GLES sampler configuration in RenderPassStateCache (flutter/flutter#193922)
2026-10-14 [email protected] Roll pub packages (flutter/flutter#194332)
2026-10-13 [email protected] [tool] Migrate RunCommand to modular dependency injection (flutter/flutter#190791)
2026-10-13 [email protected] Include `engine/src/flutter/.ci.yaml` in quarterly `goldctl` checklist (flutter/flutter#194316)
2026-10-13 [email protected] [flutter_tools] Remove the last AMD module system support (flutter/flutter#193607)
2026-10-13 [email protected] Roll Skia from 8b3394a60654 to ae297bec6012 (5 revisions) (flutter/flutter#194310)
2026-10-13 [email protected] [web] Remove the a11y placeholder only after the gesture ends (flutter/flutter#194109)
2026-10-13 [email protected] Upgrade goldctl to the latest version (flutter/flutter#193932)
2026-10-13 [email protected] [flutter_tools] Lazily initialize AndroidStudio validation and optimize candidate selection (flutter/flutter#191968)
2026-10-13 [email protected] [flutter_tools] Clean up outdated widget preview TODOs and refactor static state (flutter/flutter#189437)
2026-10-13 [email protected] Roll Skia from e5b5db6d0d6f to 8b3394a60654 (2 revisions) (flutter/flutter#194306)
2026-10-13 [email protected] Redistribute TESTOWNERS for Android team (flutter/flutter#193861)
2026-10-13 [email protected] feat(flutter_tools): introduce Test and Drive specification objects (flutter/flutter#194017)
2026-10-13 [email protected] [Impeller] Keep the aspect ratio when shrinking images to the max texture size (flutter/flutter#194010)
2026-10-13 [email protected] [flutter tool] preserve inherited `DASH__SUPPRESS_ANALYTICS=true` for sub-tools (flutter/flutter#194261)
2026-10-13 [email protected] Roll Packages from d8d9e97 to a1ed23c (9 revisions) (flutter/flutter#194302)
2026-10-13 [email protected] Use PE/COFF AOT snapshots for Windows x64 (flutter/flutter#187594)
2026-10-13 [email protected] Fix Expansible crash when PageStorage holds a non-bool value (flutter/flutter#192195)
2026-10-13 [email protected] Roll Skia from ffeccb3ca58a to e5b5db6d0d6f (1 revision) (flutter/flutter#194297)
2026-10-13 [email protected] Explain why initState() is too early to depend on an inherited widget (flutter/flutter#192727)
2026-10-13 [email protected] Refactor TestPlatformDispatcher (flutter/flutter#192747)
2026-10-13 [email protected] Roll Skia from 3de0984208ec to ffeccb3ca58a (2 revisions) (flutter/flutter#194291)
2026-10-13 [email protected] Roll Skia from 0580c2b780f6 to 3de0984208ec (2 revisions) (flutter/flutter#194281)
2026-10-13 [email protected] Roll Skia from f641d55e07a8 to 0580c2b780f6 (3 revisions) (flutter/flutter#194275)
2026-10-13 [email protected] Roll Skia from 0e5d8d1be81b to f641d55e07a8 (1 revision) (flutter/flutter#194266)
2026-10-13 [email protected] Scaffold view metrics overrides (flutter/flutter#192764)
2026-10-13 [email protected] [web] Add SemanticsRole.listBox and SemanticsRole.option (flutter/flutter#192971)
2026-10-13 [email protected] Pin mac_unopt to macOS 15 (flutter/flutter#194254)
2026-10-13 [email protected] Roll pub packages (flutter/flutter#194257)
2026-10-12 [email protected] Roll Skia from 17f6986c226c to 0e5d8d1be81b (4 revisions) (flutter/flutter#194249)
2026-10-12 [email protected] Make DisplayLists' use of DlPaint, SkPaint, and impeller::Paint agree on the default isAntiAlias (flutter/flutter#193939)

If this roll has caused a breakage, revert this CL and set the roller
...
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
…ture size (flutter#194010)

Impeller clamps each side of a decoded image to the max texture size on
its own, so an image bigger than the limit on one side gets squished. A
1000x50000 image on a device with a 16384 limit comes out 1000x16384.
This shrinks both sides by the same factor instead, so it comes out
328x16384 and keeps its shape. The image attached to flutter#177239
(6984x32975) comes out 6984x16384 today and 3470x16384 with this change.

We hit this in immich when the original of a long image loads
(immich-app/immich#11987, immich-app/immich#31690). For now we cap the
decode size in the app (immich-app/immich#29367), but every app that
shows big images needs the same workaround.

The existing `VerifySimpleDecoding` case expected the squish (a 60x20
target with a 10x10 limit came back 10x10), so it now expects 10x3, and
a tall case (20x60, expects 3x10) is added.

Before and after on a Pixel 7 (Vulkan, 32768 limit) with a 1000x50000
image of circles:

<img width="1128" height="2254" alt="case1-A-vs-B"
src="https://github.com/user-attachments/assets/4eabb7ee-7dc2-4a65-a50f-fc1b5a597be4"
/>

Fixes flutter#177239

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [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 in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [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.

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Impeller] In Image.xxx(), if the image is very high, the image will be squeezed and flattened vertically.

3 participants