Unverified Commit 4c25587b authored by gaaclarke's avatar gaaclarke Committed by GitHub

Added negative test and blur test to the wide gamut tests. (#120914)

* Added negative test and blur test to the wide gamut tests.

* switched back to dstOver

* fixed blur test

* analysis warnings

* analyzer
parent dad9eb21
...@@ -23,7 +23,10 @@ bool _isAlmost(double x, double y, double epsilon) { ...@@ -23,7 +23,10 @@ bool _isAlmost(double x, double y, double epsilon) {
return (x - y).abs() < epsilon; return (x - y).abs() < epsilon;
} }
bool _findDeepRedBGRA10(Uint8List bytes, int width, int height) { List<double> _deepRed = <double>[1.0931, -0.2268, -0.1501];
bool _findBGRA10Color(
Uint8List bytes, int width, int height, List<double> color) {
final ByteData byteData = ByteData.sublistView(bytes); final ByteData byteData = ByteData.sublistView(bytes);
expect(bytes.lengthInBytes, width * height * 8); expect(bytes.lengthInBytes, width * height * 8);
expect(bytes.lengthInBytes, byteData.lengthInBytes); expect(bytes.lengthInBytes, byteData.lengthInBytes);
...@@ -33,16 +36,17 @@ bool _findDeepRedBGRA10(Uint8List bytes, int width, int height) { ...@@ -33,16 +36,17 @@ bool _findDeepRedBGRA10(Uint8List bytes, int width, int height) {
final double blue = _decodeBGR10((pixel >> 6) & 0x3ff); final double blue = _decodeBGR10((pixel >> 6) & 0x3ff);
final double green = _decodeBGR10((pixel >> 22) & 0x3ff); final double green = _decodeBGR10((pixel >> 22) & 0x3ff);
final double red = _decodeBGR10((pixel >> 38) & 0x3ff); final double red = _decodeBGR10((pixel >> 38) & 0x3ff);
if (_isAlmost(red, 1.0931, 0.01) && if (_isAlmost(red, color[0], 0.01) &&
_isAlmost(green, -0.2268, 0.01) && _isAlmost(green, color[1], 0.01) &&
_isAlmost(blue, -0.1501, 0.01)) { _isAlmost(blue, color[2], 0.01)) {
foundDeepRed = true; foundDeepRed = true;
} }
} }
return foundDeepRed; return foundDeepRed;
} }
bool _findDeepRedBGR10(Uint8List bytes, int width, int height) { bool _findBGR10Color(
Uint8List bytes, int width, int height, List<double> color) {
final ByteData byteData = ByteData.sublistView(bytes); final ByteData byteData = ByteData.sublistView(bytes);
expect(bytes.lengthInBytes, width * height * 4); expect(bytes.lengthInBytes, width * height * 4);
expect(bytes.lengthInBytes, byteData.lengthInBytes); expect(bytes.lengthInBytes, byteData.lengthInBytes);
...@@ -52,25 +56,25 @@ bool _findDeepRedBGR10(Uint8List bytes, int width, int height) { ...@@ -52,25 +56,25 @@ bool _findDeepRedBGR10(Uint8List bytes, int width, int height) {
final double blue = _decodeBGR10(pixel & 0x3ff); final double blue = _decodeBGR10(pixel & 0x3ff);
final double green = _decodeBGR10((pixel >> 10) & 0x3ff); final double green = _decodeBGR10((pixel >> 10) & 0x3ff);
final double red = _decodeBGR10((pixel >> 20) & 0x3ff); final double red = _decodeBGR10((pixel >> 20) & 0x3ff);
if (_isAlmost(red, 1.0931, 0.01) && if (_isAlmost(red, color[0], 0.01) &&
_isAlmost(green, -0.2268, 0.01) && _isAlmost(green, color[1], 0.01) &&
_isAlmost(blue, -0.1501, 0.01)) { _isAlmost(blue, color[2], 0.01)) {
foundDeepRed = true; foundDeepRed = true;
} }
} }
return foundDeepRed; return foundDeepRed;
} }
bool _findDeepRed(List<Object?> result) { bool _findColor(List<Object?> result, List<double> color) {
expect(result, isNotNull); expect(result, isNotNull);
expect(result.length, 4); expect(result.length, 4);
final int width = (result[0] as int?)!; final int width = (result[0] as int?)!;
final int height = (result[1] as int?)!; final int height = (result[1] as int?)!;
final String format = (result[2] as String?)!; final String format = (result[2] as String?)!;
if (format == 'MTLPixelFormatBGR10_XR') { if (format == 'MTLPixelFormatBGR10_XR') {
return _findDeepRedBGR10((result[3] as Uint8List?)!, width, height); return _findBGR10Color((result[3] as Uint8List?)!, width, height, color);
} else if (format == 'MTLPixelFormatBGRA10_XR') { } else if (format == 'MTLPixelFormatBGRA10_XR') {
return _findDeepRedBGRA10((result[3] as Uint8List?)!, width, height); return _findBGRA10Color((result[3] as Uint8List?)!, width, height, color);
} else { } else {
fail('Unsupported pixel format: $format'); fail('Unsupported pixel format: $format');
} }
...@@ -87,7 +91,7 @@ void main() { ...@@ -87,7 +91,7 @@ void main() {
const MethodChannel channel = MethodChannel('flutter/screenshot'); const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result = final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>; await channel.invokeMethod('test') as List<Object?>;
expect(_findDeepRed(result), isTrue); expect(_findColor(result, _deepRed), isTrue);
}); });
testWidgets('look for display p3 deepest red', (WidgetTester tester) async { testWidgets('look for display p3 deepest red', (WidgetTester tester) async {
app.run(app.Setup.canvasSaveLayer); app.run(app.Setup.canvasSaveLayer);
...@@ -96,7 +100,27 @@ void main() { ...@@ -96,7 +100,27 @@ void main() {
const MethodChannel channel = MethodChannel('flutter/screenshot'); const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result = final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>; await channel.invokeMethod('test') as List<Object?>;
expect(_findDeepRed(result), isTrue); expect(_findColor(result, _deepRed), isTrue);
});
testWidgets('no p3 deepest red without image', (WidgetTester tester) async {
app.run(app.Setup.none);
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed), isFalse);
expect(_findColor(result, <double>[0.0, 1.0, 0.0]), isFalse);
});
testWidgets('p3 deepest red with blur', (WidgetTester tester) async {
app.run(app.Setup.blur);
await tester.pumpAndSettle(const Duration(seconds: 2));
const MethodChannel channel = MethodChannel('flutter/screenshot');
final List<Object?> result =
await channel.invokeMethod('test') as List<Object?>;
expect(_findColor(result, _deepRed), isTrue);
expect(_findColor(result, <double>[0.0, 1.0, 0.0]), isTrue);
}); });
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment