// import 'dart:async'; import 'dart:ffi'; import 'dart:io'; import 'dart:typed_data'; // import 'dart:isolate'; // import 'dart:ui'; 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'; final here = dirname(Platform.script.path); final build = join(dirname(here), "build"); /// The dynamic library in which the symbols for [ArchimedesMobileLibBindings] can be found. final DynamicLibrary _dylib = () { if (Platform.isMacOS || Platform.isIOS) { return DynamicLibrary.open(join(build, '$_libName.framework', _libName)); } if (Platform.isAndroid || Platform.isLinux) { return DynamicLibrary.open(join(build, 'lib$_libName.so')); } if (Platform.isWindows) { return DynamicLibrary.open(join('$_libName.dll')); } throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}'); }(); /// The bindings to the native functions in [_dylib]. final ArchimedesMobileLibBindings _bindings = ArchimedesMobileLibBindings(_dylib); int getImageData(Pointer frame, Pointer data) => _bindings.archimedes_get_image_data(frame, data); Pointer newFrame( Pointer data, int dataLen, int w, int h, int depth) => _bindings.new_frame_from_data(data, dataLen, w, h, depth); void main(List arguments) { final assets = join(dirname(here), "assets"); final testFrames = join(assets, "test", "frames"); final firstFrame = join(testFrames, "0001.png"); final f = File(firstFrame); final l = f.readAsBytesSync().cast(); final myPointer = malloc(l.length); for (int i = 0; i < l.length; ++i) { myPointer[i] = l[i]; print(myPointer[i]); } Pointer frame = newFrame(myPointer, l.length, 768, 768, 64); Pointer data = malloc(l.length * 4); getImageData(frame, data); }