From f6763262d10c8100bc1b167288de385c5b8fc337 Mon Sep 17 00:00:00 2001 From: Justin Fung <83911295+Deepdive543443@users.noreply.github.com> Date: Fri, 2 Feb 2024 06:42:51 +0000 Subject: [PATCH] Add draw rectangle, draw text, draw circle, and draw line to C API (#5324) --- src/c_api.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/c_api.h | 21 ++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/src/c_api.cpp b/src/c_api.cpp index 2a7ee3421e39..7b40042d692d 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -1458,6 +1458,86 @@ void ncnn_copy_cut_border_3d(const ncnn_mat_t src, ncnn_mat_t dst, int top, int copy_cut_border_3d(*(const Mat*)src, *(Mat*)dst, top, bottom, left, right, front, behind, _opt); } +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) +{ + ncnn::draw_rectangle_c1(pixels, w, h, w, rx, ry, rw, rh, color, thickness); +} + +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) +{ + ncnn::draw_rectangle_c2(pixels, w, h, w * 2, rx, ry, rw, rh, color, thickness); +} + +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) +{ + ncnn::draw_rectangle_c3(pixels, w, h, w * 3, rx, ry, rw, rh, color, thickness); +} + +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) +{ + ncnn::draw_rectangle_c4(pixels, w, h, w * 4, rx, ry, rw, rh, color, thickness); +} + +void ncnn_draw_text_c1(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color) +{ + ncnn::draw_text_c1(pixels, w, h, w, text, x, y, fontpixelsize, color); +} + +void ncnn_draw_text_c2(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color) +{ + ncnn::draw_text_c2(pixels, w, h, w * 2, text, x, y, fontpixelsize, color); +} + +void ncnn_draw_text_c3(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color) +{ + ncnn::draw_text_c3(pixels, w, h, w * 3, text, x, y, fontpixelsize, color); +} + +void ncnn_draw_text_c4(unsigned char* pixels, int w, int h, const char* text, int x, int y, int fontpixelsize, unsigned int color) +{ + ncnn::draw_text_c4(pixels, w, h, w * 4, text, x, y, fontpixelsize, color); +} + +void ncnn_draw_circle_c1(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness) +{ + ncnn::draw_circle_c1(pixels, w, h, w, cx, cy, radius, color, thickness); +} + +void ncnn_draw_circle_c2(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness) +{ + ncnn::draw_circle_c2(pixels, w, h, w * 2, cx, cy, radius, color, thickness); +} + +void ncnn_draw_circle_c3(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness) +{ + ncnn::draw_circle_c3(pixels, w, h, w * 3, cx, cy, radius, color, thickness); +} + +void ncnn_draw_circle_c4(unsigned char* pixels, int w, int h, int cx, int cy, int radius, unsigned int color, int thickness) +{ + ncnn::draw_circle_c4(pixels, w, h, w * 4, cx, cy, radius, color, thickness); +} + +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) +{ + ncnn::draw_line_c1(pixels, w, h, w, x0, y0, x1, y1, color, thickness); +} + +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) +{ + ncnn::draw_line_c2(pixels, w, h, w * 2, x0, y0, x1, y1, color, thickness); +} + +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) +{ + ncnn::draw_line_c3(pixels, w, h, w * 3, x0, y0, x1, y1, color, thickness); +} + +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) +{ + ncnn::draw_line_c4(pixels, w, h, w * 4, x0, y0, x1, y1, color, thickness); +} + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/c_api.h b/src/c_api.h index 31d5b6d70893..289490832654 100644 --- a/src/c_api.h +++ b/src/c_api.h @@ -338,6 +338,27 @@ NCNN_EXPORT void ncnn_copy_make_border_3d(const ncnn_mat_t src, ncnn_mat_t dst, 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); +/* mat pixel drawing api*/ +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); +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); +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); +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); + +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); +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); +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); +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); + +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); +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); +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); +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); + +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); +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); +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); +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); + #ifdef __cplusplus } /* extern "C" */ #endif