From ebc9d039449151402a121e0c45203ace0bb6d365 Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Sat, 2 Dec 2017 12:59:39 +0100 Subject: [PATCH] gfx: Implement GP_FillCircleSeg() Signed-off-by: Cyril Hrubis --- libs/gfx/GP_CircleSeg.c | 22 ++++------------------ libs/gfx/GP_FillCircle.gen.c.t | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/libs/gfx/GP_CircleSeg.c b/libs/gfx/GP_CircleSeg.c index 8b517976..d34d9de1 100644 --- a/libs/gfx/GP_CircleSeg.c +++ b/libs/gfx/GP_CircleSeg.c @@ -82,27 +82,13 @@ void GP_CircleSeg(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter, transform_segments(pixmap, seg_flag), pixel); } -/* -#include "algo/FillCircle.algo.h" - -GP_DEF_FILL_FN_PER_BPP(GP_FillCircle_Raw, DEF_FILLCIRCLE_FN) - -void GP_FillCircle_Raw(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter, - GP_Size r, GP_Pixel pixel) -{ - GP_CHECK_PIXMAP(pixmap); - - GP_FN_PER_BPP_PIXMAP(GP_FillCircle_Raw, pixmap, pixmap, - xcenter, ycenter, r, pixel); -} - -void GP_FillCircle(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter, - GP_Size r, GP_Pixel pixel) +void GP_FillCircleSeg(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter, + GP_Size r, uint8_t seg_flag, GP_Pixel pixel) { GP_CHECK_PIXMAP(pixmap); GP_TRANSFORM_POINT(pixmap, xcenter, ycenter); - GP_FillCircle_Raw(pixmap, xcenter, ycenter, r, pixel); + GP_FillCircleSeg_Raw(pixmap, xcenter, ycenter, r, + transform_segments(pixmap, seg_flag), pixel); } -*/ diff --git a/libs/gfx/GP_FillCircle.gen.c.t b/libs/gfx/GP_FillCircle.gen.c.t index 48ac9501..41942a31 100644 --- a/libs/gfx/GP_FillCircle.gen.c.t +++ b/libs/gfx/GP_FillCircle.gen.c.t @@ -12,6 +12,7 @@ #include "core/GP_FnPerBpp.h" #include "gfx/GP_HLine.h" #include "gfx/GP_Circle.h" +#include "gfx/GP_CircleSeg.h" /* * A filled circle drawing algorithm. @@ -45,6 +46,37 @@ static void GP_FillCircle_Raw_{{ ps.suffix }}(GP_Pixmap *pixmap, } } +static void GP_FillCircleSeg_Raw_{{ ps.suffix }}(GP_Pixmap *pixmap, + GP_Coord xcenter, GP_Coord ycenter, GP_Size r, uint8_t seg_flag, GP_Pixel pixel) +{ + /* for r == 0, circle degenerates to a point */ + if (r == 0) { + GP_PutPixel_Raw_{{ ps.suffix }}(pixmap, xcenter, ycenter, pixel); + return; + } + + int x, y, error; + for (x = 0, error = -r, y = r; y >= 0; y--) { + while (error < 0) { + error += 2*x + 1; + x++; + } + error += -2*y + 1; + + if (seg_flag & GP_CIRCLE_SEG1) + GP_HLine_Raw_{{ ps.suffix }}(pixmap, xcenter, xcenter+x-1, ycenter-y, pixel); + + if (seg_flag & GP_CIRCLE_SEG2) + GP_HLine_Raw_{{ ps.suffix }}(pixmap, xcenter-x+1, xcenter, ycenter-y, pixel); + + if (seg_flag & GP_CIRCLE_SEG3) + GP_HLine_Raw_{{ ps.suffix }}(pixmap, xcenter-x+1, xcenter, ycenter+y, pixel); + + if (seg_flag & GP_CIRCLE_SEG4) + GP_HLine_Raw_{{ ps.suffix }}(pixmap, xcenter, xcenter+x-1, ycenter+y, pixel); + } +} + @ end void GP_FillCircle_Raw(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter, @@ -56,6 +88,15 @@ void GP_FillCircle_Raw(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter, xcenter, ycenter, r, pixel); } +void GP_FillCircleSeg_Raw(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter, + GP_Size r, uint8_t seg_flag, GP_Pixel pixel) +{ + GP_CHECK_PIXMAP(pixmap); + + GP_FN_PER_BPP_PIXMAP(GP_FillCircleSeg_Raw, pixmap, pixmap, + xcenter, ycenter, r, seg_flag, pixel); +} + void GP_FillCircle(GP_Pixmap *pixmap, GP_Coord xcenter, GP_Coord ycenter, GP_Size r, GP_Pixel pixel) { -- 2.11.4.GIT