Skip to content

Commit 41ec226

Browse files
deshipudpgeorge
authored andcommitted
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.
1 parent b6bdf18 commit 41ec226

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

extmod/modframebuf.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ STATIC mp_obj_t framebuf1_fill(mp_obj_t self_in, mp_obj_t col_in) {
6868
if (col) {
6969
col = 0xff;
7070
}
71-
for (int y = 0; y < self->height / 8; ++y) {
71+
int end = (self->height + 7) >> 3;
72+
for (int y = 0; y < end; ++y) {
7273
memset(self->buf + y * self->stride, col, self->width);
7374
}
7475
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
101102
mp_obj_framebuf1_t *self = MP_OBJ_TO_PTR(self_in);
102103
mp_int_t xstep = mp_obj_get_int(xstep_in);
103104
mp_int_t ystep = mp_obj_get_int(ystep_in);
105+
int end = (self->height + 7) >> 3;
104106
if (xstep == 0 && ystep > 0) {
105-
for (int y = self->height / 8; y > 0;) {
107+
for (int y = end; y > 0;) {
106108
--y;
107109
for (int x = 0; x < self->width; ++x) {
108110
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
113115
}
114116
}
115117
} else if (xstep == 0 && ystep < 0) {
116-
for (int y = 0; y < self->height / 8; ++y) {
118+
for (int y = 0; y < end; ++y) {
117119
for (int x = 0; x < self->width; ++x) {
118120
int prev = 0;
119-
if (y + 1 < self->height / 8) {
121+
if (y + 1 < end) {
120122
prev = self->buf[(y + 1) * self->stride + x] << (8 + ystep);
121123
}
122124
self->buf[y * self->stride + x] = (self->buf[y * self->stride + x] >> -ystep) | prev;

0 commit comments

Comments
 (0)