Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
## 0.6.18+3

* Fixes incorrect camera preview mirroring for front cameras of devices using the Impeller backend.

## 0.6.18+2

* Fixes premature garbage collection of native objects when app is under memory pressure.

## 0.6.18+1

* Fixes incorrect camera preview mirroring for front cameras of devices using the `ImageReader` Impeller backend.
* Makes Java style improvements.

## 0.6.18

Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android_camerax/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_android_camerax
description: Android implementation of the camera plugin using the CameraX library.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.6.18+1
version: 0.6.18+3

environment:
sdk: ^3.7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ 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, Transform;
import 'package:flutter/widgets.dart'
show MatrixUtils, RotatedBox, Texture, Transform;
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';

Expand Down Expand Up @@ -380,6 +381,70 @@ void main() {
) =>
'Expected the preview to be rotated by $expectedQuarterTurns quarter turns (which is ${expectedQuarterTurns * 90} degrees clockwise) but instead was rotated $actualQuarterTurns quarter turns.';

/// Checks that the transform matrix (Matrix4) mirrors across the x-axis by
/// confirming the following to be the transformation matrix:
/// [[-1.0, 0.0, 0.0, 0.0],
/// [ 0.0, 1.0, 0.0, 0.0],
/// [ 0.0, 0.0, 1.0, 0.0],
/// [ 0.0, 0.0, 0.0, 1.0]]
void checkXAxisIsMirrored(Matrix4 transformationMatrix) {
final Matrix4 mirrorAcrossXMatrix = Matrix4(
-1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
);

expect(
MatrixUtils.matrixEquals(mirrorAcrossXMatrix, transformationMatrix),
isTrue,
);
}

/// Checks that the transform matrix (Matrix4) mirrors across the y-axis by
/// confirming the following to be the transformation matrix:
/// [[1.0, 0.0, 0.0, 0.0],
/// [ 0.0, -1.0, 0.0, 0.0],
/// [ 0.0, 0.0, 1.0, 0.0],
/// [ 0.0, 0.0, 0.0, 1.0]]
void checkYAxisIsMirrored(Matrix4 transformationMatrix) {
final Matrix4 mirrorAcrossYMatrix = Matrix4(
1.0,
0.0,
0.0,
0.0,
0.0,
-1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
);

expect(
MatrixUtils.matrixEquals(mirrorAcrossYMatrix, transformationMatrix),
isTrue,
);
}

group('when handlesCropAndRotation is true', () {
// Test that preview rotation responds to initial default display rotation:
group('initial device orientation is landscapeRight,', () {
Expand Down Expand Up @@ -1178,7 +1243,7 @@ void main() {

// 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));
checkYAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);
expect(
rotatedBox.quarterTurns,
Expand Down Expand Up @@ -1239,7 +1304,7 @@ void main() {

// 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));
checkXAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);
expect(
rotatedBox.quarterTurns,
Expand Down Expand Up @@ -1300,7 +1365,7 @@ void main() {

// 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));
checkYAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);
expect(
rotatedBox.quarterTurns,
Expand Down Expand Up @@ -1361,7 +1426,7 @@ void main() {

// 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));
checkXAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);
expect(
rotatedBox.quarterTurns,
Expand Down Expand Up @@ -1464,7 +1529,7 @@ void main() {

// 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));
checkXAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);
expect(
rotatedBox.quarterTurns,
Expand Down Expand Up @@ -1525,7 +1590,7 @@ void main() {

// 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));
checkXAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);

final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4;
Expand Down Expand Up @@ -1586,7 +1651,7 @@ void main() {

// 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));
checkXAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);

final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4;
Expand Down Expand Up @@ -1649,7 +1714,7 @@ void main() {

// 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));
checkXAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);

final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4;
Expand Down Expand Up @@ -1770,7 +1835,7 @@ void main() {

// 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));
checkXAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);

final int clockwiseQuarterTurns =
Expand Down Expand Up @@ -1884,9 +1949,9 @@ void main() {
// across the y-axis.
if (currentDeviceOrientation == DeviceOrientation.landscapeLeft ||
currentDeviceOrientation == DeviceOrientation.landscapeRight) {
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
checkXAxisIsMirrored(transformedPreviewMatrix);
} else {
expect(transformedPreviewMatrix.storage[5], closeTo(-1.0, 0.0001));
checkYAxisIsMirrored(transformedPreviewMatrix);
}
expect((transformedPreview.child! as Texture).textureId, cameraId);
final int clockwiseQuarterTurns =
Expand Down Expand Up @@ -2152,7 +2217,7 @@ void main() {

// 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));
checkXAxisIsMirrored(transformedPreviewMatrix);
expect((transformedPreview.child! as Texture).textureId, cameraId);
expect(
rotatedBox.quarterTurns,
Expand Down