diff options
author | Radomir Dopieralski <openstack@sheep.art.pl> | 2016-08-28 19:13:32 +0200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-09-02 23:58:34 +1000 |
commit | 41ec22632da8f61ca5c841e13206258048d1be5b (patch) | |
tree | 4423dc5b26dcfb46668105cb92e3bf091e081701 | |
parent | b6bdf18debfd75e9d39c2e8452c7b4ade448bcc5 (diff) | |
download | micropython-41ec22632da8f61ca5c841e13206258048d1be5b.tar.gz micropython-41ec22632da8f61ca5c841e13206258048d1be5b.zip |
extmod/modframebuf: Fix fill and scroll when height not divisible by 8.
There was a bug in `framebuf1_fill` function, that makes it leave a few
lines unfilled at the bottom if the height is not divisible by 8.
A similar bug is fixed in the scroll method.
-rw-r--r-- | extmod/modframebuf.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index a1e7c079be..84f1246fba 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -68,7 +68,8 @@ STATIC mp_obj_t framebuf1_fill(mp_obj_t self_in, mp_obj_t col_in) { if (col) { col = 0xff; } - for (int y = 0; y < self->height / 8; ++y) { + int end = (self->height + 7) >> 3; + for (int y = 0; y < end; ++y) { memset(self->buf + y * self->stride, col, self->width); } return mp_const_none; @@ -101,8 +102,9 @@ STATIC mp_obj_t framebuf1_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t y mp_obj_framebuf1_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t xstep = mp_obj_get_int(xstep_in); mp_int_t ystep = mp_obj_get_int(ystep_in); + int end = (self->height + 7) >> 3; if (xstep == 0 && ystep > 0) { - for (int y = self->height / 8; y > 0;) { + for (int y = end; y > 0;) { --y; for (int x = 0; x < self->width; ++x) { int prev = 0; @@ -113,10 +115,10 @@ STATIC mp_obj_t framebuf1_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t y } } } else if (xstep == 0 && ystep < 0) { - for (int y = 0; y < self->height / 8; ++y) { + for (int y = 0; y < end; ++y) { for (int x = 0; x < self->width; ++x) { int prev = 0; - if (y + 1 < self->height / 8) { + if (y + 1 < end) { prev = self->buf[(y + 1) * self->stride + x] << (8 + ystep); } self->buf[y * self->stride + x] = (self->buf[y * self->stride + x] >> -ystep) | prev; |