Skip to content

ui.Image.toByteData() doesn't work with wide gamut color images #121563

@gaaclarke

Description

@gaaclarke

description

Looks like ui.Image.toByteData() isn't supported when wide gamut colors are enabled. There is an argument with a default value there that is the format requested. It's rgba8. So, we should make that conversion happen. I'm not sure if we need to support requesting the extended range format eventually.

reproduction

  1. Go to //flutter/dev/integration_tests/wide_gamut_test/
  2. apply the following patch
--- a/dev/integration_tests/wide_gamut_test/lib/main.dart
+++ b/dev/integration_tests/wide_gamut_test/lib/main.dart
@@ -135,7 +135,7 @@ const String _displayP3Logo =
     'gr3yrjmlwqXLjmWw1O2I5Wmp9Xxjyh+AVIZ6ADIAqcwClakzeMgApDILVKbO4CED'
     'kMosUJk6g4dUBuRfvf1am9VRqzYAAAAASUVORK5CYII=';
 
-void main() => run(Setup.blur);
+void main() => run(Setup.canvasSaveLayer);
 
 enum Setup {
   none,
@@ -222,6 +222,9 @@ class _MyHomePageState extends State<MyHomePage> {
   void initState() {
     if (widget.setup == Setup.canvasSaveLayer) {
       _loadImage().then((ui.Image? value) {
+        value!.toByteData().then((byteData) {
+          print('length in bytes: ${byteData!.lengthInBytes}');
+        });
         setState(() {
           _image = value;
         });

error

(lldb) 2023-02-27 15:33:50.467690-0800 Runner[18593:6027823] [VERBOSE-2:FlutterDarwinContextMetalImpeller.mm(32)] Using the Impeller rendering backend.
[VERBOSE-2:image_encoding_impeller.cc(81)] Failed to get color type from pixel format.
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
#0      _Image.toByteData.<anonymous closure>.<anonymous closure> (dart:ui/painting.dart:1876:25)
Installing and launching...                                         9.2s

Metadata

Metadata

Assignees

No one assigned

    Labels

    e: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions