2024-03-11 15:36:09 +01:00
|
|
|
// import 'dart:async';
|
2024-03-07 15:29:36 +01:00
|
|
|
import 'dart:ffi';
|
|
|
|
import 'dart:io';
|
2024-03-11 15:36:09 +01:00
|
|
|
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;
|
2024-03-07 15:29:36 +01:00
|
|
|
|
|
|
|
import 'archimedes_mobile_lib_bindings_generated.dart';
|
|
|
|
|
|
|
|
const String _libName = 'archimedes_mobile_lib';
|
2024-03-11 15:36:09 +01:00
|
|
|
final here = dirname(Platform.script.path);
|
|
|
|
final build = join(dirname(here), "build");
|
2024-03-07 15:29:36 +01:00
|
|
|
|
|
|
|
/// The dynamic library in which the symbols for [ArchimedesMobileLibBindings] can be found.
|
|
|
|
final DynamicLibrary _dylib = () {
|
|
|
|
if (Platform.isMacOS || Platform.isIOS) {
|
2024-03-11 15:36:09 +01:00
|
|
|
return DynamicLibrary.open(join(build, '$_libName.framework', _libName));
|
2024-03-07 15:29:36 +01:00
|
|
|
}
|
|
|
|
if (Platform.isAndroid || Platform.isLinux) {
|
2024-03-11 15:36:09 +01:00
|
|
|
return DynamicLibrary.open(join(build, 'lib$_libName.so'));
|
2024-03-07 15:29:36 +01:00
|
|
|
}
|
|
|
|
if (Platform.isWindows) {
|
2024-03-11 15:36:09 +01:00
|
|
|
return DynamicLibrary.open(join('$_libName.dll'));
|
2024-03-07 15:29:36 +01:00
|
|
|
}
|
|
|
|
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
|
|
|
|
}();
|
|
|
|
|
|
|
|
/// The bindings to the native functions in [_dylib].
|
2024-03-11 15:36:09 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
void main(List<String> 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<Uint8>(l.length);
|
|
|
|
for (int i = 0; i < l.length; ++i) {
|
|
|
|
myPointer[i] = l[i];
|
|
|
|
print(myPointer[i]);
|
|
|
|
}
|
2024-03-07 15:29:36 +01:00
|
|
|
|
2024-03-11 15:36:09 +01:00
|
|
|
Pointer<Frame> frame = newFrame(myPointer, l.length, 768, 768, 64);
|
2024-03-07 15:29:36 +01:00
|
|
|
|
2024-03-11 15:36:09 +01:00
|
|
|
Pointer<UnsignedChar> data = malloc<UnsignedChar>(l.length * 4);
|
2024-03-07 15:29:36 +01:00
|
|
|
|
2024-03-11 15:36:09 +01:00
|
|
|
getImageData(frame, data);
|
2024-03-07 15:29:36 +01:00
|
|
|
}
|