-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[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
camsim99
wants to merge
6
commits into
flutter:main
Choose a base branch
from
camsim99:camx_mirror_2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import 'package:camera_android_camerax/src/camerax_library.dart'; | |
import 'package:camera_android_camerax/src/camerax_proxy.dart'; | ||
import 'package:camera_platform_interface/camera_platform_interface.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter/widgets.dart' show RotatedBox, Texture; | ||
import 'package:flutter/widgets.dart' show RotatedBox, Texture, Transform; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
|
@@ -1167,8 +1167,19 @@ void main() { | |
find.byType(RotatedBox), | ||
); | ||
|
||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = | ||
transformedPreview.transform; | ||
|
||
// 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)); | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
expect( | ||
rotatedBox.quarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -1216,8 +1227,20 @@ void main() { | |
final RotatedBox rotatedBox = tester.widget<RotatedBox>( | ||
find.byType(RotatedBox), | ||
); | ||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
|
||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = | ||
transformedPreview.transform; | ||
|
||
// 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the |
||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
expect( | ||
rotatedBox.quarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -1265,8 +1288,20 @@ void main() { | |
final RotatedBox rotatedBox = tester.widget<RotatedBox>( | ||
find.byType(RotatedBox), | ||
); | ||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
|
||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = | ||
transformedPreview.transform; | ||
|
||
// 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)); | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
expect( | ||
rotatedBox.quarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -1314,8 +1349,20 @@ void main() { | |
final RotatedBox rotatedBox = tester.widget<RotatedBox>( | ||
find.byType(RotatedBox), | ||
); | ||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
|
||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = | ||
transformedPreview.transform; | ||
|
||
// 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)); | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
expect( | ||
rotatedBox.quarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -1406,8 +1453,19 @@ void main() { | |
find.byType(RotatedBox), | ||
); | ||
|
||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = | ||
transformedPreview.transform; | ||
|
||
// 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)); | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
expect( | ||
rotatedBox.quarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -1455,9 +1513,22 @@ void main() { | |
final RotatedBox rotatedBox = tester.widget<RotatedBox>( | ||
find.byType(RotatedBox), | ||
); | ||
|
||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = | ||
transformedPreview.transform; | ||
|
||
// 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)); | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
|
||
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4; | ||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
expect( | ||
clockwiseQuarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -1503,9 +1574,22 @@ void main() { | |
final RotatedBox rotatedBox = tester.widget<RotatedBox>( | ||
find.byType(RotatedBox), | ||
); | ||
|
||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = | ||
transformedPreview.transform; | ||
|
||
// 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)); | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
|
||
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4; | ||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
expect( | ||
clockwiseQuarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -1553,9 +1637,22 @@ void main() { | |
final RotatedBox rotatedBox = tester.widget<RotatedBox>( | ||
find.byType(RotatedBox), | ||
); | ||
|
||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = | ||
transformedPreview.transform; | ||
|
||
// 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)); | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
|
||
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4; | ||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
expect( | ||
clockwiseQuarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -1662,12 +1759,24 @@ void main() { | |
final RotatedBox rotatedBox = tester.widget<RotatedBox>( | ||
find.byType(RotatedBox), | ||
); | ||
|
||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = transformedPreview.transform; | ||
|
||
// 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)); | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
|
||
final int clockwiseQuarterTurns = | ||
rotatedBox.quarterTurns < 0 | ||
? rotatedBox.quarterTurns + 4 | ||
: rotatedBox.quarterTurns; | ||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
expect( | ||
clockwiseQuarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -1760,12 +1869,30 @@ void main() { | |
final RotatedBox rotatedBox = tester.widget<RotatedBox>( | ||
find.byType(RotatedBox), | ||
); | ||
|
||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = transformedPreview.transform; | ||
|
||
// When the front camera is in landscape mode, we expect the camera | ||
// preview to be mirrored across the x-axis. When the front camera | ||
// is in portrait mode, we expect the camera preview to be mirrored | ||
// across the y-axis. | ||
if (currentDeviceOrientation == DeviceOrientation.landscapeLeft || | ||
currentDeviceOrientation == DeviceOrientation.landscapeRight) { | ||
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001)); | ||
} else { | ||
expect(transformedPreviewMatrix.storage[5], closeTo(-1.0, 0.0001)); | ||
} | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
final int clockwiseQuarterTurns = | ||
rotatedBox.quarterTurns < 0 | ||
? rotatedBox.quarterTurns + 4 | ||
: rotatedBox.quarterTurns; | ||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
expect( | ||
clockwiseQuarterTurns, | ||
expectedQuarterTurns, | ||
|
@@ -2013,8 +2140,20 @@ void main() { | |
final RotatedBox rotatedBox = tester.widget<RotatedBox>( | ||
find.byType(RotatedBox), | ||
); | ||
expect(rotatedBox.child, isA<Texture>()); | ||
expect((rotatedBox.child! as Texture).textureId, cameraId); | ||
|
||
// We expect a Transform widget to wrap the RotatedBox with the camera | ||
// preview to mirror the preview, since the front camera is being | ||
// used. | ||
expect(rotatedBox.child, isA<Transform>()); | ||
|
||
final Transform transformedPreview = rotatedBox.child! as Transform; | ||
final Matrix4 transformedPreviewMatrix = | ||
transformedPreview.transform; | ||
|
||
// 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)); | ||
expect((transformedPreview.child! as Texture).textureId, cameraId); | ||
expect( | ||
rotatedBox.quarterTurns, | ||
expectedQuarterTurns, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What do you think about creating a helper method for these sorts of checks? Something like
checkYAxisIsMirrored(double matrixArg5)
andcheckXAxisIsMirrored(double matrixArg0)
with docs for both explaining why this checks what we think? I think this may help for clarity in the future.