getInputDetails method

List<AiliaDetail> getInputDetails()

Implementation

List<AiliaDetail> getInputDetails() {
  List<AiliaDetail> details = List<AiliaDetail>.empty(growable: true);
  final Pointer<Uint32> inputBlobCount = malloc<Uint32>();
  inputBlobCount.value = 0;
  int status = ailia.ailiaGetInputBlobCount(ppAilia!.value, inputBlobCount);
  if (status != ailia_dart.AILIA_STATUS_SUCCESS) {
    throw Exception("ailiaGetInputBlobCount error $status");
  }

  for (int i = 0; i < inputBlobCount.value; i++) {
    Pointer<ailia_dart.AILIAShape> inputBlobShape =
        malloc<ailia_dart.AILIAShape>();
    final Pointer<Uint32> inputBlobIdx = malloc<Uint32>();
    inputBlobIdx.value = 0;
    status = ailia.ailiaGetBlobIndexByInputIndex(
      ppAilia!.value,
      inputBlobIdx,
      i,
    );
    if (status != ailia_dart.AILIA_STATUS_SUCCESS) {
      throw Exception("ailiaGetBlobIndexByOutputIndex error $status");
    }
    status = ailia.ailiaGetBlobShape(
      ppAilia!.value,
      inputBlobShape,
      inputBlobIdx.value,
      ailia_dart.AILIA_SHAPE_VERSION,
    );
    if (status != ailia_dart.AILIA_STATUS_SUCCESS) {
      throw Exception("ailiaGetBlobShape error $status");
    }
    AiliaShape shape = AiliaShape();
    shape.x = inputBlobShape.ref.x;
    shape.y = inputBlobShape.ref.y;
    shape.z = inputBlobShape.ref.z;
    shape.w = inputBlobShape.ref.w;
    shape.dim = inputBlobShape.ref.dim;

    final Pointer<Uint32> blobNameLength = malloc<Uint32>();
    blobNameLength.value = 0;
    status = ailia.ailiaGetBlobNameLengthByIndex(
        ppAilia!.value, inputBlobIdx.value, blobNameLength);
    if (status != ailia_dart.AILIA_STATUS_SUCCESS) {
      throw Exception("ailiaGetBlobNameLengthByIndex error $status");
    }
    final Pointer<Int8> blobName = malloc<Int8>(blobNameLength.value);
    status = ailia.ailiaFindBlobNameByIndex(
      ppAilia!.value,
      blobName,
      blobNameLength.value,
      inputBlobIdx.value,
    );
    if (status != ailia_dart.AILIA_STATUS_SUCCESS) {
      throw Exception("ailiaFindBlobNameByIndex error $status");
    }

    AiliaDetail detail = AiliaDetail();
    detail.name = blobName.cast<Utf8>().toDartString();
    detail.shape = shape;

    details.add(detail);

    malloc.free(inputBlobIdx);
    malloc.free(inputBlobShape);
    malloc.free(blobName);
    malloc.free(blobNameLength);
  }

  malloc.free(inputBlobCount);

  return details;
}