Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[image_picker]fix load error when the image is BMP/HEIF/HEIC format #4665

Closed
wants to merge 12 commits into from

Conversation

xiaoxiaowesley
Copy link

@xiaoxiaowesley xiaoxiaowesley commented Jan 13, 2022

This PR attends to fix the image_picker no response error when picking the BMP images greater than iOS 14 in iOS simulator or iOS devices.

The reason why did not respond to the BMP image is that when picking the BMP format image the process step in FLTPHPickerSaveImageToPathOperation.mm will return nil in completionHandler and respond nothing back to dart.

The BMP image in videos is used from https://people.math.sc.edu/Burkardt/data/bmp/bmp_24.bmp in flutter/issues/95885

image

default.mov

This only happens in iOS 14 or greater version.

Also, reference in the flutter repo flutter/flutter#95885

Device info:iPhone13 iOS 15.0

After fix

default.mov

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 relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • 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.
  • 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.

@cyanglaz
Copy link
Contributor

@xiaoxiaowesley Thanks preparing this PR! This PR will need tests to move forward :)

@stuartmorgan
Copy link
Contributor

Thanks for the submission!

In the future, please do not delete the checklist that is in the PR template; it is there for a reason. This PR is missing required elements described in the checklist (I’ve restored it to the PR description), which need to be addressed before it moves forward with review. If you have any questions about completing those steps that aren’t addressed documentation, please let me know.

@stuartmorgan
Copy link
Contributor

It looks like this will collide with #4448, so it would make sense to land that first then re-evaluate here.

@xiaoxiaowesley
Copy link
Author

Thanks for the submission!

In the future, please do not delete the checklist that is in the PR template; it is there for a reason. This PR is missing required elements described in the checklist (I’ve restored it to the PR description), which need to be addressed before it moves forward with review. If you have any questions about completing those steps that aren’t addressed documentation, please let me know.

OK. This is my first PR to Plugins.No quite sure about the rule. Thank you for letting me know.

@xiaoxiaowesley xiaoxiaowesley changed the title fix load error when the image is BMP format [image_picker]fix load error when the image is BMP format Jan 14, 2022
@xiaoxiaowesley
Copy link
Author

It looks like this will collide with #4448, so it would make sense to land that first then re-evaluate here.
YES. It would conflict with it. And I will wait for #4448

@stuartmorgan
Copy link
Contributor

Status from PR review: Still blocked on #4448, but that one is close.

@stuartmorgan
Copy link
Contributor

#4448 has landed, so you can update this against the latest trunk and address the remaining items in the PR checklist, then we can review.

@xiaoxiaowesley
Copy link
Author

#4448 has landed, so you can update this against the latest trunk and address the remaining items in the PR checklist, then we can review.

Great.On my way

@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 (don't just cc him here, he won't see it! He's on Discord!).

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.

@xiaoxiaowesley xiaoxiaowesley changed the title [image_picker]fix load error when the image is BMP format [image_picker]fix load error when the image is BMP/HEIF/HEIC format Mar 11, 2022
@xiaoxiaowesley
Copy link
Author

#4448 has landed, so you can update this against the latest trunk and address the remaining items in the PR checklist, then we can review.

@stuartmorgan hi, I had added tests, and the checks all passed but remain one failed.
The failed check showed
android-platform_tests CHANNEL:master PLUGIN_SHARDING:--shardIndex 4 --shardCount 5: completed (failure)
I just modified iOS code, why show Android test failed? iI will be very happy if you can help me .

@stuartmorgan
Copy link
Contributor

submit-queue is the live tree status; it's unrelated to your PR.

@xiaoxiaowesley
Copy link
Author

@cyanglaz hi, It seems no problem now. Would you help me to review it?

Comment on lines 104 to 154
if (error == nil) {
__block UIImage *localImage =
[[UIImage alloc] initWithData:data];
PHAsset *originalAsset = [FLTImagePickerPhotoAssetUtil
getAssetFromPHPickerResult:self.result];

if (self.maxWidth != (id)[NSNull null] ||
self.maxHeight != (id)[NSNull null]) {
localImage = [FLTImagePickerImageUtil
scaledImage:localImage
maxWidth:self.maxWidth
maxHeight:self.maxHeight
isMetadataAvailable:originalAsset != nil];
}
__block NSString *savedPath;
if (!originalAsset) {
// Image picked without an original asset (e.g. User pick
// image without permission)
savedPath = [FLTImagePickerPhotoAssetUtil
saveImageWithPickerInfo:nil
image:localImage
imageQuality:self.desiredImageQuality];
[self completeOperationWithPath:savedPath];
} else {
[[PHImageManager defaultManager]
requestImageDataForAsset:originalAsset
options:nil
resultHandler:^(
NSData *_Nullable imageData,
NSString *_Nullable dataUTI,
UIImageOrientation orientation,
NSDictionary *_Nullable info) {
// maxWidth and maxHeight are used only for
// GIF images.
savedPath = [FLTImagePickerPhotoAssetUtil
saveImageWithOriginalImageData:
imageData
image:
localImage
maxWidth:
self.maxWidth
maxHeight:
self.maxHeight
imageQuality:
self.desiredImageQuality];
[self completeOperationWithPath:savedPath];
}];
}
} else {
[self completeOperationWithPath:nil];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be replaced wtih [self processImage:image];?

Copy link
Author

Choose a reason for hiding this comment

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

ok。I modified it.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

LGTM % nits.
@stuartmorgan as a second reviewer.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

You'll need to update this for the federation of the iOS implementation, but it should be straightforward; all the changes just need to be to image_picker_ios instead.


## 0.8.4+12

* iOS:support images with heic,heif,raw,tiff formats.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* iOS:support images with heic,heif,raw,tiff formats.
* Adds support for HEIC, HEIF, RAW, and TIFF formats on iOS.

@@ -4,8 +4,8 @@

#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#import <UniformTypeIdentifiers/UTCoreTypes.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a blank line after it; they are different import sections.

#import "FLTPHPickerSaveImageToPathOperation.h"

Copy link
Contributor

Choose a reason for hiding this comment

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

Please undo this change.

UTTypeHEIC.identifier,
UTTypeJPEG.identifier,
UTTypeWebP.identifier,
UTTypeGIF.identifier,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we changing the codepath for types that already worked? Is this a preferred API?

[self processImage:image];
}];
return;
NSArray *supportedRepresentations = @[
Copy link
Contributor

Choose a reason for hiding this comment

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

"Supported" seems misleading here; this isn't an exhaustive list since there's the other codepath as well. What is distinct about these vs other types that makes them need to use a different code path (so that we can name the list accordingly)?

@stuartmorgan
Copy link
Contributor

Are you still planning on updating this PR to address the review comments above?

@stuartmorgan
Copy link
Contributor

Thank you for your contribution. I'm going to close this PR for now since there are outstanding comments, just to get this off our PR review queue. Please don't hesitate to submit a new PR if you have the time to address the review comments. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants