@@ -7,7 +7,7 @@ import 'package:camera_android_camerax/src/camerax_library.dart';
7
7
import 'package:camera_android_camerax/src/camerax_proxy.dart' ;
8
8
import 'package:camera_platform_interface/camera_platform_interface.dart' ;
9
9
import 'package:flutter/services.dart' ;
10
- import 'package:flutter/widgets.dart' show RotatedBox, Texture, Transform;
10
+ import 'package:flutter/widgets.dart' show MatrixUtils, RotatedBox, Texture, Transform;
11
11
import 'package:flutter_test/flutter_test.dart' ;
12
12
import 'package:mockito/mockito.dart' ;
13
13
@@ -380,6 +380,40 @@ void main() {
380
380
) =>
381
381
'Expected the preview to be rotated by $expectedQuarterTurns quarter turns (which is ${expectedQuarterTurns * 90 } degrees clockwise) but instead was rotated $actualQuarterTurns quarter turns.' ;
382
382
383
+ /// Checks that the transform matrix (Matrix4) mirrors across the x-axis by
384
+ /// confirming the following to be the transformation matrix:
385
+ /// [[-1.0, 0.0, 0.0, 0.0] ,
386
+ /// [ 0.0, 1.0, 0.0, 0.0] ,
387
+ /// [ 0.0, 0.0, 1.0, 0.0] ,
388
+ /// [ 0.0, 0.0, 0.0, 1.0] ]
389
+ void checkXAxisIsMirrored (Matrix4 transformationMatrix) {
390
+ final Matrix4 mirrorAcrossXMatrix = Matrix4 (
391
+ - 1.0 , 0.0 , 0.0 , 0.0 ,
392
+ 0.0 , 1.0 , 0.0 , 0.0 ,
393
+ 0.0 , 0.0 , 1.0 , 0.0 ,
394
+ 0.0 , 0.0 , 0.0 , 1.0
395
+ );
396
+
397
+ expect (MatrixUtils .matrixEquals (mirrorAcrossXMatrix, transformationMatrix), isTrue);
398
+ }
399
+
400
+ /// Checks that the transform matrix (Matrix4) mirrors across the y-axis by
401
+ /// confirming the following to be the transformation matrix:
402
+ /// [[1.0, 0.0, 0.0, 0.0] ,
403
+ /// [ 0.0, -1.0, 0.0, 0.0] ,
404
+ /// [ 0.0, 0.0, 1.0, 0.0] ,
405
+ /// [ 0.0, 0.0, 0.0, 1.0] ]
406
+ void checkYAxisIsMirrored (Matrix4 transformationMatrix) {
407
+ final Matrix4 mirrorAcrossYMatrix = Matrix4 (
408
+ 1.0 , 0.0 , 0.0 , 0.0 ,
409
+ 0.0 , - 1.0 , 0.0 , 0.0 ,
410
+ 0.0 , 0.0 , 1.0 , 0.0 ,
411
+ 0.0 , 0.0 , 0.0 , 1.0
412
+ );
413
+
414
+ expect (MatrixUtils .matrixEquals (mirrorAcrossYMatrix, transformationMatrix), isTrue);
415
+ }
416
+
383
417
group ('when handlesCropAndRotation is true' , () {
384
418
// Test that preview rotation responds to initial default display rotation:
385
419
group ('initial device orientation is landscapeRight,' , () {
@@ -1178,7 +1212,7 @@ void main() {
1178
1212
1179
1213
// Since the front camera is in portrait mode, we expect the camera
1180
1214
// preview to be mirrored across the y-axis.
1181
- expect (transformedPreviewMatrix.storage[ 5 ], closeTo ( - 1.0 , 0.0001 ) );
1215
+ checkYAxisIsMirrored (transformedPreviewMatrix);
1182
1216
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1183
1217
expect (
1184
1218
rotatedBox.quarterTurns,
@@ -1239,7 +1273,7 @@ void main() {
1239
1273
1240
1274
// Since the front camera is in landscape mode, we expect the camera
1241
1275
// preview to be mirrored across the x-axis.
1242
- expect (transformedPreviewMatrix.storage[ 0 ], closeTo ( - 1.0 , 0.0001 ) );
1276
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1243
1277
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1244
1278
expect (
1245
1279
rotatedBox.quarterTurns,
@@ -1300,7 +1334,7 @@ void main() {
1300
1334
1301
1335
// Since the front camera is in portrait mode, we expect the camera
1302
1336
// preview to be mirrored across the y-axis.
1303
- expect (transformedPreviewMatrix.storage[ 5 ], closeTo ( - 1.0 , 0.0001 ) );
1337
+ checkYAxisIsMirrored (transformedPreviewMatrix);
1304
1338
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1305
1339
expect (
1306
1340
rotatedBox.quarterTurns,
@@ -1361,7 +1395,7 @@ void main() {
1361
1395
1362
1396
// Since the front camera is in landscape mode, we expect the camera
1363
1397
// preview to be mirrored across the x-axis.
1364
- expect (transformedPreviewMatrix.storage[ 0 ], closeTo ( - 1.0 , 0.0001 ) );
1398
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1365
1399
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1366
1400
expect (
1367
1401
rotatedBox.quarterTurns,
@@ -1464,7 +1498,7 @@ void main() {
1464
1498
1465
1499
// Since the front camera is in landscape mode, we expect the camera
1466
1500
// preview to be mirrored across the x-axis.
1467
- expect (transformedPreviewMatrix.storage[ 0 ], closeTo ( - 1.0 , 0.0001 ) );
1501
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1468
1502
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1469
1503
expect (
1470
1504
rotatedBox.quarterTurns,
@@ -1525,7 +1559,7 @@ void main() {
1525
1559
1526
1560
// Since the front camera is in landscape mode, we expect the camera
1527
1561
// preview to be mirrored across the x-axis.
1528
- expect (transformedPreviewMatrix.storage[ 0 ], closeTo ( - 1.0 , 0.0001 ) );
1562
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1529
1563
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1530
1564
1531
1565
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4 ;
@@ -1586,7 +1620,7 @@ void main() {
1586
1620
1587
1621
// Since the front camera is in landscape mode, we expect the camera
1588
1622
// preview to be mirrored across the x-axis.
1589
- expect (transformedPreviewMatrix.storage[ 0 ], closeTo ( - 1.0 , 0.0001 ) );
1623
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1590
1624
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1591
1625
1592
1626
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4 ;
@@ -1649,7 +1683,7 @@ void main() {
1649
1683
1650
1684
// Since the front camera is in landscape mode, we expect the camera
1651
1685
// preview to be mirrored across the x-axis.
1652
- expect (transformedPreviewMatrix.storage[ 0 ], closeTo ( - 1.0 , 0.0001 ) );
1686
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1653
1687
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1654
1688
1655
1689
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4 ;
@@ -1770,7 +1804,7 @@ void main() {
1770
1804
1771
1805
// Since the front camera is in landscape mode, we expect the camera
1772
1806
// preview to be mirrored across the x-axis.
1773
- expect (transformedPreviewMatrix.storage[ 0 ], closeTo ( - 1.0 , 0.0001 ) );
1807
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1774
1808
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1775
1809
1776
1810
final int clockwiseQuarterTurns =
@@ -1884,9 +1918,9 @@ void main() {
1884
1918
// across the y-axis.
1885
1919
if (currentDeviceOrientation == DeviceOrientation .landscapeLeft ||
1886
1920
currentDeviceOrientation == DeviceOrientation .landscapeRight) {
1887
- expect (transformedPreviewMatrix.storage[ 0 ], closeTo ( - 1.0 , 0.0001 ) );
1921
+ checkXAxisIsMirrored (transformedPreviewMatrix);
1888
1922
} else {
1889
- expect (transformedPreviewMatrix.storage[ 5 ], closeTo ( - 1.0 , 0.0001 ) );
1923
+ checkYAxisIsMirrored (transformedPreviewMatrix);
1890
1924
}
1891
1925
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
1892
1926
final int clockwiseQuarterTurns =
@@ -2152,7 +2186,7 @@ void main() {
2152
2186
2153
2187
// Since the front camera is in landscape mode, we expect the camera
2154
2188
// preview to be mirrored across the x-axis.
2155
- expect (transformedPreviewMatrix.storage[ 0 ], closeTo ( - 1.0 , 0.0001 ) );
2189
+ checkXAxisIsMirrored (transformedPreviewMatrix);
2156
2190
expect ((transformedPreview.child! as Texture ).textureId, cameraId);
2157
2191
expect (
2158
2192
rotatedBox.quarterTurns,
0 commit comments