This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via b3779d6def780f74dc0dbaed7ed5f5172a9faa7c (commit) from 9d50a7192a8d4620a221c571092015891182f63a (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/b3779d6def780f74dc0dbaed7ed5f5172a9fa...
commit b3779d6def780f74dc0dbaed7ed5f5172a9faa7c Author: BlueBear jiri.bluebear.dluhos@gmail.com Date: Sun Jul 17 20:23:31 2011 +0200
Initial attempt on rings (only circular for now).
diff --git a/include/gfx/GP_Circle.h b/include/gfx/GP_Circle.h index 6360e72..57b5a0a 100644 --- a/include/gfx/GP_Circle.h +++ b/include/gfx/GP_Circle.h @@ -40,4 +40,10 @@ void GP_FillCircle(GP_Context *context, int xcenter, int ycenter, void GP_TFillCircle(GP_Context *context, int xcenter, int ycenter, unsigned int r, GP_Pixel pixel);
+void GP_FillRing(GP_Context *context, int xcenter, int ycenter, + unsigned int outer_r, unsigned int inner_r, GP_Pixel pixel); + +void GP_TFillRing(GP_Context *context, int xcenter, int ycenter, + unsigned int outer_r, unsigned int inner_r, GP_Pixel pixel); + #endif /* GP_CIRCLE_H */ diff --git a/libs/gfx/GP_Circle.c b/libs/gfx/GP_Circle.c index 4e92243..427a9ad 100644 --- a/libs/gfx/GP_Circle.c +++ b/libs/gfx/GP_Circle.c @@ -84,3 +84,33 @@ void GP_TFillCircle(GP_Context *context, int xcenter, int ycenter, GP_FillCircle(context, xcenter, ycenter, r, pixel); } + +#include "algo/FillRing.algo.h" + +/* Generate drawing functions for various bit depths. */ +DEF_FILLRING_FN(GP_FillRing1bpp, GP_Context *, GP_Pixel, GP_HLine1bpp) +DEF_FILLRING_FN(GP_FillRing2bpp, GP_Context *, GP_Pixel, GP_HLine2bpp) +DEF_FILLRING_FN(GP_FillRing4bpp, GP_Context *, GP_Pixel, GP_HLine4bpp) +DEF_FILLRING_FN(GP_FillRing8bpp, GP_Context *, GP_Pixel, GP_HLine8bpp) +DEF_FILLRING_FN(GP_FillRing16bpp, GP_Context *, GP_Pixel, GP_HLine16bpp) +DEF_FILLRING_FN(GP_FillRing24bpp, GP_Context *, GP_Pixel, GP_HLine24bpp) +DEF_FILLRING_FN(GP_FillRing32bpp, GP_Context *, GP_Pixel, GP_HLine32bpp) + +void GP_FillRing(GP_Context *context, int xcenter, int ycenter, + unsigned int outer_r, unsigned int inner_r, GP_Pixel pixel) +{ + GP_CHECK_CONTEXT(context); + + GP_FN_PER_BPP(GP_FillRing, context->bpp, context, + xcenter, ycenter, outer_r, inner_r, pixel); +} + +void GP_TFillRing(GP_Context *context, int xcenter, int ycenter, + unsigned int outer_r, unsigned int inner_r, GP_Pixel pixel) +{ + GP_CHECK_CONTEXT(context); + + GP_TRANSFORM_POINT(context, xcenter, ycenter); + + GP_FillRing(context, xcenter, ycenter, outer_r, inner_r, pixel); +} diff --git a/include/gfx/GP_Circle.h b/libs/gfx/algo/FillRing.algo.h similarity index 53% copy from include/gfx/GP_Circle.h copy to libs/gfx/algo/FillRing.algo.h index 6360e72..4458bec 100644 --- a/include/gfx/GP_Circle.h +++ b/libs/gfx/algo/FillRing.algo.h @@ -23,21 +23,51 @@ * * *****************************************************************************/
-#ifndef GP_CIRCLE_H -#define GP_CIRCLE_H +/* + * A filled ring drawing algorithm. + */
-#include "core/GP_Context.h" - -void GP_Circle(GP_Context *context, int xcenter, int ycenter, - unsigned int r, GP_Pixel pixel); - -void GP_TCircle(GP_Context *context, int xcenter, int ycenter, - unsigned int r, GP_Pixel pixel); - -void GP_FillCircle(GP_Context *context, int xcenter, int ycenter, - unsigned int r, GP_Pixel pixel); - -void GP_TFillCircle(GP_Context *context, int xcenter, int ycenter, - unsigned int r, GP_Pixel pixel); - -#endif /* GP_CIRCLE_H */ +/* + * This macro defines a filled circle drawing function. + * Arguments: + * CONTEXT_T - user-defined type of drawing context (passed to HLINE) + * PIXVAL_T - user-defined pixel value type (passed to HLINE) + * HLINE - horizontal line drawing function f(context, x0, x1, y, pixval) + * FN_NAME - name of the function to be defined + */ +#define DEF_FILLRING_FN(FN_NAME, CONTEXT_T, PIXVAL_T, HLINE) +void FN_NAME(CONTEXT_T context, int xcenter, int ycenter, + unsigned int outer_r, unsigned int inner_r, PIXVAL_T pixval) +{ + if (inner_r >= outer_r) return; ++ int outer_x = 0; + int inner_x = 0; + int y; + int outer_error = -outer_r; + int inner_error = -inner_r; + for (y = outer_r; y >= 0; y--) { ++ while (outer_error < 0) { + outer_error += 2*outer_x + 1; + outer_x++; + } + outer_error += -2*y + 1; ++ if (y < (int) inner_r && y > -((int) inner_r)) { + while (inner_error < 0) { + inner_error += 2*inner_x + 1; + inner_x++; + } + inner_error += -2*y + 1; ++ HLINE(context, xcenter - outer_x + 1, xcenter - inner_x - 1, ycenter - y, pixval); + HLINE(context, xcenter + inner_x + 1, xcenter + outer_x - 1, ycenter - y, pixval); + HLINE(context, xcenter - outer_x + 1, xcenter - inner_x - 1, ycenter + y, pixval); + HLINE(context, xcenter + inner_x + 1, xcenter + outer_x - 1, ycenter + y, pixva l); + } else { + HLINE(context, xcenter - outer_x + 1, xcenter + outer_x - 1, ycenter-y, pixval); + HLINE(context, xcenter - outer_x + 1, xcenter + outer_x - 1, ycenter+y, pixval); + } + } +} diff --git a/tests/SDL/shapetest.c b/tests/SDL/shapetest.c index fb85b2e..d1009d9 100644 --- a/tests/SDL/shapetest.c +++ b/tests/SDL/shapetest.c @@ -68,9 +68,10 @@ static int show_axes = 1; #define SHAPE_FIRST 1 #define SHAPE_TRIANGLE 1 #define SHAPE_CIRCLE 2 -#define SHAPE_ELLIPSE 3 -#define SHAPE_RECTANGLE 4 -#define SHAPE_LAST 4 +#define SHAPE_RING 3 +#define SHAPE_ELLIPSE 4 +#define SHAPE_RECTANGLE 5 +#define SHAPE_LAST 5 static int shape = SHAPE_FIRST;
/* Variants in coordinates, if applicable */ @@ -157,6 +158,25 @@ void draw_testing_circle(int x, int y, int xradius, GP_TCircle(&context, x, y, xradius, white); }
+void draw_testing_ring(int x, int y, int xradius, + __attribute__((unused)) int yradius) +{ + if (outline == 1) + GP_TCircle(&context, x, y, xradius, yellow); + + if (fill) { + if (xradius == yradius) { + GP_TFillRing(&context, x, y, xradius, xradius/2, red); + } else { + GP_TFillRing(&context, x, y, GP_MAX(xradius, yradius), + GP_MIN(xradius, yradius), red); + } + } + + if (outline == 2) + GP_TCircle(&context, x, y, xradius, white); +} + void draw_testing_ellipse(int x, int y, int xradius, int yradius) { if (outline == 1) @@ -217,6 +237,10 @@ void redraw_screen(void) draw_testing_circle(center_x, center_y, xradius, yradius); title = "CIRCLE"; break; + case SHAPE_RING: + draw_testing_ring(center_x, center_y, xradius, yradius); + title = "RING"; + break; case SHAPE_ELLIPSE: draw_testing_ellipse(center_x, center_y, xradius, yradius); title = "ELLIPSE";
-----------------------------------------------------------------------
Summary of changes: include/gfx/GP_Circle.h | 6 ++ libs/gfx/GP_Circle.c | 30 ++++++++++++ .../algo/{FillCircle.algo.h => FillRing.algo.h} | 49 +++++++++++++------- tests/SDL/shapetest.c | 30 +++++++++++- 4 files changed, 95 insertions(+), 20 deletions(-) copy libs/gfx/algo/{FillCircle.algo.h => FillRing.algo.h} (66%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.