Skip to content

[android_camera_camerax] Fix incorrect camera mirroring for front cameras on devices using ImageReader Impeller backend #9233

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

camsim99
Copy link
Contributor

@camsim99 camsim99 commented May 9, 2025

Fixes the incorrect camera mirroring when the front camera is used on devices that use the ImageReader Impeller backend. TLDR: for relevant rotated preview implementation, when the front camera is used, mirror the camera preview across the y-axis when the device is in a portrait orientation or across the x-axis when the device is in a landscape orientation.

Fixes flutter/flutter#156974.

cc @jesswrd, co-author of this PR

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  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. 2 3

@jesswrd jesswrd marked this pull request as draft May 9, 2025 19:36
@jesswrd jesswrd changed the title [android_camera_camerax] Fix incorrect camera mirroring for front cameras on devices using ImageReader Impeller backend [WIP] [android_camera_camerax] Fix incorrect camera mirroring for front cameras on devices using ImageReader Impeller backend May 9, 2025
@jesswrd jesswrd changed the title [WIP] [android_camera_camerax] Fix incorrect camera mirroring for front cameras on devices using ImageReader Impeller backend [android_camera_camerax] Fix incorrect camera mirroring for front cameras on devices using ImageReader Impeller backend Jun 2, 2025
@camsim99 camsim99 marked this pull request as ready for review June 2, 2025 22:36
Copy link
Contributor Author

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

These look great, thank you! Just added some suggestions for clarity in case someone has to revisit this later :)


// Since the front camera is in portrait mode, we expect the camera
// preview to be mirrored across the y-axis.
expect(transformedPreviewMatrix.storage[5], closeTo(-1.0, 0.0001));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about creating a helper method for these sorts of checks? Something like checkYAxisIsMirrored(double matrixArg5) and checkXAxisIsMirrored(double matrixArg0) with docs for both explaining why this checks what we think? I think this may help for clarity in the future.


// Since the front camera is in landscape mode, we expect the camera
// preview to be mirrored across the x-axis.
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume the closeTo is because a precision error? If there's no workaround for that, can you add a comment here (or to the helper methods if you're open to adding them) about that?

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

Successfully merging this pull request may close these issues.

Camera preview for front camera is flipped post ImageReader updates
2 participants