libdart_openmvg/lib/util.dart

26 lines
637 B
Dart
Raw Normal View History

2024-03-11 18:42:48 +01:00
import 'dart:collection';
import 'dart:ffi';
import 'dart:io';
import 'dart:typed_data';
2024-03-11 18:42:48 +01:00
import "package:ffi/ffi.dart";
class LengthPointer<T extends NativeType> {
final Pointer<T> ptr;
final int length;
LengthPointer(this.ptr, this.length);
}
2024-03-11 18:42:48 +01:00
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];
2024-03-11 18:42:48 +01:00
}
return ptr;
2024-03-11 18:42:48 +01:00
}
LengthPointer<Uint8> readUint8Ptr(File file) {
final fileData = file.readAsBytesSync();
final data = uint8ListToPointer(fileData);
return LengthPointer<Uint8>(data, fileData.length);
2024-03-11 18:42:48 +01:00
}