Skip to content

Commit

Permalink
Merge branch 'async' into async-video
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyl authored Jun 29, 2024
2 parents 0ff6839 + feeb89a commit da5da09
Show file tree
Hide file tree
Showing 18 changed files with 2,272 additions and 109 deletions.
4 changes: 4 additions & 0 deletions ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ headers:
- src/objdetect/objdetect.h
- src/objdetect/objdetect_async.h
- src/photo/photo.h
- src/photo/photo_async.h
- src/stitching/stitching.h
- src/stitching/stitching_async.h
- src/video/video.h
- src/video/video_async.h
- src/video/videoio.h
Expand Down Expand Up @@ -69,7 +71,9 @@ headers:
- src/objdetect/objdetect.h
- src/objdetect/objdetect_async.h
- src/photo/photo.h
- src/photo/photo_async.h
- src/stitching/stitching.h
- src/stitching/stitching_async.h
- src/video/video.h
- src/video/video_async.h
- src/video/videoio.h
Expand Down
2 changes: 2 additions & 0 deletions lib/opencv_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export 'src/imgproc/subdiv2d_async.dart';
export 'src/objdetect/objdetect.dart';
export 'src/objdetect/objdetect_async.dart';
export 'src/photo/photo.dart';
export 'src/photo/photo_async.dart';
export 'src/stitching/stitching.dart';
export 'src/stitching/stitching_async.dart';
export 'src/svd/svd.dart';
export 'src/video/video.dart';
export 'src/video/video_async.dart';
Expand Down
31 changes: 27 additions & 4 deletions lib/src/core/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ ffi.DynamicLibrary loadNativeLibrary() {
"windows" => "$_libraryName.dll",
"linux" || "android" || "fuchsia" => "lib$_libraryName.so",
"macos" => "lib$_libraryName.dylib",
_ => throw UnsupportedError("Platform ${Platform.operatingSystem} not supported")
_ => throw UnsupportedError(
"Platform ${Platform.operatingSystem} not supported",
)
};
final libPath = Platform.environment["OPENCV_DART_LIB_PATH"] ?? defaultLibPath;
return ffi.DynamicLibrary.open(libPath);
Expand Down Expand Up @@ -152,7 +154,13 @@ Future<T> cvRunAsync3<T>(

Future<T> cvRunAsync4<T>(
ffi.Pointer<cvg.CvStatus> Function(cvg.CvCallback_4 callback) func,
void Function(Completer<T> completer, VoidPtr p, VoidPtr p1, VoidPtr p2, VoidPtr p3) onComplete,
void Function(
Completer<T> completer,
VoidPtr p,
VoidPtr p1,
VoidPtr p2,
VoidPtr p3,
) onComplete,
) {
final completer = Completer<T>();
late final NativeCallable<cvg.CvCallback_4Function> ccallback;
Expand All @@ -168,7 +176,14 @@ Future<T> cvRunAsync4<T>(

Future<T> cvRunAsync5<T>(
ffi.Pointer<cvg.CvStatus> Function(cvg.CvCallback_5 callback) func,
void Function(Completer<T> completer, VoidPtr p, VoidPtr p1, VoidPtr p2, VoidPtr p3, VoidPtr p4) onComplete,
void Function(
Completer<T> completer,
VoidPtr p,
VoidPtr p1,
VoidPtr p2,
VoidPtr p3,
VoidPtr p4,
) onComplete,
) {
final completer = Completer<T>();
late final NativeCallable<cvg.CvCallback_5Function> ccallback;
Expand Down Expand Up @@ -197,6 +212,12 @@ void intCompleter(Completer<int> completer, VoidPtr p) {
completer.complete(value);
}

void boolCompleter(Completer<bool> completer, VoidPtr p) {
final value = p.cast<ffi.Bool>().value;
calloc.free(p);
completer.complete(value);
}

void doubleCompleter(Completer<double> completer, VoidPtr p) {
final value = p.cast<ffi.Double>().value;
calloc.free(p);
Expand Down Expand Up @@ -235,7 +256,9 @@ R cvRunArena<R>(
typedef NativeFinalizerFunctionT<T extends ffi.NativeType>
= ffi.Pointer<ffi.NativeFunction<ffi.Void Function(T token)>>;

ffi.NativeFinalizer OcvFinalizer<T extends ffi.NativeType>(NativeFinalizerFunctionT<T> func) =>
ffi.NativeFinalizer OcvFinalizer<T extends ffi.NativeType>(
NativeFinalizerFunctionT<T> func,
) =>
ffi.NativeFinalizer(func.cast<ffi.NativeFinalizerFunction>());

// native types
Expand Down
Loading

0 comments on commit da5da09

Please sign in to comment.