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 bf70bc758e8d915a99250ce0422f05f414785e5d (commit)
from e5db2b1f3508e1630b9af36a397a68ef069a56a2 (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/bf70bc758e8d915a99250ce0422f05f41478…
commit bf70bc758e8d915a99250ce0422f05f414785e5d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jan 8 20:26:11 2012 +0100
gfx: Fix CircleSeg orientation.
diff --git a/libs/gfx/GP_CircleSeg.c b/libs/gfx/GP_CircleSeg.c
index 56179c6..512699e 100644
--- a/libs/gfx/GP_CircleSeg.c
+++ b/libs/gfx/GP_CircleSeg.c
@@ -39,7 +39,7 @@ static uint8_t transform_segments(GP_Context *context, uint8_t seg_flags)
uint8_t seg4 = seg_flags & GP_CIRCLE_SEG4;
if (context->axes_swap)
- GP_SWAP(seg2, seg4);
+ GP_SWAP(seg1, seg3);
if (context->x_swap) {
GP_SWAP(seg1, seg2);
diff --git a/libs/gfx/algo/CircleSeg.algo.h b/libs/gfx/algo/CircleSeg.algo.h
index 9812888..dc176a3 100644
--- a/libs/gfx/algo/CircleSeg.algo.h
+++ b/libs/gfx/algo/CircleSeg.algo.h
@@ -84,25 +84,25 @@ void FN_NAME(CONTEXT_T context, int xcenter, int ycenter, unsigned int r, while (error < 0) { error += 2*x + 1; x++; - if (seg_flags & GP_CIRCLE_SEG3) + if (seg_flags & GP_CIRCLE_SEG2) PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); - if (seg_flags & GP_CIRCLE_SEG4) + if (seg_flags & GP_CIRCLE_SEG1) PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); - if (seg_flags & GP_CIRCLE_SEG2) + if (seg_flags & GP_CIRCLE_SEG3) PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); - if (seg_flags & GP_CIRCLE_SEG1) + if (seg_flags & GP_CIRCLE_SEG4) PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); } /* Enough changes accumulated, go to next line. */ error += -2*y + 1; - if (seg_flags & GP_CIRCLE_SEG3) + if (seg_flags & GP_CIRCLE_SEG2) PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); - if (seg_flags & GP_CIRCLE_SEG4) + if (seg_flags & GP_CIRCLE_SEG1) PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval)
; - if (seg_flags & GP_CIRCLE_SEG2) + if (seg_flags & GP_CIRCLE_SEG3) PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); - if (seg_flags & GP_CIRCLE_SEG1) + if (seg_flags & GP_CIRCLE_SEG4) PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); } }
-----------------------------------------------------------------------
Summary of changes:
libs/gfx/GP_CircleSeg.c | 2 +-
libs/gfx/algo/CircleSeg.algo.h | 16 ++++++++--------
2 files changed, 9 insertions(+), 9 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
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 e5db2b1f3508e1630b9af36a397a68ef069a56a2 (commit)
from 566ed587e8f01232c84c2aba46d1861a20cd0c27 (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/e5db2b1f3508e1630b9af36a397a68ef069a…
commit e5db2b1f3508e1630b9af36a397a68ef069a56a2
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jan 8 18:53:24 2012 +0100
gfx: Add function for circle segment drawing.
diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_CircleSeg.h
similarity index 53%
copy from include/gfx/GP_Gfx.h
copy to include/gfx/GP_CircleSeg.h
index 6503952..fddc5ef 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/gfx/GP_CircleSeg.h
@@ -16,41 +16,52 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
- * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
+ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-/*
+#ifndef GFX_GP_CIRCLE_H
+#define GFX_GP_CIRCLE_H
- This is a main header for gfx part.
+#include "core/GP_Context.h"
+/*
+ * Quadrants in cartesian space the center is set in the middle of the circle.
+ *
+ * First segment is where both x and y are possitive, second is where only y is
+ * possitive, third is for both x and y negative and the last one for only y
+ * negative.
+ *
+ * Note that on computer screen (and in in-memory bitmaps) cordinates for y
+ * grows in the opposite direction to the standard cartesian plane.
+ *
+ * So first segment is actually down right, second is down left, third is up
+ * left, and fourth is up right.
*/
+enum GP_CircleSegments {
+ GP_CIRCLE_SEG1 = 0x01, /* First Quadrant */
+ GP_CIRCLE_SEG2 = 0x02, /* Second Quadrant */
+ GP_CIRCLE_SEG3 = 0x04, /* Third Quadrant */
+ GP_CIRCLE_SEG4 = 0x08, /* Fourth Quadrant */
+};
-#ifndef GP_GFX_H
-#define GP_GFX_H
+/* Circle Segment */
-/* basic definitions and structures */
-#include "core/GP_Context.h"
-#include "core/GP_GetPutPixel.h"
-#include "core/GP_WritePixel.h"
-
-/* public drawing API */
-#include "GP_Fill.h"
-#include "GP_HLine.h"
-#include "GP_VLine.h"
-#include "GP_Line.h"
-#include "GP_Rect.h"
-#include "GP_Triangle.h"
-#include "GP_Tetragon.h"
-#include "GP_Circle.h"
-#include "GP_Ellipse.h"
-#include "GP_Arc.h"
-#include "GP_Polygon.h"
-#include "GP_Symbol.h"
-
-#include "GP_RectAA.h"
-
-#endif /* GP_GFX_H */
+void GP_CircleSeg(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, uint8_t seg_flag, GP_Pixel pixel);
+
+void GP_CircleSeg_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, uint8_t seg_flag, GP_Pixel pixel);
+
+/* Filled Circle Segment */
+
+void GP_FillCircleSeg(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, uint8_t seg_flag, GP_Pixel pixel);
+
+void GP_FillCircleSeg_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, uint8_t seg_flag, GP_Pixel pixel);
+
+#endif /* GFX_GP_CIRCLE_H */
diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_Gfx.h
index 6503952..54648a8 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/gfx/GP_Gfx.h
@@ -46,6 +46,7 @@
#include "GP_Triangle.h"
#include "GP_Tetragon.h"
#include "GP_Circle.h"
+#include "GP_CircleSeg.h"
#include "GP_Ellipse.h"
#include "GP_Arc.h"
#include "GP_Polygon.h"
diff --git a/libs/gfx/GP_CircleSeg.c b/libs/gfx/GP_CircleSeg.c
new file mode 100644
index 0000000..56179c6
--- /dev/null
+++ b/libs/gfx/GP_CircleSeg.c
@@ -0,0 +1,108 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos *
+ * <jiri.bluebear.dluhos(a)gmail.com> *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include "GP_CircleSeg.h"
+#include "GP_HLine.h"
+
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_FnPerBpp.h"
+
+#include "algo/CircleSeg.algo.h"
+
+static uint8_t transform_segments(GP_Context *context, uint8_t seg_flags)
+{
+ uint8_t seg1 = seg_flags & GP_CIRCLE_SEG1;
+ uint8_t seg2 = seg_flags & GP_CIRCLE_SEG2;
+ uint8_t seg3 = seg_flags & GP_CIRCLE_SEG3;
+ uint8_t seg4 = seg_flags & GP_CIRCLE_SEG4;
+
+ if (context->axes_swap)
+ GP_SWAP(seg2, seg4);
+
+ if (context->x_swap) {
+ GP_SWAP(seg1, seg2);
+ GP_SWAP(seg3, seg4);
+ }
+
+ if (context->y_swap) {
+ GP_SWAP(seg1, seg4);
+ GP_SWAP(seg2, seg3);
+ }
+
+ seg1 = seg1 ? GP_CIRCLE_SEG1 : 0;
+ seg2 = seg2 ? GP_CIRCLE_SEG2 : 0;
+ seg3 = seg3 ? GP_CIRCLE_SEG3 : 0;
+ seg4 = seg4 ? GP_CIRCLE_SEG4 : 0;
+
+ return seg1|seg2|seg3|seg4;
+}
+
+/* Generate drawing functions for various bit depths. */
+GP_DEF_DRAW_FN_PER_BPP(GP_CircleSeg_Raw, DEF_CIRCLE_SEG_FN)
+
+void GP_CircleSeg_Raw(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, uint8_t seg_flag, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_FN_PER_BPP_CONTEXT(GP_CircleSeg_Raw, context, context,
+ xcenter, ycenter, r, seg_flag, pixel);
+}
+
+void GP_CircleSeg(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, uint8_t seg_flag, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_TRANSFORM_POINT(context, xcenter, ycenter);
+
+ GP_CircleSeg_Raw(context, xcenter, ycenter, r,
+ transform_segments(context, 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_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_FN_PER_BPP_CONTEXT(GP_FillCircle_Raw, context, context,
+ xcenter, ycenter, r, pixel);
+}
+
+void GP_FillCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_TRANSFORM_POINT(context, xcenter, ycenter);
+
+ GP_FillCircle_Raw(context, xcenter, ycenter, r, pixel);
+}
+*/
diff --git a/libs/gfx/algo/CircleSeg.algo.h b/libs/gfx/algo/CircleSeg.algo.h
new file mode 100644
index 0000000..9812888
--- /dev/null
+++ b/libs/gfx/algo/CircleSeg.algo.h
@@ -0,0 +1,108 @@
+/*****************************************************************************
+ * This file is part of gfxprim library. *
+ * *
+ * Gfxprim is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * Gfxprim is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with gfxprim; if not, write to the Free Software *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
+ * Boston, MA 02110-1301 USA *
+ * *
+ * Copyright (C) 2009-2011 Jiri "BlueBear" Dluhos *
+ * <jiri.bluebear.dluhos(a)gmail.com> *
+ * *
+ * Copyright (C) 2009-2012 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+ * Circle drawing algorithm.
+ *
+ * The circle is drawn in a top-down manner. We start from the top, and
+ * at each line, we iterate X until we accumulate enough changes to Y
+ * to pass to the next line. In each step, 4 pixels are drawn:
+ * (X, Y), (-X, Y), (X, -Y) and (-X, -Y).
+ *
+ * The math:
+ * From the circle equation, for every point applies:
+ *
+ * x^2 + y^2 = r^2 -> x^2 + y^2 - r^2 = 0
+ *
+ * which has an exact solution for a non-integer x.
+ * For an integer approximation, we want to find x
+ * for which
+ *
+ * x^2 + y^2 - r^2 = error
+ *
+ * where error should be as close to 0 as possible.
+ * We find the x by incrementing its value until
+ * we cross the zero error boundary.
+ *
+ * Optimization:
+ * Significant amount of multiplications can be
+ * saved when calculating error by re-using previous
+ * error values. For error(x+1) we have:
+ *
+ * error(x+1) = (x+1)^2 + y^2 - r^2
+ *
+ * which can be expanded to (expanding (x+1)^2):
+ *
+ * error(x+1) = x^2 + 2*x + 1 + y^2 - r^2
+ *
+ * and after substituting the error(x) we already know:
+ *
+ * error(x+1) = error(x) + 2*x + 1
+ *
+ * The same can be done for calculating
+ * error(y-1) from error(y).
+ */
+
+/*
+ * This macro defines a circle drawing function.
+ * Arguments:
+ * CONTEXT_T - user-defined type of drawing context (passed to PUTPIXEL)
+ * PIXVAL_T - user-defined pixel value type (passed to PUTPIXEL)
+ * PUTPIXEL - a pixel drawing function f(context, x, y, pixval)
+ * FN_NAME - name of the function to be defined
+ */
+#define DEF_CIRCLE_SEG_FN(FN_NAME, CONTEXT_T, PIXVAL_T, PUTPIXEL) +void FN_NAME(CONTEXT_T context, int xcenter, int ycenter, unsigned int r, + uint8_t seg_flags, PIXVAL_T pixval) +{ + int x, y, error; + for (x = 0, error = -r, y = r; y >= 0; y--) { ++ /* Iterate X until we can pass to the next line. */ + while (error < 0) { + error += 2*x + 1; + x++; + if (seg_flags & GP_CIRCLE_SEG3) + PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); + if (seg_flags & GP_CIRCLE_SEG4) + PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval); + if (seg_flags & GP_CIRCLE_SEG2) + PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); + if (seg_flags & GP_CIRCLE_SEG1) + PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); + } ++ /* Enough changes accumulated, go to next line. */ + error += -2*y + 1; + if (seg_flags & GP_CIRCLE_SEG3) + PUTPIXEL(context, xcenter-x+1, ycenter-y, pixval); + if (seg_flags & GP_CIRCLE_SEG4) + PUTPIXEL(context, xcenter+x-1, ycenter-y, pixval);
+ if (seg_flags & GP_CIRCLE_SEG2) + PUTPIXEL(context, xcenter-x+1, ycenter+y, pixval); + if (seg_flags & GP_CIRCLE_SEG1) + PUTPIXEL(context, xcenter+x-1, ycenter+y, pixval); + } +}
-----------------------------------------------------------------------
Summary of changes:
include/gfx/{GP_Triangle.h => GP_CircleSeg.h} | 52 +++++++----
include/gfx/GP_Gfx.h | 1 +
libs/gfx/{GP_Circle.c => GP_CircleSeg.c} | 98 ++++++++++-----------
libs/gfx/algo/{Circle.algo.h => CircleSeg.algo.h} | 30 ++++---
4 files changed, 99 insertions(+), 82 deletions(-)
copy include/gfx/{GP_Triangle.h => GP_CircleSeg.h} (55%)
copy libs/gfx/{GP_Circle.c => GP_CircleSeg.c} (59%)
copy libs/gfx/algo/{Circle.algo.h => CircleSeg.algo.h} (85%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")