diff mbox series

[fbtest,04/17] drawops: Extract do_circle()

Message ID 20241215104508.191237-5-geert@linux-m68k.org (mailing list archive)
State New
Headers show
Series Export feature and large ellipses support | expand

Commit Message

Geert Uytterhoeven Dec. 15, 2024, 10:44 a.m. UTC
generic_draw_circle() and generic_fill_circle() are very similar.
Reimplement them as wrappers around a common helper function.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drawops/generic.c | 51 +++++++++++++++++------------------------------
 1 file changed, 18 insertions(+), 33 deletions(-)
diff mbox series

Patch

diff --git a/drawops/generic.c b/drawops/generic.c
index b2543b877a3a6154..9fd8aafb69a868a2 100644
--- a/drawops/generic.c
+++ b/drawops/generic.c
@@ -209,35 +209,6 @@  static void draw_circle_points(u32 cx, u32 cy, u32 x, u32 y, pixel_t pixel)
     }
 }
 
-void generic_draw_circle(u32 x, u32 y, u32 r, pixel_t pixel)
-{
-    u32 x1 = 0;
-    u32 y1 = r;
-    int d = 1-r;
-    int de = 3;
-    int dse = -2*r+5;
-
-    do {
-	draw_circle_points(x, y, x1, y1, pixel);
-	if (d < 0) {	// Select E
-	    d += de;
-	    de += 2;
-	    dse += 2;
-	} else {	// Select SE
-	    d += dse;
-	    de += 2;
-	    dse += 4;
-	    y1--;
-	}
-	x1++;
-    } while (x1 <= y1);
-}
-
-
-    /*
-     *  Draw a filled circle
-     */
-
 static void fill_circle_points_x(u32 cx, u32 cy, u32 x, u32 y, pixel_t pixel)
 {
     if (x == 0) {
@@ -259,7 +230,10 @@  static void fill_circle_points_y(u32 cx, u32 cy, u32 x, u32 y, pixel_t pixel)
     }
 }
 
-void generic_fill_circle(u32 x, u32 y, u32 r, pixel_t pixel)
+typedef void (*draw_func_t)(u32 cx, u32 cy, u32 x, u32 y, pixel_t pixel);
+
+static void do_circle(u32 x, u32 y, u32 r, pixel_t pixel, draw_func_t draw_x,
+		      draw_func_t draw_y)
 {
     u32 x1 = 0;
     u32 y1 = r;
@@ -268,7 +242,7 @@  void generic_fill_circle(u32 x, u32 y, u32 r, pixel_t pixel)
     int dse = -2*r+5;
 
     do {
-	fill_circle_points_y(x, y, x1, y1, pixel);
+	draw_y(x, y, x1, y1, pixel);
 	if (d < 0) {	// Select E
 	    d += de;
 	    de += 2;
@@ -277,14 +251,25 @@  void generic_fill_circle(u32 x, u32 y, u32 r, pixel_t pixel)
 	    d += dse;
 	    de += 2;
 	    dse += 4;
-	    if (x1 != y1)
-		fill_circle_points_x(x, y, x1, y1, pixel);
+	    if (draw_x && x1 != y1)
+		draw_x(x, y, x1, y1, pixel);
 	    y1--;
 	}
 	x1++;
     } while (x1 <= y1);
 }
 
+void generic_draw_circle(u32 x, u32 y, u32 r, pixel_t pixel)
+{
+    do_circle(x, y, r, pixel, NULL, draw_circle_points);
+}
+
+
+void generic_fill_circle(u32 x, u32 y, u32 r, pixel_t pixel)
+{
+    do_circle(x, y, r, pixel, fill_circle_points_x, fill_circle_points_y);
+}
+
 
     /*
      *  Draw an ellipse using a differential version of the Bresenham algorithm