aboutsummaryrefslogtreecommitdiff
path: root/extmod/modframebuf.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-01-23 14:35:00 +1100
committerDamien George <damien.p.george@gmail.com>2017-01-23 14:35:00 +1100
commite2d13d934a19651bb7c06c0212a1b875d8b9be1b (patch)
treee9a297a8f0c4c796145ffbff00a4bc93e052feac /extmod/modframebuf.c
parent211244d1f3c58d8b3a79a5c25c398fb646f1521a (diff)
extmod/modframebuf: Clip pixels drawn by line method.
Diffstat (limited to 'extmod/modframebuf.c')
-rw-r--r--extmod/modframebuf.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c
index 93d4922c9..e2441f194 100644
--- a/extmod/modframebuf.c
+++ b/extmod/modframebuf.c
@@ -302,9 +302,13 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
mp_int_t e = 2 * dy - dx;
for (mp_int_t i = 0; i < dx; ++i) {
if (steep) {
- setpixel(self, y1, x1, col);
+ if (0 <= y1 && y1 < self->width && 0 <= x1 && x1 < self->height) {
+ setpixel(self, y1, x1, col);
+ }
} else {
- setpixel(self, x1, y1, col);
+ if (0 <= x1 && x1 < self->width && 0 <= y1 && y1 < self->height) {
+ setpixel(self, x1, y1, col);
+ }
}
while (e >= 0) {
y1 += sy;
@@ -314,7 +318,9 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
e += 2 * dy;
}
- setpixel(self, x2, y2, col);
+ if (0 <= x2 && x2 < self->width && 0 <= y2 && y2 < self->height) {
+ setpixel(self, x2, y2, col);
+ }
return mp_const_none;
}