1
/* Tencent is pleased to support the open source community by making ncnn available.
3
* Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
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
8
* https://opensource.org/licenses/BSD-3-Clause
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.
26
#include "datareader.h"
36
using ncnn::DataReader;
49
const char* ncnn_version()
51
return NCNN_VERSION_STRING;
55
class PoolAllocator_c_api : public ncnn::PoolAllocator
58
PoolAllocator_c_api(ncnn_allocator_t _allocator)
59
: ncnn::PoolAllocator()
61
allocator = _allocator;
64
virtual void* fastMalloc(size_t size)
66
return allocator->fast_malloc(allocator, size);
69
virtual void fastFree(void* ptr)
71
return allocator->fast_free(allocator, ptr);
75
ncnn_allocator_t allocator;
78
static void* __ncnn_PoolAllocator_fast_malloc(ncnn_allocator_t allocator, size_t size)
80
return ((ncnn::PoolAllocator*)allocator->pthis)->ncnn::PoolAllocator::fastMalloc(size);
83
static void __ncnn_PoolAllocator_fast_free(ncnn_allocator_t allocator, void* ptr)
85
((ncnn::PoolAllocator*)allocator->pthis)->ncnn::PoolAllocator::fastFree(ptr);
88
class UnlockedPoolAllocator_c_api : public ncnn::UnlockedPoolAllocator
91
UnlockedPoolAllocator_c_api(ncnn_allocator_t _allocator)
92
: ncnn::UnlockedPoolAllocator()
94
allocator = _allocator;
97
virtual void* fastMalloc(size_t size)
99
return allocator->fast_malloc(allocator, size);
102
virtual void fastFree(void* ptr)
104
return allocator->fast_free(allocator, ptr);
108
ncnn_allocator_t allocator;
111
static void* __ncnn_UnlockedPoolAllocator_fast_malloc(ncnn_allocator_t allocator, size_t size)
113
return ((ncnn::UnlockedPoolAllocator*)allocator->pthis)->ncnn::UnlockedPoolAllocator::fastMalloc(size);
116
static void __ncnn_UnlockedPoolAllocator_fast_free(ncnn_allocator_t allocator, void* ptr)
118
((ncnn::UnlockedPoolAllocator*)allocator->pthis)->ncnn::UnlockedPoolAllocator::fastFree(ptr);
121
ncnn_allocator_t ncnn_allocator_create_pool_allocator()
123
ncnn_allocator_t allocator = (ncnn_allocator_t)malloc(sizeof(struct __ncnn_allocator_t));
124
allocator->pthis = (void*)(new PoolAllocator_c_api(allocator));
125
allocator->fast_malloc = __ncnn_PoolAllocator_fast_malloc;
126
allocator->fast_free = __ncnn_PoolAllocator_fast_free;
130
ncnn_allocator_t ncnn_allocator_create_unlocked_pool_allocator()
132
ncnn_allocator_t allocator = (ncnn_allocator_t)malloc(sizeof(struct __ncnn_allocator_t));
133
allocator->pthis = (void*)(new UnlockedPoolAllocator_c_api(allocator));
134
allocator->fast_malloc = __ncnn_UnlockedPoolAllocator_fast_malloc;
135
allocator->fast_free = __ncnn_UnlockedPoolAllocator_fast_free;
139
void ncnn_allocator_destroy(ncnn_allocator_t allocator)
143
delete (Allocator*)allocator->pthis;
149
ncnn_option_t ncnn_option_create()
151
return (ncnn_option_t)(new Option());
154
void ncnn_option_destroy(ncnn_option_t opt)
159
int ncnn_option_get_num_threads(const ncnn_option_t opt)
161
return ((const Option*)opt)->num_threads;
164
void ncnn_option_set_num_threads(ncnn_option_t opt, int num_threads)
166
((Option*)opt)->num_threads = num_threads;
169
int ncnn_option_get_use_local_pool_allocator(const ncnn_option_t opt)
171
return ((Option*)opt)->use_local_pool_allocator;
174
void ncnn_option_set_use_local_pool_allocator(ncnn_option_t opt, int use_local_pool_allocator)
176
((Option*)opt)->use_local_pool_allocator = use_local_pool_allocator;
179
void ncnn_option_set_blob_allocator(ncnn_option_t opt, ncnn_allocator_t allocator)
181
((Option*)opt)->blob_allocator = allocator ? (Allocator*)allocator->pthis : NULL;
184
void ncnn_option_set_workspace_allocator(ncnn_option_t opt, ncnn_allocator_t allocator)
186
((Option*)opt)->workspace_allocator = allocator ? (Allocator*)allocator->pthis : NULL;
189
int ncnn_option_get_use_vulkan_compute(const ncnn_option_t opt)
192
return ((const Option*)opt)->use_vulkan_compute;
199
void ncnn_option_set_use_vulkan_compute(ncnn_option_t opt, int use_vulkan_compute)
202
((Option*)opt)->use_vulkan_compute = use_vulkan_compute;
205
(void)use_vulkan_compute;
210
ncnn_mat_t ncnn_mat_create()
212
return (ncnn_mat_t)(new Mat());
215
ncnn_mat_t ncnn_mat_create_1d(int w, ncnn_allocator_t allocator)
217
return (ncnn_mat_t)(new Mat(w, (size_t)4u, allocator ? (Allocator*)allocator->pthis : NULL));
220
ncnn_mat_t ncnn_mat_create_2d(int w, int h, ncnn_allocator_t allocator)
222
return (ncnn_mat_t)(new Mat(w, h, (size_t)4u, allocator ? (Allocator*)allocator->pthis : NULL));
225
ncnn_mat_t ncnn_mat_create_3d(int w, int h, int c, ncnn_allocator_t allocator)
227
return (ncnn_mat_t)(new Mat(w, h, c, (size_t)4u, allocator ? (Allocator*)allocator->pthis : NULL));
230
ncnn_mat_t ncnn_mat_create_4d(int w, int h, int d, int c, ncnn_allocator_t allocator)
232
return (ncnn_mat_t)(new Mat(w, h, d, c, (size_t)4u, allocator ? (Allocator*)allocator->pthis : NULL));
235
ncnn_mat_t ncnn_mat_create_external_1d(int w, void* data, ncnn_allocator_t allocator)
237
return (ncnn_mat_t)(new Mat(w, data, (size_t)4u, allocator ? (Allocator*)allocator->pthis : NULL));
240
ncnn_mat_t ncnn_mat_create_external_2d(int w, int h, void* data, ncnn_allocator_t allocator)
242
return (ncnn_mat_t)(new Mat(w, h, data, (size_t)4u, allocator ? (Allocator*)allocator->pthis : NULL));
245
ncnn_mat_t ncnn_mat_create_external_3d(int w, int h, int c, void* data, ncnn_allocator_t allocator)
247
return (ncnn_mat_t)(new Mat(w, h, c, data, (size_t)4u, allocator ? (Allocator*)allocator->pthis : NULL));
250
ncnn_mat_t ncnn_mat_create_external_4d(int w, int h, int d, int c, void* data, ncnn_allocator_t allocator)
252
return (ncnn_mat_t)(new Mat(w, h, d, c, data, (size_t)4u, allocator ? (Allocator*)allocator->pthis : NULL));
255
ncnn_mat_t ncnn_mat_create_1d_elem(int w, size_t elemsize, int elempack, ncnn_allocator_t allocator)
257
return (ncnn_mat_t)(new Mat(w, elemsize, elempack, allocator ? (Allocator*)allocator->pthis : NULL));
260
ncnn_mat_t ncnn_mat_create_2d_elem(int w, int h, size_t elemsize, int elempack, ncnn_allocator_t allocator)
262
return (ncnn_mat_t)(new Mat(w, h, elemsize, elempack, allocator ? (Allocator*)allocator->pthis : NULL));
265
ncnn_mat_t ncnn_mat_create_3d_elem(int w, int h, int c, size_t elemsize, int elempack, ncnn_allocator_t allocator)
267
return (ncnn_mat_t)(new Mat(w, h, c, elemsize, elempack, allocator ? (Allocator*)allocator->pthis : NULL));
270
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)
272
return (ncnn_mat_t)(new Mat(w, h, d, c, elemsize, elempack, allocator ? (Allocator*)allocator->pthis : NULL));
275
ncnn_mat_t ncnn_mat_create_external_1d_elem(int w, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator)
277
return (ncnn_mat_t)(new Mat(w, data, elemsize, elempack, allocator ? (Allocator*)allocator->pthis : NULL));
280
ncnn_mat_t ncnn_mat_create_external_2d_elem(int w, int h, void* data, size_t elemsize, int elempack, ncnn_allocator_t allocator)
282
return (ncnn_mat_t)(new Mat(w, h, data, elemsize, elempack, allocator ? (Allocator*)allocator->pthis : NULL));
285
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)
287
return (ncnn_mat_t)(new Mat(w, h, c, data, elemsize, elempack, allocator ? (Allocator*)allocator->pthis : NULL));
290
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)
292
return (ncnn_mat_t)(new Mat(w, h, d, c, data, elemsize, elempack, allocator ? (Allocator*)allocator->pthis : NULL));
295
void ncnn_mat_destroy(ncnn_mat_t mat)
300
void ncnn_mat_fill_float(ncnn_mat_t mat, float v)
302
((Mat*)mat)->fill(v);
305
ncnn_mat_t ncnn_mat_clone(const ncnn_mat_t mat, ncnn_allocator_t allocator)
307
return (ncnn_mat_t)(new Mat(((const Mat*)mat)->clone(allocator ? (Allocator*)allocator->pthis : NULL)));
310
ncnn_mat_t ncnn_mat_reshape_1d(const ncnn_mat_t mat, int w, ncnn_allocator_t allocator)
312
return (ncnn_mat_t)(new Mat(((const Mat*)mat)->reshape(w, allocator ? (Allocator*)allocator->pthis : NULL)));
315
ncnn_mat_t ncnn_mat_reshape_2d(const ncnn_mat_t mat, int w, int h, ncnn_allocator_t allocator)
317
return (ncnn_mat_t)(new Mat(((const Mat*)mat)->reshape(w, h, allocator ? (Allocator*)allocator->pthis : NULL)));
320
ncnn_mat_t ncnn_mat_reshape_3d(const ncnn_mat_t mat, int w, int h, int c, ncnn_allocator_t allocator)
322
return (ncnn_mat_t)(new Mat(((const Mat*)mat)->reshape(w, h, c, allocator ? (Allocator*)allocator->pthis : NULL)));
325
ncnn_mat_t ncnn_mat_reshape_4d(const ncnn_mat_t mat, int w, int h, int d, int c, ncnn_allocator_t allocator)
327
return (ncnn_mat_t)(new Mat(((const Mat*)mat)->reshape(w, h, d, c, allocator ? (Allocator*)allocator->pthis : NULL)));
330
int ncnn_mat_get_dims(const ncnn_mat_t mat)
332
return ((const Mat*)mat)->dims;
335
int ncnn_mat_get_w(const ncnn_mat_t mat)
337
return ((const Mat*)mat)->w;
340
int ncnn_mat_get_h(const ncnn_mat_t mat)
342
return ((const Mat*)mat)->h;
345
int ncnn_mat_get_d(const ncnn_mat_t mat)
347
return ((const Mat*)mat)->d;
350
int ncnn_mat_get_c(const ncnn_mat_t mat)
352
return ((const Mat*)mat)->c;
355
size_t ncnn_mat_get_elemsize(const ncnn_mat_t mat)
357
return ((const Mat*)mat)->elemsize;
360
int ncnn_mat_get_elempack(const ncnn_mat_t mat)
362
return ((const Mat*)mat)->elempack;
365
size_t ncnn_mat_get_cstep(const ncnn_mat_t mat)
367
return ((const Mat*)mat)->cstep;
370
void* ncnn_mat_get_data(const ncnn_mat_t mat)
372
return ((const Mat*)mat)->data;
375
void* ncnn_mat_get_channel_data(const ncnn_mat_t mat, int c)
377
return ((const Mat*)mat)->channel(c).data;
383
ncnn_mat_t ncnn_mat_from_pixels(const unsigned char* pixels, int type, int w, int h, int stride, ncnn_allocator_t allocator)
385
return (ncnn_mat_t)(new Mat(Mat::from_pixels(pixels, type, w, h, stride, allocator ? (Allocator*)allocator->pthis : NULL)));
388
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)
390
return (ncnn_mat_t)(new Mat(Mat::from_pixels_resize(pixels, type, w, h, stride, target_width, target_height, allocator ? (Allocator*)allocator->pthis : NULL)));
393
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)
395
return (ncnn_mat_t)(new Mat(Mat::from_pixels_roi(pixels, type, w, h, stride, roix, roiy, roiw, roih, allocator ? (Allocator*)allocator->pthis : NULL)));
398
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)
400
return (ncnn_mat_t)(new Mat(Mat::from_pixels_roi_resize(pixels, type, w, h, stride, roix, roiy, roiw, roih, target_width, target_height, allocator ? (Allocator*)allocator->pthis : NULL)));
403
void ncnn_mat_to_pixels(const ncnn_mat_t mat, unsigned char* pixels, int type, int stride)
405
((const Mat*)mat)->to_pixels(pixels, type, stride);
408
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)
410
((const Mat*)mat)->to_pixels_resize(pixels, type, target_width, target_height, target_stride);
413
#endif /* NCNN_PIXEL */
415
void ncnn_mat_substract_mean_normalize(ncnn_mat_t mat, const float* mean_vals, const float* norm_vals)
417
((Mat*)mat)->substract_mean_normalize(mean_vals, norm_vals);
420
void ncnn_convert_packing(const ncnn_mat_t src, ncnn_mat_t* dst, int elempack, const ncnn_option_t opt)
423
ncnn::convert_packing(*(const Mat*)src, _dst, elempack, *(Option*)opt);
424
*dst = (ncnn_mat_t)(new Mat(_dst));
427
void ncnn_flatten(const ncnn_mat_t src, ncnn_mat_t* dst, const ncnn_option_t opt)
430
ncnn::flatten(*(const Mat*)src, _dst, *(Option*)opt);
431
*dst = (ncnn_mat_t)(new Mat(_dst));
436
const char* ncnn_blob_get_name(const ncnn_blob_t blob)
438
return ((const Blob*)blob)->name.c_str();
440
#endif /* NCNN_STRING */
442
int ncnn_blob_get_producer(const ncnn_blob_t blob)
444
return ((const Blob*)blob)->producer;
447
int ncnn_blob_get_consumer(const ncnn_blob_t blob)
449
return ((const Blob*)blob)->consumer;
452
void ncnn_blob_get_shape(const ncnn_blob_t blob, int* dims, int* w, int* h, int* c)
454
const Mat& shape = ((const Blob*)blob)->shape;
462
ncnn_paramdict_t ncnn_paramdict_create()
464
return (ncnn_paramdict_t)(new ParamDict());
467
void ncnn_paramdict_destroy(ncnn_paramdict_t pd)
469
delete (ParamDict*)pd;
472
int ncnn_paramdict_get_type(const ncnn_paramdict_t pd, int id)
474
return ((const ParamDict*)pd)->type(id);
477
int ncnn_paramdict_get_int(const ncnn_paramdict_t pd, int id, int def)
479
return ((const ParamDict*)pd)->get(id, def);
482
float ncnn_paramdict_get_float(const ncnn_paramdict_t pd, int id, float def)
484
return ((const ParamDict*)pd)->get(id, def);
487
ncnn_mat_t ncnn_paramdict_get_array(ncnn_paramdict_t pd, int id, const ncnn_mat_t def)
489
return (ncnn_mat_t)(new Mat(((const ParamDict*)pd)->get(id, *(const Mat*)def)));
492
void ncnn_paramdict_set_int(ncnn_paramdict_t pd, int id, int i)
494
return ((ParamDict*)pd)->set(id, i);
497
void ncnn_paramdict_set_float(ncnn_paramdict_t pd, int id, float f)
499
return ((ParamDict*)pd)->set(id, f);
502
void ncnn_paramdict_set_array(ncnn_paramdict_t pd, int id, ncnn_mat_t v)
504
return ((ParamDict*)pd)->set(id, *(const Mat*)v);
508
class DataReader_c_api : public ncnn::DataReader
511
DataReader_c_api(ncnn_datareader_t _dr)
518
virtual int scan(const char* format, void* p) const
520
return dr->scan(dr, format, p);
522
#endif /* NCNN_STRING */
524
virtual size_t read(void* buf, size_t size) const
526
return dr->read(dr, buf, size);
530
ncnn_datareader_t dr;
534
static int __ncnn_DataReader_scan(ncnn_datareader_t dr, const char* format, void* p)
536
return ((ncnn::DataReader*)dr->pthis)->ncnn::DataReader::scan(format, p);
538
#endif /* NCNN_STRING */
540
static size_t __ncnn_DataReader_read(ncnn_datareader_t dr, void* buf, size_t size)
542
return ((ncnn::DataReader*)dr->pthis)->ncnn::DataReader::read(buf, size);
546
class DataReaderFromStdio_c_api : public ncnn::DataReaderFromStdio
549
DataReaderFromStdio_c_api(FILE* fp, ncnn_datareader_t _dr)
550
: ncnn::DataReaderFromStdio(fp)
556
virtual int scan(const char* format, void* p) const
558
return dr->scan(dr, format, p);
560
#endif /* NCNN_STRING */
562
virtual size_t read(void* buf, size_t size) const
564
return dr->read(dr, buf, size);
568
ncnn_datareader_t dr;
572
static int __ncnn_DataReaderFromStdio_scan(ncnn_datareader_t dr, const char* format, void* p)
574
return ((ncnn::DataReaderFromStdio*)dr->pthis)->ncnn::DataReaderFromStdio::scan(format, p);
576
#endif /* NCNN_STRING */
578
static size_t __ncnn_DataReaderFromStdio_read(ncnn_datareader_t dr, void* buf, size_t size)
580
return ((ncnn::DataReaderFromStdio*)dr->pthis)->ncnn::DataReaderFromStdio::read(buf, size);
582
#endif /* NCNN_STDIO */
584
class DataReaderFromMemory_c_api : public ncnn::DataReaderFromMemory
587
DataReaderFromMemory_c_api(const unsigned char*& mem, ncnn_datareader_t _dr)
588
: ncnn::DataReaderFromMemory(mem)
594
virtual int scan(const char* format, void* p) const
596
return dr->scan(dr, format, p);
598
#endif /* NCNN_STRING */
600
virtual size_t read(void* buf, size_t size) const
602
return dr->read(dr, buf, size);
606
ncnn_datareader_t dr;
610
static int __ncnn_DataReaderFromMemory_scan(ncnn_datareader_t dr, const char* format, void* p)
612
return ((ncnn::DataReaderFromMemory*)dr->pthis)->ncnn::DataReaderFromMemory::scan(format, p);
614
#endif /* NCNN_STRING */
616
static size_t __ncnn_DataReaderFromMemory_read(ncnn_datareader_t dr, void* buf, size_t size)
618
return ((ncnn::DataReaderFromMemory*)dr->pthis)->ncnn::DataReaderFromMemory::read(buf, size);
621
ncnn_datareader_t ncnn_datareader_create()
623
ncnn_datareader_t dr = (ncnn_datareader_t)malloc(sizeof(struct __ncnn_datareader_t));
624
dr->pthis = (void*)(new DataReader_c_api(dr));
626
dr->scan = __ncnn_DataReader_scan;
627
#endif /* NCNN_STRING */
628
dr->read = __ncnn_DataReader_read;
633
ncnn_datareader_t ncnn_datareader_create_from_stdio(FILE* fp)
635
ncnn_datareader_t dr = (ncnn_datareader_t)malloc(sizeof(struct __ncnn_datareader_t));
636
dr->pthis = (void*)(new DataReaderFromStdio_c_api(fp, dr));
638
dr->scan = __ncnn_DataReaderFromStdio_scan;
639
#endif /* NCNN_STRING */
640
dr->read = __ncnn_DataReaderFromStdio_read;
643
#endif /* NCNN_STDIO */
645
ncnn_datareader_t ncnn_datareader_create_from_memory(const unsigned char** mem)
647
ncnn_datareader_t dr = (ncnn_datareader_t)malloc(sizeof(struct __ncnn_datareader_t));
648
dr->pthis = (void*)(new DataReaderFromMemory_c_api(*mem, dr));
650
dr->scan = __ncnn_DataReaderFromMemory_scan;
651
#endif /* NCNN_STRING */
652
dr->read = __ncnn_DataReaderFromMemory_read;
656
void ncnn_datareader_destroy(ncnn_datareader_t dr)
658
delete (DataReader*)dr->pthis;
663
class ModelBinFromDataReader_c_api : public ncnn::ModelBinFromDataReader
666
ModelBinFromDataReader_c_api(ncnn_modelbin_t _mb, const DataReader& dr)
667
: ncnn::ModelBinFromDataReader(dr)
672
virtual Mat load(int w, int type) const
674
ncnn_mat_t m = mb->load_1d(mb, w, type);
680
virtual Mat load(int w, int h, int type) const
682
ncnn_mat_t m = mb->load_2d(mb, w, h, type);
688
virtual Mat load(int w, int h, int c, int type) const
690
ncnn_mat_t m = mb->load_3d(mb, w, h, c, type);
700
static ncnn_mat_t __ncnn_ModelBinFromDataReader_load_1d(const ncnn_modelbin_t mb, int w, int type)
702
return (ncnn_mat_t)(new Mat(((const ncnn::ModelBinFromDataReader*)mb->pthis)->ncnn::ModelBinFromDataReader::load(w, type)));
705
static ncnn_mat_t __ncnn_ModelBinFromDataReader_load_2d(const ncnn_modelbin_t mb, int w, int h, int type)
707
return (ncnn_mat_t)(new Mat(((const ncnn::ModelBinFromDataReader*)mb->pthis)->ncnn::ModelBin::load(w, h, type)));
710
static ncnn_mat_t __ncnn_ModelBinFromDataReader_load_3d(const ncnn_modelbin_t mb, int w, int h, int c, int type)
712
return (ncnn_mat_t)(new Mat(((const ncnn::ModelBinFromDataReader*)mb->pthis)->ncnn::ModelBin::load(w, h, c, type)));
715
class ModelBinFromMatArray_c_api : public ncnn::ModelBinFromMatArray
718
ModelBinFromMatArray_c_api(ncnn_modelbin_t _mb, const Mat* weights)
719
: ncnn::ModelBinFromMatArray(weights)
724
virtual Mat load(int w, int type) const
726
ncnn_mat_t m = mb->load_1d(mb, w, type);
732
virtual Mat load(int w, int h, int type) const
734
ncnn_mat_t m = mb->load_2d(mb, w, h, type);
740
virtual Mat load(int w, int h, int c, int type) const
742
ncnn_mat_t m = mb->load_3d(mb, w, h, c, type);
752
static ncnn_mat_t __ncnn_ModelBinFromMatArray_load_1d(const ncnn_modelbin_t mb, int w, int type)
754
return (ncnn_mat_t)(new Mat(((const ncnn::ModelBinFromMatArray*)mb->pthis)->ncnn::ModelBinFromMatArray::load(w, type)));
757
static ncnn_mat_t __ncnn_ModelBinFromMatArray_load_2d(const ncnn_modelbin_t mb, int w, int h, int type)
759
return (ncnn_mat_t)(new Mat(((const ncnn::ModelBinFromMatArray*)mb->pthis)->ncnn::ModelBin::load(w, h, type)));
762
static ncnn_mat_t __ncnn_ModelBinFromMatArray_load_3d(const ncnn_modelbin_t mb, int w, int h, int c, int type)
764
return (ncnn_mat_t)(new Mat(((const ncnn::ModelBinFromMatArray*)mb->pthis)->ncnn::ModelBin::load(w, h, c, type)));
767
ncnn_modelbin_t ncnn_modelbin_create_from_datareader(const ncnn_datareader_t dr)
769
ncnn_modelbin_t mb = (ncnn_modelbin_t)malloc(sizeof(struct __ncnn_modelbin_t));
770
mb->pthis = (void*)(new ModelBinFromDataReader_c_api(mb, *(const DataReader*)dr->pthis));
771
mb->load_1d = __ncnn_ModelBinFromDataReader_load_1d;
772
mb->load_2d = __ncnn_ModelBinFromDataReader_load_2d;
773
mb->load_3d = __ncnn_ModelBinFromDataReader_load_3d;
777
ncnn_modelbin_t ncnn_modelbin_create_from_mat_array(const ncnn_mat_t* weights, int n)
779
std::vector<Mat> matarray(n);
780
for (int i = 0; i < n; i++)
782
matarray[i] = *(const Mat*)weights[i];
784
ncnn_modelbin_t mb = (ncnn_modelbin_t)malloc(sizeof(struct __ncnn_modelbin_t));
785
mb->pthis = (void*)(new ModelBinFromMatArray_c_api(mb, &matarray[0]));
786
mb->load_1d = __ncnn_ModelBinFromMatArray_load_1d;
787
mb->load_2d = __ncnn_ModelBinFromMatArray_load_2d;
788
mb->load_3d = __ncnn_ModelBinFromMatArray_load_3d;
792
void ncnn_modelbin_destroy(ncnn_modelbin_t mb)
794
delete (ModelBin*)mb->pthis;
798
static ncnn_mat_t __ncnn_modelbin_load_1d(const ncnn_modelbin_t mb, int w, int type)
800
return (ncnn_mat_t)(new Mat(((const ncnn::ModelBin*)mb->pthis)->load(w, type)));
803
static ncnn_mat_t __ncnn_modelbin_load_2d(const ncnn_modelbin_t mb, int w, int h, int type)
805
return (ncnn_mat_t)(new Mat(((const ncnn::ModelBin*)mb->pthis)->load(w, h, type)));
808
static ncnn_mat_t __ncnn_modelbin_load_3d(const ncnn_modelbin_t mb, int w, int h, int c, int type)
810
return (ncnn_mat_t)(new Mat(((const ncnn::ModelBin*)mb->pthis)->load(w, h, c, type)));
814
class Layer_c_api : public Layer
817
Layer_c_api(ncnn_layer_t _layer)
823
virtual int load_param(const ParamDict& pd)
825
return layer->load_param(layer, (ncnn_paramdict_t)&pd);
828
virtual int load_model(const ModelBin& mb)
830
struct __ncnn_modelbin_t mb0;
831
mb0.pthis = (void*)&mb;
832
mb0.load_1d = __ncnn_modelbin_load_1d;
833
mb0.load_2d = __ncnn_modelbin_load_2d;
834
mb0.load_3d = __ncnn_modelbin_load_3d;
835
return layer->load_model(layer, &mb0);
838
virtual int create_pipeline(const Option& opt)
840
return layer->create_pipeline(layer, (ncnn_option_t)&opt);
843
virtual int destroy_pipeline(const Option& opt)
845
return layer->destroy_pipeline(layer, (ncnn_option_t)&opt);
848
virtual int forward(const std::vector<Mat>& bottom_blobs, std::vector<Mat>& top_blobs, const Option& opt) const
850
const int n = bottom_blobs.size();
851
const int n2 = top_blobs.size();
852
std::vector<ncnn_mat_t> bottom_blobs0(n);
853
for (int i = 0; i < n; i++)
855
bottom_blobs0[i] = (ncnn_mat_t)&bottom_blobs[i];
857
std::vector<ncnn_mat_t> top_blobs0(n2, (ncnn_mat_t)0);
858
int ret = layer->forward_n(layer, &bottom_blobs0[0], n, &top_blobs0[0], n2, (ncnn_option_t)&opt);
859
for (int i = 0; i < n2; i++)
861
top_blobs[i] = *(Mat*)top_blobs0[i];
862
ncnn_mat_destroy(top_blobs0[i]);
867
virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const
869
ncnn_mat_t top_blob0 = 0;
870
int ret = layer->forward_1(layer, (ncnn_mat_t)&bottom_blob, &top_blob0, (ncnn_option_t)&opt);
871
top_blob = *(Mat*)top_blob0;
872
ncnn_mat_destroy(top_blob0);
876
virtual int forward_inplace(std::vector<Mat>& bottom_top_blobs, const Option& opt) const
878
const int n = bottom_top_blobs.size();
879
std::vector<ncnn_mat_t> bottom_top_blobs0(n);
880
for (int i = 0; i < n; i++)
882
bottom_top_blobs0[i] = (ncnn_mat_t)&bottom_top_blobs[i];
884
return layer->forward_inplace_n(layer, &bottom_top_blobs0[0], n, (ncnn_option_t)&opt);
887
virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const
889
return layer->forward_inplace_1(layer, (ncnn_mat_t)&bottom_top_blob, (ncnn_option_t)&opt);
896
static int __ncnn_Layer_load_param(ncnn_layer_t layer, const ncnn_paramdict_t pd)
898
return ((Layer*)layer->pthis)->Layer::load_param(*(const ParamDict*)pd);
901
static int __ncnn_Layer_load_model(ncnn_layer_t layer, const ncnn_modelbin_t mb)
903
return ((Layer*)layer->pthis)->Layer::load_model(*(const ModelBin*)mb);
906
static int __ncnn_Layer_create_pipeline(ncnn_layer_t layer, const ncnn_option_t opt)
908
return ((Layer*)layer->pthis)->Layer::create_pipeline(*(const Option*)opt);
911
static int __ncnn_Layer_destroy_pipeline(ncnn_layer_t layer, const ncnn_option_t opt)
913
return ((Layer*)layer->pthis)->Layer::destroy_pipeline(*(const Option*)opt);
916
static int __ncnn_Layer_forward_1(const ncnn_layer_t layer, const ncnn_mat_t bottom_blob, ncnn_mat_t* top_blob, const ncnn_option_t opt)
919
int ret = ((const Layer*)layer->pthis)->Layer::forward(*(const Mat*)bottom_blob, _top_blob, *(const Option*)opt);
920
*top_blob = (ncnn_mat_t)(new Mat(_top_blob));
924
static int __ncnn_Layer_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)
926
std::vector<Mat> _bottom_blobs(n);
927
std::vector<Mat> _top_blobs(n2);
928
for (int i = 0; i < n; i++)
930
_bottom_blobs[i] = *(Mat*)bottom_blobs[i];
932
int ret = ((const Layer*)layer->pthis)->Layer::forward(_bottom_blobs, _top_blobs, *(const Option*)opt);
933
for (int i = 0; i < n2; i++)
935
top_blobs[i] = (ncnn_mat_t)(new Mat(_top_blobs[i]));
940
static int __ncnn_Layer_forward_inplace_1(const ncnn_layer_t layer, ncnn_mat_t bottom_top_blob, const ncnn_option_t opt)
942
return ((const Layer*)layer->pthis)->Layer::forward_inplace(*(Mat*)bottom_top_blob, *(const Option*)opt);
945
static int __ncnn_Layer_forward_inplace_n(const ncnn_layer_t layer, ncnn_mat_t* bottom_top_blobs, int n, const ncnn_option_t opt)
947
std::vector<Mat> _bottom_top_blobs(n);
948
for (int i = 0; i < n; i++)
950
_bottom_top_blobs[i] = *(Mat*)bottom_top_blobs[i];
952
return ((const Layer*)layer->pthis)->Layer::forward_inplace(_bottom_top_blobs, *(const Option*)opt);
955
static int __ncnn_layer_load_param(ncnn_layer_t layer, const ncnn_paramdict_t pd)
957
return ((Layer*)layer->pthis)->load_param(*(const ParamDict*)pd);
960
static int __ncnn_layer_load_model(ncnn_layer_t layer, const ncnn_modelbin_t mb)
962
return ((Layer*)layer->pthis)->load_model(*(const ModelBin*)mb);
965
static int __ncnn_layer_create_pipeline(ncnn_layer_t layer, const ncnn_option_t opt)
967
return ((Layer*)layer->pthis)->create_pipeline(*(const Option*)opt);
970
static int __ncnn_layer_destroy_pipeline(ncnn_layer_t layer, const ncnn_option_t opt)
972
return ((Layer*)layer->pthis)->destroy_pipeline(*(const Option*)opt);
975
static int __ncnn_layer_forward_1(const ncnn_layer_t layer, const ncnn_mat_t bottom_blob, ncnn_mat_t* top_blob, const ncnn_option_t opt)
978
int ret = ((const Layer*)layer->pthis)->forward(*(const Mat*)bottom_blob, _top_blob, *(const Option*)opt);
979
*top_blob = (ncnn_mat_t)(new Mat(_top_blob));
983
static int __ncnn_layer_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)
985
std::vector<Mat> _bottom_blobs(n);
986
std::vector<Mat> _top_blobs(n2);
987
for (int i = 0; i < n; i++)
989
_bottom_blobs[i] = *(Mat*)bottom_blobs[i];
991
int ret = ((const Layer*)layer->pthis)->forward(_bottom_blobs, _top_blobs, *(const Option*)opt);
992
for (int i = 0; i < n2; i++)
994
top_blobs[i] = (ncnn_mat_t)(new Mat(_top_blobs[i]));
999
static int __ncnn_layer_forward_inplace_1(const ncnn_layer_t layer, ncnn_mat_t bottom_top_blob, const ncnn_option_t opt)
1001
return ((const Layer*)layer->pthis)->forward_inplace(*(Mat*)bottom_top_blob, *(const Option*)opt);
1004
static int __ncnn_layer_forward_inplace_n(const ncnn_layer_t layer, ncnn_mat_t* bottom_top_blobs, int n, const ncnn_option_t opt)
1006
std::vector<Mat> _bottom_top_blobs(n);
1007
for (int i = 0; i < n; i++)
1009
_bottom_top_blobs[i] = *(Mat*)bottom_top_blobs[i];
1011
return ((const Layer*)layer->pthis)->forward_inplace(_bottom_top_blobs, *(const Option*)opt);
1014
ncnn_layer_t ncnn_layer_create()
1016
ncnn_layer_t layer = (ncnn_layer_t)malloc(sizeof(__ncnn_layer_t));
1017
layer->pthis = (void*)(new Layer_c_api(layer));
1018
layer->load_param = __ncnn_Layer_load_param;
1019
layer->load_model = __ncnn_Layer_load_model;
1020
layer->create_pipeline = __ncnn_Layer_create_pipeline;
1021
layer->destroy_pipeline = __ncnn_Layer_destroy_pipeline;
1022
layer->forward_1 = __ncnn_Layer_forward_1;
1023
layer->forward_n = __ncnn_Layer_forward_n;
1024
layer->forward_inplace_1 = __ncnn_Layer_forward_inplace_1;
1025
layer->forward_inplace_n = __ncnn_Layer_forward_inplace_n;
1029
ncnn_layer_t ncnn_layer_create_by_typeindex(int typeindex)
1031
void* pthis = (void*)(ncnn::create_layer(typeindex));
1037
ncnn_layer_t layer = (ncnn_layer_t)malloc(sizeof(__ncnn_layer_t));
1038
layer->pthis = pthis;
1039
layer->load_param = __ncnn_layer_load_param;
1040
layer->load_model = __ncnn_layer_load_model;
1041
layer->create_pipeline = __ncnn_layer_create_pipeline;
1042
layer->destroy_pipeline = __ncnn_layer_destroy_pipeline;
1043
layer->forward_1 = __ncnn_layer_forward_1;
1044
layer->forward_n = __ncnn_layer_forward_n;
1045
layer->forward_inplace_1 = __ncnn_layer_forward_inplace_1;
1046
layer->forward_inplace_n = __ncnn_layer_forward_inplace_n;
1051
ncnn_layer_t ncnn_layer_create_by_type(const char* type)
1053
void* pthis = (void*)(ncnn::create_layer(type));
1059
ncnn_layer_t layer = (ncnn_layer_t)malloc(sizeof(__ncnn_layer_t));
1060
layer->pthis = pthis;
1061
layer->load_param = __ncnn_layer_load_param;
1062
layer->load_model = __ncnn_layer_load_model;
1063
layer->create_pipeline = __ncnn_layer_create_pipeline;
1064
layer->destroy_pipeline = __ncnn_layer_destroy_pipeline;
1065
layer->forward_1 = __ncnn_layer_forward_1;
1066
layer->forward_n = __ncnn_layer_forward_n;
1067
layer->forward_inplace_1 = __ncnn_layer_forward_inplace_1;
1068
layer->forward_inplace_n = __ncnn_layer_forward_inplace_n;
1072
int ncnn_layer_type_to_index(const char* type)
1074
return ncnn::layer_to_index(type);
1076
#endif /* NCNN_STRING */
1078
void ncnn_layer_destroy(ncnn_layer_t layer)
1080
delete (Layer*)layer->pthis;
1085
const char* ncnn_layer_get_name(const ncnn_layer_t layer)
1087
return ((const Layer*)layer->pthis)->name.c_str();
1089
#endif /* NCNN_STRING */
1091
int ncnn_layer_get_typeindex(const ncnn_layer_t layer)
1093
return ((const Layer*)layer->pthis)->typeindex;
1097
const char* ncnn_layer_get_type(const ncnn_layer_t layer)
1099
return ((const Layer*)layer->pthis)->type.c_str();
1101
#endif /* NCNN_STRING */
1103
int ncnn_layer_get_one_blob_only(const ncnn_layer_t layer)
1105
return ((const Layer*)layer->pthis)->one_blob_only;
1108
int ncnn_layer_get_support_inplace(const ncnn_layer_t layer)
1110
return ((const Layer*)layer->pthis)->support_inplace;
1113
int ncnn_layer_get_support_vulkan(const ncnn_layer_t layer)
1115
return ((const Layer*)layer->pthis)->support_vulkan;
1118
int ncnn_layer_get_support_packing(const ncnn_layer_t layer)
1120
return ((const Layer*)layer->pthis)->support_packing;
1123
int ncnn_layer_get_support_bf16_storage(const ncnn_layer_t layer)
1125
return ((const Layer*)layer->pthis)->support_bf16_storage;
1128
int ncnn_layer_get_support_fp16_storage(const ncnn_layer_t layer)
1130
return ((const Layer*)layer->pthis)->support_fp16_storage;
1133
int ncnn_layer_get_support_image_storage(const ncnn_layer_t layer)
1135
return ((const Layer*)layer->pthis)->support_image_storage;
1138
void ncnn_layer_set_one_blob_only(ncnn_layer_t layer, int enable)
1140
((Layer*)layer->pthis)->one_blob_only = enable;
1143
void ncnn_layer_set_support_inplace(ncnn_layer_t layer, int enable)
1145
((Layer*)layer->pthis)->support_inplace = enable;
1148
void ncnn_layer_set_support_vulkan(ncnn_layer_t layer, int enable)
1150
((Layer*)layer->pthis)->support_vulkan = enable;
1153
void ncnn_layer_set_support_packing(ncnn_layer_t layer, int enable)
1155
((Layer*)layer->pthis)->support_packing = enable;
1158
void ncnn_layer_set_support_bf16_storage(ncnn_layer_t layer, int enable)
1160
((Layer*)layer->pthis)->support_bf16_storage = enable;
1163
void ncnn_layer_set_support_fp16_storage(ncnn_layer_t layer, int enable)
1165
((Layer*)layer->pthis)->support_fp16_storage = enable;
1168
void ncnn_layer_set_support_image_storage(ncnn_layer_t layer, int enable)
1170
((Layer*)layer->pthis)->support_image_storage = enable;
1173
int ncnn_layer_get_bottom_count(const ncnn_layer_t layer)
1175
return (int)((const Layer*)layer->pthis)->bottoms.size();
1178
int ncnn_layer_get_bottom(const ncnn_layer_t layer, int i)
1180
return ((const Layer*)layer->pthis)->bottoms[i];
1183
int ncnn_layer_get_top_count(const ncnn_layer_t layer)
1185
return (int)((const Layer*)layer->pthis)->tops.size();
1188
int ncnn_layer_get_top(const ncnn_layer_t layer, int i)
1190
return ((const Layer*)layer->pthis)->tops[i];
1193
void ncnn_blob_get_bottom_shape(const ncnn_layer_t layer, int i, int* dims, int* w, int* h, int* c)
1195
const Mat& shape = ((const Layer*)layer->pthis)->bottom_shapes[i];
1202
void ncnn_blob_get_top_shape(const ncnn_layer_t layer, int i, int* dims, int* w, int* h, int* c)
1204
const Mat& shape = ((const Layer*)layer->pthis)->top_shapes[i];
1212
ncnn_net_t ncnn_net_create()
1214
ncnn_net_t net = (ncnn_net_t)malloc(sizeof(struct __ncnn_net_t));
1215
net->pthis = (void*)(new Net());
1216
net->custom_layer_factory = 0;
1220
void ncnn_net_destroy(ncnn_net_t net)
1222
delete (Net*)net->pthis;
1223
ncnn_net_custom_layer_factory_t ud = net->custom_layer_factory;
1226
ncnn_net_custom_layer_factory_t ud_next = ud->next;
1233
ncnn_option_t ncnn_net_get_option(ncnn_net_t net)
1235
return (ncnn_option_t)(&((Net*)(net->pthis))->opt);
1238
void ncnn_net_set_option(ncnn_net_t net, ncnn_option_t opt)
1240
((Net*)net->pthis)->opt = *((Option*)opt);
1244
void ncnn_net_set_vulkan_device(ncnn_net_t net, int device_index)
1246
((Net*)net->pthis)->set_vulkan_device(device_index);
1250
static ::ncnn::Layer* __Layer_c_api_layer_creator(void* userdata)
1252
ncnn_net_custom_layer_factory_t ud = (ncnn_net_custom_layer_factory_t)userdata;
1254
ncnn_layer_t layer0 = ud->creator(ud->userdata);
1256
::ncnn::Layer* layer = (::ncnn::Layer*)layer0->pthis;
1258
layer->userdata = (void*)layer0;
1260
layer->one_blob_only = ncnn_layer_get_one_blob_only(layer0);
1261
layer->support_inplace = ncnn_layer_get_support_inplace(layer0);
1262
layer->support_vulkan = ncnn_layer_get_support_vulkan(layer0);
1263
layer->support_packing = ncnn_layer_get_support_packing(layer0);
1265
layer->support_bf16_storage = ncnn_layer_get_support_bf16_storage(layer0);
1266
layer->support_fp16_storage = ncnn_layer_get_support_fp16_storage(layer0);
1267
layer->support_image_storage = ncnn_layer_get_support_image_storage(layer0);
1272
static void __Layer_c_api_layer_destroyer(::ncnn::Layer* layer, void* userdata)
1274
ncnn_net_custom_layer_factory_t ud = (ncnn_net_custom_layer_factory_t)userdata;
1276
ncnn_layer_t layer0 = (ncnn_layer_t)layer->userdata;
1278
ud->destroyer(layer0, ud->userdata);
1282
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)
1284
ncnn_net_custom_layer_factory_t ud = (ncnn_net_custom_layer_factory_t)malloc(sizeof(struct __ncnn_net_custom_layer_factory_t));
1285
ud->creator = creator;
1286
ud->destroyer = destroyer;
1287
ud->userdata = userdata;
1288
ud->next = net->custom_layer_factory;
1289
net->custom_layer_factory = ud;
1290
((Net*)net->pthis)->register_custom_layer(type, __Layer_c_api_layer_creator, __Layer_c_api_layer_destroyer, (void*)ud);
1292
#endif /* NCNN_STRING */
1294
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)
1296
ncnn_net_custom_layer_factory_t ud = (ncnn_net_custom_layer_factory_t)malloc(sizeof(struct __ncnn_net_custom_layer_factory_t));
1297
ud->creator = creator;
1298
ud->destroyer = destroyer;
1299
ud->userdata = userdata;
1300
ud->next = net->custom_layer_factory;
1301
net->custom_layer_factory = ud;
1302
((Net*)net->pthis)->register_custom_layer(typeindex, __Layer_c_api_layer_creator, __Layer_c_api_layer_destroyer, (void*)ud);
1307
int ncnn_net_load_param(ncnn_net_t net, const char* path)
1309
return ((Net*)net->pthis)->load_param(path);
1311
#endif /* NCNN_STRING */
1313
int ncnn_net_load_param_bin(ncnn_net_t net, const char* path)
1315
return ((Net*)net->pthis)->load_param_bin(path);
1318
int ncnn_net_load_model(ncnn_net_t net, const char* path)
1320
return ((Net*)net->pthis)->load_model(path);
1322
#endif /* NCNN_STDIO */
1326
int ncnn_net_load_param_memory(ncnn_net_t net, const char* mem)
1328
return ((Net*)net->pthis)->load_param_mem(mem);
1330
#endif /* NCNN_STRING */
1331
#endif /* NCNN_STDIO */
1333
int ncnn_net_load_param_bin_memory(ncnn_net_t net, const unsigned char* mem)
1335
return ((Net*)net->pthis)->load_param(mem);
1338
int ncnn_net_load_model_memory(ncnn_net_t net, const unsigned char* mem)
1340
return ((Net*)net->pthis)->load_model(mem);
1344
int ncnn_net_load_param_datareader(ncnn_net_t net, const ncnn_datareader_t dr)
1346
return ((Net*)net->pthis)->load_param(*(const DataReader*)dr->pthis);
1348
#endif /* NCNN_STRING */
1350
int ncnn_net_load_param_bin_datareader(ncnn_net_t net, const ncnn_datareader_t dr)
1352
return ((Net*)net->pthis)->load_param_bin(*(const DataReader*)dr->pthis);
1355
int ncnn_net_load_model_datareader(ncnn_net_t net, const ncnn_datareader_t dr)
1357
return ((Net*)net->pthis)->load_model(*(const DataReader*)dr->pthis);
1360
void ncnn_net_clear(ncnn_net_t net)
1362
return ((Net*)net->pthis)->clear();
1365
int ncnn_net_get_input_count(const ncnn_net_t net)
1367
return (int)((Net*)net->pthis)->input_indexes().size();
1370
int ncnn_net_get_output_count(const ncnn_net_t net)
1372
return (int)((Net*)net->pthis)->output_indexes().size();
1376
const char* ncnn_net_get_input_name(const ncnn_net_t net, int i)
1378
return ((Net*)net->pthis)->input_names()[i];
1381
const char* ncnn_net_get_output_name(const ncnn_net_t net, int i)
1383
return ((Net*)net->pthis)->output_names()[i];
1385
#endif /* NCNN_STRING */
1387
int ncnn_net_get_input_index(const ncnn_net_t net, int i)
1389
return ((Net*)net->pthis)->input_indexes()[i];
1392
int ncnn_net_get_output_index(const ncnn_net_t net, int i)
1394
return ((Net*)net->pthis)->output_indexes()[i];
1398
ncnn_extractor_t ncnn_extractor_create(ncnn_net_t net)
1400
return (ncnn_extractor_t)(new Extractor(((Net*)net->pthis)->create_extractor()));
1403
void ncnn_extractor_destroy(ncnn_extractor_t ex)
1405
delete (Extractor*)ex;
1408
void ncnn_extractor_set_option(ncnn_extractor_t ex, const ncnn_option_t opt)
1410
((Extractor*)ex)->set_num_threads(((const Option*)opt)->num_threads);
1412
((Extractor*)ex)->set_vulkan_compute(((const Option*)opt)->use_vulkan_compute);
1417
int ncnn_extractor_input(ncnn_extractor_t ex, const char* name, const ncnn_mat_t mat)
1419
return ((Extractor*)ex)->input(name, *((const Mat*)mat));
1422
int ncnn_extractor_extract(ncnn_extractor_t ex, const char* name, ncnn_mat_t* mat)
1425
int ret = ((Extractor*)ex)->extract(name, mat0);
1426
*mat = (ncnn_mat_t)(new Mat(mat0));
1429
#endif /* NCNN_STRING */
1431
int ncnn_extractor_input_index(ncnn_extractor_t ex, int index, const ncnn_mat_t mat)
1433
return ((Extractor*)ex)->input(index, *((const Mat*)mat));
1436
int ncnn_extractor_extract_index(ncnn_extractor_t ex, int index, ncnn_mat_t* mat)
1439
int ret = ((Extractor*)ex)->extract(index, mat0);
1440
*mat = (ncnn_mat_t)(new Mat(mat0));
1444
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)
1446
const Option _opt = opt ? *((const Option*)opt) : Option();
1447
copy_make_border(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, type, v, _opt);
1450
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)
1452
const Option _opt = opt ? *((const Option*)opt) : Option();
1453
copy_make_border_3d(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, front, behind, type, v, _opt);
1456
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)
1458
const Option _opt = opt ? *((const Option*)opt) : Option();
1459
copy_cut_border(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, _opt);
1462
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)
1464
const Option _opt = opt ? *((const Option*)opt) : Option();
1465
copy_cut_border_3d(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, front, behind, _opt);
1468
#if NCNN_PIXEL_DRAWING
1469
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)
1471
ncnn::draw_rectangle_c1(pixels, w, h, w, rx, ry, rw, rh, color, thickness);
1474
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)
1476
ncnn::draw_rectangle_c2(pixels, w, h, w * 2, rx, ry, rw, rh, color, thickness);
1479
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)
1481
ncnn::draw_rectangle_c3(pixels, w, h, w * 3, rx, ry, rw, rh, color, thickness);
1484
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)
1486
ncnn::draw_rectangle_c4(pixels, w, h, w * 4, rx, ry, rw, rh, color, thickness);
1489
void ncnn_draw_text_c1(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color)
1491
ncnn::draw_text_c1(pixels, w, h, w, text, x, y, fontpixelsize, color);
1494
void ncnn_draw_text_c2(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color)
1496
ncnn::draw_text_c2(pixels, w, h, w * 2, text, x, y, fontpixelsize, color);
1499
void ncnn_draw_text_c3(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color)
1501
ncnn::draw_text_c3(pixels, w, h, w * 3, text, x, y, fontpixelsize, color);
1504
void ncnn_draw_text_c4(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color)
1506
ncnn::draw_text_c4(pixels, w, h, w * 4, text, x, y, fontpixelsize, color);
1509
void ncnn_draw_circle_c1(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness)
1511
ncnn::draw_circle_c1(pixels, w, h, w, cx, cy, radius, color, thickness);
1514
void ncnn_draw_circle_c2(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness)
1516
ncnn::draw_circle_c2(pixels, w, h, w * 2, cx, cy, radius, color, thickness);
1519
void ncnn_draw_circle_c3(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness)
1521
ncnn::draw_circle_c3(pixels, w, h, w * 3, cx, cy, radius, color, thickness);
1524
void ncnn_draw_circle_c4(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness)
1526
ncnn::draw_circle_c4(pixels, w, h, w * 4, cx, cy, radius, color, thickness);
1529
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)
1531
ncnn::draw_line_c1(pixels, w, h, w, x0, y0, x1, y1, color, thickness);
1534
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)
1536
ncnn::draw_line_c2(pixels, w, h, w * 2, x0, y0, x1, y1, color, thickness);
1539
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)
1541
ncnn::draw_line_c3(pixels, w, h, w * 3, x0, y0, x1, y1, color, thickness);
1544
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)
1546
ncnn::draw_line_c4(pixels, w, h, w * 4, x0, y0, x1, y1, color, thickness);
1548
#endif /* NCNN_PIXEL_DRAWING */
1554
#endif /* NCNN_C_API */