diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2018-08-03 14:54:25 +0300 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2018-08-03 14:55:18 +0300 |
commit | ed8343cb576fc04b9e24e413534d41e0c5d9f2d0 (patch) | |
tree | a3fa6a7f660cfdf31b682b9c775ef5baa7612d53 | |
parent | 2cfc1d86771a0835abdef86a6f6fcd914506da86 (diff) |
add a simple draw_circle()
-rw-r--r-- | kms++util/inc/kms++util/kms++util.h | 1 | ||||
-rw-r--r-- | kms++util/src/drawing.cpp | 18 | ||||
-rw-r--r-- | py/pykms/pykmsutil.cpp | 3 |
3 files changed, 22 insertions, 0 deletions
diff --git a/kms++util/inc/kms++util/kms++util.h b/kms++util/inc/kms++util/kms++util.h index 8e45b0d..62ec663 100644 --- a/kms++util/inc/kms++util/kms++util.h +++ b/kms++util/inc/kms++util/kms++util.h @@ -22,6 +22,7 @@ void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, void draw_yuv420_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4); void draw_rect(IFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color); +void draw_circle(IFramebuffer& fb, int32_t xCenter, int32_t yCenter, int32_t radius, RGB color); void draw_text(IFramebuffer& buf, uint32_t x, uint32_t y, const std::string& str, RGB color); void draw_color_bar(IFramebuffer& buf, int old_xpos, int xpos, int width); diff --git a/kms++util/src/drawing.cpp b/kms++util/src/drawing.cpp index 4e5c6c1..8885112 100644 --- a/kms++util/src/drawing.cpp +++ b/kms++util/src/drawing.cpp @@ -1,4 +1,6 @@ +#include <cmath> + #include <kms++/kms++.h> #include <kms++util/kms++util.h> @@ -198,6 +200,22 @@ void draw_rect(IFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, } } +void draw_horiz_line(IFramebuffer& fb, uint32_t x1, uint32_t x2, uint32_t y, RGB color) +{ + for (uint32_t x = x1; x <= x2; ++x) + draw_rgb_pixel(fb, x, y, color); +} + +void draw_circle(IFramebuffer& fb, int32_t xCenter, int32_t yCenter, int32_t radius, RGB color) +{ + int32_t r2 = radius * radius; + + for (int y = -radius; y <= radius; y++) { + int32_t x = (int)(sqrt(r2 - y * y) + 0.5); + draw_horiz_line(fb, xCenter - x, xCenter + x, yCenter - y, color); + } +} + static bool get_char_pixel(char c, uint32_t x, uint32_t y) { #include "font_8x8.h" diff --git a/py/pykms/pykmsutil.cpp b/py/pykms/pykmsutil.cpp index 518d5ea..d5d7fde 100644 --- a/py/pykms/pykmsutil.cpp +++ b/py/pykms/pykmsutil.cpp @@ -57,6 +57,9 @@ void init_pykmstest(py::module &m) m.def("draw_rect", [](Framebuffer& fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color) { draw_rect(fb, x, y, w, h, color); } ); + m.def("draw_circle", [](Framebuffer& fb, int32_t xCenter, int32_t yCenter, int32_t radius, RGB color) { + draw_circle(fb, xCenter, yCenter, radius, color); + } ); m.def("draw_text", [](Framebuffer& fb, uint32_t x, uint32_t y, const string& str, RGB color) { draw_text(fb, x, y, str, color); } ); } |