From 89830d8eaaa80a9b4a107499f1b503626319f7e4 Mon Sep 17 00:00:00 2001 From: Mek101 Date: Wed, 12 Jul 2023 11:30:51 +0200 Subject: [PATCH 1/4] c_api expose Mat border processing api --- src/c_api.cpp | 24 ++++++++++++++++++++++++ src/c_api.h | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/c_api.cpp b/src/c_api.cpp index 2f5b2958e2e..56df0db0f8f 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -1417,6 +1417,30 @@ int ncnn_extractor_extract_index(ncnn_extractor_t ex, int index, ncnn_mat_t* mat return ret; } +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) +{ + const Option _opt = opt == nullptr ? Option() : *((const Option*)opt); + copy_make_border(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, type, v, _opt); +} + +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) +{ + const Option _opt = opt == nullptr ? Option() : *((const Option*)opt); + copy_make_border_3d(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, front, behind, type, v, _opt); +} + +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) +{ + const Option _opt = opt == nullptr ? Option() : *((const Option*)opt); + copy_cut_border(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, _opt); +} + +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) +{ + const Option _opt = opt == nullptr ? Option() : *((const Option*)opt); + copy_cut_border_3d(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, front, behind, _opt); +} + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/c_api.h b/src/c_api.h index ebf5db536fa..d863d39ea17 100644 --- a/src/c_api.h +++ b/src/c_api.h @@ -327,6 +327,16 @@ NCNN_EXPORT int ncnn_extractor_extract(ncnn_extractor_t ex, const char* name, nc NCNN_EXPORT int ncnn_extractor_input_index(ncnn_extractor_t ex, int index, const ncnn_mat_t mat); NCNN_EXPORT int ncnn_extractor_extract_index(ncnn_extractor_t ex, int index, ncnn_mat_t* mat); +/* mat process api */ +#define NCNN_BORDER_CONSTANT = 0, +#define NCNN_BORDER_REPLICATE = 1, +#define NCNN_BORDER_REFLECT = 2, +#define NCNN_BORDER_TRANSPARENT = -233, +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); +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); +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); +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); + #ifdef __cplusplus } /* extern "C" */ #endif From 24e7fb1011aa0bde6d8a88d087f1d0fac1d547c8 Mon Sep 17 00:00:00 2001 From: Mek101 Date: Wed, 12 Jul 2023 14:36:51 +0200 Subject: [PATCH 2/4] c_api: use more c-style ? operator --- src/c_api.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/c_api.cpp b/src/c_api.cpp index 56df0db0f8f..47cbfee602d 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -1419,25 +1419,25 @@ int ncnn_extractor_extract_index(ncnn_extractor_t ex, int index, ncnn_mat_t* mat 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) { - const Option _opt = opt == nullptr ? Option() : *((const Option*)opt); + const Option _opt = opt ? *((const Option*)opt) : Option(); copy_make_border(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, type, v, _opt); } 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) { - const Option _opt = opt == nullptr ? Option() : *((const Option*)opt); + const Option _opt = opt ? *((const Option*)opt) : Option(); copy_make_border_3d(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, front, behind, type, v, _opt); } 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) { - const Option _opt = opt == nullptr ? Option() : *((const Option*)opt); + const Option _opt = opt ? *((const Option*)opt) : Option(); copy_cut_border(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, _opt); } 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) { - const Option _opt = opt == nullptr ? Option() : *((const Option*)opt); + const Option _opt = opt ? *((const Option*)opt) : Option(); copy_cut_border_3d(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, front, behind, _opt); } From e93b8df67e999b3e3a7d25b777cf5a69bdfd41e8 Mon Sep 17 00:00:00 2001 From: Mek101 Date: Thu, 13 Jul 2023 10:28:16 +0000 Subject: [PATCH 3/4] Fix c-api NCNN_BORDER_* defines --- src/c_api.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/c_api.h b/src/c_api.h index d863d39ea17..03d06d3497a 100644 --- a/src/c_api.h +++ b/src/c_api.h @@ -328,10 +328,10 @@ NCNN_EXPORT int ncnn_extractor_input_index(ncnn_extractor_t ex, int index, const NCNN_EXPORT int ncnn_extractor_extract_index(ncnn_extractor_t ex, int index, ncnn_mat_t* mat); /* mat process api */ -#define NCNN_BORDER_CONSTANT = 0, -#define NCNN_BORDER_REPLICATE = 1, -#define NCNN_BORDER_REFLECT = 2, -#define NCNN_BORDER_TRANSPARENT = -233, +#define NCNN_BORDER_CONSTANT 0 +#define NCNN_BORDER_REPLICATE 1 +#define NCNN_BORDER_REFLECT 2 +#define NCNN_BORDER_TRANSPARENT -233 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); 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); 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); From c1e43181ce4951b05644474b01b122fec9b5b361 Mon Sep 17 00:00:00 2001 From: Mek101 Date: Sat, 15 Jul 2023 10:24:08 +0200 Subject: [PATCH 4/4] Format c-api border constants --- src/c_api.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/c_api.h b/src/c_api.h index 03d06d3497a..8d753dba5c2 100644 --- a/src/c_api.h +++ b/src/c_api.h @@ -328,9 +328,9 @@ NCNN_EXPORT int ncnn_extractor_input_index(ncnn_extractor_t ex, int index, const NCNN_EXPORT int ncnn_extractor_extract_index(ncnn_extractor_t ex, int index, ncnn_mat_t* mat); /* mat process api */ -#define NCNN_BORDER_CONSTANT 0 -#define NCNN_BORDER_REPLICATE 1 -#define NCNN_BORDER_REFLECT 2 +#define NCNN_BORDER_CONSTANT 0 +#define NCNN_BORDER_REPLICATE 1 +#define NCNN_BORDER_REFLECT 2 #define NCNN_BORDER_TRANSPARENT -233 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); 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);