Skip to content

Commit 948863c

Browse files
corranwebsterdpgeorge
authored andcommitted
extmod/modframebuf: Fix 0 radius bug in FrameBuffer.ellipse.
This fixes a bug in FrameBuffer.ellipse where it goes into an infinite loop if both radii are 0. This fixes the bug with a simple pre-check to see if both radii are 0, and in that case sets a single pixel at the center. This is consistent with the behaviour of the method when called with just one of the radii set to 0, where it will draw a horizontal or vertical line of 1 pixel width. The pixel is set with setpixel_checked so it should handle out-of-bounds drawing correctly. This fix also includes three new tests: one for the default behaviour, one for drawing out-of-bounds, and one for when the sector mask is 0. Fixes issue #16053. Signed-off-by: Corran Webster <cwebster@unital.dev>
1 parent 33f50d4 commit 948863c

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

extmod/modframebuf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ static mp_obj_t framebuf_ellipse(size_t n_args, const mp_obj_t *args_in) {
536536
} else {
537537
mask |= ELLIPSE_MASK_ALL;
538538
}
539+
if (args[2] == 0 && args[3] == 0) {
540+
setpixel_checked(self, args[0], args[1], args[4], mask & ELLIPSE_MASK_ALL);
541+
return mp_const_none;
542+
}
539543
mp_int_t two_asquare = 2 * args[2] * args[2];
540544
mp_int_t two_bsquare = 2 * args[3] * args[3];
541545
mp_int_t x = args[2];

tests/extmod/framebuf_ellipse.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,18 @@ def printbuf():
6363
fbuf.fill(0)
6464
fbuf.ellipse(x, y, 6, 12, 0xAA, True)
6565
printbuf()
66+
67+
# Draw an ellipse with both radius 0
68+
fbuf.fill(0)
69+
fbuf.ellipse(15, 15, 0, 0, 0xFF, True)
70+
printbuf()
71+
72+
# Draw an ellipse with both radius 0 out of bounds
73+
fbuf.fill(0)
74+
fbuf.ellipse(45, 45, 0, 0, 0xFF, True)
75+
printbuf()
76+
77+
# Draw an ellipse with radius 0 and all sectors masked out
78+
fbuf.fill(0)
79+
fbuf.ellipse(15, 15, 0, 0, 0xFF, True, 0)
80+
printbuf()

tests/extmod/framebuf_ellipse.py.exp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,3 +702,99 @@ aaaaaaaaaaaaaaaaaaaaaa00000000000000000000000000000000000000
702702
aaaaaaaaaaaaaaaaaaaaaa00000000000000000000000000000000000000
703703
aaaaaaaaaaaaaaaaaaaaaa00000000000000000000000000000000000000
704704
-->8--
705+
--8<--
706+
000000000000000000000000000000000000000000000000000000000000
707+
000000000000000000000000000000000000000000000000000000000000
708+
000000000000000000000000000000000000000000000000000000000000
709+
000000000000000000000000000000000000000000000000000000000000
710+
000000000000000000000000000000000000000000000000000000000000
711+
000000000000000000000000000000000000000000000000000000000000
712+
000000000000000000000000000000000000000000000000000000000000
713+
000000000000000000000000000000000000000000000000000000000000
714+
000000000000000000000000000000000000000000000000000000000000
715+
000000000000000000000000000000000000000000000000000000000000
716+
000000000000000000000000000000000000000000000000000000000000
717+
000000000000000000000000000000000000000000000000000000000000
718+
000000000000000000000000000000000000000000000000000000000000
719+
000000000000000000000000000000000000000000000000000000000000
720+
000000000000000000000000000000000000000000000000000000000000
721+
000000000000000000000000000000ff0000000000000000000000000000
722+
000000000000000000000000000000000000000000000000000000000000
723+
000000000000000000000000000000000000000000000000000000000000
724+
000000000000000000000000000000000000000000000000000000000000
725+
000000000000000000000000000000000000000000000000000000000000
726+
000000000000000000000000000000000000000000000000000000000000
727+
000000000000000000000000000000000000000000000000000000000000
728+
000000000000000000000000000000000000000000000000000000000000
729+
000000000000000000000000000000000000000000000000000000000000
730+
000000000000000000000000000000000000000000000000000000000000
731+
000000000000000000000000000000000000000000000000000000000000
732+
000000000000000000000000000000000000000000000000000000000000
733+
000000000000000000000000000000000000000000000000000000000000
734+
000000000000000000000000000000000000000000000000000000000000
735+
000000000000000000000000000000000000000000000000000000000000
736+
-->8--
737+
--8<--
738+
000000000000000000000000000000000000000000000000000000000000
739+
000000000000000000000000000000000000000000000000000000000000
740+
000000000000000000000000000000000000000000000000000000000000
741+
000000000000000000000000000000000000000000000000000000000000
742+
000000000000000000000000000000000000000000000000000000000000
743+
000000000000000000000000000000000000000000000000000000000000
744+
000000000000000000000000000000000000000000000000000000000000
745+
000000000000000000000000000000000000000000000000000000000000
746+
000000000000000000000000000000000000000000000000000000000000
747+
000000000000000000000000000000000000000000000000000000000000
748+
000000000000000000000000000000000000000000000000000000000000
749+
000000000000000000000000000000000000000000000000000000000000
750+
000000000000000000000000000000000000000000000000000000000000
751+
000000000000000000000000000000000000000000000000000000000000
752+
000000000000000000000000000000000000000000000000000000000000
753+
000000000000000000000000000000000000000000000000000000000000
754+
000000000000000000000000000000000000000000000000000000000000
755+
000000000000000000000000000000000000000000000000000000000000
756+
000000000000000000000000000000000000000000000000000000000000
757+
000000000000000000000000000000000000000000000000000000000000
758+
000000000000000000000000000000000000000000000000000000000000
759+
000000000000000000000000000000000000000000000000000000000000
760+
000000000000000000000000000000000000000000000000000000000000
761+
000000000000000000000000000000000000000000000000000000000000
762+
000000000000000000000000000000000000000000000000000000000000
763+
000000000000000000000000000000000000000000000000000000000000
764+
000000000000000000000000000000000000000000000000000000000000
765+
000000000000000000000000000000000000000000000000000000000000
766+
000000000000000000000000000000000000000000000000000000000000
767+
000000000000000000000000000000000000000000000000000000000000
768+
-->8--
769+
--8<--
770+
000000000000000000000000000000000000000000000000000000000000
771+
000000000000000000000000000000000000000000000000000000000000
772+
000000000000000000000000000000000000000000000000000000000000
773+
000000000000000000000000000000000000000000000000000000000000
774+
000000000000000000000000000000000000000000000000000000000000
775+
000000000000000000000000000000000000000000000000000000000000
776+
000000000000000000000000000000000000000000000000000000000000
777+
000000000000000000000000000000000000000000000000000000000000
778+
000000000000000000000000000000000000000000000000000000000000
779+
000000000000000000000000000000000000000000000000000000000000
780+
000000000000000000000000000000000000000000000000000000000000
781+
000000000000000000000000000000000000000000000000000000000000
782+
000000000000000000000000000000000000000000000000000000000000
783+
000000000000000000000000000000000000000000000000000000000000
784+
000000000000000000000000000000000000000000000000000000000000
785+
000000000000000000000000000000000000000000000000000000000000
786+
000000000000000000000000000000000000000000000000000000000000
787+
000000000000000000000000000000000000000000000000000000000000
788+
000000000000000000000000000000000000000000000000000000000000
789+
000000000000000000000000000000000000000000000000000000000000
790+
000000000000000000000000000000000000000000000000000000000000
791+
000000000000000000000000000000000000000000000000000000000000
792+
000000000000000000000000000000000000000000000000000000000000
793+
000000000000000000000000000000000000000000000000000000000000
794+
000000000000000000000000000000000000000000000000000000000000
795+
000000000000000000000000000000000000000000000000000000000000
796+
000000000000000000000000000000000000000000000000000000000000
797+
000000000000000000000000000000000000000000000000000000000000
798+
000000000000000000000000000000000000000000000000000000000000
799+
000000000000000000000000000000000000000000000000000000000000
800+
-->8--

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy