Skip to content
Snippets Groups Projects
Commit e43cb691 authored by Ross Wang's avatar Ross Wang Committed by CQ bot account: commit-bot@chromium.org
Browse files

[e2e][sl4f][dart] Update image byte order to BGRA

This changed from RGBA in
https://github.com/brendan-duncan/image/commit/f3d07a74d17d0004d88fc1043042df9111eb3b6f

Also added a test for this regression.

Issue: https://github.com/brendan-duncan/image/issues/92
Test: fx run-host-tests sl4f_client_tests
      end-to-end test
Change-Id: If8c82f9d5479d16e7c41845eb001d6ac8068ea27
parent 04e0ff45
No related branches found
No related tags found
No related merge requests found
......@@ -413,6 +413,7 @@ group("all") {
"//garnet/packages/tests:scpi",
"//garnet/packages/tests:setui_client",
"//garnet/packages/tests:setui_service",
"//garnet/packages/tests:sl4f",
"//garnet/packages/tests:sse",
"//garnet/packages/tests:stash",
"//garnet/packages/tests:svc",
......@@ -1296,3 +1297,10 @@ group("catapult_converter") {
"//garnet/bin/catapult_converter:host_catapult_converter_test($host_toolchain)",
]
}
group("sl4f") {
testonly = true
public_deps = [
"//sdk/testing/sl4f/client:tests",
]
}
......@@ -3,6 +3,8 @@
# found in the LICENSE file.
import("//build/dart/dart_library.gni")
import("//build/dart/test.gni")
import("//build/testing/environments.gni")
dart_library("client") {
package_name = "sl4f"
......@@ -26,3 +28,26 @@ dart_library("client") {
"//third_party/dart-pkg/pub/meta",
]
}
dart_test("sl4f_client_tests") {
sources = [
"scenic_test.dart",
]
deps = [
":client",
"//third_party/dart-pkg/pub/image",
"//third_party/dart-pkg/pub/mockito",
"//third_party/dart-pkg/pub/test",
]
environments = [ linux_env ]
}
group("tests") {
testonly = true
deps = [
":sl4f_client_tests($host_toolchain)",
]
}
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:convert' show base64Decode;
import 'dart:typed_data' show Uint8List;
import 'package:image/image.dart' show encodePng, Image;
......@@ -30,8 +29,8 @@ class Scenic {
/// Captures the screen of the device.
///
/// Returns an Image in RGBA format. If a [dumpName] is provided, the picture
/// is also dumped with that name as prefix.
/// Returns the screenshot as an [Image]. If a [dumpName] is provided, the
/// PNG is also dumped with that name as prefix.
Future<Image> takeScreenshot({String dumpName}) async {
final Map<String, dynamic> response =
await _sl4f.request('scenic_facade.TakeScreenshot');
......@@ -39,16 +38,8 @@ class Scenic {
assert(info['pixel_format'], 'Bgra8');
final Uint8List bytes = base64Decode(response['data']);
// Image only takes RGB/RGBA so we need to reverse from BGRA
for (int quad = 0; quad < bytes.length; quad += 4) {
final blue = bytes[quad];
bytes[quad] = bytes[quad + 2];
bytes[quad + 2] = blue;
}
final image = Image.fromBytes(info['width'], info['height'], bytes);
final image = Image.fromBytes(
info['width'], info['height'], base64Decode(response['data']));
if (dumpName != null) {
_dump.writeAsBytes(dumpName, 'png', encodePng(image));
......
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'package:image/image.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'package:sl4f/sl4f.dart';
class MockSl4f extends Mock implements Sl4f {}
void main(List<String> args) {
// This is mostly an integration test against the Image package.
test('screenshot decodes to correct colors', () async {
final color = Color.fromRgba(12, 34, 56, 78);
final sl4f = MockSl4f();
when(sl4f.request('scenic_facade.TakeScreenshot'))
.thenAnswer((_) => Future.value({
'info': {'pixel_format': 'Bgra8', 'width': 1, 'height': 1},
'data': base64Encode([
getBlue(color),
getGreen(color),
getRed(color),
getAlpha(color)
])
}));
final Image image = await Scenic(sl4f).takeScreenshot();
expect(image[0], color);
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment