From 2169f646936e7fe3be6d68a40e4ec704a42ca80e Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Tue, 30 Jan 2024 00:03:39 -0500 Subject: [PATCH] Changed getMatrix to use a pointer instead of copying --- lib/src/camera.dart | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/src/camera.dart b/lib/src/camera.dart index dad43e5..ecc538c 100644 --- a/lib/src/camera.dart +++ b/lib/src/camera.dart @@ -1,5 +1,4 @@ import "dart:ffi"; -import "dart:typed_data"; import "package:ffi/ffi.dart"; import "exceptions.dart"; @@ -152,16 +151,11 @@ OpenCVImage? encodeJpg(Pointer image, {int quality = 100}) { return OpenCVImage(pointer: buffer, length: size); } -/// Converts an [image] with the given [width] and [height] into an OpenCV image. +/// Converts an image with the given [width] and [height] into an OpenCV matrix. /// /// The matrix must be disposed using [freeMatrix]. -Pointer getMatrix(int height, int width, Uint8List image) { - final Pointer pointer = arena(image.length); - for (int i = 0; i < image.length; i++) { - pointer[i] = image[i]; - } - return nativeLib.Mat_createFrom(height, width, pointer); -} +Pointer getMatrix(int height, int width, Pointer bytes) => + nativeLib.Mat_createFrom(height, width, bytes); /// Frees memory associated with the given matrix and its underlying image. void freeMatrix(Pointer pointer) => nativeLib.Mat_destroy(pointer);