92 lines
4.4 KiB
C

#include "yolo_runtime.h"
#include <stddef.h>
#include <stdint.h>
#define ASSERT_FIELD_ORDER(type, first, second) \
_Static_assert(offsetof(type, first) < offsetof(type, second), #type " field order changed")
typedef uint32_t (*get_abi_version_fn)(void);
typedef yolo_status_t (*create_fn)(const char*, yolo_runtime_t**, yolo_error_info_v1_t*);
typedef yolo_status_t (*get_info_fn)(const yolo_runtime_t*, yolo_runtime_info_v1_t*);
typedef yolo_status_t (*infer_image_fn)(
yolo_runtime_t*,
const yolo_image_view_v1_t*,
const yolo_infer_options_v1_t*,
yolo_result_set_t**,
yolo_error_info_v1_t*);
typedef yolo_status_t (*get_count_fn)(const yolo_result_set_t*, uint32_t*);
typedef void (*release_fn)(yolo_result_set_t*);
typedef void (*destroy_fn)(yolo_runtime_t*);
_Static_assert(YOLO_RUNTIME_ABI_VERSION == 5u, "Runtime ABI version changed");
_Static_assert(YOLO_IMAGE_VIEW_ABI_VERSION == 1u, "Image view version changed");
_Static_assert(YOLO_INFER_OPTIONS_VERSION == 1u, "Infer-options version changed");
_Static_assert(YOLO_LABEL_LENGTH == 64u, "Label length changed");
_Static_assert(YOLO_SEG_GEOMETRY_MIN_AREA_RECT == 1, "Rectangle mode changed");
_Static_assert(YOLO_SEG_GEOMETRY_MIN_ENCLOSING_CIRCLE == 2, "Enclosing mode changed");
_Static_assert(sizeof(yolo_seg_geometry_v1_t) == 68, "Geometry ABI 5 size changed");
_Static_assert(offsetof(yolo_seg_geometry_v1_t, radius) == 32, "Radius ABI offset changed");
_Static_assert(offsetof(yolo_seg_geometry_v1_t, fit_status) == 36, "Fit status must use reserved word");
_Static_assert(YOLO_STATUS_OK == 0, "OK status changed");
_Static_assert(YOLO_STATUS_INVALID_ARGUMENT == -1, "Invalid-argument status changed");
_Static_assert(YOLO_STATUS_ABI_MISMATCH == -5, "ABI-mismatch status changed");
_Static_assert(YOLO_STATUS_BUFFER_TOO_SMALL == -6, "Buffer status changed");
_Static_assert(YOLO_STATUS_RESULT_NOT_AVAILABLE == -7, "Availability status changed");
_Static_assert(YOLO_STATUS_INVALID_CONFIG == -8, "Config status changed");
_Static_assert(YOLO_STATUS_INDEX_OUT_OF_RANGE == -9, "Index status changed");
ASSERT_FIELD_ORDER(yolo_image_view_v1_t, struct_size, version);
ASSERT_FIELD_ORDER(yolo_image_view_v1_t, version, data);
ASSERT_FIELD_ORDER(yolo_image_view_v1_t, data, width);
ASSERT_FIELD_ORDER(yolo_infer_options_v1_t, struct_size, version);
ASSERT_FIELD_ORDER(yolo_infer_options_v1_t, version, seg_geometry_mode);
ASSERT_FIELD_ORDER(yolo_runtime_info_v1_t, struct_size, version);
ASSERT_FIELD_ORDER(yolo_runtime_info_v1_t, abi_version, task);
ASSERT_FIELD_ORDER(yolo_result_common_v1_t, task, class_id);
ASSERT_FIELD_ORDER(yolo_result_common_v1_t, class_id, score);
ASSERT_FIELD_ORDER(yolo_result_common_v1_t, score, label);
ASSERT_FIELD_ORDER(yolo_bbox_v1_t, x, y);
ASSERT_FIELD_ORDER(yolo_bbox_v1_t, y, width);
ASSERT_FIELD_ORDER(yolo_rotated_rect_v1_t, center_x, center_y);
ASSERT_FIELD_ORDER(yolo_seg_geometry_v1_t, type, center_x);
ASSERT_FIELD_ORDER(yolo_seg_geometry_v1_t, angle_radians, radius);
ASSERT_FIELD_ORDER(yolo_mask_view_v1_t, data, width);
ASSERT_FIELD_ORDER(yolo_mask_view_v1_t, row_stride_bytes, origin_x);
int main(void) {
unsigned char rgb_ids[3] = {1, 2, 3};
if (yolo_masks_compose_rgb_ids(NULL, 0, 1, 1, rgb_ids, 3, sizeof(rgb_ids), NULL) != YOLO_STATUS_OK ||
rgb_ids[0] || rgb_ids[1] || rgb_ids[2]) return 2;
yolo_image_view_v1_t image = {0};
yolo_infer_options_v1_t options = {0};
yolo_error_info_v1_t error = {0};
get_abi_version_fn get_abi_version = yolo_runtime_get_abi_version;
create_fn create_runtime = yolo_runtime_create;
get_info_fn get_info = yolo_runtime_get_info;
infer_image_fn infer_image = yolo_runtime_infer_image;
get_count_fn get_count = yolo_result_set_get_count;
release_fn release_results = yolo_result_set_release;
destroy_fn destroy_runtime = yolo_runtime_destroy;
image.struct_size = sizeof(image);
image.version = YOLO_IMAGE_VIEW_ABI_VERSION;
image.pixel_format = YOLO_PIXEL_FORMAT_RGB888;
image.width = 640;
image.height = 480;
options.struct_size = sizeof(options);
options.version = YOLO_INFER_OPTIONS_VERSION;
options.seg_geometry_mode = YOLO_SEG_GEOMETRY_NONE;
error.struct_size = sizeof(error);
error.version = YOLO_ERROR_INFO_VERSION;
(void)create_runtime;
(void)get_info;
(void)infer_image;
(void)get_count;
(void)release_results;
(void)destroy_runtime;
return get_abi_version() == YOLO_RUNTIME_ABI_VERSION ? 0 : 1;
}