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

Replace deprecated UIGraphicsBeginImageContextWithOptions with UIGraphicsImageRenderer #6285

Merged
merged 2 commits into from
Mar 13, 2024

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented Mar 8, 2024

UIGraphicsBeginImageContextWithOptions isn't technically deprecated, but API_TO_BE_DEPRECATED. However, according to reports it's crashing in iOS 17. Replace usage with UIGraphicsImageRenderer, available in iOS 10.

I kept introducing horizontal flipping bugs when I was writing this, but it wasn't causing test failures. Changed the test images from a single color to a gradient with different colors in each corner, then updated the tests to confirm the orientation is still correct.

Generated the test image with ImageMagick:

magick \( xc:red xc:blue +append \) \( xc:yellow xc:cyan +append \) -append -filter triangle -resize 12x7\! jpgImage.jpg

Also avoid doing extra work if there's nothing to scale, and return the original image.

Fixes flutter/flutter#144602

Comment on lines +54 to +59
if ((originalWidth == maxWidth.doubleValue && originalHeight == maxHeight.doubleValue) ||
(!hasMaxWidth && !hasMaxHeight)) {
// Nothing to scale.
return image;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This code is new, and unrelated to the fix. If there is nothing to scale, return the original image instead of doing extra work.

@jmagman jmagman marked this pull request as ready for review March 11, 2024 19:00
@jmagman jmagman requested a review from vashworth as a code owner March 11, 2024 19:00
XCTAssertEqual(scaledImage.size.height, scaledHeight);

// Check the corners. Format is "R G B A"
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, 0, 0), @"1 0.776471 0 1"); // yellow
Copy link
Contributor

@vashworth vashworth Mar 12, 2024

Choose a reason for hiding this comment

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

Nit: How about making these color string representations (e.g. @"1 0.776471 0 1") consts with descriptive names so they can be reused and seem less like a magic value?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can do that for the two tests that are the same. These exact values would changes based on how small the image is scaled.

Copy link
Contributor

@vashworth vashworth 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 a small suggestion

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 12, 2024
@auto-submit auto-submit bot merged commit 131033e into flutter:main Mar 13, 2024
78 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 14, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 14, 2024
flutter/packages@38711ac...b21c542

2024-03-14 [email protected] Support overriding `ErrorWidget.builder` (flutter/packages#6302)
2024-03-13 [email protected] Manual roll Flutter from 61812ca to 394269f (6 revisions) (flutter/packages#6320)
2024-03-13 49699333+dependabot[bot]@users.noreply.github.com Bump actions/checkout from 4.1.1 to 4.1.2 (flutter/packages#6309)
2024-03-13 [email protected] Replace deprecated UIGraphicsBeginImageContextWithOptions with UIGraphicsImageRenderer (flutter/packages#6285)
2024-03-13 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.24.6 to 3.24.7 (flutter/packages#6310)

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-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: 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
@jmagman jmagman deleted the image-context branch March 20, 2024 20:25
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…hicsImageRenderer (flutter#6285)

`UIGraphicsBeginImageContextWithOptions` isn't technically deprecated, but `API_TO_BE_DEPRECATED`.  However, according to reports it's crashing in iOS 17.  Replace usage with `UIGraphicsImageRenderer`, available in iOS 10.

I kept introducing horizontal flipping bugs when I was writing this, but it wasn't causing test failures.  Changed the test images from a single color to a gradient with different colors in each corner, then updated the tests to confirm the orientation is still correct.

Generated the test image with ImageMagick:
```
magick \( xc:red xc:blue +append \) \( xc:yellow xc:cyan +append \) -append -filter triangle -resize 12x7\! jpgImage.jpg
```

Also avoid doing extra work if there's nothing to scale, and return the original image.

Fixes flutter/flutter#144602
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: image_picker platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FLTImagePickerImageUtil crash: UIGraphicsBeginImageContext() failed to allocate CGBitampContext
2 participants