Adds drawn image wide gamut test (#126715)
integration test for https://github.com/flutter/engine/pull/41994 issue https://github.com/flutter/flutter/issues/126620 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
parent
cec4f9c06e
commit
6380075503
@ -162,5 +162,14 @@ void main() {
|
||||
expect(_findColor(result, _deepRed), isTrue);
|
||||
expect(_findColor(result, <double>[0.0, 1.0, 0.0]), isTrue);
|
||||
});
|
||||
testWidgets('draw image with wide gamut works', (WidgetTester tester) async {
|
||||
app.run(app.Setup.drawnImage);
|
||||
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, <double>[0.0, 1.0, 0.0]), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async' show Completer;
|
||||
import 'dart:convert' show base64Decode;
|
||||
import 'dart:typed_data' show ByteData, Uint8List;
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -135,13 +137,14 @@ const String _displayP3Logo =
|
||||
'gr3yrjmlwqXLjmWw1O2I5Wmp9Xxjyh+AVIZ6ADIAqcwClakzeMgApDILVKbO4CED'
|
||||
'kMosUJk6g4dUBuRfvf1am9VRqzYAAAAASUVORK5CYII=';
|
||||
|
||||
void main() => run(Setup.blur);
|
||||
void main() => run(Setup.drawnImage);
|
||||
|
||||
enum Setup {
|
||||
none,
|
||||
image,
|
||||
canvasSaveLayer,
|
||||
blur,
|
||||
drawnImage,
|
||||
}
|
||||
|
||||
void run(Setup setup) {
|
||||
@ -196,6 +199,42 @@ class _SaveLayerDrawer extends CustomPainter {
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
|
||||
}
|
||||
|
||||
Future<ui.Image> _drawImage() async {
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
const Size markerSize = Size(120, 120);
|
||||
final double canvasSize = markerSize.height + 3;
|
||||
final Canvas canvas = Canvas(
|
||||
recorder,
|
||||
Rect.fromLTWH(0, 0, canvasSize, canvasSize),
|
||||
);
|
||||
|
||||
final Paint ovalPaint = Paint()..color = const Color(0xff00ff00);
|
||||
final Path ovalPath = Path()
|
||||
..addOval(Rect.fromLTWH(
|
||||
(canvasSize - markerSize.width) / 2,
|
||||
1,
|
||||
markerSize.width,
|
||||
markerSize.height,
|
||||
));
|
||||
canvas.drawPath(ovalPath, ovalPaint);
|
||||
|
||||
final ui.Picture picture = recorder.endRecording();
|
||||
final ui.Image image = await picture.toImage(
|
||||
canvasSize.toInt(),
|
||||
(canvasSize + 0).toInt(),
|
||||
);
|
||||
final ByteData? byteData =
|
||||
await image.toByteData(format: ui.ImageByteFormat.rawExtendedRgba128);
|
||||
final Completer<ui.Image> completer = Completer<ui.Image>();
|
||||
ui.decodeImageFromPixels(Uint8List.view(byteData!.buffer),
|
||||
canvasSize.toInt(),
|
||||
canvasSize.toInt(),
|
||||
ui.PixelFormat.rgbaFloat32, (ui.Image image) {
|
||||
completer.complete(image);
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future<ui.Image> _loadImage() async {
|
||||
final ui.ImmutableBuffer buffer =
|
||||
await ui.ImmutableBuffer.fromUint8List(base64Decode(_displayP3Logo));
|
||||
@ -226,6 +265,12 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
_image = value;
|
||||
});
|
||||
});
|
||||
} else if (widget.setup == Setup.drawnImage) {
|
||||
_drawImage().then((ui.Image? value) {
|
||||
setState(() {
|
||||
_image = value;
|
||||
});
|
||||
});
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
@ -238,6 +283,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
imageWidget = Container();
|
||||
case Setup.image:
|
||||
imageWidget = Image.memory(base64Decode(_displayP3Logo));
|
||||
case Setup.drawnImage:
|
||||
imageWidget = CustomPaint(painter: _SaveLayerDrawer(_image));
|
||||
case Setup.canvasSaveLayer:
|
||||
imageWidget = CustomPaint(painter: _SaveLayerDrawer(_image));
|
||||
case Setup.blur:
|
||||
|
Loading…
x
Reference in New Issue
Block a user