Repository: flutter
Issue: decodeImageFromList shows error when convert YUV420 to ui.Image
Labels: c: crash,a: quality,p: camera,package,team-ecosystem,P3,triaged-ecosystem

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill our the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

Hi Team ,

I'm trying to make a real-time image filter based on CameraController widget. But when I tried to convert controller.planes to Uint8List and convert it from YUV420 to ui.Image, it always show error 

**### "Exception has occurred.
_Exception (Exception: Could not instantiate image codec.)"**

step to implement a real-time image filter (what I've thought):

1. get image from CameraController.startImageStream(image)
2. convert CameraImage to ui.Image so I can use canvas to draw it on screen.
3. for canvas there is a way to use colorFilter to make a colorFilter matrix(4 X 5 )
4.finally I'll use a canvas to replace the CameraPreviewer to show the processed cameraImage

Problems here:

Flutter may be not having a convenient solution for matrix operation (like numpy in python, or just I haven't found) and it will take a long time to process the image and cannot achieve a 60fps animation based on my solution.( or any other solution suggested? Thanks in advanced)

When tried to convert YUV420 to ui.Image, I found another interesting "problem"
The Image size is width:720  height:1280, the length of bytes in cameraImage.planes[0] (Y channel ) is 921600.

Based on the description from Wiki or any other website, the U and V channel should be half of Y channel, but in Flutter, the length for U and V is 1 byte less. 

Y---921,600
U---460,799
V---460,799

Is this the root cause when failed to convert YUV420 or why it's 1 bytes less then half of Y channel?


### code FYI
    controller.startImageStream((CameraImage image) async {
      if (!ifProcess && mounted) {
        ifProcess = true;
        .......
        List<int> bytes=List<int>();
        image.planes.forEach((plane){
          plane.bytes.toList().forEach((byte){
            bytes.add(byte);
          });
        });
        img = await decodeImageFromList(
          Uint8List.fromList(bytes),
        );
        .......
      } else {
        return;
      }
    }).catchError((e) {
      ifProcess = false;
    });



This could not run on simulator as it requires to use camera.



**Target Platform:** Android
**Target OS version/browser:** 9.1.0.226
**Devices:** real device


## Logs

### flutter run

[  +65 ms] I/GRALLOC (19935): LockFlexLayout: baseFormat: 11, yStride: 1280, ySize: 921600,
uOffset: 921600,  uStride: 1280
[  +67 ms] I/GRALLOC (19935): LockFlexLayout: baseFormat: 11, yStride: 1280, ySize: 921600,
uOffset: 921600,  uStride: 1280
[  +49 ms] I/GRALLOC (19935): LockFlexLayout: baseFormat: 11, yStride: 1280, ySize: 921600,
uOffset: 921600,  uStride: 1280
[  +62 ms] I/GRALLOC (19935): LockFlexLayout: baseFormat: 11, yStride: 1280, ySize: 921600,
uOffset: 921600,  uStride: 1280



### flutter analyze
Analyzing realtime_camera...                                            

   info • Unused import: 'package:vector_math/vector_math_64.dart' • lib/main.dart:9:8 •
          unused_import
   info • Unused import: 'package:linalg/matrix.dart' • lib/main.dart:11:8 • unused_import
   info • The value of the local variable 'u' isn't used • lib/main.dart:83:11 •
          unused_local_variable
   info • The value of the local variable 'v' isn't used • lib/main.dart:84:11 •
          unused_local_variable
   info • The value of the local variable 'r' isn't used • lib/main.dart:85:15 •
          unused_local_variable
   info • The value of the local variable 'g' isn't used • lib/main.dart:86:15 •
          unused_local_variable
   info • The value of the local variable 'b' isn't used • lib/main.dart:87:15 •
          unused_local_variable
   info • The value of the local variable 'matrix' isn't used • lib/main.dart:194:17 •
          unused_local_variable
   info • The value of the local variable 'rightY' isn't used • lib/main.dart:298:14 •
          unused_local_variable


No issue, just not used of local variable.


[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.15 19A583, locale zh-Hans-CN)
    • Flutter version 1.9.1+hotfix.6 at /Users/geyan/development/flutter
    • Framework revision 68587a0916 (7 weeks ago), 2019-09-13 19:46:58 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/geyan/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.0, Build version 11A420a
    • CocoaPods version 1.8.3

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.39.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.6.0

[✓] Connected device (1 available)
    • ELE AL00 • 8KE0219323014086 • android-arm64 • Android 9 (API 28)

• No issues found!