| 1 | /* Tencent is pleased to support the open source community by making ncnn available. |
| 2 | * |
| 3 | * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | * |
| 5 | * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except |
| 6 | * in compliance with the License. You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://opensource.org/licenses/BSD-3-Clause |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software distributed |
| 11 | * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | * CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | * specific language governing permissions and limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #ifndef NCNN_C_API_H |
| 17 | #define NCNN_C_API_H |
| 18 | |
| 19 | #include "platform.h" |
| 20 | |
| 21 | #if NCNN_C_API |
| 22 | |
| 23 | #include <stddef.h> |
| 24 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | NCNN_EXPORT const char* ncnn_version(void); |
| 30 | |
| 31 | /* allocator api */ |
| 32 | typedef struct __ncnn_allocator_t* ncnn_allocator_t; |
| 33 | struct NCNN_EXPORT __ncnn_allocator_t |
| 34 | { |
| 35 | void* pthis; |
| 36 | |
| 37 | void* (*fast_malloc)(ncnn_allocator_t allocator, size_t size); |
| 38 | void (*fast_free)(ncnn_allocator_t allocator, void* ptr); |
| 39 | }; |
| 40 | |
| 41 | NCNN_EXPORT ncnn_allocator_t ncnn_allocator_create_pool_allocator(void); |
| 42 | NCNN_EXPORT ncnn_allocator_t ncnn_allocator_create_unlocked_pool_allocator(void); |
| 43 | NCNN_EXPORT void ncnn_allocator_destroy(ncnn_allocator_t allocator); |
| 44 | |
| 45 | /* option api */ |
| 46 | typedef struct __ncnn_option_t* ncnn_option_t; |
| 47 | |
| 48 | NCNN_EXPORT ncnn_option_t ncnn_option_create(void); |
| 49 | NCNN_EXPORT void ncnn_option_destroy(ncnn_option_t opt); |
| 50 | |
| 51 | NCNN_EXPORT int ncnn_option_get_num_threads(const ncnn_option_t opt); |
| 52 | NCNN_EXPORT void ncnn_option_set_num_threads(ncnn_option_t opt, int num_threads); |
| 53 | |
| 54 | NCNN_EXPORT int ncnn_option_get_use_local_pool_allocator(const ncnn_option_t opt); |
| 55 | NCNN_EXPORT void ncnn_option_set_use_local_pool_allocator(ncnn_option_t opt, int use_local_pool_allocator); |
| 56 | |
| 57 | NCNN_EXPORT void ncnn_option_set_blob_allocator(ncnn_option_t opt, ncnn_allocator_t allocator); |
| 58 | NCNN_EXPORT void ncnn_option_set_workspace_allocator(ncnn_option_t opt, ncnn_allocator_t allocator); |
| 59 | |
| 60 | NCNN_EXPORT int ncnn_option_get_use_vulkan_compute(const ncnn_option_t opt); |
| 61 | NCNN_EXPORT void ncnn_option_set_use_vulkan_compute(ncnn_option_t opt, int use_vulkan_compute); |
| 62 | |
| 63 | /* mat api */ |
| 64 | typedef struct __ncnn_mat_t* ncnn_mat_t; |
| 65 | |
| 66 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create(void); |
| 67 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_1d(int w, ncnn_allocator_t allocator); |
| 68 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_2d(int w, int h, ncnn_allocator_t allocator); |
| 69 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_3d(int w, int h, int c, ncnn_allocator_t allocator); |
| 70 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_4d(int w, int h, int d, int c, ncnn_allocator_t allocator); |
| 71 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_1d(int w, void* data, ncnn_allocator_t allocator); |
| 72 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_2d(int w, int h, void* data, ncnn_allocator_t allocator); |
| 73 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_3d(int w, int h, int c, void* data, ncnn_allocator_t allocator); |
| 74 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_4d(int w, int h, int d, int c, void* data, ncnn_allocator_t allocator); |
| 75 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_1d_elem(int w, size_t elemsize, int elempack, ncnn_allocator_t allocator); |
| 76 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_2d_elem(int w, int h, size_t elemsize, int elempack, ncnn_allocator_t allocator); |
| 77 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_3d_elem(int w, int h, int c, size_t elemsize, int elempack, ncnn_allocator_t allocator); |
| 78 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_4d_elem(int w, int h, int d, int c, size_t elemsize, int elempack, ncnn_allocator_t allocator); |
| 79 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_1d_elem(int w, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator); |
| 80 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_2d_elem(int w, int h, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator); |
| 81 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_3d_elem(int w, int h, int c, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator); |
| 82 | NCNN_EXPORT ncnn_mat_t ncnn_mat_create_external_4d_elem(int w, int h, int d, int c, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator); |
| 83 | NCNN_EXPORT void ncnn_mat_destroy(ncnn_mat_t mat); |
| 84 | |
| 85 | NCNN_EXPORT void ncnn_mat_fill_float(ncnn_mat_t mat, float v); |
| 86 | |
| 87 | NCNN_EXPORT ncnn_mat_t ncnn_mat_clone(const ncnn_mat_t mat, ncnn_allocator_t allocator); |
| 88 | NCNN_EXPORT ncnn_mat_t ncnn_mat_reshape_1d(const ncnn_mat_t mat, int w, ncnn_allocator_t allocator); |
| 89 | NCNN_EXPORT ncnn_mat_t ncnn_mat_reshape_2d(const ncnn_mat_t mat, int w, int h, ncnn_allocator_t allocator); |
| 90 | NCNN_EXPORT ncnn_mat_t ncnn_mat_reshape_3d(const ncnn_mat_t mat, int w, int h, int c, ncnn_allocator_t allocator); |
| 91 | NCNN_EXPORT ncnn_mat_t ncnn_mat_reshape_4d(const ncnn_mat_t mat, int w, int h, int d, int c, ncnn_allocator_t allocator); |
| 92 | |
| 93 | NCNN_EXPORT int ncnn_mat_get_dims(const ncnn_mat_t mat); |
| 94 | NCNN_EXPORT int ncnn_mat_get_w(const ncnn_mat_t mat); |
| 95 | NCNN_EXPORT int ncnn_mat_get_h(const ncnn_mat_t mat); |
| 96 | NCNN_EXPORT int ncnn_mat_get_d(const ncnn_mat_t mat); |
| 97 | NCNN_EXPORT int ncnn_mat_get_c(const ncnn_mat_t mat); |
| 98 | NCNN_EXPORT size_t ncnn_mat_get_elemsize(const ncnn_mat_t mat); |
| 99 | NCNN_EXPORT int ncnn_mat_get_elempack(const ncnn_mat_t mat); |
| 100 | NCNN_EXPORT size_t ncnn_mat_get_cstep(const ncnn_mat_t mat); |
| 101 | NCNN_EXPORT void* ncnn_mat_get_data(const ncnn_mat_t mat); |
| 102 | |
| 103 | NCNN_EXPORT void* ncnn_mat_get_channel_data(const ncnn_mat_t mat, int c); |
| 104 | |
| 105 | #if NCNN_PIXEL |
| 106 | |
| 107 | /* mat pixel api */ |
| 108 | #define NCNN_MAT_PIXEL_RGB 1 |
| 109 | #define NCNN_MAT_PIXEL_BGR 2 |
| 110 | #define NCNN_MAT_PIXEL_GRAY 3 |
| 111 | #define NCNN_MAT_PIXEL_RGBA 4 |
| 112 | #define NCNN_MAT_PIXEL_BGRA 5 |
| 113 | #define NCNN_MAT_PIXEL_X2Y(X, Y) (X | (Y << 16)) |
| 114 | NCNN_EXPORT ncnn_mat_t ncnn_mat_from_pixels(const unsigned char* pixels, int type, int w, int h, int stride, ncnn_allocator_t allocator); |
| 115 | NCNN_EXPORT ncnn_mat_t ncnn_mat_from_pixels_resize(const unsigned char* pixels, int type, int w, int h, int stride, int target_width, int target_height, ncnn_allocator_t allocator); |
| 116 | NCNN_EXPORT ncnn_mat_t ncnn_mat_from_pixels_roi(const unsigned char* pixels, int type, int w, int h, int stride, int roix, int roiy, int roiw, int roih, ncnn_allocator_t allocator); |
| 117 | NCNN_EXPORT ncnn_mat_t ncnn_mat_from_pixels_roi_resize(const unsigned char* pixels, int type, int w, int h, int stride, int roix, int roiy, int roiw, int roih, int target_width, int target_height, ncnn_allocator_t allocator); |
| 118 | NCNN_EXPORT void ncnn_mat_to_pixels(const ncnn_mat_t mat, unsigned char* pixels, int type, int stride); |
| 119 | NCNN_EXPORT void ncnn_mat_to_pixels_resize(const ncnn_mat_t mat, unsigned char* pixels, int type, int target_width, int target_height, int target_stride); |
| 120 | |
| 121 | #endif /* NCNN_PIXEL */ |
| 122 | |
| 123 | NCNN_EXPORT void ncnn_mat_substract_mean_normalize(ncnn_mat_t mat, const float* mean_vals, const float* norm_vals); |
| 124 | |
| 125 | NCNN_EXPORT void ncnn_convert_packing(const ncnn_mat_t src, ncnn_mat_t* dst, int elempack, const ncnn_option_t opt); |
| 126 | NCNN_EXPORT void ncnn_flatten(const ncnn_mat_t src, ncnn_mat_t* dst, const ncnn_option_t opt); |
| 127 | |
| 128 | /* blob api */ |
| 129 | typedef struct __ncnn_blob_t* ncnn_blob_t; |
| 130 | |
| 131 | #if NCNN_STRING |
| 132 | NCNN_EXPORT const char* ncnn_blob_get_name(const ncnn_blob_t blob); |
| 133 | #endif /* NCNN_STRING */ |
| 134 | |
| 135 | NCNN_EXPORT int ncnn_blob_get_producer(const ncnn_blob_t blob); |
| 136 | NCNN_EXPORT int ncnn_blob_get_consumer(const ncnn_blob_t blob); |
| 137 | |
| 138 | NCNN_EXPORT void ncnn_blob_get_shape(const ncnn_blob_t blob, int* dims, int* w, int* h, int* c); |
| 139 | |
| 140 | /* paramdict api */ |
| 141 | typedef struct __ncnn_paramdict_t* ncnn_paramdict_t; |
| 142 | |
| 143 | NCNN_EXPORT ncnn_paramdict_t ncnn_paramdict_create(void); |
| 144 | NCNN_EXPORT void ncnn_paramdict_destroy(ncnn_paramdict_t pd); |
| 145 | |
| 146 | NCNN_EXPORT int ncnn_paramdict_get_type(const ncnn_paramdict_t pd, int id); |
| 147 | |
| 148 | NCNN_EXPORT int ncnn_paramdict_get_int(const ncnn_paramdict_t pd, int id, int def); |
| 149 | NCNN_EXPORT float ncnn_paramdict_get_float(const ncnn_paramdict_t pd, int id, float def); |
| 150 | NCNN_EXPORT ncnn_mat_t ncnn_paramdict_get_array(const ncnn_paramdict_t pd, int id, const ncnn_mat_t def); |
| 151 | |
| 152 | NCNN_EXPORT void ncnn_paramdict_set_int(ncnn_paramdict_t pd, int id, int i); |
| 153 | NCNN_EXPORT void ncnn_paramdict_set_float(ncnn_paramdict_t pd, int id, float f); |
| 154 | NCNN_EXPORT void ncnn_paramdict_set_array(ncnn_paramdict_t pd, int id, const ncnn_mat_t v); |
| 155 | |
| 156 | /* datareader api */ |
| 157 | typedef struct __ncnn_datareader_t* ncnn_datareader_t; |
| 158 | struct NCNN_EXPORT __ncnn_datareader_t |
| 159 | { |
| 160 | void* pthis; |
| 161 | |
| 162 | #if NCNN_STRING |
| 163 | int (*scan)(ncnn_datareader_t dr, const char* format, void* p); |
| 164 | #endif /* NCNN_STRING */ |
| 165 | size_t (*read)(ncnn_datareader_t dr, void* buf, size_t size); |
| 166 | }; |
| 167 | |
| 168 | NCNN_EXPORT ncnn_datareader_t ncnn_datareader_create(void); |
| 169 | #if NCNN_STDIO |
| 170 | NCNN_EXPORT ncnn_datareader_t ncnn_datareader_create_from_stdio(FILE* fp); |
| 171 | #endif /* NCNN_STDIO */ |
| 172 | NCNN_EXPORT ncnn_datareader_t ncnn_datareader_create_from_memory(const unsigned char** mem); |
| 173 | NCNN_EXPORT void ncnn_datareader_destroy(ncnn_datareader_t dr); |
| 174 | |
| 175 | /* modelbin api */ |
| 176 | typedef struct __ncnn_modelbin_t* ncnn_modelbin_t; |
| 177 | struct NCNN_EXPORT __ncnn_modelbin_t |
| 178 | { |
| 179 | void* pthis; |
| 180 | |
| 181 | ncnn_mat_t (*load_1d)(const ncnn_modelbin_t mb, int w, int type); |
| 182 | ncnn_mat_t (*load_2d)(const ncnn_modelbin_t mb, int w, int h, int type); |
| 183 | ncnn_mat_t (*load_3d)(const ncnn_modelbin_t mb, int w, int h, int c, int type); |
| 184 | }; |
| 185 | |
| 186 | NCNN_EXPORT ncnn_modelbin_t ncnn_modelbin_create_from_datareader(const ncnn_datareader_t dr); |
| 187 | NCNN_EXPORT ncnn_modelbin_t ncnn_modelbin_create_from_mat_array(const ncnn_mat_t* weights, int n); |
| 188 | NCNN_EXPORT void ncnn_modelbin_destroy(ncnn_modelbin_t mb); |
| 189 | |
| 190 | /* layer api */ |
| 191 | typedef struct __ncnn_layer_t* ncnn_layer_t; |
| 192 | struct NCNN_EXPORT __ncnn_layer_t |
| 193 | { |
| 194 | void* pthis; |
| 195 | |
| 196 | int (*load_param)(ncnn_layer_t layer, const ncnn_paramdict_t pd); |
| 197 | int (*load_model)(ncnn_layer_t layer, const ncnn_modelbin_t mb); |
| 198 | |
| 199 | int (*create_pipeline)(ncnn_layer_t layer, const ncnn_option_t opt); |
| 200 | int (*destroy_pipeline)(ncnn_layer_t layer, const ncnn_option_t opt); |
| 201 | |
| 202 | int (*forward_1)(const ncnn_layer_t layer, const ncnn_mat_t bottom_blob, ncnn_mat_t* top_blob, const ncnn_option_t opt); |
| 203 | int (*forward_n)(const ncnn_layer_t layer, const ncnn_mat_t* bottom_blobs, int n, ncnn_mat_t* top_blobs, int n2, const ncnn_option_t opt); |
| 204 | |
| 205 | int (*forward_inplace_1)(const ncnn_layer_t layer, ncnn_mat_t bottom_top_blob, const ncnn_option_t opt); |
| 206 | int (*forward_inplace_n)(const ncnn_layer_t layer, ncnn_mat_t* bottom_top_blobs, int n, const ncnn_option_t opt); |
| 207 | }; |
| 208 | |
| 209 | NCNN_EXPORT ncnn_layer_t ncnn_layer_create(void); |
| 210 | NCNN_EXPORT ncnn_layer_t ncnn_layer_create_by_typeindex(int typeindex); |
| 211 | #if NCNN_STRING |
| 212 | NCNN_EXPORT ncnn_layer_t ncnn_layer_create_by_type(const char* type); |
| 213 | NCNN_EXPORT int ncnn_layer_type_to_index(const char* type); |
| 214 | #endif /* NCNN_STRING */ |
| 215 | NCNN_EXPORT void ncnn_layer_destroy(ncnn_layer_t layer); |
| 216 | |
| 217 | #if NCNN_STRING |
| 218 | NCNN_EXPORT const char* ncnn_layer_get_name(const ncnn_layer_t layer); |
| 219 | #endif /* NCNN_STRING */ |
| 220 | |
| 221 | NCNN_EXPORT int ncnn_layer_get_typeindex(const ncnn_layer_t layer); |
| 222 | #if NCNN_STRING |
| 223 | NCNN_EXPORT const char* ncnn_layer_get_type(const ncnn_layer_t layer); |
| 224 | #endif /* NCNN_STRING */ |
| 225 | |
| 226 | NCNN_EXPORT int ncnn_layer_get_one_blob_only(const ncnn_layer_t layer); |
| 227 | NCNN_EXPORT int ncnn_layer_get_support_inplace(const ncnn_layer_t layer); |
| 228 | NCNN_EXPORT int ncnn_layer_get_support_vulkan(const ncnn_layer_t layer); |
| 229 | NCNN_EXPORT int ncnn_layer_get_support_packing(const ncnn_layer_t layer); |
| 230 | NCNN_EXPORT int ncnn_layer_get_support_bf16_storage(const ncnn_layer_t layer); |
| 231 | NCNN_EXPORT int ncnn_layer_get_support_fp16_storage(const ncnn_layer_t layer); |
| 232 | NCNN_EXPORT int ncnn_layer_get_support_image_storage(const ncnn_layer_t layer); |
| 233 | |
| 234 | NCNN_EXPORT void ncnn_layer_set_one_blob_only(ncnn_layer_t layer, int enable); |
| 235 | NCNN_EXPORT void ncnn_layer_set_support_inplace(ncnn_layer_t layer, int enable); |
| 236 | NCNN_EXPORT void ncnn_layer_set_support_vulkan(ncnn_layer_t layer, int enable); |
| 237 | NCNN_EXPORT void ncnn_layer_set_support_packing(ncnn_layer_t layer, int enable); |
| 238 | NCNN_EXPORT void ncnn_layer_set_support_bf16_storage(ncnn_layer_t layer, int enable); |
| 239 | NCNN_EXPORT void ncnn_layer_set_support_fp16_storage(ncnn_layer_t layer, int enable); |
| 240 | NCNN_EXPORT void ncnn_layer_set_support_image_storage(ncnn_layer_t layer, int enable); |
| 241 | |
| 242 | NCNN_EXPORT int ncnn_layer_get_bottom_count(const ncnn_layer_t layer); |
| 243 | NCNN_EXPORT int ncnn_layer_get_bottom(const ncnn_layer_t layer, int i); |
| 244 | NCNN_EXPORT int ncnn_layer_get_top_count(const ncnn_layer_t layer); |
| 245 | NCNN_EXPORT int ncnn_layer_get_top(const ncnn_layer_t layer, int i); |
| 246 | |
| 247 | NCNN_EXPORT void ncnn_blob_get_bottom_shape(const ncnn_layer_t layer, int i, int* dims, int* w, int* h, int* c); |
| 248 | NCNN_EXPORT void ncnn_blob_get_top_shape(const ncnn_layer_t layer, int i, int* dims, int* w, int* h, int* c); |
| 249 | |
| 250 | /* layer factory function */ |
| 251 | typedef ncnn_layer_t (*ncnn_layer_creator_t)(void* userdata); |
| 252 | typedef void (*ncnn_layer_destroyer_t)(ncnn_layer_t layer, void* userdata); |
| 253 | |
| 254 | typedef struct __ncnn_net_custom_layer_factory_t* ncnn_net_custom_layer_factory_t; |
| 255 | struct __ncnn_net_custom_layer_factory_t |
| 256 | { |
| 257 | ncnn_layer_creator_t creator; |
| 258 | ncnn_layer_destroyer_t destroyer; |
| 259 | void* userdata; |
| 260 | ncnn_net_custom_layer_factory_t next; |
| 261 | }; |
| 262 | |
| 263 | /* net api */ |
| 264 | typedef struct __ncnn_net_t* ncnn_net_t; |
| 265 | struct __ncnn_net_t |
| 266 | { |
| 267 | void* pthis; |
| 268 | |
| 269 | ncnn_net_custom_layer_factory_t custom_layer_factory; |
| 270 | }; |
| 271 | |
| 272 | NCNN_EXPORT ncnn_net_t ncnn_net_create(void); |
| 273 | NCNN_EXPORT void ncnn_net_destroy(ncnn_net_t net); |
| 274 | |
| 275 | NCNN_EXPORT ncnn_option_t ncnn_net_get_option(ncnn_net_t net); |
| 276 | NCNN_EXPORT void ncnn_net_set_option(ncnn_net_t net, ncnn_option_t opt); |
| 277 | |
| 278 | #if NCNN_VULKAN |
| 279 | NCNN_EXPORT void ncnn_net_set_vulkan_device(ncnn_net_t net, int device_index); |
| 280 | #endif |
| 281 | |
| 282 | #if NCNN_STRING |
| 283 | NCNN_EXPORT void ncnn_net_register_custom_layer_by_type(ncnn_net_t net, const char* type, ncnn_layer_creator_t creator, ncnn_layer_destroyer_t destroyer, void* userdata); |
| 284 | #endif /* NCNN_STRING */ |
| 285 | NCNN_EXPORT void ncnn_net_register_custom_layer_by_typeindex(ncnn_net_t net, int typeindex, ncnn_layer_creator_t creator, ncnn_layer_destroyer_t destroyer, void* userdata); |
| 286 | |
| 287 | #if NCNN_STDIO |
| 288 | #if NCNN_STRING |
| 289 | NCNN_EXPORT int ncnn_net_load_param(ncnn_net_t net, const char* path); |
| 290 | #endif /* NCNN_STRING */ |
| 291 | NCNN_EXPORT int ncnn_net_load_param_bin(ncnn_net_t net, const char* path); |
| 292 | NCNN_EXPORT int ncnn_net_load_model(ncnn_net_t net, const char* path); |
| 293 | #endif /* NCNN_STDIO */ |
| 294 | |
| 295 | #if NCNN_STDIO |
| 296 | #if NCNN_STRING |
| 297 | NCNN_EXPORT int ncnn_net_load_param_memory(ncnn_net_t net, const char* mem); |
| 298 | #endif /* NCNN_STRING */ |
| 299 | #endif /* NCNN_STDIO */ |
| 300 | NCNN_EXPORT int ncnn_net_load_param_bin_memory(ncnn_net_t net, const unsigned char* mem); |
| 301 | NCNN_EXPORT int ncnn_net_load_model_memory(ncnn_net_t net, const unsigned char* mem); |
| 302 | |
| 303 | #if NCNN_STRING |
| 304 | NCNN_EXPORT int ncnn_net_load_param_datareader(ncnn_net_t net, const ncnn_datareader_t dr); |
| 305 | #endif /* NCNN_STRING */ |
| 306 | NCNN_EXPORT int ncnn_net_load_param_bin_datareader(ncnn_net_t net, const ncnn_datareader_t dr); |
| 307 | NCNN_EXPORT int ncnn_net_load_model_datareader(ncnn_net_t net, const ncnn_datareader_t dr); |
| 308 | |
| 309 | NCNN_EXPORT void ncnn_net_clear(ncnn_net_t net); |
| 310 | |
| 311 | NCNN_EXPORT int ncnn_net_get_input_count(const ncnn_net_t net); |
| 312 | NCNN_EXPORT int ncnn_net_get_output_count(const ncnn_net_t net); |
| 313 | #if NCNN_STRING |
| 314 | NCNN_EXPORT const char* ncnn_net_get_input_name(const ncnn_net_t net, int i); |
| 315 | NCNN_EXPORT const char* ncnn_net_get_output_name(const ncnn_net_t net, int i); |
| 316 | #endif /* NCNN_STRING */ |
| 317 | NCNN_EXPORT int ncnn_net_get_input_index(const ncnn_net_t net, int i); |
| 318 | NCNN_EXPORT int ncnn_net_get_output_index(const ncnn_net_t net, int i); |
| 319 | |
| 320 | /* extractor api */ |
| 321 | typedef struct __ncnn_extractor_t* ncnn_extractor_t; |
| 322 | |
| 323 | NCNN_EXPORT ncnn_extractor_t ncnn_extractor_create(ncnn_net_t net); |
| 324 | NCNN_EXPORT void ncnn_extractor_destroy(ncnn_extractor_t ex); |
| 325 | |
| 326 | NCNN_EXPORT void ncnn_extractor_set_option(ncnn_extractor_t ex, const ncnn_option_t opt); |
| 327 | |
| 328 | #if NCNN_STRING |
| 329 | NCNN_EXPORT int ncnn_extractor_input(ncnn_extractor_t ex, const char* name, const ncnn_mat_t mat); |
| 330 | NCNN_EXPORT int ncnn_extractor_extract(ncnn_extractor_t ex, const char* name, ncnn_mat_t* mat); |
| 331 | #endif /* NCNN_STRING */ |
| 332 | NCNN_EXPORT int ncnn_extractor_input_index(ncnn_extractor_t ex, int index, const ncnn_mat_t mat); |
| 333 | NCNN_EXPORT int ncnn_extractor_extract_index(ncnn_extractor_t ex, int index, ncnn_mat_t* mat); |
| 334 | |
| 335 | /* mat process api */ |
| 336 | #define NCNN_BORDER_CONSTANT 0 |
| 337 | #define NCNN_BORDER_REPLICATE 1 |
| 338 | #define NCNN_BORDER_REFLECT 2 |
| 339 | #define NCNN_BORDER_TRANSPARENT -233 |
| 340 | NCNN_EXPORT void ncnn_copy_make_border(const ncnn_mat_t src, ncnn_mat_t dst, int top, int bottom, int left, int right, int type, float v, const ncnn_option_t opt); |
| 341 | NCNN_EXPORT void ncnn_copy_make_border_3d(const ncnn_mat_t src, ncnn_mat_t dst, int top, int bottom, int left, int right, int front, int behind, int type, float v, const ncnn_option_t opt); |
| 342 | NCNN_EXPORT void ncnn_copy_cut_border(const ncnn_mat_t src, ncnn_mat_t dst, int top, int bottom, int left, int right, const ncnn_option_t opt); |
| 343 | NCNN_EXPORT void ncnn_copy_cut_border_3d(const ncnn_mat_t src, ncnn_mat_t dst, int top, int bottom, int left, int right, int front, int behind, const ncnn_option_t opt); |
| 344 | |
| 345 | #if NCNN_PIXEL_DRAWING |
| 346 | /* mat pixel drawing api*/ |
| 347 | NCNN_EXPORT void ncnn_draw_rectangle_c1(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness); |
| 348 | NCNN_EXPORT void ncnn_draw_rectangle_c2(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness); |
| 349 | NCNN_EXPORT void ncnn_draw_rectangle_c3(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness); |
| 350 | NCNN_EXPORT void ncnn_draw_rectangle_c4(unsigned char* pixels, int w, int h, int rx, int ry, int rw, int rh, unsigned int color, int thickness); |
| 351 | |
| 352 | NCNN_EXPORT void ncnn_draw_text_c1(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color); |
| 353 | NCNN_EXPORT void ncnn_draw_text_c2(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color); |
| 354 | NCNN_EXPORT void ncnn_draw_text_c3(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color); |
| 355 | NCNN_EXPORT void ncnn_draw_text_c4(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color); |
| 356 | |
| 357 | NCNN_EXPORT void ncnn_draw_circle_c1(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness); |
| 358 | NCNN_EXPORT void ncnn_draw_circle_c2(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness); |
| 359 | NCNN_EXPORT void ncnn_draw_circle_c3(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness); |
| 360 | NCNN_EXPORT void ncnn_draw_circle_c4(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness); |
| 361 | |
| 362 | NCNN_EXPORT void ncnn_draw_line_c1(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness); |
| 363 | NCNN_EXPORT void ncnn_draw_line_c2(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness); |
| 364 | NCNN_EXPORT void ncnn_draw_line_c3(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness); |
| 365 | NCNN_EXPORT void ncnn_draw_line_c4(unsigned char* pixels, int w, int h, int x0, int y0, int x1, int y1, unsigned int color, int thickness); |
| 366 | #endif /* NCNN_PIXEL_DRAWING */ |
| 367 | |
| 368 | #ifdef __cplusplus |
| 369 | } /* extern "C" */ |
| 370 | #endif |
| 371 | |
| 372 | #endif /* NCNN_C_API */ |
| 373 | |
| 374 | #endif /* NCNN_C_API_H */ |