fix: Add support for YUV_420_888 Image format.#732
fix: Add support for YUV_420_888 Image format.#732panmari wants to merge 1 commit intoflutter-ml:developfrom
Conversation
|
There's still the open issue of cleaning up the texture. I'd appreciate some feedback on how to change the API accordingly. I don't think there's a way around that. |
|
If you allow me, I will share with you the method I used to solve a similar problem. Maybe it can help: |
|
I fixed the resource leak by making @wantroba thanks for providing an alternative solution! I feel it targets a slightly different use case (saving to file) as the one I target here (using as ML-Kit input). |
| } | ||
| if (imageFormat == ImageFormat.YUV_420_888) { | ||
| // This image format is only supported in InputImage.fromMediaImage, which requires to transform the data to the right java type. | ||
| // TODO: Consider reusing the same Surface across multiple calls to save on allocations. |
There was a problem hiding this comment.
Reusing this ImageWriter across multiple calls, thus avoiding the allocation, would make this likely more performant. Could any of the reviewers take a look?
Is it something that could be left as a TODO and fixed later?
|
May I ask what was the reason for closing this PR? It did add an additional feature, which allows clients to move to the better supported |
|
my mistake, could you resolve the conflicts. |
|
could you resolve the conflicts |
|
@panmari It would be great if you could resolve the conflicts. That would be great. |
Casting the bytes to a type directly is not possible, thus allocating a new texture is necessary (and costly). But on the bright side, we avoid the conversion inside the camera plugin [0]. Or any other custom conversion code in dart, which is likely more costly. [0] https://github.com/flutter/packages/blob/d1fd6232ec33cd5a25aa762e605c494afced812f/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/ImageStreamReaderUtils.java#L35
|
Rebased and resolved conflicts. The caveat that the conversion code is expensive still applies. |
|
@fbernaly this is ready for review. |
|
Is there any movement on this, we have production issues that we need to resolve and waiting another month... would not be nice. |
|
If you're consuming images directly from the camera package, there's always the option to the alternative implementation to consume the supported image format, see |
Casting the bytes to a type directly is not possible, thus allocating a new texture is necessary (and costly).
But on the bright side, we avoid the conversion inside the camera plugin [0].
[0] https://github.com/flutter/packages/blob/d1fd6232ec33cd5a25aa762e605c494afced812f/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/media/ImageStreamReaderUtils.java#L35