rename project. lean it up. validate image stream test works.
This commit is contained in:
@ -1,14 +0,0 @@
|
||||
import 'dart:ffi';
|
||||
import 'package:archimedes_mobile_lib/dynloader.dart';
|
||||
import 'archimedes_mobile_lib_bindings_generated.dart';
|
||||
|
||||
final _dylib = getArchimedesCLib();
|
||||
final ArchimedesMobileLibBindings _bindings =
|
||||
ArchimedesMobileLibBindings(_dylib);
|
||||
|
||||
int getImageData(Pointer<Frame> frame, Pointer<UnsignedChar> data) =>
|
||||
_bindings.archimedes_get_image_data(frame, data);
|
||||
|
||||
Pointer<Frame> newFrame(
|
||||
Pointer<Uint8> data, int dataLen, int w, int h, int depth) =>
|
||||
_bindings.new_frame_from_data(data, dataLen, w, h, depth);
|
@ -3,9 +3,8 @@ import 'dart:io';
|
||||
import "package:ffi/ffi.dart";
|
||||
import "package:path/path.dart" show dirname, join;
|
||||
import 'dart:io' show Platform;
|
||||
import 'archimedes_mobile_lib_bindings_generated.dart';
|
||||
|
||||
const String _libName = 'archimedes_mobile_lib';
|
||||
const String _libName = 'libdart_openmvg';
|
||||
final HERE = File(String.fromEnvironment("CURRENT_EXEC_DIR",
|
||||
defaultValue: (File(Platform.script.path).parent.absolute.path)));
|
||||
final BUILD_DIR = File(join(HERE.path, "build"));
|
||||
|
@ -8,25 +8,68 @@
|
||||
// ignore_for_file: type=lint
|
||||
import 'dart:ffi' as ffi;
|
||||
|
||||
/// Bindings for `src/image.h`.
|
||||
/// Dart bindings for the OpenMVG library.
|
||||
///
|
||||
/// Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
|
||||
///
|
||||
class ArchimedesMobileLibBindings {
|
||||
class LibDartOpenMVG {
|
||||
/// Holds the symbol lookup function.
|
||||
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
|
||||
_lookup;
|
||||
|
||||
/// The symbols are looked up in [dynamicLibrary].
|
||||
ArchimedesMobileLibBindings(ffi.DynamicLibrary dynamicLibrary)
|
||||
LibDartOpenMVG(ffi.DynamicLibrary dynamicLibrary)
|
||||
: _lookup = dynamicLibrary.lookup;
|
||||
|
||||
/// The symbols are looked up with [lookup].
|
||||
ArchimedesMobileLibBindings.fromLookup(
|
||||
LibDartOpenMVG.fromLookup(
|
||||
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
|
||||
lookup)
|
||||
: _lookup = lookup;
|
||||
|
||||
ffi.Pointer<ImageResult> image_result_new(
|
||||
ffi.Pointer<u_char> arg0,
|
||||
int data_len,
|
||||
) {
|
||||
return _image_result_new(
|
||||
arg0,
|
||||
data_len,
|
||||
);
|
||||
}
|
||||
|
||||
late final _image_result_newPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Pointer<ImageResult> Function(
|
||||
ffi.Pointer<u_char>, ffi.Size)>>('image_result_new');
|
||||
late final _image_result_new = _image_result_newPtr.asFunction<
|
||||
ffi.Pointer<ImageResult> Function(ffi.Pointer<u_char>, int)>();
|
||||
|
||||
ffi.Pointer<ImageResult> image_result_new_error(
|
||||
int error_t,
|
||||
) {
|
||||
return _image_result_new_error(
|
||||
error_t,
|
||||
);
|
||||
}
|
||||
|
||||
late final _image_result_new_errorPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Pointer<ImageResult> Function(ffi.Int)>>(
|
||||
'image_result_new_error');
|
||||
late final _image_result_new_error = _image_result_new_errorPtr
|
||||
.asFunction<ffi.Pointer<ImageResult> Function(int)>();
|
||||
|
||||
int image_result_free(
|
||||
ffi.Pointer<ImageResult> arg0,
|
||||
) {
|
||||
return _image_result_free(
|
||||
arg0,
|
||||
);
|
||||
}
|
||||
|
||||
late final _image_result_freePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Int Function(ffi.Pointer<ImageResult>)>>(
|
||||
'image_result_free');
|
||||
late final _image_result_free = _image_result_freePtr
|
||||
.asFunction<int Function(ffi.Pointer<ImageResult>)>();
|
||||
|
||||
ffi.Pointer<Frame> new_frame_from_handle(
|
||||
ffi.Pointer<FILE> arg0,
|
||||
int arg1,
|
||||
@ -72,23 +115,37 @@ class ArchimedesMobileLibBindings {
|
||||
ffi.Pointer<Frame> Function(
|
||||
ffi.Pointer<ffi.Uint8>, int, int, int, int)>();
|
||||
|
||||
int archimedes_get_image_data(
|
||||
ffi.Pointer<ImageResult> archimedes_get_image_data(
|
||||
ffi.Pointer<Frame> arg0,
|
||||
ffi.Pointer<ffi.UnsignedChar> arg1,
|
||||
) {
|
||||
return _archimedes_get_image_data(
|
||||
arg0,
|
||||
arg1,
|
||||
);
|
||||
}
|
||||
|
||||
late final _archimedes_get_image_dataPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Int Function(ffi.Pointer<Frame>,
|
||||
ffi.Pointer<ffi.UnsignedChar>)>>('archimedes_get_image_data');
|
||||
late final _archimedes_get_image_data =
|
||||
_archimedes_get_image_dataPtr.asFunction<
|
||||
int Function(ffi.Pointer<Frame>, ffi.Pointer<ffi.UnsignedChar>)>();
|
||||
ffi.Pointer<ImageResult> Function(
|
||||
ffi.Pointer<Frame>)>>('archimedes_get_image_data');
|
||||
late final _archimedes_get_image_data = _archimedes_get_image_dataPtr
|
||||
.asFunction<ffi.Pointer<ImageResult> Function(ffi.Pointer<Frame>)>();
|
||||
|
||||
int archimedes_images_to_sfm(
|
||||
ffi.Pointer<ffi.Pointer<Frame>> arg0,
|
||||
int arg1,
|
||||
) {
|
||||
return _archimedes_images_to_sfm(
|
||||
arg0,
|
||||
arg1,
|
||||
);
|
||||
}
|
||||
|
||||
late final _archimedes_images_to_sfmPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Int Function(ffi.Pointer<ffi.Pointer<Frame>>,
|
||||
ffi.Size)>>('archimedes_images_to_sfm');
|
||||
late final _archimedes_images_to_sfm = _archimedes_images_to_sfmPtr
|
||||
.asFunction<int Function(ffi.Pointer<ffi.Pointer<Frame>>, int)>();
|
||||
}
|
||||
|
||||
final class _Frame extends ffi.Struct {
|
||||
@ -187,4 +244,17 @@ final class _IO_codecvt extends ffi.Opaque {}
|
||||
|
||||
final class _IO_wide_data extends ffi.Opaque {}
|
||||
|
||||
final class _ImageResult extends ffi.Struct {
|
||||
external ffi.Pointer<u_char> data;
|
||||
|
||||
@ffi.Size()
|
||||
external int data_len;
|
||||
|
||||
@ffi.Int()
|
||||
external int error;
|
||||
}
|
||||
|
||||
typedef u_char = __u_char;
|
||||
typedef __u_char = ffi.UnsignedChar;
|
||||
typedef ImageResult = _ImageResult;
|
||||
typedef Frame = _Frame;
|
13
lib/openmvg_c_shim.dart
Normal file
13
lib/openmvg_c_shim.dart
Normal file
@ -0,0 +1,13 @@
|
||||
import 'dart:ffi';
|
||||
import 'package:dart_openmvg/dynloader.dart';
|
||||
import 'package:dart_openmvg/libdart_openmvg_generated.dart';
|
||||
|
||||
final _dylib = getArchimedesCLib();
|
||||
final LibDartOpenMVG _bindings = LibDartOpenMVG(_dylib);
|
||||
|
||||
Pointer<ImageResult> getImageData(Pointer<Frame> frame) =>
|
||||
_bindings.archimedes_get_image_data(frame);
|
||||
|
||||
Pointer<Frame> newFrame(
|
||||
Pointer<Uint8> data, int dataLen, int w, int h, int depth) =>
|
||||
_bindings.new_frame_from_data(data, dataLen, w, h, depth);
|
@ -1,56 +1,25 @@
|
||||
import 'dart:collection';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import "package:ffi/ffi.dart";
|
||||
|
||||
class Uint8FlexList extends ListBase<Uint8> {
|
||||
final List<Uint8> _list = [];
|
||||
Uint8FlexList();
|
||||
|
||||
late Pointer<Uint8> pointer;
|
||||
|
||||
@override
|
||||
Uint8 operator [](int index) => _list[index];
|
||||
|
||||
set list(List<Uint8> l) {
|
||||
_list.removeWhere((element) => true);
|
||||
_list.addAll(l);
|
||||
Pointer<Uint8> p = pointer;
|
||||
pointer = calloc<Uint8>(l.length);
|
||||
for (int i = 0; i < _list.length; ++i) {
|
||||
pointer[i] = _list[i] as int;
|
||||
}
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
@override
|
||||
void operator []=(int index, Uint8 value) {
|
||||
if (index > _list.length) {
|
||||
// resize the pointer
|
||||
pointer = calloc<Uint8>(index - 1);
|
||||
for (int i = 0; i < _list.length; ++i) {
|
||||
pointer[i] = _list[i] as int;
|
||||
}
|
||||
}
|
||||
_list[index] = value;
|
||||
pointer[index] = value as int;
|
||||
}
|
||||
|
||||
@override
|
||||
int get length => _list.length;
|
||||
|
||||
@override
|
||||
set length(int newLength) {
|
||||
throw Error();
|
||||
}
|
||||
|
||||
static fromList(List<Uint8> l) {
|
||||
final l2 = Uint8FlexList();
|
||||
l2.list = l;
|
||||
return l2;
|
||||
}
|
||||
class LengthPointer<T extends NativeType> {
|
||||
final Pointer<T> ptr;
|
||||
final int length;
|
||||
LengthPointer(this.ptr, this.length);
|
||||
}
|
||||
|
||||
Uint8FlexList readUint8Ptr(File file) {
|
||||
return Uint8FlexList.fromList(file.readAsBytesSync().cast());
|
||||
Pointer<Uint8> uint8ListToPointer(Uint8List data) {
|
||||
final Pointer<Uint8> ptr = malloc<Uint8>(data.length);
|
||||
for (int i = 0; i < data.length; ++i) {
|
||||
ptr[i] = data[i];
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
LengthPointer<Uint8> readUint8Ptr(File file) {
|
||||
final fileData = file.readAsBytesSync();
|
||||
final data = uint8ListToPointer(fileData);
|
||||
return LengthPointer<Uint8>(data, fileData.length);
|
||||
}
|
||||
|
Reference in New Issue
Block a user