Skip to content
Snippets Groups Projects
Commit e2d13d93 authored by Damien George's avatar Damien George
Browse files

extmod/modframebuf: Clip pixels drawn by line method.

parent 211244d1
Branches
No related tags found
No related merge requests found
...@@ -302,10 +302,14 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) { ...@@ -302,10 +302,14 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
mp_int_t e = 2 * dy - dx; mp_int_t e = 2 * dy - dx;
for (mp_int_t i = 0; i < dx; ++i) { for (mp_int_t i = 0; i < dx; ++i) {
if (steep) { if (steep) {
if (0 <= y1 && y1 < self->width && 0 <= x1 && x1 < self->height) {
setpixel(self, y1, x1, col); setpixel(self, y1, x1, col);
}
} else { } else {
if (0 <= x1 && x1 < self->width && 0 <= y1 && y1 < self->height) {
setpixel(self, x1, y1, col); setpixel(self, x1, y1, col);
} }
}
while (e >= 0) { while (e >= 0) {
y1 += sy; y1 += sy;
e -= 2 * dx; e -= 2 * dx;
...@@ -314,7 +318,9 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) { ...@@ -314,7 +318,9 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
e += 2 * dy; e += 2 * dy;
} }
if (0 <= x2 && x2 < self->width && 0 <= y2 && y2 < self->height) {
setpixel(self, x2, y2, col); setpixel(self, x2, y2, col);
}
return mp_const_none; return mp_const_none;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment