linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: linux-fbdev@vger.kernel.org
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH fbtest 04/17] drawops: Extract do_circle()
Date: Sun, 15 Dec 2024 11:44:55 +0100	[thread overview]
Message-ID: <20241215104508.191237-5-geert@linux-m68k.org> (raw)
In-Reply-To: <20241215104508.191237-1-geert@linux-m68k.org>

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 --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
-- 
2.34.1


  parent reply	other threads:[~2024-12-15 10:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-15 10:44 [PATCH fbtest 00/17] Export feature and large ellipses support Geert Uytterhoeven
2024-12-15 10:44 ` [PATCH fbtest 01/17] Add support for exporting virtual test images Geert Uytterhoeven
2024-12-15 10:44 ` [PATCH fbtest 02/17] tests: Print test description in debug mode Geert Uytterhoeven
2024-12-15 10:44 ` [PATCH fbtest 03/17] Test002: Fix test description Geert Uytterhoeven
2024-12-15 10:44 ` Geert Uytterhoeven [this message]
2024-12-15 10:44 ` [PATCH fbtest 05/17] drawops: Use "y == 0" in draw_ellipse_points() Geert Uytterhoeven
2024-12-15 10:44 ` [PATCH fbtest 06/17] drawops: Remove always-false check in generic_fill_ellipse() Geert Uytterhoeven
2024-12-15 10:44 ` [PATCH fbtest 07/17] drawops: Refactor generic_draw_ellipse() Geert Uytterhoeven
2024-12-15 10:44 ` [PATCH fbtest 08/17] drawops: Return early in generic_{draw,fill}_ellipse() Geert Uytterhoeven
2024-12-15 10:45 ` [PATCH fbtest 09/17] drawops: Extract do_ellipse() Geert Uytterhoeven
2024-12-15 10:45 ` [PATCH fbtest 10/17] drawops: Make de in do_circle() unsigned Geert Uytterhoeven
2024-12-15 10:45 ` [PATCH fbtest 11/17] drawops: Make dT1 and dS1 in do_ellipse() unsigned Geert Uytterhoeven
2024-12-15 10:45 ` [PATCH fbtest 12/17] drawops: Fix crash when drawing large ellipses Geert Uytterhoeven
2024-12-15 15:08   ` Helge Deller
2024-12-18 16:29     ` Geert Uytterhoeven
2024-12-18 18:00       ` Helge Deller
2024-12-15 10:45 ` [PATCH fbtest 13/17] tests: Clear frame buffer before each test Geert Uytterhoeven
2024-12-15 10:45 ` [PATCH fbtest 14/17] Make variables that are never negative unsigned Geert Uytterhoeven
2024-12-15 10:45 ` [PATCH fbtest 15/17] test013: Fix off-by-one error in maximum circle calculation Geert Uytterhoeven
2024-12-15 10:45 ` [PATCH fbtest 16/17] visops: Mark fall-through switch case Geert Uytterhoeven
2024-12-15 10:45 ` [PATCH fbtest 17/17] util: Use __attribute__ Geert Uytterhoeven
2024-12-24 13:07 ` [PATCH fbtest 00/17] Export feature and large ellipses support Geert Uytterhoeven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241215104508.191237-5-geert@linux-m68k.org \
    --to=geert@linux-m68k.org \
    --cc=linux-fbdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).