yekeskin / flutter_avif

A flutter plugin to view and encode avif images.
https://pub.dev/packages/flutter_avif
MIT License
61 stars 17 forks source link

how can we decode AVIF image from Uint8List bytes? #9

Closed ozexpert closed 1 year ago

ozexpert commented 1 year ago

I'd like to know whether it is possible to decode AVIF image.

problem with https://pub.dev/packages/image is that it does not support AVIF format. I'd like to see whether it is possible to use this package to decode AVIF format and manipulate image using the Image class if possible.

yekeskin commented 1 year ago

It is possible. You can directly instantiate AvifCodec and then use it to access the image.

final bytes = await rootBundle.load("assets/fox.profile0.8bpc.yuv420.avif");
final codec = AvifCodec(key: 1, avifBytes: bytes.buffer.asUint8List());
await codec.ready();
final AvifFrameInfo frame = await codec.getNextFrame();
// frame.image

frame.image will be your image.

ozexpert commented 1 year ago

great thanks, however; I'm getting

E/flutter ( 3580): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FfiException(PANIC_ERROR, assertion failed: `(left == right)`
E/flutter ( 3580):   left: `12970367453362002624`,
E/flutter ( 3580):  right: `0`, null)
E/flutter ( 3580): #0      FlutterRustBridgeBase._transformRust2DartMessage (package:flutter_rust_bridge/src/basic.dart:101:9)
E/flutter ( 3580): #1      FlutterRustBridgeBase.executeNormal.<anonymous closure> (package:flutter_rust_bridge/src/basic.dart:49:9)
E/flutter ( 3580): <asynchronous suspension>

most of the time. in some case it succeeds.

yekeskin commented 1 year ago

can you provide a repo or sample images & code to reproduce the error?