@@ -23,40 +23,80 @@ bool _isAlmost(double x, double y, double epsilon) {
23
23
return (x - y).abs () < epsilon;
24
24
}
25
25
26
+ bool _findDeepRedBGRA10 (Uint8List bytes, int width, int height) {
27
+ final ByteData byteData = ByteData .sublistView (bytes);
28
+ expect (bytes.lengthInBytes, width * height * 8 );
29
+ expect (bytes.lengthInBytes, byteData.lengthInBytes);
30
+ bool foundDeepRed = false ;
31
+ for (int i = 0 ; i < bytes.lengthInBytes; i += 8 ) {
32
+ final int pixel = byteData.getUint64 (i, Endian .host);
33
+ final double blue = _decodeBGR10 ((pixel >> 6 ) & 0x3ff );
34
+ final double green = _decodeBGR10 ((pixel >> 22 ) & 0x3ff );
35
+ final double red = _decodeBGR10 ((pixel >> 38 ) & 0x3ff );
36
+ if (_isAlmost (red, 1.0931 , 0.01 ) &&
37
+ _isAlmost (green, - 0.2268 , 0.01 ) &&
38
+ _isAlmost (blue, - 0.1501 , 0.01 )) {
39
+ foundDeepRed = true ;
40
+ }
41
+ }
42
+ return foundDeepRed;
43
+ }
44
+
45
+ bool _findDeepRedBGR10 (Uint8List bytes, int width, int height) {
46
+ final ByteData byteData = ByteData .sublistView (bytes);
47
+ expect (bytes.lengthInBytes, width * height * 4 );
48
+ expect (bytes.lengthInBytes, byteData.lengthInBytes);
49
+ bool foundDeepRed = false ;
50
+ for (int i = 0 ; i < bytes.lengthInBytes; i += 4 ) {
51
+ final int pixel = byteData.getUint32 (i, Endian .host);
52
+ final double blue = _decodeBGR10 (pixel & 0x3ff );
53
+ final double green = _decodeBGR10 ((pixel >> 10 ) & 0x3ff );
54
+ final double red = _decodeBGR10 ((pixel >> 20 ) & 0x3ff );
55
+ if (_isAlmost (red, 1.0931 , 0.01 ) &&
56
+ _isAlmost (green, - 0.2268 , 0.01 ) &&
57
+ _isAlmost (blue, - 0.1501 , 0.01 )) {
58
+ foundDeepRed = true ;
59
+ }
60
+ }
61
+ return foundDeepRed;
62
+ }
63
+
64
+ bool _findDeepRed (List <Object ?> result) {
65
+ expect (result, isNotNull);
66
+ expect (result.length, 4 );
67
+ final int width = (result[0 ] as int ? )! ;
68
+ final int height = (result[1 ] as int ? )! ;
69
+ final String format = (result[2 ] as String ? )! ;
70
+ if (format == 'MTLPixelFormatBGR10_XR' ) {
71
+ return _findDeepRedBGR10 ((result[3 ] as Uint8List ? )! , width, height);
72
+ } else if (format == 'MTLPixelFormatBGRA10_XR' ) {
73
+ return _findDeepRedBGRA10 ((result[3 ] as Uint8List ? )! , width, height);
74
+ } else {
75
+ fail ('Unsupported pixel format: $format ' );
76
+ }
77
+ }
78
+
26
79
void main () {
27
80
IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
28
81
29
82
group ('end-to-end test' , () {
30
83
testWidgets ('look for display p3 deepest red' , (WidgetTester tester) async {
31
- app.main ();
84
+ app.run (app.Setup .image);
85
+ await tester.pumpAndSettle (const Duration (seconds: 2 ));
86
+
87
+ const MethodChannel channel = MethodChannel ('flutter/screenshot' );
88
+ final List <Object ?> result =
89
+ await channel.invokeMethod ('test' ) as List <Object ?>;
90
+ expect (_findDeepRed (result), isTrue);
91
+ });
92
+ testWidgets ('look for display p3 deepest red' , (WidgetTester tester) async {
93
+ app.run (app.Setup .canvasSaveLayer);
32
94
await tester.pumpAndSettle (const Duration (seconds: 2 ));
33
95
34
96
const MethodChannel channel = MethodChannel ('flutter/screenshot' );
35
97
final List <Object ?> result =
36
98
await channel.invokeMethod ('test' ) as List <Object ?>;
37
- expect (result, isNotNull);
38
- expect (result.length, 4 );
39
- final int width = (result[0 ] as int ? )! ;
40
- final int height = (result[1 ] as int ? )! ;
41
- final String format = (result[2 ] as String ? )! ;
42
- expect (format, 'MTLPixelFormatBGR10_XR' );
43
- final Uint8List bytes = (result[3 ] as Uint8List ? )! ;
44
- final ByteData byteData = ByteData .sublistView (bytes);
45
- expect (bytes.lengthInBytes, width * height * 4 );
46
- expect (bytes.lengthInBytes, byteData.lengthInBytes);
47
- bool foundDeepRed = false ;
48
- for (int i = 0 ; i < bytes.lengthInBytes; i += 4 ) {
49
- final int pixel = byteData.getUint32 (i, Endian .host);
50
- final double blue = _decodeBGR10 (pixel & 0x3ff );
51
- final double green = _decodeBGR10 ((pixel >> 10 ) & 0x3ff );
52
- final double red = _decodeBGR10 ((pixel >> 20 ) & 0x3ff );
53
- if (_isAlmost (red, 1.0931 , 0.01 ) &&
54
- _isAlmost (green, - 0.2268 , 0.01 ) &&
55
- _isAlmost (blue, - 0.1501 , 0.01 )) {
56
- foundDeepRed = true ;
57
- }
58
- }
59
- expect (foundDeepRed, isTrue);
99
+ expect (_findDeepRed (result), isTrue);
60
100
});
61
101
});
62
102
}
0 commit comments