-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[camera_android_x] Refactor ImageProxyUtils.planesToNV21 to prevent buffer issues #10163
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
base: main
Are you sure you want to change the base?
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. |
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.Invoking GeminiYou can request assistance from Gemini at any point by creating a comment using either `/gemini ` or `@gemini-code-assist `. Below is a summary of the supported commands on the current page.Feature | Command | Description--- | --- | ---CustomizationTo customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).Limitations & FeedbackGemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG). |
…ve UV plane mocking
|
||
List<PlaneProxy> planes = Arrays.asList(yPlane, uPlane, vPlane); | ||
|
||
ByteBuffer nv21Buffer = ImageProxyUtils.planesToNV21(planes, width, height); |
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.
1280x720 → ~4.6 ms per frame. Further evaluation is needed to assess the impact on the processing pipeline.
@Mairramer two things -- First, can you possibly update to the PR description to describe how you came to these changes? I'm not an expert in the conversion so it would help me review this PR. Second, I assumed the fix would be using this logic I left out initially: Thoughts on that versus your approach? |
While this approach is valid, it still encounters the same issue when checking areUVPlanesNV21(). My implementation essentially replicates part of the unpackPlane() logic, avoiding assumptions about the U/V buffer layout and ensuring a deterministic NV21 output. Additionally, it leverages CameraX’s internal ImageUtil Both approaches perform a complete manual reconstruction of the image, guaranteeing correctness regardless of how the U/V planes are arranged. I am still investigating why position == limit occurs in some CameraX buffers. Understanding this behavior could help refine the reconstruction logic. |
My only concern is the per-frame processing time. |
This change replaces the previous
planesToNV21()
implementation with a direct and stride-aware conversion.The prior version assumed that the U and V planes followed the same layout used by Camera2, which is not always true for CameraX. This assumption could cause color distortion or corrupted frames because CameraX applies internal transformations (rotation, cropping, or proxy wrapping) that modify rowStride, pixelStride, and overall buffer layout.
After investigating inconsistencies between the original
areUVPlanesNV21()
-based logic and the actual ImageProxy buffers returned by CameraX, this version explicitly reconstructs NV21 by reading each plane row by row while respecting their individual strides, rather than simply validating whether the format already matchesNV21
.Fixes flutter/flutter#176410
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assist
bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3