libdart_openmvg/lib/util.dart

26 lines
637 B
Dart

import 'dart:collection';
import 'dart:ffi';
import 'dart:io';
import 'dart:typed_data';
import "package:ffi/ffi.dart";
class LengthPointer<T extends NativeType> {
final Pointer<T> ptr;
final int length;
LengthPointer(this.ptr, this.length);
}
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);
}