From 949dc88407754f4709deee823d35639cdbbfe36b Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Tue, 9 May 2023 16:47:52 +0400 Subject: [PATCH] downgrade to image v3 --- example/pubspec.lock | 4 ++-- lib/src/ui/reader_widget.dart | 3 ++- lib/src/ui/writer_widget.dart | 7 +++---- lib/src/utils/image_converter.dart | 23 ++++++++++++----------- pubspec.yaml | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index e33b787..ca468cc 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -259,10 +259,10 @@ packages: dependency: transitive description: name: image - sha256: a72242c9a0ffb65d03de1b7113bc4e189686fc07c7147b8b41811d0dd0e0d9bf + sha256: "8e9d133755c3e84c73288363e6343157c383a0c6c56fc51afcc5d4d7180306d6" url: "https://pub.dev" source: hosted - version: "4.0.17" + version: "3.3.0" image_picker: dependency: transitive description: diff --git a/lib/src/ui/reader_widget.dart b/lib/src/ui/reader_widget.dart index 67c36a0..b8e1447 100644 --- a/lib/src/ui/reader_widget.dart +++ b/lib/src/ui/reader_widget.dart @@ -234,7 +234,8 @@ class _ReaderWidgetState extends State cameraDescription, widget.resolution, enableAudio: false, - imageFormatGroup: ImageFormatGroup.yuv420, + imageFormatGroup: + isAndroid() ? ImageFormatGroup.yuv420 : ImageFormatGroup.bgra8888, ); controller = cameraController; try { diff --git a/lib/src/ui/writer_widget.dart b/lib/src/ui/writer_widget.dart index ee57b57..11e3903 100644 --- a/lib/src/ui/writer_widget.dart +++ b/lib/src/ui/writer_widget.dart @@ -278,10 +278,9 @@ class _WriterWidgetState extends State if (result.isValid && result.data != null) { try { final imglib.Image img = imglib.Image.fromBytes( - width: width, - height: height, - bytes: result.data!.buffer, - numChannels: 4, + width, + height, + result.data!, ); final Uint8List encodedBytes = Uint8List.fromList( imglib.encodeJpg(img), diff --git a/lib/src/utils/image_converter.dart b/lib/src/utils/image_converter.dart index d0b4171..8a58054 100644 --- a/lib/src/utils/image_converter.dart +++ b/lib/src/utils/image_converter.dart @@ -16,7 +16,7 @@ Future convertImage(CameraImage image) async { } else if (image.format.group == ImageFormatGroup.bgra8888) { img = convertBGRA8888(image); } - return img.toUint8List(); + return img.getBytes(format: imglib.Format.luminance); //.toUint8List(); } catch (e) { debugPrint('>>>>>>>>>>>> ERROR: $e'); } @@ -25,10 +25,10 @@ Future convertImage(CameraImage image) async { imglib.Image convertBGRA8888(CameraImage image) { return imglib.Image.fromBytes( - width: image.width, - height: image.height, - bytes: image.planes[0].bytes.buffer, - // format: imglib.Format.bgra, + image.width, + image.height, + image.planes[0].bytes, + format: imglib.Format.bgra, // format: imglib.Format.int8, // order: imglib.ChannelOrder.bgra, ); @@ -85,10 +85,11 @@ imglib.Image resizeToMaxSize(imglib.Image image, int? maxSize) { // get the bytes of the image in grayscale format (luminance) like v3 Uint8List grayscaleBytes(imglib.Image image) { - final imglib.Image imgRgba8 = image.convert( - format: imglib.Format.uint8, - numChannels: 1, - ); // Make sure it's an RGBA 32-bit image like v3 - imglib.grayscale(imgRgba8); // map the pixels to grayscale (luminance) - return imgRgba8.getBytes(); + return image.getBytes(format: imglib.Format.luminance); + // final imglib.Image imgRgba8 = image.convert( + // format: imglib.Format.uint8, + // numChannels: 1, + // ); // Make sure it's an RGBA 32-bit image like v3 + // imglib.grayscale(imgRgba8); // map the pixels to grayscale (luminance) + // return imgRgba8.getBytes(); } diff --git a/pubspec.yaml b/pubspec.yaml index 82f99c4..809c666 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: ffi: ^2.0.0 flutter: sdk: flutter - image: ^4.0.0 + image: ^3.0.0 image_picker: ^0.8.0 melos: ^3.0.0