You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[camera_android_x] Refactor ImageProxyUtils.planesToNV21 to prevent buffer issues (#10163)
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 matches `NV21`.
Fixesflutter/flutter#176410
## Pre-Review Checklist
**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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.
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Copy file name to clipboardExpand all lines: packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageProxyUtils.java
+66-41Lines changed: 66 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -18,55 +18,80 @@ public class ImageProxyUtils {
Copy file name to clipboardExpand all lines: packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ImageProxyUtilsTest.java
+59-5Lines changed: 59 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,13 @@
5
5
packageio.flutter.plugins.camerax;
6
6
7
7
importstaticorg.junit.Assert.assertArrayEquals;
8
+
importstaticorg.junit.Assert.assertEquals;
8
9
importstaticorg.junit.Assert.assertThrows;
10
+
importstaticorg.mockito.Mockito.mock;
11
+
importstaticorg.mockito.Mockito.when;
9
12
10
13
importandroidx.camera.core.ImageProxy.PlaneProxy;
14
+
importjava.nio.BufferUnderflowException;
11
15
importjava.nio.ByteBuffer;
12
16
importjava.util.Arrays;
13
17
importjava.util.List;
@@ -35,18 +39,19 @@ public void planesToNV21_throwsExceptionForNonNV21Layout() {
0 commit comments